@modern-js/module-tools 1.0.0-alpha.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.
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/bin/modern.js +3 -0
- package/dist/js/modern/cli/build.js +9 -0
- package/dist/js/modern/cli/dev.js +8 -0
- package/dist/js/modern/cli/index.js +3 -0
- package/dist/js/modern/cli/new.js +16 -0
- package/dist/js/modern/commands/build.js +56 -0
- package/dist/js/modern/commands/dev.js +29 -0
- package/dist/js/modern/commands/index.js +2 -0
- package/dist/js/modern/features/build/build-platform.js +70 -0
- package/dist/js/modern/features/build/build-watch.js +96 -0
- package/dist/js/modern/features/build/build.js +110 -0
- package/dist/js/modern/features/build/constants.js +66 -0
- package/dist/js/modern/features/build/index.js +29 -0
- package/dist/js/modern/features/build/logger/index.js +2 -0
- package/dist/js/modern/features/build/logger/logText.js +63 -0
- package/dist/js/modern/features/build/logger/loggerManager.js +101 -0
- package/dist/js/modern/features/build/utils.js +198 -0
- package/dist/js/modern/features/dev/index.js +41 -0
- package/dist/js/modern/index.js +46 -0
- package/dist/js/modern/locale/en.js +23 -0
- package/dist/js/modern/locale/index.js +10 -0
- package/dist/js/modern/locale/zh.js +23 -0
- package/dist/js/modern/schema/index.js +3 -0
- package/dist/js/modern/schema/output.js +29 -0
- package/dist/js/modern/schema/source.js +15 -0
- package/dist/js/modern/tasks/build-source-code.js +213 -0
- package/dist/js/modern/tasks/build-style.js +152 -0
- package/dist/js/modern/tasks/build-watch-source-code.js +144 -0
- package/dist/js/modern/tasks/build-watch-style.js +213 -0
- package/dist/js/modern/tasks/constants.js +1 -0
- package/dist/js/modern/tasks/copy-assets.js +108 -0
- package/dist/js/modern/tasks/generator-dts.js +220 -0
- package/dist/js/modern/types.js +0 -0
- package/dist/js/modern/utils/babel.js +85 -0
- package/dist/js/modern/utils/color.js +2 -0
- package/dist/js/modern/utils/copy.js +80 -0
- package/dist/js/modern/utils/json.js +13 -0
- package/dist/js/modern/utils/language.js +6 -0
- package/dist/js/modern/utils/logger.js +110 -0
- package/dist/js/modern/utils/readline.js +19 -0
- package/dist/js/modern/utils/tsconfig.js +15 -0
- package/dist/js/modern/utils/tspaths-transform/constants.js +3 -0
- package/dist/js/modern/utils/tspaths-transform/index.js +130 -0
- package/dist/js/modern/utils/tspaths-transform/utils.js +21 -0
- package/dist/js/modern/utils/valide.js +28 -0
- package/dist/js/node/cli/build.js +21 -0
- package/dist/js/node/cli/dev.js +20 -0
- package/dist/js/node/cli/index.js +44 -0
- package/dist/js/node/cli/new.js +28 -0
- package/dist/js/node/commands/build.js +76 -0
- package/dist/js/node/commands/dev.js +49 -0
- package/dist/js/node/commands/index.js +21 -0
- package/dist/js/node/features/build/build-platform.js +84 -0
- package/dist/js/node/features/build/build-watch.js +118 -0
- package/dist/js/node/features/build/build.js +133 -0
- package/dist/js/node/features/build/constants.js +79 -0
- package/dist/js/node/features/build/index.js +41 -0
- package/dist/js/node/features/build/logger/index.js +31 -0
- package/dist/js/node/features/build/logger/logText.js +79 -0
- package/dist/js/node/features/build/logger/loggerManager.js +111 -0
- package/dist/js/node/features/build/utils.js +231 -0
- package/dist/js/node/features/dev/index.js +60 -0
- package/dist/js/node/index.js +64 -0
- package/dist/js/node/locale/en.js +30 -0
- package/dist/js/node/locale/index.js +22 -0
- package/dist/js/node/locale/zh.js +30 -0
- package/dist/js/node/schema/index.js +14 -0
- package/dist/js/node/schema/output.js +36 -0
- package/dist/js/node/schema/source.js +22 -0
- package/dist/js/node/tasks/build-source-code.js +240 -0
- package/dist/js/node/tasks/build-style.js +168 -0
- package/dist/js/node/tasks/build-watch-source-code.js +156 -0
- package/dist/js/node/tasks/build-watch-style.js +231 -0
- package/dist/js/node/tasks/constants.js +8 -0
- package/dist/js/node/tasks/copy-assets.js +126 -0
- package/dist/js/node/tasks/generator-dts.js +243 -0
- package/dist/js/node/types.js +0 -0
- package/dist/js/node/utils/babel.js +99 -0
- package/dist/js/node/utils/color.js +12 -0
- package/dist/js/node/utils/copy.js +99 -0
- package/dist/js/node/utils/json.js +22 -0
- package/dist/js/node/utils/language.js +15 -0
- package/dist/js/node/utils/logger.js +133 -0
- package/dist/js/node/utils/readline.js +33 -0
- package/dist/js/node/utils/tsconfig.js +30 -0
- package/dist/js/node/utils/tspaths-transform/constants.js +10 -0
- package/dist/js/node/utils/tspaths-transform/index.js +155 -0
- package/dist/js/node/utils/tspaths-transform/utils.js +32 -0
- package/dist/js/node/utils/valide.js +41 -0
- package/dist/types/cli/build.d.ts +2 -0
- package/dist/types/cli/dev.d.ts +2 -0
- package/dist/types/cli/index.d.ts +3 -0
- package/dist/types/cli/new.d.ts +2 -0
- package/dist/types/commands/build.d.ts +16 -0
- package/dist/types/commands/dev.d.ts +4 -0
- package/dist/types/commands/index.d.ts +2 -0
- package/dist/types/features/build/build-platform.d.ts +6 -0
- package/dist/types/features/build/build-watch.d.ts +3 -0
- package/dist/types/features/build/build.d.ts +3 -0
- package/dist/types/features/build/constants.d.ts +14 -0
- package/dist/types/features/build/index.d.ts +3 -0
- package/dist/types/features/build/logger/index.d.ts +2 -0
- package/dist/types/features/build/logger/logText.d.ts +39 -0
- package/dist/types/features/build/logger/loggerManager.d.ts +39 -0
- package/dist/types/features/build/utils.d.ts +58 -0
- package/dist/types/features/dev/index.d.ts +7 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/locale/en.d.ts +23 -0
- package/dist/types/locale/index.d.ts +47 -0
- package/dist/types/locale/zh.d.ts +23 -0
- package/dist/types/schema/index.d.ts +36 -0
- package/dist/types/schema/output.d.ts +22 -0
- package/dist/types/schema/source.d.ts +15 -0
- package/dist/types/tasks/build-source-code.d.ts +42 -0
- package/dist/types/tasks/build-style.d.ts +1 -0
- package/dist/types/tasks/build-watch-source-code.d.ts +1 -0
- package/dist/types/tasks/build-watch-style.d.ts +1 -0
- package/dist/types/tasks/constants.d.ts +1 -0
- package/dist/types/tasks/copy-assets.d.ts +1 -0
- package/dist/types/tasks/generator-dts.d.ts +1 -0
- package/dist/types/types.d.ts +48 -0
- package/dist/types/utils/babel.d.ts +8 -0
- package/dist/types/utils/color.d.ts +2 -0
- package/dist/types/utils/copy.d.ts +5 -0
- package/dist/types/utils/json.d.ts +4 -0
- package/dist/types/utils/language.d.ts +1 -0
- package/dist/types/utils/logger.d.ts +56 -0
- package/dist/types/utils/readline.d.ts +9 -0
- package/dist/types/utils/tsconfig.d.ts +16 -0
- package/dist/types/utils/tspaths-transform/constants.d.ts +1 -0
- package/dist/types/utils/tspaths-transform/index.d.ts +15 -0
- package/dist/types/utils/tspaths-transform/utils.d.ts +4 -0
- package/dist/types/utils/valide.d.ts +12 -0
- package/modern.config.js +6 -0
- package/package.json +95 -0
- package/src/.eslintrc.json +5 -0
- package/src/cli/build.ts +39 -0
- package/src/cli/dev.ts +24 -0
- package/src/cli/index.ts +3 -0
- package/src/cli/new.ts +32 -0
- package/src/commands/build.ts +81 -0
- package/src/commands/dev.ts +41 -0
- package/src/commands/index.ts +2 -0
- package/src/features/build/build-platform.ts +76 -0
- package/src/features/build/build-watch.ts +93 -0
- package/src/features/build/build.ts +111 -0
- package/src/features/build/constants.ts +52 -0
- package/src/features/build/index.ts +36 -0
- package/src/features/build/logger/index.ts +2 -0
- package/src/features/build/logger/logText.ts +80 -0
- package/src/features/build/logger/loggerManager.ts +132 -0
- package/src/features/build/utils.ts +250 -0
- package/src/features/dev/index.ts +62 -0
- package/src/index.ts +55 -0
- package/src/locale/en.ts +21 -0
- package/src/locale/index.ts +15 -0
- package/src/locale/zh.ts +21 -0
- package/src/schema/index.ts +4 -0
- package/src/schema/output.ts +34 -0
- package/src/schema/schema.d.ts +13 -0
- package/src/schema/source.ts +16 -0
- package/src/tasks/build-source-code.ts +245 -0
- package/src/tasks/build-style.ts +175 -0
- package/src/tasks/build-watch-source-code.ts +185 -0
- package/src/tasks/build-watch-style.ts +260 -0
- package/src/tasks/constants.ts +1 -0
- package/src/tasks/copy-assets.ts +117 -0
- package/src/tasks/generator-dts.ts +277 -0
- package/src/type.d.ts +1 -0
- package/src/types.ts +63 -0
- package/src/utils/babel.ts +100 -0
- package/src/utils/color.ts +3 -0
- package/src/utils/copy.ts +70 -0
- package/src/utils/json.ts +13 -0
- package/src/utils/language.ts +9 -0
- package/src/utils/logger.ts +144 -0
- package/src/utils/readline.ts +28 -0
- package/src/utils/tsconfig.ts +37 -0
- package/src/utils/tspaths-transform/constants.ts +19 -0
- package/src/utils/tspaths-transform/index.ts +139 -0
- package/src/utils/tspaths-transform/utils.ts +25 -0
- package/src/utils/valide.ts +37 -0
- package/tsconfig.json +13 -0
- package/types.d.ts +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "build", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _build.build;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "dev", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _dev.dev;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var _dev = require("./dev");
|
|
20
|
+
|
|
21
|
+
var _build = require("./build");
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildPlatform = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("@modern-js/utils");
|
|
9
|
+
|
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
11
|
+
|
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
13
|
+
|
|
14
|
+
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
|
+
|
|
16
|
+
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
17
|
+
|
|
18
|
+
const execa = _utils.Import.lazy('execa', require);
|
|
19
|
+
|
|
20
|
+
const lg = _utils.Import.lazy('./logger', require);
|
|
21
|
+
|
|
22
|
+
const pMap = _utils.Import.lazy('p-map', require);
|
|
23
|
+
|
|
24
|
+
const buildPlatform = async option => {
|
|
25
|
+
const {
|
|
26
|
+
isTsProject = false,
|
|
27
|
+
platform
|
|
28
|
+
} = option;
|
|
29
|
+
const lm = new lg.LoggerManager(); // 获取platforms的参数
|
|
30
|
+
|
|
31
|
+
const buildTasks = await core.mountHook().platformBuild({
|
|
32
|
+
isTsProject
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (buildTasks.length <= 0) {
|
|
36
|
+
console.info(_utils.chalk.yellow('No build tasks detected.\nYou can use the `new` command to enable the more features'));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const loggerMap = {};
|
|
41
|
+
const taskMapper = buildTasks.filter(task => platform === 'all' || task.name === platform).map(params => {
|
|
42
|
+
const logger = lm.createLoggerText({
|
|
43
|
+
title: params.title
|
|
44
|
+
});
|
|
45
|
+
loggerMap[params.name] = logger;
|
|
46
|
+
return _objectSpread({
|
|
47
|
+
logger
|
|
48
|
+
}, params);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (taskMapper.length <= 0) {
|
|
52
|
+
console.info(_utils.chalk.yellow(`'${platform}' is undefined task`));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
lm.showCompiling();
|
|
57
|
+
await pMap(taskMapper, async ({
|
|
58
|
+
taskPath,
|
|
59
|
+
params,
|
|
60
|
+
logger
|
|
61
|
+
}) => {
|
|
62
|
+
const childProcess = execa.node(taskPath, params, {
|
|
63
|
+
stdio: 'pipe',
|
|
64
|
+
all: true
|
|
65
|
+
});
|
|
66
|
+
lm.addStdout(logger, childProcess.stdout, {
|
|
67
|
+
event: {
|
|
68
|
+
data: true,
|
|
69
|
+
error: true
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
lm.addStderr(logger, childProcess.stderr);
|
|
73
|
+
await childProcess; // lm.disappearCompiling();
|
|
74
|
+
// console.info(lg.colors.title(title));
|
|
75
|
+
// console.info(a.all);
|
|
76
|
+
});
|
|
77
|
+
lm.disappearCompiling();
|
|
78
|
+
|
|
79
|
+
for (const key of Object.keys(loggerMap)) {
|
|
80
|
+
console.info(loggerMap[key].value);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
exports.buildPlatform = buildPlatform;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildInWatchMode = void 0;
|
|
7
|
+
|
|
8
|
+
var path = _interopRequireWildcard(require("path"));
|
|
9
|
+
|
|
10
|
+
var os = _interopRequireWildcard(require("os"));
|
|
11
|
+
|
|
12
|
+
var _utils = require("@modern-js/utils");
|
|
13
|
+
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
19
|
+
|
|
20
|
+
const execa = _utils.Import.lazy('execa', require);
|
|
21
|
+
|
|
22
|
+
const lg = _utils.Import.lazy('./logger', require);
|
|
23
|
+
|
|
24
|
+
const pMap = _utils.Import.lazy('p-map', require);
|
|
25
|
+
|
|
26
|
+
const utils = _utils.Import.lazy('./utils', require);
|
|
27
|
+
|
|
28
|
+
const constants = _utils.Import.lazy('./constants', require);
|
|
29
|
+
|
|
30
|
+
const buildInWatchMode = async (config, _) => {
|
|
31
|
+
const {
|
|
32
|
+
appDirectory
|
|
33
|
+
} = core.useAppContext().value;
|
|
34
|
+
const {
|
|
35
|
+
sourceDir,
|
|
36
|
+
enableTscCompiler
|
|
37
|
+
} = config;
|
|
38
|
+
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
39
|
+
const concurrency = os.cpus().length;
|
|
40
|
+
const lm = new lg.LoggerManager();
|
|
41
|
+
const codeLog = lm.createLoggerText({
|
|
42
|
+
title: constants.runBabelCompilerTitle
|
|
43
|
+
});
|
|
44
|
+
const dtsLog = lm.createLoggerText({
|
|
45
|
+
title: constants.runTscWatchTitle
|
|
46
|
+
});
|
|
47
|
+
const styleLog = lm.createLoggerText({
|
|
48
|
+
title: constants.runStyleCompilerTitle
|
|
49
|
+
});
|
|
50
|
+
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
51
|
+
const taskMapper = [...utils.getCodeMapper({
|
|
52
|
+
logger: codeLog,
|
|
53
|
+
taskPath: require.resolve("../../tasks/build-watch-source-code"),
|
|
54
|
+
config,
|
|
55
|
+
willCompilerDirOrFile: sourceDir,
|
|
56
|
+
initMapper: initCodeMapper,
|
|
57
|
+
srcRootDir
|
|
58
|
+
}), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
|
|
59
|
+
logger: styleLog,
|
|
60
|
+
taskPath: require.resolve("../../tasks/build-watch-style")
|
|
61
|
+
}];
|
|
62
|
+
lm.on('data', () => {
|
|
63
|
+
console.info(constants.clearFlag);
|
|
64
|
+
enableTscCompiler && console.info(dtsLog.value);
|
|
65
|
+
console.info(codeLog.value);
|
|
66
|
+
console.info(styleLog.value);
|
|
67
|
+
});
|
|
68
|
+
await pMap(taskMapper, async ({
|
|
69
|
+
logger,
|
|
70
|
+
taskPath,
|
|
71
|
+
params
|
|
72
|
+
}) => {
|
|
73
|
+
const childProcess = execa.node(taskPath, params, {
|
|
74
|
+
stdio: 'pipe'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (logger === codeLog) {
|
|
78
|
+
lm.addStdout(logger, childProcess.stdout, {
|
|
79
|
+
event: {
|
|
80
|
+
error: true,
|
|
81
|
+
data: true
|
|
82
|
+
} // colors: { data: s => s },
|
|
83
|
+
|
|
84
|
+
});
|
|
85
|
+
lm.addStderr(logger, childProcess.stderr);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (logger === dtsLog) {
|
|
89
|
+
lm.addStdout(logger, childProcess.stdout, {
|
|
90
|
+
event: {
|
|
91
|
+
data: true,
|
|
92
|
+
error: true
|
|
93
|
+
},
|
|
94
|
+
colors: {
|
|
95
|
+
// tsc 的log信息无论是错误还是正确都是从 data event 中获取到的
|
|
96
|
+
data: s => s
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (logger === styleLog) {
|
|
102
|
+
lm.addStdout(logger, childProcess.stdout, {
|
|
103
|
+
event: {
|
|
104
|
+
error: true,
|
|
105
|
+
data: true
|
|
106
|
+
} // colors: { data: s => s },
|
|
107
|
+
|
|
108
|
+
});
|
|
109
|
+
lm.addStderr(logger, childProcess.stderr);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
await childProcess;
|
|
113
|
+
}, {
|
|
114
|
+
concurrency
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
exports.buildInWatchMode = buildInWatchMode;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildSourceCode = void 0;
|
|
7
|
+
|
|
8
|
+
var path = _interopRequireWildcard(require("path"));
|
|
9
|
+
|
|
10
|
+
var os = _interopRequireWildcard(require("os"));
|
|
11
|
+
|
|
12
|
+
var _utils = require("@modern-js/utils");
|
|
13
|
+
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
/* eslint-disable max-statements */
|
|
19
|
+
const pMap = _utils.Import.lazy('p-map', require);
|
|
20
|
+
|
|
21
|
+
const utils = _utils.Import.lazy('./utils', require);
|
|
22
|
+
|
|
23
|
+
const execa = _utils.Import.lazy('execa', require);
|
|
24
|
+
|
|
25
|
+
const lg = _utils.Import.lazy('./logger', require);
|
|
26
|
+
|
|
27
|
+
const constants = _utils.Import.lazy('./constants', require);
|
|
28
|
+
|
|
29
|
+
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
30
|
+
|
|
31
|
+
const buildSourceCode = async (config, _) => {
|
|
32
|
+
const {
|
|
33
|
+
sourceDir,
|
|
34
|
+
enableTscCompiler
|
|
35
|
+
} = config;
|
|
36
|
+
const {
|
|
37
|
+
appDirectory
|
|
38
|
+
} = core.useAppContext().value;
|
|
39
|
+
const concurrency = os.cpus().length;
|
|
40
|
+
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
41
|
+
const lm = new lg.LoggerManager();
|
|
42
|
+
const codeLog = lm.createLoggerText({
|
|
43
|
+
title: constants.runBabelCompilerTitle
|
|
44
|
+
});
|
|
45
|
+
const dtsLog = lm.createLoggerText({
|
|
46
|
+
title: constants.runTscTitle
|
|
47
|
+
});
|
|
48
|
+
const styleLog = lm.createLoggerText({
|
|
49
|
+
title: constants.runStyleCompilerTitle
|
|
50
|
+
});
|
|
51
|
+
const copyLog = lm.createLoggerText({
|
|
52
|
+
title: 'Copy Log:'
|
|
53
|
+
});
|
|
54
|
+
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
55
|
+
const taskMapper = [...utils.getCodeMapper({
|
|
56
|
+
logger: codeLog,
|
|
57
|
+
taskPath: require.resolve("../../tasks/build-source-code"),
|
|
58
|
+
config,
|
|
59
|
+
willCompilerDirOrFile: sourceDir,
|
|
60
|
+
initMapper: initCodeMapper,
|
|
61
|
+
srcRootDir
|
|
62
|
+
}), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
|
|
63
|
+
logger: styleLog,
|
|
64
|
+
taskPath: require.resolve("../../tasks/build-style")
|
|
65
|
+
}, {
|
|
66
|
+
logger: copyLog,
|
|
67
|
+
taskPath: require.resolve("../../tasks/copy-assets")
|
|
68
|
+
}];
|
|
69
|
+
lm.showCompiling();
|
|
70
|
+
await pMap(taskMapper, async ({
|
|
71
|
+
logger,
|
|
72
|
+
taskPath,
|
|
73
|
+
params
|
|
74
|
+
}) => {
|
|
75
|
+
const childProcess = execa.node(taskPath, params, {
|
|
76
|
+
stdio: 'pipe'
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (logger === codeLog || logger === copyLog) {
|
|
80
|
+
lm.addStdout(logger, childProcess.stdout, {
|
|
81
|
+
event: {
|
|
82
|
+
data: true,
|
|
83
|
+
error: true
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
lm.addStderr(logger, childProcess.stderr);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (logger === dtsLog) {
|
|
90
|
+
lm.addStdout(dtsLog, childProcess.stdout, {
|
|
91
|
+
event: {
|
|
92
|
+
data: true,
|
|
93
|
+
error: true
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
lm.addStderr(dtsLog, childProcess.stderr);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (logger === styleLog) {
|
|
100
|
+
lm.addStdout(logger, childProcess.stdout, {
|
|
101
|
+
event: {
|
|
102
|
+
data: true,
|
|
103
|
+
error: true
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
lm.addStderr(logger, childProcess.stderr);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
await childProcess;
|
|
110
|
+
}, {
|
|
111
|
+
concurrency
|
|
112
|
+
});
|
|
113
|
+
lm.disappearCompiling();
|
|
114
|
+
enableTscCompiler && console.info(dtsLog.value);
|
|
115
|
+
console.info(codeLog.value);
|
|
116
|
+
|
|
117
|
+
if (styleLog.hasMessages()) {
|
|
118
|
+
console.info(styleLog.value);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (copyLog.hasMessages()) {
|
|
122
|
+
console.info(copyLog.value);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (dtsLog.hasErrorMessage || codeLog.hasErrorMessage || styleLog.hasErrorMessage || copyLog.hasErrorMessage) {
|
|
126
|
+
// eslint-disable-next-line no-process-exit
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
/* eslint-enable max-statements */
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
exports.buildSourceCode = buildSourceCode;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.runTscWatchTitle = exports.runTscTitle = exports.runStyleCompilerTitle = exports.runBabelCompilerTitle = exports.clearFlag = exports.PACKAGE_MODES = exports.DEFAULT_PACKAGE_MODE = void 0;
|
|
7
|
+
// Universal JS 的默认选择,三份构建产物,支持 Node.js,对现代浏览器有优化
|
|
8
|
+
const universalJs = [{
|
|
9
|
+
type: 'module',
|
|
10
|
+
syntax: 'es5',
|
|
11
|
+
outDir: 'treeshaking'
|
|
12
|
+
}, {
|
|
13
|
+
type: 'commonjs',
|
|
14
|
+
syntax: 'es6+',
|
|
15
|
+
outDir: 'node'
|
|
16
|
+
}, {
|
|
17
|
+
type: 'module',
|
|
18
|
+
syntax: 'es6+',
|
|
19
|
+
outDir: 'modern'
|
|
20
|
+
}]; // Universal JS 的优化选择,两份构建产物,对现代浏览器无优化
|
|
21
|
+
|
|
22
|
+
const universalJsLite = [{
|
|
23
|
+
type: 'module',
|
|
24
|
+
syntax: 'es5',
|
|
25
|
+
outDir: 'treeshaking'
|
|
26
|
+
}, {
|
|
27
|
+
type: 'commonjs',
|
|
28
|
+
syntax: 'es6+',
|
|
29
|
+
outDir: 'node',
|
|
30
|
+
copyDirs: ['modern']
|
|
31
|
+
}]; // 纯前端代码的默认选择,两份构建产物
|
|
32
|
+
|
|
33
|
+
const browserJs = [{
|
|
34
|
+
type: 'module',
|
|
35
|
+
syntax: 'es5',
|
|
36
|
+
outDir: 'treeshaking',
|
|
37
|
+
copyDirs: ['node']
|
|
38
|
+
}, {
|
|
39
|
+
type: 'module',
|
|
40
|
+
syntax: 'es6+',
|
|
41
|
+
outDir: 'modern'
|
|
42
|
+
}]; // 纯前端代码的优化选择,单份构建产物,对现代浏览器无优化
|
|
43
|
+
|
|
44
|
+
const browserJsLite = [{
|
|
45
|
+
type: 'module',
|
|
46
|
+
syntax: 'es5',
|
|
47
|
+
outDir: 'treeshaking',
|
|
48
|
+
copyDirs: ['modern', 'node']
|
|
49
|
+
}]; // 纯 Node.js 代码的默认选择,两份构建产物
|
|
50
|
+
|
|
51
|
+
const nodeJs = [{
|
|
52
|
+
type: 'commonjs',
|
|
53
|
+
syntax: 'es6+',
|
|
54
|
+
outDir: 'node'
|
|
55
|
+
}, {
|
|
56
|
+
type: 'module',
|
|
57
|
+
syntax: 'es6+',
|
|
58
|
+
outDir: 'modern'
|
|
59
|
+
}];
|
|
60
|
+
const DEFAULT_PACKAGE_MODE = 'universal-js';
|
|
61
|
+
exports.DEFAULT_PACKAGE_MODE = DEFAULT_PACKAGE_MODE;
|
|
62
|
+
const PACKAGE_MODES = {
|
|
63
|
+
'universal-js': universalJs,
|
|
64
|
+
'universal-js-lite': universalJsLite,
|
|
65
|
+
'browser-js': browserJs,
|
|
66
|
+
'browser-js-lite': browserJsLite,
|
|
67
|
+
'node-js': nodeJs
|
|
68
|
+
};
|
|
69
|
+
exports.PACKAGE_MODES = PACKAGE_MODES;
|
|
70
|
+
const runBabelCompilerTitle = 'Run babel compiler code log';
|
|
71
|
+
exports.runBabelCompilerTitle = runBabelCompilerTitle;
|
|
72
|
+
const runTscWatchTitle = 'Run `tsc -w` log';
|
|
73
|
+
exports.runTscWatchTitle = runTscWatchTitle;
|
|
74
|
+
const runTscTitle = 'Run `tsc` log';
|
|
75
|
+
exports.runTscTitle = runTscTitle;
|
|
76
|
+
const runStyleCompilerTitle = 'Run style compiler code log';
|
|
77
|
+
exports.runStyleCompilerTitle = runStyleCompilerTitle;
|
|
78
|
+
const clearFlag = '\x1Bc';
|
|
79
|
+
exports.clearFlag = clearFlag;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.build = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("@modern-js/utils");
|
|
9
|
+
|
|
10
|
+
const buildFeature = _utils.Import.lazy('./build', require);
|
|
11
|
+
|
|
12
|
+
const buildWatchFeature = _utils.Import.lazy('./build-watch', require); // const bp: typeof import('./build-platform') = Import.lazy(
|
|
13
|
+
// './build-platform',
|
|
14
|
+
// require,
|
|
15
|
+
// );
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const build = async (config, modernConfig) => {
|
|
19
|
+
const {
|
|
20
|
+
enableWatchMode,
|
|
21
|
+
platform
|
|
22
|
+
} = config; // TODO: maybe need watch mode in build platform
|
|
23
|
+
|
|
24
|
+
if (typeof platform === 'boolean' && platform) {
|
|
25
|
+
// await bp.buildPlatform({ platform: 'all', isTsProject });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof platform === 'string') {
|
|
30
|
+
// await bp.buildPlatform({ platform, isTsProject });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (enableWatchMode) {
|
|
35
|
+
await buildWatchFeature.buildInWatchMode(config, modernConfig);
|
|
36
|
+
} else {
|
|
37
|
+
await buildFeature.buildSourceCode(config, modernConfig);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
exports.build = build;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _logText = require("./logText");
|
|
8
|
+
|
|
9
|
+
Object.keys(_logText).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _logText[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _logText[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _loggerManager = require("./loggerManager");
|
|
21
|
+
|
|
22
|
+
Object.keys(_loggerManager).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _loggerManager[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _loggerManager[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.logTemplate = exports.colors = exports.clearFlag = exports.LoggerText = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("@modern-js/utils");
|
|
9
|
+
|
|
10
|
+
const colors = {
|
|
11
|
+
title: _utils.chalk.rgb(218, 152, 92)
|
|
12
|
+
};
|
|
13
|
+
exports.colors = colors;
|
|
14
|
+
const clearFlag = '\x1Bc';
|
|
15
|
+
exports.clearFlag = clearFlag;
|
|
16
|
+
|
|
17
|
+
const logTemplate = (title, messageStack, {
|
|
18
|
+
noBottomBorder: _noBottomBorder = false,
|
|
19
|
+
bottomBorderText: _bottomBorderText = '',
|
|
20
|
+
noLeftBorder: _noLeftBorder = false,
|
|
21
|
+
leftBorder: _leftBorder = '',
|
|
22
|
+
contentColor: _contentColor = s => s
|
|
23
|
+
} = {}) => {
|
|
24
|
+
const maxLength = Infinity; // TODO: 考虑后面是否提供该参数
|
|
25
|
+
|
|
26
|
+
const leftBorderFlag = _noLeftBorder ? '' : _leftBorder;
|
|
27
|
+
const messageFragments = messageStack.map(p => {
|
|
28
|
+
p.trim();
|
|
29
|
+
return `${leftBorderFlag}${p.replace(clearFlag, '')}`;
|
|
30
|
+
}) // 移除 clearFlag
|
|
31
|
+
.filter(s => s !== leftBorderFlag) // 过滤空字符串
|
|
32
|
+
.slice(0, maxLength); // 控制长度
|
|
33
|
+
|
|
34
|
+
const template = `${colors.title(title)}:
|
|
35
|
+
${_contentColor(messageFragments.join(''))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
|
|
36
|
+
return template;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.logTemplate = logTemplate;
|
|
40
|
+
|
|
41
|
+
// 处理Log内容如何展示
|
|
42
|
+
class LoggerText {
|
|
43
|
+
constructor(option) {
|
|
44
|
+
this.messages = void 0;
|
|
45
|
+
this.hasErrorMessage = void 0;
|
|
46
|
+
this.option = void 0;
|
|
47
|
+
this.messages = [];
|
|
48
|
+
this.option = option;
|
|
49
|
+
this.hasErrorMessage = false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
append(message) {
|
|
53
|
+
if (message.includes(clearFlag)) {
|
|
54
|
+
this.messages = [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.messages.push(message);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
errorHappen() {
|
|
61
|
+
this.hasErrorMessage = true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
hasMessages() {
|
|
65
|
+
return this.messages.length > 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get value() {
|
|
69
|
+
const {
|
|
70
|
+
title,
|
|
71
|
+
contentConfig
|
|
72
|
+
} = this.option;
|
|
73
|
+
const messages = [...new Set(this.messages)];
|
|
74
|
+
return logTemplate(title, messages, contentConfig);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
exports.LoggerText = LoggerText;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LoggerManager = void 0;
|
|
7
|
+
|
|
8
|
+
var _events = _interopRequireDefault(require("events"));
|
|
9
|
+
|
|
10
|
+
var _utils = require("@modern-js/utils");
|
|
11
|
+
|
|
12
|
+
let _ = t => t,
|
|
13
|
+
_t;
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
|
|
17
|
+
const logText = _utils.Import.lazy('./logText', require);
|
|
18
|
+
|
|
19
|
+
const readline = _utils.Import.lazy('../../../utils/readline', require);
|
|
20
|
+
|
|
21
|
+
class LoggerManager extends _events.default {
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this._compilering = void 0;
|
|
25
|
+
this._listeners = void 0;
|
|
26
|
+
this._compilering = false;
|
|
27
|
+
this._listeners = [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
createLoggerText(option) {
|
|
31
|
+
return new logText.LoggerText(option);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
addStdout(loggerText, stdout, config = {}) {
|
|
35
|
+
const {
|
|
36
|
+
event = {
|
|
37
|
+
data: true,
|
|
38
|
+
error: true
|
|
39
|
+
},
|
|
40
|
+
colors = {
|
|
41
|
+
data: _utils.chalk.green,
|
|
42
|
+
error: _utils.chalk.red,
|
|
43
|
+
warning: _utils.chalk.yellow
|
|
44
|
+
}
|
|
45
|
+
} = config;
|
|
46
|
+
|
|
47
|
+
if (event.data) {
|
|
48
|
+
stdout === null || stdout === void 0 ? void 0 : stdout.on('data', chunk => {
|
|
49
|
+
const data = chunk.toString();
|
|
50
|
+
const content = colors.data ? colors.data(data) : _utils.chalk.green(data);
|
|
51
|
+
loggerText.append(content);
|
|
52
|
+
this.emit('data');
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (event.error) {
|
|
57
|
+
stdout === null || stdout === void 0 ? void 0 : stdout.on('error', error => {
|
|
58
|
+
console.info('error');
|
|
59
|
+
const data = error.message;
|
|
60
|
+
const content = colors.error ? colors.error(data) : _utils.chalk.red(data);
|
|
61
|
+
loggerText.append(content);
|
|
62
|
+
loggerText.errorHappen();
|
|
63
|
+
this.emit('data');
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
this._listeners.push(stdout);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
addStderr(loggerText, stderr, color = _utils.chalk.red) {
|
|
71
|
+
stderr === null || stderr === void 0 ? void 0 : stderr.on('data', chunk => {
|
|
72
|
+
const data = chunk.toString();
|
|
73
|
+
loggerText.append(color(data));
|
|
74
|
+
loggerText.errorHappen();
|
|
75
|
+
this.emit('data');
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
showCompiling() {
|
|
80
|
+
if (!this._compilering) {
|
|
81
|
+
this._compilering = true;
|
|
82
|
+
console.info(_utils.chalk.green(_t || (_t = _`Compiling in progress...`)));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
disappearCompiling() {
|
|
87
|
+
if (this._compilering) {
|
|
88
|
+
readline.ReadlineUtils.clearLine(process.stdout);
|
|
89
|
+
this._compilering = false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
listenDateAndShow(logTexts // stdout: NodeJS.WriteStream & {
|
|
94
|
+
// fd: 1;
|
|
95
|
+
// } = process.stdout,
|
|
96
|
+
) {
|
|
97
|
+
this.on('data', () => {
|
|
98
|
+
this.disappearCompiling();
|
|
99
|
+
const content = logTexts.map(logtext => logtext.value).join(''); // 每次更新,使用新的内容覆盖旧的内容,有几率出现内容错乱问题
|
|
100
|
+
|
|
101
|
+
console.info(content);
|
|
102
|
+
});
|
|
103
|
+
return () => {
|
|
104
|
+
// eslint-disable-next-line no-process-exit
|
|
105
|
+
process.exit(0);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
exports.LoggerManager = LoggerManager;
|