@modern-js/module-tools 1.5.7 → 1.6.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 +48 -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 -55
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -70
- 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 +4 -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 -55
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +59 -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 +22 -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/cli/new.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/logger/loggerManager.d.ts +2 -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/dist/types/utils/logger.d.ts +2 -0
- package/package.json +28 -13
- 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 -207
- package/dist/js/modern/tasks/build-style.js +0 -168
- package/dist/js/modern/tasks/build-watch-source-code.js +0 -161
- package/dist/js/modern/tasks/build-watch-style.js +0 -215
- 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 -233
- package/dist/js/node/tasks/build-style.js +0 -183
- package/dist/js/node/tasks/build-watch-source-code.js +0 -173
- package/dist/js/node/tasks/build-watch-style.js +0 -232
- 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,161 +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, fs } from '@modern-js/utils';
|
|
8
|
-
import { initEnv } from "../utils/init-env";
|
|
9
|
-
const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
|
|
10
|
-
const logger = Import.lazy('../features/build/logger', require);
|
|
11
|
-
const ts = Import.lazy('../utils/tsconfig', require);
|
|
12
|
-
const babel = Import.lazy('../utils/babel', require);
|
|
13
|
-
const core = Import.lazy('@modern-js/core', require);
|
|
14
|
-
const argv = Import.lazy('process.argv', require);
|
|
15
|
-
|
|
16
|
-
const generatorRealFiles = virtualDists => {
|
|
17
|
-
for (const virtualDist of virtualDists) {
|
|
18
|
-
const {
|
|
19
|
-
distPath,
|
|
20
|
-
code,
|
|
21
|
-
sourcemap,
|
|
22
|
-
sourceMapPath
|
|
23
|
-
} = virtualDist;
|
|
24
|
-
fs.ensureFileSync(distPath);
|
|
25
|
-
fs.writeFileSync(distPath, code);
|
|
26
|
-
|
|
27
|
-
if (sourcemap.length > 0) {
|
|
28
|
-
fs.ensureFileSync(sourceMapPath);
|
|
29
|
-
fs.writeFileSync(sourceMapPath, sourcemap);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const runBabelCompiler = async (config, modernConfig) => {
|
|
35
|
-
const {
|
|
36
|
-
tsconfigPath
|
|
37
|
-
} = config;
|
|
38
|
-
const babelConfig = babel.resolveBabelConfig(config.appDirectory, modernConfig, {
|
|
39
|
-
sourceAbsDir: config.srcRootDir,
|
|
40
|
-
tsconfigPath,
|
|
41
|
-
syntax: config.syntax,
|
|
42
|
-
type: config.type
|
|
43
|
-
});
|
|
44
|
-
const tsconfig = ts.readTsConfig(tsconfigPath || '', {});
|
|
45
|
-
const isTs = Boolean(tsconfig);
|
|
46
|
-
|
|
47
|
-
const getExts = isTsProject => {
|
|
48
|
-
// TODO: 是否受控tsconfig.json 里的jsx配置
|
|
49
|
-
let exts = [];
|
|
50
|
-
|
|
51
|
-
if (isTsProject) {
|
|
52
|
-
var _tsconfig$compilerOpt;
|
|
53
|
-
|
|
54
|
-
exts = tsconfig !== null && tsconfig !== void 0 && (_tsconfig$compilerOpt = tsconfig.compilerOptions) !== null && _tsconfig$compilerOpt !== void 0 && _tsconfig$compilerOpt.allowJs ? ['.ts', '.tsx', '.js', '.jsx'] : ['.ts', '.tsx'];
|
|
55
|
-
} else {
|
|
56
|
-
exts = ['.js', '.jsx'];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return exts;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const emitter = await babelCompiler.compiler({
|
|
63
|
-
enableVirtualDist: true,
|
|
64
|
-
quiet: true,
|
|
65
|
-
enableWatch: true,
|
|
66
|
-
rootDir: config.srcRootDir,
|
|
67
|
-
distDir: config.distDir,
|
|
68
|
-
watchDir: config.srcRootDir,
|
|
69
|
-
extensions: getExts(isTs),
|
|
70
|
-
ignore: ['*.d.ts']
|
|
71
|
-
}, _objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
72
|
-
sourceMaps: config.sourceMaps
|
|
73
|
-
}));
|
|
74
|
-
emitter.on(babelCompiler.BuildWatchEvent.compiling, () => {
|
|
75
|
-
console.info(logger.clearFlag, `Compiling...`);
|
|
76
|
-
});
|
|
77
|
-
emitter.on(babelCompiler.BuildWatchEvent.firstCompiler, result => {
|
|
78
|
-
if (result.code === 1) {
|
|
79
|
-
console.error(logger.clearFlag);
|
|
80
|
-
console.error(result.message);
|
|
81
|
-
|
|
82
|
-
for (const detail of result.messageDetails || []) {
|
|
83
|
-
console.error(detail.content);
|
|
84
|
-
}
|
|
85
|
-
} else {
|
|
86
|
-
generatorRealFiles(result.virtualDists);
|
|
87
|
-
console.info(logger.clearFlag, '[Babel Compiler]: Successfully');
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
emitter.on(babelCompiler.BuildWatchEvent.watchingCompiler, result => {
|
|
91
|
-
if (result.code === 1) {
|
|
92
|
-
var _result$virtualDists;
|
|
93
|
-
|
|
94
|
-
console.error(logger.clearFlag);
|
|
95
|
-
console.error(result.message);
|
|
96
|
-
|
|
97
|
-
for (const detail of result.messageDetails || []) {
|
|
98
|
-
console.error(detail.content);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (Array.isArray(result.virtualDists) && ((_result$virtualDists = result.virtualDists) === null || _result$virtualDists === void 0 ? void 0 : _result$virtualDists.length) > 0) {
|
|
102
|
-
generatorRealFiles(result.virtualDists);
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
generatorRealFiles(result.virtualDists);
|
|
106
|
-
console.info(result.message);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
await emitter.watch();
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const buildSourceCode = async (config, modernConfig) => {
|
|
113
|
-
const {
|
|
114
|
-
compiler
|
|
115
|
-
} = config;
|
|
116
|
-
|
|
117
|
-
if (compiler === 'babel') {
|
|
118
|
-
await runBabelCompiler(config, modernConfig);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const taskMain = async ({
|
|
123
|
-
modernConfig
|
|
124
|
-
}) => {
|
|
125
|
-
const processArgv = argv(process.argv.slice(2));
|
|
126
|
-
const config = processArgv({
|
|
127
|
-
srcRootDir: `${process.cwd()}/src`,
|
|
128
|
-
distDir: '',
|
|
129
|
-
compiler: 'babel',
|
|
130
|
-
appDirectory: '',
|
|
131
|
-
sourceMaps: false,
|
|
132
|
-
tsconfigPath: '',
|
|
133
|
-
syntax: 'es5',
|
|
134
|
-
type: 'module'
|
|
135
|
-
});
|
|
136
|
-
process.env.BUILD_FORMAT = initEnv(config);
|
|
137
|
-
await buildSourceCode(config, modernConfig);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
(async () => {
|
|
141
|
-
let options;
|
|
142
|
-
|
|
143
|
-
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
144
|
-
({
|
|
145
|
-
options
|
|
146
|
-
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const {
|
|
150
|
-
resolved
|
|
151
|
-
} = await core.cli.init([], options);
|
|
152
|
-
await core.manager.run(async () => {
|
|
153
|
-
try {
|
|
154
|
-
await taskMain({
|
|
155
|
-
modernConfig: resolved
|
|
156
|
-
});
|
|
157
|
-
} catch (e) {
|
|
158
|
-
console.error(e);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
})();
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import { fs, glob, watch, WatchChangeType, Import } from '@modern-js/utils';
|
|
3
|
-
const logger = Import.lazy('../features/build/logger', require);
|
|
4
|
-
const cssConfig = Import.lazy('@modern-js/css-config', require);
|
|
5
|
-
const hooks = Import.lazy('../hooks', require);
|
|
6
|
-
const core = Import.lazy('@modern-js/core', require);
|
|
7
|
-
const compiler = Import.lazy('@modern-js/style-compiler', require);
|
|
8
|
-
const STYLE_DIRS = 'styles';
|
|
9
|
-
const SRC_STYLE_DIRS = 'src';
|
|
10
|
-
|
|
11
|
-
const checkStylesDirExist = option => {
|
|
12
|
-
const {
|
|
13
|
-
appDirectory
|
|
14
|
-
} = option;
|
|
15
|
-
return fs.existsSync(path.join(appDirectory, STYLE_DIRS));
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const generatorFileAndReturnLog = (result, successMessage = '') => {
|
|
19
|
-
if (result.code === 0) {
|
|
20
|
-
for (const file of result.dists) {
|
|
21
|
-
fs.ensureFileSync(file.filename);
|
|
22
|
-
fs.writeFileSync(file.filename, file.content);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return successMessage;
|
|
26
|
-
} else {
|
|
27
|
-
return result.errors.join('\n');
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const getPostcssOption = (appDirectory, modernConfig) => {
|
|
32
|
-
var _postcssOption$postcs;
|
|
33
|
-
|
|
34
|
-
const postcssOption = cssConfig.getPostcssConfig(appDirectory, modernConfig, false);
|
|
35
|
-
return {
|
|
36
|
-
plugins: (postcssOption === null || postcssOption === void 0 ? void 0 : (_postcssOption$postcs = postcssOption.postcssOptions) === null || _postcssOption$postcs === void 0 ? void 0 : _postcssOption$postcs.plugins) || [],
|
|
37
|
-
enableSourceMap: (postcssOption === null || postcssOption === void 0 ? void 0 : postcssOption.sourceMap) || false,
|
|
38
|
-
options: {}
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const copyOriginStyleFiles = ({
|
|
43
|
-
targetDir,
|
|
44
|
-
outputDir
|
|
45
|
-
}) => {
|
|
46
|
-
const styleFiles = glob.sync(`${targetDir}/**/*.{css,sass,scss,less}`);
|
|
47
|
-
|
|
48
|
-
if (styleFiles.length > 0) {
|
|
49
|
-
fs.ensureDirSync(outputDir);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
for (const styleFile of styleFiles) {
|
|
53
|
-
const file = path.relative(targetDir, styleFile);
|
|
54
|
-
fs.ensureFileSync(path.join(outputDir, file));
|
|
55
|
-
fs.copyFileSync(styleFile, path.join(outputDir, file));
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const logCompilerMessage = compilerMessage => {
|
|
60
|
-
console.info(logger.clearFlag);
|
|
61
|
-
console.info(compilerMessage.src);
|
|
62
|
-
console.info(compilerMessage.styles);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const taskMain = async ({
|
|
66
|
-
modernConfig,
|
|
67
|
-
appContext
|
|
68
|
-
}) => {
|
|
69
|
-
const {
|
|
70
|
-
assetsPath = 'styles',
|
|
71
|
-
path: outputPath = 'dist',
|
|
72
|
-
jsPath = 'js',
|
|
73
|
-
importStyle
|
|
74
|
-
} = modernConfig.output;
|
|
75
|
-
const {
|
|
76
|
-
appDirectory
|
|
77
|
-
} = appContext;
|
|
78
|
-
const lessOption = await core.mountHook().moduleLessConfig({
|
|
79
|
-
modernConfig
|
|
80
|
-
}, {
|
|
81
|
-
onLast: async _ => null
|
|
82
|
-
});
|
|
83
|
-
const sassOption = await core.mountHook().moduleSassConfig({
|
|
84
|
-
modernConfig
|
|
85
|
-
}, {
|
|
86
|
-
onLast: async _ => null
|
|
87
|
-
});
|
|
88
|
-
const postcssOption = getPostcssOption(appDirectory, modernConfig);
|
|
89
|
-
const existStylesDir = checkStylesDirExist({
|
|
90
|
-
appDirectory
|
|
91
|
-
});
|
|
92
|
-
const compilerMessage = {
|
|
93
|
-
src: '',
|
|
94
|
-
styles: ''
|
|
95
|
-
}; // 编译 styles 目录样式
|
|
96
|
-
|
|
97
|
-
let styleEmitter = null;
|
|
98
|
-
|
|
99
|
-
if (existStylesDir) {
|
|
100
|
-
styleEmitter = compiler.styleCompiler({
|
|
101
|
-
watch: true,
|
|
102
|
-
projectDir: appDirectory,
|
|
103
|
-
stylesDir: path.resolve(appDirectory, STYLE_DIRS),
|
|
104
|
-
outDir: path.join(appDirectory, outputPath, assetsPath),
|
|
105
|
-
enableVirtualDist: true,
|
|
106
|
-
compilerOption: {
|
|
107
|
-
less: lessOption,
|
|
108
|
-
sass: sassOption,
|
|
109
|
-
postcss: postcssOption
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
styleEmitter.on(compiler.BuildWatchEvent.firstCompiler, styleResult => {
|
|
113
|
-
compilerMessage.styles = generatorFileAndReturnLog(styleResult, `[Style Compiler] Successfully for 'styles' dir`);
|
|
114
|
-
logCompilerMessage(compilerMessage);
|
|
115
|
-
});
|
|
116
|
-
styleEmitter.on(compiler.BuildWatchEvent.compilering, () => {
|
|
117
|
-
compilerMessage.styles = `[${assetsPath}] Compiling...`;
|
|
118
|
-
logCompilerMessage(compilerMessage);
|
|
119
|
-
});
|
|
120
|
-
styleEmitter.on(compiler.BuildWatchEvent.watchingCompiler, styleResult => {
|
|
121
|
-
compilerMessage.styles = generatorFileAndReturnLog(styleResult, `[Style Compiler] Successfully for 'styles' dir`);
|
|
122
|
-
logCompilerMessage(compilerMessage);
|
|
123
|
-
}); // await styleEmitter.watch();
|
|
124
|
-
} // 编译 src 内的样式代码
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const srcDir = path.resolve(appDirectory, SRC_STYLE_DIRS);
|
|
128
|
-
const outputDirToSrc = path.join(appDirectory, outputPath, jsPath, assetsPath);
|
|
129
|
-
|
|
130
|
-
if (importStyle === 'compiled-code') {
|
|
131
|
-
compilerMessage.src = `[src] Compiling`;
|
|
132
|
-
const srcStyleEmitter = compiler.styleCompiler({
|
|
133
|
-
watch: true,
|
|
134
|
-
projectDir: appDirectory,
|
|
135
|
-
stylesDir: srcDir,
|
|
136
|
-
outDir: outputDirToSrc,
|
|
137
|
-
enableVirtualDist: true,
|
|
138
|
-
compilerOption: {
|
|
139
|
-
less: lessOption,
|
|
140
|
-
sass: sassOption,
|
|
141
|
-
postcss: postcssOption
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
srcStyleEmitter.on(compiler.BuildWatchEvent.firstCompiler, srcStyleResult => {
|
|
145
|
-
compilerMessage.src = generatorFileAndReturnLog(srcStyleResult, `[Style Compiler] Successfully for 'src' dir`);
|
|
146
|
-
logCompilerMessage(compilerMessage);
|
|
147
|
-
});
|
|
148
|
-
srcStyleEmitter.on(compiler.BuildWatchEvent.compilering, () => {
|
|
149
|
-
compilerMessage.src = `[src] Compiling`;
|
|
150
|
-
logCompilerMessage(compilerMessage);
|
|
151
|
-
});
|
|
152
|
-
srcStyleEmitter.on(compiler.BuildWatchEvent.watchingCompiler, srcStyleResult => {
|
|
153
|
-
compilerMessage.src = generatorFileAndReturnLog(srcStyleResult, `[Style Compiler] Successfully for 'src' dir`);
|
|
154
|
-
logCompilerMessage(compilerMessage);
|
|
155
|
-
});
|
|
156
|
-
styleEmitter && (await styleEmitter.watch());
|
|
157
|
-
await srcStyleEmitter.watch();
|
|
158
|
-
} else {
|
|
159
|
-
compilerMessage.src = `['src' dir] Copying in progress`;
|
|
160
|
-
styleEmitter && (await styleEmitter.watch());
|
|
161
|
-
logCompilerMessage(compilerMessage);
|
|
162
|
-
copyOriginStyleFiles({
|
|
163
|
-
targetDir: srcDir,
|
|
164
|
-
outputDir: outputDirToSrc
|
|
165
|
-
});
|
|
166
|
-
compilerMessage.src = `[Style Compiler] Successfully for 'src' dir`;
|
|
167
|
-
logCompilerMessage(compilerMessage);
|
|
168
|
-
watch(`${srcDir}/**/*.{css,less,sass,scss}`, ({
|
|
169
|
-
changeType,
|
|
170
|
-
changedFilePath
|
|
171
|
-
}) => {
|
|
172
|
-
compilerMessage.src = `['src' dir] Copying in progress`;
|
|
173
|
-
logCompilerMessage(compilerMessage);
|
|
174
|
-
|
|
175
|
-
if (changeType === WatchChangeType.UNLINK) {
|
|
176
|
-
const removeFile = path.normalize(`${outputDirToSrc}/${path.relative(srcDir, changedFilePath)}`);
|
|
177
|
-
fs.removeSync(removeFile);
|
|
178
|
-
} else {
|
|
179
|
-
copyOriginStyleFiles({
|
|
180
|
-
targetDir: srcDir,
|
|
181
|
-
outputDir: outputDirToSrc
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
compilerMessage.src = `[Style Compiler] Successfully for 'src' dir`;
|
|
186
|
-
logCompilerMessage(compilerMessage);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
(async () => {
|
|
192
|
-
let options;
|
|
193
|
-
|
|
194
|
-
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
195
|
-
({
|
|
196
|
-
options
|
|
197
|
-
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
hooks.buildLifeCycle();
|
|
201
|
-
const {
|
|
202
|
-
resolved: modernConfig,
|
|
203
|
-
appContext
|
|
204
|
-
} = await core.cli.init([], options);
|
|
205
|
-
await core.manager.run(async () => {
|
|
206
|
-
try {
|
|
207
|
-
await taskMain({
|
|
208
|
-
modernConfig,
|
|
209
|
-
appContext
|
|
210
|
-
});
|
|
211
|
-
} catch (e) {
|
|
212
|
-
console.error(e);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const tempTsconfigName = './tsconfig.temp.json';
|
|
@@ -1,121 +0,0 @@
|
|
|
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 lg = _utils.Import.lazy('./logger', require);
|
|
19
|
-
|
|
20
|
-
const pMap = _utils.Import.lazy('p-map', require);
|
|
21
|
-
|
|
22
|
-
const utils = _utils.Import.lazy('./utils', require);
|
|
23
|
-
|
|
24
|
-
const constants = _utils.Import.lazy('./constants', require);
|
|
25
|
-
|
|
26
|
-
const buildInWatchMode = async (api, config, _) => {
|
|
27
|
-
const {
|
|
28
|
-
appDirectory
|
|
29
|
-
} = api.useAppContext();
|
|
30
|
-
const {
|
|
31
|
-
sourceDir,
|
|
32
|
-
enableTscCompiler
|
|
33
|
-
} = config;
|
|
34
|
-
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
35
|
-
const concurrency = os.cpus().length;
|
|
36
|
-
const lm = new lg.LoggerManager();
|
|
37
|
-
const codeLog = lm.createLoggerText({
|
|
38
|
-
title: constants.runBabelCompilerTitle
|
|
39
|
-
});
|
|
40
|
-
const dtsLog = lm.createLoggerText({
|
|
41
|
-
title: constants.runTscWatchTitle
|
|
42
|
-
});
|
|
43
|
-
const styleLog = lm.createLoggerText({
|
|
44
|
-
title: constants.runStyleCompilerTitle
|
|
45
|
-
});
|
|
46
|
-
const copyLog = lm.createLoggerText({
|
|
47
|
-
title: 'Copy Log:'
|
|
48
|
-
});
|
|
49
|
-
const initCodeMapper = utils.getCodeInitMapper(api, config);
|
|
50
|
-
const taskMapper = [...utils.getCodeMapper(api, {
|
|
51
|
-
logger: codeLog,
|
|
52
|
-
taskPath: require.resolve("../../tasks/build-watch-source-code"),
|
|
53
|
-
config,
|
|
54
|
-
willCompilerDirOrFile: sourceDir,
|
|
55
|
-
initMapper: initCodeMapper,
|
|
56
|
-
srcRootDir
|
|
57
|
-
}), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
|
|
58
|
-
logger: styleLog,
|
|
59
|
-
taskPath: require.resolve("../../tasks/build-watch-style")
|
|
60
|
-
}, {
|
|
61
|
-
logger: copyLog,
|
|
62
|
-
taskPath: require.resolve("../../tasks/copy-assets"),
|
|
63
|
-
params: ['--watch']
|
|
64
|
-
}];
|
|
65
|
-
lm.on('data', () => {
|
|
66
|
-
console.info(constants.clearFlag);
|
|
67
|
-
enableTscCompiler && console.info(dtsLog.value);
|
|
68
|
-
console.info(codeLog.value);
|
|
69
|
-
console.info(styleLog.value);
|
|
70
|
-
});
|
|
71
|
-
await pMap(taskMapper, async ({
|
|
72
|
-
logger,
|
|
73
|
-
taskPath,
|
|
74
|
-
params
|
|
75
|
-
}) => {
|
|
76
|
-
const childProcess = _utils.execa.node(taskPath, params, {
|
|
77
|
-
stdio: 'pipe'
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
if (logger === codeLog) {
|
|
81
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
82
|
-
event: {
|
|
83
|
-
error: true,
|
|
84
|
-
data: true
|
|
85
|
-
} // colors: { data: s => s },
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
lm.addStderr(logger, childProcess.stderr);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (logger === dtsLog) {
|
|
92
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
93
|
-
event: {
|
|
94
|
-
data: true,
|
|
95
|
-
error: true
|
|
96
|
-
},
|
|
97
|
-
colors: {
|
|
98
|
-
// tsc 的log信息无论是错误还是正确都是从 data event 中获取到的
|
|
99
|
-
data: s => s
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (logger === styleLog || logger === copyLog) {
|
|
105
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
106
|
-
event: {
|
|
107
|
-
error: true,
|
|
108
|
-
data: true
|
|
109
|
-
} // colors: { data: s => s },
|
|
110
|
-
|
|
111
|
-
});
|
|
112
|
-
lm.addStderr(logger, childProcess.stderr);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
await childProcess;
|
|
116
|
-
}, {
|
|
117
|
-
concurrency
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
exports.buildInWatchMode = buildInWatchMode;
|
|
@@ -1,143 +0,0 @@
|
|
|
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
|
-
const pMap = _utils.Import.lazy('p-map', require);
|
|
19
|
-
|
|
20
|
-
const utils = _utils.Import.lazy('./utils', require);
|
|
21
|
-
|
|
22
|
-
const lg = _utils.Import.lazy('./logger', require);
|
|
23
|
-
|
|
24
|
-
const constants = _utils.Import.lazy('./constants', require);
|
|
25
|
-
|
|
26
|
-
const buildSourceCode = async (api, config, _) => {
|
|
27
|
-
const {
|
|
28
|
-
sourceDir,
|
|
29
|
-
enableTscCompiler,
|
|
30
|
-
styleOnly
|
|
31
|
-
} = config;
|
|
32
|
-
const {
|
|
33
|
-
appDirectory
|
|
34
|
-
} = api.useAppContext();
|
|
35
|
-
const concurrency = os.cpus().length;
|
|
36
|
-
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
37
|
-
const lm = new lg.LoggerManager();
|
|
38
|
-
const codeLog = lm.createLoggerText({
|
|
39
|
-
title: constants.runBabelCompilerTitle
|
|
40
|
-
});
|
|
41
|
-
const dtsLog = lm.createLoggerText({
|
|
42
|
-
title: constants.runTscTitle
|
|
43
|
-
});
|
|
44
|
-
const styleLog = lm.createLoggerText({
|
|
45
|
-
title: constants.runStyleCompilerTitle
|
|
46
|
-
});
|
|
47
|
-
const copyLog = lm.createLoggerText({
|
|
48
|
-
title: 'Copy Log:'
|
|
49
|
-
});
|
|
50
|
-
const initCodeMapper = utils.getCodeInitMapper(api, config);
|
|
51
|
-
let taskMapper = [];
|
|
52
|
-
|
|
53
|
-
if (styleOnly) {
|
|
54
|
-
taskMapper = [{
|
|
55
|
-
logger: styleLog,
|
|
56
|
-
taskPath: require.resolve("../../tasks/build-style")
|
|
57
|
-
}, {
|
|
58
|
-
logger: copyLog,
|
|
59
|
-
taskPath: require.resolve("../../tasks/copy-assets")
|
|
60
|
-
}];
|
|
61
|
-
} else {
|
|
62
|
-
taskMapper = [...utils.getCodeMapper(api, {
|
|
63
|
-
logger: codeLog,
|
|
64
|
-
taskPath: require.resolve("../../tasks/build-source-code"),
|
|
65
|
-
config,
|
|
66
|
-
willCompilerDirOrFile: sourceDir,
|
|
67
|
-
initMapper: initCodeMapper,
|
|
68
|
-
srcRootDir
|
|
69
|
-
}), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
|
|
70
|
-
logger: styleLog,
|
|
71
|
-
taskPath: require.resolve("../../tasks/build-style")
|
|
72
|
-
}, {
|
|
73
|
-
logger: copyLog,
|
|
74
|
-
taskPath: require.resolve("../../tasks/copy-assets")
|
|
75
|
-
}];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
lm.showCompiling();
|
|
79
|
-
await pMap(taskMapper, async ({
|
|
80
|
-
logger,
|
|
81
|
-
taskPath,
|
|
82
|
-
params
|
|
83
|
-
}) => {
|
|
84
|
-
const childProcess = _utils.execa.node(taskPath, params, {
|
|
85
|
-
stdio: 'pipe'
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (logger === codeLog || logger === copyLog) {
|
|
89
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
90
|
-
event: {
|
|
91
|
-
data: true,
|
|
92
|
-
error: true
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
lm.addStderr(logger, childProcess.stderr);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (logger === dtsLog) {
|
|
99
|
-
lm.addStdout(dtsLog, childProcess.stdout, {
|
|
100
|
-
event: {
|
|
101
|
-
data: true,
|
|
102
|
-
error: true
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
lm.addStderr(dtsLog, childProcess.stderr);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (logger === styleLog) {
|
|
109
|
-
lm.addStdout(logger, childProcess.stdout, {
|
|
110
|
-
event: {
|
|
111
|
-
data: true,
|
|
112
|
-
error: true
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
lm.addStderr(logger, childProcess.stderr);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
await childProcess;
|
|
119
|
-
}, {
|
|
120
|
-
concurrency
|
|
121
|
-
});
|
|
122
|
-
lm.disappearCompiling();
|
|
123
|
-
|
|
124
|
-
if (!styleOnly) {
|
|
125
|
-
enableTscCompiler && console.info(dtsLog.value);
|
|
126
|
-
console.info(codeLog.value);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (styleLog.hasMessages()) {
|
|
130
|
-
console.info(styleLog.value);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (copyLog.hasMessages()) {
|
|
134
|
-
console.info(copyLog.value);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (dtsLog.hasErrorMessage || codeLog.hasErrorMessage || styleLog.hasErrorMessage || copyLog.hasErrorMessage) {
|
|
138
|
-
// eslint-disable-next-line no-process-exit
|
|
139
|
-
process.exit(1);
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
exports.buildSourceCode = buildSourceCode;
|