@easyv/react-component-builder 0.22.2 → 0.22.3

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/utils/index.js +73 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/react-component-builder",
3
- "version": "0.22.2",
3
+ "version": "0.22.3",
4
4
  "files": [
5
5
  "launcher",
6
6
  "templates",
@@ -20,8 +20,8 @@
20
20
  "@babel/core": "7.9.0",
21
21
  "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
22
22
  "@babel/register": "^7.10.4",
23
- "@easyv/react-gui": "1.20.7",
24
- "@easyv/simulator": "0.6.1",
23
+ "@easyv/react-gui": "1.20.9",
24
+ "@easyv/simulator": "0.6.2",
25
25
  "@svgr/webpack": "8.1.0",
26
26
  "acorn": "^7.3.1",
27
27
  "acorn-jsx": "^5.2.0",
package/utils/index.js CHANGED
@@ -1,37 +1,38 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const chalk = require("chalk");
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const chalk = require('chalk');
4
+ const { appComponents } = require('../config/paths');
4
5
 
5
6
  // todo: 把这个替换掉
6
- require("@babel/register")({
7
- presets: [require.resolve("@babel/preset-env")],
7
+ require('@babel/register')({
8
+ presets: [require.resolve('@babel/preset-env')],
8
9
  });
9
10
 
10
11
  function getConfigContent(componentFolder) {
11
12
  let jsonFileExist = fs.existsSync(
12
- path.join(componentFolder, "config/main.json")
13
+ path.join(componentFolder, 'config/main.json'),
13
14
  );
14
15
  if (jsonFileExist) {
15
16
  return JSON.parse(
16
- fs.readFileSync(path.join(componentFolder, "config/main.json"), {
17
- encoding: "utf8",
18
- })
17
+ fs.readFileSync(path.join(componentFolder, 'config/main.json'), {
18
+ encoding: 'utf8',
19
+ }),
19
20
  );
20
21
  } else {
21
- return require(path.resolve(componentFolder, "config/main.js")).default;
22
+ return require(path.resolve(componentFolder, 'config/main.js')).default;
22
23
  }
23
24
  }
24
25
 
25
26
  function getDataContent(componentFolder) {
26
27
  let jsonFileExist = fs.existsSync(
27
- path.join(componentFolder, "config/main.data.json")
28
+ path.join(componentFolder, 'config/main.data.json'),
28
29
  );
29
30
  if (jsonFileExist) {
30
31
  return JSON.parse(
31
- fs.readFileSync(path.join(componentFolder, "config/main.data.json"))
32
+ fs.readFileSync(path.join(componentFolder, 'config/main.data.json')),
32
33
  );
33
34
  } else {
34
- return require(path.resolve(componentFolder, "config/main.data.js"))
35
+ return require(path.resolve(componentFolder, 'config/main.data.js'))
35
36
  .default;
36
37
  }
37
38
  }
@@ -47,33 +48,33 @@ module.exports.checkComponentFiles = function checkConfigs(folder) {
47
48
  }
48
49
 
49
50
  {
50
- const oldConfigs = ["js/config.js", "mocks/data.js"];
51
+ const oldConfigs = ['js/config.js', 'mocks/data.js'];
51
52
  const exists = oldConfigs.every((file) =>
52
- fs.existsSync(path.join(folder, file))
53
+ fs.existsSync(path.join(folder, file)),
53
54
  );
54
55
  if (exists) {
55
56
  // 垫一下变量名防止js访问变量空指针
56
57
  global.window = {
57
58
  appConfig: {},
58
- ASSETS_URL: "",
59
+ ASSETS_URL: '',
59
60
  };
60
- const base = require(path.resolve(folder, "js/config.js")).config.base;
61
+ const base = require(path.resolve(folder, 'js/config.js')).config.base;
61
62
  return { base };
62
63
  }
63
64
  }
64
65
 
65
- const newConfigs = ["config/main", "config/main.data"];
66
+ const newConfigs = ['config/main', 'config/main.data'];
66
67
  newConfigs.every((file) => {
67
68
  if (
68
69
  !(
69
- fs.existsSync(path.join(folder, file + ".js")) ||
70
- fs.existsSync(path.join(folder, file + ".json"))
70
+ fs.existsSync(path.join(folder, file + '.js')) ||
71
+ fs.existsSync(path.join(folder, file + '.json'))
71
72
  )
72
73
  ) {
73
74
  console.error(
74
75
  chalk.red(
75
- `${file}.js or ${file}.json cannot be found in folder ${folder}, if the folder is not a component folder please move it out.`
76
- )
76
+ `${file}.js or ${file}.json cannot be found in folder ${folder}, if the folder is not a component folder please move it out.`,
77
+ ),
77
78
  );
78
79
  process.exit();
79
80
  }
@@ -87,5 +88,55 @@ module.exports.checkComponentFiles = function checkConfigs(folder) {
87
88
  };
88
89
  };
89
90
 
91
+ function getComponentBase(name) {
92
+ const sourcePath = path.join(appComponents, name);
93
+ if (!fs.existsSync(sourcePath)) {
94
+ console.error(chalk.red(`cannot found folder ${sourcePath}.`));
95
+ process.exit();
96
+ }
97
+
98
+ //旧配置
99
+ if (
100
+ fs.existsSync(path.join(sourcePath, 'js/config.js')) &&
101
+ fs.existsSync(path.join(sourcePath, 'mocks/data.js'))
102
+ ) {
103
+ const base = require(path.resolve(sourcePath, 'js/config.js')).config.base;
104
+ return { base };
105
+ }
106
+
107
+ //新配置
108
+ const newConfigs = ['config/main', 'config/main.data'];
109
+ newConfigs.every((file) => {
110
+ if (
111
+ !(
112
+ fs.existsSync(path.join(sourcePath, file + '.js')) ||
113
+ fs.existsSync(path.join(sourcePath, file + '.json'))
114
+ )
115
+ ) {
116
+ console.error(
117
+ chalk.red(
118
+ `${file}.js or ${file}.json cannot be found in folder ${sourcePath}, if the folder is not a component folder please move it out.`,
119
+ ),
120
+ );
121
+ process.exit();
122
+ }
123
+ return true;
124
+ });
125
+
126
+ let base = {};
127
+ if (fs.existsSync(path.join(sourcePath, 'config/main.json'))) {
128
+ base = JSON.parse(
129
+ fs.readFileSync(path.join(sourcePath, 'config/main.json'), {
130
+ encoding: 'utf8',
131
+ }),
132
+ ).base;
133
+ } else {
134
+ base = require(path.resolve(sourcePath, 'config/main.js')).default.base;
135
+ }
136
+
137
+ return { base };
138
+ }
139
+
90
140
  module.exports.getConfigContent = getConfigContent;
91
141
  module.exports.getDataContent = getDataContent;
142
+ module.exports.getComponentBase = getComponentBase;