@mpxjs/cli 3.4.0 → 3.4.2

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.
@@ -79,6 +79,31 @@ test('normal-nocross', async () => {
79
79
  expect(staticAliDir).toBe(false)
80
80
  })
81
81
 
82
+ test('test-eslint', async () => {
83
+ const cwd = path.resolve(__dirname, '../../test')
84
+ const name = 'test-normal-eslint'
85
+ await create(
86
+ name,
87
+ {
88
+ force: true,
89
+ git: false,
90
+ cwd
91
+ },
92
+ {
93
+ srcMode: 'wx',
94
+ appid: 'test',
95
+ description: 'test',
96
+ cross: true,
97
+ plugins: {},
98
+ useConfigFiles: true,
99
+ needEslint: true
100
+ }
101
+ )
102
+
103
+ const pkg = require(path.resolve(cwd, name, 'package.json'))
104
+ expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-eslint')
105
+ })
106
+
82
107
  test('test-ts', async () => {
83
108
  const cwd = path.resolve(__dirname, '../../test')
84
109
  const name = 'test-ts'
@@ -278,6 +303,7 @@ test('test-typescript', async () => {
278
303
  const pkg = require(path.resolve(cwd, name, 'package.json'))
279
304
  expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-typescript')
280
305
  })
306
+
281
307
  test('test-ssr', async () => {
282
308
  const cwd = path.resolve(__dirname, '../../test')
283
309
  const name = 'test-ssr'
@@ -302,3 +328,28 @@ test('test-ssr', async () => {
302
328
  const pkg = require(path.resolve(cwd, name, 'package.json'))
303
329
  expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-ssr')
304
330
  })
331
+
332
+ test('test-rn', async () => {
333
+ const cwd = path.resolve(__dirname, '../../test')
334
+ const name = 'test-rn'
335
+ await create(
336
+ name,
337
+ {
338
+ force: true,
339
+ git: false,
340
+ cwd
341
+ },
342
+ {
343
+ srcMode: 'wx',
344
+ appid: 'test',
345
+ description: 'test',
346
+ needRn: true,
347
+ cross: true,
348
+ plugins: {},
349
+ useConfigFiles: true
350
+ }
351
+ )
352
+
353
+ const pkg = require(path.resolve(cwd, name, 'package.json'))
354
+ expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx')
355
+ })
@@ -0,0 +1,31 @@
1
+ jest.mock('inquirer')
2
+ const path = require('path')
3
+ const create = require('@mpxjs/cli/lib/create')
4
+
5
+ test('test-theme', async () => {
6
+ const cwd = path.resolve(__dirname, '../../test')
7
+ const name = 'test-theme'
8
+ await create(
9
+ name,
10
+ {
11
+ force: true,
12
+ git: false,
13
+ cwd
14
+ },
15
+ {
16
+ srcMode: 'wx',
17
+ appid: 'test',
18
+ description: 'test',
19
+ cross: true,
20
+ plugins: {
21
+ '@mpxjs/vue-cli-plugin-mpx-theme': {
22
+ version: '2.1.4'
23
+ }
24
+ },
25
+ useConfigFiles: true
26
+ }
27
+ )
28
+
29
+ const pkg = require(path.resolve(cwd, name, 'package.json'))
30
+ expect(pkg.devDependencies).toHaveProperty('@mpxjs/vue-cli-plugin-mpx-theme')
31
+ })
package/lib/create.js CHANGED
@@ -17,6 +17,7 @@ const { clearConsole } = require('@vue/cli/lib/util/clearConsole')
17
17
  const merge = require('lodash.merge')
18
18
  const prompts = require('./prompts')
19
19
  const builtInPreset = require('./preset')
20
+ const { createRnProject } = require('./createRn')
20
21
 
21
22
  async function resolvePreset (args = {}) {
22
23
  const { p, preset, c, clone } = args
@@ -81,14 +82,10 @@ async function create (projectName, options, preset = null) {
81
82
  preset.cssPreprocessor = 'stylus'
82
83
 
83
84
  // mpx cli 插件
84
- preset.plugins = Object.assign(
85
- {},
86
- preset.plugins,
87
- builtInPreset.plugins
88
- )
85
+ preset.plugins = Object.assign({}, preset.plugins, builtInPreset.plugins)
89
86
 
90
87
  // 合并问答中的preset
91
- prompts.forEach(v => {
88
+ prompts.forEach((v) => {
92
89
  if (preset[v.name]) {
93
90
  merge(preset, v.preset)
94
91
  }
@@ -172,6 +169,7 @@ async function create (projectName, options, preset = null) {
172
169
  cloudFunc: preset.cloudFunc,
173
170
  cross: preset.cross,
174
171
  needSSR: preset.needSSR,
172
+ needRn: preset.needRn,
175
173
  name
176
174
  })
177
175
  })
@@ -196,6 +194,10 @@ async function create (projectName, options, preset = null) {
196
194
  preset: undefined,
197
195
  inlinePreset: JSON.stringify(preset)
198
196
  })
197
+
198
+ if (!process.env.VUE_CLI_TEST && preset.needRn) {
199
+ await createRnProject(targetDir, options)
200
+ }
199
201
  }
200
202
 
201
203
  module.exports = function (...args) {
@@ -0,0 +1,80 @@
1
+ const { hasYarn, hasPnpm3OrLater, execa } = require('@vue/cli-shared-utils')
2
+ const path = require('path')
3
+ const fs = require('fs-extra')
4
+ const { loadOptions } = require('@vue/cli/lib/options')
5
+ const PackageManager = require('@vue/cli/lib/util/ProjectPackageManager')
6
+
7
+ const RN_DEP = {
8
+ '@ant-design/icons-react-native': '^2.3.2',
9
+ '@ant-design/react-native': '^5.2.2',
10
+ '@react-native-async-storage/async-storage': '^1.24.0',
11
+ '@react-native-clipboard/clipboard': '^1.14.2',
12
+ '@react-native-community/netinfo': '^11.3.2',
13
+ '@react-native-masked-view/masked-view': '^0.3.1',
14
+ '@react-native/assets-registry': '^0.75.2',
15
+ '@react-native/gradle-plugin': '^0.75.2',
16
+ '@react-navigation/elements': '^1.3.31',
17
+ '@react-navigation/native': '^6.1.18',
18
+ '@react-navigation/native-stack': '^6.11.0',
19
+ expo: '^51.0.32',
20
+ 'expo-brightness': '~12.0.1',
21
+ 'expo-clipboard': '~6.0.3',
22
+ react: '18.3.1',
23
+ 'react-native': '0.75.2',
24
+ 'react-native-collapsible': '^1.6.1',
25
+ 'react-native-device-info': '^11.1.0',
26
+ 'react-native-gesture-handler': '^2.18.1',
27
+ 'react-native-get-location': '^5.0.0',
28
+ 'react-native-haptic-feedback': '^2.3.3',
29
+ 'react-native-linear-gradient': '^2.8.3',
30
+ 'react-native-maps': '^1.18.0',
31
+ 'react-native-modal-popover': '^2.1.3',
32
+ 'react-native-reanimated': '3.15.0',
33
+ 'react-native-root-siblings': '^5.0.1',
34
+ 'react-native-safe-area-context': '^4.10.9',
35
+ 'react-native-screens': '^3.34.0',
36
+ 'react-native-webview': '^13.12.1'
37
+ }
38
+
39
+ async function createRnProject (targetDir, options) {
40
+ const rnProjectPath = path.resolve(targetDir, 'ReactNativeProject')
41
+ const packageManager =
42
+ options.packageManager ||
43
+ loadOptions().packageManager ||
44
+ (hasYarn() ? 'yarn' : null) ||
45
+ (hasPnpm3OrLater() ? 'pnpm' : 'npm')
46
+ const pm = new PackageManager({
47
+ context: rnProjectPath,
48
+ forcePackageManager: packageManager
49
+ })
50
+ await execa(
51
+ 'npx',
52
+ [
53
+ '@react-native-community/cli',
54
+ 'init',
55
+ 'ReactNativeProject',
56
+ '--pm',
57
+ pm.bin,
58
+ '--skip-install',
59
+ true,
60
+ '--skip-git-init',
61
+ true
62
+ ],
63
+ { stdio: 'inherit', cwd: targetDir }
64
+ )
65
+ const pkgPath = path.resolve(targetDir, 'ReactNativeProject', 'package.json')
66
+ const pkg = require(pkgPath)
67
+ Object.assign(pkg.dependencies, RN_DEP)
68
+ Object.assign(pkg.scripts, {
69
+ 'bundle:ios': 'react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ./ios/main.jsbundle --assets-dest ./ios',
70
+ 'bundle:android': 'react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/'
71
+ })
72
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2))
73
+ await pm.install()
74
+ await execa('npx', ['install-expo-modules'], {
75
+ stdio: 'inherit',
76
+ cwd: rnProjectPath
77
+ })
78
+ }
79
+
80
+ module.exports.createRnProject = createRnProject
package/lib/preset.js CHANGED
@@ -9,9 +9,6 @@ module.exports = {
9
9
  },
10
10
  '@mpxjs/vue-cli-plugin-mpx': {
11
11
  version: '^2.0.0'
12
- },
13
- '@mpxjs/vue-cli-plugin-mpx-eslint': {
14
- version: '^2.0.0'
15
12
  }
16
13
  }
17
14
  }
package/lib/prompts.js CHANGED
@@ -17,8 +17,15 @@ module.exports = [
17
17
  default: true
18
18
  },
19
19
  {
20
- name: 'needSSR',
20
+ name: 'needRn',
21
21
  when: ({ srcMode }) => srcMode === 'wx',
22
+ message: '是否需要输出react-native',
23
+ type: 'confirm',
24
+ default: false
25
+ },
26
+ {
27
+ name: 'needSSR',
28
+ when: ({ srcMode, cross }) => srcMode === 'wx' && cross === true,
22
29
  message: '是否需要 web ssr',
23
30
  type: 'confirm',
24
31
  default: false,
@@ -59,6 +66,19 @@ module.exports = [
59
66
  }
60
67
  }
61
68
  },
69
+ {
70
+ name: 'needEslint',
71
+ type: 'confirm',
72
+ message: '是否需要eslint',
73
+ default: true,
74
+ preset: {
75
+ plugins: {
76
+ [`${prefix}-eslint`]: {
77
+ version: '^2.0.0'
78
+ }
79
+ }
80
+ }
81
+ },
62
82
  {
63
83
  name: 'needTs',
64
84
  type: 'confirm',
@@ -72,7 +92,6 @@ module.exports = [
72
92
  }
73
93
  }
74
94
  },
75
-
76
95
  {
77
96
  name: 'needUtilityFirstCSS',
78
97
  type: 'confirm',
package/package.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "dependencies": {
7
7
  "@types/inquirer": "^8.1.3",
8
8
  "@vue/cli": "^5.0.0",
9
+ "@vue/cli-shared-utils": "^5.0.4",
9
10
  "commander": "^7.1.0",
10
11
  "fs-extra": "^9.1.0",
11
12
  "inquirer": "^8.0.0",
@@ -29,5 +30,5 @@
29
30
  "access": "public",
30
31
  "registry": "https://registry.npmjs.org"
31
32
  },
32
- "version": "3.4.0"
33
+ "version": "3.4.2"
33
34
  }