@mpxjs/cli 3.3.3 → 3.4.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/__tests__/preset.spec.js +74 -0
- package/lib/create.js +19 -12
- package/lib/prompts.js +28 -0
- package/package.json +1 -1
package/__tests__/preset.spec.js
CHANGED
|
@@ -228,3 +228,77 @@ test('test-e2e', async () => {
|
|
|
228
228
|
const pkg = require(path.resolve(cwd, name, 'package.json'))
|
|
229
229
|
expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-e2e-test')
|
|
230
230
|
})
|
|
231
|
+
|
|
232
|
+
test('test-unocss', async () => {
|
|
233
|
+
const cwd = path.resolve(__dirname, '../../test')
|
|
234
|
+
const name = 'test-unocss'
|
|
235
|
+
await create(
|
|
236
|
+
name,
|
|
237
|
+
{
|
|
238
|
+
force: true,
|
|
239
|
+
git: false,
|
|
240
|
+
cwd
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
srcMode: 'wx',
|
|
244
|
+
appid: 'test',
|
|
245
|
+
description: 'test',
|
|
246
|
+
cross: true,
|
|
247
|
+
needUtilityFirstCSS: true,
|
|
248
|
+
plugins: {},
|
|
249
|
+
useConfigFiles: true
|
|
250
|
+
}
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
const pkg = require(path.resolve(cwd, name, 'package.json'))
|
|
254
|
+
expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-utility-first-css')
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
test('test-typescript', async () => {
|
|
258
|
+
const cwd = path.resolve(__dirname, '../../test')
|
|
259
|
+
const name = 'test-typescript'
|
|
260
|
+
await create(
|
|
261
|
+
name,
|
|
262
|
+
{
|
|
263
|
+
force: true,
|
|
264
|
+
git: false,
|
|
265
|
+
cwd
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
srcMode: 'wx',
|
|
269
|
+
appid: 'test',
|
|
270
|
+
description: 'test',
|
|
271
|
+
cross: true,
|
|
272
|
+
needTs: true,
|
|
273
|
+
plugins: {},
|
|
274
|
+
useConfigFiles: true
|
|
275
|
+
}
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
const pkg = require(path.resolve(cwd, name, 'package.json'))
|
|
279
|
+
expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-typescript')
|
|
280
|
+
})
|
|
281
|
+
test('test-ssr', async () => {
|
|
282
|
+
const cwd = path.resolve(__dirname, '../../test')
|
|
283
|
+
const name = 'test-ssr'
|
|
284
|
+
await create(
|
|
285
|
+
name,
|
|
286
|
+
{
|
|
287
|
+
force: true,
|
|
288
|
+
git: false,
|
|
289
|
+
cwd
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
srcMode: 'wx',
|
|
293
|
+
appid: 'test',
|
|
294
|
+
description: 'test',
|
|
295
|
+
cross: true,
|
|
296
|
+
needSSR: true,
|
|
297
|
+
plugins: {},
|
|
298
|
+
useConfigFiles: true
|
|
299
|
+
}
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
const pkg = require(path.resolve(cwd, name, 'package.json'))
|
|
303
|
+
expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-ssr')
|
|
304
|
+
})
|
package/lib/create.js
CHANGED
|
@@ -48,6 +48,21 @@ async function resolvePrompts () {
|
|
|
48
48
|
return inquirer.prompt(prompts).then((answers) => answers)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
async function mergePreset (preset, options) {
|
|
52
|
+
if (options.preset) {
|
|
53
|
+
const remotePreset = await resolvePreset(options)
|
|
54
|
+
merge(preset, remotePreset)
|
|
55
|
+
} else if (options.inlinePreset) {
|
|
56
|
+
try {
|
|
57
|
+
const inlinePreset = JSON.parse(options.inlinePreset)
|
|
58
|
+
merge(preset, inlinePreset)
|
|
59
|
+
} catch (error) {
|
|
60
|
+
error(`CLI inline preset is not valid JSON: ${options.inlinePreset}`)
|
|
61
|
+
exit(1)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return preset
|
|
65
|
+
}
|
|
51
66
|
/**
|
|
52
67
|
* 从vue-cli clone 下来,方便处理creator的创建以及生命周期管理
|
|
53
68
|
* @param {*} projectName
|
|
@@ -58,18 +73,9 @@ async function resolvePrompts () {
|
|
|
58
73
|
async function create (projectName, options, preset = null) {
|
|
59
74
|
// resolve preset
|
|
60
75
|
if (!preset) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
preset = JSON.parse(options.inlinePreset)
|
|
66
|
-
} catch (error) {
|
|
67
|
-
error(`CLI inline preset is not valid JSON: ${options.inlinePreset}`)
|
|
68
|
-
exit(1)
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
preset = await resolvePrompts()
|
|
72
|
-
}
|
|
76
|
+
// 默认回答
|
|
77
|
+
preset = await resolvePrompts()
|
|
78
|
+
await mergePreset(preset, options)
|
|
73
79
|
}
|
|
74
80
|
// css preprocessor
|
|
75
81
|
preset.cssPreprocessor = 'stylus'
|
|
@@ -165,6 +171,7 @@ async function create (projectName, options, preset = null) {
|
|
|
165
171
|
isPlugin: preset.isPlugin,
|
|
166
172
|
cloudFunc: preset.cloudFunc,
|
|
167
173
|
cross: preset.cross,
|
|
174
|
+
needSSR: preset.needSSR,
|
|
168
175
|
name
|
|
169
176
|
})
|
|
170
177
|
})
|
package/lib/prompts.js
CHANGED
|
@@ -16,6 +16,20 @@ module.exports = [
|
|
|
16
16
|
type: 'confirm',
|
|
17
17
|
default: true
|
|
18
18
|
},
|
|
19
|
+
{
|
|
20
|
+
name: 'needSSR',
|
|
21
|
+
when: ({ srcMode }) => srcMode === 'wx',
|
|
22
|
+
message: '是否需要 web ssr',
|
|
23
|
+
type: 'confirm',
|
|
24
|
+
default: false,
|
|
25
|
+
preset: {
|
|
26
|
+
plugins: {
|
|
27
|
+
[`${prefix}-ssr`]: {
|
|
28
|
+
version: '^2.0.0'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
19
33
|
{
|
|
20
34
|
name: 'cloudFunc',
|
|
21
35
|
when: ({ srcMode, cross }) => srcMode === 'wx' && cross === false,
|
|
@@ -58,6 +72,20 @@ module.exports = [
|
|
|
58
72
|
}
|
|
59
73
|
}
|
|
60
74
|
},
|
|
75
|
+
|
|
76
|
+
{
|
|
77
|
+
name: 'needUtilityFirstCSS',
|
|
78
|
+
type: 'confirm',
|
|
79
|
+
message: '是否需要使用原子类',
|
|
80
|
+
default: false,
|
|
81
|
+
preset: {
|
|
82
|
+
plugins: {
|
|
83
|
+
[`${prefix}-utility-first-css`]: {
|
|
84
|
+
version: '^2.0.0'
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
61
89
|
{
|
|
62
90
|
name: 'needUnitTest',
|
|
63
91
|
message: '是否需要单元测试',
|
package/package.json
CHANGED