@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.
Files changed (187) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +21 -0
  3. package/README.md +32 -0
  4. package/bin/modern.js +3 -0
  5. package/dist/js/modern/cli/build.js +9 -0
  6. package/dist/js/modern/cli/dev.js +8 -0
  7. package/dist/js/modern/cli/index.js +3 -0
  8. package/dist/js/modern/cli/new.js +16 -0
  9. package/dist/js/modern/commands/build.js +56 -0
  10. package/dist/js/modern/commands/dev.js +29 -0
  11. package/dist/js/modern/commands/index.js +2 -0
  12. package/dist/js/modern/features/build/build-platform.js +70 -0
  13. package/dist/js/modern/features/build/build-watch.js +96 -0
  14. package/dist/js/modern/features/build/build.js +110 -0
  15. package/dist/js/modern/features/build/constants.js +66 -0
  16. package/dist/js/modern/features/build/index.js +29 -0
  17. package/dist/js/modern/features/build/logger/index.js +2 -0
  18. package/dist/js/modern/features/build/logger/logText.js +63 -0
  19. package/dist/js/modern/features/build/logger/loggerManager.js +101 -0
  20. package/dist/js/modern/features/build/utils.js +198 -0
  21. package/dist/js/modern/features/dev/index.js +41 -0
  22. package/dist/js/modern/index.js +46 -0
  23. package/dist/js/modern/locale/en.js +23 -0
  24. package/dist/js/modern/locale/index.js +10 -0
  25. package/dist/js/modern/locale/zh.js +23 -0
  26. package/dist/js/modern/schema/index.js +3 -0
  27. package/dist/js/modern/schema/output.js +29 -0
  28. package/dist/js/modern/schema/source.js +15 -0
  29. package/dist/js/modern/tasks/build-source-code.js +213 -0
  30. package/dist/js/modern/tasks/build-style.js +152 -0
  31. package/dist/js/modern/tasks/build-watch-source-code.js +144 -0
  32. package/dist/js/modern/tasks/build-watch-style.js +213 -0
  33. package/dist/js/modern/tasks/constants.js +1 -0
  34. package/dist/js/modern/tasks/copy-assets.js +108 -0
  35. package/dist/js/modern/tasks/generator-dts.js +220 -0
  36. package/dist/js/modern/types.js +0 -0
  37. package/dist/js/modern/utils/babel.js +85 -0
  38. package/dist/js/modern/utils/color.js +2 -0
  39. package/dist/js/modern/utils/copy.js +80 -0
  40. package/dist/js/modern/utils/json.js +13 -0
  41. package/dist/js/modern/utils/language.js +6 -0
  42. package/dist/js/modern/utils/logger.js +110 -0
  43. package/dist/js/modern/utils/readline.js +19 -0
  44. package/dist/js/modern/utils/tsconfig.js +15 -0
  45. package/dist/js/modern/utils/tspaths-transform/constants.js +3 -0
  46. package/dist/js/modern/utils/tspaths-transform/index.js +130 -0
  47. package/dist/js/modern/utils/tspaths-transform/utils.js +21 -0
  48. package/dist/js/modern/utils/valide.js +28 -0
  49. package/dist/js/node/cli/build.js +21 -0
  50. package/dist/js/node/cli/dev.js +20 -0
  51. package/dist/js/node/cli/index.js +44 -0
  52. package/dist/js/node/cli/new.js +28 -0
  53. package/dist/js/node/commands/build.js +76 -0
  54. package/dist/js/node/commands/dev.js +49 -0
  55. package/dist/js/node/commands/index.js +21 -0
  56. package/dist/js/node/features/build/build-platform.js +84 -0
  57. package/dist/js/node/features/build/build-watch.js +118 -0
  58. package/dist/js/node/features/build/build.js +133 -0
  59. package/dist/js/node/features/build/constants.js +79 -0
  60. package/dist/js/node/features/build/index.js +41 -0
  61. package/dist/js/node/features/build/logger/index.js +31 -0
  62. package/dist/js/node/features/build/logger/logText.js +79 -0
  63. package/dist/js/node/features/build/logger/loggerManager.js +111 -0
  64. package/dist/js/node/features/build/utils.js +231 -0
  65. package/dist/js/node/features/dev/index.js +60 -0
  66. package/dist/js/node/index.js +64 -0
  67. package/dist/js/node/locale/en.js +30 -0
  68. package/dist/js/node/locale/index.js +22 -0
  69. package/dist/js/node/locale/zh.js +30 -0
  70. package/dist/js/node/schema/index.js +14 -0
  71. package/dist/js/node/schema/output.js +36 -0
  72. package/dist/js/node/schema/source.js +22 -0
  73. package/dist/js/node/tasks/build-source-code.js +240 -0
  74. package/dist/js/node/tasks/build-style.js +168 -0
  75. package/dist/js/node/tasks/build-watch-source-code.js +156 -0
  76. package/dist/js/node/tasks/build-watch-style.js +231 -0
  77. package/dist/js/node/tasks/constants.js +8 -0
  78. package/dist/js/node/tasks/copy-assets.js +126 -0
  79. package/dist/js/node/tasks/generator-dts.js +243 -0
  80. package/dist/js/node/types.js +0 -0
  81. package/dist/js/node/utils/babel.js +99 -0
  82. package/dist/js/node/utils/color.js +12 -0
  83. package/dist/js/node/utils/copy.js +99 -0
  84. package/dist/js/node/utils/json.js +22 -0
  85. package/dist/js/node/utils/language.js +15 -0
  86. package/dist/js/node/utils/logger.js +133 -0
  87. package/dist/js/node/utils/readline.js +33 -0
  88. package/dist/js/node/utils/tsconfig.js +30 -0
  89. package/dist/js/node/utils/tspaths-transform/constants.js +10 -0
  90. package/dist/js/node/utils/tspaths-transform/index.js +155 -0
  91. package/dist/js/node/utils/tspaths-transform/utils.js +32 -0
  92. package/dist/js/node/utils/valide.js +41 -0
  93. package/dist/types/cli/build.d.ts +2 -0
  94. package/dist/types/cli/dev.d.ts +2 -0
  95. package/dist/types/cli/index.d.ts +3 -0
  96. package/dist/types/cli/new.d.ts +2 -0
  97. package/dist/types/commands/build.d.ts +16 -0
  98. package/dist/types/commands/dev.d.ts +4 -0
  99. package/dist/types/commands/index.d.ts +2 -0
  100. package/dist/types/features/build/build-platform.d.ts +6 -0
  101. package/dist/types/features/build/build-watch.d.ts +3 -0
  102. package/dist/types/features/build/build.d.ts +3 -0
  103. package/dist/types/features/build/constants.d.ts +14 -0
  104. package/dist/types/features/build/index.d.ts +3 -0
  105. package/dist/types/features/build/logger/index.d.ts +2 -0
  106. package/dist/types/features/build/logger/logText.d.ts +39 -0
  107. package/dist/types/features/build/logger/loggerManager.d.ts +39 -0
  108. package/dist/types/features/build/utils.d.ts +58 -0
  109. package/dist/types/features/dev/index.d.ts +7 -0
  110. package/dist/types/index.d.ts +17 -0
  111. package/dist/types/locale/en.d.ts +23 -0
  112. package/dist/types/locale/index.d.ts +47 -0
  113. package/dist/types/locale/zh.d.ts +23 -0
  114. package/dist/types/schema/index.d.ts +36 -0
  115. package/dist/types/schema/output.d.ts +22 -0
  116. package/dist/types/schema/source.d.ts +15 -0
  117. package/dist/types/tasks/build-source-code.d.ts +42 -0
  118. package/dist/types/tasks/build-style.d.ts +1 -0
  119. package/dist/types/tasks/build-watch-source-code.d.ts +1 -0
  120. package/dist/types/tasks/build-watch-style.d.ts +1 -0
  121. package/dist/types/tasks/constants.d.ts +1 -0
  122. package/dist/types/tasks/copy-assets.d.ts +1 -0
  123. package/dist/types/tasks/generator-dts.d.ts +1 -0
  124. package/dist/types/types.d.ts +48 -0
  125. package/dist/types/utils/babel.d.ts +8 -0
  126. package/dist/types/utils/color.d.ts +2 -0
  127. package/dist/types/utils/copy.d.ts +5 -0
  128. package/dist/types/utils/json.d.ts +4 -0
  129. package/dist/types/utils/language.d.ts +1 -0
  130. package/dist/types/utils/logger.d.ts +56 -0
  131. package/dist/types/utils/readline.d.ts +9 -0
  132. package/dist/types/utils/tsconfig.d.ts +16 -0
  133. package/dist/types/utils/tspaths-transform/constants.d.ts +1 -0
  134. package/dist/types/utils/tspaths-transform/index.d.ts +15 -0
  135. package/dist/types/utils/tspaths-transform/utils.d.ts +4 -0
  136. package/dist/types/utils/valide.d.ts +12 -0
  137. package/modern.config.js +6 -0
  138. package/package.json +95 -0
  139. package/src/.eslintrc.json +5 -0
  140. package/src/cli/build.ts +39 -0
  141. package/src/cli/dev.ts +24 -0
  142. package/src/cli/index.ts +3 -0
  143. package/src/cli/new.ts +32 -0
  144. package/src/commands/build.ts +81 -0
  145. package/src/commands/dev.ts +41 -0
  146. package/src/commands/index.ts +2 -0
  147. package/src/features/build/build-platform.ts +76 -0
  148. package/src/features/build/build-watch.ts +93 -0
  149. package/src/features/build/build.ts +111 -0
  150. package/src/features/build/constants.ts +52 -0
  151. package/src/features/build/index.ts +36 -0
  152. package/src/features/build/logger/index.ts +2 -0
  153. package/src/features/build/logger/logText.ts +80 -0
  154. package/src/features/build/logger/loggerManager.ts +132 -0
  155. package/src/features/build/utils.ts +250 -0
  156. package/src/features/dev/index.ts +62 -0
  157. package/src/index.ts +55 -0
  158. package/src/locale/en.ts +21 -0
  159. package/src/locale/index.ts +15 -0
  160. package/src/locale/zh.ts +21 -0
  161. package/src/schema/index.ts +4 -0
  162. package/src/schema/output.ts +34 -0
  163. package/src/schema/schema.d.ts +13 -0
  164. package/src/schema/source.ts +16 -0
  165. package/src/tasks/build-source-code.ts +245 -0
  166. package/src/tasks/build-style.ts +175 -0
  167. package/src/tasks/build-watch-source-code.ts +185 -0
  168. package/src/tasks/build-watch-style.ts +260 -0
  169. package/src/tasks/constants.ts +1 -0
  170. package/src/tasks/copy-assets.ts +117 -0
  171. package/src/tasks/generator-dts.ts +277 -0
  172. package/src/type.d.ts +1 -0
  173. package/src/types.ts +63 -0
  174. package/src/utils/babel.ts +100 -0
  175. package/src/utils/color.ts +3 -0
  176. package/src/utils/copy.ts +70 -0
  177. package/src/utils/json.ts +13 -0
  178. package/src/utils/language.ts +9 -0
  179. package/src/utils/logger.ts +144 -0
  180. package/src/utils/readline.ts +28 -0
  181. package/src/utils/tsconfig.ts +37 -0
  182. package/src/utils/tspaths-transform/constants.ts +19 -0
  183. package/src/utils/tspaths-transform/index.ts +139 -0
  184. package/src/utils/tspaths-transform/utils.ts +25 -0
  185. package/src/utils/valide.ts +37 -0
  186. package/tsconfig.json +13 -0
  187. package/types.d.ts +1 -0
