@tmsfe/tmskit 0.0.1

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 (39) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/README.md +24 -0
  3. package/dist/index.cjs.js +2248 -0
  4. package/main.js +3 -0
  5. package/package.json +72 -0
  6. package/rollup.config.js +179 -0
  7. package/src/config/constant.js +65 -0
  8. package/src/config/defaultTmsConfig.js +17 -0
  9. package/src/entry.js +20 -0
  10. package/src/index.js +47 -0
  11. package/src/init.js +38 -0
  12. package/src/scripts/create/ask.js +61 -0
  13. package/src/scripts/create/generator.js +27 -0
  14. package/src/scripts/create/ignoreFiles.js +7 -0
  15. package/src/scripts/create/index.js +65 -0
  16. package/src/scripts/create/render.js +19 -0
  17. package/src/scripts/run/build/index.js +16 -0
  18. package/src/scripts/run/dev/index.js +67 -0
  19. package/src/scripts/run/index.js +57 -0
  20. package/src/scripts/run/init/index.js +97 -0
  21. package/src/utils/buildAppJson.js +144 -0
  22. package/src/utils/checkDependencies.js +77 -0
  23. package/src/utils/cliUtils.js +35 -0
  24. package/src/utils/cloneModules.js +90 -0
  25. package/src/utils/global.js +36 -0
  26. package/src/utils/io.js +21 -0
  27. package/src/utils/log.js +44 -0
  28. package/src/utils/mpCiUtils.js +74 -0
  29. package/src/utils/npmUtils.js +126 -0
  30. package/src/utils/tkitUtils.js +84 -0
  31. package/src/utils/widgets.js +177 -0
  32. package/src/webpack/base.js +65 -0
  33. package/src/webpack/build.js +21 -0
  34. package/src/webpack/buildServer.js +34 -0
  35. package/src/webpack/dev.js +31 -0
  36. package/src/webpack/devServer.js +37 -0
  37. package/src/webpack/plugins/entryExtractPlugin/index.js +29 -0
  38. package/src/webpack/plugins/px2rpx/index.js +14 -0
  39. package/src/webpack/utils.js +244 -0
