1 | 'use strict'
|
2 | const co = require('co')
|
3 | const prompt = require('co-prompt')
|
4 | const config = require('../templates')
|
5 | const chalk = require('chalk')
|
6 | const fs = require('fs')
|
7 |
|
8 | module.exports = () => {
|
9 | co(function *() {
|
10 |
|
11 |
|
12 | let tplName = yield prompt('Template name: ')
|
13 | let desc = yield prompt('desc: ')
|
14 | let gitUrl = yield prompt('Git https link: ')
|
15 | let branch = yield prompt('Branch: ')
|
16 |
|
17 |
|
18 |
|
19 | if (!config.tpl[tplName]) {
|
20 | config.tpl[tplName] = {}
|
21 | config.tpl[tplName]['url'] = gitUrl.replace(/[\u0000-\u0019]/g, '')
|
22 | config.tpl[tplName]['branch'] = branch
|
23 | config.tpl[tplName]['desc'] = desc
|
24 | } else {
|
25 | console.log(chalk.red('Template has already existed!'))
|
26 | process.exit()
|
27 | }
|
28 |
|
29 |
|
30 | fs.writeFile(__dirname + '/../templates.json', JSON.stringify(config), 'utf-8', (err) => {
|
31 | if (err) console.log(err)
|
32 | console.log(chalk.green('New template added!\n'))
|
33 | console.log(chalk.grey('The last template list is: \n'))
|
34 | console.log(config)
|
35 | console.log('\n')
|
36 | process.exit()
|
37 | })
|
38 | })
|
39 | }
|