@modern-js/module-tools 1.1.1 → 1.1.4-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/CHANGELOG.md +47 -0
- package/dist/js/modern/cli/new.js +2 -2
- package/dist/js/modern/commands/dev.js +12 -5
- package/dist/js/modern/features/build/build-platform.js +21 -18
- package/dist/js/modern/features/build/build-watch.js +8 -1
- package/dist/js/modern/features/build/index.js +18 -8
- package/dist/js/modern/tasks/build-source-code.js +16 -21
- package/dist/js/modern/tasks/build-style.js +9 -1
- package/dist/js/modern/tasks/build-watch-source-code.js +11 -1
- package/dist/js/modern/tasks/build-watch-style.js +15 -2
- package/dist/js/modern/tasks/copy-assets.js +9 -1
- package/dist/js/modern/tasks/generator-dts.js +11 -3
- package/dist/js/modern/utils/babel.js +2 -2
- package/dist/js/modern/utils/init-env.js +14 -0
- package/dist/js/node/cli/new.js +2 -2
- package/dist/js/node/commands/dev.js +13 -6
- package/dist/js/node/features/build/build-platform.js +21 -18
- package/dist/js/node/features/build/build-watch.js +8 -1
- package/dist/js/node/features/build/index.js +18 -7
- package/dist/js/node/tasks/build-source-code.js +18 -24
- package/dist/js/node/tasks/build-style.js +9 -1
- package/dist/js/node/tasks/build-watch-source-code.js +12 -1
- package/dist/js/node/tasks/build-watch-style.js +16 -2
- package/dist/js/node/tasks/copy-assets.js +9 -1
- package/dist/js/node/tasks/generator-dts.js +11 -3
- package/dist/js/node/utils/babel.js +2 -2
- package/dist/js/node/utils/init-env.js +23 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/tasks/build-source-code.d.ts +0 -17
- package/dist/types/utils/init-env.d.ts +21 -0
- package/package.json +14 -13
- package/src/commands/dev.ts +5 -3
- package/src/features/build/build-platform.ts +27 -20
- package/src/features/build/build-watch.ts +7 -1
- package/src/features/build/index.ts +17 -7
- package/src/tasks/build-source-code.ts +10 -17
- package/src/tasks/build-style.ts +13 -2
- package/src/tasks/build-watch-source-code.ts +8 -2
- package/src/tasks/build-watch-style.ts +27 -9
- package/src/tasks/copy-assets.ts +13 -2
- package/src/tasks/generator-dts.ts +6 -2
- package/src/utils/init-env.ts +31 -0
|
@@ -13,18 +13,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
13
13
|
|
|
14
14
|
const buildFeature = _utils.Import.lazy('./build', require);
|
|
15
15
|
|
|
16
|
-
const buildWatchFeature = _utils.Import.lazy('./build-watch', require);
|
|
17
|
-
// './build-platform',
|
|
18
|
-
// require,
|
|
19
|
-
// );
|
|
16
|
+
const buildWatchFeature = _utils.Import.lazy('./build-watch', require);
|
|
20
17
|
|
|
18
|
+
const bp = _utils.Import.lazy('./build-platform', require);
|
|
21
19
|
|
|
22
20
|
const build = async (config, modernConfig) => {
|
|
23
21
|
const {
|
|
24
22
|
appDirectory,
|
|
25
23
|
enableWatchMode,
|
|
26
24
|
platform,
|
|
27
|
-
clear = true
|
|
25
|
+
clear = true,
|
|
26
|
+
isTsProject
|
|
28
27
|
} = config;
|
|
29
28
|
const {
|
|
30
29
|
output: {
|
|
@@ -33,12 +32,24 @@ const build = async (config, modernConfig) => {
|
|
|
33
32
|
} = modernConfig; // TODO: maybe need watch mode in build platform
|
|
34
33
|
|
|
35
34
|
if (typeof platform === 'boolean' && platform) {
|
|
36
|
-
|
|
35
|
+
if (process.env.RUN_PLATFORM) {
|
|
36
|
+
await bp.buildPlatform({
|
|
37
|
+
platform: 'all',
|
|
38
|
+
isTsProject
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
37
42
|
return;
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
if (typeof platform === 'string') {
|
|
41
|
-
|
|
46
|
+
if (process.env.RUN_PLATFORM) {
|
|
47
|
+
await bp.buildPlatform({
|
|
48
|
+
platform,
|
|
49
|
+
isTsProject
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
return;
|
|
43
54
|
}
|
|
44
55
|
|
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.getWillCompilerCode = exports.buildSourceCode = exports.Compiler = void 0;
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
var _initEnv = require("../utils/init-env");
|
|
11
11
|
|
|
12
|
-
function
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
|
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
15
|
|
|
14
16
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
17
|
|
|
@@ -136,22 +138,6 @@ const generatorRealFiles = virtualDists => {
|
|
|
136
138
|
}
|
|
137
139
|
};
|
|
138
140
|
|
|
139
|
-
const initEnv = ({
|
|
140
|
-
syntax,
|
|
141
|
-
type
|
|
142
|
-
}) => {
|
|
143
|
-
if (syntax === 'es6+' && type === 'commonjs') {
|
|
144
|
-
return 'nodejs';
|
|
145
|
-
} else if (syntax === 'es6+' && type === 'module') {
|
|
146
|
-
return 'modern';
|
|
147
|
-
} else if (syntax === 'es5' && type === 'module') {
|
|
148
|
-
return 'legacy-browser';
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return '';
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
exports.initEnv = initEnv;
|
|
155
141
|
const defaultConfig = {
|
|
156
142
|
srcRootDir: `${process.cwd()}/src`,
|
|
157
143
|
willCompilerDirOrFile: `${process.cwd()}/src`,
|
|
@@ -168,11 +154,11 @@ const defaultConfig = {
|
|
|
168
154
|
const taskMain = async ({
|
|
169
155
|
modernConfig
|
|
170
156
|
}) => {
|
|
171
|
-
//
|
|
157
|
+
// Execution of the script's parameter handling and related required configuration acquisition
|
|
172
158
|
const processArgv = argv(process.argv.slice(2));
|
|
173
|
-
const config = processArgv(defaultConfig);
|
|
174
|
-
|
|
175
|
-
const compiler = Compiler.babel; //
|
|
159
|
+
const config = processArgv(defaultConfig);
|
|
160
|
+
process.env.BUILD_FORMAT = (0, _initEnv.initEnv)(config);
|
|
161
|
+
const compiler = Compiler.babel; // Currently, only babel is supported.
|
|
176
162
|
|
|
177
163
|
const babelConfig = bc.resolveBabelConfig(config.appDirectory, modernConfig, {
|
|
178
164
|
sourceAbsDir: config.srcRootDir,
|
|
@@ -222,9 +208,17 @@ const taskMain = async ({
|
|
|
222
208
|
};
|
|
223
209
|
|
|
224
210
|
(async () => {
|
|
211
|
+
let options;
|
|
212
|
+
|
|
213
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
214
|
+
({
|
|
215
|
+
options
|
|
216
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
217
|
+
}
|
|
218
|
+
|
|
225
219
|
const {
|
|
226
220
|
resolved
|
|
227
|
-
} = await core.cli.init();
|
|
221
|
+
} = await core.cli.init([], options);
|
|
228
222
|
await core.manager.run(async () => {
|
|
229
223
|
try {
|
|
230
224
|
await taskMain({
|
|
@@ -159,11 +159,19 @@ const taskMain = async ({
|
|
|
159
159
|
};
|
|
160
160
|
|
|
161
161
|
(async () => {
|
|
162
|
+
let options;
|
|
163
|
+
|
|
164
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
165
|
+
({
|
|
166
|
+
options
|
|
167
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
168
|
+
}
|
|
169
|
+
|
|
162
170
|
hooks.buildLifeCycle();
|
|
163
171
|
const {
|
|
164
172
|
resolved: modernConfig,
|
|
165
173
|
appContext
|
|
166
|
-
} = await core.cli.init();
|
|
174
|
+
} = await core.cli.init([], options);
|
|
167
175
|
await core.manager.run(async () => {
|
|
168
176
|
try {
|
|
169
177
|
await taskMain({
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var _utils = require("@modern-js/utils");
|
|
4
4
|
|
|
5
|
+
var _initEnv = require("../utils/init-env");
|
|
6
|
+
|
|
5
7
|
const babelCompiler = _utils.Import.lazy('@modern-js/babel-compiler', require);
|
|
6
8
|
|
|
7
9
|
const logger = _utils.Import.lazy('../features/build/logger', require);
|
|
@@ -134,13 +136,22 @@ const taskMain = async ({
|
|
|
134
136
|
syntax: 'es5',
|
|
135
137
|
type: 'module'
|
|
136
138
|
});
|
|
139
|
+
process.env.BUILD_FORMAT = (0, _initEnv.initEnv)(config);
|
|
137
140
|
await buildSourceCode(config, modernConfig);
|
|
138
141
|
};
|
|
139
142
|
|
|
140
143
|
(async () => {
|
|
144
|
+
let options;
|
|
145
|
+
|
|
146
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
147
|
+
({
|
|
148
|
+
options
|
|
149
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
150
|
+
}
|
|
151
|
+
|
|
141
152
|
const {
|
|
142
153
|
resolved
|
|
143
|
-
} = await core.cli.init();
|
|
154
|
+
} = await core.cli.init([], options);
|
|
144
155
|
await core.manager.run(async () => {
|
|
145
156
|
try {
|
|
146
157
|
await taskMain({
|
|
@@ -69,6 +69,8 @@ const copyOriginStyleFiles = ({
|
|
|
69
69
|
for (const styleFile of styleFiles) {
|
|
70
70
|
const file = path.relative(targetDir, styleFile);
|
|
71
71
|
|
|
72
|
+
_utils.fs.ensureFileSync(path.join(outputDir, file));
|
|
73
|
+
|
|
72
74
|
_utils.fs.copyFileSync(styleFile, path.join(outputDir, file));
|
|
73
75
|
}
|
|
74
76
|
};
|
|
@@ -93,9 +95,13 @@ const taskMain = async ({
|
|
|
93
95
|
appDirectory
|
|
94
96
|
} = appContext;
|
|
95
97
|
const lessOption = await core.mountHook().moduleLessConfig({
|
|
98
|
+
modernConfig
|
|
99
|
+
}, {
|
|
96
100
|
onLast: async _ => null
|
|
97
101
|
});
|
|
98
102
|
const sassOption = await core.mountHook().moduleSassConfig({
|
|
103
|
+
modernConfig
|
|
104
|
+
}, {
|
|
99
105
|
onLast: async _ => null
|
|
100
106
|
});
|
|
101
107
|
const postcssOption = getPostcssOption(appDirectory, modernConfig);
|
|
@@ -203,11 +209,19 @@ const taskMain = async ({
|
|
|
203
209
|
};
|
|
204
210
|
|
|
205
211
|
(async () => {
|
|
212
|
+
let options;
|
|
213
|
+
|
|
214
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
215
|
+
({
|
|
216
|
+
options
|
|
217
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
218
|
+
}
|
|
219
|
+
|
|
206
220
|
hooks.buildLifeCycle();
|
|
207
221
|
const {
|
|
208
222
|
resolved: modernConfig,
|
|
209
223
|
appContext
|
|
210
|
-
} = await core.cli.init();
|
|
224
|
+
} = await core.cli.init([], options);
|
|
211
225
|
await core.manager.run(async () => {
|
|
212
226
|
try {
|
|
213
227
|
await taskMain({
|
|
@@ -215,7 +229,7 @@ const taskMain = async ({
|
|
|
215
229
|
appContext
|
|
216
230
|
});
|
|
217
231
|
} catch (e) {
|
|
218
|
-
console.error(e
|
|
232
|
+
console.error(e);
|
|
219
233
|
}
|
|
220
234
|
});
|
|
221
235
|
})();
|
|
@@ -106,10 +106,18 @@ const taskMain = ({
|
|
|
106
106
|
};
|
|
107
107
|
|
|
108
108
|
(async () => {
|
|
109
|
+
let options;
|
|
110
|
+
|
|
111
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
112
|
+
({
|
|
113
|
+
options
|
|
114
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
115
|
+
}
|
|
116
|
+
|
|
109
117
|
const {
|
|
110
118
|
resolved: modernConfig,
|
|
111
119
|
appContext
|
|
112
|
-
} = await core.cli.init();
|
|
120
|
+
} = await core.cli.init([], options);
|
|
113
121
|
core.manager.run(() => {
|
|
114
122
|
try {
|
|
115
123
|
taskMain({
|
|
@@ -10,9 +10,9 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
10
10
|
|
|
11
11
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
12
|
|
|
13
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
13
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
14
14
|
|
|
15
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
15
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
16
16
|
|
|
17
17
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
18
|
|
|
@@ -223,9 +223,17 @@ const taskMain = async ({
|
|
|
223
223
|
};
|
|
224
224
|
|
|
225
225
|
(async () => {
|
|
226
|
+
let options;
|
|
227
|
+
|
|
228
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
229
|
+
({
|
|
230
|
+
options
|
|
231
|
+
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
232
|
+
}
|
|
233
|
+
|
|
226
234
|
const {
|
|
227
235
|
resolved
|
|
228
|
-
} = await core.cli.init();
|
|
236
|
+
} = await core.cli.init([], options);
|
|
229
237
|
await core.manager.run(async () => {
|
|
230
238
|
try {
|
|
231
239
|
await taskMain({
|
|
@@ -9,9 +9,9 @@ var _babelPresetModule = require("@modern-js/babel-preset-module");
|
|
|
9
9
|
|
|
10
10
|
var _utils = require("@modern-js/utils");
|
|
11
11
|
|
|
12
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
13
|
|
|
14
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
15
15
|
|
|
16
16
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
17
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.initEnv = void 0;
|
|
7
|
+
|
|
8
|
+
const initEnv = ({
|
|
9
|
+
syntax,
|
|
10
|
+
type
|
|
11
|
+
}) => {
|
|
12
|
+
if (syntax === 'es6+' && type === 'commonjs') {
|
|
13
|
+
return 'CJS_ES6';
|
|
14
|
+
} else if (syntax === 'es6+' && type === 'module') {
|
|
15
|
+
return 'ESM_ES6';
|
|
16
|
+
} else if (syntax === 'es5' && type === 'module') {
|
|
17
|
+
return 'ESM_ES5';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return '';
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.initEnv = initEnv;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ export declare const defineConfig: (config: import("@modern-js/core/config").Con
|
|
|
2
2
|
|
|
3
3
|
declare const _default: import("@modern-js/core").AsyncPlugin<Partial<import("@modern-js/core").Progresses2Threads<{
|
|
4
4
|
config: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
5
|
+
resolvedConfig: import("@modern-js/core").AsyncWaterfall<{
|
|
6
|
+
resolved: import("@modern-js/core").NormalizedConfig;
|
|
7
|
+
}>;
|
|
5
8
|
validateSchema: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
6
9
|
prepare: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
7
10
|
commands: import("@modern-js/core").AsyncWorkflow<{
|
|
@@ -22,21 +22,4 @@ export declare const getWillCompilerCode: (srcDirOrFile: string, option: {
|
|
|
22
22
|
isTsProject: boolean;
|
|
23
23
|
}) => string[];
|
|
24
24
|
export declare const buildSourceCode: (config: IBuildSourceCodeConfig) => Promise<import("@modern-js/babel-compiler").ICompilerResult>;
|
|
25
|
-
export declare const initEnv: ({
|
|
26
|
-
syntax,
|
|
27
|
-
type
|
|
28
|
-
}: ITaskConfig) => "" | "modern" | "nodejs" | "legacy-browser";
|
|
29
|
-
interface ITaskConfig {
|
|
30
|
-
srcRootDir: string;
|
|
31
|
-
willCompilerDirOrFile: string;
|
|
32
|
-
distDir: string;
|
|
33
|
-
appDirectory: string;
|
|
34
|
-
sourceMaps: boolean;
|
|
35
|
-
syntax: 'es5' | 'es6+';
|
|
36
|
-
type: 'module' | 'commonjs';
|
|
37
|
-
tsconfigPath: string;
|
|
38
|
-
copyDirs?: string;
|
|
39
|
-
compiler?: 'babel' | 'esbuild' | 'swc';
|
|
40
|
-
watch: boolean;
|
|
41
|
-
}
|
|
42
25
|
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface ITaskConfig {
|
|
2
|
+
srcRootDir: string;
|
|
3
|
+
willCompilerDirOrFile: string;
|
|
4
|
+
distDir: string;
|
|
5
|
+
appDirectory: string;
|
|
6
|
+
sourceMaps: boolean;
|
|
7
|
+
syntax: 'es5' | 'es6+';
|
|
8
|
+
type: 'module' | 'commonjs';
|
|
9
|
+
tsconfigPath: string;
|
|
10
|
+
copyDirs?: string;
|
|
11
|
+
compiler?: 'babel' | 'esbuild' | 'swc';
|
|
12
|
+
watch: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const initEnv: ({
|
|
15
|
+
syntax,
|
|
16
|
+
type
|
|
17
|
+
}: {
|
|
18
|
+
syntax: ITaskConfig['syntax'];
|
|
19
|
+
type: ITaskConfig['type'];
|
|
20
|
+
}) => "" | "CJS_ES6" | "ESM_ES6" | "ESM_ES5";
|
|
21
|
+
export {};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.1.
|
|
14
|
+
"version": "1.1.4-beta.0",
|
|
15
15
|
"bin": {
|
|
16
16
|
"modern": "./bin/modern.js"
|
|
17
17
|
},
|
|
@@ -44,19 +44,19 @@
|
|
|
44
44
|
"@babel/runtime": "^7",
|
|
45
45
|
"@babel/traverse": "^7.15.0",
|
|
46
46
|
"@babel/types": "^7.15.0",
|
|
47
|
-
"@modern-js/babel-compiler": "^1.1.
|
|
48
|
-
"@modern-js/babel-preset-module": "^1.1.
|
|
49
|
-
"@modern-js/core": "^1.
|
|
50
|
-
"@modern-js/css-config": "^1.1.
|
|
47
|
+
"@modern-js/babel-compiler": "^1.1.3",
|
|
48
|
+
"@modern-js/babel-preset-module": "^1.1.2",
|
|
49
|
+
"@modern-js/core": "^1.2.0",
|
|
50
|
+
"@modern-js/css-config": "^1.1.2",
|
|
51
51
|
"@modern-js/i18n-cli-language-detector": "^1.1.1",
|
|
52
|
-
"@modern-js/module-tools-hooks": "^1.1.
|
|
53
|
-
"@modern-js/new-action": "^1.
|
|
54
|
-
"@modern-js/plugin-analyze": "^1.1.
|
|
52
|
+
"@modern-js/module-tools-hooks": "^1.1.2",
|
|
53
|
+
"@modern-js/new-action": "^1.2.0",
|
|
54
|
+
"@modern-js/plugin-analyze": "^1.1.2",
|
|
55
55
|
"@modern-js/plugin-changeset": "^1.1.1",
|
|
56
56
|
"@modern-js/plugin-fast-refresh": "^1.1.1",
|
|
57
57
|
"@modern-js/plugin-i18n": "^1.1.1",
|
|
58
|
-
"@modern-js/style-compiler": "^1.1.
|
|
59
|
-
"@modern-js/utils": "^1.1.
|
|
58
|
+
"@modern-js/style-compiler": "^1.1.3",
|
|
59
|
+
"@modern-js/utils": "^1.1.5",
|
|
60
60
|
"chalk": "^4.1.2",
|
|
61
61
|
"chokidar": "^3.5.2",
|
|
62
62
|
"dotenv": "^10.0.0",
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
"@types/signale": "^1.4.2",
|
|
89
89
|
"commander": "^8.1.0",
|
|
90
90
|
"typescript": "^4",
|
|
91
|
-
"@modern-js/plugin-testing": "^1.
|
|
92
|
-
"@modern-js/module-tools": "^1.1.
|
|
91
|
+
"@modern-js/plugin-testing": "^1.2.0",
|
|
92
|
+
"@modern-js/module-tools": "^1.1.3"
|
|
93
93
|
},
|
|
94
94
|
"sideEffects": false,
|
|
95
95
|
"modernConfig": {
|
|
@@ -105,5 +105,6 @@
|
|
|
105
105
|
"new": "modern new",
|
|
106
106
|
"build": "modern build",
|
|
107
107
|
"test": "modern test --passWithNoTests"
|
|
108
|
-
}
|
|
108
|
+
},
|
|
109
|
+
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
|
109
110
|
}
|
package/src/commands/dev.ts
CHANGED
|
@@ -35,7 +35,9 @@ export const dev = async (option: IDevOption) => {
|
|
|
35
35
|
valid.valideBeforeTask({ modernConfig, tsconfigPath });
|
|
36
36
|
|
|
37
37
|
const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
if (process.env.RUN_PLATFORM) {
|
|
39
|
+
await devFeature.showMenu({ isTsProject, appDirectory });
|
|
40
|
+
} else {
|
|
41
|
+
await devFeature.devStorybook({ isTsProject, appDirectory });
|
|
42
|
+
}
|
|
41
43
|
};
|
|
@@ -44,33 +44,40 @@ export const buildPlatform = async (option: IBuildPlatformOption) => {
|
|
|
44
44
|
...params,
|
|
45
45
|
};
|
|
46
46
|
});
|
|
47
|
-
|
|
48
47
|
if (taskMapper.length <= 0) {
|
|
49
48
|
console.info(chalk.yellow(`'${platform}' is undefined task`));
|
|
50
49
|
return;
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
lm.showCompiling();
|
|
54
|
-
await pMap(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
event: { data: true, error: true },
|
|
62
|
-
});
|
|
53
|
+
await pMap(
|
|
54
|
+
taskMapper,
|
|
55
|
+
async ({ taskPath, params, logger: _ }: any) => {
|
|
56
|
+
const childProcess = execa.node(taskPath, params, {
|
|
57
|
+
stdio: 'inherit',
|
|
58
|
+
all: true,
|
|
59
|
+
});
|
|
63
60
|
|
|
64
|
-
|
|
61
|
+
// lm.addStdout(logger, childProcess.stdout, {
|
|
62
|
+
// event: { data: true, error: true },
|
|
63
|
+
// });
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
// lm.addStderr(logger, childProcess.stderr);
|
|
66
|
+
try {
|
|
67
|
+
await childProcess;
|
|
68
|
+
} catch {
|
|
69
|
+
// eslint-disable-next-line no-process-exit
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
// lm.disappearCompiling();
|
|
73
|
+
// console.info(lg.colors.title(title));
|
|
74
|
+
// console.info(a.all);
|
|
75
|
+
},
|
|
76
|
+
{ concurrency: 1 },
|
|
77
|
+
);
|
|
71
78
|
|
|
72
|
-
lm.disappearCompiling();
|
|
73
|
-
for (const key of Object.keys(loggerMap)) {
|
|
74
|
-
|
|
75
|
-
}
|
|
79
|
+
// lm.disappearCompiling();
|
|
80
|
+
// for (const key of Object.keys(loggerMap)) {
|
|
81
|
+
// console.info(loggerMap[key].value);
|
|
82
|
+
// }
|
|
76
83
|
};
|
|
@@ -34,6 +34,7 @@ export const buildInWatchMode = async (
|
|
|
34
34
|
const styleLog = lm.createLoggerText({
|
|
35
35
|
title: constants.runStyleCompilerTitle,
|
|
36
36
|
});
|
|
37
|
+
const copyLog = lm.createLoggerText({ title: 'Copy Log:' });
|
|
37
38
|
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
38
39
|
const taskMapper: ITaskMapper[] = [
|
|
39
40
|
...utils.getCodeMapper({
|
|
@@ -49,6 +50,11 @@ export const buildInWatchMode = async (
|
|
|
49
50
|
logger: styleLog,
|
|
50
51
|
taskPath: require.resolve('../../tasks/build-watch-style'),
|
|
51
52
|
},
|
|
53
|
+
{
|
|
54
|
+
logger: copyLog,
|
|
55
|
+
taskPath: require.resolve('../../tasks/copy-assets'),
|
|
56
|
+
params: ['--watch'],
|
|
57
|
+
},
|
|
52
58
|
];
|
|
53
59
|
lm.on('data', () => {
|
|
54
60
|
console.info(constants.clearFlag);
|
|
@@ -78,7 +84,7 @@ export const buildInWatchMode = async (
|
|
|
78
84
|
});
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
if (logger === styleLog) {
|
|
87
|
+
if (logger === styleLog || logger === copyLog) {
|
|
82
88
|
lm.addStdout(logger, childProcess.stdout, {
|
|
83
89
|
event: { error: true, data: true },
|
|
84
90
|
// colors: { data: s => s },
|
|
@@ -8,27 +8,37 @@ const buildWatchFeature: typeof import('./build-watch') = Import.lazy(
|
|
|
8
8
|
'./build-watch',
|
|
9
9
|
require,
|
|
10
10
|
);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const bp: typeof import('./build-platform') = Import.lazy(
|
|
12
|
+
'./build-platform',
|
|
13
|
+
require,
|
|
14
|
+
);
|
|
15
15
|
|
|
16
16
|
export const build = async (
|
|
17
17
|
config: IBuildConfig,
|
|
18
18
|
modernConfig: NormalizedConfig,
|
|
19
19
|
) => {
|
|
20
|
-
const {
|
|
20
|
+
const {
|
|
21
|
+
appDirectory,
|
|
22
|
+
enableWatchMode,
|
|
23
|
+
platform,
|
|
24
|
+
clear = true,
|
|
25
|
+
isTsProject,
|
|
26
|
+
} = config;
|
|
21
27
|
const {
|
|
22
28
|
output: { path: outputPath = 'dist' },
|
|
23
29
|
} = modernConfig;
|
|
24
30
|
// TODO: maybe need watch mode in build platform
|
|
25
31
|
if (typeof platform === 'boolean' && platform) {
|
|
26
|
-
|
|
32
|
+
if (process.env.RUN_PLATFORM) {
|
|
33
|
+
await bp.buildPlatform({ platform: 'all', isTsProject });
|
|
34
|
+
}
|
|
27
35
|
return;
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
if (typeof platform === 'string') {
|
|
31
|
-
|
|
39
|
+
if (process.env.RUN_PLATFORM) {
|
|
40
|
+
await bp.buildPlatform({ platform, isTsProject });
|
|
41
|
+
}
|
|
32
42
|
return;
|
|
33
43
|
}
|
|
34
44
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Import, fs } from '@modern-js/utils';
|
|
2
|
-
import type { NormalizedConfig } from '@modern-js/core';
|
|
2
|
+
import type { NormalizedConfig, CoreOptions } from '@modern-js/core';
|
|
3
3
|
import type { BabelOptions, IVirtualDist } from '@modern-js/babel-compiler';
|
|
4
4
|
import type { ITsconfig } from '../types';
|
|
5
|
+
import { initEnv } from '../utils/init-env';
|
|
5
6
|
|
|
6
7
|
const babelCompiler: typeof import('@modern-js/babel-compiler') = Import.lazy(
|
|
7
8
|
'@modern-js/babel-compiler',
|
|
@@ -138,18 +139,6 @@ const generatorRealFiles = (virtualDists: IVirtualDist[]) => {
|
|
|
138
139
|
}
|
|
139
140
|
};
|
|
140
141
|
|
|
141
|
-
export const initEnv = ({ syntax, type }: ITaskConfig) => {
|
|
142
|
-
if (syntax === 'es6+' && type === 'commonjs') {
|
|
143
|
-
return 'nodejs';
|
|
144
|
-
} else if (syntax === 'es6+' && type === 'module') {
|
|
145
|
-
return 'modern';
|
|
146
|
-
} else if (syntax === 'es5' && type === 'module') {
|
|
147
|
-
return 'legacy-browser';
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return '';
|
|
151
|
-
};
|
|
152
|
-
|
|
153
142
|
interface ITaskConfig {
|
|
154
143
|
srcRootDir: string; // 源码的根目录
|
|
155
144
|
willCompilerDirOrFile: string; // 用于编译的源码文件或者源码目录
|
|
@@ -180,11 +169,11 @@ const taskMain = async ({
|
|
|
180
169
|
}: {
|
|
181
170
|
modernConfig: NormalizedConfig;
|
|
182
171
|
}) => {
|
|
183
|
-
//
|
|
172
|
+
// Execution of the script's parameter handling and related required configuration acquisition
|
|
184
173
|
const processArgv = argv(process.argv.slice(2));
|
|
185
174
|
const config = processArgv<ITaskConfig>(defaultConfig);
|
|
186
|
-
|
|
187
|
-
const compiler = Compiler.babel; //
|
|
175
|
+
process.env.BUILD_FORMAT = initEnv(config);
|
|
176
|
+
const compiler = Compiler.babel; // Currently, only babel is supported.
|
|
188
177
|
const babelConfig = bc.resolveBabelConfig(config.appDirectory, modernConfig, {
|
|
189
178
|
sourceAbsDir: config.srcRootDir,
|
|
190
179
|
tsconfigPath: config.tsconfigPath,
|
|
@@ -229,7 +218,11 @@ const taskMain = async ({
|
|
|
229
218
|
};
|
|
230
219
|
|
|
231
220
|
(async () => {
|
|
232
|
-
|
|
221
|
+
let options: CoreOptions | undefined;
|
|
222
|
+
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
223
|
+
({ options } = require(process.env.CORE_INIT_OPTION_FILE));
|
|
224
|
+
}
|
|
225
|
+
const { resolved } = await core.cli.init([], options);
|
|
233
226
|
await core.manager.run(async () => {
|
|
234
227
|
try {
|
|
235
228
|
await taskMain({ modernConfig: resolved });
|