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