@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
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.logTemplate = exports.getDtsMapper = exports.getCodeMapper = exports.getCodeInitMapper = exports.TimeCounter = exports.LogStack = void 0;
|
|
7
|
+
|
|
8
|
+
var path = _interopRequireWildcard(require("path"));
|
|
9
|
+
|
|
10
|
+
var os = _interopRequireWildcard(require("os"));
|
|
11
|
+
|
|
12
|
+
var _utils = require("@modern-js/utils");
|
|
13
|
+
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
+
|
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
+
|
|
18
|
+
/* eslint-disable max-classes-per-file */
|
|
19
|
+
const constants = _utils.Import.lazy('./constants', require);
|
|
20
|
+
|
|
21
|
+
const core = _utils.Import.lazy('@modern-js/core', require); // 硬解字符串返回相应格式的对象
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const updateMapper = (packageFieldValue, outDir, mapper) => {
|
|
25
|
+
if (packageFieldValue === 'CJS+ES6') {
|
|
26
|
+
return [...mapper, {
|
|
27
|
+
type: 'commonjs',
|
|
28
|
+
syntax: 'es6+',
|
|
29
|
+
outDir
|
|
30
|
+
}];
|
|
31
|
+
} else if (packageFieldValue === 'ESM+ES5') {
|
|
32
|
+
return [...mapper, {
|
|
33
|
+
type: 'module',
|
|
34
|
+
syntax: 'es5',
|
|
35
|
+
outDir
|
|
36
|
+
}];
|
|
37
|
+
} else if (packageFieldValue === 'ESM+ES6') {
|
|
38
|
+
return [...mapper, {
|
|
39
|
+
type: 'module',
|
|
40
|
+
syntax: 'es6+',
|
|
41
|
+
outDir
|
|
42
|
+
}];
|
|
43
|
+
} else {
|
|
44
|
+
return [...mapper];
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const getCodeInitMapper = _ => {
|
|
49
|
+
const {
|
|
50
|
+
output: {
|
|
51
|
+
packageFields,
|
|
52
|
+
packageMode
|
|
53
|
+
}
|
|
54
|
+
} = core.useResolvedConfigContext().value;
|
|
55
|
+
let initMapper = []; // 如果不存在packageFields配置或者packageFields为空对象,则使用 packageMode
|
|
56
|
+
|
|
57
|
+
if (!packageFields || typeof packageFields === 'object' && Object.keys(packageFields).length === 0) {
|
|
58
|
+
initMapper = constants.PACKAGE_MODES[packageMode || constants.DEFAULT_PACKAGE_MODE];
|
|
59
|
+
} else if (packageFields && Object.keys(packageFields).length > 0) {
|
|
60
|
+
if (packageFields['modern']) {
|
|
61
|
+
initMapper = updateMapper(packageFields['modern'], 'modern', initMapper);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (packageFields.main) {
|
|
65
|
+
initMapper = updateMapper(packageFields.main, 'node', initMapper);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (packageFields.module) {
|
|
69
|
+
initMapper = updateMapper(packageFields.module, 'treeshaking', initMapper);
|
|
70
|
+
} // TODO: 如果存在其他配置,需要提示
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
if (!packageFields['modern'] && !packageFields.main && !packageFields.module) {
|
|
74
|
+
console.error(_utils.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
|
|
75
|
+
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return initMapper;
|
|
81
|
+
}; // 获取执行构建源码的参数
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
exports.getCodeInitMapper = getCodeInitMapper;
|
|
85
|
+
|
|
86
|
+
const getCodeMapper = ({
|
|
87
|
+
logger,
|
|
88
|
+
taskPath,
|
|
89
|
+
config,
|
|
90
|
+
initMapper,
|
|
91
|
+
srcRootDir,
|
|
92
|
+
willCompilerDirOrFile
|
|
93
|
+
}) => {
|
|
94
|
+
const {
|
|
95
|
+
value: {
|
|
96
|
+
appDirectory
|
|
97
|
+
}
|
|
98
|
+
} = core.useAppContext();
|
|
99
|
+
const modernConfig = core.useResolvedConfigContext().value;
|
|
100
|
+
const {
|
|
101
|
+
output: {
|
|
102
|
+
enableSourceMap,
|
|
103
|
+
jsPath = 'js',
|
|
104
|
+
path: distDir = 'dist'
|
|
105
|
+
}
|
|
106
|
+
} = modernConfig;
|
|
107
|
+
const {
|
|
108
|
+
tsconfigName = 'tsconfig.json'
|
|
109
|
+
} = config;
|
|
110
|
+
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
111
|
+
return initMapper.map(option => {
|
|
112
|
+
var _option$copyDirs;
|
|
113
|
+
|
|
114
|
+
// 不是output.copy配置,而是内部的js copy逻辑
|
|
115
|
+
const copyDirs = (_option$copyDirs = option.copyDirs) === null || _option$copyDirs === void 0 ? void 0 : _option$copyDirs.map(copyDir => path.join(appDirectory, `./${distDir}/${jsPath}/${copyDir}`));
|
|
116
|
+
return {
|
|
117
|
+
logger,
|
|
118
|
+
taskPath,
|
|
119
|
+
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}`]
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
}; // 获取执行生成 d.ts 的参数
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
exports.getCodeMapper = getCodeMapper;
|
|
126
|
+
|
|
127
|
+
const getDtsMapper = (config, logger) => {
|
|
128
|
+
const {
|
|
129
|
+
value: {
|
|
130
|
+
appDirectory
|
|
131
|
+
}
|
|
132
|
+
} = core.useAppContext();
|
|
133
|
+
const modernConfig = core.useResolvedConfigContext().value;
|
|
134
|
+
const {
|
|
135
|
+
output: {
|
|
136
|
+
disableTsChecker,
|
|
137
|
+
path: outputPath = 'dist'
|
|
138
|
+
}
|
|
139
|
+
} = modernConfig;
|
|
140
|
+
const {
|
|
141
|
+
tsconfigName = 'tsconfig.json',
|
|
142
|
+
enableWatchMode,
|
|
143
|
+
sourceDir
|
|
144
|
+
} = config;
|
|
145
|
+
const srcDir = path.join(appDirectory, './src');
|
|
146
|
+
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
147
|
+
return [{
|
|
148
|
+
logger,
|
|
149
|
+
taskPath: require.resolve("../../tasks/generator-dts"),
|
|
150
|
+
params: [`--srcDir=${srcDir}`, `--distDir=${path.join(appDirectory, `./${outputPath}/types`)}`, `--appDirectory=${appDirectory}`, `--tsconfigPath=${tsconfigPath}`, `--sourceDirName=${sourceDir}`, enableWatchMode ? `--watch` : '', disableTsChecker ? '' : `--tsCheck`]
|
|
151
|
+
}];
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* 处理日志信息
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
exports.getDtsMapper = getDtsMapper;
|
|
159
|
+
|
|
160
|
+
class LogStack {
|
|
161
|
+
constructor() {
|
|
162
|
+
this._codeLogStack = void 0;
|
|
163
|
+
this._codeLogStack = [];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
update(latestLog, {
|
|
167
|
+
splitEOL = false
|
|
168
|
+
} = {}) {
|
|
169
|
+
if (splitEOL) {
|
|
170
|
+
latestLog.split(os.EOL).forEach(log => {
|
|
171
|
+
this._codeLogStack.unshift(log.trim());
|
|
172
|
+
});
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
this._codeLogStack.unshift(latestLog.trim());
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
clear() {
|
|
180
|
+
this._codeLogStack = [];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
get value() {
|
|
184
|
+
return [...new Set(this._codeLogStack)];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
exports.LogStack = LogStack;
|
|
190
|
+
|
|
191
|
+
const logTemplate = (title, messageStack, maxLength, {
|
|
192
|
+
noBottomBorder: _noBottomBorder = false,
|
|
193
|
+
bottomBorderText: _bottomBorderText = '',
|
|
194
|
+
noLeftBorder: _noLeftBorder = false,
|
|
195
|
+
leftBorder: _leftBorder = '│',
|
|
196
|
+
contentColor: _contentColor = s => s
|
|
197
|
+
} = {}) => {
|
|
198
|
+
const leftBorderFlag = _noLeftBorder ? '' : _leftBorder;
|
|
199
|
+
const messageFragments = messageStack.map(p => {
|
|
200
|
+
p.trim();
|
|
201
|
+
return `${leftBorderFlag}${p.replace(constants.clearFlag, '')}`;
|
|
202
|
+
}) // 移除 clearFlag
|
|
203
|
+
.slice(0, maxLength) // 控制长度
|
|
204
|
+
.filter(s => s !== leftBorderFlag) // 过滤空字符串
|
|
205
|
+
.reverse(); // 调换顺序,最新的消息在最后面
|
|
206
|
+
|
|
207
|
+
const template = `${title}:
|
|
208
|
+
${_contentColor(messageFragments.join(os.EOL))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
|
|
209
|
+
return template;
|
|
210
|
+
}; // eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
exports.logTemplate = logTemplate;
|
|
214
|
+
|
|
215
|
+
class TimeCounter {
|
|
216
|
+
static time() {
|
|
217
|
+
this._now = Date.now();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
static timeEnd() {
|
|
221
|
+
const span = Date.now() - this._now;
|
|
222
|
+
|
|
223
|
+
return span < 1000 ? `${span}ms` : `${(span / 1000).toFixed(2)}s`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
}
|
|
227
|
+
/* eslint-enable max-classes-per-file */
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
exports.TimeCounter = TimeCounter;
|
|
231
|
+
TimeCounter._now = void 0;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.showMenu = exports.devStorybook = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("@modern-js/utils");
|
|
9
|
+
|
|
10
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
15
|
+
|
|
16
|
+
const inquirer = _utils.Import.lazy('inquirer', require);
|
|
17
|
+
|
|
18
|
+
const color = _utils.Import.lazy('../../utils/color', require);
|
|
19
|
+
|
|
20
|
+
const showMenu = async config => {
|
|
21
|
+
const metas = await core.mountHook().moduleToolsMenu(undefined);
|
|
22
|
+
|
|
23
|
+
if (metas.length <= 0) {
|
|
24
|
+
console.info(_chalk.default.yellow('No runnable development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
|
|
25
|
+
|
|
26
|
+
process.exit(0);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const menuMessage = color.devMenuTitle('Select the debug mode:');
|
|
30
|
+
const {
|
|
31
|
+
type
|
|
32
|
+
} = await inquirer.prompt([{
|
|
33
|
+
name: 'type',
|
|
34
|
+
message: menuMessage,
|
|
35
|
+
type: 'list',
|
|
36
|
+
choices: metas
|
|
37
|
+
}]);
|
|
38
|
+
const devMeta = metas.find(meta => meta.value === type);
|
|
39
|
+
|
|
40
|
+
if (devMeta) {
|
|
41
|
+
await devMeta.runTask(config);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.showMenu = showMenu;
|
|
46
|
+
|
|
47
|
+
const devStorybook = async config => {
|
|
48
|
+
const metas = await core.mountHook().moduleToolsMenu(undefined);
|
|
49
|
+
const findStorybook = metas.find(meta => meta.value === 'storybook');
|
|
50
|
+
|
|
51
|
+
if (findStorybook) {
|
|
52
|
+
await findStorybook.runTask(config);
|
|
53
|
+
} else {
|
|
54
|
+
console.info(_chalk.default.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
|
|
55
|
+
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.devStorybook = devStorybook;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.defineConfig = exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("@modern-js/utils");
|
|
9
|
+
|
|
10
|
+
const core = _utils.Import.lazy('@modern-js/core', require); // const { createPlugin, usePlugins, defineConfig } = core;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const hooks = _utils.Import.lazy('@modern-js/module-tools-hooks', require);
|
|
14
|
+
|
|
15
|
+
const cli = _utils.Import.lazy('./cli', require);
|
|
16
|
+
|
|
17
|
+
const local = _utils.Import.lazy('./locale', require);
|
|
18
|
+
|
|
19
|
+
const schema = _utils.Import.lazy('./schema', require);
|
|
20
|
+
|
|
21
|
+
const lang = _utils.Import.lazy('./utils/language', require);
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
defineConfig
|
|
25
|
+
} = core;
|
|
26
|
+
exports.defineConfig = defineConfig;
|
|
27
|
+
core.usePlugins([require.resolve('@modern-js/plugin-changeset/cli'), require.resolve('@modern-js/plugin-analyze/cli')]);
|
|
28
|
+
|
|
29
|
+
var _default = core.createPlugin(() => {
|
|
30
|
+
const locale = lang.getLocaleLanguage();
|
|
31
|
+
local.i18n.changeLanguage({
|
|
32
|
+
locale
|
|
33
|
+
});
|
|
34
|
+
hooks.lifecycle();
|
|
35
|
+
return {
|
|
36
|
+
validateSchema() {
|
|
37
|
+
return schema.addSchema();
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
config() {
|
|
41
|
+
return {
|
|
42
|
+
output: {
|
|
43
|
+
enableSourceMap: false,
|
|
44
|
+
jsPath: 'js'
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
commands({
|
|
50
|
+
program
|
|
51
|
+
}) {
|
|
52
|
+
cli.devCli(program);
|
|
53
|
+
cli.buildCli(program);
|
|
54
|
+
cli.newCli(program, locale); // 便于其他插件辨别
|
|
55
|
+
|
|
56
|
+
program.$$libraryName = 'module-tools';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
};
|
|
60
|
+
}, {
|
|
61
|
+
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset']
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
exports.default = _default;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.EN_LOCALE = void 0;
|
|
7
|
+
const EN_LOCALE = {
|
|
8
|
+
command: {
|
|
9
|
+
build: {
|
|
10
|
+
describe: 'command for building module',
|
|
11
|
+
watch: 'building module in watch mode',
|
|
12
|
+
tsconfig: 'Specify a path to the tsconfig.json file',
|
|
13
|
+
style_only: 'only build style',
|
|
14
|
+
platform: 'building for other platforms',
|
|
15
|
+
no_tsc: 'close tsc compiler to emit d.ts',
|
|
16
|
+
no_clear: 'disable auto clear dist dir'
|
|
17
|
+
},
|
|
18
|
+
dev: {
|
|
19
|
+
describe: 'start dev server'
|
|
20
|
+
},
|
|
21
|
+
new: {
|
|
22
|
+
describe: 'generator runner for modern project',
|
|
23
|
+
debug: 'using debug mode to log something',
|
|
24
|
+
config: 'set default generator config(json string)',
|
|
25
|
+
distTag: `use specified tag version for it's generator`,
|
|
26
|
+
registry: 'set npm registry url to run npm command'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.EN_LOCALE = EN_LOCALE;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.localeKeys = exports.i18n = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("@modern-js/utils");
|
|
9
|
+
|
|
10
|
+
var _zh = require("./zh");
|
|
11
|
+
|
|
12
|
+
var _en = require("./en");
|
|
13
|
+
|
|
14
|
+
const i18nPlugin = _utils.Import.lazy('@modern-js/plugin-i18n', require);
|
|
15
|
+
|
|
16
|
+
const i18n = new i18nPlugin.I18n();
|
|
17
|
+
exports.i18n = i18n;
|
|
18
|
+
const localeKeys = i18n.init('zh', {
|
|
19
|
+
zh: _zh.ZH_LOCALE,
|
|
20
|
+
en: _en.EN_LOCALE
|
|
21
|
+
});
|
|
22
|
+
exports.localeKeys = localeKeys;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ZH_LOCALE = void 0;
|
|
7
|
+
const ZH_LOCALE = {
|
|
8
|
+
command: {
|
|
9
|
+
build: {
|
|
10
|
+
describe: '构建模块命令',
|
|
11
|
+
watch: '使用 Watch 模式构建模块',
|
|
12
|
+
tsconfig: '指定 tsconfig.json 文件的路径',
|
|
13
|
+
style_only: '只构建样式文件',
|
|
14
|
+
platform: '构建其他平台产物',
|
|
15
|
+
no_tsc: '关闭 tsc 编译',
|
|
16
|
+
no_clear: '不清理产物目录'
|
|
17
|
+
},
|
|
18
|
+
dev: {
|
|
19
|
+
describe: '本地开发命令'
|
|
20
|
+
},
|
|
21
|
+
new: {
|
|
22
|
+
describe: '模块化工程方案中执行生成器',
|
|
23
|
+
debug: '开启 Debug 模式,打印调试日志信息',
|
|
24
|
+
config: '生成器运行默认配置(JSON 字符串)',
|
|
25
|
+
distTag: '生成器使用特殊的 npm Tag 版本',
|
|
26
|
+
registry: '生成器运行过程中定制 npm Registry'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.ZH_LOCALE = ZH_LOCALE;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.addSchema = void 0;
|
|
7
|
+
|
|
8
|
+
var _source = require("./source");
|
|
9
|
+
|
|
10
|
+
var _output = require("./output");
|
|
11
|
+
|
|
12
|
+
const addSchema = () => [..._source.sourceSchema, ..._output.outputSchema];
|
|
13
|
+
|
|
14
|
+
exports.addSchema = addSchema;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.outputSchema = void 0;
|
|
7
|
+
const PACKAGE_MODE_LIST = ['universal-js', 'universal-js-lite', 'browser-js', 'browser-js-lite', 'node-js'];
|
|
8
|
+
const outputSchema = [{
|
|
9
|
+
target: 'output.packageMode',
|
|
10
|
+
schema: {
|
|
11
|
+
enum: PACKAGE_MODE_LIST
|
|
12
|
+
}
|
|
13
|
+
}, {
|
|
14
|
+
target: 'output.packageFields',
|
|
15
|
+
schema: {
|
|
16
|
+
typeof: 'object'
|
|
17
|
+
}
|
|
18
|
+
}, {
|
|
19
|
+
target: 'output.disableTsChecker',
|
|
20
|
+
schema: {
|
|
21
|
+
typeof: 'boolean'
|
|
22
|
+
}
|
|
23
|
+
}, {
|
|
24
|
+
target: 'output.enableSourceMap',
|
|
25
|
+
schema: {
|
|
26
|
+
typeof: 'boolean'
|
|
27
|
+
}
|
|
28
|
+
}, {
|
|
29
|
+
target: 'output.importStyle',
|
|
30
|
+
schema: {
|
|
31
|
+
enum: ['compiled-code', 'source-code'],
|
|
32
|
+
// TODO: 目前default是无效的
|
|
33
|
+
default: 'source-code'
|
|
34
|
+
}
|
|
35
|
+
}];
|
|
36
|
+
exports.outputSchema = outputSchema;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sourceSchema = void 0;
|
|
7
|
+
const sourceSchema = [// 启动区块运行时
|
|
8
|
+
{
|
|
9
|
+
target: 'source.enableBlockRuntime',
|
|
10
|
+
schema: {
|
|
11
|
+
type: 'boolean'
|
|
12
|
+
}
|
|
13
|
+
}, {
|
|
14
|
+
target: 'source.jsxTransformRuntime',
|
|
15
|
+
schema: {
|
|
16
|
+
// https://babeljs.io/docs/en/babel-preset-react#runtime
|
|
17
|
+
enum: ['classic', 'automatic'],
|
|
18
|
+
// TODO: 目前default是无效的
|
|
19
|
+
default: 'automatic'
|
|
20
|
+
}
|
|
21
|
+
}];
|
|
22
|
+
exports.sourceSchema = sourceSchema;
|