@cyklang/cli 0.5.4 → 0.5.6

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.
@@ -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>;
@@ -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 this.cleanDestination(dest);
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 this.uploadDirectory(source, dest, options);
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 this.uploadAsset({ path: source, mtime: filestat.mtime }, dest + base, options.auth);
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,221 @@ class AssetU extends Cmd_1.Cmd {
295
281
  logger.error(err);
296
282
  }
297
283
  }
298
- //----------------------------------------------------------------------------------------------
299
- // cleanDestination
300
- //----------------------------------------------------------------------------------------------
301
- async cleanDestination(dest) {
302
- const remoteList = await scanAssets(this.dbManager);
303
- for (let ind = 0; ind < remoteList.length; ind++) {
304
- const fd = remoteList[ind];
305
- if (fd.path.startsWith(dest)) {
306
- const url = '/api/admin/assets/' + fd.id;
307
- await this.dbRemote?.apiServer.delete(url);
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
- // uploadDirectory
313
- //----------------------------------------------------------------------------------------------
314
- async uploadDirectory(source, dest, options) {
315
- const localList = [];
316
- let dirName;
317
- if (source.substring(source.length - 1) === '/') {
318
- // trailing directory separator
319
- dirName = source;
320
- }
321
- else {
322
- dirName = source + '/';
323
- }
324
- // logger.debug('options', options)
325
- this.scanDir(dirName, localList);
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
- // buildUploadList
352
- //----------------------------------------------------------------------------------------------
353
- buildUploadList(dirName, dest, localList, remoteList) {
354
- const result = [];
355
- const remoteMap = new Map();
356
- for (let ind = 0; ind < remoteList.length; ind++) {
357
- const remote = remoteList[ind];
358
- remoteMap.set(remote.path, remote);
359
- }
360
- for (let ind = 0; ind < localList.length; ind++) {
361
- const localDesc = localList[ind];
362
- const route = dest + localDesc.path.substring(dirName.length);
363
- const remoteDesc = remoteMap.get(route);
364
- if (remoteDesc === undefined || remoteDesc.mtime.getTime() + 1000 < localDesc.mtime.getTime()) {
365
- if (remoteDesc === undefined)
366
- logger.debug('remoteDesc undefined');
367
- else
368
- logger.debug('remoteDesc.mtime ' + remoteDesc.mtime.getTime(), 'localDesc.mtime ' + localDesc.mtime.getTime());
369
- logger.info(localDesc.path);
370
- result.push(localDesc);
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) logger.debug('remoteDesc undefined')
358
+ // else logger.debug('remoteDesc.mtime ' + remoteDesc.mtime.getTime(), 'localDesc.mtime ' + localDesc.mtime.getTime())
359
+ // logger.info(localDesc.path)
360
+ result.push(localDesc);
372
361
  }
373
- return result;
374
362
  }
375
- //----------------------------------------------------------------------------------------------
376
- // scanDir
377
- //----------------------------------------------------------------------------------------------
378
- scanDir(dirName, result) {
379
- const files = fs.readdirSync(dirName);
380
- for (let ind = 0; ind < files.length; ind++) {
381
- const fileName = files[ind];
382
- if (this.file2exclude(fileName) === true)
363
+ return result;
364
+ }
365
+ /**
366
+ * function scanDir
367
+ * @param dirName
368
+ * @param result
369
+ */
370
+ function scanDir(dirName, result) {
371
+ const files = fs.readdirSync(dirName);
372
+ for (let ind = 0; ind < files.length; ind++) {
373
+ const fileName = files[ind];
374
+ if (file2exclude(fileName) === true)
375
+ continue;
376
+ const fstat = fs.statSync(dirName + fileName);
377
+ if (fstat.isDirectory() === true) {
378
+ scanDir(dirName + fileName + '/', result);
379
+ }
380
+ else {
381
+ if (mimetypeLookup(fileName) === false) {
382
+ logger.info(fileName + ' file extension is unknown and will not be uploaded');
383
383
  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
384
  }
385
+ //const dbAssetExist = this.dbManager?.dbAssetExist()
386
+ result.push({ path: dirName + fileName, mtime: fstat.mtime });
387
+ // logger.debug(dirName + '/' + fileName)
397
388
  }
398
389
  }
399
- file2exclude(fileName) {
400
- let result = false;
401
- this.ignorePatterns.forEach((pattern) => {
402
- if (fileName === pattern)
403
- result = true;
404
- });
405
- return result;
390
+ }
391
+ const ignorePatterns = ['.git', 'node_modules'];
392
+ /**
393
+ * function file2exclude
394
+ * @param fileName
395
+ * @returns
396
+ */
397
+ function file2exclude(fileName) {
398
+ let result = false;
399
+ ignorePatterns.forEach((pattern) => {
400
+ if (fileName === pattern)
401
+ result = true;
402
+ });
403
+ return result;
404
+ }
405
+ /**
406
+ * function uploadFiles
407
+ * @param dirName
408
+ * @param uploadList
409
+ * @param dest
410
+ * @param dbManager
411
+ * @param dbRemote
412
+ * @param auth
413
+ */
414
+ async function uploadFiles(dirName, uploadList, dest, dbManager, dbRemote, auth) {
415
+ for (let ind = 0; ind < uploadList.length; ind++) {
416
+ const upload = uploadList[ind];
417
+ const route = dest + upload.path.substring(dirName.length);
418
+ // logger.debug('upload ' + upload.path + ' to ' + route)
419
+ await uploadAsset(upload, route, dbManager, dbRemote, auth);
406
420
  }
407
- //----------------------------------------------------------------------------------------------
408
- // uploadFiles
409
- //----------------------------------------------------------------------------------------------
410
- async uploadFiles(dirName, uploadList, dest, auth) {
411
- for (let ind = 0; ind < uploadList.length; ind++) {
412
- const upload = uploadList[ind];
413
- const route = dest + upload.path.substring(dirName.length);
414
- logger.debug('upload ' + upload.path + ' to ' + route);
415
- await this.uploadAsset(upload, route, auth);
421
+ }
422
+ /**
423
+ * function uploadAsset
424
+ * @param upload
425
+ * @param route
426
+ * @param dbManager
427
+ * @param dbRemote
428
+ * @param auth
429
+ */
430
+ async function uploadAsset(upload, route, dbManager, dbRemote, auth) {
431
+ // logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth)
432
+ try {
433
+ let dbAsset = await dbManager?.dbAssetExist(route);
434
+ if (dbAsset === undefined) {
435
+ dbAsset = new core_1.DBAsset();
416
436
  }
417
- }
418
- //----------------------------------------------------------------------------------------------
419
- // uploadAsset
420
- //----------------------------------------------------------------------------------------------
421
- async uploadAsset(upload, route, auth) {
422
- // logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth)
423
- try {
424
- let dbAsset = await this.dbManager?.dbAssetExist(route);
425
- if (dbAsset === undefined) {
426
- dbAsset = new core_1.DBAsset();
427
- }
428
- const mimetype = this.mimetypeLookup(upload.path);
429
- if (mimetype === false)
430
- throw 'mimetype false for ' + upload;
431
- dbAsset.mimetype = mimetype;
432
- dbAsset.route = 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);
437
+ const mimetype = mimetypeLookup(upload.path);
438
+ if (mimetype === false)
439
+ throw 'mimetype false for ' + upload;
440
+ dbAsset.mimetype = mimetype;
441
+ dbAsset.route = route;
442
+ dbAsset.auth = auth;
443
+ if (dbAsset.auth === 'none')
444
+ dbAsset.auth = undefined;
445
+ // const fstat = fs.statSync(fileName)
446
+ dbAsset.last_update = upload.mtime;
447
+ // const contentBuffer = fs.readFileSync(fileName)
448
+ // dbAsset.content = contentBuffer
449
+ // logger.debug('dbAsset.content length ' + dbAsset.content.length)
450
+ if (dbAsset.id === undefined) {
451
+ dbAsset.id = await dbManager?.dbAssetInsert(dbAsset);
452
+ logger.info('inserted asset ' + dbAsset.route);
450
453
  }
451
- catch (err) {
452
- logger.error(err);
454
+ else {
455
+ await dbManager?.dbAssetUpdate(dbAsset);
456
+ logger.info('updated asset ' + dbAsset.route);
453
457
  }
458
+ await uploadAssetContent(dbAsset, upload.path, dbRemote);
454
459
  }
455
- //----------------------------------------------------------------------------------------------
456
- // uploadAssetContent
457
- //----------------------------------------------------------------------------------------------
458
- async uploadAssetContent(dbAsset, fileName) {
459
- logger.debug('uploadAssetContent file ' + fileName + ' to path ' + path_1.default);
460
- try {
461
- const file = fs.createReadStream(fileName);
462
- const form = new form_data_1.default();
463
- form.append('uploadFile', file);
464
- const route = '/api/upload/cyk_asset/asset_content?asset_id=' + dbAsset.id;
465
- const resp = await this.dbRemote?.apiServer.post(route, form);
466
- if (resp.status === 200) {
467
- logger.info(fileName + ' uploaded');
468
- }
469
- }
470
- catch (err) {
471
- logger.error(err);
460
+ catch (err) {
461
+ logger.error(err);
462
+ }
463
+ }
464
+ exports.uploadAsset = uploadAsset;
465
+ /**
466
+ * function mimetypeLookup
467
+ * @param filename
468
+ * @returns
469
+ */
470
+ function mimetypeLookup(filename) {
471
+ let result;
472
+ if (path_1.default.extname(filename) === '.cyk') {
473
+ result = 'application/xml';
474
+ }
475
+ else {
476
+ result = mime_types_1.default.lookup(filename);
477
+ }
478
+ return result;
479
+ }
480
+ /**
481
+ * function uploadAssetContent
482
+ * @param dbAsset
483
+ * @param fileName
484
+ * @param dbRemote
485
+ */
486
+ async function uploadAssetContent(dbAsset, fileName, dbRemote) {
487
+ // logger.debug('uploadAssetContent file ' + fileName + ' to path ' + path)
488
+ try {
489
+ const file = fs.createReadStream(fileName);
490
+ const form = new form_data_1.default();
491
+ form.append('uploadFile', file);
492
+ const route = '/api/upload/cyk_asset/asset_content?asset_id=' + dbAsset.id;
493
+ const resp = await dbRemote?.apiServer.post(route, form);
494
+ if (resp.status === 200) {
495
+ logger.info(fileName + ' uploaded');
472
496
  }
473
497
  }
498
+ catch (err) {
499
+ logger.error(err);
500
+ }
474
501
  }
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
- * method runShellCommand
105
- * @param command
106
- */
107
- async runShellCommand(command, args) {
108
- try {
109
- await this.spawnCommand(command, args);
110
- // console.log(command)
111
- // const result = await this.executeCommand(command);
112
- // console.log(result.stdout);
113
- // if (result.stderr && result.stderr.trim() !== '')
114
- // console.error(result.stderr);
115
- }
116
- catch (error) {
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
- * @param command
124
- * @param args
125
- * @returns
126
- */
127
- spawnCommand(command, args) {
128
- console.log();
129
- console.log([command, ...args, '...'].join(' '));
130
- const child_process = (0, child_process_1.spawn)(command, args, { stdio: 'inherit' });
131
- return new Promise((resolve, reject) => {
132
- child_process.on('close', (code) => {
133
- if (code === 0) {
134
- console.log((0, kolorist_1.green)('*') + ' ' + [command, ...args].join(' '));
135
- resolve();
136
- }
137
- else {
138
- reject(new Error([command, ...args].join(' ') + ' --> Error ' + code));
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.Cmd = Cmd;
187
+ exports.readPackageJson = readPackageJson;
package/build/DBClient.js CHANGED
@@ -123,6 +123,7 @@ class DBClient {
123
123
  throw ('Module ' + dbname + ' not found');
124
124
  }
125
125
  await this.dbManager.dbModuleDelete(dbModule);
126
+ logger.info('module ' + dbname + ' (id ' + dbModule.id + ' deleted)');
126
127
  }
127
128
  catch (err) {
128
129
  logger.error(err);