@giteeteam/apps-cli 0.2.0 → 0.2.2

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 +41 -35
  2. package/package.json +2 -2
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.0";
34
+ var version = "0.2.2";
35
35
 
36
36
  const packageApp = async ({ outputDir, manifest, copyFiles }) => {
37
37
  const { resources } = manifest;
@@ -169,7 +169,7 @@ class Manifest {
169
169
  }
170
170
 
171
171
  const getManifest = async () => {
172
- const manifestFile = path__default["default"].resolve('./manifest.yml');
172
+ const manifestFile = path__default["default"].resolve('manifest.yml');
173
173
  const strBuffer = await fse__default["default"].readFile(manifestFile);
174
174
  return new Manifest(strBuffer.toString());
175
175
  };
@@ -389,6 +389,8 @@ class DockerService {
389
389
  console.log(`Download image(${this.imageName}) success`);
390
390
  }
391
391
  async runContainer({ port, env, name, volume = [] }) {
392
+ // 先删掉容器
393
+ await this.removeContainer(name);
392
394
  const envStr = Object.keys(env)
393
395
  .map(k => `-e ${k}=${env[k]}`)
394
396
  .join(' ');
@@ -400,10 +402,12 @@ class DockerService {
400
402
  await this.execPromise(`docker rm -f ${containerName}`);
401
403
  }
402
404
  execPromise(cmd) {
403
- return new Promise(resolve => {
405
+ return new Promise((resolve, reject) => {
404
406
  child_process__default["default"].exec(cmd, (err, stdout, stderr) => {
407
+ if (err) {
408
+ return reject(err);
409
+ }
405
410
  resolve({
406
- err: err,
407
411
  stdout: stdout,
408
412
  stderr: stderr,
409
413
  });
@@ -438,55 +442,57 @@ const watchFiles = async (options) => {
438
442
  }
439
443
  };
440
444
 
441
- var _a$1;
442
- const containerPort = Number((_a$1 = process.env.CONTAINER_PORT) !== null && _a$1 !== void 0 ? _a$1 : 8455);
445
+ var _a, _b;
446
+ const image = {
447
+ repository: 'registry.baidubce.com/proxima/proxima-apps-runtime-server',
448
+ tag: (_a = process.env.IMAGE_TAG) !== null && _a !== void 0 ? _a : '2.5.0-alpha-41',
449
+ };
450
+ const containerPort = Number((_b = process.env.CONTAINER_PORT) !== null && _b !== void 0 ? _b : 8455);
443
451
  const containerName = 'cli-dev-apps-runtime-server';
444
- const copyManifest = async (pluginDir) => {
445
- const manifestFile = path__default["default"].resolve('./manifest.yml');
446
- const targetFile = path__default["default"].join(pluginDir, 'manifest.yml');
452
+ const tempAppDir = 'app/production/1.0/server-side';
453
+ const containerEnv = {
454
+ PORT: containerPort,
455
+ APPS_DIR: '/usr/src/app/apps',
456
+ LRU_TTL: 0,
457
+ DEBUG: 'runtime*',
458
+ PARSE_PUBLIC_SERVER_URL: process.env.PARSE_PUBLIC_SERVER_URL,
459
+ PARSE_SERVER_MASTER_KEY: process.env.PARSE_SERVER_MASTER_KEY,
460
+ PROXIMA_CORE_URL: process.env.PROXIMA_CORE_URL,
461
+ PGSQL_CLIENT_HOST: process.env.PGSQL_CLIENT_HOST,
462
+ PGSQL_CLIENT_PORT: process.env.PGSQL_CLIENT_PORT,
463
+ PGSQL_CLIENT_USER: process.env.PGSQL_CLIENT_USER,
464
+ PGSQL_CLIENT_PASSWORD: process.env.PGSQL_CLIENT_PASSWORD,
465
+ };
466
+ const copyManifest = async (appDir) => {
467
+ const manifestFile = path__default["default"].resolve('manifest.yml');
468
+ const targetFile = path__default["default"].join(appDir, 'manifest.yml');
447
469
  await fse__default["default"].copy(manifestFile, targetFile);
448
470
  };
449
471
  var run = async (options) => {
450
- const { imageName, inputDir, outputDir } = options;
472
+ const { inputDir, outputDir } = options;
473
+ await fse__default["default"].emptyDir(outputDir);
474
+ const imageName = `${image.repository}:${image.tag}`;
475
+ const appDir = path__default["default"].join(outputDir, tempAppDir);
451
476
  const dockerService = new DockerService(imageName);
452
- const pluginDir = path__default["default"].join(outputDir, '_test/production/1.0/server-side');
453
477
  await dockerService.downloadImage();
454
478
  await dockerService.runContainer({
455
479
  port: containerPort,
456
- env: {
457
- PORT: containerPort,
458
- APPS_DIR: '/usr/src/app/apps',
459
- LRU_TTL: 0,
460
- DEBUG: 'runtime*',
461
- PARSE_PUBLIC_SERVER_URL: process.env.PARSE_PUBLIC_SERVER_URL,
462
- PARSE_SERVER_MASTER_KEY: process.env.PARSE_SERVER_MASTER_KEY,
463
- PROXIMA_CORE_URL: process.env.PROXIMA_CORE_URL,
464
- PGSQL_CLIENT_HOST: process.env.PGSQL_CLIENT_HOST,
465
- PGSQL_CLIENT_PORT: process.env.PGSQL_CLIENT_PORT,
466
- PGSQL_CLIENT_USER: process.env.PGSQL_CLIENT_USER,
467
- PGSQL_CLIENT_PASSWORD: process.env.PGSQL_CLIENT_PASSWORD,
468
- },
480
+ env: containerEnv,
469
481
  volume: [`${outputDir}:/usr/src/app/apps`],
470
482
  name: containerName,
471
483
  });
472
- process.on('SIGINT', () => {
473
- console.log('process,SIGINT');
474
- dockerService.removeContainer(containerName);
484
+ process.on('SIGINT', async () => {
485
+ await dockerService.removeContainer(containerName);
486
+ await fse__default["default"].remove(outputDir);
475
487
  process.exit();
476
488
  });
477
- await copyManifest(pluginDir);
478
- await watchFiles({ inputDir, outputDir: pluginDir });
489
+ await copyManifest(appDir);
490
+ await watchFiles({ inputDir, outputDir: appDir });
479
491
  };
480
492
 
481
- var _a;
482
- const image = {
483
- repository: 'registry.baidubce.com/proxima/proxima-apps-runtime-server',
484
- tag: (_a = process.env.IMAGE_TAG) !== null && _a !== void 0 ? _a : '2.5.0-alpha-41',
485
- };
486
493
  var dev = async (options) => {
487
494
  const { input = 'src', output = 'cache' } = options;
488
495
  await run({
489
- imageName: `${image.repository}:${image.tag}`,
490
496
  outputDir: path__default["default"].resolve(output),
491
497
  inputDir: path__default["default"].resolve(input),
492
498
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giteeteam/apps-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Giteeteam Apps cli",
5
5
  "keywords": [
6
6
  "typescript",
@@ -59,5 +59,5 @@
59
59
  "@types/inquirer": "^8.2.1",
60
60
  "@types/uuid": "^8.3.4"
61
61
  },
62
- "gitHead": "11be8747537fcd607f97a80f5f3e07a592e85b14"
62
+ "gitHead": "21e371df9bb6e4b94ccd508f17db93f5055a0b3d"
63
63
  }