提交 872ac28f 作者: 潘亚楠

命令行参数解析#2

上级 992680e8
## 测试步骤
1.
2.
3.
4.
## 测试结果
## 期望结果
## 附件
\ No newline at end of file
## 修改类型(必填)
- [ ] bug修复
- [ ] 需求添加
- [ ] 页面调整
- [ ] 代码审查
- [ ] 提测
- [ ] 上线
## 内容
1. 修改issue编号
2. 代码审查issue
3. 其他
......@@ -42,6 +42,27 @@
"internalConsoleOptions": "neverOpen"
},
{
"name": "bin index",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}", // 当前文件
"create",
"hello",
"world"
],
"runtimeArgs": [
"--nolazy",
"-r",
"ts-node/register",
],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"name": "Current Test File",
"type": "node",
"request": "launch",
......
......@@ -4,6 +4,11 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@types/color-name": {
"version": "1.1.1",
"resolved": "http://39.106.145.141:9000/repository/node-public/@types/color-name/-/color-name-1.1.1.tgz",
"integrity": "sha1-HBJhu+qhCoBVu8XYq4S3sq/IRqA="
},
"@types/commander": {
"version": "2.12.2",
"resolved": "http://39.106.145.141:9000/repository/node-public/@types/commander/-/commander-2.12.2.tgz",
......@@ -151,6 +156,19 @@
"string-width": "^2.0.0",
"term-size": "^1.2.0",
"widest-line": "^2.0.0"
},
"dependencies": {
"chalk": {
"version": "2.4.2",
"resolved": "http://39.106.145.141:9000/repository/node-public/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha1-zUJUFnelQzPPVBpJEIwUMrRMlCQ=",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
}
}
},
"brace-expansion": {
......@@ -203,14 +221,49 @@
"dev": true
},
"chalk": {
"version": "2.4.2",
"resolved": "http://39.106.145.141:9000/repository/node-public/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha1-zUJUFnelQzPPVBpJEIwUMrRMlCQ=",
"dev": true,
"version": "3.0.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/chalk/-/chalk-3.0.0.tgz",
"integrity": "sha1-P3PCv1JlkfV0zEksUeJFY0n4ROQ=",
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"dependencies": {
"ansi-styles": {
"version": "4.2.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/ansi-styles/-/ansi-styles-4.2.0.tgz",
"integrity": "sha1-VoHw3PeuWICnhB2IMcRyTtnMAXI=",
"requires": {
"@types/color-name": "^1.1.1",
"color-convert": "^2.0.1"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "http://39.106.145.141:9000/repository/node-public/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha1-ctOmjVmMm9s68q0ehPIdiWq9TeM=",
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "http://39.106.145.141:9000/repository/node-public/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha1-wqCah6y95pVD3m9j+jmVyCbFNqI="
},
"has-flag": {
"version": "4.0.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha1-lEdx/ZyByBJlxNaUGGDaBrtZR5s="
},
"supports-color": {
"version": "7.1.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/supports-color/-/supports-color-7.1.0.tgz",
"integrity": "sha1-aOMlkd9z4lrRxLSRCKLsUHliv9E=",
"requires": {
"has-flag": "^4.0.0"
}
}
}
},
"chokidar": {
......@@ -323,6 +376,28 @@
"yargs": "^13.3.0"
},
"dependencies": {
"chalk": {
"version": "2.4.2",
"resolved": "http://39.106.145.141:9000/repository/node-public/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha1-zUJUFnelQzPPVBpJEIwUMrRMlCQ=",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
},
"dependencies": {
"supports-color": {
"version": "5.5.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha1-4uaaRKyHcveKHsCzW2id9lMO/I8=",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
}
}
}
},
"supports-color": {
"version": "6.1.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/supports-color/-/supports-color-6.1.0.tgz",
......@@ -946,6 +1021,19 @@
"dev": true,
"requires": {
"chalk": "^2.0.1"
},
"dependencies": {
"chalk": {
"version": "2.4.2",
"resolved": "http://39.106.145.141:9000/repository/node-public/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha1-zUJUFnelQzPPVBpJEIwUMrRMlCQ=",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
}
}
},
"lowercase-keys": {
......@@ -1816,6 +1904,19 @@
"latest-version": "^3.0.0",
"semver-diff": "^2.0.0",
"xdg-basedir": "^3.0.0"
},
"dependencies": {
"chalk": {
"version": "2.4.2",
"resolved": "http://39.106.145.141:9000/repository/node-public/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha1-zUJUFnelQzPPVBpJEIwUMrRMlCQ=",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
}
}
},
"url-parse-lax": {
......
......@@ -3,12 +3,16 @@
"version": "0.1.0",
"description": "qj-vue-cli",
"main": "index.js",
"bin": {
"qj-cli": "dist/bin/index.js"
},
"scripts": {
"watch-node": "nodemon dist/index.js",
"watch-ts": "tsc -w",
"dev": "concurrently \"npm run watch-ts\" \"npm run watch-node\"",
"watch-bin": "nodemon dist/bin/index.js create vue2.0 hello",
"dev": "concurrently \"npm run watch-ts\" \"npm run watch-bin\"",
"build": "tsc",
"test": "mocha -r ts-node/register dist/**/*.test.js"
"dev-link": "npm run build && npm unlink && npm link",
"test": "mocha -r ts-node/register src/test/**/*.test.ts"
},
"repository": {
"type": "git",
......@@ -34,6 +38,7 @@
"typescript": "^3.7.3"
},
"dependencies": {
"chalk": "^3.0.0",
"commander": "^4.0.1"
}
}
#!/usr/bin/env node
import * as program from 'commander';
import { Templates } from '../config/template.config';
program
.command('create [projectName]')
.description('create command')
.option('-o, --open', 'Open browser')
.action((projectName, cmd) => {
console.log(projectName, cmd);
})
program.parse(process.argv)
#!/usr/bin/env node
import * as program from 'commander';
import { hasTemplate } from '../config/template.config';
import listTemplates from '../lib/listTemplates';
program
.version(`${require('../../package.json').version}`)
.name('world')
.usage('<command> [options]');
program
.command('create <templateName> <projectName>')
.description('create a project from a template')
.action((templateName: string, projectName: string, cmd) => {
console.log(templateName);
console.log(projectName);
})
program
.command('ls')
.description('list all templates')
.action(cmd => {
listTemplates();
})
program.parse(process.argv)
import * as chalk from 'chalk';
/**
* @date 2019.12.16
* @author panyanan
* @information 框架模板配置文件
*/
export interface Repo {
url: string, // 仓库地址
user: string, // 用户名
password: string, // 用户密码
readonly url: string, // 仓库地址
readonly username: string, // 用户名
readonly password: string, // 用户密码
}
export interface Template {
name: string, // 模板名称
desc: string, // 模板描述
repo: Repo,
readonly name: string, // 模板名称
readonly desc: string, // 模板描述
readonly repo: Repo, // 模板仓库信息
}
export const Templates: Template[] = [
{ name: 'vue2.0', desc: 'hello world', repo: { url: '', user: '', password: ''} },
// other todo
];
\ No newline at end of file
{ name: 'vue2.0', desc: 'hello world', repo: { url: '', username: '', password: ''} },
// todo other template
];
/**
* @date 2019.12.16
* @author panyanan
* @information 是否是正确的模板名称
* @param targetName
*/
export function hasTemplate(targetName: string): boolean {
return Templates.some(({ name }) => name.toLowerCase() === targetName.toLocaleLowerCase());
}
/**
* @date 2019.12.16
* @author panyanan
* @information 打印模板
*/
import { Templates } from '../config/template.config';
import * as chalk from 'chalk';
/**
* @date 2019.12.16
* @author panyanan
* @information 打印所有的模板
*/
export default function () {
const { log } = console;
Templates.forEach(template => {
const { name, desc } = template;
log(` ${chalk.blueBright(name)}: ${chalk.gray(desc)}`)
})
}
\ No newline at end of file
import { Templates, hasTemplate } from '../../config/template.config';
import * as assert from 'power-assert';
describe('#template.config.ts', function () {
it('#hasTemplate', function () {
// vue2.0 should in Templates
assert.ok(hasTemplate('vue2.0'));
// Vue2.0 equals vue2.0 should in Templates
assert.ok(hasTemplate('Vue2.0'));
// abc should not in Templates
assert.strictEqual(hasTemplate('abc'), false);
})
})
\ No newline at end of file
import * as assert from 'power-assert';
describe('test', function () {
it('is a test', function () {
assert(true);
})
})
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论