@giteeteam/apps-cli 0.2.6 → 0.2.8

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 (2) hide show
  1. package/dist/index.js +89 -23
  2. package/package.json +3 -4
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
31
31
  var child_process__default = /*#__PURE__*/_interopDefaultLegacy(child_process);
32
32
  var chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
33
33
 
34
- var version = "0.2.6";
34
+ var version = "0.2.8";
35
35
 
36
36
  const packageApp = async ({ outputDir, manifest, copyFiles }) => {
37
37
  const { resources } = manifest;
@@ -118,8 +118,9 @@ const execActionWithSpinner = async (message, action) => {
118
118
  };
119
119
 
120
120
  class Manifest {
121
- constructor(manifestStr) {
122
- this.manifest = yaml.parse(manifestStr);
121
+ constructor(manifestString) {
122
+ this.manifest = yaml.parse(manifestString);
123
+ this.manifestString = manifestString;
123
124
  }
124
125
  get resources() {
125
126
  return this.manifest.resources;
@@ -127,13 +128,63 @@ class Manifest {
127
128
  get app() {
128
129
  return this.manifest.app;
129
130
  }
131
+ get tables() {
132
+ return this.manifest.tables;
133
+ }
134
+ getManifest() {
135
+ return this.manifest;
136
+ }
137
+ getManifestString() {
138
+ return this.manifestString;
139
+ }
140
+ /**
141
+ * 获取所有自定义事项类型
142
+ */
143
+ getCustomItemType() {
144
+ const { modules } = this.manifest;
145
+ return modules.customItemType || [];
146
+ }
147
+ /**
148
+ * 获取所有自定义字段类型
149
+ */
150
+ getCustomFieldType() {
151
+ const { modules } = this.manifest;
152
+ return modules.customFieldType || [];
153
+ }
154
+ /**
155
+ * 获取所有自定义字段
156
+ */
157
+ getCustomField() {
158
+ const { modules } = this.manifest;
159
+ return modules.customField || [];
160
+ }
130
161
  /**
131
- * 根据key获取执行的function名称
162
+ * 根据key获取执行的function
132
163
  * @param key
133
164
  * @returns
134
165
  */
135
166
  getFunctionByKey(key) {
136
- var _a, _b, _c, _d, _e;
167
+ const functionKey = this.getFunctionKeyByKey(key);
168
+ if (functionKey) {
169
+ return this.getFunctionByFunctionKey(functionKey);
170
+ }
171
+ }
172
+ /**
173
+ * 根据functionKey获取执行的function
174
+ * @param functionKey
175
+ * @returns
176
+ */
177
+ getFunctionByFunctionKey(functionKey) {
178
+ var _a, _b;
179
+ return (_b = (_a = this.manifest.modules) === null || _a === void 0 ? void 0 : _a.function) === null || _b === void 0 ? void 0 : _b.find(f => f.key === functionKey);
180
+ }
181
+ /**
182
+ * 根据key获取执行的functionKey
183
+ * @param key
184
+ * @returns
185
+ */
186
+ getFunctionKeyByKey(key) {
187
+ var _a, _b, _c;
137
188
  const { modules } = this.manifest;
138
189
  for (const k in modules) {
139
190
  if (k === 'function') {
@@ -142,13 +193,13 @@ class Manifest {
142
193
  else if (k === 'importer') {
143
194
  // importer扩展点需要判断function和validate
144
195
  if (key === ((_a = modules[k]) === null || _a === void 0 ? void 0 : _a.function) || key === ((_b = modules[k]) === null || _b === void 0 ? void 0 : _b.validate)) {
145
- return (_c = modules === null || modules === void 0 ? void 0 : modules.function) === null || _c === void 0 ? void 0 : _c.find(v => v.key === key);
196
+ return key;
146
197
  }
147
198
  }
148
199
  else if (Array.isArray(modules[k])) {
149
- const targetModule = (_d = modules[k]) === null || _d === void 0 ? void 0 : _d.find(v => v.key === key);
200
+ const targetModule = (_c = modules[k]) === null || _c === void 0 ? void 0 : _c.find(v => v.key === key);
150
201
  if (targetModule) {
151
- return (_e = modules === null || modules === void 0 ? void 0 : modules.function) === null || _e === void 0 ? void 0 : _e.find(v => v.key === targetModule.function);
202
+ return targetModule.function;
152
203
  }
153
204
  }
154
205
  }
@@ -168,6 +219,14 @@ class Manifest {
168
219
  }
169
220
  }
170
221
 
222
+ var Triggers;
223
+ (function (Triggers) {
224
+ Triggers["appInstall"] = "proxima:app:install";
225
+ Triggers["appUninstall"] = "proxima:app:uninstall";
226
+ Triggers["appUpdate"] = "proxima:app:update";
227
+ Triggers["itemChange"] = "proxima:item:change";
228
+ })(Triggers || (Triggers = {}));
229
+
171
230
  const getManifest = async () => {
172
231
  const manifestFile = path__default["default"].resolve('manifest.yml');
173
232
  const strBuffer = await fse__default["default"].readFile(manifestFile);
@@ -436,10 +495,11 @@ const watchFiles = async (options) => {
436
495
  // 监听整个文件夹,有一个文件改动,则全部重新build
437
496
  // TODO 解析出文件之间的依赖关系,提升构建速度
438
497
  const watcher = chokidar__default["default"].watch(inputDir);
439
- watcher.on('change', () => {
498
+ console.log(`watch: ${inputDir}`);
499
+ watcher.on('change', path => {
440
500
  clearTimeout(timer);
441
501
  timer = setTimeout(() => {
442
- console.log(`build ${inputDir}`);
502
+ console.log(`${path} has change`);
443
503
  build(functionFiles, inputDir, outputDir);
444
504
  }, 1000);
445
505
  });
@@ -448,7 +508,7 @@ const watchFiles = async (options) => {
448
508
  var _a, _b;
449
509
  const image = {
450
510
  repository: 'registry.baidubce.com/proxima/proxima-apps-runtime-server',
451
- tag: (_a = process.env.IMAGE_TAG) !== null && _a !== void 0 ? _a : '2.7.0-alpha-45',
511
+ tag: (_a = process.env.IMAGE_TAG) !== null && _a !== void 0 ? _a : 'latest',
452
512
  };
453
513
  const containerPort = Number((_b = process.env.CONTAINER_PORT) !== null && _b !== void 0 ? _b : 8455);
454
514
  const containerName = 'cli-dev-apps-runtime-server';
@@ -457,7 +517,7 @@ const tempAppDir = `${tempApp}/server-side`;
457
517
  const containerEnv = {
458
518
  PORT: containerPort,
459
519
  APPS_DIR: '/usr/src/app/apps',
460
- LRU_TTL: 0,
520
+ LRU_TTL: 1,
461
521
  DEBUG: 'runtime*',
462
522
  PARSE_PUBLIC_SERVER_URL: process.env.PARSE_PUBLIC_SERVER_URL,
463
523
  PARSE_SERVER_MASTER_KEY: process.env.PARSE_SERVER_MASTER_KEY,
@@ -473,18 +533,20 @@ const copyManifest = async (appDir) => {
473
533
  await fse__default["default"].copy(manifestFile, targetFile);
474
534
  };
475
535
  var run = async (options) => {
476
- const { inputDir, outputDir } = options;
536
+ const { inputDir, outputDir, server } = options;
477
537
  await fse__default["default"].emptyDir(outputDir);
478
538
  const imageName = `${image.repository}:${image.tag}`;
479
539
  const appDir = path__default["default"].join(outputDir, tempAppDir);
480
540
  const dockerService = new DockerService(imageName);
481
- await dockerService.downloadImage();
482
- await dockerService.runContainer({
483
- port: containerPort,
484
- env: containerEnv,
485
- volume: [`${outputDir}:/usr/src/app/apps`],
486
- name: containerName,
487
- });
541
+ if (server) {
542
+ await dockerService.downloadImage();
543
+ await dockerService.runContainer({
544
+ port: containerPort,
545
+ env: containerEnv,
546
+ volume: [`${outputDir}:/usr/src/app/apps`],
547
+ name: containerName,
548
+ });
549
+ }
488
550
  process.on('SIGINT', async () => {
489
551
  await dockerService.removeContainer(containerName);
490
552
  await fse__default["default"].remove(outputDir);
@@ -492,15 +554,18 @@ var run = async (options) => {
492
554
  });
493
555
  await copyManifest(appDir);
494
556
  await watchFiles({ inputDir, outputDir: appDir });
495
- console.log('You can use this url for test:');
496
- console.log(`POST http://localhost:${containerPort}/v1/apps${tempApp}/functions/:key`);
557
+ if (server) {
558
+ console.log('You can use this url for test:');
559
+ console.log(`POST http://localhost:${containerPort}/v1/apps${tempApp}/functions/:key`);
560
+ }
497
561
  };
498
562
 
499
563
  var dev = async (options) => {
500
- const { input = 'src', output = 'cache' } = options;
564
+ const { input = 'src', output = 'cache', server = true } = options;
501
565
  await run({
502
566
  outputDir: path__default["default"].resolve(output),
503
567
  inputDir: path__default["default"].resolve(input),
568
+ server,
504
569
  });
505
570
  };
506
571
 
@@ -519,5 +584,6 @@ program
519
584
  .command('dev')
520
585
  .option('-i --input [dir]', 'input dir')
521
586
  .option('-o --output [dir]', 'output dir,default cache')
587
+ .option('--no-server', 'no server')
522
588
  .action(dev);
523
589
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giteeteam/apps-cli",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Giteeteam Apps cli",
5
5
  "keywords": [
6
6
  "typescript",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@giteeteam/apps-bundler": "^0.1.7",
42
- "@giteeteam/apps-manifest": "^0.1.0",
42
+ "@giteeteam/apps-manifest": "^0.1.1",
43
43
  "archiver": "^5.3.1",
44
44
  "chalk": "^4.1.2",
45
45
  "chokidar": "^3.5.3",
@@ -58,6 +58,5 @@
58
58
  "@types/fs-extra": "^9.0.13",
59
59
  "@types/inquirer": "^8.2.1",
60
60
  "@types/uuid": "^8.3.4"
61
- },
62
- "gitHead": "f32eb236ef8765f6788e9906416745043cf76158"
61
+ }
63
62
  }