@easyv/react-component-builder 0.18.0 → 0.18.1-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.
- package/config/paths.js +24 -24
- package/config/webpack.config.build.js +70 -70
- package/config/webpack.config.common.js +126 -126
- package/config/webpack.config.js +116 -116
- package/launcher/build.js +107 -107
- package/launcher/generate.js +99 -99
- package/launcher/start.js +229 -229
- package/loaders/react-entry-loader.js +425 -425
- package/package.json +70 -70
- package/public/component.ejs +51 -51
- package/public/home.ejs +21 -21
- package/templates/basic/assets/logo.png +0 -0
- package/templates/basic/config/main.data.json +14 -14
- package/templates/basic/config/main.json +6 -6
- package/templates/basic/index.jsx +26 -26
- package/templates/basic/styles/index.module.css +3 -3
- package/templates/basic/utils/bind-children.js +10 -10
- package/templates/basic/utils/reduce-config.js +20 -20
- package/templates/three-component/config/main.data.json +14 -14
- package/templates/three-component/config/main.json +76 -76
- package/templates/three-component/index.jsx +122 -122
- package/templates/three-component/utils/Component.js +274 -274
- package/templates/three-component/utils/OrbitControls.js +1051 -1051
- package/templates/three-component/utils/reduce-config.js +20 -20
- package/utils/auto-assign-port.js +11 -11
- package/utils/index.js +91 -91
- package/utils/openBrowser.js +153 -153
- package/utils/openChrome.applescript +94 -94
package/launcher/start.js
CHANGED
|
@@ -1,229 +1,229 @@
|
|
|
1
|
-
const webpack = require("webpack");
|
|
2
|
-
const WebpackDevServer = require("webpack-dev-server");
|
|
3
|
-
const getWebpackConfig = require("../config/webpack.config");
|
|
4
|
-
const chalk = require("chalk");
|
|
5
|
-
const glob = require("glob");
|
|
6
|
-
const { appComponents, appPackage } = require("../config/paths");
|
|
7
|
-
const { checkComponentFiles } = require("../utils");
|
|
8
|
-
const autoAssignPort = require("../utils/auto-assign-port");
|
|
9
|
-
const path = require("path");
|
|
10
|
-
const openBrowser = require("../utils/openBrowser");
|
|
11
|
-
|
|
12
|
-
const isInteractive = process.stdout.isTTY;
|
|
13
|
-
const DEFAULT_PORT = 3005;
|
|
14
|
-
const HOST = process.env.HOST || "0.0.0.0";
|
|
15
|
-
let isFirstCompile = true;
|
|
16
|
-
|
|
17
|
-
function clearConsole() {
|
|
18
|
-
process.stdout.write(
|
|
19
|
-
process.platform === "win32" ? "\x1B[2J\x1B[0f" : "\x1B[2J\x1B[3J\x1B[H"
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function printInstructions(appName, urls) {
|
|
24
|
-
console.log();
|
|
25
|
-
console.log(`You can now view ${chalk.bold(appName)} in the browser.`);
|
|
26
|
-
console.log();
|
|
27
|
-
|
|
28
|
-
if (urls.lanUrlForTerminal) {
|
|
29
|
-
console.log(
|
|
30
|
-
` ${chalk.bold("Local:")} ${urls.localUrlForTerminal}`
|
|
31
|
-
);
|
|
32
|
-
// console.log(
|
|
33
|
-
// ` ${chalk.bold('On Your Network:')} ${urls.lanUrlForTerminal}`
|
|
34
|
-
// );
|
|
35
|
-
} else {
|
|
36
|
-
console.log(` ${urls.localUrlForTerminal}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function createCompiler({ appName, config, urls }) {
|
|
41
|
-
let compiler;
|
|
42
|
-
try {
|
|
43
|
-
compiler = webpack(config);
|
|
44
|
-
} catch (err) {
|
|
45
|
-
console.log(chalk.red("Failed to compile."));
|
|
46
|
-
console.log();
|
|
47
|
-
console.log(err.message || err);
|
|
48
|
-
console.log();
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// "invalid" event fires when you have changed a file, and webpack is
|
|
53
|
-
// recompiling a bundle. WebpackDevServer takes care to pause serving the
|
|
54
|
-
// bundle, so if you refresh, it'll wait instead of serving the old one.
|
|
55
|
-
// "invalid" is short for "bundle invalidated", it doesn't imply any errors.
|
|
56
|
-
compiler.hooks.invalid.tap("invalid", () => {
|
|
57
|
-
if (isInteractive) {
|
|
58
|
-
clearConsole();
|
|
59
|
-
}
|
|
60
|
-
console.log("Compiling...");
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// "done" event fires when webpack has finished recompiling the bundle.
|
|
64
|
-
// Whether or not you have warnings or errors, you will get this event.
|
|
65
|
-
compiler.hooks.done.tap("done", async (stats) => {
|
|
66
|
-
if (isInteractive) {
|
|
67
|
-
clearConsole();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const statsData = stats.toJson({
|
|
71
|
-
all: false,
|
|
72
|
-
warnings: true,
|
|
73
|
-
errors: true,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const messages = statsData;
|
|
77
|
-
const isSuccessful = !messages.errors.length && !messages.warnings.length;
|
|
78
|
-
if (isSuccessful) {
|
|
79
|
-
console.log(chalk.green("Compiled successfully!"));
|
|
80
|
-
}
|
|
81
|
-
if (isSuccessful && (isInteractive || isFirstCompile)) {
|
|
82
|
-
printInstructions(appName, urls);
|
|
83
|
-
}
|
|
84
|
-
isFirstCompile = false;
|
|
85
|
-
|
|
86
|
-
if (messages.errors.length) {
|
|
87
|
-
if (messages.errors.length > 1) {
|
|
88
|
-
messages.errors.length = 1;
|
|
89
|
-
}
|
|
90
|
-
console.log(chalk.red("Failed to compile.\n"));
|
|
91
|
-
console.log(messages.errors.join("\n\n"));
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (messages.warnings.length) {
|
|
96
|
-
console.log(chalk.yellow("Compiled with warnings.\n"));
|
|
97
|
-
console.log(messages.warnings.join("\n\n"));
|
|
98
|
-
|
|
99
|
-
console.log(
|
|
100
|
-
"\nSearch for the " +
|
|
101
|
-
chalk.underline(chalk.yellow("keywords")) +
|
|
102
|
-
" to learn more about each warning."
|
|
103
|
-
);
|
|
104
|
-
console.log(
|
|
105
|
-
"To ignore, add " +
|
|
106
|
-
chalk.cyan("// eslint-disable-next-line") +
|
|
107
|
-
" to the line before.\n"
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
return compiler;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function start({ port, modules }) {
|
|
116
|
-
const url = `http://localhost:${port}`;
|
|
117
|
-
|
|
118
|
-
const config = getWebpackConfig({ port, modules });
|
|
119
|
-
const compiler = createCompiler({
|
|
120
|
-
appName: appPackage.name,
|
|
121
|
-
config,
|
|
122
|
-
urls: {
|
|
123
|
-
localUrlForTerminal: url,
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
const server = new WebpackDevServer(compiler, config.devServer);
|
|
128
|
-
|
|
129
|
-
server.listen(port, HOST, (err) => {
|
|
130
|
-
if (err) {
|
|
131
|
-
return console.log(err);
|
|
132
|
-
}
|
|
133
|
-
if (isInteractive) {
|
|
134
|
-
clearConsole();
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
console.log(chalk.cyan("Starting the development server...\n"));
|
|
138
|
-
openBrowser(url);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
["SIGINT", "SIGTERM"].forEach(function (sig) {
|
|
142
|
-
process.on(sig, function () {
|
|
143
|
-
server.close();
|
|
144
|
-
process.exit();
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function getBuildEntrys(modules = []) {
|
|
150
|
-
// 优先级
|
|
151
|
-
const suffix = ["jsx", "tsx", "js", "ts"];
|
|
152
|
-
|
|
153
|
-
return new Promise((resolve, reject) => {
|
|
154
|
-
// 两种获取方式配置方式
|
|
155
|
-
// new configs: ['config/main.json', 'config/main.data.json']
|
|
156
|
-
// old configs: ['config/base.js', 'config/config.js', 'mock/data.js']
|
|
157
|
-
|
|
158
|
-
glob(
|
|
159
|
-
`*/index.+(${suffix.join("|")})`,
|
|
160
|
-
{
|
|
161
|
-
cwd: appComponents,
|
|
162
|
-
},
|
|
163
|
-
function (err, matches) {
|
|
164
|
-
if (err) {
|
|
165
|
-
console.error(err);
|
|
166
|
-
process.exit();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (!matches.length) process.exit();
|
|
170
|
-
|
|
171
|
-
const dir = matches.reduce((acc, path) => {
|
|
172
|
-
const name = path.slice(0, path.indexOf("/"));
|
|
173
|
-
if (modules.length && !~modules.indexOf(name)) return acc; // 排除不打包的 如果目录是空的则忽略
|
|
174
|
-
if (!acc[name]) acc[name] = [path];
|
|
175
|
-
else acc[name].push(path);
|
|
176
|
-
return acc;
|
|
177
|
-
}, {});
|
|
178
|
-
|
|
179
|
-
const moduleNames = new Set();
|
|
180
|
-
|
|
181
|
-
// {a: [a.js, a.jsx, ...], ...}
|
|
182
|
-
const components = Object.keys(dir).map((dirname) => {
|
|
183
|
-
let indexPath;
|
|
184
|
-
suffix.every((ext) => {
|
|
185
|
-
const i = dir[dirname].findIndex((path) =>
|
|
186
|
-
path.endsWith("." + ext)
|
|
187
|
-
);
|
|
188
|
-
return i > -1
|
|
189
|
-
? ((indexPath = path.join(appComponents, dir[dirname][i])), false)
|
|
190
|
-
: true;
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
const { base } = checkComponentFiles(
|
|
194
|
-
path.join(appComponents, dirname)
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
// 组件名称重复检查
|
|
198
|
-
let name = base.module_name;
|
|
199
|
-
if (moduleNames.has(moduleNames)) {
|
|
200
|
-
console.error(chalk.red`component name ${name} is duplicate.`);
|
|
201
|
-
process.exit();
|
|
202
|
-
}
|
|
203
|
-
moduleNames.add(name);
|
|
204
|
-
|
|
205
|
-
return {
|
|
206
|
-
dirname,
|
|
207
|
-
name,
|
|
208
|
-
base,
|
|
209
|
-
path: indexPath,
|
|
210
|
-
};
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
if (components.length) {
|
|
214
|
-
resolve(components);
|
|
215
|
-
} else {
|
|
216
|
-
process.exit();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
);
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
module.exports = (modules) => {
|
|
224
|
-
getBuildEntrys(modules).then((modules) => {
|
|
225
|
-
autoAssignPort(DEFAULT_PORT, (port) => {
|
|
226
|
-
start({ port, modules });
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
};
|
|
1
|
+
const webpack = require("webpack");
|
|
2
|
+
const WebpackDevServer = require("webpack-dev-server");
|
|
3
|
+
const getWebpackConfig = require("../config/webpack.config");
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const glob = require("glob");
|
|
6
|
+
const { appComponents, appPackage } = require("../config/paths");
|
|
7
|
+
const { checkComponentFiles } = require("../utils");
|
|
8
|
+
const autoAssignPort = require("../utils/auto-assign-port");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const openBrowser = require("../utils/openBrowser");
|
|
11
|
+
|
|
12
|
+
const isInteractive = process.stdout.isTTY;
|
|
13
|
+
const DEFAULT_PORT = 3005;
|
|
14
|
+
const HOST = process.env.HOST || "0.0.0.0";
|
|
15
|
+
let isFirstCompile = true;
|
|
16
|
+
|
|
17
|
+
function clearConsole() {
|
|
18
|
+
process.stdout.write(
|
|
19
|
+
process.platform === "win32" ? "\x1B[2J\x1B[0f" : "\x1B[2J\x1B[3J\x1B[H"
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function printInstructions(appName, urls) {
|
|
24
|
+
console.log();
|
|
25
|
+
console.log(`You can now view ${chalk.bold(appName)} in the browser.`);
|
|
26
|
+
console.log();
|
|
27
|
+
|
|
28
|
+
if (urls.lanUrlForTerminal) {
|
|
29
|
+
console.log(
|
|
30
|
+
` ${chalk.bold("Local:")} ${urls.localUrlForTerminal}`
|
|
31
|
+
);
|
|
32
|
+
// console.log(
|
|
33
|
+
// ` ${chalk.bold('On Your Network:')} ${urls.lanUrlForTerminal}`
|
|
34
|
+
// );
|
|
35
|
+
} else {
|
|
36
|
+
console.log(` ${urls.localUrlForTerminal}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function createCompiler({ appName, config, urls }) {
|
|
41
|
+
let compiler;
|
|
42
|
+
try {
|
|
43
|
+
compiler = webpack(config);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.log(chalk.red("Failed to compile."));
|
|
46
|
+
console.log();
|
|
47
|
+
console.log(err.message || err);
|
|
48
|
+
console.log();
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// "invalid" event fires when you have changed a file, and webpack is
|
|
53
|
+
// recompiling a bundle. WebpackDevServer takes care to pause serving the
|
|
54
|
+
// bundle, so if you refresh, it'll wait instead of serving the old one.
|
|
55
|
+
// "invalid" is short for "bundle invalidated", it doesn't imply any errors.
|
|
56
|
+
compiler.hooks.invalid.tap("invalid", () => {
|
|
57
|
+
if (isInteractive) {
|
|
58
|
+
clearConsole();
|
|
59
|
+
}
|
|
60
|
+
console.log("Compiling...");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// "done" event fires when webpack has finished recompiling the bundle.
|
|
64
|
+
// Whether or not you have warnings or errors, you will get this event.
|
|
65
|
+
compiler.hooks.done.tap("done", async (stats) => {
|
|
66
|
+
if (isInteractive) {
|
|
67
|
+
clearConsole();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const statsData = stats.toJson({
|
|
71
|
+
all: false,
|
|
72
|
+
warnings: true,
|
|
73
|
+
errors: true,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const messages = statsData;
|
|
77
|
+
const isSuccessful = !messages.errors.length && !messages.warnings.length;
|
|
78
|
+
if (isSuccessful) {
|
|
79
|
+
console.log(chalk.green("Compiled successfully!"));
|
|
80
|
+
}
|
|
81
|
+
if (isSuccessful && (isInteractive || isFirstCompile)) {
|
|
82
|
+
printInstructions(appName, urls);
|
|
83
|
+
}
|
|
84
|
+
isFirstCompile = false;
|
|
85
|
+
|
|
86
|
+
if (messages.errors.length) {
|
|
87
|
+
if (messages.errors.length > 1) {
|
|
88
|
+
messages.errors.length = 1;
|
|
89
|
+
}
|
|
90
|
+
console.log(chalk.red("Failed to compile.\n"));
|
|
91
|
+
console.log(messages.errors.join("\n\n"));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (messages.warnings.length) {
|
|
96
|
+
console.log(chalk.yellow("Compiled with warnings.\n"));
|
|
97
|
+
console.log(messages.warnings.join("\n\n"));
|
|
98
|
+
|
|
99
|
+
console.log(
|
|
100
|
+
"\nSearch for the " +
|
|
101
|
+
chalk.underline(chalk.yellow("keywords")) +
|
|
102
|
+
" to learn more about each warning."
|
|
103
|
+
);
|
|
104
|
+
console.log(
|
|
105
|
+
"To ignore, add " +
|
|
106
|
+
chalk.cyan("// eslint-disable-next-line") +
|
|
107
|
+
" to the line before.\n"
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return compiler;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function start({ port, modules }) {
|
|
116
|
+
const url = `http://localhost:${port}`;
|
|
117
|
+
|
|
118
|
+
const config = getWebpackConfig({ port, modules });
|
|
119
|
+
const compiler = createCompiler({
|
|
120
|
+
appName: appPackage.name,
|
|
121
|
+
config,
|
|
122
|
+
urls: {
|
|
123
|
+
localUrlForTerminal: url,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const server = new WebpackDevServer(compiler, config.devServer);
|
|
128
|
+
|
|
129
|
+
server.listen(port, HOST, (err) => {
|
|
130
|
+
if (err) {
|
|
131
|
+
return console.log(err);
|
|
132
|
+
}
|
|
133
|
+
if (isInteractive) {
|
|
134
|
+
clearConsole();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
console.log(chalk.cyan("Starting the development server...\n"));
|
|
138
|
+
openBrowser(url);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
["SIGINT", "SIGTERM"].forEach(function (sig) {
|
|
142
|
+
process.on(sig, function () {
|
|
143
|
+
server.close();
|
|
144
|
+
process.exit();
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function getBuildEntrys(modules = []) {
|
|
150
|
+
// 优先级
|
|
151
|
+
const suffix = ["jsx", "tsx", "js", "ts"];
|
|
152
|
+
|
|
153
|
+
return new Promise((resolve, reject) => {
|
|
154
|
+
// 两种获取方式配置方式
|
|
155
|
+
// new configs: ['config/main.json', 'config/main.data.json']
|
|
156
|
+
// old configs: ['config/base.js', 'config/config.js', 'mock/data.js']
|
|
157
|
+
|
|
158
|
+
glob(
|
|
159
|
+
`*/index.+(${suffix.join("|")})`,
|
|
160
|
+
{
|
|
161
|
+
cwd: appComponents,
|
|
162
|
+
},
|
|
163
|
+
function (err, matches) {
|
|
164
|
+
if (err) {
|
|
165
|
+
console.error(err);
|
|
166
|
+
process.exit();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!matches.length) process.exit();
|
|
170
|
+
|
|
171
|
+
const dir = matches.reduce((acc, path) => {
|
|
172
|
+
const name = path.slice(0, path.indexOf("/"));
|
|
173
|
+
if (modules.length && !~modules.indexOf(name)) return acc; // 排除不打包的 如果目录是空的则忽略
|
|
174
|
+
if (!acc[name]) acc[name] = [path];
|
|
175
|
+
else acc[name].push(path);
|
|
176
|
+
return acc;
|
|
177
|
+
}, {});
|
|
178
|
+
|
|
179
|
+
const moduleNames = new Set();
|
|
180
|
+
|
|
181
|
+
// {a: [a.js, a.jsx, ...], ...}
|
|
182
|
+
const components = Object.keys(dir).map((dirname) => {
|
|
183
|
+
let indexPath;
|
|
184
|
+
suffix.every((ext) => {
|
|
185
|
+
const i = dir[dirname].findIndex((path) =>
|
|
186
|
+
path.endsWith("." + ext)
|
|
187
|
+
);
|
|
188
|
+
return i > -1
|
|
189
|
+
? ((indexPath = path.join(appComponents, dir[dirname][i])), false)
|
|
190
|
+
: true;
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const { base } = checkComponentFiles(
|
|
194
|
+
path.join(appComponents, dirname)
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
// 组件名称重复检查
|
|
198
|
+
let name = base.module_name;
|
|
199
|
+
if (moduleNames.has(moduleNames)) {
|
|
200
|
+
console.error(chalk.red`component name ${name} is duplicate.`);
|
|
201
|
+
process.exit();
|
|
202
|
+
}
|
|
203
|
+
moduleNames.add(name);
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
dirname,
|
|
207
|
+
name,
|
|
208
|
+
base,
|
|
209
|
+
path: indexPath,
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
if (components.length) {
|
|
214
|
+
resolve(components);
|
|
215
|
+
} else {
|
|
216
|
+
process.exit();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
module.exports = (modules) => {
|
|
224
|
+
getBuildEntrys(modules).then((modules) => {
|
|
225
|
+
autoAssignPort(DEFAULT_PORT, (port) => {
|
|
226
|
+
start({ port, modules });
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
};
|