@opentapd/tplugin-cli 0.32.0 → 0.32.1-alpha.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.
- package/cli.js +1 -2
- package/lib/create.js +9 -22
- package/package.json +2 -2
- package/util/getFolderHash/index.js +37 -0
- package/util/getFolderHash/test.js +11 -0
package/cli.js
CHANGED
|
@@ -27,9 +27,8 @@ program.version(packageJson.version)
|
|
|
27
27
|
.usage('<command> [options]');
|
|
28
28
|
|
|
29
29
|
// create <code> 创建插件
|
|
30
|
-
program.command('create <
|
|
30
|
+
program.command('create <name>')
|
|
31
31
|
.description('通过CLI创建一个TAPD插件')
|
|
32
|
-
.option('-n, --name <name>', '插件名字')
|
|
33
32
|
.action(actionRunner((code, opts) => require('./lib/create')(code, opts)));
|
|
34
33
|
|
|
35
34
|
// login 登录
|
package/lib/create.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Author: terrysxu@tencent.com
|
|
4
4
|
* Author: raferzeng@tencent.com
|
|
5
5
|
*
|
|
6
|
-
* The implementation of CLI: create <
|
|
6
|
+
* The implementation of CLI: create <name>
|
|
7
7
|
*/
|
|
8
8
|
const inquirer = require('inquirer');
|
|
9
9
|
const chalk = require('chalk');
|
|
@@ -21,22 +21,16 @@ const { downloadAndUnzip } = require('../util/tools');
|
|
|
21
21
|
const { promisify } = require('util');
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* @description
|
|
25
|
-
* @param
|
|
26
|
-
* @param options 选择的创建配置
|
|
24
|
+
* @description 根据名称创建插件
|
|
25
|
+
* @param name 插件名称
|
|
27
26
|
*/
|
|
28
|
-
module.exports = async (
|
|
27
|
+
module.exports = async (name) => {
|
|
29
28
|
// 初始化Session
|
|
30
29
|
const session = new Session();
|
|
31
30
|
|
|
32
31
|
// 校验登录态
|
|
33
32
|
session.checkAuth();
|
|
34
33
|
|
|
35
|
-
await checkAppParams({
|
|
36
|
-
code,
|
|
37
|
-
name: options.name || code,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
34
|
spinner.start('加载应用模板...');
|
|
41
35
|
// 加载创建模板
|
|
42
36
|
const createTmpl = await getCreateTmpl();
|
|
@@ -67,8 +61,7 @@ module.exports = async (code, options) => {
|
|
|
67
61
|
const entranceConfigs = supportEntrances ? await selectEntrances() : {};
|
|
68
62
|
|
|
69
63
|
const params = {
|
|
70
|
-
|
|
71
|
-
name: options.name || code,
|
|
64
|
+
name,
|
|
72
65
|
template: selectedTmpl.template,
|
|
73
66
|
...entranceConfigs,
|
|
74
67
|
async: true,
|
|
@@ -79,15 +72,6 @@ module.exports = async (code, options) => {
|
|
|
79
72
|
await create(params);
|
|
80
73
|
};
|
|
81
74
|
|
|
82
|
-
/**
|
|
83
|
-
* checkAppParams(): 检查插件参数
|
|
84
|
-
* @return array data
|
|
85
|
-
*/
|
|
86
|
-
async function checkAppParams(params) {
|
|
87
|
-
const { data } = await tapdsdk.request({ url: '/open_user_app/check_app_params', method: 'POST', params });
|
|
88
|
-
return data;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
75
|
/**
|
|
92
76
|
* getCreateTmpl(): 获取创建模板列表
|
|
93
77
|
* @return array data
|
|
@@ -134,7 +118,9 @@ async function create(params) {
|
|
|
134
118
|
return ;
|
|
135
119
|
}
|
|
136
120
|
|
|
137
|
-
|
|
121
|
+
const { data: { code } } = data;
|
|
122
|
+
|
|
123
|
+
await getAppCreateStatus(code);
|
|
138
124
|
}
|
|
139
125
|
|
|
140
126
|
async function getAppCreateStatus(code) {
|
|
@@ -322,3 +308,4 @@ async function selectEntrances() {
|
|
|
322
308
|
}))),
|
|
323
309
|
};
|
|
324
310
|
}
|
|
311
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentapd/tplugin-cli",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.1-alpha.1",
|
|
4
4
|
"description": "tplugin-cli",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tplugin-cli": "index.js"
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"node": ">=14.13.0"
|
|
80
80
|
},
|
|
81
81
|
"main": "index.js",
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "e4ee96999c4f4efc2307e46ed16975a45f777fef"
|
|
83
83
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const crypto = require('crypto');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { difference } = require('lodash');
|
|
5
|
+
|
|
6
|
+
async function getFolderHash(folderPath, git) {
|
|
7
|
+
const hash = crypto.createHash('sha256');
|
|
8
|
+
const files = fs.readdirSync(folderPath).sort(); // 排序读取的文件
|
|
9
|
+
const gitFiles = await ignoreFilter(folderPath, files, git);
|
|
10
|
+
// console.log(gitFiles);
|
|
11
|
+
for (const filePath of gitFiles) {
|
|
12
|
+
const fileStats = fs.statSync(filePath);
|
|
13
|
+
hash.update(filePath);
|
|
14
|
+
|
|
15
|
+
if (fileStats.isDirectory()) {
|
|
16
|
+
hash.update(await getFolderHash(filePath, git)); // 递归加入子目录
|
|
17
|
+
} else {
|
|
18
|
+
const fileData = fs.readFileSync(filePath);
|
|
19
|
+
hash.update(fileData);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return hash.digest('hex');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function ignoreFilter(dir = '', files = [], git) {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
const paths = files.map(file => path.join(dir, file));
|
|
28
|
+
git.checkIgnore(
|
|
29
|
+
paths,
|
|
30
|
+
(snoop, ignorePaths) => {
|
|
31
|
+
resolve(difference(paths, ignorePaths));
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = getFolderHash;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const SimpleGit = require('simple-git');
|
|
3
|
+
const getFolderHash = require('./index.js');
|
|
4
|
+
|
|
5
|
+
(async () => {
|
|
6
|
+
const hash = await getFolderHash(
|
|
7
|
+
path.join(__dirname, '../../', 'util'),
|
|
8
|
+
new SimpleGit(path.join(__dirname)),
|
|
9
|
+
);
|
|
10
|
+
console.log(hash);
|
|
11
|
+
})();
|