根據如下流程
新建資料夾pwb-cli,在資料夾中
npm init -y
|——bin |——pwb |——pwb-download|——conf |——template。json |——package。json
package。json 在後面download檔案中引入有相應的依賴功能解釋
{ “name”: “pwb-cli”, “version”: “1。0。0”, “scripts”: { “test”: “echo \”Error: no test specified\“ && exit 1” }, “bin”: { “pwb”: “bin/pwb”, “pwb-download”: “bin/pwb-download” }, “license”: “ISC”, “dependencies”: { “chalk”: “^4。1。0”, “commander”: “^6。1。0”, “download-git-repo”: “^3。0。2”, “ejs”: “^2。7。4”, “git-clone”: “^0。1。0”, “glob”: “^7。1。6”, “handlebars”: “^4。7。6”, “inquirer”: “^6。5。2”, “latest-version”: “^5。1。0”, “log-symbols”: “^4。0。0”, “metalsmith”: “^2。3。0”, “minimatch”: “^3。0。4”, “ora”: “^5。1。0”, “request”: “^2。88。2”, “rimraf”: “^3。0。2”, “unzip-stream”: “^0。3。1”, “wrap-ansi”: “^7。0。0” }, “keywords”: [ “cli”, “模板”, “構建工具” ]}
安裝依賴
npm i
bin/pwb檔案內容
#!/usr/bin/env nodeconst program = require(‘commander’)//console。log(‘version’, require(‘。。/package’)。version)program 。version(require(‘。。/package’)。version) 。usage(‘
bin/pwb-download檔案內容
#!/usr/bin/env node// NODE moudleconst unzip = require(“unzip-stream”);const request = require(“request”);// node。js 命令列解決方案const program = require(“commander”);// node。js path模組const path = require(“path”);// node。js fs模組const fs = require(“fs”);// 常見的互動式命令列使用者介面的集合const inquirer = require(“inquirer”);// 使用shell模式匹配檔案const glob = require(“glob”);// The UNIX command rm -rf for node。const rm = require(“rimraf”)。sync;// fileconst ora = require(“ora”);const logSymbols = require(“log-symbols”);const chalk = require(“chalk”);const templateConfig = require(“。。/conf/template。json”);program。usage(“
conf/template。json內容
{ “vue”: { “name”: “模板一”, “value”: “big-screen-demo。zip”, “fileUrl”: “http://192。168。3。42/doc/template/big-screen-demo。zip” }, “react”: { “name”: “模板二”, “value”: “big-screen-demo。zip”, “fileUrl”: “http://192。168。3。42/doc/template/big-screen-demo。zip” }, “angular”: { “name”: “模板三”, “value”: “big-screen-demo。zip”, “fileUrl”: “http://192。168。3。42/doc/template/big-screen-demo。zip” }}
執行專案
npm link
如果安裝過
npm link ——force
下載模板
pwb download