@licq/tpkg
Version:
pack or unpack wechatapp and qqminiapp package
51 lines (48 loc) • 1.24 kB
JavaScript
const fs = require("fs");
const program = require("commander");
const tpkg = require("./index");
const version = require("./package.json").version;
program
.version(version)
.argument("<resource>", "pkg file or a dir", function (value) {
if (!fs.existsSync(value)) {
throw new program.InvalidArgumentError(
`path: [${value}] does not exist.`
);
}
return value;
})
.argument(
"[target]",
"target path, default is the same as the resource",
function (value) {
if (value && !fs.existsSync(value)) {
throw new program.InvalidArgumentError(
`path: [${value}] does not exist.`
);
}
return value;
}
)
.argument(
"[filename]",
"target filename, default is the same as the resource. only use for pack.",
function (value) {
return value;
}
)
.usage("resource [target] [filename]")
.action((resource, target, filename) => {
if (fs.statSync(resource).isFile()) {
tpkg.unpack(resource, target);
} else {
tpkg.pack(resource, target, filename);
}
})
.on("--help", () => {
console.log();
console.log(`Only ww is required.`);
})
.showHelpAfterError()
.parse();