@modern-js/module-tools 1.5.8 → 1.6.1
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 +41 -0
- package/dist/js/modern/cli/build.js +5 -4
- package/dist/js/modern/commands/build.js +55 -28
- package/dist/js/modern/features/build/bundle/index.js +9 -0
- package/dist/js/modern/features/build/bundle/runRollup.js +149 -0
- package/dist/js/modern/features/build/bundle/runSpeedy.js +185 -0
- package/dist/js/modern/{tasks → features/build/bundleless}/copy-assets.js +31 -56
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -71
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +10 -10
- package/dist/js/modern/features/build/bundleless/index.js +23 -0
- package/dist/js/modern/features/build/bundleless/runBabel.js +269 -0
- package/dist/js/modern/features/build/bundleless/style.js +266 -0
- package/dist/js/modern/features/build/constants.js +94 -59
- package/dist/js/modern/features/build/error.js +150 -0
- package/dist/js/modern/features/build/index.js +87 -18
- package/dist/js/modern/features/build/legacy-constants.js +99 -0
- package/dist/js/modern/features/build/normalize.js +301 -0
- package/dist/js/modern/features/build/types.js +0 -0
- package/dist/js/modern/features/build/utils.js +39 -136
- package/dist/js/modern/index.js +3 -1
- package/dist/js/modern/locale/en.js +5 -3
- package/dist/js/modern/locale/zh.js +5 -3
- package/dist/js/modern/schema/build-config.js +111 -0
- package/dist/js/modern/schema/index.js +2 -1
- package/dist/js/modern/schema/output.js +18 -9
- package/dist/js/modern/schema/source.js +2 -10
- package/dist/js/modern/schema/tools.js +6 -0
- package/dist/js/modern/schema/types.js +0 -0
- package/dist/js/modern/utils/babel.js +4 -1
- package/dist/js/modern/utils/constants.js +3 -0
- package/dist/js/modern/utils/copy.js +2 -2
- package/dist/js/node/cli/build.js +5 -4
- package/dist/js/node/commands/build.js +62 -29
- package/dist/js/node/features/build/bundle/index.js +23 -0
- package/dist/js/node/features/build/bundle/runRollup.js +174 -0
- package/dist/js/node/features/build/bundle/runSpeedy.js +209 -0
- package/dist/js/node/{tasks → features/build/bundleless}/copy-assets.js +37 -56
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +58 -73
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +9 -10
- package/dist/js/node/features/build/bundleless/index.js +40 -0
- package/dist/js/node/features/build/bundleless/runBabel.js +309 -0
- package/dist/js/node/features/build/bundleless/style.js +299 -0
- package/dist/js/node/features/build/constants.js +115 -67
- package/dist/js/node/features/build/error.js +175 -0
- package/dist/js/node/features/build/index.js +104 -18
- package/dist/js/node/features/build/legacy-constants.js +107 -0
- package/dist/js/node/features/build/normalize.js +330 -0
- package/dist/js/node/features/build/types.js +0 -0
- package/dist/js/node/features/build/utils.js +48 -145
- package/dist/js/node/index.js +20 -1
- package/dist/js/node/locale/en.js +5 -3
- package/dist/js/node/locale/zh.js +5 -3
- package/dist/js/node/schema/build-config.js +120 -0
- package/dist/js/node/schema/index.js +3 -1
- package/dist/js/node/schema/output.js +20 -9
- package/dist/js/node/schema/source.js +2 -10
- package/dist/js/node/schema/tools.js +13 -0
- package/dist/js/node/schema/types.js +0 -0
- package/dist/js/node/utils/babel.js +4 -1
- package/dist/js/node/utils/constants.js +11 -0
- package/dist/js/node/utils/copy.js +1 -1
- package/dist/types/cli/build.d.ts +1 -1
- package/dist/types/commands/build.d.ts +12 -12
- package/dist/types/features/build/bundle/index.d.ts +3 -0
- package/dist/types/features/build/bundle/runRollup.d.ts +3 -0
- package/dist/types/features/build/bundle/runSpeedy.d.ts +10 -0
- package/dist/types/features/build/bundleless/copy-assets.d.ts +3 -0
- package/dist/types/features/build/bundleless/generator-dts/index.d.ts +3 -0
- package/dist/types/{tasks → features/build/bundleless}/generator-dts/utils.d.ts +3 -6
- package/dist/types/features/build/bundleless/index.d.ts +4 -0
- package/dist/types/features/build/bundleless/runBabel.d.ts +32 -0
- package/dist/types/features/build/bundleless/style.d.ts +25 -0
- package/dist/types/features/build/constants.d.ts +17 -13
- package/dist/types/features/build/error.d.ts +33 -0
- package/dist/types/features/build/index.d.ts +12 -3
- package/dist/types/features/build/legacy-constants.d.ts +8 -0
- package/dist/types/features/build/normalize.d.ts +19 -0
- package/dist/types/features/build/types.d.ts +15 -0
- package/dist/types/features/build/utils.d.ts +10 -31
- package/dist/types/index.d.ts +1 -0
- package/dist/types/locale/en.d.ts +2 -0
- package/dist/types/locale/index.d.ts +4 -0
- package/dist/types/locale/zh.d.ts +2 -0
- package/dist/types/schema/build-config.d.ts +197 -0
- package/dist/types/schema/index.d.ts +184 -18
- package/dist/types/schema/output.d.ts +188 -10
- package/dist/types/schema/source.d.ts +2 -11
- package/dist/types/schema/tools.d.ts +6 -0
- package/dist/types/schema/types.d.ts +46 -0
- package/dist/types/types.d.ts +29 -28
- package/dist/types/utils/babel.d.ts +3 -2
- package/dist/types/utils/constants.d.ts +2 -0
- package/package.json +23 -9
- package/dist/js/modern/features/build/build-watch.js +0 -101
- package/dist/js/modern/features/build/build.js +0 -123
- package/dist/js/modern/tasks/build-source-code.js +0 -208
- package/dist/js/modern/tasks/build-style.js +0 -169
- package/dist/js/modern/tasks/build-watch-source-code.js +0 -162
- package/dist/js/modern/tasks/build-watch-style.js +0 -216
- package/dist/js/modern/tasks/constants.js +0 -1
- package/dist/js/node/features/build/build-watch.js +0 -121
- package/dist/js/node/features/build/build.js +0 -143
- package/dist/js/node/tasks/build-source-code.js +0 -234
- package/dist/js/node/tasks/build-style.js +0 -184
- package/dist/js/node/tasks/build-watch-source-code.js +0 -174
- package/dist/js/node/tasks/build-watch-style.js +0 -233
- package/dist/js/node/tasks/constants.js +0 -8
- package/dist/types/features/build/build-watch.d.ts +0 -3
- package/dist/types/features/build/build.d.ts +0 -3
- package/dist/types/tasks/build-source-code.d.ts +0 -25
- package/dist/types/tasks/build-style.d.ts +0 -1
- package/dist/types/tasks/build-watch-source-code.d.ts +0 -1
- package/dist/types/tasks/build-watch-style.d.ts +0 -1
- package/dist/types/tasks/constants.d.ts +0 -1
- package/dist/types/tasks/copy-assets.d.ts +0 -1
- package/dist/types/tasks/generator-dts/index.d.ts +0 -1
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import * as os from 'os';
|
|
3
|
-
import { execa, Import } from '@modern-js/utils';
|
|
4
|
-
const lg = Import.lazy('./logger', require);
|
|
5
|
-
const pMap = Import.lazy('p-map', require);
|
|
6
|
-
const utils = Import.lazy('./utils', require);
|
|
7
|
-
const constants = Import.lazy('./constants', require);
|
|
8
|
-
export const buildInWatchMode = async (api, config, _) => {
|
|
9
|
-
const {
|
|
10
|
-
appDirectory
|
|
11
|
-
} = api.useAppContext();
|
|
12
|
-
const {
|
|
13
|
-
sourceDir,
|
|
14
|
-
enableTscCompiler
|
|
15
|
-
} = config;
|
|
16
|
-
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
17
|
-
const concurrency = os.cpus().length;
|
|
18
|
-
const lm = new lg.LoggerManager();
|
|
19
|
-
const codeLog = lm.createLoggerText({
|
|
20
|
-
title: constants.runBabelCompilerTitle
|
|
21
|
-
});
|
|
22
|
-
const dtsLog = lm.createLoggerText({
|
|
23
|
-
title: constants.runTscWatchTitle
|
|
24
|
-
});
|
|
25
|
-
const styleLog = lm.createLoggerText({
|
|
26
|
-
title: constants.runStyleCompilerTitle
|
|
27
|
-
});
|
|
28
|
-
const copyLog = lm.createLoggerText({
|
|
29
|
-
title: 'Copy Log:'
|
|
30
|
-
});
|
|
31
|
-
const initCodeMapper = utils.getCodeInitMapper(api, config);
|
|
32
|
-
const taskMapper = [...utils.getCodeMapper(api, {
|
|
33
|
-
logger: codeLog,
|
|
34
|
-
taskPath: require.resolve("../../tasks/build-watch-source-code"),
|
|
35
|
-
config,
|
|
36
|
-
willCompilerDirOrFile: sourceDir,
|
|
37
|
-
initMapper: initCodeMapper,
|
|
38
|
-
srcRootDir
|
|
39
|
-
}), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
|
|
40
|
-
logger: styleLog,
|
|
41
|
-
taskPath: require.resolve("../../tasks/build-watch-style")
|
|
42
|
-
}, {
|
|
43
|
-
logger: copyLog,
|
|
44
|
-
taskPath: require.resolve("../../tasks/copy-assets"),
|
|
45
|
-
params: ['--watch']
|
|
46
|
-
}];
|
|
47
|
-
lm.on('data', () => {
|
|
48
|
-
console.info(constants.clearFlag);
|
|
49
|
-
enableTscCompiler && console.info(dtsLog.value);
|
|
50
|
-
console.info(codeLog.value);
|
|
51
|
-
console.info(styleLog.value);
|
|
52
|
-
});
|
|
53
|
-
await pMap(taskMapper, async ({
|
|
54
|
-
logger,
|
|
55
|
-
taskPath,
|
|
56
|
-
params
|
|
57
|
-
}) => {
|
|
58
|
-
const childProcess = execa.node(taskPath, params, {
|
|
59
|
-
stdio: 'pipe'
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
if (logger === codeLog) {
|
|
63
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
64
|
-
event: {
|
|
65
|
-
error: true,
|
|
66
|
-
data: true
|
|
67
|
-
} // colors: { data: s => s },
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
lm.addStderr(logger, childProcess.stderr);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (logger === dtsLog) {
|
|
74
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
75
|
-
event: {
|
|
76
|
-
data: true,
|
|
77
|
-
error: true
|
|
78
|
-
},
|
|
79
|
-
colors: {
|
|
80
|
-
// tsc 的log信息无论是错误还是正确都是从 data event 中获取到的
|
|
81
|
-
data: s => s
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (logger === styleLog || logger === copyLog) {
|
|
87
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
88
|
-
event: {
|
|
89
|
-
error: true,
|
|
90
|
-
data: true
|
|
91
|
-
} // colors: { data: s => s },
|
|
92
|
-
|
|
93
|
-
});
|
|
94
|
-
lm.addStderr(logger, childProcess.stderr);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
await childProcess;
|
|
98
|
-
}, {
|
|
99
|
-
concurrency
|
|
100
|
-
});
|
|
101
|
-
};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import * as os from 'os';
|
|
3
|
-
import { execa, Import } from '@modern-js/utils';
|
|
4
|
-
const pMap = Import.lazy('p-map', require);
|
|
5
|
-
const utils = Import.lazy('./utils', require);
|
|
6
|
-
const lg = Import.lazy('./logger', require);
|
|
7
|
-
const constants = Import.lazy('./constants', require);
|
|
8
|
-
export const buildSourceCode = async (api, config, _) => {
|
|
9
|
-
const {
|
|
10
|
-
sourceDir,
|
|
11
|
-
enableTscCompiler,
|
|
12
|
-
styleOnly
|
|
13
|
-
} = config;
|
|
14
|
-
const {
|
|
15
|
-
appDirectory
|
|
16
|
-
} = api.useAppContext();
|
|
17
|
-
const concurrency = os.cpus().length;
|
|
18
|
-
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
19
|
-
const lm = new lg.LoggerManager();
|
|
20
|
-
const codeLog = lm.createLoggerText({
|
|
21
|
-
title: constants.runBabelCompilerTitle
|
|
22
|
-
});
|
|
23
|
-
const dtsLog = lm.createLoggerText({
|
|
24
|
-
title: constants.runTscTitle
|
|
25
|
-
});
|
|
26
|
-
const styleLog = lm.createLoggerText({
|
|
27
|
-
title: constants.runStyleCompilerTitle
|
|
28
|
-
});
|
|
29
|
-
const copyLog = lm.createLoggerText({
|
|
30
|
-
title: 'Copy Log:'
|
|
31
|
-
});
|
|
32
|
-
const initCodeMapper = utils.getCodeInitMapper(api, config);
|
|
33
|
-
let taskMapper = [];
|
|
34
|
-
|
|
35
|
-
if (styleOnly) {
|
|
36
|
-
taskMapper = [{
|
|
37
|
-
logger: styleLog,
|
|
38
|
-
taskPath: require.resolve("../../tasks/build-style")
|
|
39
|
-
}, {
|
|
40
|
-
logger: copyLog,
|
|
41
|
-
taskPath: require.resolve("../../tasks/copy-assets")
|
|
42
|
-
}];
|
|
43
|
-
} else {
|
|
44
|
-
taskMapper = [...utils.getCodeMapper(api, {
|
|
45
|
-
logger: codeLog,
|
|
46
|
-
taskPath: require.resolve("../../tasks/build-source-code"),
|
|
47
|
-
config,
|
|
48
|
-
willCompilerDirOrFile: sourceDir,
|
|
49
|
-
initMapper: initCodeMapper,
|
|
50
|
-
srcRootDir
|
|
51
|
-
}), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
|
|
52
|
-
logger: styleLog,
|
|
53
|
-
taskPath: require.resolve("../../tasks/build-style")
|
|
54
|
-
}, {
|
|
55
|
-
logger: copyLog,
|
|
56
|
-
taskPath: require.resolve("../../tasks/copy-assets")
|
|
57
|
-
}];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
lm.showCompiling();
|
|
61
|
-
await pMap(taskMapper, async ({
|
|
62
|
-
logger,
|
|
63
|
-
taskPath,
|
|
64
|
-
params
|
|
65
|
-
}) => {
|
|
66
|
-
const childProcess = execa.node(taskPath, params, {
|
|
67
|
-
stdio: 'pipe'
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
if (logger === codeLog || logger === copyLog) {
|
|
71
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
72
|
-
event: {
|
|
73
|
-
data: true,
|
|
74
|
-
error: true
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
lm.addStderr(logger, childProcess.stderr);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (logger === dtsLog) {
|
|
81
|
-
lm.addStdout(dtsLog, childProcess.stdout, {
|
|
82
|
-
event: {
|
|
83
|
-
data: true,
|
|
84
|
-
error: true
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
lm.addStderr(dtsLog, childProcess.stderr);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (logger === styleLog) {
|
|
91
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
92
|
-
event: {
|
|
93
|
-
data: true,
|
|
94
|
-
error: true
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
lm.addStderr(logger, childProcess.stderr);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
await childProcess;
|
|
101
|
-
}, {
|
|
102
|
-
concurrency
|
|
103
|
-
});
|
|
104
|
-
lm.disappearCompiling();
|
|
105
|
-
|
|
106
|
-
if (!styleOnly) {
|
|
107
|
-
enableTscCompiler && console.info(dtsLog.value);
|
|
108
|
-
console.info(codeLog.value);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (styleLog.hasMessages()) {
|
|
112
|
-
console.info(styleLog.value);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (copyLog.hasMessages()) {
|
|
116
|
-
console.info(copyLog.value);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (dtsLog.hasErrorMessage || codeLog.hasErrorMessage || styleLog.hasErrorMessage || copyLog.hasErrorMessage) {
|
|
120
|
-
// eslint-disable-next-line no-process-exit
|
|
121
|
-
process.exit(1);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
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; }
|
|
2
|
-
|
|
3
|
-
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; }
|
|
4
|
-
|
|
5
|
-
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; }
|
|
6
|
-
|
|
7
|
-
import { Import, glob, fs } from '@modern-js/utils';
|
|
8
|
-
import { initEnv } from "../utils/init-env";
|
|
9
|
-
const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
|
|
10
|
-
const argv = Import.lazy('process.argv', require);
|
|
11
|
-
const core = Import.lazy('@modern-js/core', require);
|
|
12
|
-
const bc = Import.lazy('../utils/babel', require);
|
|
13
|
-
const ts = Import.lazy('../utils/tsconfig', require);
|
|
14
|
-
export let Compiler;
|
|
15
|
-
|
|
16
|
-
(function (Compiler) {
|
|
17
|
-
Compiler[Compiler["babel"] = 0] = "babel";
|
|
18
|
-
Compiler[Compiler["esbuild"] = 1] = "esbuild";
|
|
19
|
-
Compiler[Compiler["swc"] = 2] = "swc";
|
|
20
|
-
})(Compiler || (Compiler = {}));
|
|
21
|
-
|
|
22
|
-
const runBabelCompiler = async (willCompilerFiles, config, babelConfig = {}) => {
|
|
23
|
-
const {
|
|
24
|
-
srcRootDir,
|
|
25
|
-
distDir
|
|
26
|
-
} = config; // TODO: 判断lynx模式下,修改distFileExtMap: {'js': 'js', 'jsx': 'jsx', 'ts': 'js', 'tsx': 'jsx'}
|
|
27
|
-
|
|
28
|
-
return babelCompiler.compiler({
|
|
29
|
-
quiet: true,
|
|
30
|
-
enableVirtualDist: true,
|
|
31
|
-
rootDir: srcRootDir,
|
|
32
|
-
filenames: willCompilerFiles,
|
|
33
|
-
distDir,
|
|
34
|
-
ignore: ['*.d.ts']
|
|
35
|
-
}, babelConfig);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const getWillCompilerCode = (srcDirOrFile, option) => {
|
|
39
|
-
const {
|
|
40
|
-
tsconfig,
|
|
41
|
-
isTsProject
|
|
42
|
-
} = option; // 如果是一个文件路径,则直接返回
|
|
43
|
-
|
|
44
|
-
if (fs.existsSync(srcDirOrFile) && fs.lstatSync(srcDirOrFile).isFile()) {
|
|
45
|
-
return [srcDirOrFile];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const getExts = isTs => {
|
|
49
|
-
// TODO: 是否受控tsconfig.json 里的jsx配置
|
|
50
|
-
let exts = [];
|
|
51
|
-
|
|
52
|
-
if (isTs) {
|
|
53
|
-
var _tsconfig$compilerOpt;
|
|
54
|
-
|
|
55
|
-
exts = tsconfig !== null && tsconfig !== void 0 && (_tsconfig$compilerOpt = tsconfig.compilerOptions) !== null && _tsconfig$compilerOpt !== void 0 && _tsconfig$compilerOpt.allowJs ? ['.ts', '.tsx', '.js', '.jsx'] : ['.ts', '.tsx'];
|
|
56
|
-
} else {
|
|
57
|
-
exts = ['.js', '.jsx'];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return exts;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const exts = getExts(isTsProject);
|
|
64
|
-
const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
|
|
65
|
-
const files = glob.sync(globPattern, {
|
|
66
|
-
ignore: [`${srcDirOrFile}/**/*.d.ts`],
|
|
67
|
-
absolute: true
|
|
68
|
-
});
|
|
69
|
-
return files;
|
|
70
|
-
};
|
|
71
|
-
export const buildSourceCode = async config => {
|
|
72
|
-
const {
|
|
73
|
-
compiler,
|
|
74
|
-
willCompilerDirOrFile,
|
|
75
|
-
tsconfigPath,
|
|
76
|
-
sourceMaps,
|
|
77
|
-
babelConfig
|
|
78
|
-
} = config;
|
|
79
|
-
const tsconfig = ts.readTsConfig(tsconfigPath);
|
|
80
|
-
const willCompilerFiles = getWillCompilerCode(willCompilerDirOrFile, {
|
|
81
|
-
tsconfig,
|
|
82
|
-
isTsProject: Boolean(tsconfig)
|
|
83
|
-
});
|
|
84
|
-
let distSet = null;
|
|
85
|
-
|
|
86
|
-
if (compiler === Compiler.babel) {
|
|
87
|
-
distSet = await runBabelCompiler(willCompilerFiles, config, _objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
88
|
-
sourceMaps
|
|
89
|
-
}));
|
|
90
|
-
} else {
|
|
91
|
-
distSet = {
|
|
92
|
-
code: 1,
|
|
93
|
-
message: 'no compiler'
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return distSet;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const generatorRealFiles = virtualDists => {
|
|
101
|
-
for (const virtualDist of virtualDists) {
|
|
102
|
-
const {
|
|
103
|
-
distPath,
|
|
104
|
-
code,
|
|
105
|
-
sourcemap,
|
|
106
|
-
sourceMapPath
|
|
107
|
-
} = virtualDist;
|
|
108
|
-
fs.ensureFileSync(distPath);
|
|
109
|
-
fs.writeFileSync(distPath, code);
|
|
110
|
-
|
|
111
|
-
if (sourcemap.length > 0) {
|
|
112
|
-
fs.ensureFileSync(sourceMapPath);
|
|
113
|
-
fs.writeFileSync(sourceMapPath, sourcemap);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const defaultConfig = {
|
|
119
|
-
srcRootDir: `${process.cwd()}/src`,
|
|
120
|
-
willCompilerDirOrFile: `${process.cwd()}/src`,
|
|
121
|
-
distDir: './dist/js/temp',
|
|
122
|
-
compiler: 'babel',
|
|
123
|
-
appDirectory: '',
|
|
124
|
-
sourceMaps: false,
|
|
125
|
-
tsconfigPath: '',
|
|
126
|
-
syntax: 'es5',
|
|
127
|
-
type: 'module',
|
|
128
|
-
watch: false
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const taskMain = async ({
|
|
132
|
-
modernConfig
|
|
133
|
-
}) => {
|
|
134
|
-
// Execution of the script's parameter handling and related required configuration acquisition
|
|
135
|
-
const processArgv = argv(process.argv.slice(2));
|
|
136
|
-
const config = processArgv(defaultConfig);
|
|
137
|
-
process.env.BUILD_FORMAT = initEnv(config);
|
|
138
|
-
const compiler = Compiler.babel; // Currently, only babel is supported.
|
|
139
|
-
|
|
140
|
-
const babelConfig = bc.resolveBabelConfig(config.appDirectory, modernConfig, {
|
|
141
|
-
sourceAbsDir: config.srcRootDir,
|
|
142
|
-
tsconfigPath: config.tsconfigPath,
|
|
143
|
-
syntax: config.syntax,
|
|
144
|
-
type: config.type
|
|
145
|
-
});
|
|
146
|
-
const {
|
|
147
|
-
code,
|
|
148
|
-
message,
|
|
149
|
-
messageDetails,
|
|
150
|
-
virtualDists = []
|
|
151
|
-
} = await buildSourceCode({
|
|
152
|
-
distDir: config.distDir,
|
|
153
|
-
srcRootDir: config.srcRootDir,
|
|
154
|
-
willCompilerDirOrFile: config.willCompilerDirOrFile,
|
|
155
|
-
sourceMaps: config.sourceMaps,
|
|
156
|
-
compiler,
|
|
157
|
-
projectData: {
|
|
158
|
-
appDirectory: config.appDirectory
|
|
159
|
-
},
|
|
160
|
-
tsconfigPath: config.tsconfigPath,
|
|
161
|
-
babelConfig
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
if (code === 0) {
|
|
165
|
-
generatorRealFiles(virtualDists); // 执行成功log使用 console.info
|
|
166
|
-
|
|
167
|
-
console.info('[Babel Compiler]: Successfully');
|
|
168
|
-
} else if (messageDetails && messageDetails.length > 0) {
|
|
169
|
-
console.error(message);
|
|
170
|
-
|
|
171
|
-
for (const detail of messageDetails || []) {
|
|
172
|
-
console.error(detail.content);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (code === 0 && config.copyDirs) {
|
|
177
|
-
const copyList = config.copyDirs.split(',');
|
|
178
|
-
|
|
179
|
-
for (const copyDir of copyList) {
|
|
180
|
-
fs.ensureDirSync(copyDir);
|
|
181
|
-
fs.copySync(config.distDir, copyDir);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
(async () => {
|
|
187
|
-
let options;
|
|
188
|
-
|
|
189
|
-
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
190
|
-
({
|
|
191
|
-
options
|
|
192
|
-
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const {
|
|
196
|
-
resolved
|
|
197
|
-
} = await core.cli.init([], options);
|
|
198
|
-
|
|
199
|
-
(async () => {
|
|
200
|
-
try {
|
|
201
|
-
await taskMain({
|
|
202
|
-
modernConfig: resolved
|
|
203
|
-
});
|
|
204
|
-
} catch (e) {
|
|
205
|
-
console.error(e);
|
|
206
|
-
}
|
|
207
|
-
})();
|
|
208
|
-
})();
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import { fs, glob, Import } from '@modern-js/utils';
|
|
3
|
-
const cssConfig = Import.lazy('@modern-js/css-config', require);
|
|
4
|
-
const core = Import.lazy('@modern-js/core', require);
|
|
5
|
-
const compiler = Import.lazy('@modern-js/style-compiler', require);
|
|
6
|
-
const hooks = Import.lazy('../hooks', require);
|
|
7
|
-
const STYLE_DIRS = 'styles';
|
|
8
|
-
const SRC_STYLE_DIRS = 'src';
|
|
9
|
-
|
|
10
|
-
const checkStylesDirExist = option => {
|
|
11
|
-
const {
|
|
12
|
-
appDirectory
|
|
13
|
-
} = option;
|
|
14
|
-
return fs.existsSync(path.join(appDirectory, STYLE_DIRS));
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const generatorFileOrLogError = (result, successMessage = '') => {
|
|
18
|
-
if (result.code === 0 && result.dists.length > 0) {
|
|
19
|
-
for (const file of result.dists) {
|
|
20
|
-
fs.ensureFileSync(file.filename);
|
|
21
|
-
fs.writeFileSync(file.filename, file.content);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (successMessage) {
|
|
25
|
-
console.info(successMessage);
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
for (const file of result.errors) {
|
|
29
|
-
console.error(file.error);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const getPostcssOption = (appDirectory, modernConfig) => {
|
|
35
|
-
var _postcssOption$postcs;
|
|
36
|
-
|
|
37
|
-
const postcssOption = cssConfig.getPostcssConfig(appDirectory, modernConfig, false);
|
|
38
|
-
return {
|
|
39
|
-
plugins: (postcssOption === null || postcssOption === void 0 ? void 0 : (_postcssOption$postcs = postcssOption.postcssOptions) === null || _postcssOption$postcs === void 0 ? void 0 : _postcssOption$postcs.plugins) || [],
|
|
40
|
-
enableSourceMap: (postcssOption === null || postcssOption === void 0 ? void 0 : postcssOption.sourceMap) || false,
|
|
41
|
-
options: {}
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const copyOriginStyleFiles = ({
|
|
46
|
-
targetDir,
|
|
47
|
-
outputDir
|
|
48
|
-
}) => {
|
|
49
|
-
const styleFiles = glob.sync(`${targetDir}/**/*.{css,sass,scss,less}`);
|
|
50
|
-
|
|
51
|
-
if (styleFiles.length > 0) {
|
|
52
|
-
fs.ensureDirSync(outputDir);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
for (const styleFile of styleFiles) {
|
|
56
|
-
const file = path.relative(targetDir, styleFile);
|
|
57
|
-
fs.ensureDirSync(path.dirname(path.join(outputDir, file)));
|
|
58
|
-
fs.copyFileSync(styleFile, path.join(outputDir, file));
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const taskMain = async ({
|
|
63
|
-
modernConfig,
|
|
64
|
-
appContext
|
|
65
|
-
}) => {
|
|
66
|
-
const {
|
|
67
|
-
assetsPath = 'styles',
|
|
68
|
-
path: outputPath = 'dist',
|
|
69
|
-
jsPath = 'js'
|
|
70
|
-
} = modernConfig.output;
|
|
71
|
-
const {
|
|
72
|
-
appDirectory
|
|
73
|
-
} = appContext;
|
|
74
|
-
const lessOption = await core.mountHook().moduleLessConfig({
|
|
75
|
-
modernConfig
|
|
76
|
-
}, {
|
|
77
|
-
onLast: async _ => undefined
|
|
78
|
-
});
|
|
79
|
-
const sassOption = await core.mountHook().moduleSassConfig({
|
|
80
|
-
modernConfig
|
|
81
|
-
}, {
|
|
82
|
-
onLast: async _ => undefined
|
|
83
|
-
});
|
|
84
|
-
const tailwindPlugin = await core.mountHook().moduleTailwindConfig({
|
|
85
|
-
modernConfig
|
|
86
|
-
}, {
|
|
87
|
-
onLast: async _ => undefined
|
|
88
|
-
});
|
|
89
|
-
const postcssOption = getPostcssOption(appDirectory, modernConfig);
|
|
90
|
-
|
|
91
|
-
if (tailwindPlugin) {
|
|
92
|
-
var _postcssOption$plugin;
|
|
93
|
-
|
|
94
|
-
(_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const {
|
|
98
|
-
importStyle
|
|
99
|
-
} = modernConfig.output;
|
|
100
|
-
const existStylesDir = checkStylesDirExist({
|
|
101
|
-
appDirectory
|
|
102
|
-
}); // 编译 styles 目录样式
|
|
103
|
-
|
|
104
|
-
if (existStylesDir) {
|
|
105
|
-
const styleResult = await compiler.styleCompiler({
|
|
106
|
-
projectDir: appDirectory,
|
|
107
|
-
stylesDir: path.resolve(appDirectory, STYLE_DIRS),
|
|
108
|
-
outDir: path.join(appDirectory, outputPath, assetsPath),
|
|
109
|
-
enableVirtualDist: true,
|
|
110
|
-
compilerOption: {
|
|
111
|
-
less: lessOption,
|
|
112
|
-
sass: sassOption,
|
|
113
|
-
postcss: postcssOption
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
generatorFileOrLogError(styleResult, `[Style Compiler] Successfully for 'styles' dir`);
|
|
117
|
-
} // 编译 src 内的样式代码
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const srcDir = path.resolve(appDirectory, SRC_STYLE_DIRS);
|
|
121
|
-
const outputDirToSrc = path.join(appDirectory, outputPath, jsPath, assetsPath);
|
|
122
|
-
|
|
123
|
-
if (importStyle === 'compiled-code') {
|
|
124
|
-
const srcStyleResult = await compiler.styleCompiler({
|
|
125
|
-
projectDir: appDirectory,
|
|
126
|
-
stylesDir: srcDir,
|
|
127
|
-
outDir: outputDirToSrc,
|
|
128
|
-
enableVirtualDist: true,
|
|
129
|
-
compilerOption: {
|
|
130
|
-
less: lessOption,
|
|
131
|
-
sass: sassOption,
|
|
132
|
-
postcss: postcssOption
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
generatorFileOrLogError(srcStyleResult, `[Style Compiler] Successfully for 'src' dir`);
|
|
136
|
-
} else {
|
|
137
|
-
copyOriginStyleFiles({
|
|
138
|
-
targetDir: srcDir,
|
|
139
|
-
outputDir: outputDirToSrc
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
(async () => {
|
|
145
|
-
let options;
|
|
146
|
-
|
|
147
|
-
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
148
|
-
({
|
|
149
|
-
options
|
|
150
|
-
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
hooks.buildLifeCycle();
|
|
154
|
-
const {
|
|
155
|
-
resolved: modernConfig,
|
|
156
|
-
appContext
|
|
157
|
-
} = await core.cli.init([], options);
|
|
158
|
-
|
|
159
|
-
(async () => {
|
|
160
|
-
try {
|
|
161
|
-
await taskMain({
|
|
162
|
-
modernConfig,
|
|
163
|
-
appContext
|
|
164
|
-
});
|
|
165
|
-
} catch (e) {
|
|
166
|
-
console.error(e.toString());
|
|
167
|
-
}
|
|
168
|
-
})();
|
|
169
|
-
})();
|