@giteeteam/apps-cli 0.1.17-alpha.0 → 0.1.18-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.
Files changed (3) hide show
  1. package/README.md +7 -2
  2. package/dist/index.js +83 -19
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -8,10 +8,15 @@ $ npm install @giteeteam/apps-cli -g
8
8
  ## 创建应用
9
9
  ```bash
10
10
  // uikit-app为项目名称
11
- $ giteeteam-apps-cli create uikit-app
11
+ $ giteeteam-apps create uikit-app
12
12
  ```
13
13
 
14
14
  ## 打包应用
15
15
  ```bash
16
- $ giteeteam-apps-cli build
16
+ $ giteeteam-apps build
17
+ ```
18
+
19
+ ## 调试插件function
20
+ ```bash
21
+ $ giteeteam-apps dev
17
22
  ```
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ var chalk = require('chalk');
15
15
  var readline = require('readline');
16
16
  var execa = require('execa');
17
17
  var child_process = require('child_process');
18
+ var chokidar = require('chokidar');
18
19
 
19
20
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
21
 
@@ -27,8 +28,9 @@ var simpleGit__default = /*#__PURE__*/_interopDefaultLegacy(simpleGit);
27
28
  var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
28
29
  var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
29
30
  var child_process__default = /*#__PURE__*/_interopDefaultLegacy(child_process);
31
+ var chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
30
32
 
31
- var version = "0.1.17-alpha.0";
33
+ var version = "0.1.18-alpha.0";
32
34
 
