1 | 'use strict'
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const co = require('co')
|
7 | const prompt = require('co-prompt')
|
8 | const chalk = require('chalk')
|
9 | const tplJson = require('../tpl')
|
10 | const fs = require('fs')
|
11 |
|
12 | module.exports = () => {
|
13 | co(function *() {
|
14 |
|
15 | let tplName = process.argv[3]
|
16 |
|
17 | if(!tplName) {
|
18 | tplName = yield prompt('Template name: ')
|
19 | if (!tplName) {
|
20 | console.log(chalk.red('Template name not empty!'))
|
21 | process.exit()
|
22 | }
|
23 | }
|
24 |
|
25 | if (!tplJson.tpl[tplName]) {
|
26 | console.log(chalk.red('Template name not existed!'))
|
27 | process.exit()
|
28 | }
|
29 |
|
30 | let gitUrl = yield prompt('Repository address: ')
|
31 | if(gitUrl == "") {
|
32 | console.log(chalk.red('Repository address not empty!'))
|
33 | process.exit()
|
34 | }
|
35 |
|
36 | let branch = yield prompt('Branch(master): ')
|
37 |
|
38 | tplJson.tpl[tplName]['url'] = gitUrl.replace(/[\u0000-\u0019]/g, '')
|
39 | tplJson.tpl[tplName]['branch'] = branch || 'master'
|
40 |
|
41 |
|
42 | fs.writeFile(__dirname + '/../tpl.json', JSON.stringify(tplJson), 'utf-8', (err) => {
|
43 | if (err) console.log(err)
|
44 | console.log()
|
45 | console.log(chalk.green('New template added!\n'))
|
46 | console.log(chalk.grey('The last template list is: \n'))
|
47 | console.log(tplJson)
|
48 | console.log('\n')
|
49 | process.exit()
|
50 | })
|
51 | })
|
52 | }
|