#!/usr/bin/env node 'use strict'; process.title = 'image2d-cli'; const __ = require('@yelloxing/core.js'); const cuf = require('cuf'); const options = require('./options').config; const help = require('./options').help; const pkg = require('../package.json'); const path = require('path'); // 组装好缩写和全写的映射 let shortHands = {}; for (let key in options) { if (options[key].short) shortHands["-" + options[key].short] = "--" + key; } // 命令行传递的参数 const parsed = cuf.option(shortHands, process.argv); // 打印帮助信息 if (__.isArray(parsed.help)) { // 打印具体的配置提示 if (parsed.help.length > 0) { let help0 = parsed.help[0]; // 缩写转全拼 if (help0.length == 1) help0 = shortHands["-" + help0]; if (help0) { help0 = help0.replace(/^--/, ""); // 根据需要帮助的命令获取对应的信息 const help0Option = options[help0]; if (help0Option) { cuf.log("\n" + help0Option.demo + ` ` + help0Option.info + "\n"); return; } } } cuf.log(help); } // 打印版本信息 else if (__.isArray(parsed.version)) { cuf.log("\nv" + pkg.version + "\n"); } // 初始化组件项目 else if (__.isArray(parsed.init)) { // 组件名称 let componentName = "image2d-contrib-" + (parsed.init[0] || 'default'); // 主体文件和目标文件地址 let codeUrl = path.join(__dirname, '../contrib'); let targetUrl = path.join(process.cwd(), './' + componentName); // 复制主体文件 cuf.copySync(codeUrl, targetUrl); // 生成一些不确定的文件 require('./_package.json.js')(path.join(targetUrl, 'package.json'), componentName); require('./_ignore.js')(path.join(targetUrl, '.npmignore'), path.join(targetUrl, '.gitignore')); require('./_README.md.js')(path.join(targetUrl, 'README.md'), componentName); } // 打印统一提示 else { cuf.log(` ` + pkg.name + `@v` + pkg.version + `:` + pkg.description + ` 【1】干什么的? -------------------------------------------------------- 辅助你开发基于image2D.js <`+ pkg.repository.url + `> 的图形组件。 【2】如何升级? -------------------------------------------------------- 直接执行安装命令即可:npm install -g image2d `); cuf.log(help); }