@tmsfe/tmskit 0.0.1 → 0.0.5
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/README.md +5 -17
- package/dist/index.cjs.js +263 -215
- package/package.json +10 -25
- package/src/config/constant.js +3 -0
- package/src/index.js +1 -1
- package/src/scripts/create/ask.js +7 -5
- package/src/scripts/create/generator.js +0 -2
- package/src/scripts/create/index.js +13 -6
- package/src/scripts/run/index.js +7 -1
- package/src/scripts/run/install/index.js +39 -0
- package/src/utils/widgets.js +4 -11
- package/src/webpack/plugins/entryExtractPlugin/index.js +0 -1
- package/src/webpack/plugins/px2rpx/index.js +0 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tmskit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "tmskit",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"bin": {
|
|
@@ -18,49 +18,34 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
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
21
|
"@rollup/plugin-babel": "^5.0.2",
|
|
25
22
|
"@rollup/plugin-commonjs": "^19.0.0",
|
|
26
23
|
"@rollup/plugin-dynamic-import-vars": "^1.1.1",
|
|
27
24
|
"@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
25
|
"rollup": "^2.6.1",
|
|
37
26
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
27
|
+
"rollup-plugin-replace": "^2.2.0",
|
|
38
28
|
"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"
|
|
29
|
+
"rollup-plugin-typescript2": "0.27.0"
|
|
44
30
|
},
|
|
45
31
|
"dependencies": {
|
|
46
|
-
"
|
|
32
|
+
"async": "^3.2.2",
|
|
47
33
|
"chalk": "^4.1.0",
|
|
48
34
|
"commander": "^6.2.1",
|
|
35
|
+
"copy-webpack-plugin": "^9.1.0",
|
|
49
36
|
"download-git-repo": "^3.0.2",
|
|
50
37
|
"ejs": "^3.1.5",
|
|
51
|
-
"
|
|
52
|
-
"fs-extra": "^9.0.1",
|
|
38
|
+
"glob-ignore": "^1.0.2",
|
|
53
39
|
"inquirer": "^7.3.3",
|
|
40
|
+
"leven": "3.1.0",
|
|
54
41
|
"lodash": "^4.17.21",
|
|
55
|
-
"
|
|
42
|
+
"metalsmith": "^2.3.0",
|
|
56
43
|
"miniprogram-ci": "1.4.13",
|
|
57
44
|
"ora": "^5.1.0",
|
|
58
45
|
"replace-ext": "^2.0.0",
|
|
59
|
-
"rollup-plugin-replace": "^2.2.0",
|
|
60
46
|
"shelljs": "^0.8.4",
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"username": "5.1.0",
|
|
47
|
+
"ts-loader": "^9.2.6",
|
|
48
|
+
"webpack": "^5.64.0",
|
|
64
49
|
"webpack-chain": "^6.5.1"
|
|
65
50
|
},
|
|
66
51
|
"engines": {
|
package/src/config/constant.js
CHANGED
package/src/index.js
CHANGED
|
@@ -24,7 +24,7 @@ commands.forEach((cmd) => {
|
|
|
24
24
|
|
|
25
25
|
program.on('--help', () => {
|
|
26
26
|
log();
|
|
27
|
-
log(` Run ${chalk.cyan(
|
|
27
|
+
log(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
|
|
28
28
|
log();
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const inquirer = require('inquirer');
|
|
3
|
+
const { resolve } = require('../../utils/widgets');
|
|
4
|
+
const { TEMPLATE_TKIT_DIR } = require('../../config/constant');
|
|
3
5
|
/**
|
|
4
6
|
* 获取模板内的问题
|
|
5
|
-
* @param {string}
|
|
7
|
+
* @param {string} dir questions.json所在的目录
|
|
6
8
|
* @returns {Array} inquirer 问题数组
|
|
7
9
|
*/
|
|
8
|
-
const parseTemplateQuestions = (
|
|
10
|
+
const parseTemplateQuestions = (dir) => {
|
|
9
11
|
let prompts = [];
|
|
10
|
-
if (!fs.existsSync(`${
|
|
12
|
+
if (!fs.existsSync(`${dir}/questions.json`)) {
|
|
11
13
|
return prompts;
|
|
12
14
|
}
|
|
13
15
|
try {
|
|
14
|
-
const json = JSON.parse(fs.readFileSync(`${
|
|
16
|
+
const json = JSON.parse(fs.readFileSync(`${dir}/questions.json`));
|
|
15
17
|
if (Array.isArray(json) && json.length > 0) {
|
|
16
18
|
json.forEach((item, index) => {
|
|
17
19
|
if (!isQuestionType(item)) {
|
|
@@ -38,7 +40,7 @@ const isQuestionType = (result) => {
|
|
|
38
40
|
};
|
|
39
41
|
|
|
40
42
|
const ask = templateDir => (files, metalsmith, next) => {
|
|
41
|
-
const prompts = parseTemplateQuestions(templateDir);
|
|
43
|
+
const prompts = parseTemplateQuestions(resolve(templateDir, TEMPLATE_TKIT_DIR));
|
|
42
44
|
const metadata = metalsmith.metadata();
|
|
43
45
|
const filteredPrompts = prompts.filter((prompt) => {
|
|
44
46
|
if (metadata[prompt.name] && `${metadata[prompt.name]}`.trim() !== '') {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const Metalsmith = require('metalsmith');
|
|
2
|
-
const fs = require('fs');
|
|
3
2
|
const render = require('./render');
|
|
4
3
|
const ask = require('./ask');
|
|
5
4
|
const FILES_TO_IGNORE = require('./ignoreFiles');
|
|
@@ -18,7 +17,6 @@ const generator = (buildDir, distDir, preMetadata) => new Promise((resolve, reje
|
|
|
18
17
|
if (err) {
|
|
19
18
|
reject(err);
|
|
20
19
|
} else {
|
|
21
|
-
fs.unlinkSync(`${distDir}/questions.json`);
|
|
22
20
|
resolve('finish');
|
|
23
21
|
}
|
|
24
22
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const shelljs = require('shelljs');
|
|
4
|
-
const { TEMPLATE_DIR, TEMPLATE_PATH } = require('../../config/constant.js');
|
|
4
|
+
const { TEMPLATE_DIR, TEMPLATE_PATH, TEMPLATE_TKIT_DIR } = require('../../config/constant.js');
|
|
5
5
|
const { downloadRepoForGit, createTask, resolve } = require('../../utils/widgets');
|
|
6
6
|
const io = require('../../utils/io');
|
|
7
7
|
const { fail, succeed } = require('../../utils/log');
|
|
@@ -33,7 +33,7 @@ async function create(appName) {
|
|
|
33
33
|
const cwd = process.cwd();
|
|
34
34
|
const targetDir = path.resolve(cwd, appName);
|
|
35
35
|
const appType = 'mp';
|
|
36
|
-
createAppDir(targetDir);
|
|
36
|
+
await createAppDir(targetDir);
|
|
37
37
|
|
|
38
38
|
// 创建缓存目录
|
|
39
39
|
io.ensureDirExist(TEMPLATE_DIR);
|
|
@@ -49,12 +49,19 @@ async function create(appName) {
|
|
|
49
49
|
appName,
|
|
50
50
|
appType,
|
|
51
51
|
}).then(() => {
|
|
52
|
-
succeed('项目创建完成,开始初始化...');
|
|
53
52
|
shelljs.cd(appName);
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
|
|
53
|
+
const hooks = require(resolve(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
|
|
54
|
+
if (hooks.afterCreate) {
|
|
55
|
+
hooks.afterCreate.forEach((item) => {
|
|
56
|
+
if (typeof item === 'function') {
|
|
57
|
+
item.call(null, shelljs, { appName });
|
|
58
|
+
} else {
|
|
59
|
+
shelljs.exec(item);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
57
62
|
}
|
|
63
|
+
shelljs.rm('-rf', resolve(appName, TEMPLATE_TKIT_DIR));
|
|
64
|
+
succeed('项目创建完成.');
|
|
58
65
|
})
|
|
59
66
|
.catch((err) => {
|
|
60
67
|
fail(err.message);
|
package/src/scripts/run/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const init = require('./init/index');
|
|
2
2
|
const dev = require('./dev/index');
|
|
3
3
|
const build = require('./build/index');
|
|
4
|
-
const
|
|
4
|
+
const install = require('./install/index');
|
|
5
|
+
const { createTask, resolve } = require('../../utils/widgets');
|
|
5
6
|
const { MODE } = require('../../config/constant');
|
|
6
7
|
const { readTmsConfig, checkModules } = require('../../utils/tkitUtils');
|
|
7
8
|
|
|
@@ -22,6 +23,11 @@ const handleModulesArg = (cmd) => {
|
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
async function run(commandName, cmd) {
|
|
26
|
+
if (commandName === 'install') {
|
|
27
|
+
install(resolve('./'));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
25
31
|
const moduleArg = handleModulesArg(cmd);
|
|
26
32
|
const { env } = cmd;
|
|
27
33
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const shelljs = require('shelljs');
|
|
2
|
+
const { createTask } = require('../../../utils/widgets');
|
|
3
|
+
const { buildMpNpm } = require('../../../utils/mpCiUtils');
|
|
4
|
+
const glob = require('glob-ignore');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
function npmInstall(contextDir) {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
|
|
10
|
+
if (err) {
|
|
11
|
+
reject(err);
|
|
12
|
+
}
|
|
13
|
+
files.forEach((file) => {
|
|
14
|
+
const dir = path.dirname(file);
|
|
15
|
+
shelljs.cd(dir);
|
|
16
|
+
shelljs.exec('npx pnpm install --prod --registry http://mirrors.tencent.com/npm/', { silent: false });
|
|
17
|
+
});
|
|
18
|
+
resolve();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function install(contextDir) {
|
|
24
|
+
// npm install
|
|
25
|
+
await createTask(
|
|
26
|
+
npmInstall,
|
|
27
|
+
'开始npm install',
|
|
28
|
+
'npm install完成',
|
|
29
|
+
)(contextDir);
|
|
30
|
+
|
|
31
|
+
// 构建miniprograme_npm
|
|
32
|
+
await createTask(
|
|
33
|
+
buildMpNpm,
|
|
34
|
+
'开始构建miniprogram_npm',
|
|
35
|
+
'构建miniprogram_npm 完成',
|
|
36
|
+
)({ appId: 'null', projectPath: contextDir, privateKey: 'null' });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = install;
|
package/src/utils/widgets.js
CHANGED
|
@@ -96,7 +96,7 @@ function downloadRepo(dest, downloadOptions = { repoUrl: '', gitUrl: '', branch:
|
|
|
96
96
|
function downloadRepoForGit(url, dest, branch) {
|
|
97
97
|
const cwd = process.cwd();
|
|
98
98
|
|
|
99
|
-
return new Promise((resolve
|
|
99
|
+
return new Promise((resolve) => {
|
|
100
100
|
// 如果目标目录不存在
|
|
101
101
|
if (fs.existsSync(dest)) {
|
|
102
102
|
shelljs.rm('-rf', path.join(dest));
|
|
@@ -105,17 +105,10 @@ function downloadRepoForGit(url, dest, branch) {
|
|
|
105
105
|
shelljs.mkdir('-p', dest);
|
|
106
106
|
shelljs.cd(dest);
|
|
107
107
|
|
|
108
|
-
shelljs.exec(`git clone ${url} ${dest} --depth
|
|
109
|
-
|
|
110
|
-
shelljs.exec(`git checkout ${branch}`, (code) => {
|
|
111
|
-
if (code === 0) {
|
|
112
|
-
shelljs.cd(cwd);
|
|
108
|
+
shelljs.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptons);
|
|
113
109
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
reject();
|
|
118
|
-
});
|
|
110
|
+
shelljs.cd(cwd);
|
|
111
|
+
resolve();
|
|
119
112
|
});
|
|
120
113
|
}
|
|
121
114
|
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const px2rpx = postcss.plugin('postcss-px2rpx', (opts = {}) => {
|
|
2
|
-
const { proportion = 1, minPixelValue = 0 } = opts;
|
|
3
|
-
|
|
4
|
-
return (root) => {
|
|
5
|
-
root.replaceValues(pxRegExp, { fast: 'px' }, (string) => {
|
|
6
|
-
const pixels = parseInt(string, 10);
|
|
7
|
-
if (pixels < minPixelValue) return `${pixels}px`;
|
|
8
|
-
return `${proportion * parseInt(string, 10)}rpx`;
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export default px2rpx;
|