Skip to content

Commit a44e933

Browse files
committed
feat: 0.0.7 add vue and react template
1 parent 979aeda commit a44e933

File tree

3 files changed

+119
-87
lines changed

3 files changed

+119
-87
lines changed

bin/ebuild-init.js

Lines changed: 117 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -8,114 +8,146 @@ const progress = require('log-progress')
88
const fs = require('fs')
99
const chalk = require('chalk')
1010

11-
const gitUrl = {
12-
'def': 'github:theajack/ebuild-template-light',
13-
'css': 'github:theajack/ebuild-template-css',
14-
'origin': 'github:theajack/ebuild-template',
15-
'ts': 'github:theajack/ts-demo',
11+
const gits = {
12+
'def': {
13+
url: 'github:theajack/ebuild-template-light',
14+
renderPackage: true,
15+
renderBuild: true,
16+
name: 'light (Recommended, only pure js + webpack + babel)',
17+
},
18+
'css': {
19+
url: 'github:theajack/ebuild-template-css',
20+
renderPackage: true,
21+
renderBuild: true,
22+
name: 'css (With css and less)',
23+
},
24+
'ts': {
25+
url: 'github:theajack/ts-demo',
26+
renderPackage: false,
27+
renderBuild: true,
28+
name: 'typescript (With typescript)',
29+
},
30+
'vue': {
31+
url: 'github:theajack/ebuild-template-vue',
32+
renderPackage: true,
33+
renderBuild: true,
34+
name: 'vue (vue2.x + vue-router + react)',
35+
},
36+
'react-ts': {
37+
url: 'github:theajack/react-ts',
38+
renderPackage: false,
39+
renderBuild: false,
40+
name: 'react (react17 + typescript)',
41+
},
42+
'origin': {
43+
url: 'github:theajack/ebuild-template',
44+
renderPackage: true,
45+
renderBuild: false,
46+
name: 'origin (Old version. Not recommended)',
47+
},
1648
}
49+
50+
const choices = []
51+
52+
for(let k in gits){
53+
choices.push({
54+
name: gits[k].name,
55+
value: k
56+
})
57+
}
58+
1759
const log = require('../lib/log')
1860
const {formatName} = require('../lib/util')
19-
let date = new Date()
61+
let date = new Date()
2062

21-
/**
63+
/**
2264
* Settings.
2365
*/
2466

2567
function main() {
26-
program.usage('<name>')
27-
28-
program.on('--help', () => {
29-
log.n(' Examples:')
30-
log.n()
31-
log.n(chalk.gray(' # create a new project with an official template'))
32-
log.n(' $ ebuild init <project-name>')
33-
log.n()
34-
log.n()
35-
})
68+
program.usage('<name>')
3669

70+
program.on('--help', () => {
71+
log.n(' Examples:')
72+
log.n()
73+
log.n(chalk.gray(' # create a new project with an official template'))
74+
log.n(' $ ebuild init <project-name>')
75+
log.n()
3776
log.n()
77+
})
3878

39-
program.parse(process.argv)
79+
log.n()
4080

41-
if (program.args.length < 1) {
42-
return program.help()
43-
} else {
44-
init(program.args[0])
45-
}
81+
program.parse(process.argv)
82+
83+
if (program.args.length < 1) {
84+
return program.help()
85+
} else {
86+
init(program.args[0])
87+
}
4688
}
4789

4890
function start() {
49-
progress.start({
50-
title: 'Downloading ebuild template.',
51-
ontick: function(value, percent) {
52-
if (percent > 90) {
53-
this.pause(value)
54-
}
55-
},
56-
time: 100,
57-
total: 199
58-
})
91+
progress.start({
92+
title: 'Downloading ebuild template.',
93+
ontick: function(value, percent) {
94+
if (percent > 90) {
95+
this.pause(value)
96+
}
97+
},
98+
time: 100,
99+
total: 199
100+
})
59101
}
60102

61103
function init(name) {
62-
inquirer
63-
.prompt([
64-
{
65-
type: 'input',
66-
name: 'name',
67-
default: name,
68-
message: 'Input project name'
69-
},
70-
{
71-
type: 'input',
72-
name: 'description',
73-
default: 'Ebuild project',
74-
message: 'Input description'
75-
},
76-
{
77-
type: 'input',
78-
name: 'author',
79-
default: 'author',
80-
message: 'Input author name'
81-
},
82-
{
83-
type: 'list',
84-
name: 'mode',
85-
message: 'Choice mode',
86-
choices: [{
87-
name: 'default (Recommended)',
88-
value: 'def'
89-
},{
90-
name: 'css (With css and less)',
91-
value: 'css'
92-
},{
93-
name: 'typescript',
94-
value: 'ts'
95-
},{
96-
name: 'origin (Old version)',
97-
value: 'origin'
98-
}]
99-
}
100-
])
101-
.then(answers => {
102-
answers.libName = formatName(answers.name);
103-
downloadProject(answers)
104-
})
104+
inquirer
105+
.prompt([
106+
{
107+
type: 'input',
108+
name: 'name',
109+
default: name,
110+
message: 'Input project name'
111+
},
112+
{
113+
type: 'input',
114+
name: 'description',
115+
default: 'Ebuild project',
116+
message: 'Input description'
117+
},
118+
{
119+
type: 'input',
120+
name: 'author',
121+
default: 'author',
122+
message: 'Input author name'
123+
},
124+
{
125+
type: 'list',
126+
name: 'mode',
127+
message: 'Choice mode',
128+
choices
129+
}
130+
])
131+
.then(answers => {
132+
answers.libName = formatName(answers.name);
133+
downloadProject(answers)
134+
})
105135
}
106136

107137
function downloadProject(answers) {
108138
log.n()
109139
start()
110-
let url = gitUrl[answers.mode]
111-
download(url, answers.name, err => {
140+
let object = gits[answers.mode]
141+
download(object.url, answers.name, err => {
112142
if (progress.isPause()) {
113143
progress.start()
114144
}
115-
116-
render('package.json', answers);
117145

118-
if(answers.mode !== 'origin'){
146+
if(object.renderPackage){
147+
render('package.json', answers);
148+
}
149+
150+
if(object.renderBuild){
119151
render('webpack-config/build.js', answers);
120152
}
121153

@@ -133,10 +165,10 @@ function downloadProject(answers) {
133165
}
134166

135167
function render(file, answers){
136-
const fileName = answers.name + '/' + file
137-
const content = fs.readFileSync(fileName).toString()
138-
const result = handlebars.compile(content)(answers)
139-
fs.writeFileSync(fileName, result)
168+
const fileName = answers.name + '/' + file
169+
const content = fs.readFileSync(fileName).toString()
170+
const result = handlebars.compile(content)(answers)
171+
fs.writeFileSync(fileName, result)
140172
}
141173

142174
main()

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ebuild-cli",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "A project for build a project easily",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)