@mpxjs/cli 3.4.9 → 3.4.11
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/lib/create.js +33 -1
- package/lib/createRn.js +37 -7
- package/package.json +1 -1
package/lib/create.js
CHANGED
|
@@ -7,8 +7,11 @@ const {
|
|
|
7
7
|
exit,
|
|
8
8
|
error,
|
|
9
9
|
log,
|
|
10
|
-
stopSpinner
|
|
10
|
+
stopSpinner,
|
|
11
|
+
hasYarn,
|
|
12
|
+
hasPnpm3OrLater
|
|
11
13
|
} = require('@vue/cli-shared-utils')
|
|
14
|
+
const { loadOptions } = require('@vue/cli/lib/options')
|
|
12
15
|
const Creator = require('@vue/cli/lib/Creator')
|
|
13
16
|
const loadRemotePreset = require('@vue/cli/lib/util/loadRemotePreset')
|
|
14
17
|
const loadLocalPreset = require('@vue/cli/lib/util/loadLocalPreset')
|
|
@@ -176,6 +179,35 @@ async function create (projectName, options, preset = null) {
|
|
|
176
179
|
|
|
177
180
|
const creator = new Creator(name, targetDir, getPromptModules())
|
|
178
181
|
|
|
182
|
+
const packageManager =
|
|
183
|
+
options.packageManager ||
|
|
184
|
+
loadOptions().packageManager ||
|
|
185
|
+
(hasYarn() ? 'yarn' : null) ||
|
|
186
|
+
(hasPnpm3OrLater() ? 'pnpm' : 'npm')
|
|
187
|
+
|
|
188
|
+
// @achrinza/node-ipc与node23不兼容,需要映射到修复包node-ipc-compat@1.0.0
|
|
189
|
+
creator.on('creation', ({ event }) => {
|
|
190
|
+
if (event === 'plugins-install' || event === 'deps-install') {
|
|
191
|
+
try {
|
|
192
|
+
const pkgPath = path.resolve(targetDir, 'package.json')
|
|
193
|
+
const pkg = fs.readJsonSync(pkgPath)
|
|
194
|
+
// 根据包管理器类型写入对应的 overrides 配置,yarn无需处理
|
|
195
|
+
if (packageManager === 'pnpm') {
|
|
196
|
+
pkg.pnpm = {
|
|
197
|
+
overrides: {
|
|
198
|
+
'@achrinza/node-ipc': 'npm:node-ipc-compat@1.0.0'
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} else if (packageManager === 'npm') {
|
|
202
|
+
pkg.overrides = {
|
|
203
|
+
'@achrinza/node-ipc': 'npm:node-ipc-compat@1.0.0'
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
fs.writeJsonSync(pkgPath, pkg, { spaces: 2 })
|
|
207
|
+
} catch (e) {}
|
|
208
|
+
}
|
|
209
|
+
})
|
|
210
|
+
|
|
179
211
|
if (process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG) {
|
|
180
212
|
// 单测下,link bin文件到源码
|
|
181
213
|
const { linkBin } = require('@vue/cli/lib/util/linkBin')
|
package/lib/createRn.js
CHANGED
|
@@ -20,13 +20,36 @@ const RN_DEP = {
|
|
|
20
20
|
'react-native-haptic-feedback': '^2.3.3',
|
|
21
21
|
'react-native-linear-gradient': '^2.8.3',
|
|
22
22
|
'react-native-reanimated': '3.16.7',
|
|
23
|
-
'react-native-screens': '
|
|
23
|
+
'react-native-screens': '~4.18.0',
|
|
24
24
|
'react-native-webview': '^13.13.2',
|
|
25
25
|
'react-native-safe-area-context': '^4.10.9',
|
|
26
26
|
react: '18.3.1',
|
|
27
27
|
'react-native': '0.77.2'
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
const RN_SCRIPTS = {
|
|
31
|
+
'bundle:ios': 'react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ./ios/main.jsbundle --assets-dest ./ios',
|
|
32
|
+
'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/'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function updateJsonFile (filePath, updater) {
|
|
36
|
+
const config = require(filePath)
|
|
37
|
+
updater(config)
|
|
38
|
+
fs.writeFileSync(filePath, JSON.stringify(config, null, 2))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function updateJsModule (filePath, updater) {
|
|
42
|
+
const config = require(filePath)
|
|
43
|
+
updater(config)
|
|
44
|
+
fs.writeFileSync(filePath, `module.exports = ${JSON.stringify(config, null, 2)};`)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function addArrayItem (arr, item) {
|
|
48
|
+
if (!arr.includes(item)) {
|
|
49
|
+
arr.push(item)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
30
53
|
async function createRnProject (targetDir, options) {
|
|
31
54
|
const rnProjectPath = path.resolve(targetDir, 'ReactNativeProject')
|
|
32
55
|
const packageManager =
|
|
@@ -56,14 +79,21 @@ async function createRnProject (targetDir, options) {
|
|
|
56
79
|
],
|
|
57
80
|
{ stdio: 'inherit', cwd: targetDir }
|
|
58
81
|
)
|
|
82
|
+
|
|
59
83
|
const pkgPath = path.resolve(targetDir, 'ReactNativeProject', 'package.json')
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
'bundle:ios': 'react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ./ios/main.jsbundle --assets-dest ./ios',
|
|
64
|
-
'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/'
|
|
84
|
+
updateJsonFile(pkgPath, pkg => {
|
|
85
|
+
Object.assign(pkg.dependencies, RN_DEP)
|
|
86
|
+
Object.assign(pkg.scripts, RN_SCRIPTS)
|
|
65
87
|
})
|
|
66
|
-
|
|
88
|
+
|
|
89
|
+
const babelConfigPath = path.resolve(targetDir, 'ReactNativeProject', 'babel.config.js')
|
|
90
|
+
updateJsModule(babelConfigPath, config => {
|
|
91
|
+
if (!config.plugins) {
|
|
92
|
+
config.plugins = []
|
|
93
|
+
}
|
|
94
|
+
addArrayItem(config.plugins, 'react-native-reanimated/plugin')
|
|
95
|
+
})
|
|
96
|
+
|
|
67
97
|
await pm.install()
|
|
68
98
|
}
|
|
69
99
|
|
package/package.json
CHANGED