package/main.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('./dist/index.cjs'); // eslint-disable-line
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@tmsfe/tmskit",
3
+ "version": "0.0.1",
4
+ "description": "tmskit",
5
+ "main": "main.js",
6
+ "bin": {
7
+ "tmskit": "main.js"
8
+ },
9
+ "scripts": {
10
+ "dev": "rollup -wc --environment TARGET:tmskit",
11
+ "build": "rollup -c --environment TARGET:tmskit"
12
+ },
13
+ "author": "tms·web",
14
+ "license": "ISC",
15
+ "buildOptions": {
16
+ "formats": [
17
+ "cjs"
18
+ ]
19
+ },
20
+ "devDependencies": {
21
+ "@babel/core": "^7.15.0",
22
+ "@babel/plugin-transform-modules-commonjs": "^7.16.0",
23
+ "@babel/preset-env": "^7.16.0",
24
+ "@rollup/plugin-babel": "^5.0.2",
25
+ "@rollup/plugin-commonjs": "^19.0.0",
26
+ "@rollup/plugin-dynamic-import-vars": "^1.1.1",
27
+ "@rollup/plugin-json": "^4.0.3",
28
+ "async": "^3.2.2",
29
+ "babel-core": "^6.26.3",
30
+ "babel-loader": "^8.2.3",
31
+ "copy-webpack-plugin": "^9.1.0",
32
+ "cross-env": "^7.0.3",
33
+ "leven": "3.1.0",
34
+ "metalsmith": "^2.3.0",
35
+ "minimist": "^1.2.5",
36
+ "rollup": "^2.6.1",
37
+ "rollup-plugin-node-resolve": "^5.2.0",
38
+ "rollup-plugin-terser": "^6.1.0",
39
+ "rollup-plugin-typescript2": "0.27.0",
40
+ "ts-loader": "^9.2.6",
41
+ "url-loader": "^4.1.1",
42
+ "webpack": "^5.64.0",
43
+ "webpack-cli": "^4.9.1"
44
+ },
45
+ "dependencies": {
46
+ "axios": "^0.21.4",
47
+ "chalk": "^4.1.0",
48
+ "commander": "^6.2.1",
49
+ "download-git-repo": "^3.0.2",
50
+ "ejs": "^3.1.5",
51
+ "file-loader": "^6.2.0",
52
+ "fs-extra": "^9.0.1",
53
+ "inquirer": "^7.3.3",
54
+ "lodash": "^4.17.21",
55
+ "mini-css-extract-plugin": "^2.4.5",
56
+ "miniprogram-ci": "1.4.13",
57
+ "ora": "^5.1.0",
58
+ "replace-ext": "^2.0.0",
59
+ "rollup-plugin-replace": "^2.2.0",
60
+ "shelljs": "^0.8.4",
61
+ "tslib": "^1.14.1",
62
+ "typescript": "^3.8.3",
63
+ "username": "5.1.0",
64
+ "webpack-chain": "^6.5.1"
65
+ },
66
+ "engines": {
67
+ "node": "^12.17.0 || >= 14.0.0"
68
+ },
69
+ "jest": {
70
+ "testEnvironment": "jest-environment-node"
71
+ }
72
+ }
@@ -0,0 +1,179 @@
1
+ import path from 'path';
2
+ import ts from 'rollup-plugin-typescript2';
3
+ import babel from '@rollup/plugin-babel';
4
+ import json from '@rollup/plugin-json';
5
+ import replace from 'rollup-plugin-replace';
6
+ import nodeResolve from 'rollup-plugin-node-resolve';
7
+ import commonjs from '@rollup/plugin-commonjs';
8
+
9
+ if (!process.env.TARGET) {
10
+ throw new Error('TARGET package must be specified via --environment flag.');
11
+ }
12
+
13
+ // 指定包地址
14
+ const packageDir = path.resolve(__dirname);
15
+ // 包名
16
+ const name = path.basename(packageDir);
17
+ // 环境
18
+ const interEnv = process.env.INTER_ENV || 'public';
19
+
20
+ // eslint-disable-next-line
21
+ const packageJson = require('./package.json');
22
+
23
+ const packageOptions = packageJson.buildOptions || {};
24
+
25
+ function resolve(name) { // eslint-disable-line
26
+ return path.resolve(packageDir, name);
27
+ }
28
+
29
+ const outputConfig = {
30
+ esm: {
31
+ dir: resolve('dist'),
32
+ entryFileNames: '[name].js',
33
+ format: 'es',
34
+ },
35
+ 'esm-browser': {
36
+ dir: resolve('dist'),
37
+ entryFileNames: '[name].esm-browser.js',
38
+ format: 'es',
39
+ },
40
+ cjs: {
41
+ dir: resolve('dist'),
42
+ entryFileNames: '[name].cjs.js',
43
+ format: 'cjs',
44
+ },
45
+ global: {
46
+ dir: resolve('dist'),
47
+ entryFileNames: '[name].global.js',
48
+ format: 'iife',
49
+ },
50
+ };
51
+
52
+ const defaultFormats = ['esm'];
53
+ // 打包格式
54
+ const packageFormats = packageOptions.formats || defaultFormats;
55
+
56
+ const packageConfigs = packageFormats.map(format => createConfig(format, outputConfig[format]));
57
+
58
+ export default packageConfigs;
59
+
60
+ /**
61
+ * format rollup package configuration object
62
+ * @param {string} format 文件打包格式
63
+ * @param {object} output 输出对象
64
+ * @param {array} plugins 插件
65
+ * @returns {object} rollup配置对象
66
+ */
67
+ function createConfig(format, output, plugins = []) {
68
+ if (!output) {
69
+ // eslint-disable-next-line
70
+ console.log(require('chalk').yellow(`invalid format: "${format}"`)); // eslint-disable-line no-console
71
+ process.exit(1);
72
+ }
73
+
74
+ output.sourceMap = true; // eslint-disable-line
75
+ output.externalLiveBindings = false; // eslint-disable-line
76
+
77
+ // 兼容不同的包的入口文件 -- 后面会统一为index.ts
78
+ const entryFile = setEntryFile(name);
79
+
80
+ // 定制化cjs的插件和esmodule的插件。
81
+ const extralPlugin = setEsPlugin(output.format);
82
+
83
+ return {
84
+ input: entryFile,
85
+ output,
86
+ external: [],
87
+ plugins: [
88
+ json({
89
+ namedExports: false,
90
+ }),
91
+ commonjs({
92
+ ignoreDynamicRequires: true,
93
+ // include: 'node_modules/**', // Default: undefined
94
+ browser: true,
95
+ }),
96
+ babel({
97
+ plugins: ['@babel/plugin-proposal-nullish-coalescing-operator', '@babel/plugin-proposal-optional-chaining'],
98
+ // exclude: ['node_modules/**'],
99
+ }),
100
+ // terser(),
101
+ createReplacePlugin(),
102
+ ...extralPlugin,
103
+ ...plugins,
104
+ ],
105
+ onwarn: (msg, warn) => {
106
+ if (!/Circular/.test(msg)) {
107
+ warn(msg);
108
+ }
109
+ },
110
+ treeshake: {
111
+ moduleSideEffects: false,
112
+ },
113
+ };
114
+ }
115
+
116
+ /**
117
+ * 兼容现在的包会存在不同入口的情况。 后面会统一为index.ts
118
+ * @param { string } packageName 包名称
119
+ * @returns { Object } entryFile
120
+ */
121
+ function setEntryFile(packageName) {
122
+ let entryFile = resolve('src/index.js');
123
+
124
+ switch (packageName) {
125
+ case 'tms-core':
126
+ entryFile = {
127
+ index: resolve('src/index'),
128
+ request: resolve('src/request'),
129
+ cloudService: resolve('src/cloudService'),
130
+ };
131
+ if (interEnv !== 'public') {
132
+ entryFile['index-proxy'] = resolve('src/index-proxy');
133
+ }
134
+ break;
135
+ case 'tms-websdk':
136
+ entryFile = resolve('src/index.ts');
137
+ break;
138
+ default:
139
+ entryFile = resolve('src/index.js');
140
+ };
141
+
142
+ return entryFile;
143
+ }
144
+
145
+ /**
146
+ * 定制化cjs和esmodule的插件
147
+ * @param { string } format 打包格式
148
+ * @returns { Array<plugin> } 插件数组
149
+ */
150
+ function setEsPlugin(format) {
151
+ const extralPlugins = [];
152
+
153
+
154
+ if (format.indexOf('es') > -1) {
155
+ extralPlugins.push(ts({
156
+ tsconfig: resolve('tsconfig.json'),
157
+ }));
158
+ };
159
+ if (format.indexOf('iife') > -1) {
160
+ extralPlugins.push(nodeResolve({ jsnext: true, preferBuiltins: true, browser: true }));
161
+ }
162
+ return extralPlugins;
163
+ }
164
+
165
+ /**
166
+ * 创建变量替换插件
167
+ * @returns {function} 插件函数
168
+ */
169
+ function createReplacePlugin() {
170
+ const replacements = {
171
+ tmsCore: interEnv === 'public' ? '@tmsfe/tms-core' : '@tmsfe/tms-core',
172
+ INTER_ENV_VB: JSON.stringify(interEnv || 'private'),
173
+ };
174
+
175
+ return replace({
176
+ values: replacements,
177
+ preventAssignment: true,
178
+ });
179
+ }
@@ -0,0 +1,65 @@
1
+ const path = require('path');
2
+
3
+ // 用户目录
4
+ const HOME_DIR = process.env.HOME;
5
+
6
+ // 所有文件的缓存目录
7
+ const CACHE_DIR = path.resolve(HOME_DIR, '.tmskit');
8
+
9
+ // 脚手架模板代码所在目录
10
+ const TEMPLATE_DIR = path.resolve(CACHE_DIR, 'template');
11
+
12
+ // 第三方模块源码存放的临时缓存目录
13
+ const MODULE_CODE_DIR = path.resolve(CACHE_DIR, 'modules_code');
14
+
15
+ // 脚手架模板代码的具体路径
16
+ const TEMPLATE_PATH = path.resolve(TEMPLATE_DIR, 'tools/tms-cli-template');
17
+
18
+ // 脚手架的名称
19
+ const TMS_NAME = 'tmskit';
20
+
21
+ // 脚手架的配置名称
22
+ const TMS_CONFIG_FILENAME = 'tms.config.js';
23
+
24
+
25
+ // 模块代码的默认在modules子目录
26
+ const DEFAULT_MODULE_DIR = 'modules';
27
+
28
+ // 模块的配置文件的名称
29
+ const MODULE_CONFIG_FILENAME = 'module.config.json';
30
+
31
+ // 默认的webpack entry
32
+ const DEFAULT_WEBPACK_ENTRY = {
33
+ app: path.resolve(process.cwd(), 'app'),
34
+ };
35
+
36
+ // 默认从源码拷贝到编译后的配置
37
+ const DEFAULT_COPY_CONFIG = ['package.json', 'app.js', 'app.ts', 'app.less', 'app.wxss', 'sitemap.json'];
38
+
39
+ // 开发模式
40
+ const MODE = {
41
+ main: 'tkitmain',
42
+ all: 'all',
43
+ multi: 'multi',
44
+ };
45
+
46
+ const ENV = {
47
+ dev: 'development',
48
+ prod: 'production',
49
+ };
50
+
51
+ export {
52
+ HOME_DIR,
53
+ CACHE_DIR,
54
+ TEMPLATE_DIR,
55
+ TEMPLATE_PATH,
56
+ TMS_NAME,
57
+ TMS_CONFIG_FILENAME,
58
+ DEFAULT_MODULE_DIR,
59
+ MODULE_CONFIG_FILENAME,
60
+ DEFAULT_WEBPACK_ENTRY,
61
+ DEFAULT_COPY_CONFIG,
62
+ MODULE_CODE_DIR,
63
+ MODE,
64
+ ENV,
65
+ };
@@ -0,0 +1,17 @@
1
+ // tmsConfig默认配置项
2
+ module.exports = {
3
+ // 全局的环境配置项
4
+ envData: {},
5
+ // 模块配置信息
6
+ modules: [],
7
+ webpack: {
8
+ /** 编译输出文件夹位置 */
9
+ outputDir: 'dist',
10
+ /** 源码监听路径 */
11
+ sourceDir: './',
12
+ /** 源码Map */
13
+ sourceMap: 'none',
14
+ /** 别名 */
15
+ alias: {},
16
+ },
17
+ };
package/src/entry.js ADDED
@@ -0,0 +1,20 @@
1
+ module.exports = [
2
+ {
3
+ command: 'create <app-name>',
4
+ description: '创建新的应用',
5
+ action: (appName, cmd) => {
6
+ require('./scripts/create')(appName, cmd);
7
+ },
8
+ },
9
+ {
10
+ command: 'run <command-name>',
11
+ options: [
12
+ ['-m, --module [moduleName]', '模块名称'],
13
+ ['-e, --env [env]', '环境变量'],
14
+ ],
15
+ description: '运行模块',
16
+ action: (commandName, cmd) => {
17
+ require('./scripts/run/index')(commandName, cmd);
18
+ },
19
+ },
20
+ ];
package/src/index.js ADDED
@@ -0,0 +1,47 @@
1
+ const chalk = require('chalk');
2
+ const program = require('commander');
3
+ const { log, suggestCommands } = require('./utils/widgets');
4
+ const { TMS_NAME } = require('./config/constant.js');
5
+ const commands = require('./entry');
6
+ const init = require('./init');
7
+
8
+ init();
9
+
10
+ program
11
+ .version(`${TMS_NAME} ${require('../package.json').version}`);
12
+
13
+ commands.forEach((cmd) => {
14
+ const command = program.command(cmd.command);
15
+
16
+ cmd.usage && command.usage(cmd.usage);
17
+
18
+ cmd.description && command.description(cmd.description);
19
+
20
+ cmd.options?.forEach(opt => command.option(...opt));
21
+
22
+ command.action(cmd.action);
23
+ });
24
+
25
+ program.on('--help', () => {
26
+ log();
27
+ log(` Run ${chalk.cyan('tms <command> --help')} for detailed usage of given command.`);
28
+ log();
29
+ });
30
+
31
+ // 捕获未注册的命令
32
+ program
33
+ .arguments('<command>')
34
+ .action((cmd) => {
35
+ program.outputHelp();
36
+ log(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
37
+ log();
38
+ suggestCommands(cmd);
39
+ process.exitCode = 1;
40
+ });
41
+
42
+ if (!process.argv.slice(2).length) {
43
+ program.outputHelp();
44
+ process.exit(-1);
45
+ }
46
+
47
+ program.parse(process.argv);
package/src/init.js ADDED
@@ -0,0 +1,38 @@
1
+ const { exec } = require('shelljs');
2
+ const semver = require('semver');
3
+ const packageJson = require('../package.json');
4
+ const chalk = require('chalk');
5
+ const { log } = require('./utils/widgets');
6
+
7
+ const requiredVersion = packageJson.engines.node;
8
+ const packName = packageJson.name;
9
+
10
+ /**
11
+ * 检查node版本
12
+ * @param {String} wanted 希望的node版本
13
+ * @param {String} id 某node特性
14
+ * @returns {Undefined} 无需返回值
15
+ */
16
+ const checkNodeVersion = (wanted, id) => {
17
+ if (!semver.satisfies(process.version, wanted, { includePrerelease: true })) {
18
+ log(chalk.red(`你正在使用的Node版本: ${process.version}, 但是此版本的 ${id
19
+ } 需要的Node最小版本 ${wanted}.\n请先升级你的Node版本.`));
20
+ process.exit(1);
21
+ }
22
+ };
23
+
24
+ /**
25
+ * 检查运行环境
26
+ * @returns {Undefined} 无需返回值
27
+ */
28
+ function initCliContext() {
29
+ // 执行操作前检查node版本
30
+ // 旧版本node直接提示升级,退出脚本
31
+ checkNodeVersion(requiredVersion, packName);
32
+
33
+
34
+ // 执行前配置正确的npm源
35
+ exec('npm config set registry https://mirrors.tencent.com/npm/ --global', { silent: true });
36
+ }
37
+
38
+ module.exports = initCliContext;
@@ -0,0 +1,61 @@
1
+ const fs = require('fs');
2
+ const inquirer = require('inquirer');
3
+ /**
4
+ * 获取模板内的问题
5
+ * @param {string} templateDir 模板目录
6
+ * @returns {Array} inquirer 问题数组
7
+ */
8
+ const parseTemplateQuestions = (templateDir) => {
9
+ let prompts = [];
10
+ if (!fs.existsSync(`${templateDir}/questions.json`)) {
11
+ return prompts;
12
+ }
13
+ try {
14
+ const json = JSON.parse(fs.readFileSync(`${templateDir}/questions.json`));
15
+ if (Array.isArray(json) && json.length > 0) {
16
+ json.forEach((item, index) => {
17
+ if (!isQuestionType(item)) {
18
+ throw new Error(`第 ${index} 个问题不符合"inquirer"的格式要求`);
19
+ }
20
+ });
21
+ } else {
22
+ throw new Error('问题文件只能是数组');
23
+ }
24
+ prompts = json;
25
+ } catch (err) {
26
+ throw new Error(`模板异常,${err.message}`);
27
+ }
28
+ return prompts;
29
+ };
30
+ const isQuestionType = (result) => {
31
+ if (!('message' in result)) {
32
+ return false;
33
+ }
34
+ if (!('name' in result)) {
35
+ return false;
36
+ }
37
+ return true;
38
+ };
39
+
40
+ const ask = templateDir => (files, metalsmith, next) => {
41
+ const prompts = parseTemplateQuestions(templateDir);
42
+ const metadata = metalsmith.metadata();
43
+ const filteredPrompts = prompts.filter((prompt) => {
44
+ if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
45
+ return false;
46
+ }
47
+ return true;
48
+ });
49
+ inquirer.prompt(filteredPrompts)
50
+ .then((res) => {
51
+ for (const prompt of filteredPrompts) {
52
+ metadata[prompt.name] = res[prompt.name];
53
+ }
54
+ next();
55
+ })
56
+ .catch((err) => {
57
+ next(err);
58
+ });
59
+ };
60
+
61
+ module.exports = ask;
@@ -0,0 +1,27 @@
1
+ const Metalsmith = require('metalsmith');
2
+ const fs = require('fs');
3
+ const render = require('./render');
4
+ const ask = require('./ask');
5
+ const FILES_TO_IGNORE = require('./ignoreFiles');
6
+
7
+
8
+ const generator = (buildDir, distDir, preMetadata) => new Promise((resolve, reject) => {
9
+ Metalsmith(buildDir)
10
+ .metadata(preMetadata)
11
+ .ignore(FILES_TO_IGNORE)
12
+ .clean(false)
13
+ .use(ask(buildDir))
14
+ .source('./')
15
+ .destination(distDir)
16
+ .use(render)
17
+ .build((err) => {
18
+ if (err) {
19
+ reject(err);
20
+ } else {
21
+ fs.unlinkSync(`${distDir}/questions.json`);
22
+ resolve('finish');
23
+ }
24
+ });
25
+ });
26
+
27
+ module.exports = generator;
@@ -0,0 +1,7 @@
1
+
2
+ // 在metal smith遍历时需要忽略的文件,这些文件会引起metalsmith的parse error
3
+ const FILES_TO_IGNORE = [
4
+ 'node_modules',
5
+ ];
6
+
7
+ module.exports = FILES_TO_IGNORE;
@@ -0,0 +1,65 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const shelljs = require('shelljs');
4
+ const { TEMPLATE_DIR, TEMPLATE_PATH } = require('../../config/constant.js');
5
+ const { downloadRepoForGit, createTask, resolve } = require('../../utils/widgets');
6
+ const io = require('../../utils/io');
7
+ const { fail, succeed } = require('../../utils/log');
8
+ const generator = require('./generator');
9
+
10
+ /**
11
+ * 如果该目录下面存在文件,换个名字
12
+ * @param { string } targetDir 当前文件夹
13
+ * @returns { undefined }
14
+ */
15
+ async function createAppDir(targetDir) {
16
+ // 如果目录非空或者已经存在,提示用户,做选择
17
+ if (fs.existsSync(targetDir)) {
18
+ if (!await io.isDirEmpty(targetDir)) {
19
+ fail('该目录名已经存在,换个项目名字吧~');
20
+ process.exit(1);
21
+ }
22
+ } else {
23
+ shelljs.mkdir('-p', targetDir);
24
+ }
25
+ }
26
+
27
+ /**
28
+ * 创建本地小程序运行环境
29
+ * @param { string } appType 项目类型
30
+ * @param { string } appName 项目名称
31
+ */
32
+ async function create(appName) {
33
+ const cwd = process.cwd();
34
+ const targetDir = path.resolve(cwd, appName);
35
+ const appType = 'mp';
36
+ createAppDir(targetDir);
37
+
38
+ // 创建缓存目录
39
+ io.ensureDirExist(TEMPLATE_DIR);
40
+ // 拉取git模板
41
+ await createTask(downloadRepoForGit, '拉取模板仓库', '拉取模板仓库完成')(
42
+ 'https://git.woa.com/tmsfe/tms-frontend.git',
43
+ TEMPLATE_DIR,
44
+ 'master',
45
+ );
46
+
47
+ // 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
48
+ generator(path.join(TEMPLATE_PATH, appType), targetDir, {
49
+ appName,
50
+ appType,
51
+ }).then(() => {
52
+ succeed('项目创建完成,开始初始化...');
53
+ shelljs.cd(appName);
54
+ // 初始化构件主包的代码, 让用户打开项目可以跑起来
55
+ if (fs.existsSync(resolve(`${appName}/tms.config.js`))) {
56
+ shelljs.exec('tmskit run build');
57
+ }
58
+ })
59
+ .catch((err) => {
60
+ fail(err.message);
61
+ console.log('详细的错误信息:', err);
62
+ });
63
+ }
64
+
65
+ module.exports = create;
@@ -0,0 +1,19 @@
1
+
2
+ const async = require('async');
3
+ const ejs = require('ejs');
4
+
5
+ const render = (files, metalsmith, next) => {
6
+ const keys = Object.keys(files);
7
+ const metadata = metalsmith.metadata();
8
+ const run = (file, next) => {
9
+ const str = files[file].contents.toString();
10
+ const newStr = ejs.render(str, metadata);
11
+ // eslint-disable-next-line
12
+ files[file].contents = Buffer.from(newStr);
13
+ next();
14
+ };
15
+
16
+ async.each(keys, run, next);
17
+ };
18
+
19
+ module.exports = render;
@@ -0,0 +1,16 @@
1
+ const shelljs = require('shelljs');
2
+ const webpackBuildServer = require('../../../webpack/buildServer');
3
+ const { resolve } = require('../../../utils/widgets');
4
+ const init = require('../init/index');
5
+
6
+ async function build(tmsConfig, targetModules, env) {
7
+ // 开始构建前,清理输出目录
8
+ await shelljs.rm('-rf', resolve('dist'));
9
+
10
+ const { targetModules: newModules } = await init(tmsConfig, targetModules);
11
+
12
+ webpackBuildServer(tmsConfig, newModules, env);
13
+ }
14
+
15
+ module.exports = build;
16
+