@giteeteam/apps-cli 0.1.18-alpha.0 → 0.2.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/dist/index.js +65 -16
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
require('dotenv/config');
|
|
4
5
|
var commander = require('commander');
|
|
5
6
|
var appsBundler = require('@giteeteam/apps-bundler');
|
|
6
7
|
var fse = require('fs-extra');
|
|
@@ -30,7 +31,7 @@ var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
|
|
|
30
31
|
var child_process__default = /*#__PURE__*/_interopDefaultLegacy(child_process);
|
|
31
32
|
var chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
|
|
32
33
|
|
|
33
|
-
var version = "0.1
|
|
34
|
+
var version = "0.2.1";
|
|
34
35
|
|
|
35
36
|
const packageApp = async ({ outputDir, manifest, copyFiles }) => {
|
|
36
37
|
const { resources } = manifest;
|
|
@@ -379,26 +380,34 @@ var create = async (packageName) => {
|
|
|
379
380
|
});
|
|
380
381
|
};
|
|
381
382
|
|
|
382
|
-
const containerName = 'cli-dev-apps-runtime-server';
|
|
383
383
|
class DockerService {
|
|
384
384
|
constructor(imageName) {
|
|
385
385
|
this.imageName = imageName;
|
|
386
386
|
}
|
|
387
387
|
async downloadImage() {
|
|
388
388
|
await this.execPromise(`docker pull ${this.imageName}`);
|
|
389
|
+
console.log(`Download image(${this.imageName}) success`);
|
|
389
390
|
}
|
|
390
|
-
async runContainer() {
|
|
391
|
-
|
|
391
|
+
async runContainer({ port, env, name, volume = [] }) {
|
|
392
|
+
// 先删掉容器
|
|
393
|
+
await this.removeContainer(name);
|
|
394
|
+
const envStr = Object.keys(env)
|
|
395
|
+
.map(k => `-e ${k}=${env[k]}`)
|
|
396
|
+
.join(' ');
|
|
397
|
+
const volumeStr = volume === null || volume === void 0 ? void 0 : volume.map(v => `-v ${v}`).join(' ');
|
|
398
|
+
const command = `docker run -d -p ${port}:${port} ${envStr} ${volumeStr} --name ${name} ${this.imageName}`;
|
|
392
399
|
await this.execPromise(command);
|
|
393
400
|
}
|
|
394
|
-
async removeContainer() {
|
|
401
|
+
async removeContainer(containerName) {
|
|
395
402
|
await this.execPromise(`docker rm -f ${containerName}`);
|
|
396
403
|
}
|
|
397
404
|
execPromise(cmd) {
|
|
398
|
-
return new Promise(resolve => {
|
|
405
|
+
return new Promise((resolve, reject) => {
|
|
399
406
|
child_process__default["default"].exec(cmd, (err, stdout, stderr) => {
|
|
407
|
+
if (err) {
|
|
408
|
+
return reject(err);
|
|
409
|
+
}
|
|
400
410
|
resolve({
|
|
401
|
-
err: err,
|
|
402
411
|
stdout: stdout,
|
|
403
412
|
stderr: stderr,
|
|
404
413
|
});
|
|
@@ -412,9 +421,17 @@ const watchFiles = async (options) => {
|
|
|
412
421
|
const manifest = await getManifest();
|
|
413
422
|
const functionFiles = manifest.getFunctionFiles();
|
|
414
423
|
for (const fileName of functionFiles) {
|
|
415
|
-
|
|
424
|
+
appsBundler.bundle({
|
|
425
|
+
inputDir,
|
|
426
|
+
outputDir,
|
|
427
|
+
fileName,
|
|
428
|
+
mode: appsBundler.MODE.DEV,
|
|
429
|
+
});
|
|
430
|
+
const filePath = path__default["default"].join(inputDir, `${fileName}.ts`);
|
|
431
|
+
console.log(`watch file path: ${filePath}`);
|
|
416
432
|
const watcher = chokidar__default["default"].watch(filePath);
|
|
417
433
|
watcher.on('change', () => {
|
|
434
|
+
console.log(`File ${filePath} has been changed`);
|
|
418
435
|
appsBundler.bundle({
|
|
419
436
|
inputDir,
|
|
420
437
|
outputDir,
|
|
@@ -425,25 +442,53 @@ const watchFiles = async (options) => {
|
|
|
425
442
|
}
|
|
426
443
|
};
|
|
427
444
|
|
|
445
|
+
var _a$1;
|
|
446
|
+
const containerPort = Number((_a$1 = process.env.CONTAINER_PORT) !== null && _a$1 !== void 0 ? _a$1 : 8455);
|
|
447
|
+
const containerName = 'cli-dev-apps-runtime-server';
|
|
448
|
+
const copyManifest = async (pluginDir) => {
|
|
449
|
+
const manifestFile = path__default["default"].resolve('./manifest.yml');
|
|
450
|
+
const targetFile = path__default["default"].join(pluginDir, 'manifest.yml');
|
|
451
|
+
await fse__default["default"].copy(manifestFile, targetFile);
|
|
452
|
+
};
|
|
428
453
|
var run = async (options) => {
|
|
429
454
|
const { imageName, inputDir, outputDir } = options;
|
|
430
455
|
const dockerService = new DockerService(imageName);
|
|
456
|
+
const pluginDir = path__default["default"].join(outputDir, '_test/production/1.0/server-side');
|
|
431
457
|
await dockerService.downloadImage();
|
|
432
|
-
await dockerService.runContainer(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
458
|
+
await dockerService.runContainer({
|
|
459
|
+
port: containerPort,
|
|
460
|
+
env: {
|
|
461
|
+
PORT: containerPort,
|
|
462
|
+
APPS_DIR: '/usr/src/app/apps',
|
|
463
|
+
LRU_TTL: 0,
|
|
464
|
+
DEBUG: 'runtime*',
|
|
465
|
+
PARSE_PUBLIC_SERVER_URL: process.env.PARSE_PUBLIC_SERVER_URL,
|
|
466
|
+
PARSE_SERVER_MASTER_KEY: process.env.PARSE_SERVER_MASTER_KEY,
|
|
467
|
+
PROXIMA_CORE_URL: process.env.PROXIMA_CORE_URL,
|
|
468
|
+
PGSQL_CLIENT_HOST: process.env.PGSQL_CLIENT_HOST,
|
|
469
|
+
PGSQL_CLIENT_PORT: process.env.PGSQL_CLIENT_PORT,
|
|
470
|
+
PGSQL_CLIENT_USER: process.env.PGSQL_CLIENT_USER,
|
|
471
|
+
PGSQL_CLIENT_PASSWORD: process.env.PGSQL_CLIENT_PASSWORD,
|
|
472
|
+
},
|
|
473
|
+
volume: [`${outputDir}:/usr/src/app/apps`],
|
|
474
|
+
name: containerName,
|
|
475
|
+
});
|
|
476
|
+
process.on('SIGINT', async () => {
|
|
477
|
+
await dockerService.removeContainer(containerName);
|
|
478
|
+
await fse__default["default"].remove(outputDir);
|
|
436
479
|
process.exit();
|
|
437
480
|
});
|
|
438
|
-
await
|
|
481
|
+
await copyManifest(pluginDir);
|
|
482
|
+
await watchFiles({ inputDir, outputDir: pluginDir });
|
|
439
483
|
};
|
|
440
484
|
|
|
485
|
+
var _a;
|
|
441
486
|
const image = {
|
|
442
487
|
repository: 'registry.baidubce.com/proxima/proxima-apps-runtime-server',
|
|
443
|
-
tag: '2.5.0-alpha-41',
|
|
488
|
+
tag: (_a = process.env.IMAGE_TAG) !== null && _a !== void 0 ? _a : '2.5.0-alpha-41',
|
|
444
489
|
};
|
|
445
490
|
var dev = async (options) => {
|
|
446
|
-
const { input = 'src', output = '
|
|
491
|
+
const { input = 'src', output = 'cache' } = options;
|
|
447
492
|
await run({
|
|
448
493
|
imageName: `${image.repository}:${image.tag}`,
|
|
449
494
|
outputDir: path__default["default"].resolve(output),
|
|
@@ -462,5 +507,9 @@ program
|
|
|
462
507
|
.option('-o --output [dir]', 'output dir')
|
|
463
508
|
.action(build);
|
|
464
509
|
program.command('create [name]').action(create);
|
|
465
|
-
program
|
|
510
|
+
program
|
|
511
|
+
.command('dev')
|
|
512
|
+
.option('-i --input [dir]', 'input dir')
|
|
513
|
+
.option('-o --output [dir]', 'output dir,default cache')
|
|
514
|
+
.action(dev);
|
|
466
515
|
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@giteeteam/apps-cli",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Giteeteam Apps cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"chalk": "^4.1.2",
|
|
45
45
|
"chokidar": "^3.5.3",
|
|
46
46
|
"commander": "^9.3.0",
|
|
47
|
+
"dotenv": "^16.0.2",
|
|
47
48
|
"execa": "^5.1.1",
|
|
48
49
|
"fs-extra": "^10.1.0",
|
|
49
50
|
"inquirer": "^8.2.4",
|
|
@@ -58,5 +59,5 @@
|
|
|
58
59
|
"@types/inquirer": "^8.2.1",
|
|
59
60
|
"@types/uuid": "^8.3.4"
|
|
60
61
|
},
|
|
61
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "668caac9b1c7f4a82beb57b615ef827a84912823"
|
|
62
63
|
}
|