This repository was archived by the owner on Feb 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathindex.js
executable file
·555 lines (526 loc) · 15.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
module.exports = (api, options, rootOptions) => {
// 是否需要 vite 作为开发调试工具
const isNeedVite = options['build-tools'];
// 小程序
if (options.preset === 'mini') {
api.extendPackage(
{
scripts: {
serve: null,
build: null
},
dependencies: {
vue: null
},
devDependencies: {
'@vue/cli-plugin-babel': null,
'vue-cli-plugin-qrcode': null,
'@vue/cli-service': null,
chalk: null,
'internal-ip': null,
less: null,
'less-loader': null,
'qrcode-terminal': null
}
},
{
prune: true
}
);
api.extendPackage({
name: 'miniprogram',
version: '1.0.0',
private: true,
description: 'mini program app',
templateInfo: {
name: 'taro-ui-vue',
typescript: true,
css: 'less'
},
scripts: {
'build:weapp': 'taro build --type weapp',
'build:swan': 'taro build --type swan',
'build:alipay': 'taro build --type alipay',
'build:tt': 'taro build --type tt',
'build:h5': 'taro build --type h5',
'build:rn': 'taro build --type rn',
'build:qq': 'taro build --type qq',
'build:jd': 'taro build --type jd',
'build:quickapp': 'taro build --type quickapp',
'dev:weapp': 'npm run build:weapp -- --watch',
'dev:swan': 'npm run build:swan -- --watch',
'dev:alipay': 'npm run build:alipay -- --watch',
'dev:tt': 'npm run build:tt -- --watch',
'dev:h5': 'npm run build:h5 -- --watch',
'dev:rn': 'npm run build:rn -- --watch',
'dev:qq': 'npm run build:qq -- --watch',
'dev:jd': 'npm run build:jd -- --watch',
'dev:quickapp': 'npm run build:quickapp -- --watch'
},
author: 'winner-fed',
dependencies: {
'@winner-fed/magicless': '*',
'@babel/runtime': '^7.7.7',
'@tarojs/cli': '3.3.15',
'@tarojs/components': '3.3.15',
'@tarojs/runtime': '3.3.15',
'@tarojs/taro': '3.3.15',
lodash: '4.17.15',
'vue-template-compiler': '^2.5.0',
vue: '^2.5.0',
'taro-ui-vue': '^1.0.0-alpha.5'
},
devDependencies: {
'@babel/core': '^7.8.0',
'@tarojs/mini-runner': '3.3.15',
'@tarojs/webpack-runner': '3.3.15',
'@types/webpack-env': '^1.13.6',
'babel-preset-taro': '3.3.15',
eslint: '^6.8.0',
'vue-loader': '^15.9.2',
'eslint-plugin-vue': '^7.x',
'eslint-config-taro': '3.1.4',
stylelint: '9.3.0',
'@typescript-eslint/parser': '^2.x',
'@typescript-eslint/eslint-plugin': '^2.x',
typescript: '^3.7.0'
}
});
// 删除 vue-cli3 默认目录
api.render((files) => {
Object.keys(files)
.filter((path) => path.startsWith('src/') || path.startsWith('public/'))
.forEach((path) => delete files[path]);
});
api.render('./miniprogram');
// 屏蔽 generator 之后的文件写入操作
// writeFileTree 函数不写文件直接退出,这样 vue-cli3 在写 README.md 时会直接跳过
api.onCreateComplete(() => {
process.env.VUE_CLI_SKIP_WRITE = true;
});
return;
}
// 版本控制工具
// svn or git
if (options['version-control'] === 'git') {
api.extendPackage({
scripts: {
'gen:log': 'conventional-changelog -p angular -i CHANGELOG.md -s -r 0',
'lint:ls-lint': 'ls-lint',
'lint:lint-staged': 'lint-staged -c ./.husky/lintstagedrc.js',
'install:husky': 'is-ci || husky install'
},
devDependencies: {
'@commitlint/cli': '^13.1.0',
'@commitlint/config-conventional': '^13.1.0',
'@ls-lint/ls-lint': '^1.9.2',
'commitizen': '^4.2.3',
'conventional-changelog-cli': '^2.1.1',
'husky': '^7.0.1',
'is-ci': '^2.0.0',
'lint-staged': '^10.5.4'
}
});
} else {
api.extendPackage({
devDependencies: {
'svn-info': '^1.1.0'
}
});
}
// 命令
api.extendPackage({
buildVersion: 'V202101-00-000',
scripts: {
bootstrap:
'yarn --registry https://registry.npm.taobao.org || npm install --registry https://registry.npm.taobao.org || cnpm install',
build: 'node build/index.js',
serve: 'vue-cli-service serve',
lint: 'vue-cli-service lint',
'lint:style': 'vue-cli-service lint:style',
prettier: 'prettier --write "src/**/*.{js,json,tsx,css,less,scss,vue,html,md}"',
report: 'vue-cli-service build --report',
deploy: 'npm run build && npm run zip',
inspect: 'vue inspect > output.js --verbose',
reinstall: 'rimraf node_modules && rimraf yarn.lock && rimraf package.lock.json && npm run bootstrap',
escheck: 'es-check',
zip: 'node build/zip.js',
postinstall: 'node ./tools/init.js'
},
'scripts-info': {
serve: '运行开发服务器',
build: '生产环境执行构建',
analyz: '生产环境执行构建打包分析',
deploy: '生产环境执行构建并压缩zip包',
'build:see': '生成 see 平台部署发布物',
escheck: '检测是否含有 ES6+ 语法'
}
});
// 公共依赖包
api.extendPackage({
dependencies: {
'@winner-fed/cloud-utils': '*',
'@winner-fed/magicless': '*',
axios: '^0.23.0',
'normalize.css': '8.0.1'
},
devDependencies: {
'@winner-fed/eslint-config-win': '^1.0.2',
'@vue/eslint-config-prettier': '^6.0.0',
'@winner-fed/stylelint-config-win': '^0.1.0',
'@winner-fed/vue-cli-plugin-eslint': '^1.0.2',
'@winner-fed/vue-cli-plugin-stylelint': '^1.0.2',
'add-asset-html-webpack-plugin': '^3.1.3',
archiver: '^3.0.0',
'babel-eslint': '^10.1.0',
chalk: '^2.4.1',
'compression-webpack-plugin': '^3.0.0',
'less-loader': '^7.3.0',
rimraf: '^3.0.2',
'es-check': '^5.2.3',
'eslint': '^7.24.0',
'eslint-plugin-vue': '^7.13.0',
prettier: '^2.4.1',
'script-ext-html-webpack-plugin': '^2.1.3',
shelljs: '^0.8.5',
stylelint: '^13.6.1',
tasksfile: '^5.1.0',
'webpack-manifest-plugin': '^3.0.0',
webpackbar: '^4.0.0'
}
});
if (options.language === 'ts') {
api.extendPackage({
dependencies: {
'register-service-worker': '1.7.2'
},
devDependencies: {
'@types/node': '^10.14.17',
'@types/webpack-env': '^1.14.0',
'@typescript-eslint/eslint-plugin': '^4.28.0',
'@typescript-eslint/parser': '^4.28.0',
'@vue/cli-plugin-pwa': '~4.5.0',
'@vue/cli-plugin-typescript': '~4.5.0',
'@vue/eslint-config-typescript': '^5.0.2',
typescript: '4.3.5'
}
});
}
// vue preset 版本
if (options.preset === 'v2') {
// vue2
if (isNeedVite) {
api.extendPackage({
scripts: {
dev: 'vite'
}
});
}
api.extendPackage({
dependencies: {
'vue-router': '3.5.1',
'vue-svgicon': '3.2.6'
}
});
api.extendPackage({
scripts: {
svg: 'vsvg -s ./src/icons/svg -t ./src/icons/components --ext js --es6'
}
});
if (options.language === 'ts') {
api.extendPackage({
dependencies: {
'vue-class-component': '7.2.6',
'vue-property-decorator': '9.1.2'
}
});
// vue2 ts
if (isNeedVite) {
api.extendPackage({
scripts: {
dev: 'tsc --noEmit && vite'
}
});
}
}
} else {
// v3
// vue3 不需要 vue-template-compiler
// 因此移除 vue2 及 vue-template-compiler
// 消除 warning
api.extendPackage(
{
dependencies: {
vue: null
},
devDependencies: {
'vue-template-compiler': null
}
},
{
prune: true
}
);
api.extendPackage({
dependencies: {
'@yzfe/svgicon': '1.0.1',
'@yzfe/vue3-svgicon': '1.0.1',
vue: '^3.2.31',
'vue-router': '^4.0.12'
},
devDependencies: {
'@vue/compiler-sfc': '^3.2.31',
'@winner-fed/svgicon-loader': '^1.0.0'
}
});
}
// postcss
// pc
api.extendPackage({
postcss: {
plugins: {
autoprefixer: {
overrideBrowserslist: [
'Android >= 5.0',
'iOS >= 9.0',
'Chrome > 43',
'ff > 34',
'ie >= 11'
]
}
}
}
});
// 支持see平台发布物
if (options['see-package']) {
api.extendPackage({
scripts: {
'build:see': 'npm run build && node build/package/see.js'
},
devDependencies: {
'@winner-fed/winner-deploy': '^3.0.0'
}
});
}
// 支持子应用功能
if (options['needs-subsystem']) {
api.extendPackage({
scripts: {
'child': 'node --max_old_space_size=4096 build/child/build.child.js',
'build:see:child': 'npm run child && node build/package/see.child.js'
},
'dependencies': {
'js-cookie': '^3.0.1'
},
devDependencies: {
'@winner-fed/winner-deploy': '^3.0.0',
'postcss-import': '11.1.0',
'postcss-loader': '2.1.6',
'postcss-url': '7.3.2',
'replace-in-file': '^6.2.0'
}
});
}
// application 应用类型为 mobile
if (options.application === 'mobile' || options.application === 'offline') {
api.extendPackage({
postcss: {
plugins: {
autoprefixer: {
overrideBrowserslist: [
'Android >= 5.0',
'iOS >= 9.0',
'Chrome > 43',
'ff > 34',
'ie >= 11'
]
}
}
}
});
// 移动端适配方案
if (options['layout-adapter'] === 'vw') {
api.extendPackage({
devDependencies: {
'postcss-px-to-viewport': '^1.1.1'
},
postcss: {
plugins: {
'postcss-px-to-viewport': {
unitToConvert: 'px', // 要转化的单位
viewportWidth: 375, // UI设计稿的宽度
unitPrecision: 6, // 转换后的精度,即小数点位数
propList: [
'height',
'line-height',
'width',
'padding*',
'margin*',
'top',
'left',
'right',
'bottom',
'border*'
], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
viewportUnit: 'vw', // 指定需要转换成的视窗单位,默认vw
fontViewportUnit: 'vw', // 指定字体需要转换成的视窗单位,默认vw
selectorBlackList: ['wrap', '.ignore-', '.hairlines'], // 指定不转换为视窗单位的类名,
minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
replace: true, // 是否转换后直接更换属性值
exclude: [/node_modules/], // 设置忽略文件,用正则做目录名匹配
landscape: false, // 是否处理横屏情况,是否添加根据 landscapeWidth 生成的媒体查询条件 @media (orientation: landscape)
landscapeUnit: 'vw', //横屏时使用的单位
landscapeWidth: 1134 //横屏时使用的视口宽度
}
}
}
});
} else {
api.extendPackage({
dependencies: {
'amfe-flexible': '2.2.1'
},
devDependencies: {
'postcss-pxtorem': '^4.0.1'
},
postcss: {
plugins: {
'postcss-pxtorem': {
rootValue: 37.5,
unitPrecision: 2,
propList: [
'height',
'line-height',
'width',
'padding',
'margin',
'top',
'left',
'right',
'bottom'
],
selectorBlackList: [],
replace: true,
mediaQuery: false,
minPixelValue: 1
}
}
}
});
}
}
// application 应用类型为 H5离线包
if (options.application === 'offline') {
api.extendPackage({
dependencies: {
'light-sdk': '^2.0.4',
'@winner-fed/native-bridge-methods': '*'
}
});
}
// 是否需要 vite
if (isNeedVite) {
api.extendPackage({
devDependencies: {
vite: '^2.8.2',
'unplugin-vue-components': '^0.17.18',
'vite-plugin-html': '^3.0.6',
'vite-plugin-style-import': '^2.0.0',
'vite-plugin-vue2': '^1.9.3'
}
});
}
// 删除 vue-cli3 默认目录
api.render((files) => {
Object.keys(files)
.filter((path) => path.startsWith('src/') || path.startsWith('public/'))
.forEach((path) => delete files[path]);
});
if (options['ui-framework'] === 'element-ui') {
require('./element.js')(api, options);
} else if (options['ui-framework'] === 'iview') {
require('./iview.js')(api, options);
} else if (options['ui-framework'] === 'ant') {
require('./ant.js')(api, options);
} else if (options['ui-framework'] === 'hui') {
require('./hui.js')(api, options);
} else if (options['mobile-ui-framework'] === 'vant') {
require('./vant.js')(api, options);
} else if (options['mobile-ui-framework'] === 'wui') {
require('./wui.js')(api, options);
}
// 创建模板
// 基础模板
api.render('./template-base', options);
if (options.preset === 'v2') {
if (options.language === 'js') {
if (isNeedVite) {
api.render('./template-vue2-vite');
} else {
api.render('./template-vue2');
}
} else {
api.render('./template-vue2-ts');
}
} else {
if (options.language === 'js') {
api.render('./template-vue3');
} else {
api.render('./template-vue3-ts');
}
}
// 支持子应用功能
if (options['needs-subsystem']) {
api.render('./subsystem', options);
}
api.postProcessFiles((files) => {
Object.keys(files).forEach((name) => {
// 只有离线包才有这个文件
if (options.application !== 'offline') {
delete files['offlinePackage.json'];
}
// 版本控制工具 git
if (options['version-control'] !== 'git') {
if (/^\.husky[/$]/.test(name)) {
delete files[name];
}
delete files['.ls-lint.yml'];
delete files['commitlint.config.js'];
}
// 是否为公司内部项目
if (!options['mirror-source']) {
delete files['.npmrc'];
delete files['.yarnrc'];
}
// 是否支持see平台发布物
if (!options['mirror-source'] || !options['see-package']) {
// 删除 build/package 文件夹
if (/^build\/package[/$]/.test(name)) {
delete files[name];
}
}
// PC项目
if (options['application'] === 'pc') {
delete files['public/console.js'];
delete files['public/vconsole.min.js'];
}
// vite
if (isNeedVite) {
delete files['public/index.html'];
} else {
delete files['index.html'];
delete files['vite.config.js'];
}
// v3
if (options.preset === 'v3') {
delete files['vite.config.js'];
}
});
});
// 屏蔽 generator 之后的文件写入操作
// writeFileTree 函数不写文件直接退出,这样 vue-cli3 在写 README.md 时会直接跳过
api.onCreateComplete(() => {
process.env.VUE_CLI_SKIP_WRITE = true;
});
};