@easyv/react-component-builder 0.19.3 → 0.19.5-beta.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.
@@ -1,21 +1,21 @@
1
- let notAtomConfigTypes = ['array', 'object', 'group', 'colors', 'menu', 'modal', 'rangeColor'];
2
- export function reduceConfig(config) {
3
- if (!Array.isArray(config)) {
4
- return config;
5
- }
6
- return config.reduce((result, item) => {
7
- result[item.name] = item.type && !notAtomConfigTypes.includes(item.type) ? item.value : reduceConfig(item.value);
8
- return result;
9
- }, {});
10
- }
11
-
12
- // 用于解析3.15之前的老版本带下划线的配置
13
- export function reduceConfigWithUndeline(config) {
14
- if (!Array.isArray(config)) {
15
- return config;
16
- }
17
- return config.reduce((result, item) => {
18
- result[item._name] = item._type && !notAtomConfigTypes.includes(item._type) ? item._value : reduceConfigWithUndeline(item._value);
19
- return result;
20
- }, {});
1
+ let notAtomConfigTypes = ['array', 'object', 'group', 'colors', 'menu', 'modal', 'rangeColor'];
2
+ export function reduceConfig(config) {
3
+ if (!Array.isArray(config)) {
4
+ return config;
5
+ }
6
+ return config.reduce((result, item) => {
7
+ result[item.name] = item.type && !notAtomConfigTypes.includes(item.type) ? item.value : reduceConfig(item.value);
8
+ return result;
9
+ }, {});
10
+ }
11
+
12
+ // 用于解析3.15之前的老版本带下划线的配置
13
+ export function reduceConfigWithUndeline(config) {
14
+ if (!Array.isArray(config)) {
15
+ return config;
16
+ }
17
+ return config.reduce((result, item) => {
18
+ result[item._name] = item._type && !notAtomConfigTypes.includes(item._type) ? item._value : reduceConfigWithUndeline(item._value);
19
+ return result;
20
+ }, {});
21
21
  }
@@ -1,12 +1,12 @@
1
- const http = require('http');
2
-
3
- const HOST = '0.0.0.0';
4
- module.exports = function autoAssignPort(port, callback) {
5
- var server = http.createServer();
6
- server.listen(port, HOST, function (err) {
7
- server.close(() => callback(port));
8
- });
9
- server.on('error', function (err) {
10
- autoAssignPort(port + 1, callback);
11
- });
1
+ const http = require('http');
2
+
3
+ const HOST = '0.0.0.0';
4
+ module.exports = function autoAssignPort(port, callback) {
5
+ var server = http.createServer();
6
+ server.listen(port, HOST, function (err) {
7
+ server.close(() => callback(port));
8
+ });
9
+ server.on('error', function (err) {
10
+ autoAssignPort(port + 1, callback);
11
+ });
12
12
  }
package/utils/index.js CHANGED
@@ -1,91 +1,91 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const chalk = require("chalk");
4
-
5
- // todo: 把这个替换掉
6
- require("@babel/register")({
7
- presets: [require.resolve("@babel/preset-env")],
8
- });
9
-
10
- function getConfigContent(componentFolder) {
11
- let jsonFileExist = fs.existsSync(
12
- path.join(componentFolder, "config/main.json")
13
- );
14
- if (jsonFileExist) {
15
- return JSON.parse(
16
- fs.readFileSync(path.join(componentFolder, "config/main.json"), {
17
- encoding: "utf8",
18
- })
19
- );
20
- } else {
21
- return require(path.resolve(componentFolder, "config/main.js")).default;
22
- }
23
- }
24
-
25
- function getDataContent(componentFolder) {
26
- let jsonFileExist = fs.existsSync(
27
- path.join(componentFolder, "config/main.data.json")
28
- );
29
- if (jsonFileExist) {
30
- return JSON.parse(
31
- fs.readFileSync(path.join(componentFolder, "config/main.data.json"))
32
- );
33
- } else {
34
- return require(path.resolve(componentFolder, "config/main.data.js"))
35
- .default;
36
- }
37
- }
38
-
39
- /**
40
- * 检查组件配置文件
41
- * @param {*} folder
42
- */
43
- module.exports.checkComponentFiles = function checkConfigs(folder) {
44
- if (!fs.existsSync(path.join(folder))) {
45
- console.error(chalk.red(`cannot found folder ${folder}.`));
46
- process.exit();
47
- }
48
-
49
- {
50
- const oldConfigs = ["js/config.js", "mocks/data.js"];
51
- const exists = oldConfigs.every((file) =>
52
- fs.existsSync(path.join(folder, file))
53
- );
54
- if (exists) {
55
- // 垫一下变量名防止js访问变量空指针
56
- global.window = {
57
- appConfig: {},
58
- ASSETS_URL: "",
59
- };
60
- const base = require(path.resolve(folder, "js/config.js")).config.base;
61
- return { base };
62
- }
63
- }
64
-
65
- const newConfigs = ["config/main", "config/main.data"];
66
- newConfigs.every((file) => {
67
- if (
68
- !(
69
- fs.existsSync(path.join(folder, file + ".js")) ||
70
- fs.existsSync(path.join(folder, file + ".json"))
71
- )
72
- ) {
73
- console.error(
74
- 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
- )
77
- );
78
- process.exit();
79
- }
80
- return true;
81
- });
82
-
83
- const base = getConfigContent(folder).base;
84
-
85
- return {
86
- base,
87
- };
88
- };
89
-
90
- module.exports.getConfigContent = getConfigContent;
91
- module.exports.getDataContent = getDataContent;
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const chalk = require("chalk");
4
+
5
+ // todo: 把这个替换掉
6
+ require("@babel/register")({
7
+ presets: [require.resolve("@babel/preset-env")],
8
+ });
9
+
10
+ function getConfigContent(componentFolder) {
11
+ let jsonFileExist = fs.existsSync(
12
+ path.join(componentFolder, "config/main.json")
13
+ );
14
+ if (jsonFileExist) {
15
+ return JSON.parse(
16
+ fs.readFileSync(path.join(componentFolder, "config/main.json"), {
17
+ encoding: "utf8",
18
+ })
19
+ );
20
+ } else {
21
+ return require(path.resolve(componentFolder, "config/main.js")).default;
22
+ }
23
+ }
24
+
25
+ function getDataContent(componentFolder) {
26
+ let jsonFileExist = fs.existsSync(
27
+ path.join(componentFolder, "config/main.data.json")
28
+ );
29
+ if (jsonFileExist) {
30
+ return JSON.parse(
31
+ fs.readFileSync(path.join(componentFolder, "config/main.data.json"))
32
+ );
33
+ } else {
34
+ return require(path.resolve(componentFolder, "config/main.data.js"))
35
+ .default;
36
+ }
37
+ }
38
+
39
+ /**
40
+ * 检查组件配置文件
41
+ * @param {*} folder
42
+ */
43
+ module.exports.checkComponentFiles = function checkConfigs(folder) {
44
+ if (!fs.existsSync(path.join(folder))) {
45
+ console.error(chalk.red(`cannot found folder ${folder}.`));
46
+ process.exit();
47
+ }
48
+
49
+ {
50
+ const oldConfigs = ["js/config.js", "mocks/data.js"];
51
+ const exists = oldConfigs.every((file) =>
52
+ fs.existsSync(path.join(folder, file))
53
+ );
54
+ if (exists) {
55
+ // 垫一下变量名防止js访问变量空指针
56
+ global.window = {
57
+ appConfig: {},
58
+ ASSETS_URL: "",
59
+ };
60
+ const base = require(path.resolve(folder, "js/config.js")).config.base;
61
+ return { base };
62
+ }
63
+ }
64
+
65
+ const newConfigs = ["config/main", "config/main.data"];
66
+ newConfigs.every((file) => {
67
+ if (
68
+ !(
69
+ fs.existsSync(path.join(folder, file + ".js")) ||
70
+ fs.existsSync(path.join(folder, file + ".json"))
71
+ )
72
+ ) {
73
+ console.error(
74
+ 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
+ )
77
+ );
78
+ process.exit();
79
+ }
80
+ return true;
81
+ });
82
+
83
+ const base = getConfigContent(folder).base;
84
+
85
+ return {
86
+ base,
87
+ };
88
+ };
89
+
90
+ module.exports.getConfigContent = getConfigContent;
91
+ module.exports.getDataContent = getDataContent;
@@ -1,153 +1,153 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- 'use strict';
9
-
10
- var chalk = require('chalk');
11
- var execSync = require('child_process').execSync;
12
- var spawn = require('cross-spawn');
13
- var open = require('open');
14
-
15
- // https://github.com/sindresorhus/open#app
16
- var OSX_CHROME = 'google chrome';
17
-
18
- const Actions = Object.freeze({
19
- NONE: 0,
20
- BROWSER: 1,
21
- SCRIPT: 2,
22
- });
23
-
24
- function getBrowserEnv() {
25
- // Attempt to honor this environment variable.
26
- // It is specific to the operating system.
27
- // See https://github.com/sindresorhus/open#app for documentation.
28
- const value = process.env.BROWSER;
29
- const args = process.env.BROWSER_ARGS
30
- ? process.env.BROWSER_ARGS.split(' ')
31
- : [];
32
- let action;
33
- if (!value) {
34
- // Default.
35
- action = Actions.BROWSER;
36
- } else if (value.toLowerCase().endsWith('.js')) {
37
- action = Actions.SCRIPT;
38
- } else if (value.toLowerCase() === 'none') {
39
- action = Actions.NONE;
40
- } else {
41
- action = Actions.BROWSER;
42
- }
43
- return { action, value, args };
44
- }
45
-
46
- function executeNodeScript(scriptPath, url) {
47
- const extraArgs = process.argv.slice(2);
48
- const child = spawn('node', [scriptPath, ...extraArgs, url], {
49
- stdio: 'inherit',
50
- });
51
- child.on('close', code => {
52
- if (code !== 0) {
53
- console.log();
54
- console.log(
55
- chalk.red(
56
- 'The script specified as BROWSER environment variable failed.'
57
- )
58
- );
59
- console.log(chalk.cyan(scriptPath) + ' exited with code ' + code + '.');
60
- console.log();
61
- return;
62
- }
63
- });
64
- return true;
65
- }
66
-
67
- function startBrowserProcess(browser, url, args) {
68
- // If we're on OS X, the user hasn't specifically
69
- // requested a different browser, we can try opening
70
- // Chrome with AppleScript. This lets us reuse an
71
- // existing tab when possible instead of creating a new one.
72
- const shouldTryOpenChromiumWithAppleScript =
73
- process.platform === 'darwin' &&
74
- (typeof browser !== 'string' || browser === OSX_CHROME);
75
-
76
- if (shouldTryOpenChromiumWithAppleScript) {
77
- // Will use the first open browser found from list
78
- const supportedChromiumBrowsers = [
79
- 'Google Chrome Canary',
80
- 'Google Chrome',
81
- 'Microsoft Edge',
82
- 'Brave Browser',
83
- 'Vivaldi',
84
- 'Chromium',
85
- ];
86
-
87
- for (let chromiumBrowser of supportedChromiumBrowsers) {
88
- try {
89
- // Try our best to reuse existing tab
90
- // on OSX Chromium-based browser with AppleScript
91
- execSync('ps cax | grep "' + chromiumBrowser + '"');
92
- execSync(
93
- 'osascript openChrome.applescript "' +
94
- encodeURI(url) +
95
- '" "' +
96
- chromiumBrowser +
97
- '"',
98
- {
99
- cwd: __dirname,
100
- stdio: 'ignore',
101
- }
102
- );
103
- return true;
104
- } catch (err) {
105
- // Ignore errors.
106
- }
107
- }
108
- }
109
-
110
- // Another special case: on OS X, check if BROWSER has been set to "open".
111
- // In this case, instead of passing `open` to `opn` (which won't work),
112
- // just ignore it (thus ensuring the intended behavior, i.e. opening the system browser):
113
- // https://github.com/facebook/create-react-app/pull/1690#issuecomment-283518768
114
- if (process.platform === 'darwin' && browser === 'open') {
115
- browser = undefined;
116
- }
117
-
118
- // If there are arguments, they must be passed as array with the browser
119
- if (typeof browser === 'string' && args.length > 0) {
120
- browser = [browser].concat(args);
121
- }
122
-
123
- // Fallback to open
124
- // (It will always open new tab)
125
- try {
126
- var options = { app: browser, wait: false, url: true };
127
- open(url, options).catch(() => { }); // Prevent `unhandledRejection` error.
128
- return true;
129
- } catch (err) {
130
- return false;
131
- }
132
- }
133
-
134
- /**
135
- * Reads the BROWSER environment variable and decides what to do with it. Returns
136
- * true if it opened a browser or ran a node.js script, otherwise false.
137
- */
138
- function openBrowser(url) {
139
- const { action, value, args } = getBrowserEnv();
140
- switch (action) {
141
- case Actions.NONE:
142
- // Special case: BROWSER="none" will prevent opening completely.
143
- return false;
144
- case Actions.SCRIPT:
145
- return executeNodeScript(value, url);
146
- case Actions.BROWSER:
147
- return startBrowserProcess(value, url, args);
148
- default:
149
- throw new Error('Not implemented.');
150
- }
151
- }
152
-
153
- module.exports = openBrowser;
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ var chalk = require('chalk');
11
+ var execSync = require('child_process').execSync;
12
+ var spawn = require('cross-spawn');
13
+ var open = require('open');
14
+
15
+ // https://github.com/sindresorhus/open#app
16
+ var OSX_CHROME = 'google chrome';
17
+
18
+ const Actions = Object.freeze({
19
+ NONE: 0,
20
+ BROWSER: 1,
21
+ SCRIPT: 2,
22
+ });
23
+
24
+ function getBrowserEnv() {
25
+ // Attempt to honor this environment variable.
26
+ // It is specific to the operating system.
27
+ // See https://github.com/sindresorhus/open#app for documentation.
28
+ const value = process.env.BROWSER;
29
+ const args = process.env.BROWSER_ARGS
30
+ ? process.env.BROWSER_ARGS.split(' ')
31
+ : [];
32
+ let action;
33
+ if (!value) {
34
+ // Default.
35
+ action = Actions.BROWSER;
36
+ } else if (value.toLowerCase().endsWith('.js')) {
37
+ action = Actions.SCRIPT;
38
+ } else if (value.toLowerCase() === 'none') {
39
+ action = Actions.NONE;
40
+ } else {
41
+ action = Actions.BROWSER;
42
+ }
43
+ return { action, value, args };
44
+ }
45
+
46
+ function executeNodeScript(scriptPath, url) {
47
+ const extraArgs = process.argv.slice(2);
48
+ const child = spawn('node', [scriptPath, ...extraArgs, url], {
49
+ stdio: 'inherit',
50
+ });
51
+ child.on('close', code => {
52
+ if (code !== 0) {
53
+ console.log();
54
+ console.log(
55
+ chalk.red(
56
+ 'The script specified as BROWSER environment variable failed.'
57
+ )
58
+ );
59
+ console.log(chalk.cyan(scriptPath) + ' exited with code ' + code + '.');
60
+ console.log();
61
+ return;
62
+ }
63
+ });
64
+ return true;
65
+ }
66
+
67
+ function startBrowserProcess(browser, url, args) {
68
+ // If we're on OS X, the user hasn't specifically
69
+ // requested a different browser, we can try opening
70
+ // Chrome with AppleScript. This lets us reuse an
71
+ // existing tab when possible instead of creating a new one.
72
+ const shouldTryOpenChromiumWithAppleScript =
73
+ process.platform === 'darwin' &&
74
+ (typeof browser !== 'string' || browser === OSX_CHROME);
75
+
76
+ if (shouldTryOpenChromiumWithAppleScript) {
77
+ // Will use the first open browser found from list
78
+ const supportedChromiumBrowsers = [
79
+ 'Google Chrome Canary',
80
+ 'Google Chrome',
81
+ 'Microsoft Edge',
82
+ 'Brave Browser',
83
+ 'Vivaldi',
84
+ 'Chromium',
85
+ ];
86
+
87
+ for (let chromiumBrowser of supportedChromiumBrowsers) {
88
+ try {
89
+ // Try our best to reuse existing tab
90
+ // on OSX Chromium-based browser with AppleScript
91
+ execSync('ps cax | grep "' + chromiumBrowser + '"');
92
+ execSync(
93
+ 'osascript openChrome.applescript "' +
94
+ encodeURI(url) +
95
+ '" "' +
96
+ chromiumBrowser +
97
+ '"',
98
+ {
99
+ cwd: __dirname,
100
+ stdio: 'ignore',
101
+ }
102
+ );
103
+ return true;
104
+ } catch (err) {
105
+ // Ignore errors.
106
+ }
107
+ }
108
+ }
109
+
110
+ // Another special case: on OS X, check if BROWSER has been set to "open".
111
+ // In this case, instead of passing `open` to `opn` (which won't work),
112
+ // just ignore it (thus ensuring the intended behavior, i.e. opening the system browser):
113
+ // https://github.com/facebook/create-react-app/pull/1690#issuecomment-283518768
114
+ if (process.platform === 'darwin' && browser === 'open') {
115
+ browser = undefined;
116
+ }
117
+
118
+ // If there are arguments, they must be passed as array with the browser
119
+ if (typeof browser === 'string' && args.length > 0) {
120
+ browser = [browser].concat(args);
121
+ }
122
+
123
+ // Fallback to open
124
+ // (It will always open new tab)
125
+ try {
126
+ var options = { app: browser, wait: false, url: true };
127
+ open(url, options).catch(() => { }); // Prevent `unhandledRejection` error.
128
+ return true;
129
+ } catch (err) {
130
+ return false;
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Reads the BROWSER environment variable and decides what to do with it. Returns
136
+ * true if it opened a browser or ran a node.js script, otherwise false.
137
+ */
138
+ function openBrowser(url) {
139
+ const { action, value, args } = getBrowserEnv();
140
+ switch (action) {
141
+ case Actions.NONE:
142
+ // Special case: BROWSER="none" will prevent opening completely.
143
+ return false;
144
+ case Actions.SCRIPT:
145
+ return executeNodeScript(value, url);
146
+ case Actions.BROWSER:
147
+ return startBrowserProcess(value, url, args);
148
+ default:
149
+ throw new Error('Not implemented.');
150
+ }
151
+ }
152
+
153
+ module.exports = openBrowser;