inkplugin
Version:
INK cli tools for plugin developers.
49 lines (42 loc) • 1.53 kB
JavaScript
const { Command, flags } = require("@oclif/command");
const { hashElement } = require('folder-hash');
const fs = require("fs");
const path = require("path")
class HashCommand extends Command {
async run() {
const { flags, args } = this.parse(HashCommand);
const location = args.path;
this.log(
"\n******************** Creating Plugin's Hash ********************\n"
);
this.log(`Location: ${location}\n`);
const options = {
folders: { exclude: ['.*', 'node_modules', 'dist'] },
files: { exclude: ['.*', 'inkapi.js'] },
}
hashElement(location, options).then(hash => {
let outputLocation = path.join(path.dirname(location), "hash.json");
fs.writeFile(outputLocation, JSON.stringify(hash.children), (err) => {
if (err) {
this.error("Something went wrong while creating hash file, please try again.")
} else {
this.log(`Created Hash Successfully :: ${outputLocation}`)
}
})
}, () => {
this.error("Something went wrong, please try again.")
})
}
}
HashCommand.description = `Create Hash for your plugin
Hash can be used to maintain your plugin's integrity across devices.
`;
HashCommand.args = [
{
name: "path", // name of arg to show in help and reference with args[name]
required: true, // make the arg required with `required: true`
description: "Path for plugin project root.", // help description
hidden: false, // hide this arg from help
},
];
module.exports = HashCommand;