@modern-js/module-tools 1.3.0 → 1.4.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/js/modern/features/dev/index.js +1 -1
  3. package/dist/js/node/features/dev/index.js +1 -1
  4. package/dist/types/index.d.ts +2 -0
  5. package/lib/types.d.ts +0 -10
  6. package/package.json +16 -17
  7. package/tests/dev-feature.test.ts +17 -1
  8. package/src/.eslintrc.json +0 -5
  9. package/src/cli/build.ts +0 -39
  10. package/src/cli/dev.ts +0 -24
  11. package/src/cli/index.ts +0 -3
  12. package/src/cli/new.ts +0 -32
  13. package/src/commands/build.ts +0 -74
  14. package/src/commands/dev.ts +0 -52
  15. package/src/commands/index.ts +0 -2
  16. package/src/features/build/build-platform.ts +0 -83
  17. package/src/features/build/build-watch.ts +0 -99
  18. package/src/features/build/build.ts +0 -111
  19. package/src/features/build/constants.ts +0 -52
  20. package/src/features/build/index.ts +0 -54
  21. package/src/features/build/logger/index.ts +0 -2
  22. package/src/features/build/logger/logText.ts +0 -80
  23. package/src/features/build/logger/loggerManager.ts +0 -132
  24. package/src/features/build/utils.ts +0 -235
  25. package/src/features/dev/index.ts +0 -74
  26. package/src/index.ts +0 -55
  27. package/src/locale/en.ts +0 -21
  28. package/src/locale/index.ts +0 -15
  29. package/src/locale/zh.ts +0 -21
  30. package/src/schema/index.ts +0 -4
  31. package/src/schema/output.ts +0 -41
  32. package/src/schema/schema.d.ts +0 -13
  33. package/src/schema/source.ts +0 -16
  34. package/src/tasks/build-source-code.ts +0 -234
  35. package/src/tasks/build-style.ts +0 -194
  36. package/src/tasks/build-watch-source-code.ts +0 -186
  37. package/src/tasks/build-watch-style.ts +0 -271
  38. package/src/tasks/constants.ts +0 -1
  39. package/src/tasks/copy-assets.ts +0 -123
  40. package/src/tasks/generator-dts.ts +0 -277
  41. package/src/type.d.ts +0 -1
  42. package/src/types.ts +0 -65
  43. package/src/utils/babel.ts +0 -104
  44. package/src/utils/color.ts +0 -3
  45. package/src/utils/copy.ts +0 -71
  46. package/src/utils/init-env.ts +0 -31
  47. package/src/utils/json.ts +0 -13
  48. package/src/utils/language.ts +0 -9
  49. package/src/utils/logger.ts +0 -141
  50. package/src/utils/readline.ts +0 -28
  51. package/src/utils/tsconfig.ts +0 -37
  52. package/src/utils/tspaths-transform/constants.ts +0 -19
  53. package/src/utils/tspaths-transform/index.ts +0 -139
  54. package/src/utils/tspaths-transform/utils.ts +0 -25
  55. package/src/utils/valide.ts +0 -37
package/CHANGELOG.md CHANGED
@@ -1,5 +1,60 @@
1
1
  # @modern-js/module-tools
2
2
 
