create-vue 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/outfile.cjs +5700 -0
- package/package.json +42 -31
- package/template/base/.vscode/extensions.json +3 -0
- package/template/base/_gitignore +27 -0
- package/template/base/index.html +13 -0
- package/template/base/package.json +19 -0
- package/template/base/public/favicon.ico +0 -0
- package/template/base/vite.config.js +25 -0
- package/template/code/default/cypress/integration/example.spec.js +8 -0
- package/template/code/default/src/App.vue +83 -0
- package/template/code/default/src/assets/base.css +74 -0
- package/template/code/default/src/assets/logo.svg +1 -0
- package/template/code/default/src/components/HelloWorld.vue +44 -0
- package/template/code/default/src/components/TheWelcome.vue +86 -0
- package/template/code/default/src/components/WelcomeItem.vue +86 -0
- package/template/code/default/src/components/__tests__/HelloWorld.spec.js +13 -0
- package/template/code/default/src/components/icons/IconCommunity.vue +7 -0
- package/template/code/default/src/components/icons/IconDocumentation.vue +7 -0
- package/template/code/default/src/components/icons/IconEcosystem.vue +7 -0
- package/template/code/default/src/components/icons/IconSupport.vue +7 -0
- package/template/code/default/src/components/icons/IconTooling.vue +19 -0
- package/template/code/router/cypress/integration/example.spec.js +13 -0
- package/template/code/router/src/App.vue +120 -0
- package/template/code/router/src/assets/base.css +74 -0
- package/template/code/router/src/assets/logo.svg +1 -0
- package/template/code/router/src/components/HelloWorld.vue +44 -0
- package/template/code/router/src/components/TheWelcome.vue +86 -0
- package/template/code/router/src/components/WelcomeItem.vue +86 -0
- package/template/code/router/src/components/__tests__/HelloWorld.spec.js +13 -0
- package/template/code/router/src/components/icons/IconCommunity.vue +7 -0
- package/template/code/router/src/components/icons/IconDocumentation.vue +7 -0
- package/template/code/router/src/components/icons/IconEcosystem.vue +7 -0
- package/template/code/router/src/components/icons/IconSupport.vue +7 -0
- package/template/code/router/src/components/icons/IconTooling.vue +19 -0
- package/template/code/router/src/router/index.js +27 -0
- package/template/code/router/src/views/AboutView.vue +15 -0
- package/template/code/router/src/views/HomeView.vue +9 -0
- package/template/code/typescript-default/cypress/integration/example.spec.ts +8 -0
- package/template/code/typescript-default/src/App.vue +83 -0
- package/template/code/typescript-default/src/assets/base.css +74 -0
- package/template/code/typescript-default/src/assets/logo.svg +1 -0
- package/template/code/typescript-default/src/components/HelloWorld.vue +41 -0
- package/template/code/typescript-default/src/components/TheWelcome.vue +86 -0
- package/template/code/typescript-default/src/components/WelcomeItem.vue +86 -0
- package/template/code/typescript-default/src/components/__tests__/HelloWorld.spec.ts +13 -0
- package/template/code/typescript-default/src/components/icons/IconCommunity.vue +7 -0
- package/template/code/typescript-default/src/components/icons/IconDocumentation.vue +7 -0
- package/template/code/typescript-default/src/components/icons/IconEcosystem.vue +7 -0
- package/template/code/typescript-default/src/components/icons/IconSupport.vue +7 -0
- package/template/code/typescript-default/src/components/icons/IconTooling.vue +19 -0
- package/template/code/typescript-router/cypress/integration/example.spec.ts +13 -0
- package/template/code/typescript-router/src/App.vue +120 -0
- package/template/code/typescript-router/src/assets/base.css +74 -0
- package/template/code/typescript-router/src/assets/logo.svg +1 -0
- package/template/code/typescript-router/src/components/HelloWorld.vue +41 -0
- package/template/code/typescript-router/src/components/TheWelcome.vue +86 -0
- package/template/code/typescript-router/src/components/WelcomeItem.vue +86 -0
- package/template/code/typescript-router/src/components/__tests__/HelloWorld.spec.ts +13 -0
- package/template/code/typescript-router/src/components/icons/IconCommunity.vue +7 -0
- package/template/code/typescript-router/src/components/icons/IconDocumentation.vue +7 -0
- package/template/code/typescript-router/src/components/icons/IconEcosystem.vue +7 -0
- package/template/code/typescript-router/src/components/icons/IconSupport.vue +7 -0
- package/template/code/typescript-router/src/components/icons/IconTooling.vue +19 -0
- package/template/code/typescript-router/src/router/index.ts +27 -0
- package/template/code/typescript-router/src/views/AboutView.vue +15 -0
- package/template/code/typescript-router/src/views/HomeView.vue +9 -0
- package/template/config/cypress/cypress/fixtures/example.json +5 -0
- package/template/config/cypress/cypress/jsconfig.json +8 -0
- package/template/config/cypress/cypress/plugins/index.js +28 -0
- package/template/config/cypress/cypress/support/commands.js +25 -0
- package/template/config/cypress/cypress/support/index.js +20 -0
- package/template/config/cypress/cypress.json +7 -0
- package/template/config/cypress/package.json +14 -0
- package/template/config/pinia/package.json +5 -0
- package/template/config/pinia/src/stores/counter.js +16 -0
- package/template/config/router/package.json +5 -0
- package/template/config/typescript/env.d.ts +16 -0
- package/template/config/typescript/package.json +11 -0
- package/template/config/typescript/tsconfig.json +24 -0
- package/template/entry/default/src/main.js +12 -0
- package/template/entry/pinia/src/main.js +15 -0
- package/template/entry/router/src/main.js +14 -0
- package/template/entry/router-and-pinia/src/main.js +17 -0
- package/src/config/index.js +0 -33
- package/src/main.js +0 -270
- package/src/render.js +0 -30
- package/yarn.lock +0 -1011
package/src/main.js
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const program = require('commander');
|
|
3
|
-
const inquirer = require('inquirer');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const fse = require('fs-extra');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const download = require('download-git-repo');
|
|
8
|
-
const ora = require('ora');
|
|
9
|
-
const rm = require('rimraf').sync;
|
|
10
|
-
const pack = require('../package.json');
|
|
11
|
-
const config = require('./config/index');
|
|
12
|
-
const renderTemplate = require('./render');
|
|
13
|
-
const { exec, cd } = require('shelljs');
|
|
14
|
-
|
|
15
|
-
inquirer.registerPrompt('chalk-pipe', require('inquirer-chalk-pipe'));
|
|
16
|
-
|
|
17
|
-
program
|
|
18
|
-
.version(pack.version);
|
|
19
|
-
|
|
20
|
-
program
|
|
21
|
-
.command('init')
|
|
22
|
-
.description('创建项目')
|
|
23
|
-
.action(async (fileName) => {
|
|
24
|
-
// 选项
|
|
25
|
-
let options = {
|
|
26
|
-
router: false
|
|
27
|
-
};
|
|
28
|
-
// 项目目录
|
|
29
|
-
let projectPath = path.join(process.cwd(), fileName);
|
|
30
|
-
// 组织需要过滤的文件或目录
|
|
31
|
-
let filterFiles = [];
|
|
32
|
-
if (typeof fileName !== 'string') {
|
|
33
|
-
console.log('文件夹名称不能为空 => demo: create-vue init projectName');
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
await downloadTemplate();
|
|
38
|
-
|
|
39
|
-
// 判断文件夹是否存在
|
|
40
|
-
await isExistence(fileName);
|
|
41
|
-
|
|
42
|
-
// 项目名称
|
|
43
|
-
Object.assign(options, await prompt({
|
|
44
|
-
type: 'input',
|
|
45
|
-
message: '项目名称:',
|
|
46
|
-
default: fileName,
|
|
47
|
-
name: 'name'
|
|
48
|
-
}));
|
|
49
|
-
|
|
50
|
-
// 项目介绍
|
|
51
|
-
Object.assign(options, await prompt({
|
|
52
|
-
type: 'input',
|
|
53
|
-
message: '项目介绍:',
|
|
54
|
-
name: 'description'
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
// 作者
|
|
58
|
-
Object.assign(options, await prompt({
|
|
59
|
-
type: 'input',
|
|
60
|
-
message: '作者:',
|
|
61
|
-
name: 'author'
|
|
62
|
-
}));
|
|
63
|
-
|
|
64
|
-
// 单页 or 多页
|
|
65
|
-
let data = await prompt({
|
|
66
|
-
type: 'list',
|
|
67
|
-
name: 'type',
|
|
68
|
-
message: '请选择多页或单页模式:',
|
|
69
|
-
choices: ['单页', '多页']
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
Object.assign(options, {
|
|
73
|
-
type: data.type === '单页'
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
// 公用模块提取方式
|
|
77
|
-
Object.assign(options, await prompt({
|
|
78
|
-
type: 'list',
|
|
79
|
-
name: 'extractingType',
|
|
80
|
-
message: '公用模块提取方式:',
|
|
81
|
-
choices: ['commonsChunkPlugin', 'dll']
|
|
82
|
-
}));
|
|
83
|
-
|
|
84
|
-
// css预处理
|
|
85
|
-
Object.assign(options, await prompt({
|
|
86
|
-
type: 'list',
|
|
87
|
-
name: 'cssPretreatment',
|
|
88
|
-
message: '请选择css预处理:',
|
|
89
|
-
choices: ['sass', 'less', 'stylus', '不使用']
|
|
90
|
-
}));
|
|
91
|
-
|
|
92
|
-
// 是否开启eslint
|
|
93
|
-
try {
|
|
94
|
-
await prompt({
|
|
95
|
-
type: 'confirm',
|
|
96
|
-
message: '是否开启 eslint (js代码检测) ?',
|
|
97
|
-
name: 'eslint'
|
|
98
|
-
});
|
|
99
|
-
options.eslint = true;
|
|
100
|
-
} catch (error) {
|
|
101
|
-
options.eslint = false;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// 是否开启stylelint
|
|
105
|
-
try {
|
|
106
|
-
await prompt({
|
|
107
|
-
type: 'confirm',
|
|
108
|
-
message: '是否开启 stylelint (css检测) ?',
|
|
109
|
-
name: 'stylelint'
|
|
110
|
-
});
|
|
111
|
-
options.stylelint = true;
|
|
112
|
-
} catch (error) {
|
|
113
|
-
options.stylelint = false;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// 单页才执行选择添加路由
|
|
117
|
-
if (options.type) {
|
|
118
|
-
// 是否集成vue-router
|
|
119
|
-
try {
|
|
120
|
-
await prompt({
|
|
121
|
-
type: 'confirm',
|
|
122
|
-
message: '是否集成vue-router ?',
|
|
123
|
-
name: 'router'
|
|
124
|
-
});
|
|
125
|
-
options.router = true;
|
|
126
|
-
} catch (error) {
|
|
127
|
-
options.router = false;
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// 渲染配置
|
|
132
|
-
console.log('开始渲染模板...');
|
|
133
|
-
await renderTemplate.render(options);
|
|
134
|
-
console.log('模板渲染完成...');
|
|
135
|
-
console.log('开始拷贝模板');
|
|
136
|
-
|
|
137
|
-
// 组织需要过滤的文件
|
|
138
|
-
// dll
|
|
139
|
-
if (options.extractingType === 'commonsChunkPlugin') filterFiles.push('webpack-dll-config.js');
|
|
140
|
-
|
|
141
|
-
// eslint
|
|
142
|
-
if (!options.eslint) filterFiles.push('/.eslintrc.js', '/.eslintignore');
|
|
143
|
-
|
|
144
|
-
// eslint
|
|
145
|
-
if (!options.stylelint) filterFiles.push('/stylelint.config.js');
|
|
146
|
-
|
|
147
|
-
// 单页不添加路由
|
|
148
|
-
if (!options.router && options.type) {
|
|
149
|
-
filterFiles.push('/src/views');
|
|
150
|
-
} else if (options.type) {
|
|
151
|
-
filterFiles.push('/src/views/index');
|
|
152
|
-
} else {
|
|
153
|
-
filterFiles.push('/src/index.html', '/src/main.js', '/src/app.vue', '/src/views/home.vue');
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// 路由
|
|
157
|
-
if (!options.router) filterFiles.push('/src/router');
|
|
158
|
-
|
|
159
|
-
await copyTemplate(config.templatePath, projectPath, filterFiles);
|
|
160
|
-
console.log('开始安装依赖包...');
|
|
161
|
-
// 执行npm install
|
|
162
|
-
cd(`./${fileName}`);
|
|
163
|
-
exec('npm install');
|
|
164
|
-
console.log('依赖安装完成');
|
|
165
|
-
console.log('开始启动服务...');
|
|
166
|
-
exec('npm run dev');
|
|
167
|
-
} catch (error) {
|
|
168
|
-
console.error(error);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
program.parse(process.argv);
|
|
173
|
-
|
|
174
|
-
// 文件夹是否存在
|
|
175
|
-
function isExistence(name) {
|
|
176
|
-
return new Promise(async (resolve, reject) => {
|
|
177
|
-
// 文件夹存在就询问是否继续
|
|
178
|
-
if (fs.existsSync(name)) {
|
|
179
|
-
try {
|
|
180
|
-
await prompt({
|
|
181
|
-
type: 'confirm',
|
|
182
|
-
message: '文件夹已经存在, 是否继续?',
|
|
183
|
-
name: 'state'
|
|
184
|
-
});
|
|
185
|
-
resolve();
|
|
186
|
-
} catch (error) {
|
|
187
|
-
reject('您已取消操作!');
|
|
188
|
-
}
|
|
189
|
-
} else {
|
|
190
|
-
resolve();
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function prompt(options) {
|
|
196
|
-
return new Promise((resolve, reject) => {
|
|
197
|
-
inquirer.prompt(options).then((data) => {
|
|
198
|
-
if (options.type === 'confirm') {
|
|
199
|
-
if (data[Object.keys(data)[0]]) {
|
|
200
|
-
resolve(data);
|
|
201
|
-
} else {
|
|
202
|
-
reject(data);
|
|
203
|
-
}
|
|
204
|
-
} else {
|
|
205
|
-
resolve(data);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// 文件下载
|
|
212
|
-
function downloadTemplate() {
|
|
213
|
-
return new Promise((resolve, reject) => {
|
|
214
|
-
// 如果文件夹存在则先删除
|
|
215
|
-
if (fs.existsSync(config.templatePath)) rm(config.templatePath);
|
|
216
|
-
// 下载文件
|
|
217
|
-
let spinner = ora('正在下载模板文件.....');
|
|
218
|
-
spinner.start();
|
|
219
|
-
download(config.templateDownloadPath, config.templatePath, (error, data) => {
|
|
220
|
-
spinner.stop();
|
|
221
|
-
if (error) {
|
|
222
|
-
console.log('模板下载失败');
|
|
223
|
-
reject(error);
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
console.log('模板下载完成');
|
|
227
|
-
resolve();
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// 拷贝文件夹
|
|
233
|
-
function copyTemplate (src, dest, filterFiles) {
|
|
234
|
-
return new Promise((resolve, reject) => {
|
|
235
|
-
fse.copy(src, dest, { filter: filter })
|
|
236
|
-
.then(() => {
|
|
237
|
-
resolve();
|
|
238
|
-
})
|
|
239
|
-
.catch(err => {
|
|
240
|
-
reject('模板拷贝错误...', err);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
// 过滤
|
|
244
|
-
function filter (src, dest) {
|
|
245
|
-
let state = true;
|
|
246
|
-
src = src.replace(/\\/g, '\/');
|
|
247
|
-
for (let i = 0; i < filterFiles.length; i++) {
|
|
248
|
-
if (src.indexOf(filterFiles[i]) >= 0) {
|
|
249
|
-
state = false;
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return state;
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// 命令调用
|
|
259
|
-
function commandAsync (command) {
|
|
260
|
-
return new Promise((resolve, reject) => {
|
|
261
|
-
exec(command, (err, stdout, stderr) => {
|
|
262
|
-
console.log(123)
|
|
263
|
-
if (err) {
|
|
264
|
-
return reject('npm install失败, 请手执行npm install安装');
|
|
265
|
-
}
|
|
266
|
-
resolve();
|
|
267
|
-
})
|
|
268
|
-
})
|
|
269
|
-
}
|
|
270
|
-
|
package/src/render.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const ejs = require('ejs');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const config = require('./config/');
|
|
5
|
-
|
|
6
|
-
exports.render = function (data) {
|
|
7
|
-
return new Promise(async (resolve, reject) => {
|
|
8
|
-
// 列表
|
|
9
|
-
const tplList = config.templateList;
|
|
10
|
-
// 遍历
|
|
11
|
-
for (let i = 0; i < tplList.length; i++) {
|
|
12
|
-
const filePath = path.join(config.templatePath, tplList[i]);
|
|
13
|
-
let str = fs.readFileSync(filePath);
|
|
14
|
-
str = ejs.render(str.toString(), data);
|
|
15
|
-
// 写入
|
|
16
|
-
await writeFile(filePath, str, i);
|
|
17
|
-
}
|
|
18
|
-
resolve();
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// 写入
|
|
23
|
-
function writeFile (filePath, str, i) {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
fs.writeFile(filePath, str, (error, data) => {
|
|
26
|
-
if (error) reject('模板写入失败', error);
|
|
27
|
-
resolve();
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
}
|