33
35
  const packageApp = async ({ outputDir, manifest, copyFiles }) => {
34
36
  const { resources } = manifest;
@@ -88,14 +90,9 @@ const archiveApp = async (archiveDir, pkgName) => {
88
90
  };
89
91
 
90
92
  const bundleApp = async (opts) => {
91
- var _a, _b;
92
93
  const { manifest, mode, outputDir, inputDir } = opts;
93
- const fileNames = new Set();
94
- (_b = (_a = manifest.modules) === null || _a === void 0 ? void 0 : _a.function) === null || _b === void 0 ? void 0 : _b.forEach(({ handler }) => {
95
- const filename = handler.split('.')[0];
96
- fileNames.add(filename);
97
- });
98
- const bundlePromise = [...fileNames].map(async (fileName) => {
94
+ const functionFiles = manifest.getFunctionFiles();
95
+ const bundlePromise = functionFiles.map(async (fileName) => {
99
96
  await appsBundler.bundle({
100
97
  inputDir,
101
98
  fileName,
@@ -119,16 +116,66 @@ const execActionWithSpinner = async (message, action) => {
119
116
  spinner.succeed(message.succeed);
120
117
  };
121
118
 
122
- const getManifestObject = async () => {
119
+ class Manifest {
120
+ constructor(manifestStr) {
121
+ this.manifest = yaml.parse(manifestStr);
122
+ }
123
+ get resources() {
124
+ return this.manifest.resources;
125
+ }
126
+ get app() {
127
+ return this.manifest.app;
128
+ }
129
+ /**
130
+ * 根据key获取执行的function名称
131
+ * @param key
132
+ * @returns
133
+ */
134
+ getFunctionByKey(key) {
135
+ var _a, _b, _c, _d, _e;
136
+ const { modules } = this.manifest;
137
+ for (const k in modules) {
138
+ if (k === 'function') {
139
+ continue;
140
+ }
141
+ else if (k === 'importer') {
142
+ // importer扩展点需要判断function和validate
143
+ 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)) {
144
+ return (_c = modules === null || modules === void 0 ? void 0 : modules.function) === null || _c === void 0 ? void 0 : _c.find(v => v.key === key);
145
+ }
146
+ }
147
+ else if (Array.isArray(modules[k])) {
148
+ const targetModule = (_d = modules[k]) === null || _d === void 0 ? void 0 : _d.find(v => v.key === key);
149
+ if (targetModule) {
150
+ return (_e = modules === null || modules === void 0 ? void 0 : modules.function) === null || _e === void 0 ? void 0 : _e.find(v => v.key === targetModule.function);
151
+ }
152
+ }
153
+ }
154
+ }
155
+ /**
156
+ * 获取function下的文件列表
157
+ * @returns
158
+ */
159
+ getFunctionFiles() {
160
+ var _a, _b;
161
+ const fileNames = new Set();
162
+ (_b = (_a = this.manifest.modules) === null || _a === void 0 ? void 0 : _a.function) === null || _b === void 0 ? void 0 : _b.forEach(({ handler }) => {
163
+ const filename = handler.split('.')[0];
164
+ fileNames.add(filename);
165
+ });
166
+ return [...fileNames];
167
+ }
168
+ }
169
+
170
+ const getManifest = async () => {
123
171
  const manifestFile = path__default["default"].resolve('./manifest.yml');
124
172
  const strBuffer = await fse__default["default"].readFile(manifestFile);
125
- const obj = yaml.parse(strBuffer.toString());
126
- return obj;
173
+ return new Manifest(strBuffer.toString());
127
174
  };
128
175
 
129
176
  var run$2 = async ({ outputDir, inputDir, prod, copyFiles, zip }) => {
130
- const manifest = await getManifestObject();
131
- const { app: { version, key }, } = manifest;
177
+ const manifest = await getManifest();
178
+ const { version, key } = manifest.app;
132
179
  if (!key) {
133
180
  console.error('manifest app key is required');
134
181
  return;
@@ -360,18 +407,35 @@ class DockerService {
360
407
  }
361
408
  }
362
409
 
363
- const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
410
+ const watchFiles = async (options) => {
411
+ const { inputDir, outputDir } = options;
412
+ const manifest = await getManifest();
413
+ const functionFiles = manifest.getFunctionFiles();
414
+ for (const fileName of functionFiles) {
415
+ const filePath = path__default["default"].join(inputDir, fileName);
416
+ const watcher = chokidar__default["default"].watch(filePath);
417
+ watcher.on('change', () => {
418
+ appsBundler.bundle({
419
+ inputDir,
420
+ outputDir,
421
+ fileName,
422
+ mode: appsBundler.MODE.DEV,
423
+ });
424
+ });
425
+ }
426
+ };
427
+
364
428
  var run = async (options) => {
365
- const { imageName } = options;
429
+ const { imageName, inputDir, outputDir } = options;
366
430
  const dockerService = new DockerService(imageName);
431
+ await dockerService.downloadImage();
432
+ await dockerService.runContainer();
367
433
  process.on('SIGINT', () => {
368
434
  console.log('process,SIGINT');
369
435
  dockerService.removeContainer();
370
436
  process.exit();
371
437
  });
372
- await dockerService.downloadImage();
373
- await dockerService.runContainer();
374
- await sleep(30000);
438
+ await watchFiles({ inputDir, outputDir });
375
439
  };
376
440
 
377
441
  const image = {
@@ -398,5 +462,5 @@ program
398
462
  .option('-o --output [dir]', 'output dir')
399
463
  .action(build);
400
464
  program.command('create [name]').action(create);
401
- program.command('dev').action(dev);
465
+ program.command('dev').option('-i --input [dir]', 'input dir').option('-o --output [dir]', 'output dir').action(dev);
402
466
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giteeteam/apps-cli",
3
- "version": "0.1.17-alpha.0",
3
+ "version": "0.1.18-alpha.0",
4
4
  "description": "Giteeteam Apps cli",
5
5
  "keywords": [
6
6
  "typescript",
@@ -39,6 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@giteeteam/apps-bundler": "^0.1.7",
42
+ "@giteeteam/apps-manifest": "^0.1.0",
42
43
  "archiver": "^5.3.1",
43
44
  "chalk": "^4.1.2",
44
45
  "chokidar": "^3.5.3",
@@ -57,5 +58,5 @@
57
58
  "@types/inquirer": "^8.2.1",
58
59
  "@types/uuid": "^8.3.4"
59
60
  },
60
- "gitHead": "2151038acb5e1e9695f11009e542187839482907"
61
+ "gitHead": "0b6fe536c2487a1f43e9d373bd2dc2f800c8ae92"
61
62
  }