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 = yield prompt('Template name: ')
|
16 | if(tplName == "" && tplJson.tpl[tplName] !== 'undefined') {
|
17 | console.log(chalk.red('Template name empty or already existed!'))
|
18 | process.exit()
|
19 | }
|
20 |
|
21 | let gitUrl = yield prompt('Repository address: ')
|
22 | if(gitUrl == "") {
|
23 | console.log(chalk.red('Repository address not empty!'))
|
24 | process.exit()
|
25 | }
|
26 |
|
27 | let branch = yield prompt('Branch(master): ')
|
28 |
|
29 | tplJson.tpl[tplName] = {}
|
30 | tplJson.tpl[tplName]['url'] = gitUrl.replace(/[\u0000-\u0019]/g, '')
|
31 | tplJson.tpl[tplName]['branch'] = branch || 'master'
|
32 |
|
33 |
|
34 | fs.writeFile(__dirname + '/../tpl.json', JSON.stringify(tplJson), 'utf-8', (err) => {
|
35 | if (err) console.log(err)
|
36 | console.log()
|
37 | console.log(chalk.green('New template added!\n'))
|
38 | console.log(chalk.grey('The last template list is: \n'))
|
39 | console.log(tplJson)
|
40 | console.log('\n')
|
41 | process.exit()
|
42 | })
|
43 | })
|
44 | }
|