3
+ ## 1.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 67503500: add alais subCmd
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [118da5b4]
12
+ - Updated dependencies [b376c8d6]
13
+ - Updated dependencies [e62c4efd]
14
+ - Updated dependencies [6891e4c2]
15
+ - Updated dependencies [e2a8233f]
16
+ - @modern-js/css-config@1.2.2
17
+ - @modern-js/style-compiler@1.2.2
18
+ - @modern-js/core@1.4.2
19
+ - @modern-js/plugin-analyze@1.3.2
20
+
21
+ ## 1.3.2
22
+
23
+ ### Patch Changes
24
+
25
+ - c78400c7: fix: remove stylus support
26
+ - Updated dependencies [b7a9eeba]
27
+ - Updated dependencies [53aca274]
28
+ - Updated dependencies [78279953]
29
+ - Updated dependencies [e116ace5]
30
+ - Updated dependencies [4d72edea]
31
+ - @modern-js/plugin-analyze@1.3.1
32
+ - @modern-js/core@1.4.1
33
+ - @modern-js/utils@1.3.1
34
+
35
+ ## 1.3.1
36
+
37
+ ### Patch Changes
38
+
39
+ - 83166714: change .npmignore
40
+ - Updated dependencies [83166714]
41
+ - Updated dependencies [c3de9882]
42
+ - Updated dependencies [33ff48af]
43
+ - Updated dependencies [b7c48198]
44
+ - @modern-js/babel-preset-module@1.3.1
45
+ - @modern-js/core@1.3.2
46
+ - @modern-js/css-config@1.2.1
47
+ - @modern-js/i18n-cli-language-detector@1.2.1
48
+ - @modern-js/plugin-analyze@1.2.1
49
+ - @modern-js/plugin-changeset@1.2.1
50
+ - @modern-js/plugin-fast-refresh@1.2.1
51
+ - @modern-js/plugin-i18n@1.2.1
52
+ - @modern-js/new-action@1.3.1
53
+ - @modern-js/babel-compiler@1.2.1
54
+ - @modern-js/style-compiler@1.2.1
55
+ - @modern-js/module-tools-hooks@1.2.1
56
+ - @modern-js/utils@1.2.2
57
+
3
58
  ## 1.3.0
4
59
 
5
60
  ### Minor Changes
@@ -41,7 +41,7 @@ export const devStorybook = async config => {
41
41
  };
