@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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @modern-js/module-tools
|
|
2
|
+
|
|
3
|
+
## 1.0.0-alpha.3
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- feat: initial
|
|
7
|
+
- Updated dependencies [undefined]
|
|
8
|
+
- @modern-js/plugin-changeset@1.0.0-alpha.3
|
|
9
|
+
- @modern-js/babel-preset-module@1.0.0-alpha.3
|
|
10
|
+
- @modern-js/core@1.0.0-alpha.3
|
|
11
|
+
- @modern-js/css-config@1.0.0-alpha.3
|
|
12
|
+
- @modern-js/i18n-cli-language-detector@1.0.0-alpha.3
|
|
13
|
+
- @modern-js/plugin-analyze@1.0.0-alpha.3
|
|
14
|
+
- @modern-js/plugin-fast-refresh@1.0.0-alpha.3
|
|
15
|
+
- @modern-js/plugin-i18n@1.0.0-alpha.3
|
|
16
|
+
- @modern-js/new-action@1.0.0-alpha.3
|
|
17
|
+
- @modern-js/babel-compiler@1.0.0-alpha.3
|
|
18
|
+
- @modern-js/style-compiler@1.0.0-alpha.3
|
|
19
|
+
- @modern-js/module-tools-hooks@1.0.0-alpha.3
|
|
20
|
+
- @modern-js/plugin@1.0.0-alpha.3
|
|
21
|
+
- @modern-js/utils@1.0.0-alpha.3
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Modern.js
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
<p align="center">
|
|
3
|
+
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
<p align="center">现代 Web 工程体系</p>
|
|
7
|
+
|
|
8
|
+
## 背景
|
|
9
|
+
- [迈入现代 Web 开发](https://zhuanlan.zhihu.com/p/386607009)
|
|
10
|
+
- [现代 Web 开发者问卷调查报告](https://zhuanlan.zhihu.com/p/403206195)
|
|
11
|
+
|
|
12
|
+
## 计划
|
|
13
|
+
|
|
14
|
+
Modern.js 的 1.0.0.rc 版已经发到 npm,目前在做测试改进,README 文档之后统一提供(现阶段加入测试和开发,可以发 [issue](https://github.com/modern-js-dev/modern.js/issues) 留微信联系),完整的文档站计划在10月14日上线
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
package/bin/modern.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Import } from '@modern-js/utils';
|
|
2
|
+
const local = Import.lazy('../locale/index', require);
|
|
3
|
+
const commands = Import.lazy('../commands', require);
|
|
4
|
+
export const buildCli = program => {
|
|
5
|
+
// TODO: 初始化环境变量
|
|
6
|
+
program.command('build').usage('[options]').description(local.i18n.t(local.localeKeys.command.build.describe)).option('-w, --watch', local.i18n.t(local.localeKeys.command.build.watch)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), './tsconfig.json').option('--style-only', local.i18n.t(local.localeKeys.command.build.style_only)).option('--platform [platform]', local.i18n.t(local.localeKeys.command.build.platform)).option('--no-tsc', local.i18n.t(local.localeKeys.command.build.no_tsc)).option('--no-clear', local.i18n.t(local.localeKeys.command.build.no_clear)).action(async subCommand => {
|
|
7
|
+
await commands.build(subCommand);
|
|
8
|
+
});
|
|
9
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Import } from '@modern-js/utils';
|
|
2
|
+
const local = Import.lazy('../locale', require);
|
|
3
|
+
const commands = Import.lazy('../commands', require);
|
|
4
|
+
export const devCli = program => {
|
|
5
|
+
program.command('dev').usage('[options]').description(local.i18n.t(local.localeKeys.command.dev.describe)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), './tsconfig.json').action(async params => {
|
|
6
|
+
await commands.dev(params);
|
|
7
|
+
});
|
|
8
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
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; }
|
|
2
|
+
|
|
3
|
+
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; }
|
|
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 } from '@modern-js/utils';
|
|
8
|
+
const newAction = Import.lazy('@modern-js/new-action', require);
|
|
9
|
+
const local = Import.lazy('../locale', require);
|
|
10
|
+
export const newCli = (program, locale) => {
|
|
11
|
+
program.command('new').usage('[options]').description(local.i18n.t(local.localeKeys.command.new.describe)).option('-d, --debug', local.i18n.t(local.localeKeys.command.new.debug), false).option('-c, --config <config>', local.i18n.t(local.localeKeys.command.new.config)).option('--dist-tag <tag>', local.i18n.t(local.localeKeys.command.new.distTag)).option('--registry', local.i18n.t(local.localeKeys.command.new.registry)).action(async options => {
|
|
12
|
+
await newAction.ModuleNewAction(_objectSpread(_objectSpread({}, options), {}, {
|
|
13
|
+
locale
|
|
14
|
+
}));
|
|
15
|
+
});
|
|
16
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { fs, Import } from '@modern-js/utils';
|
|
3
|
+
const tsConfigutils = Import.lazy('../utils/tsconfig', require);
|
|
4
|
+
const valid = Import.lazy('../utils/valide', require);
|
|
5
|
+
const buildFeature = Import.lazy('../features/build', require);
|
|
6
|
+
const core = Import.lazy('@modern-js/core', require);
|
|
7
|
+
const dotenv = Import.lazy('dotenv', require);
|
|
8
|
+
export const build = async ({
|
|
9
|
+
watch: _watch = false,
|
|
10
|
+
tsconfig: tsconfigName,
|
|
11
|
+
tsc,
|
|
12
|
+
clear: _clear = true,
|
|
13
|
+
platform
|
|
14
|
+
}) => {
|
|
15
|
+
const {
|
|
16
|
+
value: {
|
|
17
|
+
appDirectory
|
|
18
|
+
}
|
|
19
|
+
} = core.useAppContext();
|
|
20
|
+
const modernConfig = core.useResolvedConfigContext().value;
|
|
21
|
+
const {
|
|
22
|
+
output: {
|
|
23
|
+
path: outputPath = 'dist'
|
|
24
|
+
}
|
|
25
|
+
} = modernConfig;
|
|
26
|
+
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
27
|
+
dotenv.config();
|
|
28
|
+
const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
|
|
29
|
+
const enableTscCompiler = isTsProject && tsc;
|
|
30
|
+
valid.valideBeforeTask({
|
|
31
|
+
modernConfig,
|
|
32
|
+
tsconfigPath
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (_clear) {
|
|
36
|
+
fs.removeSync(path.join(appDirectory, outputPath));
|
|
37
|
+
} // TODO: 一些配置只需要从modernConfig中获取
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
await buildFeature.build({
|
|
41
|
+
enableWatchMode: _watch,
|
|
42
|
+
isTsProject,
|
|
43
|
+
platform,
|
|
44
|
+
sourceDir: 'src',
|
|
45
|
+
tsconfigName,
|
|
46
|
+
enableTscCompiler
|
|
47
|
+
}, modernConfig);
|
|
48
|
+
process.on('SIGBREAK', () => {
|
|
49
|
+
console.info('exit');
|
|
50
|
+
const tempTsconfigFilePath = path.join(appDirectory, './tsconfig.temp.json');
|
|
51
|
+
|
|
52
|
+
if (fs.existsSync(tempTsconfigFilePath)) {
|
|
53
|
+
fs.removeSync(tempTsconfigFilePath);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { Import } from '@modern-js/utils';
|
|
3
|
+
const devFeature = Import.lazy('../features/dev', require);
|
|
4
|
+
const core = Import.lazy('@modern-js/core', require);
|
|
5
|
+
const dotenv = Import.lazy('dotenv', require);
|
|
6
|
+
const tsConfigutils = Import.lazy('../utils/tsconfig', require);
|
|
7
|
+
const valid = Import.lazy('../utils/valide', require);
|
|
8
|
+
export const dev = async option => {
|
|
9
|
+
const {
|
|
10
|
+
tsconfig: tsconfigName
|
|
11
|
+
} = option;
|
|
12
|
+
const appContext = core.useAppContext().value;
|
|
13
|
+
const modernConfig = core.useResolvedConfigContext().value;
|
|
14
|
+
const {
|
|
15
|
+
appDirectory
|
|
16
|
+
} = appContext;
|
|
17
|
+
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
18
|
+
dotenv.config();
|
|
19
|
+
valid.valideBeforeTask({
|
|
20
|
+
modernConfig,
|
|
21
|
+
tsconfigPath
|
|
22
|
+
});
|
|
23
|
+
const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath); // await devFeature.showMenu({ isTsProject, appDirectory });
|
|
24
|
+
|
|
25
|
+
await devFeature.devStorybook({
|
|
26
|
+
isTsProject,
|
|
27
|
+
appDirectory
|
|
28
|
+
});
|
|
29
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
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; }
|
|
2
|
+
|
|
3
|
+
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; }
|
|
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, chalk } from '@modern-js/utils';
|
|
8
|
+
const core = Import.lazy('@modern-js/core', require);
|
|
9
|
+
const execa = Import.lazy('execa', require);
|
|
10
|
+
const lg = Import.lazy('./logger', require);
|
|
11
|
+
const pMap = Import.lazy('p-map', require);
|
|
12
|
+
export const buildPlatform = async option => {
|
|
13
|
+
const {
|
|
14
|
+
isTsProject = false,
|
|
15
|
+
platform
|
|
16
|
+
} = option;
|
|
17
|
+
const lm = new lg.LoggerManager(); // 获取platforms的参数
|
|
18
|
+
|
|
19
|
+
const buildTasks = await core.mountHook().platformBuild({
|
|
20
|
+
isTsProject
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (buildTasks.length <= 0) {
|
|
24
|
+
console.info(chalk.yellow('No build tasks detected.\nYou can use the `new` command to enable the more features'));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const loggerMap = {};
|
|
29
|
+
const taskMapper = buildTasks.filter(task => platform === 'all' || task.name === platform).map(params => {
|
|
30
|
+
const logger = lm.createLoggerText({
|
|
31
|
+
title: params.title
|
|
32
|
+
});
|
|
33
|
+
loggerMap[params.name] = logger;
|
|
34
|
+
return _objectSpread({
|
|
35
|
+
logger
|
|
36
|
+
}, params);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (taskMapper.length <= 0) {
|
|
40
|
+
console.info(chalk.yellow(`'${platform}' is undefined task`));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
lm.showCompiling();
|
|
45
|
+
await pMap(taskMapper, async ({
|
|
46
|
+
taskPath,
|
|
47
|
+
params,
|
|
48
|
+
logger
|
|
49
|
+
}) => {
|
|
50
|
+
const childProcess = execa.node(taskPath, params, {
|
|
51
|
+
stdio: 'pipe',
|
|
52
|
+
all: true
|
|
53
|
+
});
|
|
54
|
+
lm.addStdout(logger, childProcess.stdout, {
|
|
55
|
+
event: {
|
|
56
|
+
data: true,
|
|
57
|
+
error: true
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
lm.addStderr(logger, childProcess.stderr);
|
|
61
|
+
await childProcess; // lm.disappearCompiling();
|
|
62
|
+
// console.info(lg.colors.title(title));
|
|
63
|
+
// console.info(a.all);
|
|
64
|
+
});
|
|
65
|
+
lm.disappearCompiling();
|
|
66
|
+
|
|
67
|
+
for (const key of Object.keys(loggerMap)) {
|
|
68
|
+
console.info(loggerMap[key].value);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as os from 'os';
|
|
3
|
+
import { Import } from '@modern-js/utils';
|
|
4
|
+
const core = Import.lazy('@modern-js/core', require);
|
|
5
|
+
const execa = Import.lazy('execa', require);
|
|
6
|
+
const lg = Import.lazy('./logger', require);
|
|
7
|
+
const pMap = Import.lazy('p-map', require);
|
|
8
|
+
const utils = Import.lazy('./utils', require);
|
|
9
|
+
const constants = Import.lazy('./constants', require);
|
|
10
|
+
export const buildInWatchMode = async (config, _) => {
|
|
11
|
+
const {
|
|
12
|
+
appDirectory
|
|
13
|
+
} = core.useAppContext().value;
|
|
14
|
+
const {
|
|
15
|
+
sourceDir,
|
|
16
|
+
enableTscCompiler
|
|
17
|
+
} = config;
|
|
18
|
+
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
19
|
+
const concurrency = os.cpus().length;
|
|
20
|
+
const lm = new lg.LoggerManager();
|
|
21
|
+
const codeLog = lm.createLoggerText({
|
|
22
|
+
title: constants.runBabelCompilerTitle
|
|
23
|
+
});
|
|
24
|
+
const dtsLog = lm.createLoggerText({
|
|
25
|
+
title: constants.runTscWatchTitle
|
|
26
|
+
});
|
|
27
|
+
const styleLog = lm.createLoggerText({
|
|
28
|
+
title: constants.runStyleCompilerTitle
|
|
29
|
+
});
|
|
30
|
+
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
31
|
+
const taskMapper = [...utils.getCodeMapper({
|
|
32
|
+
logger: codeLog,
|
|
33
|
+
taskPath: require.resolve("../../tasks/build-watch-source-code"),
|
|
34
|
+
config,
|
|
35
|
+
willCompilerDirOrFile: sourceDir,
|
|
36
|
+
initMapper: initCodeMapper,
|
|
37
|
+
srcRootDir
|
|
38
|
+
}), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
|
|
39
|
+
logger: styleLog,
|
|
40
|
+
taskPath: require.resolve("../../tasks/build-watch-style")
|
|
41
|
+
}];
|
|
42
|
+
lm.on('data', () => {
|
|
43
|
+
console.info(constants.clearFlag);
|
|
44
|
+
enableTscCompiler && console.info(dtsLog.value);
|
|
45
|
+
console.info(codeLog.value);
|
|
46
|
+
console.info(styleLog.value);
|
|
47
|
+
});
|
|
48
|
+
await pMap(taskMapper, async ({
|
|
49
|
+
logger,
|
|
50
|
+
taskPath,
|
|
51
|
+
params
|
|
52
|
+
}) => {
|
|
53
|
+
const childProcess = execa.node(taskPath, params, {
|
|
54
|
+
stdio: 'pipe'
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (logger === codeLog) {
|
|
58
|
+
lm.addStdout(logger, childProcess.stdout, {
|
|
59
|
+
event: {
|
|
60
|
+
error: true,
|
|
61
|
+
data: true
|
|
62
|
+
} // colors: { data: s => s },
|
|
63
|
+
|
|
64
|
+
});
|
|
65
|
+
lm.addStderr(logger, childProcess.stderr);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (logger === dtsLog) {
|
|
69
|
+
lm.addStdout(logger, childProcess.stdout, {
|
|
70
|
+
event: {
|
|
71
|
+
data: true,
|
|
72
|
+
error: true
|
|
73
|
+
},
|
|
74
|
+
colors: {
|
|
75
|
+
// tsc 的log信息无论是错误还是正确都是从 data event 中获取到的
|
|
76
|
+
data: s => s
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (logger === styleLog) {
|
|
82
|
+
lm.addStdout(logger, childProcess.stdout, {
|
|
83
|
+
event: {
|
|
84
|
+
error: true,
|
|
85
|
+
data: true
|
|
86
|
+
} // colors: { data: s => s },
|
|
87
|
+
|
|
88
|
+
});
|
|
89
|
+
lm.addStderr(logger, childProcess.stderr);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
await childProcess;
|
|
93
|
+
}, {
|
|
94
|
+
concurrency
|
|
95
|
+
});
|
|
96
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
import { Import } from '@modern-js/utils';
|
|
5
|
+
const pMap = Import.lazy('p-map', require);
|
|
6
|
+
const utils = Import.lazy('./utils', require);
|
|
7
|
+
const execa = Import.lazy('execa', require);
|
|
8
|
+
const lg = Import.lazy('./logger', require);
|
|
9
|
+
const constants = Import.lazy('./constants', require);
|
|
10
|
+
const core = Import.lazy('@modern-js/core', require);
|
|
11
|
+
export const buildSourceCode = async (config, _) => {
|
|
12
|
+
const {
|
|
13
|
+
sourceDir,
|
|
14
|
+
enableTscCompiler
|
|
15
|
+
} = config;
|
|
16
|
+
const {
|
|
17
|
+
appDirectory
|
|
18
|
+
} = core.useAppContext().value;
|
|
19
|
+
const concurrency = os.cpus().length;
|
|
20
|
+
const srcRootDir = path.join(appDirectory, sourceDir);
|
|
21
|
+
const lm = new lg.LoggerManager();
|
|
22
|
+
const codeLog = lm.createLoggerText({
|
|
23
|
+
title: constants.runBabelCompilerTitle
|
|
24
|
+
});
|
|
25
|
+
const dtsLog = lm.createLoggerText({
|
|
26
|
+
title: constants.runTscTitle
|
|
27
|
+
});
|
|
28
|
+
const styleLog = lm.createLoggerText({
|
|
29
|
+
title: constants.runStyleCompilerTitle
|
|
30
|
+
});
|
|
31
|
+
const copyLog = lm.createLoggerText({
|
|
32
|
+
title: 'Copy Log:'
|
|
33
|
+
});
|
|
34
|
+
const initCodeMapper = utils.getCodeInitMapper(config);
|
|
35
|
+
const taskMapper = [...utils.getCodeMapper({
|
|
36
|
+
logger: codeLog,
|
|
37
|
+
taskPath: require.resolve("../../tasks/build-source-code"),
|
|
38
|
+
config,
|
|
39
|
+
willCompilerDirOrFile: sourceDir,
|
|
40
|
+
initMapper: initCodeMapper,
|
|
41
|
+
srcRootDir
|
|
42
|
+
}), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
|
|
43
|
+
logger: styleLog,
|
|
44
|
+
taskPath: require.resolve("../../tasks/build-style")
|
|
45
|
+
}, {
|
|
46
|
+
logger: copyLog,
|
|
47
|
+
taskPath: require.resolve("../../tasks/copy-assets")
|
|
48
|
+
}];
|
|
49
|
+
lm.showCompiling();
|
|
50
|
+
await pMap(taskMapper, async ({
|
|
51
|
+
logger,
|
|
52
|
+
taskPath,
|
|
53
|
+
params
|
|
54
|
+
}) => {
|
|
55
|
+
const childProcess = execa.node(taskPath, params, {
|
|
56
|
+
stdio: 'pipe'
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (logger === codeLog || logger === copyLog) {
|
|
60
|
+
lm.addStdout(logger, childProcess.stdout, {
|
|
61
|
+
event: {
|
|
62
|
+
data: true,
|
|
63
|
+
error: true
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
lm.addStderr(logger, childProcess.stderr);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (logger === dtsLog) {
|
|
70
|
+
lm.addStdout(dtsLog, childProcess.stdout, {
|
|
71
|
+
event: {
|
|
72
|
+
data: true,
|
|
73
|
+
error: true
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
lm.addStderr(dtsLog, childProcess.stderr);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (logger === styleLog) {
|
|
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
|
+
await childProcess;
|
|
90
|
+
}, {
|
|
91
|
+
concurrency
|
|
92
|
+
});
|
|
93
|
+
lm.disappearCompiling();
|
|
94
|
+
enableTscCompiler && console.info(dtsLog.value);
|
|
95
|
+
console.info(codeLog.value);
|
|
96
|
+
|
|
97
|
+
if (styleLog.hasMessages()) {
|
|
98
|
+
console.info(styleLog.value);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (copyLog.hasMessages()) {
|
|
102
|
+
console.info(copyLog.value);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (dtsLog.hasErrorMessage || codeLog.hasErrorMessage || styleLog.hasErrorMessage || copyLog.hasErrorMessage) {
|
|
106
|
+
// eslint-disable-next-line no-process-exit
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
/* eslint-enable max-statements */
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Universal JS 的默认选择,三份构建产物,支持 Node.js,对现代浏览器有优化
|
|
2
|
+
const universalJs = [{
|
|
3
|
+
type: 'module',
|
|
4
|
+
syntax: 'es5',
|
|
5
|
+
outDir: 'treeshaking'
|
|
6
|
+
}, {
|
|
7
|
+
type: 'commonjs',
|
|
8
|
+
syntax: 'es6+',
|
|
9
|
+
outDir: 'node'
|
|
10
|
+
}, {
|
|
11
|
+
type: 'module',
|
|
12
|
+
syntax: 'es6+',
|
|
13
|
+
outDir: 'modern'
|
|
14
|
+
}]; // Universal JS 的优化选择,两份构建产物,对现代浏览器无优化
|
|
15
|
+
|
|
16
|
+
const universalJsLite = [{
|
|
17
|
+
type: 'module',
|
|
18
|
+
syntax: 'es5',
|
|
19
|
+
outDir: 'treeshaking'
|
|
20
|
+
}, {
|
|
21
|
+
type: 'commonjs',
|
|
22
|
+
syntax: 'es6+',
|
|
23
|
+
outDir: 'node',
|
|
24
|
+
copyDirs: ['modern']
|
|
25
|
+
}]; // 纯前端代码的默认选择,两份构建产物
|
|
26
|
+
|
|
27
|
+
const browserJs = [{
|
|
28
|
+
type: 'module',
|
|
29
|
+
syntax: 'es5',
|
|
30
|
+
outDir: 'treeshaking',
|
|
31
|
+
copyDirs: ['node']
|
|
32
|
+
}, {
|
|
33
|
+
type: 'module',
|
|
34
|
+
syntax: 'es6+',
|
|
35
|
+
outDir: 'modern'
|
|
36
|
+
}]; // 纯前端代码的优化选择,单份构建产物,对现代浏览器无优化
|
|
37
|
+
|
|
38
|
+
const browserJsLite = [{
|
|
39
|
+
type: 'module',
|
|
40
|
+
syntax: 'es5',
|
|
41
|
+
outDir: 'treeshaking',
|
|
42
|
+
copyDirs: ['modern', 'node']
|
|
43
|
+
}]; // 纯 Node.js 代码的默认选择,两份构建产物
|
|
44
|
+
|
|
45
|
+
const nodeJs = [{
|
|
46
|
+
type: 'commonjs',
|
|
47
|
+
syntax: 'es6+',
|
|
48
|
+
outDir: 'node'
|
|
49
|
+
}, {
|
|
50
|
+
type: 'module',
|
|
51
|
+
syntax: 'es6+',
|
|
52
|
+
outDir: 'modern'
|
|
53
|
+
}];
|
|
54
|
+
export const DEFAULT_PACKAGE_MODE = 'universal-js';
|
|
55
|
+
export const PACKAGE_MODES = {
|
|
56
|
+
'universal-js': universalJs,
|
|
57
|
+
'universal-js-lite': universalJsLite,
|
|
58
|
+
'browser-js': browserJs,
|
|
59
|
+
'browser-js-lite': browserJsLite,
|
|
60
|
+
'node-js': nodeJs
|
|
61
|
+
};
|
|
62
|
+
export const runBabelCompilerTitle = 'Run babel compiler code log';
|
|
63
|
+
export const runTscWatchTitle = 'Run `tsc -w` log';
|
|
64
|
+
export const runTscTitle = 'Run `tsc` log';
|
|
65
|
+
export const runStyleCompilerTitle = 'Run style compiler code log';
|
|
66
|
+
export const clearFlag = '\x1Bc';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Import } from '@modern-js/utils';
|
|
2
|
+
const buildFeature = Import.lazy('./build', require);
|
|
3
|
+
const buildWatchFeature = Import.lazy('./build-watch', require); // const bp: typeof import('./build-platform') = Import.lazy(
|
|
4
|
+
// './build-platform',
|
|
5
|
+
// require,
|
|
6
|
+
// );
|
|
7
|
+
|
|
8
|
+
export const build = async (config, modernConfig) => {
|
|
9
|
+
const {
|
|
10
|
+
enableWatchMode,
|
|
11
|
+
platform
|
|
12
|
+
} = config; // TODO: maybe need watch mode in build platform
|
|
13
|
+
|
|
14
|
+
if (typeof platform === 'boolean' && platform) {
|
|
15
|
+
// await bp.buildPlatform({ platform: 'all', isTsProject });
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (typeof platform === 'string') {
|
|
20
|
+
// await bp.buildPlatform({ platform, isTsProject });
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (enableWatchMode) {
|
|
25
|
+
await buildWatchFeature.buildInWatchMode(config, modernConfig);
|
|
26
|
+
} else {
|
|
27
|
+
await buildFeature.buildSourceCode(config, modernConfig);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { chalk } from '@modern-js/utils';
|
|
2
|
+
export const colors = {
|
|
3
|
+
title: chalk.rgb(218, 152, 92)
|
|
4
|
+
};
|
|
5
|
+
export const clearFlag = '\x1Bc';
|
|
6
|
+
export const logTemplate = (title, messageStack, {
|
|
7
|
+
noBottomBorder: _noBottomBorder = false,
|
|
8
|
+
bottomBorderText: _bottomBorderText = '',
|
|
9
|
+
noLeftBorder: _noLeftBorder = false,
|
|
10
|
+
leftBorder: _leftBorder = '',
|
|
11
|
+
contentColor: _contentColor = s => s
|
|
12
|
+
} = {}) => {
|
|
13
|
+
const maxLength = Infinity; // TODO: 考虑后面是否提供该参数
|
|
14
|
+
|
|
15
|
+
const leftBorderFlag = _noLeftBorder ? '' : _leftBorder;
|
|
16
|
+
const messageFragments = messageStack.map(p => {
|
|
17
|
+
p.trim();
|
|
18
|
+
return `${leftBorderFlag}${p.replace(clearFlag, '')}`;
|
|
19
|
+
}) // 移除 clearFlag
|
|
20
|
+
.filter(s => s !== leftBorderFlag) // 过滤空字符串
|
|
21
|
+
.slice(0, maxLength); // 控制长度
|
|
22
|
+
|
|
23
|
+
const template = `${colors.title(title)}:
|
|
24
|
+
${_contentColor(messageFragments.join(''))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
|
|
25
|
+
return template;
|
|
26
|
+
};
|
|
27
|
+
// 处理Log内容如何展示
|
|
28
|
+
export class LoggerText {
|
|
29
|
+
constructor(option) {
|
|
30
|
+
this.messages = void 0;
|
|
31
|
+
this.hasErrorMessage = void 0;
|
|
32
|
+
this.option = void 0;
|
|
33
|
+
this.messages = [];
|
|
34
|
+
this.option = option;
|
|
35
|
+
this.hasErrorMessage = false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
append(message) {
|
|
39
|
+
if (message.includes(clearFlag)) {
|
|
40
|
+
this.messages = [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.messages.push(message);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
errorHappen() {
|
|
47
|
+
this.hasErrorMessage = true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
hasMessages() {
|
|
51
|
+
return this.messages.length > 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get value() {
|
|
55
|
+
const {
|
|
56
|
+
title,
|
|
57
|
+
contentConfig
|
|
58
|
+
} = this.option;
|
|
59
|
+
const messages = [...new Set(this.messages)];
|
|
60
|
+
return logTemplate(title, messages, contentConfig);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|