@opentapd/tplugin-cli 0.40.0 → 0.40.1-alpha.0

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 CHANGED
@@ -89,12 +89,12 @@ program.command('encrypt <value>')
89
89
  .description('加密敏感变量')
90
90
  .action(actionRunner(value => require('./lib/encrypt')(value)));
91
91
 
92
- if (tpluginConf.tapd.pluginEnv !== 'cloud') {
93
- // resource 添加新的UI扩展模块
94
- program.command('resources')
95
- .description('添加扩展模块模板')
96
- .action(actionRunner(() => require('./lib/resources')()));
92
+ // resource 添加新的UI扩展模块
93
+ program.command('resources')
94
+ .description('添加扩展模块模板')
95
+ .action(actionRunner(() => require('./lib/resources')()));
97
96
 
97
+ if (tpluginConf.tapd.pluginEnv !== 'cloud') {
98
98
  // workspace 创建个人专属开发项目
99
99
  program.command('workspace')
100
100
  .description('创建TAPD开发项目')
package/lib/resources.js CHANGED
@@ -18,6 +18,17 @@ const rimraf = require('rimraf');
18
18
  const { exec } = require('child_process');
19
19
  const path = require('path');
20
20
  const { downloadAndUnzip } = require('../util/tools');
21
+ const tpluginConf = require('../config');
22
+ const util = require('util');
23
+ const execPromised = util.promisify(exec);
24
+ const asyncExec = async (...args) => {
25
+ const { stdout, stderr } = await execPromised(...args);
26
+ if (stderr) {
27
+ throw new Error(stderr);
28
+ }
29
+
30
+ return stdout;
31
+ };
21
32
 
22
33
  // resource命令实现
23
34
  module.exports = async () => {
@@ -43,7 +54,7 @@ module.exports = async () => {
43
54
 
44
55
 
45
56
  // 拉取并添加扩展点文件
46
- await getEntranceFiles(entranceTmpl);
57
+ await createEntranceFromZip(entranceTmpl);
47
58
  };
48
59
 
49
60
  /**
@@ -57,15 +68,11 @@ async function getEntranceTmpl() {
57
68
  name: 'frame',
58
69
  message: '请选择前端框架:',
59
70
  choices: [
60
- {
61
- name: 'vue',
62
- value: 'ui-nodejs-vue',
63
- }
64
- // {
65
- // name: 'react',
66
- // value: 'ui-nodejs-react',
67
- // }
68
- ],
71
+ {
72
+ name: 'vue',
73
+ value: 'ui-nodejs-vue',
74
+ },
75
+ ],
69
76
  }]);
70
77
 
71
78
  spinner.start('加载应用模板...');
@@ -230,12 +237,37 @@ async function createEntranceFromZip(entranceTmpl) {
230
237
 
231
238
  spinner.start('开始生成 Demo 代码');
232
239
  await downloadAndUnzip(repoRes.data.download_url);
233
- spinner.succeed('Demo 代码生成成功');
240
+ spinner.start('开始模板定制工作 🔥🔥🔥');
241
+ await demoDecorateJob(entranceTmpl);
234
242
 
243
+ spinner.succeed('Demo 代码生成成功');
235
244
  rimraf('demo.zip', () => {});
245
+
236
246
  createEntranceResource(entranceTmpl);
237
247
  }
238
248
 
249
+ /**
250
+ *
251
+ * @description 替换demo中的一些特定值,如 @tencent 的包名
252
+ */
253
+ async function demoDecorateJob({ frame }) {
254
+ const PLUGIN_ENV = tpluginConf.tapd.pluginEnv;
255
+
256
+ if (
257
+ PLUGIN_ENV !== 'oa'
258
+ ) {
259
+ const NPM_SCOPED_NAME = {
260
+ cloud: '@opentapd',
261
+ ex: '@tapd',
262
+ };
263
+
264
+ const npmScopedName = NPM_SCOPED_NAME[PLUGIN_ENV];
265
+
266
+ await asyncExec(`node demo/scripts/replace-tencent-in-package-json/sh.js demo/${frame}/package.json ${npmScopedName}`);
267
+ await asyncExec(`node demo/scripts/replace-package-name/sh.js ${path.join(process.env.PWD, `demo/${frame}`)} ${npmScopedName}`);
268
+ }
269
+ }
270
+
239
271
  /**
240
272
  * getTmpRepoUrl(): 获取仓库当前代码制品code.zip的临时下载链接
241
273
  * @return array data
@@ -244,16 +276,3 @@ async function getTmpRepoUrl(params) {
244
276
  const { data } = await tapdsdk.request({ url: '/open_user_app/get_tmp_repo_url', method: 'POST', params });
245
277
  return data;
246
278
  }
247
-
248
-
249
- /**
250
- * getEntranceFiles() 获取扩展模块的模板文件,并添加到仓库中
251
- * @param {Object} entranceTmpl - 模版配置
252
- * @param {string} entranceTmpl.frame - 扩展前端框架
253
- * @param {string} entranceTmpl.entrances - 扩展模块名
254
- * @returns void
255
- */
256
- async function getEntranceFiles(entranceTmpl) {
257
- // 改造为只从zip获取
258
- await createEntranceFromZip(entranceTmpl);
259
- }
package/lib/serve.js CHANGED
@@ -66,50 +66,50 @@ module.exports = async () => {
66
66
  }
67
67
 
68
68
  if (tpluginConf.tapd.pluginEnv === 'cloud') {
69
- //获取当前公司信息
69
+ // 获取当前公司信息
70
70
  const { data } = await tapdsdk.request({ url: 'open_user_app/get_company_info', params: {}, method: 'POST' });
71
71
 
72
- //获取公司信息失败
72
+ // 获取公司信息失败
73
73
  if (!data.status || !data.data) {
74
- spinner.fail("获取公司信息失败");
74
+ spinner.fail('获取公司信息失败');
75
75
  process.exit(1);
76
76
  }
77
77
 
78
78
 
79
- if(!data.data.is_test) {
80
- spinner.info("当前企业不是测试企业");
79
+ if (!data.data.is_test) {
80
+ spinner.info('当前企业不是测试企业');
81
81
  const { data } = await tapdsdk.request({ url: 'open_user_app/get_test_deploy_company_option', params: {}, method: 'POST' });
82
82
  if (!data.status || !data.data) {
83
- spinner.fail("获取测试公司信息失败");
83
+ spinner.fail('获取测试公司信息失败');
84
84
  process.exit(1);
85
85
  }
86
86
 
87
- if(Array.isArray(data.data.data_list) && data.data.data_list.length === 0) {
87
+ if (Array.isArray(data.data.data_list) && data.data.data_list.length === 0) {
88
88
  const { createTestCompany } = await inquirer.prompt({
89
89
  type: 'confirm',
90
90
  message: '是否创建测试企业',
91
91
  name: 'createTestCompany',
92
92
  });
93
-
93
+
94
94
  if (createTestCompany) {
95
95
  spinner.info('开始创建测试企业');
96
96
  const { data } = await tapdsdk.request({ url: 'open_user_app/register_test_company', params: {}, method: 'POST' });
97
97
  if (!data.status) {
98
- spinner.fail("创建测试企业失败");
98
+ spinner.fail('创建测试企业失败');
99
99
  process.exit(1);
100
100
  }
101
- spinner.succeed("创建测试企业成功,请重新登陆切换到测试企业");
101
+ spinner.succeed('创建测试企业成功,请重新登陆切换到测试企业');
102
102
  process.exit(1);
103
103
  } else {
104
- spinner.info("请前往开放平台->开发者后台->应用测试创建测试企业");
104
+ spinner.info('请前往开放平台->开发者后台->应用测试创建测试企业');
105
105
  process.exit(1);
106
106
  }
107
107
  } else {
108
- spinner.fail("当前企业不是测试企业,请重新登陆切换到测试企业调试应用");
108
+ spinner.fail('当前企业不是测试企业,请重新登陆切换到测试企业调试应用');
109
109
  process.exit(1);
110
110
  }
111
111
  }
112
- }
112
+ }
113
113
 
114
114
  console.log(`\n 进入调试空间: ${chalk.red(`${tpluginConf.tapd.tapdHost}/${workspaceId}`)}`);
115
115
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentapd/tplugin-cli",
3
- "version": "0.40.0",
3
+ "version": "0.40.1-alpha.0",
4
4
  "description": "tplugin-cli",
5
5
  "bin": {
6
6
  "tplugin-cli": "index.js"
@@ -78,5 +78,5 @@
78
78
  "node": ">=14.13.0"
79
79
  },
80
80
  "main": "index.js",
81
- "gitHead": "7cc83729aa15bbadec7de5ae3aad71e52984f9cc"
81
+ "gitHead": "e15f5d68c4dcc136b37d33497f6d1cfab4d08765"
82
82
  }