@@ -0,0 +1,101 @@
1
+ let _ = t => t,
2
+ _t;
3
+
4
+ /**
5
+ * 1. 注册构建任务
6
+ * 2. 监听各个构建任务进程中的信息:process.stdout.on('data' | 'error')
7
+ * 3. 分别输出内容
8
+ */
9
+ import EventEmitter from 'events';
10
+ import { chalk, Import } from '@modern-js/utils';
11
+ const logText = Import.lazy('./logText', require);
12
+ const readline = Import.lazy('../../../utils/readline', require);
13
+ export class LoggerManager extends EventEmitter {
14
+ constructor() {
15
+ super();
16
+ this._compilering = void 0;
17
+ this._listeners = void 0;
18
+ this._compilering = false;
19
+ this._listeners = [];
20
+ }
21
+
22
+ createLoggerText(option) {
23
+ return new logText.LoggerText(option);
24
+ }
25
+
26
+ addStdout(loggerText, stdout, config = {}) {
27
+ const {
28
+ event = {
29
+ data: true,
30
+ error: true
31
+ },
32
+ colors = {
33
+ data: chalk.green,
34
+ error: chalk.red,
35
+ warning: chalk.yellow
36
+ }
37
+ } = config;
38
+
39
+ if (event.data) {
40
+ stdout === null || stdout === void 0 ? void 0 : stdout.on('data', chunk => {
41
+ const data = chunk.toString();
42
+ const content = colors.data ? colors.data(data) : chalk.green(data);
43
+ loggerText.append(content);
44
+ this.emit('data');
45
+ });
46
+ }
47
+
48
+ if (event.error) {
49
+ stdout === null || stdout === void 0 ? void 0 : stdout.on('error', error => {
50
+ console.info('error');
51
+ const data = error.message;
52
+ const content = colors.error ? colors.error(data) : chalk.red(data);
53
+ loggerText.append(content);
54
+ loggerText.errorHappen();
55
+ this.emit('data');
56
+ });
57
+ }
58
+
59
+ this._listeners.push(stdout);
60
+ }
61
+
62
+ addStderr(loggerText, stderr, color = chalk.red) {
63
+ stderr === null || stderr === void 0 ? void 0 : stderr.on('data', chunk => {
64
+ const data = chunk.toString();
65
+ loggerText.append(color(data));
66
+ loggerText.errorHappen();
67
+ this.emit('data');
68
+ });
69
+ }
70
+
71
+ showCompiling() {
72
+ if (!this._compilering) {
73
+ this._compilering = true;
74
+ console.info(chalk.green(_t || (_t = _`Compiling in progress...`)));
75
+ }
76
+ }
77
+
78
+ disappearCompiling() {
79
+ if (this._compilering) {
80
+ readline.ReadlineUtils.clearLine(process.stdout);
81
+ this._compilering = false;
82
+ }
83
+ }
84
+
85
+ listenDateAndShow(logTexts // stdout: NodeJS.WriteStream & {
86
+ // fd: 1;
87
+ // } = process.stdout,
88
+ ) {
89
+ this.on('data', () => {
90
+ this.disappearCompiling();
91
+ const content = logTexts.map(logtext => logtext.value).join(''); // 每次更新,使用新的内容覆盖旧的内容,有几率出现内容错乱问题
92
+
93
+ console.info(content);
94
+ });
95
+ return () => {
96
+ // eslint-disable-next-line no-process-exit
97
+ process.exit(0);
98
+ };
99
+ }
100
+
101
+ }
@@ -0,0 +1,198 @@
1
+ /* eslint-disable max-classes-per-file */
2
+ import * as path from 'path';
3
+ import * as os from 'os';
4
+ import { Import, chalk } from '@modern-js/utils';
5
+ const constants = Import.lazy('./constants', require);
6
+ const core = Import.lazy('@modern-js/core', require); // 硬解字符串返回相应格式的对象
7
+
8
+ const updateMapper = (packageFieldValue, outDir, mapper) => {
9
+ if (packageFieldValue === 'CJS+ES6') {
10
+ return [...mapper, {
11
+ type: 'commonjs',
12
+ syntax: 'es6+',
13
+ outDir
14
+ }];
15
+ } else if (packageFieldValue === 'ESM+ES5') {
16
+ return [...mapper, {
17
+ type: 'module',
18
+ syntax: 'es5',
19
+ outDir
20
+ }];
21
+ } else if (packageFieldValue === 'ESM+ES6') {
22
+ return [...mapper, {
23
+ type: 'module',
24
+ syntax: 'es6+',
25
+ outDir
26
+ }];
27
+ } else {
28
+ return [...mapper];
29
+ }
30
+ };
31
+
32
+ export const getCodeInitMapper = _ => {
33
+ const {
34
+ output: {
35
+ packageFields,
36
+ packageMode
37
+ }
38
+ } = core.useResolvedConfigContext().value;
39
+ let initMapper = []; // 如果不存在packageFields配置或者packageFields为空对象,则使用 packageMode
40
+
41
+ if (!packageFields || typeof packageFields === 'object' && Object.keys(packageFields).length === 0) {
42
+ initMapper = constants.PACKAGE_MODES[packageMode || constants.DEFAULT_PACKAGE_MODE];
43
+ } else if (packageFields && Object.keys(packageFields).length > 0) {
44
+ if (packageFields['modern']) {
45
+ initMapper = updateMapper(packageFields['modern'], 'modern', initMapper);
46
+ }
47
+
48
+ if (packageFields.main) {
49
+ initMapper = updateMapper(packageFields.main, 'node', initMapper);
50
+ }
51
+
52
+ if (packageFields.module) {
53
+ initMapper = updateMapper(packageFields.module, 'treeshaking', initMapper);
54
+ } // TODO: 如果存在其他配置,需要提示
55
+
56
+
57
+ if (!packageFields['modern'] && !packageFields.main && !packageFields.module) {
58
+ console.error(chalk.red(`Unrecognized ${JSON.stringify(packageFields)} configuration, please use keys: 'modern, main, jupiter:modern' and use values: 'CJS+ES6, ESM+ES5, ESM+ES6'`)); // eslint-disable-next-line no-process-exit
59
+
60
+ process.exit(1);
61
+ }
62
+ }
63
+
64
+ return initMapper;
65
+ }; // 获取执行构建源码的参数
66
+
67
+ export const getCodeMapper = ({
68
+ logger,
69
+ taskPath,
70
+ config,
71
+ initMapper,
72
+ srcRootDir,
73
+ willCompilerDirOrFile
74
+ }) => {
75
+ const {
76
+ value: {
77
+ appDirectory
78
+ }
79
+ } = core.useAppContext();
80
+ const modernConfig = core.useResolvedConfigContext().value;
81
+ const {
82
+ output: {
83
+ enableSourceMap,
84
+ jsPath = 'js',
85
+ path: distDir = 'dist'
86
+ }
87
+ } = modernConfig;
88
+ const {
89
+ tsconfigName = 'tsconfig.json'
90
+ } = config;
91
+ const tsconfigPath = path.join(appDirectory, tsconfigName);
92
+ return initMapper.map(option => {
93
+ var _option$copyDirs;
94
+
95
+ // 不是output.copy配置,而是内部的js copy逻辑
96
+ const copyDirs = (_option$copyDirs = option.copyDirs) === null || _option$copyDirs === void 0 ? void 0 : _option$copyDirs.map(copyDir => path.join(appDirectory, `./${distDir}/${jsPath}/${copyDir}`));
97
+ return {
98
+ logger,
99
+ taskPath,
100
+ params: [`--syntax=${option.syntax}`, `--type=${option.type}`, `--srcRootDir=${srcRootDir}`, `--willCompilerDirOrFile=${willCompilerDirOrFile}`, copyDirs ? `--copyDirs=${copyDirs.join(',')}` : '', `--distDir=${path.join(appDirectory, `./${distDir}/${jsPath}/${option.outDir}`)}`, `--appDirectory=${appDirectory}`, enableSourceMap ? '--sourceMaps' : '', `--tsconfigPath=${tsconfigPath}`]
101
+ };
102
+ });
103
+ }; // 获取执行生成 d.ts 的参数
104
+
105
+ export const getDtsMapper = (config, logger) => {
106
+ const {
107
+ value: {
108
+ appDirectory
109
+ }
110
+ } = core.useAppContext();
111
+ const modernConfig = core.useResolvedConfigContext().value;
112
+ const {
113
+ output: {
114
+ disableTsChecker,
115
+ path: outputPath = 'dist'
116
+ }
117
+ } = modernConfig;
118
+ const {
119
+ tsconfigName = 'tsconfig.json',
120
+ enableWatchMode,
121
+ sourceDir
122
+ } = config;
123
+ const srcDir = path.join(appDirectory, './src');
124
+ const tsconfigPath = path.join(appDirectory, tsconfigName);
125
+ return [{
126
+ logger,
127
+ taskPath: require.resolve("../../tasks/generator-dts"),
128
+ params: [`--srcDir=${srcDir}`, `--distDir=${path.join(appDirectory, `./${outputPath}/types`)}`, `--appDirectory=${appDirectory}`, `--tsconfigPath=${tsconfigPath}`, `--sourceDirName=${sourceDir}`, enableWatchMode ? `--watch` : '', disableTsChecker ? '' : `--tsCheck`]
129
+ }];
130
+ };
131
+ /**
132
+ * 处理日志信息
133
+ */
134
+
135
+ export class LogStack {
136
+ constructor() {
137
+ this._codeLogStack = void 0;
138
+ this._codeLogStack = [];
139
+ }
140
+
141
+ update(latestLog, {
142
+ splitEOL = false
143
+ } = {}) {
144
+ if (splitEOL) {
145
+ latestLog.split(os.EOL).forEach(log => {
146
+ this._codeLogStack.unshift(log.trim());
147
+ });
148
+ return;
149
+ }
150
+
151
+ this._codeLogStack.unshift(latestLog.trim());
152
+ }
153
+
154
+ clear() {
155
+ this._codeLogStack = [];
156
+ }
157
+
158
+ get value() {
159
+ return [...new Set(this._codeLogStack)];
160
+ }
161
+
162
+ }
163
+ export const logTemplate = (title, messageStack, maxLength, {
164
+ noBottomBorder: _noBottomBorder = false,
165
+ bottomBorderText: _bottomBorderText = '',
166
+ noLeftBorder: _noLeftBorder = false,
167
+ leftBorder: _leftBorder = '│',
168
+ contentColor: _contentColor = s => s
169
+ } = {}) => {
170
+ const leftBorderFlag = _noLeftBorder ? '' : _leftBorder;
171
+ const messageFragments = messageStack.map(p => {
172
+ p.trim();
173
+ return `${leftBorderFlag}${p.replace(constants.clearFlag, '')}`;
174
+ }) // 移除 clearFlag
175
+ .slice(0, maxLength) // 控制长度
176
+ .filter(s => s !== leftBorderFlag) // 过滤空字符串
177
+ .reverse(); // 调换顺序,最新的消息在最后面
178
+
179
+ const template = `${title}:
180
+ ${_contentColor(messageFragments.join(os.EOL))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
181
+ return template;
182
+ }; // eslint-disable-next-line @typescript-eslint/no-extraneous-class
183
+
184
+ export class TimeCounter {
185
+ static time() {
186
+ this._now = Date.now();
187
+ }
188
+
189
+ static timeEnd() {
190
+ const span = Date.now() - this._now;
191
+
192
+ return span < 1000 ? `${span}ms` : `${(span / 1000).toFixed(2)}s`;
193
+ }
194
+
195
+ }
196
+ /* eslint-enable max-classes-per-file */
197
+
198
+ TimeCounter._now = void 0;
@@ -0,0 +1,41 @@
1
+ import { Import } from '@modern-js/utils';
2
+ import chalk from 'chalk';
3
+ const core = Import.lazy('@modern-js/core', require);
4
+ const inquirer = Import.lazy('inquirer', require);
5
+ const color = Import.lazy('../../utils/color', require);
6
+ export const showMenu = async config => {
7
+ const metas = await core.mountHook().moduleToolsMenu(undefined);
8
+
9
+ if (metas.length <= 0) {
10
+ console.info(chalk.yellow('No runnable development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
11
+
12
+ process.exit(0);
13
+ }
14
+
15
+ const menuMessage = color.devMenuTitle('Select the debug mode:');
16
+ const {
17
+ type
18
+ } = await inquirer.prompt([{
19
+ name: 'type',
20
+ message: menuMessage,
21
+ type: 'list',
22
+ choices: metas
23
+ }]);
24
+ const devMeta = metas.find(meta => meta.value === type);
25
+
26
+ if (devMeta) {
27
+ await devMeta.runTask(config);
28
+ }
29
+ };
30
+ export const devStorybook = async config => {
31
+ const metas = await core.mountHook().moduleToolsMenu(undefined);
32
+ const findStorybook = metas.find(meta => meta.value === 'storybook');
33
+
34
+ if (findStorybook) {
35
+ await findStorybook.runTask(config);
36
+ } else {
37
+ console.info(chalk.yellow('You need to enable storybook functionality with the `new` script or `modern new` or install @modern-js/plugin-storybook')); // eslint-disable-next-line no-process-exit
38
+
39
+ process.exit(0);
40
+ }
41
+ };
@@ -0,0 +1,46 @@
1
+ import { Import } from '@modern-js/utils';
2
+ const core = Import.lazy('@modern-js/core', require); // const { createPlugin, usePlugins, defineConfig } = core;
3
+
4
+ const hooks = Import.lazy('@modern-js/module-tools-hooks', require);
5
+ const cli = Import.lazy('./cli', require);
6
+ const local = Import.lazy('./locale', require);
7
+ const schema = Import.lazy('./schema', require);
8
+ const lang = Import.lazy('./utils/language', require);
9
+ export const {
10
+ defineConfig
11
+ } = core;
12
+ core.usePlugins([require.resolve('@modern-js/plugin-changeset/cli'), require.resolve('@modern-js/plugin-analyze/cli')]);
13
+ export default core.createPlugin(() => {
14
+ const locale = lang.getLocaleLanguage();
15
+ local.i18n.changeLanguage({
16
+ locale
17
+ });
18
+ hooks.lifecycle();
19
+ return {
20
+ validateSchema() {
21
+ return schema.addSchema();
22
+ },
23
+
24
+ config() {
25
+ return {
26
+ output: {
27
+ enableSourceMap: false,
28
+ jsPath: 'js'
29
+ }
30
+ };
31
+ },
32
+
33
+ commands({
34
+ program
35
+ }) {
36
+ cli.devCli(program);
37
+ cli.buildCli(program);
38
+ cli.newCli(program, locale); // 便于其他插件辨别
39
+
40
+ program.$$libraryName = 'module-tools';
41
+ }
42
+
43
+ };
44
+ }, {
45
+ post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset']
46
+ });
@@ -0,0 +1,23 @@
1
+ export const EN_LOCALE = {
2
+ command: {
3
+ build: {
4
+ describe: 'command for building module',
5
+ watch: 'building module in watch mode',
6
+ tsconfig: 'Specify a path to the tsconfig.json file',
7
+ style_only: 'only build style',
8
+ platform: 'building for other platforms',
9
+ no_tsc: 'close tsc compiler to emit d.ts',
10
+ no_clear: 'disable auto clear dist dir'
11
+ },
12
+ dev: {
13
+ describe: 'start dev server'
14
+ },
15
+ new: {
16
+ describe: 'generator runner for modern project',
17
+ debug: 'using debug mode to log something',
18
+ config: 'set default generator config(json string)',
19
+ distTag: `use specified tag version for it's generator`,
20
+ registry: 'set npm registry url to run npm command'
21
+ }
22
+ }
23
+ };
@@ -0,0 +1,10 @@
1
+ import { Import } from '@modern-js/utils';
2
+ import { ZH_LOCALE } from "./zh";
3
+ import { EN_LOCALE } from "./en";
4
+ const i18nPlugin = Import.lazy('@modern-js/plugin-i18n', require);
5
+ const i18n = new i18nPlugin.I18n();
6
+ const localeKeys = i18n.init('zh', {
7
+ zh: ZH_LOCALE,
8
+ en: EN_LOCALE
9
+ });
10
+ export { i18n, localeKeys };
@@ -0,0 +1,23 @@
1
+ export const ZH_LOCALE = {
2
+ command: {
3
+ build: {
4
+ describe: '构建模块命令',
5
+ watch: '使用 Watch 模式构建模块',
6
+ tsconfig: '指定 tsconfig.json 文件的路径',
7
+ style_only: '只构建样式文件',
8
+ platform: '构建其他平台产物',
9
+ no_tsc: '关闭 tsc 编译',
10
+ no_clear: '不清理产物目录'
11
+ },
12
+ dev: {
13
+ describe: '本地开发命令'
14
+ },
15
+ new: {
16
+ describe: '模块化工程方案中执行生成器',
17
+ debug: '开启 Debug 模式,打印调试日志信息',
18
+ config: '生成器运行默认配置(JSON 字符串)',
19
+ distTag: '生成器使用特殊的 npm Tag 版本',
20
+ registry: '生成器运行过程中定制 npm Registry'
21
+ }
22
+ }
23
+ };
@@ -0,0 +1,3 @@
1
+ import { sourceSchema } from "./source";
2
+ import { outputSchema } from "./output";
3
+ export const addSchema = () => [...sourceSchema, ...outputSchema];
@@ -0,0 +1,29 @@
1
+ const PACKAGE_MODE_LIST = ['universal-js', 'universal-js-lite', 'browser-js', 'browser-js-lite', 'node-js'];
2
+ export const outputSchema = [{
3
+ target: 'output.packageMode',
4
+ schema: {
5
+ enum: PACKAGE_MODE_LIST
6
+ }
7
+ }, {
8
+ target: 'output.packageFields',
9
+ schema: {
10
+ typeof: 'object'
11
+ }
12
+ }, {
13
+ target: 'output.disableTsChecker',
14
+ schema: {
15
+ typeof: 'boolean'
16
+ }
17
+ }, {
18
+ target: 'output.enableSourceMap',
19
+ schema: {
20
+ typeof: 'boolean'
21
+ }
22
+ }, {
23
+ target: 'output.importStyle',
24
+ schema: {
25
+ enum: ['compiled-code', 'source-code'],
26
+ // TODO: 目前default是无效的
27
+ default: 'source-code'
28
+ }
29
+ }];
@@ -0,0 +1,15 @@
1
+ export const sourceSchema = [// 启动区块运行时
2
+ {
3
+ target: 'source.enableBlockRuntime',
4
+ schema: {
5
+ type: 'boolean'
6
+ }
7
+ }, {
8
+ target: 'source.jsxTransformRuntime',
9
+ schema: {
10
+ // https://babeljs.io/docs/en/babel-preset-react#runtime
11
+ enum: ['classic', 'automatic'],
12
+ // TODO: 目前default是无效的
13
+ default: 'automatic'
14
+ }
15
+ }];