@htyf-mp/cli 0.1.2 → 0.2.0-alpha.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.
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@htyf-mp/cli",
3
- "version": "0.1.2",
3
+ "version": "0.2.0-alpha.2",
4
4
  "description": "红糖云服app小程序模板-cli",
5
5
  "type": "module",
6
- "bin": "cli.js",
6
+ "bin": "src/index.mjs",
7
7
  "scripts": {
8
+ "start": "node src/index.mjs",
8
9
  "test": "echo \"Error: no test specified\" && exit 1"
9
10
  },
10
11
  "keywords": [
@@ -20,14 +21,31 @@
20
21
  "url": "https://github.com/htyf-mp-community/htyf-mp.git"
21
22
  },
22
23
  "dependencies": {
23
- "@inquirer/prompts": "^3.1.1",
24
- "chalk": "^5.3.0",
25
- "cli-spinners": "^2.9.0",
26
- "commander": "^11.0.0",
27
- "execa": "^8.0.1",
28
- "fs-extra": "^11.2.0",
24
+ "@callstack/repack": "^5.1.3",
25
+ "@callstack/repack-plugin-expo-modules": "^5.1.3",
26
+ "@callstack/repack-plugin-reanimated": "^5.1.3",
27
+ "@inquirer/prompts": "^7.8.0",
28
+ "@inquirer/select": "^4.3.1",
29
+ "adm-zip": "0.5.10",
30
+ "boxen": "^8.0.1",
31
+ "chalk": "^5.4.1",
32
+ "execa": "^9.6.0",
33
+ "fs-extra": "^11.3.0",
34
+ "gradient-string": "^3.0.0",
35
+ "inquirer": "^12.9.0",
36
+ "lodash": "^4.17.21",
29
37
  "md5": "^2.3.0",
30
- "ora": "^7.0.1",
31
- "uuid": "^9.0.1"
38
+ "ora": "^8.2.0",
39
+ "portfinder": "^1.0.37",
40
+ "qrcode": "^1.5.4",
41
+ "react-native-reanimated": "4.0.1",
42
+ "react-native-worklets": "^0.4.1",
43
+ "shelljs": "^0.10.0",
44
+ "superstatic": "^9.2.0",
45
+ "systeminformation": "^5.27.7",
46
+ "terser-webpack-plugin": "^5.3.14",
47
+ "uuid": "^9.0.1",
48
+ "webpack": "^5.101.0",
49
+ "webpack-cli": "^6.0.1"
32
50
  }
33
51
  }
@@ -0,0 +1,105 @@
1
+
2
+ import path from 'path';
3
+ import fse from 'fs-extra'
4
+ import { fileURLToPath } from 'url'
5
+
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
7
+ const sharedPkg = fse.readJSONSync(path.join(__dirname, './shared-output.json'))
8
+
9
+ function trimTemplateStrings(strings, ...values) {
10
+ let fullString = strings.reduce((acc, str, i) => acc + str + (values[i] || ''), '');
11
+ return fullString.replace(/^[ \t]+/gm, '');
12
+ }
13
+
14
+ export class HtyfModulesPlugin {
15
+ constructor(appConfig) {
16
+ this.config = appConfig;
17
+ }
18
+ apply(compiler) {
19
+ const config = this.config;
20
+ compiler.hooks.emit.tapAsync('AnalyzeThirdPartyModulesPlugin', (compilation, callback) => {
21
+ let thirdPartyModules = new Set();
22
+
23
+ compilation.modules.forEach(module => {
24
+ if (module.context && module.context.includes('node_modules')) {
25
+ let packageName = module.context.split('node_modules/')[1].split('/')[0];
26
+ if (packageName.startsWith('@')) {
27
+ packageName = module.context.split('node_modules/')[1].split('/').splice(0,2).join('/');
28
+ }
29
+ const ios_path = path.join(__dirname, '../node_modules/', packageName, 'ios');
30
+ const and_path = path.join(__dirname, '../node_modules/', packageName, 'android');
31
+ const isNative = fse.pathExistsSync(ios_path) || fse.pathExistsSync(and_path);
32
+ if (isNative) {
33
+ thirdPartyModules.add(packageName);
34
+ }
35
+ }
36
+ });
37
+ const nonsupport = []
38
+ thirdPartyModules = Array.from(thirdPartyModules);
39
+ for (const key in thirdPartyModules) {
40
+ const pkg = thirdPartyModules[key];
41
+ if (!sharedPkg[pkg]) {
42
+ if (
43
+ pkg !== 'expo-splash-screen' &&
44
+ pkg !== '@callstack/repack' &&
45
+ pkg !== 'react-native-iap'
46
+ ) {
47
+ nonsupport.push(pkg)
48
+ }
49
+ }
50
+ }
51
+ if (nonsupport.length) {
52
+ const msgArr = ['红糖云服暂不支持以上第三方native组件']
53
+ console.log(' ')
54
+ console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
55
+ console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
56
+ console.log(' ')
57
+ console.log('红糖云服暂不支持以下第三方native组件: ')
58
+ for (const key in nonsupport) {
59
+ const element = nonsupport[key];
60
+ const _msg = `${Number(key) + 1}. ${element}`;
61
+ console.log(_msg)
62
+ msgArr.push(_msg)
63
+ }
64
+ console.log(' ')
65
+ console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
66
+ console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
67
+ console.log(' ')
68
+ console.log(' ')
69
+ callback(msgArr.join(`\n`));
70
+ process.exit(1);
71
+ } else {
72
+ callback();
73
+ }
74
+ });
75
+ if (config.codeSigning) {
76
+ compiler.hooks.emit.tapAsync('WrapCodePlugin', (compilation, callback) => {
77
+ // 遍历所有编译过的资源文件
78
+ for (const filename in compilation.assets) {
79
+ if (compilation.assets.hasOwnProperty(filename)) {
80
+ // 获取文件内容
81
+ let source = compilation.assets[filename].source();
82
+
83
+ // 包裹代码
84
+ const wrappedSource = trimTemplateStrings`
85
+ try {
86
+ ${source}
87
+ } catch (error) {
88
+ const that = globalThis || global || self || window;
89
+ that.__htyf_error_callback__ && that.__htyf_error_callback__(error, that)
90
+ console.error(error)
91
+ }
92
+ `;
93
+
94
+ // 更新文件内容
95
+ compilation.assets[filename] = {
96
+ source: () => wrappedSource,
97
+ size: () => wrappedSource.length
98
+ };
99
+ }
100
+ }
101
+ callback();
102
+ });
103
+ }
104
+ }
105
+ }
@@ -0,0 +1,10 @@
1
+ module.exports = api => {
2
+ api.cache(false);
3
+ return {
4
+ presets: ['module:@react-native/babel-preset'],
5
+ plugins: [
6
+ 'react-native-worklets/plugin'
7
+ ],
8
+ comments: true,
9
+ };
10
+ };