datamax-cli
Version:
datamax plugin cli
53 lines (45 loc) • 1.58 kB
JavaScript
// download-git-repo :在git中下载模板
// metalsmith :读取所有文件,实现模板渲染
// consolidate :统一模板引擎
const chalk = require("chalk");
const program = require("commander");
const _ = require("lodash");
let config = require("../package.json");
const buildProject = require("../build/index.js");
const shelljs = require("shelljs");
shelljs.config.verbose = true;
shelljs.config.silent = true;
const logo = `
.___ __
__| _/____ _/ |______ _____ _____ ___ ___
/ __ |\\__ \\\\ __\\__ \\ / \\\\__ \\ \\ \\/ /
/ /_/ | / __ \\| | / __ \\| Y Y \\/ __ \\_> <
\\____ |(____ /__| (____ /__|_| (____ /__/\\_ \\
\\/ \\/ \\/ \\/ \\/ \\/
`;
const COMMANDMAP = {
init: require("../libs/init"), //初始化
package: require("../libs/package"), //打包文件
preview: require("../libs/preview"), //打包文件
};
function exec(command, ...args) {
COMMANDMAP[command](config, ...args);
}
console.log(chalk.cyan(logo));
config = _.merge(config, require("../config"));
program.usage("[options] <folder|file...>").version(config.version);
program
.command("init")
.description("初始化datamax插件")
.action((...args) => exec("init", ...args));
program
.command("package")
.description("打包并发布")
.action((...args) => exec("package", ...args));
program
.command("preview")
.description("插件预览")
.action((...args) => exec("preview", ...args));
program.parse(process.argv);
;