@cyklang/cli 0.5.3 → 0.5.5
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/build/AssetCommand.d.ts +24 -0
- package/build/AssetCommand.js +207 -178
- package/build/Cmd.d.ts +17 -12
- package/build/Cmd.js +82 -39
- package/build/DBClient.js +1 -0
- package/build/InstallCommand.d.ts +8 -7
- package/build/InstallCommand.js +148 -73
- package/build/ModuleCommand.d.ts +6 -0
- package/build/ModuleCommand.js +12 -1
- package/build/UninstallCommand.d.ts +20 -0
- package/build/UninstallCommand.js +164 -0
- package/build/index.js +3 -1
- package/package.json +2 -2
- package/src/AssetCommand.ts +212 -197
- package/src/Cmd.ts +59 -38
- package/src/DBClient.ts +1 -0
- package/src/InstallCommand.ts +156 -75
- package/src/ModuleCommand.ts +12 -0
- package/src/UninstallCommand.ts +145 -0
- package/src/index.ts +3 -1
package/build/AssetCommand.d.ts
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
+
import { DBManager, DBRemote } from "@cyklang/core";
|
|
2
3
|
export declare class AssetCommand extends Command {
|
|
3
4
|
constructor(name: string, description: string);
|
|
4
5
|
}
|
|
6
|
+
export interface FileDescriptor {
|
|
7
|
+
path: string;
|
|
8
|
+
mtime: Date;
|
|
9
|
+
id?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* function uploadDirectory
|
|
13
|
+
* @param source
|
|
14
|
+
* @param dest
|
|
15
|
+
* @param options {yes: no confirmation, auth: basic/token/cookie/undefined}
|
|
16
|
+
* @param dbManager
|
|
17
|
+
* @param dbRemote
|
|
18
|
+
*/
|
|
19
|
+
export declare function uploadDirectory(source: string, dest: string, options: any, dbManager: DBManager | undefined, dbRemote: DBRemote | undefined): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* function uploadAsset
|
|
22
|
+
* @param upload
|
|
23
|
+
* @param route
|
|
24
|
+
* @param dbManager
|
|
25
|
+
* @param dbRemote
|
|
26
|
+
* @param auth
|
|
27
|
+
*/
|
|
28
|
+
export declare function uploadAsset(upload: FileDescriptor, route: string, dbManager: DBManager | undefined, dbRemote: DBRemote | undefined, auth?: string): Promise<void>;
|
package/build/AssetCommand.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.AssetCommand = void 0;
|
|
29
|
+
exports.uploadAsset = exports.uploadDirectory = exports.AssetCommand = void 0;
|
|
30
30
|
const commander_1 = require("commander");
|
|
31
31
|
const loglevel_1 = require("loglevel");
|
|
32
32
|
const Cmd_1 = require("./Cmd");
|
|
@@ -184,10 +184,6 @@ class AssetList extends Cmd_1.Cmd {
|
|
|
184
184
|
class AssetU extends Cmd_1.Cmd {
|
|
185
185
|
constructor(name, description) {
|
|
186
186
|
super(name);
|
|
187
|
-
//----------------------------------------------------------------------------------------------
|
|
188
|
-
// file2exclude
|
|
189
|
-
//----------------------------------------------------------------------------------------------
|
|
190
|
-
this.ignorePatterns = ['.git', 'node_modules'];
|
|
191
187
|
this.description(description)
|
|
192
188
|
.option('-i --id <id>', 'asset id or pathname whose properties are updated')
|
|
193
189
|
.option('--auth <auth_schema>', 'authentication schema : basic | token | cookie | any | none, default is none')
|
|
@@ -200,16 +196,6 @@ class AssetU extends Cmd_1.Cmd {
|
|
|
200
196
|
await this.commandU(sources, options);
|
|
201
197
|
});
|
|
202
198
|
}
|
|
203
|
-
mimetypeLookup(filename) {
|
|
204
|
-
let result;
|
|
205
|
-
if (path_1.default.extname(filename) === '.cyk') {
|
|
206
|
-
result = 'application/xml';
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
result = mime_types_1.default.lookup(filename);
|
|
210
|
-
}
|
|
211
|
-
return result;
|
|
212
|
-
}
|
|
213
199
|
/**
|
|
214
200
|
* method commandU
|
|
215
201
|
* @param sources
|
|
@@ -274,7 +260,7 @@ class AssetU extends Cmd_1.Cmd {
|
|
|
274
260
|
if (dest.substring(dest.length - 1) !== '/')
|
|
275
261
|
dest = dest + '/';
|
|
276
262
|
if (options.clean) {
|
|
277
|
-
await
|
|
263
|
+
await cleanDestination(dest, this.dbManager, this.dbRemote);
|
|
278
264
|
}
|
|
279
265
|
for (let ind = 0; ind < sources.length; ind++) {
|
|
280
266
|
const source = sources[ind];
|
|
@@ -282,12 +268,12 @@ class AssetU extends Cmd_1.Cmd {
|
|
|
282
268
|
throw 'source ' + source + ' does not exist';
|
|
283
269
|
const filestat = fs.lstatSync(source);
|
|
284
270
|
if (filestat.isDirectory() === true) {
|
|
285
|
-
await
|
|
271
|
+
await uploadDirectory(source, dest, options, this.dbManager, this.dbRemote);
|
|
286
272
|
}
|
|
287
273
|
else if (filestat.isFile() === true) {
|
|
288
274
|
const base = path_1.default.parse(source).base;
|
|
289
275
|
logger.debug('upload file ' + source + ' to ' + dest + base);
|
|
290
|
-
await
|
|
276
|
+
await uploadAsset({ path: source, mtime: filestat.mtime }, dest + base, this.dbManager, this.dbRemote, options.auth);
|
|
291
277
|
}
|
|
292
278
|
}
|
|
293
279
|
}
|
|
@@ -295,180 +281,223 @@ class AssetU extends Cmd_1.Cmd {
|
|
|
295
281
|
logger.error(err);
|
|
296
282
|
}
|
|
297
283
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* function cleanDestination
|
|
287
|
+
* @param dest
|
|
288
|
+
* @param dbManager
|
|
289
|
+
* @param dbRemote
|
|
290
|
+
*/
|
|
291
|
+
async function cleanDestination(dest, dbManager, dbRemote) {
|
|
292
|
+
const remoteList = await scanAssets(dbManager);
|
|
293
|
+
for (let ind = 0; ind < remoteList.length; ind++) {
|
|
294
|
+
const fd = remoteList[ind];
|
|
295
|
+
if (fd.path.startsWith(dest)) {
|
|
296
|
+
const url = '/api/admin/assets/' + fd.id;
|
|
297
|
+
await dbRemote?.apiServer.delete(url);
|
|
309
298
|
}
|
|
310
299
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
//
|
|
325
|
-
|
|
326
|
-
const remoteList = await scanAssets(this.dbManager);
|
|
327
|
-
const uploadList = this.buildUploadList(dirName, dest, localList, remoteList);
|
|
328
|
-
// logger.info(fileNames.join('\n'))
|
|
329
|
-
if (uploadList.length === 0)
|
|
330
|
-
throw 'None file to upload';
|
|
331
|
-
let uploadConfirmed = (options.yes !== undefined);
|
|
332
|
-
if (uploadConfirmed === false) {
|
|
333
|
-
const reply = await inquirer_1.default.prompt({ type: 'confirm', name: 'confirm', message: 'Do you want to upload this(these) ' + uploadList.length + ' file(s) ?' });
|
|
334
|
-
if (reply.confirm === true)
|
|
335
|
-
uploadConfirmed = true;
|
|
336
|
-
}
|
|
337
|
-
if (uploadConfirmed === true) {
|
|
338
|
-
await this.uploadFiles(dirName, uploadList, dest, options.auth);
|
|
339
|
-
}
|
|
340
|
-
// const rl = readline.createInterface(process.stdin, process.stdout)
|
|
341
|
-
// rl.question('Do you want to upload this(these) ' + uploadList.length + ' file(s) (Y/N/y/n) ?', async (reply) => {
|
|
342
|
-
// rl.close()
|
|
343
|
-
// if (reply !== 'Y' && reply !== 'y') {
|
|
344
|
-
// logger.info('upload cancelled')
|
|
345
|
-
// return
|
|
346
|
-
// }
|
|
347
|
-
// await this.uploadFiles(dirName, uploadList, dest)
|
|
348
|
-
// })
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* function uploadDirectory
|
|
303
|
+
* @param source
|
|
304
|
+
* @param dest
|
|
305
|
+
* @param options {yes: no confirmation, auth: basic/token/cookie/undefined}
|
|
306
|
+
* @param dbManager
|
|
307
|
+
* @param dbRemote
|
|
308
|
+
*/
|
|
309
|
+
async function uploadDirectory(source, dest, options, dbManager, dbRemote) {
|
|
310
|
+
const localList = [];
|
|
311
|
+
let dirName;
|
|
312
|
+
if (source.substring(source.length - 1) === '/') {
|
|
313
|
+
// trailing directory separator
|
|
314
|
+
dirName = source;
|
|
349
315
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
316
|
+
else {
|
|
317
|
+
dirName = source + '/';
|
|
318
|
+
}
|
|
319
|
+
// logger.debug('options', options)
|
|
320
|
+
scanDir(dirName, localList);
|
|
321
|
+
const remoteList = await scanAssets(dbManager);
|
|
322
|
+
const uploadList = buildUploadList(dirName, dest, localList, remoteList);
|
|
323
|
+
// logger.info(fileNames.join('\n'))
|
|
324
|
+
if (uploadList.length === 0)
|
|
325
|
+
throw 'None file to upload';
|
|
326
|
+
let uploadConfirmed = (options.yes !== undefined);
|
|
327
|
+
if (uploadConfirmed === false) {
|
|
328
|
+
const reply = await inquirer_1.default.prompt({ type: 'confirm', name: 'confirm', message: 'Do you want to upload this(these) ' + uploadList.length + ' file(s) ?' });
|
|
329
|
+
if (reply.confirm === true)
|
|
330
|
+
uploadConfirmed = true;
|
|
331
|
+
}
|
|
332
|
+
if (uploadConfirmed === true) {
|
|
333
|
+
await uploadFiles(dirName, uploadList, dest, dbManager, dbRemote, options.auth);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
exports.uploadDirectory = uploadDirectory;
|
|
337
|
+
/**
|
|
338
|
+
* function buildUploadList
|
|
339
|
+
* @param dirName
|
|
340
|
+
* @param dest
|
|
341
|
+
* @param localList
|
|
342
|
+
* @param remoteList
|
|
343
|
+
* @returns
|
|
344
|
+
*/
|
|
345
|
+
function buildUploadList(dirName, dest, localList, remoteList) {
|
|
346
|
+
const result = [];
|
|
347
|
+
const remoteMap = new Map();
|
|
348
|
+
for (let ind = 0; ind < remoteList.length; ind++) {
|
|
349
|
+
const remote = remoteList[ind];
|
|
350
|
+
remoteMap.set(remote.path, remote);
|
|
351
|
+
}
|
|
352
|
+
for (let ind = 0; ind < localList.length; ind++) {
|
|
353
|
+
const localDesc = localList[ind];
|
|
354
|
+
const route = dest + localDesc.path.substring(dirName.length);
|
|
355
|
+
const remoteDesc = remoteMap.get(route);
|
|
356
|
+
if (remoteDesc === undefined || remoteDesc.mtime.getTime() + 1000 < localDesc.mtime.getTime()) {
|
|
357
|
+
if (remoteDesc === undefined)
|
|
358
|
+
logger.debug('remoteDesc undefined');
|
|
359
|
+
else
|
|
360
|
+
logger.debug('remoteDesc.mtime ' + remoteDesc.mtime.getTime(), 'localDesc.mtime ' + localDesc.mtime.getTime());
|
|
361
|
+
logger.info(localDesc.path);
|
|
362
|
+
result.push(localDesc);
|
|
372
363
|
}
|
|
373
|
-
return result;
|
|
374
364
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
365
|
+
return result;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* function scanDir
|
|
369
|
+
* @param dirName
|
|
370
|
+
* @param result
|
|
371
|
+
*/
|
|
372
|
+
function scanDir(dirName, result) {
|
|
373
|
+
const files = fs.readdirSync(dirName);
|
|
374
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
375
|
+
const fileName = files[ind];
|
|
376
|
+
if (file2exclude(fileName) === true)
|
|
377
|
+
continue;
|
|
378
|
+
const fstat = fs.statSync(dirName + fileName);
|
|
379
|
+
if (fstat.isDirectory() === true) {
|
|
380
|
+
scanDir(dirName + fileName + '/', result);
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
if (mimetypeLookup(fileName) === false) {
|
|
384
|
+
logger.info(fileName + ' file extension is unknown and will not be uploaded');
|
|
383
385
|
continue;
|
|
384
|
-
const fstat = fs.statSync(dirName + fileName);
|
|
385
|
-
if (fstat.isDirectory() === true) {
|
|
386
|
-
this.scanDir(dirName + fileName + '/', result);
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
if (this.mimetypeLookup(fileName) === false) {
|
|
390
|
-
logger.info(fileName + ' file extension is unknown and will not be uploaded');
|
|
391
|
-
continue;
|
|
392
|
-
}
|
|
393
|
-
//const dbAssetExist = this.dbManager?.dbAssetExist()
|
|
394
|
-
result.push({ path: dirName + fileName, mtime: fstat.mtime });
|
|
395
|
-
// logger.debug(dirName + '/' + fileName)
|
|
396
386
|
}
|
|
387
|
+
//const dbAssetExist = this.dbManager?.dbAssetExist()
|
|
388
|
+
result.push({ path: dirName + fileName, mtime: fstat.mtime });
|
|
389
|
+
// logger.debug(dirName + '/' + fileName)
|
|
397
390
|
}
|
|
398
391
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
392
|
+
}
|
|
393
|
+
const ignorePatterns = ['.git', 'node_modules'];
|
|
394
|
+
/**
|
|
395
|
+
* function file2exclude
|
|
396
|
+
* @param fileName
|
|
397
|
+
* @returns
|
|
398
|
+
*/
|
|
399
|
+
function file2exclude(fileName) {
|
|
400
|
+
let result = false;
|
|
401
|
+
ignorePatterns.forEach((pattern) => {
|
|
402
|
+
if (fileName === pattern)
|
|
403
|
+
result = true;
|
|
404
|
+
});
|
|
405
|
+
return result;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* function uploadFiles
|
|
409
|
+
* @param dirName
|
|
410
|
+
* @param uploadList
|
|
411
|
+
* @param dest
|
|
412
|
+
* @param dbManager
|
|
413
|
+
* @param dbRemote
|
|
414
|
+
* @param auth
|
|
415
|
+
*/
|
|
416
|
+
async function uploadFiles(dirName, uploadList, dest, dbManager, dbRemote, auth) {
|
|
417
|
+
for (let ind = 0; ind < uploadList.length; ind++) {
|
|
418
|
+
const upload = uploadList[ind];
|
|
419
|
+
const route = dest + upload.path.substring(dirName.length);
|
|
420
|
+
logger.debug('upload ' + upload.path + ' to ' + route);
|
|
421
|
+
await uploadAsset(upload, route, dbManager, dbRemote, auth);
|
|
406
422
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* function uploadAsset
|
|
426
|
+
* @param upload
|
|
427
|
+
* @param route
|
|
428
|
+
* @param dbManager
|
|
429
|
+
* @param dbRemote
|
|
430
|
+
* @param auth
|
|
431
|
+
*/
|
|
432
|
+
async function uploadAsset(upload, route, dbManager, dbRemote, auth) {
|
|
433
|
+
// logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth)
|
|
434
|
+
try {
|
|
435
|
+
let dbAsset = await dbManager?.dbAssetExist(route);
|
|
436
|
+
if (dbAsset === undefined) {
|
|
437
|
+
dbAsset = new core_1.DBAsset();
|
|
416
438
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
dbAsset.
|
|
432
|
-
dbAsset.route
|
|
433
|
-
dbAsset.auth = auth;
|
|
434
|
-
if (dbAsset.auth === 'none')
|
|
435
|
-
dbAsset.auth = undefined;
|
|
436
|
-
// const fstat = fs.statSync(fileName)
|
|
437
|
-
dbAsset.last_update = upload.mtime;
|
|
438
|
-
// const contentBuffer = fs.readFileSync(fileName)
|
|
439
|
-
// dbAsset.content = contentBuffer
|
|
440
|
-
// logger.debug('dbAsset.content length ' + dbAsset.content.length)
|
|
441
|
-
if (dbAsset.id === undefined) {
|
|
442
|
-
dbAsset.id = await this.dbManager?.dbAssetInsert(dbAsset);
|
|
443
|
-
logger.info('inserted asset ' + dbAsset.id + ' route ' + dbAsset.route);
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
await this.dbManager?.dbAssetUpdate(dbAsset);
|
|
447
|
-
logger.info('updated asset ' + dbAsset.route);
|
|
448
|
-
}
|
|
449
|
-
await this.uploadAssetContent(dbAsset, upload.path);
|
|
439
|
+
const mimetype = mimetypeLookup(upload.path);
|
|
440
|
+
if (mimetype === false)
|
|
441
|
+
throw 'mimetype false for ' + upload;
|
|
442
|
+
dbAsset.mimetype = mimetype;
|
|
443
|
+
dbAsset.route = route;
|
|
444
|
+
dbAsset.auth = auth;
|
|
445
|
+
if (dbAsset.auth === 'none')
|
|
446
|
+
dbAsset.auth = undefined;
|
|
447
|
+
// const fstat = fs.statSync(fileName)
|
|
448
|
+
dbAsset.last_update = upload.mtime;
|
|
449
|
+
// const contentBuffer = fs.readFileSync(fileName)
|
|
450
|
+
// dbAsset.content = contentBuffer
|
|
451
|
+
// logger.debug('dbAsset.content length ' + dbAsset.content.length)
|
|
452
|
+
if (dbAsset.id === undefined) {
|
|
453
|
+
dbAsset.id = await dbManager?.dbAssetInsert(dbAsset);
|
|
454
|
+
logger.info('inserted asset ' + dbAsset.id + ' route ' + dbAsset.route);
|
|
450
455
|
}
|
|
451
|
-
|
|
452
|
-
|
|
456
|
+
else {
|
|
457
|
+
await dbManager?.dbAssetUpdate(dbAsset);
|
|
458
|
+
logger.info('updated asset ' + dbAsset.route);
|
|
453
459
|
}
|
|
460
|
+
await uploadAssetContent(dbAsset, upload.path, dbRemote);
|
|
454
461
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
462
|
+
catch (err) {
|
|
463
|
+
logger.error(err);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
exports.uploadAsset = uploadAsset;
|
|
467
|
+
/**
|
|
468
|
+
* function mimetypeLookup
|
|
469
|
+
* @param filename
|
|
470
|
+
* @returns
|
|
471
|
+
*/
|
|
472
|
+
function mimetypeLookup(filename) {
|
|
473
|
+
let result;
|
|
474
|
+
if (path_1.default.extname(filename) === '.cyk') {
|
|
475
|
+
result = 'application/xml';
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
result = mime_types_1.default.lookup(filename);
|
|
479
|
+
}
|
|
480
|
+
return result;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* function uploadAssetContent
|
|
484
|
+
* @param dbAsset
|
|
485
|
+
* @param fileName
|
|
486
|
+
* @param dbRemote
|
|
487
|
+
*/
|
|
488
|
+
async function uploadAssetContent(dbAsset, fileName, dbRemote) {
|
|
489
|
+
logger.debug('uploadAssetContent file ' + fileName + ' to path ' + path_1.default);
|
|
490
|
+
try {
|
|
491
|
+
const file = fs.createReadStream(fileName);
|
|
492
|
+
const form = new form_data_1.default();
|
|
493
|
+
form.append('uploadFile', file);
|
|
494
|
+
const route = '/api/upload/cyk_asset/asset_content?asset_id=' + dbAsset.id;
|
|
495
|
+
const resp = await dbRemote?.apiServer.post(route, form);
|
|
496
|
+
if (resp.status === 200) {
|
|
497
|
+
logger.info(fileName + ' uploaded');
|
|
472
498
|
}
|
|
473
499
|
}
|
|
500
|
+
catch (err) {
|
|
501
|
+
logger.error(err);
|
|
502
|
+
}
|
|
474
503
|
}
|
package/build/Cmd.d.ts
CHANGED
|
@@ -22,16 +22,21 @@ export declare class Cmd extends Command {
|
|
|
22
22
|
stdout: string;
|
|
23
23
|
stderr: string;
|
|
24
24
|
}>;
|
|
25
|
-
/**
|
|
26
|
-
* method runShellCommand
|
|
27
|
-
* @param command
|
|
28
|
-
*/
|
|
29
|
-
runShellCommand(command: string, args: string[]): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
* @param command
|
|
33
|
-
* @param args
|
|
34
|
-
* @returns
|
|
35
|
-
*/
|
|
36
|
-
spawnCommand(command: string, args: string[]): Promise<void>;
|
|
37
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* method runShellCommand
|
|
28
|
+
* @param command
|
|
29
|
+
*/
|
|
30
|
+
export declare function runShellCommand(command: string, args: string[]): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* function spawnCommand
|
|
33
|
+
* @param command
|
|
34
|
+
* @param args
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export declare function spawnCommand(command: string, args: string[]): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* function readPackageJson
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
export declare function readPackageJson(): Promise<any>;
|
package/build/Cmd.js
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Cmd = void 0;
|
|
29
|
+
exports.readPackageJson = exports.spawnCommand = exports.runShellCommand = exports.Cmd = void 0;
|
|
7
30
|
const core_1 = require("@cyklang/core");
|
|
8
31
|
const commander_1 = require("commander");
|
|
9
32
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
@@ -12,6 +35,7 @@ const NodeCrypto_1 = require("./NodeCrypto");
|
|
|
12
35
|
const DBClient_1 = require("./DBClient");
|
|
13
36
|
const child_process_1 = require("child_process");
|
|
14
37
|
const kolorist_1 = require("kolorist");
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
15
39
|
const logger = loglevel_1.default.getLogger('Cmd.ts');
|
|
16
40
|
logger.setLevel('debug');
|
|
17
41
|
class Cmd extends commander_1.Command {
|
|
@@ -100,45 +124,64 @@ class Cmd extends commander_1.Command {
|
|
|
100
124
|
});
|
|
101
125
|
});
|
|
102
126
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
console.error('Error running "' + command + '":', error);
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
127
|
+
}
|
|
128
|
+
exports.Cmd = Cmd;
|
|
129
|
+
/**
|
|
130
|
+
* method runShellCommand
|
|
131
|
+
* @param command
|
|
132
|
+
*/
|
|
133
|
+
async function runShellCommand(command, args) {
|
|
134
|
+
try {
|
|
135
|
+
await spawnCommand(command, args);
|
|
136
|
+
// console.log(command)
|
|
137
|
+
// const result = await this.executeCommand(command);
|
|
138
|
+
// console.log(result.stdout);
|
|
139
|
+
// if (result.stderr && result.stderr.trim() !== '')
|
|
140
|
+
// console.error(result.stderr);
|
|
120
141
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
catch (error) {
|
|
143
|
+
console.error('Error running "' + command + '":', error);
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.runShellCommand = runShellCommand;
|
|
148
|
+
/**
|
|
149
|
+
* function spawnCommand
|
|
150
|
+
* @param command
|
|
151
|
+
* @param args
|
|
152
|
+
* @returns
|
|
153
|
+
*/
|
|
154
|
+
function spawnCommand(command, args) {
|
|
155
|
+
console.log();
|
|
156
|
+
console.log([command, ...args, '...'].join(' '));
|
|
157
|
+
const child_process = (0, child_process_1.spawn)(command, args, { stdio: 'inherit' });
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
child_process.on('close', (code) => {
|
|
160
|
+
if (code === 0) {
|
|
161
|
+
console.log((0, kolorist_1.green)('*') + ' ' + [command, ...args].join(' '));
|
|
162
|
+
resolve();
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
reject(new Error([command, ...args].join(' ') + ' --> Error ' + code));
|
|
166
|
+
}
|
|
141
167
|
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
exports.spawnCommand = spawnCommand;
|
|
171
|
+
/**
|
|
172
|
+
* function readPackageJson
|
|
173
|
+
* @returns
|
|
174
|
+
*/
|
|
175
|
+
async function readPackageJson() {
|
|
176
|
+
try {
|
|
177
|
+
if (!fs.existsSync("package.json"))
|
|
178
|
+
throw 'package.json not found';
|
|
179
|
+
const fileContent = fs.readFileSync("package.json");
|
|
180
|
+
return JSON.parse(fileContent.toString());
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
console.error(err);
|
|
184
|
+
throw err;
|
|
142
185
|
}
|
|
143
186
|
}
|
|
144
|
-
exports.
|
|
187
|
+
exports.readPackageJson = readPackageJson;
|
package/build/DBClient.js
CHANGED