提交 f25e311d 作者: 潘亚楠

create 命令#6

上级 5b57a372
src
.gitlab
tsconfig.json
.gitignore
\ No newline at end of file
{ {
"name": "qj-vue-cli", "name": "qj-cli",
"version": "0.1.0", "version": "0.1.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
...@@ -42,6 +42,16 @@ ...@@ -42,6 +42,16 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"@types/inquirer": {
"version": "6.5.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/@types/inquirer/-/inquirer-6.5.0.tgz",
"integrity": "sha1-uDsL8wuIuL5yRtQOUdMv6dEOCb4=",
"dev": true,
"requires": {
"@types/through": "*",
"rxjs": "^6.4.0"
}
},
"@types/mocha": { "@types/mocha": {
"version": "5.2.7", "version": "5.2.7",
"resolved": "http://39.106.145.141:9000/repository/node-public/@types/mocha/-/mocha-5.2.7.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/@types/mocha/-/mocha-5.2.7.tgz",
...@@ -70,6 +80,15 @@ ...@@ -70,6 +80,15 @@
"integrity": "sha1-Jbj922MiJZxrkcNTONObD45SQlI=", "integrity": "sha1-Jbj922MiJZxrkcNTONObD45SQlI=",
"dev": true "dev": true
}, },
"@types/through": {
"version": "0.0.29",
"resolved": "http://39.106.145.141:9000/repository/node-public/@types/through/-/through-0.0.29.tgz",
"integrity": "sha1-cpQ6rJIuF5M5xlH6NKRCik1yL5M=",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"abbrev": { "abbrev": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "http://39.106.145.141:9000/repository/node-public/abbrev/-/abbrev-1.1.1.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/abbrev/-/abbrev-1.1.1.tgz",
...@@ -103,6 +122,14 @@ ...@@ -103,6 +122,14 @@
"integrity": "sha1-V9NbhoboUeLMBMQD8cACA5dqGBM=", "integrity": "sha1-V9NbhoboUeLMBMQD8cACA5dqGBM=",
"dev": true "dev": true
}, },
"ansi-escapes": {
"version": "4.3.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/ansi-escapes/-/ansi-escapes-4.3.0.tgz",
"integrity": "sha1-pM4rM9ayFLeVDYWVwhLxKsnMVp0=",
"requires": {
"type-fest": "^0.8.1"
}
},
"ansi-regex": { "ansi-regex": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/ansi-regex/-/ansi-regex-3.0.0.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/ansi-regex/-/ansi-regex-3.0.0.tgz",
...@@ -283,6 +310,11 @@ ...@@ -283,6 +310,11 @@
} }
} }
}, },
"chardet": {
"version": "0.7.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/chardet/-/chardet-0.7.0.tgz",
"integrity": "sha1-kAlISfCTfy7twkJdDSip5fDLrZ4="
},
"chokidar": { "chokidar": {
"version": "3.3.0", "version": "3.3.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/chokidar/-/chokidar-3.3.0.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/chokidar/-/chokidar-3.3.0.tgz",
...@@ -324,6 +356,11 @@ ...@@ -324,6 +356,11 @@
"resolved": "http://39.106.145.141:9000/repository/node-public/cli-spinners/-/cli-spinners-2.2.0.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/cli-spinners/-/cli-spinners-2.2.0.tgz",
"integrity": "sha1-6LmI2SBsaSMC2O6DTnqFwBRNj3c=" "integrity": "sha1-6LmI2SBsaSMC2O6DTnqFwBRNj3c="
}, },
"cli-width": {
"version": "2.2.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/cli-width/-/cli-width-2.2.0.tgz",
"integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk="
},
"cliui": { "cliui": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/cliui/-/cliui-5.0.0.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/cliui/-/cliui-5.0.0.tgz",
...@@ -705,6 +742,24 @@ ...@@ -705,6 +742,24 @@
} }
} }
}, },
"external-editor": {
"version": "3.1.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/external-editor/-/external-editor-3.1.0.tgz",
"integrity": "sha1-ywP3QL764D6k0oPK7SdBqD8zVJU=",
"requires": {
"chardet": "^0.7.0",
"iconv-lite": "^0.4.24",
"tmp": "^0.0.33"
}
},
"figures": {
"version": "3.1.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/figures/-/figures-3.1.0.tgz",
"integrity": "sha1-SxmN0H2NcVMGQoZK8tRd2eRZxOw=",
"requires": {
"escape-string-regexp": "^1.0.5"
}
},
"fill-range": { "fill-range": {
"version": "7.0.1", "version": "7.0.1",
"resolved": "http://39.106.145.141:9000/repository/node-public/fill-range/-/fill-range-7.0.1.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/fill-range/-/fill-range-7.0.1.tgz",
...@@ -872,6 +927,14 @@ ...@@ -872,6 +927,14 @@
"resolved": "http://39.106.145.141:9000/repository/node-public/human-signals/-/human-signals-1.1.1.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/human-signals/-/human-signals-1.1.1.tgz",
"integrity": "sha1-xbHNFPUK6uCatsWf5jujOV/k36M=" "integrity": "sha1-xbHNFPUK6uCatsWf5jujOV/k36M="
}, },
"iconv-lite": {
"version": "0.4.24",
"resolved": "http://39.106.145.141:9000/repository/node-public/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha1-ICK0sl+93CHS9SSXSkdKr+czkIs=",
"requires": {
"safer-buffer": ">= 2.1.2 < 3"
}
},
"ignore-by-default": { "ignore-by-default": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "http://39.106.145.141:9000/repository/node-public/ignore-by-default/-/ignore-by-default-1.0.1.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
...@@ -918,6 +981,88 @@ ...@@ -918,6 +981,88 @@
"integrity": "sha1-7uJfVtscnsYIXgwid4CD9Zar+Sc=", "integrity": "sha1-7uJfVtscnsYIXgwid4CD9Zar+Sc=",
"dev": true "dev": true
}, },
"inquirer": {
"version": "7.0.1",
"resolved": "http://39.106.145.141:9000/repository/node-public/inquirer/-/inquirer-7.0.1.tgz",
"integrity": "sha1-E/eYDu3HPGif7/OZSxCcTnmcbrs=",
"requires": {
"ansi-escapes": "^4.2.1",
"chalk": "^2.4.2",
"cli-cursor": "^3.1.0",
"cli-width": "^2.0.0",
"external-editor": "^3.0.3",
"figures": "^3.0.0",
"lodash": "^4.17.15",
"mute-stream": "0.0.8",
"run-async": "^2.2.0",
"rxjs": "^6.5.3",
"string-width": "^4.1.0",
"strip-ansi": "^5.1.0",
"through": "^2.3.6"
},
"dependencies": {
"ansi-regex": {
"version": "5.0.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/ansi-regex/-/ansi-regex-5.0.0.tgz",
"integrity": "sha1-OIU59VF5vzkznIGvMKZU1p+Hy3U="
},
"chalk": {
"version": "2.4.2",
"resolved": "http://39.106.145.141:9000/repository/node-public/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha1-zUJUFnelQzPPVBpJEIwUMrRMlCQ=",
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"emoji-regex": {
"version": "8.0.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/emoji-regex/-/emoji-regex-8.0.0.tgz",
"integrity": "sha1-6Bj9ac5cz8tARZT4QpY79TFkzDc="
},
"is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
"integrity": "sha1-8Rb4Bk/pCz94RKOJl8C3UFEmnx0="
},
"string-width": {
"version": "4.2.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/string-width/-/string-width-4.2.0.tgz",
"integrity": "sha1-lSGCxGzHssMT0VluYjmSvRY7crU=",
"requires": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.0"
},
"dependencies": {
"strip-ansi": {
"version": "6.0.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/strip-ansi/-/strip-ansi-6.0.0.tgz",
"integrity": "sha1-CxVx3XZpzNTz4G4U7x7tJiJa5TI=",
"requires": {
"ansi-regex": "^5.0.0"
}
}
}
},
"strip-ansi": {
"version": "5.2.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/strip-ansi/-/strip-ansi-5.2.0.tgz",
"integrity": "sha1-jJpTb+tq/JYr36WxBKUJHBrZwK4=",
"requires": {
"ansi-regex": "^4.1.0"
},
"dependencies": {
"ansi-regex": {
"version": "4.1.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/ansi-regex/-/ansi-regex-4.1.0.tgz",
"integrity": "sha1-i5+PCM8ay4Q3Vqg5yox+MWjFGZc="
}
}
}
}
},
"is-arrayish": { "is-arrayish": {
"version": "0.2.1", "version": "0.2.1",
"resolved": "http://39.106.145.141:9000/repository/node-public/is-arrayish/-/is-arrayish-0.2.1.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/is-arrayish/-/is-arrayish-0.2.1.tgz",
...@@ -1023,6 +1168,11 @@ ...@@ -1023,6 +1168,11 @@
"path-is-inside": "^1.0.1" "path-is-inside": "^1.0.1"
} }
}, },
"is-promise": {
"version": "2.1.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/is-promise/-/is-promise-2.1.0.tgz",
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o="
},
"is-redirect": { "is-redirect": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/is-redirect/-/is-redirect-1.0.0.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/is-redirect/-/is-redirect-1.0.0.tgz",
...@@ -1110,8 +1260,7 @@ ...@@ -1110,8 +1260,7 @@
"lodash": { "lodash": {
"version": "4.17.15", "version": "4.17.15",
"resolved": "http://39.106.145.141:9000/repository/node-public/lodash/-/lodash-4.17.15.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg=", "integrity": "sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg="
"dev": true
}, },
"log-symbols": { "log-symbols": {
"version": "2.2.0", "version": "2.2.0",
...@@ -1430,6 +1579,11 @@ ...@@ -1430,6 +1579,11 @@
} }
} }
}, },
"os-tmpdir": {
"version": "1.0.2",
"resolved": "http://39.106.145.141:9000/repository/node-public/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ="
},
"p-finally": { "p-finally": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "http://39.106.145.141:9000/repository/node-public/p-finally/-/p-finally-2.0.1.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/p-finally/-/p-finally-2.0.1.tgz",
...@@ -1750,11 +1904,18 @@ ...@@ -1750,11 +1904,18 @@
"signal-exit": "^3.0.2" "signal-exit": "^3.0.2"
} }
}, },
"run-async": {
"version": "2.3.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/run-async/-/run-async-2.3.0.tgz",
"integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=",
"requires": {
"is-promise": "^2.1.0"
}
},
"rxjs": { "rxjs": {
"version": "6.5.3", "version": "6.5.3",
"resolved": "http://39.106.145.141:9000/repository/node-public/rxjs/-/rxjs-6.5.3.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/rxjs/-/rxjs-6.5.3.tgz",
"integrity": "sha1-UQ4mMX9NuRp+sd532d2boKSJmjo=", "integrity": "sha1-UQ4mMX9NuRp+sd532d2boKSJmjo=",
"dev": true,
"requires": { "requires": {
"tslib": "^1.9.0" "tslib": "^1.9.0"
} }
...@@ -1765,6 +1926,11 @@ ...@@ -1765,6 +1926,11 @@
"integrity": "sha1-t02uxJsRSPiMZLaNSbHoFcHy9Rk=", "integrity": "sha1-t02uxJsRSPiMZLaNSbHoFcHy9Rk=",
"dev": true "dev": true
}, },
"safer-buffer": {
"version": "2.1.2",
"resolved": "http://39.106.145.141:9000/repository/node-public/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha1-RPoWGwGHuVSd2Eu5GAL5vYOFzWo="
},
"semver": { "semver": {
"version": "5.7.1", "version": "5.7.1",
"resolved": "http://39.106.145.141:9000/repository/node-public/semver/-/semver-5.7.1.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/semver/-/semver-5.7.1.tgz",
...@@ -2012,12 +2178,25 @@ ...@@ -2012,12 +2178,25 @@
} }
} }
}, },
"through": {
"version": "2.3.8",
"resolved": "http://39.106.145.141:9000/repository/node-public/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
},
"timed-out": { "timed-out": {
"version": "4.0.1", "version": "4.0.1",
"resolved": "http://39.106.145.141:9000/repository/node-public/timed-out/-/timed-out-4.0.1.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/timed-out/-/timed-out-4.0.1.tgz",
"integrity": "sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=", "integrity": "sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=",
"dev": true "dev": true
}, },
"tmp": {
"version": "0.0.33",
"resolved": "http://39.106.145.141:9000/repository/node-public/tmp/-/tmp-0.0.33.tgz",
"integrity": "sha1-bTQzWIl2jSGyvNoKonfO07G/rfk=",
"requires": {
"os-tmpdir": "~1.0.2"
}
},
"to-regex-range": { "to-regex-range": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "http://39.106.145.141:9000/repository/node-public/to-regex-range/-/to-regex-range-5.0.1.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/to-regex-range/-/to-regex-range-5.0.1.tgz",
...@@ -2072,8 +2251,12 @@ ...@@ -2072,8 +2251,12 @@
"tslib": { "tslib": {
"version": "1.10.0", "version": "1.10.0",
"resolved": "http://39.106.145.141:9000/repository/node-public/tslib/-/tslib-1.10.0.tgz", "resolved": "http://39.106.145.141:9000/repository/node-public/tslib/-/tslib-1.10.0.tgz",
"integrity": "sha1-w8GflZc/sKYpc/sJ2Q2WHuQ+XIo=", "integrity": "sha1-w8GflZc/sKYpc/sJ2Q2WHuQ+XIo="
"dev": true },
"type-fest": {
"version": "0.8.1",
"resolved": "http://39.106.145.141:9000/repository/node-public/type-fest/-/type-fest-0.8.1.tgz",
"integrity": "sha1-CeJJ696FHTseSNJ8EFREZn8XuD0="
}, },
"type-name": { "type-name": {
"version": "2.0.2", "version": "2.0.2",
......
{ {
"name": "qj-vue-cli", "name": "qj-cli",
"version": "0.1.0", "version": "0.1.0",
"description": "qj-vue-cli", "description": "qj-vue-cli",
"main": "index.js", "main": "index.js",
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
"watch-bin": "nodemon dist/bin/index.js create vue2.0 hello", "watch-bin": "nodemon dist/bin/index.js create vue2.0 hello",
"dev": "concurrently \"npm run watch-ts\" \"npm run watch-bin\"", "dev": "concurrently \"npm run watch-ts\" \"npm run watch-bin\"",
"build": "tsc", "build": "tsc",
"dev-link": "npm run build && npm unlink && npm link", "test-ts": "mocha -r ts-node/register src/test/**/*.test.ts",
"test": "mocha -r ts-node/register src/test/**/*.test.ts" "test": "mocha dist/test/**/*.test.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
"@types/commander": "^2.12.2", "@types/commander": "^2.12.2",
"@types/cross-spawn": "^6.0.1", "@types/cross-spawn": "^6.0.1",
"@types/fs-extra": "^8.0.1", "@types/fs-extra": "^8.0.1",
"@types/inquirer": "^6.5.0",
"@types/mocha": "^5.2.7", "@types/mocha": "^5.2.7",
"@types/node": "^12.12.17", "@types/node": "^12.12.17",
"@types/power-assert": "^1.5.2", "@types/power-assert": "^1.5.2",
...@@ -45,6 +46,7 @@ ...@@ -45,6 +46,7 @@
"cross-spawn": "^7.0.1", "cross-spawn": "^7.0.1",
"execa": "^3.4.0", "execa": "^3.4.0",
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",
"inquirer": "^7.0.1",
"ora": "^4.0.3" "ora": "^4.0.3"
} }
} }
...@@ -6,7 +6,7 @@ import { create } from '../lib/create' ...@@ -6,7 +6,7 @@ import { create } from '../lib/create'
// 版本号 // 版本号
program program
.version(`${require('../../package.json').version}`) .version(`${require('../../package.json').version}`)
.name('world') .name('qj-cli')
.usage('<command> [options]'); .usage('<command> [options]');
// create command // create command
program program
......
import * as ora from 'ora' import * as ora from 'ora'
import { Git } from '../util/Git' import { Git } from '../util/Git'
import { Templates, Template } from '../config/template.config' import { Templates, Template } from '../config/template.config'
import * as inquirer from 'inquirer'
import * as chalk from 'chalk';
/** /**
* @date 2019.12.18 * @date 2019.12.18
* @author panyanan * @author panyanan
...@@ -18,16 +20,40 @@ export class CreateVue2 { ...@@ -18,16 +20,40 @@ export class CreateVue2 {
this.projectName = projectName; this.projectName = projectName;
this.targetDir = targetDir; this.targetDir = targetDir;
} }
create(options: any): void{ /**
* @date 2019.12.19
* @author panyanan
* @information 创建
* @param { Object } commander中设置的option
*/
public async create(options: any): Promise<void>{
try { try {
const spinner = ora('create new a project'); let spinner = ora('create new a project');
spinner.start(); spinner.start(`拉取${this.template.name}模板`);
const git = new Git(this.template.repo, this.targetDir); // 通过仓库地址和输出目录创建git实例
git.pull(); const pullGit = new Git(this.template.repo, this.targetDir);
spinner.stop(); pullGit.pull();
spinner.succeed('clone succeed'); spinner.succeed('拉取模板成功');
// 是否推送到gitLab
let answer = await inquirer.prompt([
{ name: 'push', type: 'confirm', message: '是否将项目推送到gitlab',}
]);
// 如果推送
if (answer.push) {
const { repo } = await inquirer.prompt([
{ name: 'repo', type: 'input', message: '请输入gitlab项目地址:'}
]);
const pushGit = new Git(repo, this.targetDir);
try {
spinner.start(`正在推送到gitlab: ${repo}`)
pushGit.push();
spinner.succeed('推送成功')
} catch (error) {
spinner.fail(`推送失败: ${error.message}`);
}
}
} catch (error) { } catch (error) {
console.error(error); console.log(`${chalk.red('创建失败')}: ${error.message}`);
} }
} }
} }
\ No newline at end of file
...@@ -42,11 +42,11 @@ export class Git { ...@@ -42,11 +42,11 @@ export class Git {
cwd: this.dir, cwd: this.dir,
} }
// remove origin // remove origin
spawn.sync('git', ['remote', 'remove', 'origin',], options); spawn.sync('git', ['remote', 'remove', 'origin'], options);
// set origin 为当前url // set origin 为当前url
spawn.sync('git', ['remote', 'add', 'origin', this.gitURL], options); spawn.sync('git', ['remote', 'add', 'origin', this.gitURL], options);
// 推送 // 推送
const { status, stderr } = spawn.sync('git', ['push', '-u', 'origin', '--all'], options); const { status, stderr, stdout } = spawn.sync('git', ['push', '-u', 'origin', '--all'], options);
// status 为0时命令执行成功, 为1是命令执行失败 // status 为0时命令执行成功, 为1是命令执行失败
if (status === 0) { if (status === 0) {
res = true; res = true;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论