@giteeteam/apps-cli 0.2.5 → 0.2.7
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 +39 -27
- package/package.json +3 -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.
|
|
34
|
+
var version = "0.2.7";
|
|
35
35
|
|
|
36
36
|
const packageApp = async ({ outputDir, manifest, copyFiles }) => {
|
|
37
37
|
const { resources } = manifest;
|
|
@@ -211,7 +211,7 @@ var run$2 = async ({ outputDir, inputDir, prod, copyFiles, zip }) => {
|
|
|
211
211
|
};
|
|
212
212
|
|
|
213
213
|
const defaultCopyFiles = ['manifest.yml'];
|
|
214
|
-
var build = async (options) => {
|
|
214
|
+
var build$1 = async (options) => {
|
|
215
215
|
const { input = 'src', output = 'dist', prod, copy = [], zip } = options;
|
|
216
216
|
await run$2({
|
|
217
217
|
outputDir: path__default["default"].resolve(output),
|
|
@@ -385,8 +385,9 @@ class DockerService {
|
|
|
385
385
|
this.imageName = imageName;
|
|
386
386
|
}
|
|
387
387
|
async downloadImage() {
|
|
388
|
+
console.log(`Downloading image(${this.imageName}) ...`);
|
|
388
389
|
await this.execPromise(`docker pull ${this.imageName}`);
|
|
389
|
-
console.log(`Download image(${this.imageName}) success
|
|
390
|
+
console.log(`Download image(${this.imageName}) success!`);
|
|
390
391
|
}
|
|
391
392
|
async runContainer({ port, env, name, volume = [] }) {
|
|
392
393
|
// 先删掉容器
|
|
@@ -416,26 +417,31 @@ class DockerService {
|
|
|
416
417
|
}
|
|
417
418
|
}
|
|
418
419
|
|
|
420
|
+
const build = (functionFiles, inputDir, outputDir) => {
|
|
421
|
+
for (const fileName of functionFiles) {
|
|
422
|
+
appsBundler.bundle({
|
|
423
|
+
inputDir,
|
|
424
|
+
outputDir,
|
|
425
|
+
fileName,
|
|
426
|
+
mode: appsBundler.MODE.DEV,
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
};
|
|
419
430
|
const watchFiles = async (options) => {
|
|
420
431
|
const { inputDir, outputDir } = options;
|
|
421
432
|
const manifest = await getManifest();
|
|
422
433
|
const functionFiles = manifest.getFunctionFiles();
|
|
434
|
+
build(functionFiles, inputDir, outputDir);
|
|
423
435
|
let timer;
|
|
424
436
|
// 监听整个文件夹,有一个文件改动,则全部重新build
|
|
425
437
|
// TODO 解析出文件之间的依赖关系,提升构建速度
|
|
426
438
|
const watcher = chokidar__default["default"].watch(inputDir);
|
|
427
|
-
|
|
439
|
+
console.log(`watch: ${inputDir}`);
|
|
440
|
+
watcher.on('change', path => {
|
|
428
441
|
clearTimeout(timer);
|
|
429
442
|
timer = setTimeout(() => {
|
|
430
|
-
console.log(
|
|
431
|
-
|
|
432
|
-
appsBundler.bundle({
|
|
433
|
-
inputDir,
|
|
434
|
-
outputDir,
|
|
435
|
-
fileName,
|
|
436
|
-
mode: appsBundler.MODE.DEV,
|
|
437
|
-
});
|
|
438
|
-
}
|
|
443
|
+
console.log(`${path} has change`);
|
|
444
|
+
build(functionFiles, inputDir, outputDir);
|
|
439
445
|
}, 1000);
|
|
440
446
|
});
|
|
441
447
|
};
|
|
@@ -443,7 +449,7 @@ const watchFiles = async (options) => {
|
|
|
443
449
|
var _a, _b;
|
|
444
450
|
const image = {
|
|
445
451
|
repository: 'registry.baidubce.com/proxima/proxima-apps-runtime-server',
|
|
446
|
-
tag: (_a = process.env.IMAGE_TAG) !== null && _a !== void 0 ? _a : '
|
|
452
|
+
tag: (_a = process.env.IMAGE_TAG) !== null && _a !== void 0 ? _a : 'latest',
|
|
447
453
|
};
|
|
448
454
|
const containerPort = Number((_b = process.env.CONTAINER_PORT) !== null && _b !== void 0 ? _b : 8455);
|
|
449
455
|
const containerName = 'cli-dev-apps-runtime-server';
|
|
@@ -452,7 +458,7 @@ const tempAppDir = `${tempApp}/server-side`;
|
|
|
452
458
|
const containerEnv = {
|
|
453
459
|
PORT: containerPort,
|
|
454
460
|
APPS_DIR: '/usr/src/app/apps',
|
|
455
|
-
LRU_TTL:
|
|
461
|
+
LRU_TTL: 1,
|
|
456
462
|
DEBUG: 'runtime*',
|
|
457
463
|
PARSE_PUBLIC_SERVER_URL: process.env.PARSE_PUBLIC_SERVER_URL,
|
|
458
464
|
PARSE_SERVER_MASTER_KEY: process.env.PARSE_SERVER_MASTER_KEY,
|
|
@@ -468,18 +474,20 @@ const copyManifest = async (appDir) => {
|
|
|
468
474
|
await fse__default["default"].copy(manifestFile, targetFile);
|
|
469
475
|
};
|
|
470
476
|
var run = async (options) => {
|
|
471
|
-
const { inputDir, outputDir } = options;
|
|
477
|
+
const { inputDir, outputDir, server } = options;
|
|
472
478
|
await fse__default["default"].emptyDir(outputDir);
|
|
473
479
|
const imageName = `${image.repository}:${image.tag}`;
|
|
474
480
|
const appDir = path__default["default"].join(outputDir, tempAppDir);
|
|
475
481
|
const dockerService = new DockerService(imageName);
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
482
|
+
if (server) {
|
|
483
|
+
await dockerService.downloadImage();
|
|
484
|
+
await dockerService.runContainer({
|
|
485
|
+
port: containerPort,
|
|
486
|
+
env: containerEnv,
|
|
487
|
+
volume: [`${outputDir}:/usr/src/app/apps`],
|
|
488
|
+
name: containerName,
|
|
489
|
+
});
|
|
490
|
+
}
|
|
483
491
|
process.on('SIGINT', async () => {
|
|
484
492
|
await dockerService.removeContainer(containerName);
|
|
485
493
|
await fse__default["default"].remove(outputDir);
|
|
@@ -487,15 +495,18 @@ var run = async (options) => {
|
|
|
487
495
|
});
|
|
488
496
|
await copyManifest(appDir);
|
|
489
497
|
await watchFiles({ inputDir, outputDir: appDir });
|
|
490
|
-
|
|
491
|
-
|
|
498
|
+
if (server) {
|
|
499
|
+
console.log('You can use this url for test:');
|
|
500
|
+
console.log(`POST http://localhost:${containerPort}/v1/apps${tempApp}/functions/:key`);
|
|
501
|
+
}
|
|
492
502
|
};
|
|
493
503
|
|
|
494
504
|
var dev = async (options) => {
|
|
495
|
-
const { input = 'src', output = 'cache' } = options;
|
|
505
|
+
const { input = 'src', output = 'cache', server = true } = options;
|
|
496
506
|
await run({
|
|
497
507
|
outputDir: path__default["default"].resolve(output),
|
|
498
508
|
inputDir: path__default["default"].resolve(input),
|
|
509
|
+
server,
|
|
499
510
|
});
|
|
500
511
|
};
|
|
501
512
|
|
|
@@ -508,11 +519,12 @@ program
|
|
|
508
519
|
.option('-c --copy [letters...]', 'copy files')
|
|
509
520
|
.option('-i --input [dir]', 'input dir')
|
|
510
521
|
.option('-o --output [dir]', 'output dir')
|
|
511
|
-
.action(build);
|
|
522
|
+
.action(build$1);
|
|
512
523
|
program.command('create [name]').action(create);
|
|
513
524
|
program
|
|
514
525
|
.command('dev')
|
|
515
526
|
.option('-i --input [dir]', 'input dir')
|
|
516
527
|
.option('-o --output [dir]', 'output dir,default cache')
|
|
528
|
+
.option('--no-server', 'no server')
|
|
517
529
|
.action(dev);
|
|
518
530
|
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@giteeteam/apps-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Giteeteam Apps cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -58,5 +58,6 @@
|
|
|
58
58
|
"@types/fs-extra": "^9.0.13",
|
|
59
59
|
"@types/inquirer": "^8.2.1",
|
|
60
60
|
"@types/uuid": "^8.3.4"
|
|
61
|
-
}
|
|
61
|
+
},
|
|
62
|
+
"gitHead": "3c1344d0154b4671d9477d491c514f02385a1f0d"
|
|
62
63
|
}
|