42
42
  export const runSubCmd = async (subCmd, config) => {
43
43
  const metas = await core.mountHook().moduleToolsMenu(undefined);
44
- const devMeta = metas.find(meta => meta.value === subCmd);
44
+ const devMeta = metas.find(meta => meta.value === subCmd || Array.isArray(meta.aliasValues) && meta.aliasValues.includes(subCmd));
45
45
 
46
46
  if (devMeta) {
47
47
  await devMeta.runTask(config);
@@ -61,7 +61,7 @@ exports.devStorybook = devStorybook;
61
61
 
62
62
  const runSubCmd = async (subCmd, config) => {
63
63
  const metas = await core.mountHook().moduleToolsMenu(undefined);
64
- const devMeta = metas.find(meta => meta.value === subCmd);
64
+ const devMeta = metas.find(meta => meta.value === subCmd || Array.isArray(meta.aliasValues) && meta.aliasValues.includes(subCmd));
65
65
 
66
66
  if (devMeta) {
67
67
  await devMeta.runTask(config);
@@ -13,8 +13,10 @@ declare const _default: import("@modern-js/core").AsyncPlugin<Partial<import("@m
13
13
  watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
14
14
  fileChange: import("@modern-js/core").AsyncWorkflow<{
15
15
  filename: string;
16
+ eventType: "add" | "unlink" | "change";
16
17
  }, void>;
17
18
  beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
19
+ beforeRestart: import("@modern-js/core").AsyncWorkflow<void, void>;
18
20
  } & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
19
21
 
20
22
  export default _default;
package/lib/types.d.ts CHANGED
@@ -70,11 +70,6 @@ declare module '*.less' {
70
70
  export default classes;
71
71
  }
72
72
 
73
- declare module '*.styl' {
74
- const classes: { readonly [key: string]: string };
75
- export default classes;
76
- }
77
-
78
73
  declare module '*.sass' {
79
74
  const classes: { readonly [key: string]: string };
80
75
  export default classes;
@@ -95,11 +90,6 @@ declare module '*.module.less' {
95
90
  export default classes;
96
91
  }
97
92
 
98
- declare module '*.module.styl' {
99
- const classes: { readonly [key: string]: string };
100
- export default classes;
101
- }
102
-
103
93
  declare module '*.module.sass' {
104
94
  const classes: { readonly [key: string]: string };
105
95
  export default classes;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.3.0",
14
+ "version": "1.4.0",
15
15
  "bin": {
16
16
  "modern": "./bin/modern.js"
17
17
  },
@@ -51,19 +51,19 @@
51
51
  "@babel/runtime": "^7",
52
52
  "@babel/traverse": "^7.15.0",
53
53
  "@babel/types": "^7.15.0",
54
- "@modern-js/babel-compiler": "^1.2.0",
55
- "@modern-js/babel-preset-module": "^1.3.0",
56
- "@modern-js/core": "^1.3.1",
57
- "@modern-js/css-config": "^1.2.0",
58
- "@modern-js/i18n-cli-language-detector": "^1.2.0",
59
- "@modern-js/module-tools-hooks": "^1.2.0",
60
- "@modern-js/new-action": "^1.3.0",
61
- "@modern-js/plugin-analyze": "^1.2.0",
62
- "@modern-js/plugin-changeset": "^1.2.0",
63
- "@modern-js/plugin-fast-refresh": "^1.2.0",
64
- "@modern-js/plugin-i18n": "^1.2.0",
65
- "@modern-js/style-compiler": "^1.2.0",
66
- "@modern-js/utils": "^1.2.1",
54
+ "@modern-js/babel-compiler": "^1.2.1",
55
+ "@modern-js/babel-preset-module": "^1.3.1",
56
+ "@modern-js/core": "^1.4.2",
57
+ "@modern-js/css-config": "^1.2.2",
58
+ "@modern-js/i18n-cli-language-detector": "^1.2.1",
59
+ "@modern-js/module-tools-hooks": "^1.2.1",
60
+ "@modern-js/new-action": "^1.3.1",
61
+ "@modern-js/plugin-analyze": "^1.3.2",
62
+ "@modern-js/plugin-changeset": "^1.2.1",
63
+ "@modern-js/plugin-fast-refresh": "^1.2.1",
64
+ "@modern-js/plugin-i18n": "^1.2.1",
65
+ "@modern-js/style-compiler": "^1.2.2",
66
+ "@modern-js/utils": "^1.3.1",
67
67
  "chalk": "^4.1.2",
68
68
  "chokidar": "^3.5.2",
69
69
  "dotenv": "^10.0.0",
@@ -82,7 +82,7 @@
82
82
  },
83
83
  "devDependencies": {
84
84
  "@babel/preset-typescript": "^7.15.0",
85
- "@modern-js/babel-chain": "^1.2.0",
85
+ "@modern-js/babel-chain": "^1.2.1",
86
86
  "@types/babel__core": "^7.1.15",
87
87
  "@types/babel__generator": "^7.6.3",
88
88
  "@types/babel__traverse": "^7.14.2",
@@ -107,8 +107,7 @@
107
107
  },
108
108
  "publishConfig": {
109
109
  "registry": "https://registry.npmjs.org/",
110
- "access": "public",
111
- "types": "./dist/types/index.d.ts"
110
+ "access": "public"
112
111
  },
113
112
  "scripts": {
114
113
  "new": "modern new",
@@ -12,7 +12,7 @@ jest.mock('@modern-js/core', () => ({
12
12
 
13
13
  describe('dev feature with subCmd', () => {
14
14
  beforeEach(() => {
15
- console.info('asdas');
15
+ jest.clearAllMocks();
16
16
  });
17
17
  it('should run task with "storybook" params when storybook plugin exist', async () => {
18
18
  mockModuleToolsMenu.mockReturnValue([
@@ -27,4 +27,20 @@ describe('dev feature with subCmd', () => {
27
27
  await runSubCmd('storybook', { isTsProject: true, appDirectory: '' });
28
28
  expect(exit).toHaveBeenCalled();
29
29
  });
30
+
31
+ it('should run task with alias name "story" params when storybook plugin exist', async () => {
32
+ mockModuleToolsMenu.mockReturnValue([
33
+ { value: 'storybook', aliasValues: ['story'], runTask: mockDevMeta },
34
+ ]);
35
+ await runSubCmd('story', { isTsProject: true, appDirectory: '' });
36
+ expect(mockDevMeta.mock.calls.length).toBe(1);
37
+ });
38
+
39
+ it('should run task with alias name "story1" params when storybook plugin exist', async () => {
40
+ mockModuleToolsMenu.mockReturnValue([
41
+ { value: 'storybook', aliasValues: ['story'], runTask: mockDevMeta },
42
+ ]);
43
+ await runSubCmd('story1', { isTsProject: true, appDirectory: '' });
44
+ expect(mockDevMeta.mock.calls.length).toBe(0);
45
+ });
30
46
  });
@@ -1,5 +0,0 @@
1
- {
2
- "rules": {
3
- "react-hooks/rules-of-hooks": "off"
4
- }
5
- }
package/src/cli/build.ts DELETED
@@ -1,39 +0,0 @@
1
- import { Import } from '@modern-js/utils';
2
- import type { Command } from 'commander';
3
- import type { IBuildOption } from '../commands/build';
4
-
5
- const local: typeof import('../locale') = Import.lazy(
6
- '../locale/index',
7
- require,
8
- );
9
- const commands: typeof import('../commands') = Import.lazy(
10
- '../commands',
11
- require,
12
- );
13
-
14
- export const buildCli = (program: Command) => {
15
- // TODO: 初始化环境变量
16
- program
17
- .command('build')
18
- .usage('[options]')
19
- .description(local.i18n.t(local.localeKeys.command.build.describe))
20
- .option('-w, --watch', local.i18n.t(local.localeKeys.command.build.watch))
21
- .option(
22
- '--tsconfig [tsconfig]',
23
- local.i18n.t(local.localeKeys.command.build.tsconfig),
24
- './tsconfig.json',
25
- )
26
- .option(
27
- '--style-only',
28
- local.i18n.t(local.localeKeys.command.build.style_only),
29
- )
30
- .option(
31
- '-p, --platform [platform]',
32
- local.i18n.t(local.localeKeys.command.build.platform),
33
- )
34
- .option('--no-tsc', local.i18n.t(local.localeKeys.command.build.no_tsc))
35
- .option('--no-clear', local.i18n.t(local.localeKeys.command.build.no_clear))
36
- .action(async (subCommand: IBuildOption) => {
37
- await commands.build(subCommand);
38
- });
39
- };
package/src/cli/dev.ts DELETED
@@ -1,24 +0,0 @@
1
- import { Import } from '@modern-js/utils';
2
- import type { Command } from 'commander';
3
- import type { IDevOption } from '../commands/dev';
4
-
5
- const local: typeof import('../locale') = Import.lazy('../locale', require);
6
- const commands: typeof import('../commands') = Import.lazy(
7
- '../commands',
8
- require,
9
- );
10
-
11
- export const devCli = (program: Command) => {
12
- program
13
- .command('dev [subCmd]')
14
- .usage('[options]')
15
- .description(local.i18n.t(local.localeKeys.command.dev.describe))
16
- .option(
17
- '--tsconfig [tsconfig]',
18
- local.i18n.t(local.localeKeys.command.build.tsconfig),
19
- './tsconfig.json',
20
- )
21
- .action(async (subCmd: string, params: IDevOption) => {
22
- await commands.dev(params, subCmd);
23
- });
24
- };
package/src/cli/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './build';
2
- export * from './dev';
3
- export * from './new';
package/src/cli/new.ts DELETED
@@ -1,32 +0,0 @@
1
- import type { Command } from 'commander';
2
- import { Import } from '@modern-js/utils';
3
-
4
- const newAction: typeof import('@modern-js/new-action') = Import.lazy(
5
- '@modern-js/new-action',
6
- require,
7
- );
8
- const local: typeof import('../locale') = Import.lazy('../locale', require);
9
-
10
- export const newCli = (program: Command, locale?: string) => {
11
- program
12
- .command('new')
13
- .usage('[options]')
14
- .description(local.i18n.t(local.localeKeys.command.new.describe))
15
- .option(
16
- '-d, --debug',
17
- local.i18n.t(local.localeKeys.command.new.debug),
18
- false,
19
- )
20
- .option(
21
- '-c, --config <config>',
22
- local.i18n.t(local.localeKeys.command.new.config),
23
- )
24
- .option(
25
- '--dist-tag <tag>',
26
- local.i18n.t(local.localeKeys.command.new.distTag),
27
- )
28
- .option('--registry', local.i18n.t(local.localeKeys.command.new.registry))
29
- .action(async options => {
30
- await newAction.ModuleNewAction({ ...options, locale });
31
- });
32
- };
@@ -1,74 +0,0 @@
1
- import * as path from 'path';
2
- import { fs, Import } from '@modern-js/utils';
3
- import type { Platform } from '../types';
4
-
5
- const tsConfigutils: typeof import('../utils/tsconfig') = Import.lazy(
6
- '../utils/tsconfig',
7
- require,
8
- );
9
-
10
- const valid: typeof import('../utils/valide') = Import.lazy(
11
- '../utils/valide',
12
- require,
13
- );
14
- const buildFeature: typeof import('../features/build') = Import.lazy(
15
- '../features/build',
16
- require,
17
- );
18
- const core: typeof import('@modern-js/core') = Import.lazy(
19
- '@modern-js/core',
20
- require,
21
- );
22
- const dotenv: typeof import('dotenv') = Import.lazy('dotenv', require);
23
-
24
- export interface IBuildOption {
25
- watch: boolean;
26
- tsconfig: string;
27
- platform: boolean | Exclude<Platform, 'all'>;
28
- styleOnly: boolean;
29
- tsc: boolean;
30
- clear: boolean;
31
- }
32
-
33
- export const build = async ({
34
- watch = false,
35
- tsconfig: tsconfigName,
36
- tsc,
37
- clear = true,
38
- platform,
39
- }: IBuildOption) => {
40
- const { appDirectory } = core.useAppContext();
41
- const modernConfig = core.useResolvedConfigContext();
42
- const tsconfigPath = path.join(appDirectory, tsconfigName);
43
- dotenv.config();
44
- const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
45
- const enableTscCompiler = isTsProject && tsc;
46
-
47
- valid.valideBeforeTask({ modernConfig, tsconfigPath });
48
-
49
- // TODO: 一些配置只需要从modernConfig中获取
50
- await buildFeature.build(
51
- {
52
- appDirectory,
53
- enableWatchMode: watch,
54
- isTsProject,
55
- platform,
56
- sourceDir: 'src',
57
- tsconfigName,
58
- enableTscCompiler,
59
- clear,
60
- },
61
- modernConfig,
62
- );
63
-
64
- process.on('SIGBREAK', () => {
65
- console.info('exit');
66
- const tempTsconfigFilePath = path.join(
67
- appDirectory,
68
- './tsconfig.temp.json',
69
- );
70
- if (fs.existsSync(tempTsconfigFilePath)) {
71
- fs.removeSync(tempTsconfigFilePath);
72
- }
73
- });
74
- };
@@ -1,52 +0,0 @@
1
- import * as path from 'path';
2
- import { Import } from '@modern-js/utils';
3
-
4
- const devFeature: typeof import('../features/dev') = Import.lazy(
5
- '../features/dev',
6
- require,
7
- );
8
- const core: typeof import('@modern-js/core') = Import.lazy(
9
- '@modern-js/core',
10
- require,
11
- );
12
- const dotenv: typeof import('dotenv') = Import.lazy('dotenv', require);
13
- const tsConfigutils: typeof import('../utils/tsconfig') = Import.lazy(
14
- '../utils/tsconfig',
15
- require,
16
- );
17
- const valid: typeof import('../utils/valide') = Import.lazy(
18
- '../utils/valide',
19
- require,
20
- );
21
-
22
- export interface IDevOption {
23
- tsconfig: string;
24
- }
25
-
26
- const existSubCmd = (subCmd: string) => subCmd.length > 0;
27
-
28
- export const dev = async (option: IDevOption, subCmd = '') => {
29
- const { tsconfig: tsconfigName } = option;
30
- const appContext = core.useAppContext();
31
- const modernConfig = core.useResolvedConfigContext();
32
- const { appDirectory } = appContext;
33
- const tsconfigPath = path.join(appDirectory, tsconfigName);
34
-
35
- dotenv.config();
36
-
37
- valid.valideBeforeTask({ modernConfig, tsconfigPath });
38
-
39
- const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
40
-
41
- if (existSubCmd(subCmd)) {
42
- await devFeature.runSubCmd(subCmd, { isTsProject, appDirectory });
43
- return;
44
- }
45
-
46
- // Compatible with the use of jupiter, RUN_PLATFORM is used in jupiter
47
- if (process.env.RUN_PLATFORM) {
48
- await devFeature.showMenu({ isTsProject, appDirectory });
49
- } else {
50
- await devFeature.devStorybook({ isTsProject, appDirectory });
51
- }
52
- };
@@ -1,2 +0,0 @@
1
- export { dev } from './dev';
2
- export { build } from './build';
@@ -1,83 +0,0 @@
1
- import { Import, chalk } from '@modern-js/utils';
2
- import type { LoggerText } from './logger';
3
-
4
- const core: typeof import('@modern-js/core') = Import.lazy(
5
- '@modern-js/core',
6
- require,
7
- );
8
- const execa: typeof import('execa') = Import.lazy('execa', require);
9
- const lg: typeof import('./logger') = Import.lazy('./logger', require);
10
- const pMap: typeof import('p-map') = Import.lazy('p-map', require);
11
-
12
- export type Platform = 'all' | 'docs' | 'storybook';
13
-
14
- export interface IBuildPlatformOption {
15
- platform: Platform;
16
- isTsProject?: boolean;
17
- }
18
-
19
- export const buildPlatform = async (option: IBuildPlatformOption) => {
20
- const { isTsProject = false, platform } = option;
21
- const lm = new lg.LoggerManager();
22
- // 获取platforms的参数
23
- const buildTasks = await (core.mountHook() as any).platformBuild({
24
- isTsProject,
25
- });
26
-
27
- if (buildTasks.length <= 0) {
28
- console.info(
29
- chalk.yellow(
30
- 'No build tasks detected.\nYou can use the `new` command to enable the more features',
31
- ),
32
- );
33
- return;
34
- }
35
-
36
- const loggerMap: Record<string, LoggerText> = {};
37
- const taskMapper = buildTasks
38
- .filter((task: any) => platform === 'all' || task.name === platform)
39
- .map((params: any) => {
40
- const logger = lm.createLoggerText({ title: params.title });
41
- loggerMap[params.name] = logger;
42
- return {
43
- logger,
44
- ...params,
45
- };
46
- });
47
- if (taskMapper.length <= 0) {
48
- console.info(chalk.yellow(`'${platform}' is undefined task`));
49
- return;
50
- }
51
-
52
- lm.showCompiling();
53
- await pMap(
54
- taskMapper,
55
- async ({ taskPath, params, logger: _ }: any) => {
56
- const childProcess = execa.node(taskPath, params, {
57
- stdio: 'inherit',
58
- all: true,
59
- });
60
-
61
- // lm.addStdout(logger, childProcess.stdout, {
62
- // event: { data: true, error: true },
63
- // });
64
-
65
- // lm.addStderr(logger, childProcess.stderr);
66
- try {
67
- await childProcess;
68
- } catch {
69
- // eslint-disable-next-line no-process-exit
70
- process.exit(1);
71
- }
72
- // lm.disappearCompiling();
73
- // console.info(lg.colors.title(title));
74
- // console.info(a.all);
75
- },
76
- { concurrency: 1 },
77
- );
78
-
79
- // lm.disappearCompiling();
80
- // for (const key of Object.keys(loggerMap)) {
81
- // console.info(loggerMap[key].value);
82
- // }
83
- };
@@ -1,99 +0,0 @@
1
- import * as path from 'path';
2
- import * as os from 'os';
3
- import { Import } from '@modern-js/utils';
4
-
5
- import type { NormalizedConfig } from '@modern-js/core';
6
- import type { IBuildConfig, ITaskMapper } from '../../types';
7
-
8
- const core: typeof import('@modern-js/core') = Import.lazy(
9
- '@modern-js/core',
10
- require,
11
- );
12
- const execa: typeof import('execa') = Import.lazy('execa', require);
13
- const lg: typeof import('./logger') = Import.lazy('./logger', require);
14
- const pMap: typeof import('p-map') = Import.lazy('p-map', require);
15
- const utils: typeof import('./utils') = Import.lazy('./utils', require);
16
- const constants: typeof import('./constants') = Import.lazy(
17
- './constants',
18
- require,
19
- );
20
-
21
- export const buildInWatchMode = async (
22
- config: IBuildConfig,
23
- _: NormalizedConfig,
24
- ) => {
25
- const { appDirectory } = core.useAppContext();
26
- const { sourceDir, enableTscCompiler } = config;
27
- const srcRootDir = path.join(appDirectory, sourceDir);
28
- const concurrency = os.cpus().length;
29
- const lm = new lg.LoggerManager();
30
- const codeLog = lm.createLoggerText({
31
- title: constants.runBabelCompilerTitle,
32
- });
33
- const dtsLog = lm.createLoggerText({ title: constants.runTscWatchTitle });
34
- const styleLog = lm.createLoggerText({
35
- title: constants.runStyleCompilerTitle,
36
- });
37
- const copyLog = lm.createLoggerText({ title: 'Copy Log:' });
38
- const initCodeMapper = utils.getCodeInitMapper(config);
39
- const taskMapper: ITaskMapper[] = [
40
- ...utils.getCodeMapper({
41
- logger: codeLog,
42
- taskPath: require.resolve('../../tasks/build-watch-source-code'),
43
- config,
44
- willCompilerDirOrFile: sourceDir,
45
- initMapper: initCodeMapper,
46
- srcRootDir,
47
- }),
48
- ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []),
49
- {
50
- logger: styleLog,
51
- taskPath: require.resolve('../../tasks/build-watch-style'),
52
- },
53
- {
54
- logger: copyLog,
55
- taskPath: require.resolve('../../tasks/copy-assets'),
56
- params: ['--watch'],
57
- },
58
- ];
59
- lm.on('data', () => {
60
- console.info(constants.clearFlag);
61
- enableTscCompiler && console.info(dtsLog.value);
62
- console.info(codeLog.value);
63
- console.info(styleLog.value);
64
- });
65
- await pMap(
66
- taskMapper,
67
- async ({ logger, taskPath, params }) => {
68
- const childProcess = execa.node(taskPath, params, { stdio: 'pipe' });
69
- if (logger === codeLog) {
70
- lm.addStdout(logger, childProcess.stdout, {
71
- event: { error: true, data: true },
72
- // colors: { data: s => s },
73
- });
74
- lm.addStderr(logger, childProcess.stderr);
75
- }
76
-
77
- if (logger === dtsLog) {
78
- lm.addStdout(logger, childProcess.stdout, {
79
- event: { data: true, error: true },
80
- colors: {
81
- // tsc 的log信息无论是错误还是正确都是从 data event 中获取到的
82
- data: s => s,
83
- },
84
- });
85
- }
86
-
87
- if (logger === styleLog || logger === copyLog) {
88
- lm.addStdout(logger, childProcess.stdout, {
89
- event: { error: true, data: true },
90
- // colors: { data: s => s },
91
- });
92
- lm.addStderr(logger, childProcess.stderr);
93
- }
94
-
95
- await childProcess;
96
- },
97
- { concurrency },
98
- );
99
- };