@cyklang/cli 0.5.5 → 0.6.0

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.
@@ -354,11 +354,9 @@ function buildUploadList(dirName, dest, localList, remoteList) {
354
354
  const route = dest + localDesc.path.substring(dirName.length);
355
355
  const remoteDesc = remoteMap.get(route);
356
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);
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)
362
360
  result.push(localDesc);
363
361
  }
364
362
  }
@@ -417,7 +415,7 @@ async function uploadFiles(dirName, uploadList, dest, dbManager, dbRemote, auth)
417
415
  for (let ind = 0; ind < uploadList.length; ind++) {
418
416
  const upload = uploadList[ind];
419
417
  const route = dest + upload.path.substring(dirName.length);
420
- logger.debug('upload ' + upload.path + ' to ' + route);
418
+ // logger.debug('upload ' + upload.path + ' to ' + route)
421
419
  await uploadAsset(upload, route, dbManager, dbRemote, auth);
422
420
  }
423
421
  }
@@ -451,7 +449,7 @@ async function uploadAsset(upload, route, dbManager, dbRemote, auth) {
451
449
  // logger.debug('dbAsset.content length ' + dbAsset.content.length)
452
450
  if (dbAsset.id === undefined) {
453
451
  dbAsset.id = await dbManager?.dbAssetInsert(dbAsset);
454
- logger.info('inserted asset ' + dbAsset.id + ' route ' + dbAsset.route);
452
+ logger.info('inserted asset ' + dbAsset.route);
455
453
  }
456
454
  else {
457
455
  await dbManager?.dbAssetUpdate(dbAsset);
@@ -486,7 +484,7 @@ function mimetypeLookup(filename) {
486
484
  * @param dbRemote
487
485
  */
488
486
  async function uploadAssetContent(dbAsset, fileName, dbRemote) {
489
- logger.debug('uploadAssetContent file ' + fileName + ' to path ' + path_1.default);
487
+ // logger.debug('uploadAssetContent file ' + fileName + ' to path ' + path)
490
488
  try {
491
489
  const file = fs.createReadStream(fileName);
492
490
  const form = new form_data_1.default();
@@ -72,7 +72,7 @@ async function installPackage(node_package, dbManager, dbRemote) {
72
72
  /**
73
73
  * install the Node Package
74
74
  */
75
- await installNodePackage(node_package, dbManager);
75
+ await installNodePackage(node_package, dbManager, dbRemote);
76
76
  const installScript = await lookupInstallScript(node_package);
77
77
  if (installScript) {
78
78
  /**
@@ -117,8 +117,6 @@ async function uploadPackageAssets(node_package, dbManager, dbRemote) {
117
117
  }
118
118
  console.log();
119
119
  console.log('upload assets to server ...');
120
- if (!dbManager)
121
- throw 'dbManager undefined';
122
120
  const items = fs.readdirSync(assetFolder);
123
121
  for (let ind = 0; ind < items.length; ind++) {
124
122
  const item = items[ind];
@@ -168,7 +166,7 @@ async function uploadPackageModules(node_package, dbManager) {
168
166
  * method installNodePackage
169
167
  * @param node_package
170
168
  */
171
- async function installNodePackage(node_package, dbManager) {
169
+ async function installNodePackage(node_package, dbManager, dbRemote) {
172
170
  try {
173
171
  const packageJson = await (0, Cmd_1.readPackageJson)();
174
172
  if (packageJson.devDependencies && packageJson.devDependencies[node_package]
@@ -176,7 +174,7 @@ async function installNodePackage(node_package, dbManager) {
176
174
  console.log(node_package + ' already installed. We uninstall it first');
177
175
  if (!dbManager)
178
176
  throw 'dbManager undefined';
179
- await (0, UninstallCommand_1.uninstallPackage)(node_package, dbManager);
177
+ await (0, UninstallCommand_1.uninstallPackage)(node_package, dbManager, dbRemote);
180
178
  }
181
179
  await (0, Cmd_1.runShellCommand)('npm', ['install', '--save-dev', node_package]);
182
180
  }
@@ -1,5 +1,14 @@
1
1
  #!/usr/bin/env ts-node
2
+ import { DBManager } from "@cyklang/core";
3
+ import loglevel from 'loglevel';
2
4
  import { Command } from "commander";
5
+ export declare const logger: loglevel.Logger;
3
6
  export declare class TableCommand extends Command {
4
7
  constructor(name: string);
5
8
  }
9
+ /**
10
+ * function dropTable
11
+ * @param table
12
+ * @param dbManager
13
+ */
14
+ export declare function dropTable(table: string, dbManager: DBManager): Promise<void>;
@@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  return (mod && mod.__esModule) ? mod : { "default": mod };
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.TableCommand = void 0;
30
+ exports.dropTable = exports.TableCommand = exports.logger = void 0;
31
31
  const fs = __importStar(require("fs"));
32
32
  const loglevel_1 = __importDefault(require("loglevel"));
33
33
  const commander_1 = require("commander");
@@ -35,8 +35,9 @@ const child_process_1 = require("child_process");
35
35
  const Cmd_1 = require("./Cmd");
36
36
  const DBClient_1 = require("./DBClient");
37
37
  const form_data_1 = __importDefault(require("form-data"));
38
- const logger = loglevel_1.default.getLogger("TableCommand.ts");
39
- logger.setLevel("debug");
38
+ const inquirer_1 = __importDefault(require("inquirer"));
39
+ exports.logger = loglevel_1.default.getLogger("TableCommand.ts");
40
+ exports.logger.setLevel("debug");
40
41
  class TableCommand extends commander_1.Command {
41
42
  constructor(name) {
42
43
  super(name);
@@ -45,8 +46,7 @@ class TableCommand extends commander_1.Command {
45
46
  this.addCommand(new TableImportCmd());
46
47
  this.addCommand(new TableList('list', 'list database tables'));
47
48
  this.addCommand(new TableList('l', '(l)ist database tables'));
48
- this.addCommand(new TableData('data', 'table (d)ata'));
49
- this.addCommand(new TableData('d', 'table (d)ata'));
49
+ this.addCommand(new TableDropCommand('drop', 'drop table'));
50
50
  this.addCommand(new TableUpdate('update', 'update table properties'));
51
51
  this.addCommand(new TableUpdate('u', 'shortcut for (u)pdate table properties'));
52
52
  }
@@ -84,7 +84,7 @@ class TableUpdate extends Cmd_1.Cmd {
84
84
  await this.updateAuthAccess('cyk_table', 'table', dbTable.id || '', options);
85
85
  }
86
86
  catch (err) {
87
- logger.error(err);
87
+ exports.logger.error(err);
88
88
  }
89
89
  }
90
90
  }
@@ -115,7 +115,7 @@ class TableExportCmd extends Cmd_1.Cmd {
115
115
  const tableName = tables[indi];
116
116
  const dbTable = await this.dbManager.dbTableExist(tableName);
117
117
  if (dbTable === undefined) {
118
- logger.info('table ' + tableName + ' not found');
118
+ exports.logger.info('table ' + tableName + ' not found');
119
119
  continue;
120
120
  }
121
121
  const filename = buildFilename(dbTable.name, options);
@@ -123,7 +123,7 @@ class TableExportCmd extends Cmd_1.Cmd {
123
123
  }
124
124
  }
125
125
  catch (err) {
126
- logger.error(err);
126
+ exports.logger.error(err);
127
127
  }
128
128
  }
129
129
  async copyTo(dbTable, filename) {
@@ -134,15 +134,15 @@ class TableExportCmd extends Cmd_1.Cmd {
134
134
  const response = await this.dbRemote.apiServer.get('/admin/export/' + dbTable.name, { responseType: 'stream' });
135
135
  const stream = response;
136
136
  stream.on('data', (data) => {
137
- logger.debug('**** DATA ****', data.length);
137
+ exports.logger.debug('**** DATA ****', data.length);
138
138
  const textDecoder = new TextDecoder();
139
139
  const chunk = (textDecoder.decode(data));
140
140
  writeStream.write(chunk);
141
141
  });
142
- stream.on('end', () => logger.debug('**** DONE ****'));
142
+ stream.on('end', () => exports.logger.debug('**** DONE ****'));
143
143
  }
144
144
  catch (err) {
145
- logger.error(err);
145
+ exports.logger.error(err);
146
146
  }
147
147
  }
148
148
  }
@@ -173,7 +173,7 @@ class TableImportCmd extends Cmd_1.Cmd {
173
173
  const tableName = tables[indi];
174
174
  const dbTable = await this.dbManager.dbTableExist(tableName);
175
175
  if (dbTable === undefined) {
176
- logger.info('table ' + tableName + ' not found');
176
+ exports.logger.info('table ' + tableName + ' not found');
177
177
  continue;
178
178
  }
179
179
  const filename = buildFilename(dbTable.name, options);
@@ -181,7 +181,7 @@ class TableImportCmd extends Cmd_1.Cmd {
181
181
  }
182
182
  }
183
183
  catch (err) {
184
- logger.error(err);
184
+ exports.logger.error(err);
185
185
  }
186
186
  }
187
187
  async copyFrom(dbTable, filename) {
@@ -194,11 +194,11 @@ class TableImportCmd extends Cmd_1.Cmd {
194
194
  const route = '/admin/import/' + dbTable.name;
195
195
  const resp = await this.dbRemote.apiServer.post(route, form);
196
196
  if (resp.status === 200) {
197
- logger.debug(filename + ' uploaded');
197
+ exports.logger.debug(filename + ' uploaded');
198
198
  }
199
199
  }
200
200
  catch (err) {
201
- logger.error(err);
201
+ exports.logger.error(err);
202
202
  }
203
203
  }
204
204
  }
@@ -226,7 +226,7 @@ function buildFilename(tableName, options) {
226
226
  return filename;
227
227
  }
228
228
  const commandImportExport = async (dbManager, direction, tables, options) => {
229
- logger.debug('tables : ', tables, 'options : ', options);
229
+ exports.logger.debug('tables : ', tables, 'options : ', options);
230
230
  try {
231
231
  if (options.file === undefined && options.dir === undefined)
232
232
  throw '--file or --dir mandatory';
@@ -240,14 +240,14 @@ const commandImportExport = async (dbManager, direction, tables, options) => {
240
240
  const tableName = tables[indi];
241
241
  const dbTable = await dbManager.dbTableExist(tableName);
242
242
  if (dbTable === undefined) {
243
- logger.info('table ' + tableName + ' not found');
243
+ exports.logger.info('table ' + tableName + ' not found');
244
244
  continue;
245
245
  }
246
246
  psqlCmd(dbTable, direction, options);
247
247
  }
248
248
  }
249
249
  catch (err) {
250
- logger.error(err);
250
+ exports.logger.error(err);
251
251
  }
252
252
  };
253
253
  //--------------------------------------------------------------------------------------------------------------------
@@ -282,7 +282,7 @@ function psqlCmd(dbTable, direction, options) {
282
282
  else if (fs.existsSync(options.dir) === false)
283
283
  throw 'directory ' + options.dir + ' does not exist';
284
284
  else if (fs.lstatSync(options.dir).isFile()) {
285
- logger.debug("--dir " + options.dir + " is a file ");
285
+ exports.logger.debug("--dir " + options.dir + " is a file ");
286
286
  }
287
287
  else {
288
288
  let directory = options.dir.trim();
@@ -293,7 +293,7 @@ function psqlCmd(dbTable, direction, options) {
293
293
  }
294
294
  let copy_cmd = "\\copy " + dbTable.name + lcols + direction + " '" + filename + "' csv header";
295
295
  const shell_cmd = psql_cmd + '"' + copy_cmd + '"';
296
- logger.debug(shell_cmd);
296
+ exports.logger.debug(shell_cmd);
297
297
  const child = (0, child_process_1.spawn)(shell_cmd.trim(), { stdio: 'inherit', shell: true });
298
298
  }
299
299
  //--------------------------------------------------------------------------------------------------------------------
@@ -316,57 +316,43 @@ class TableList extends Cmd_1.Cmd {
316
316
  dbClient.selectFromTable('List of Tables', 'cyk_table', { fields: 'table_id,table_name,table_auth,table_access,table_description', sort: options.sort || '1' });
317
317
  }
318
318
  }
319
- //--------------------------------------------------------------------------------------------------------------------
320
- // class TableData
321
- //--------------------------------------------------------------------------------------------------------------------
322
- class TableData extends Cmd_1.Cmd {
319
+ class TableDropCommand extends Cmd_1.Cmd {
323
320
  constructor(name, description) {
324
321
  super(name);
325
322
  this.description(description)
326
323
  .argument('<table>', 'table name')
327
- .option('--where <clause_where_sql>', 'criteria in SQL syntax')
328
- .option('-s --sort <columns>', 'sort by columns positions (begins by 0) separated by comma')
329
- .option('-w --width <colwidth>', 'columns widths separated by comma')
330
324
  .action(async (table, options) => {
331
- this.commandData(table, options);
325
+ await this.commandDrop(table, options);
332
326
  });
333
327
  }
334
- async commandData(table, options) {
328
+ async commandDrop(table, options) {
335
329
  try {
336
330
  await this.prologue(options);
337
- if (this.dbManager === undefined)
331
+ if (!this.dbManager)
338
332
  throw 'dbManager undefined';
339
333
  const dbTable = await this.dbManager.dbTableExist(table);
340
- if (dbTable === undefined)
341
- throw 'table ' + table + ' not found';
342
- let fields = '';
343
- for (let ind = 0; ind < dbTable.columns.length; ind++) {
344
- const dbColumn = dbTable.columns[ind];
345
- let ok = false;
346
- let fieldName = dbColumn.name;
347
- if (dbColumn.dbType === 'text' || dbColumn.dbType === 'bytea') {
348
- ok = false;
349
- fieldName = 'length(' + dbColumn.name + ')';
350
- }
351
- else {
352
- ok = true;
353
- }
354
- if (ok === true) {
355
- if (fields !== '')
356
- fields += ',';
357
- fields += fieldName;
358
- }
334
+ if (!dbTable) {
335
+ console.log('table ' + table + ' does not exist');
336
+ return;
359
337
  }
360
- logger.debug('commandQuery', table);
361
- const dbClient = new DBClient_1.DBClient(this.dbManager);
362
- let title = 'Table ' + table;
363
- if (options.where !== undefined) {
364
- title += ' where ' + options.where;
338
+ const reply = await inquirer_1.default.prompt({ type: 'confirm', name: 'confirm', message: 'Drop table ' + table + '?' });
339
+ if (reply.confirm && this.dbManager) {
340
+ await dropTable(table, this.dbManager);
365
341
  }
366
- dbClient.selectFromTable(title, table, { fields: fields, width: options.width, sort: options.sort || '1', where: options.where });
367
342
  }
368
343
  catch (err) {
369
- logger.error(err);
344
+ exports.logger.error(err);
370
345
  }
371
346
  }
372
347
  }
348
+ /**
349
+ * function dropTable
350
+ * @param table
351
+ * @param dbManager
352
+ */
353
+ async function dropTable(table, dbManager) {
354
+ const dbTable = await dbManager.dbTableExist(table);
355
+ if (dbTable)
356
+ await dbManager.dbTableDelete(dbTable);
357
+ }
358
+ exports.dropTable = dropTable;
@@ -0,0 +1,5 @@
1
+ import { Cmd } from "./Cmd";
2
+ export declare class TableDataCommand extends Cmd {
3
+ constructor(name: string, description: string);
4
+ commandData(table: string, options: any): Promise<void>;
5
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TableDataCommand = void 0;
4
+ const Cmd_1 = require("./Cmd");
5
+ const DBClient_1 = require("./DBClient");
6
+ const TableCommand_1 = require("./TableCommand");
7
+ //--------------------------------------------------------------------------------------------------------------------
8
+ // class TableData
9
+ //--------------------------------------------------------------------------------------------------------------------
10
+ class TableDataCommand extends Cmd_1.Cmd {
11
+ constructor(name, description) {
12
+ super(name);
13
+ this.description(description)
14
+ .argument('<table>', 'table name')
15
+ .option('--where <clause_where_sql>', 'criteria in SQL syntax')
16
+ .option('-s --sort <columns>', 'sort by columns positions (begins by 0) separated by comma')
17
+ .option('-w --width <colwidth>', 'columns widths separated by comma')
18
+ .action(async (table, options) => {
19
+ this.commandData(table, options);
20
+ });
21
+ }
22
+ async commandData(table, options) {
23
+ try {
24
+ await this.prologue(options);
25
+ if (this.dbManager === undefined)
26
+ throw 'dbManager undefined';
27
+ const dbTable = await this.dbManager.dbTableExist(table);
28
+ if (dbTable === undefined)
29
+ throw 'table ' + table + ' not found';
30
+ let fields = '';
31
+ for (let ind = 0; ind < dbTable.columns.length; ind++) {
32
+ const dbColumn = dbTable.columns[ind];
33
+ let ok = false;
34
+ let fieldName = dbColumn.name;
35
+ if (dbColumn.dbType === 'text' || dbColumn.dbType === 'bytea') {
36
+ ok = false;
37
+ fieldName = 'length(' + dbColumn.name + ')';
38
+ }
39
+ else {
40
+ ok = true;
41
+ }
42
+ if (ok === true) {
43
+ if (fields !== '')
44
+ fields += ',';
45
+ fields += fieldName;
46
+ }
47
+ }
48
+ TableCommand_1.logger.debug('commandQuery', table);
49
+ const dbClient = new DBClient_1.DBClient(this.dbManager);
50
+ let title = 'Table ' + table;
51
+ if (options.where !== undefined) {
52
+ title += ' where ' + options.where;
53
+ }
54
+ dbClient.selectFromTable(title, table, { fields: fields, width: options.width, sort: options.sort || '1', where: options.where });
55
+ }
56
+ catch (err) {
57
+ TableCommand_1.logger.error(err);
58
+ }
59
+ }
60
+ }
61
+ exports.TableDataCommand = TableDataCommand;
@@ -0,0 +1,5 @@
1
+ import { Cmd } from "./Cmd";
2
+ export declare class TableDataCommand extends Cmd {
3
+ constructor(name: string, description: string);
4
+ commandData(table: string, options: any): Promise<void>;
5
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TableDataCommand = void 0;
4
+ const Cmd_1 = require("./Cmd");
5
+ const DBClient_1 = require("./DBClient");
6
+ const TableCommand_1 = require("./TableCommand");
7
+ //--------------------------------------------------------------------------------------------------------------------
8
+ // class TableData
9
+ //--------------------------------------------------------------------------------------------------------------------
10
+ class TableDataCommand extends Cmd_1.Cmd {
11
+ constructor(name, description) {
12
+ super(name);
13
+ this.description(description)
14
+ .argument('<table>', 'table name')
15
+ .option('--where <clause_where_sql>', 'criteria in SQL syntax')
16
+ .option('-s --sort <columns>', 'sort by columns positions (begins by 0) separated by comma')
17
+ .option('-w --width <colwidth>', 'columns widths separated by comma')
18
+ .action(async (table, options) => {
19
+ this.commandData(table, options);
20
+ });
21
+ }
22
+ async commandData(table, options) {
23
+ try {
24
+ await this.prologue(options);
25
+ if (this.dbManager === undefined)
26
+ throw 'dbManager undefined';
27
+ const dbTable = await this.dbManager.dbTableExist(table);
28
+ if (dbTable === undefined)
29
+ throw 'table ' + table + ' not found';
30
+ let fields = '';
31
+ for (let ind = 0; ind < dbTable.columns.length; ind++) {
32
+ const dbColumn = dbTable.columns[ind];
33
+ let ok = false;
34
+ let fieldName = dbColumn.name;
35
+ if (dbColumn.dbType === 'text' || dbColumn.dbType === 'bytea') {
36
+ ok = false;
37
+ fieldName = 'length(' + dbColumn.name + ')';
38
+ }
39
+ else {
40
+ ok = true;
41
+ }
42
+ if (ok === true) {
43
+ if (fields !== '')
44
+ fields += ',';
45
+ fields += fieldName;
46
+ }
47
+ }
48
+ TableCommand_1.logger.debug('commandQuery', table);
49
+ const dbClient = new DBClient_1.DBClient(this.dbManager);
50
+ let title = 'Table ' + table;
51
+ if (options.where !== undefined) {
52
+ title += ' where ' + options.where;
53
+ }
54
+ dbClient.selectFromTable(title, table, { fields: fields, width: options.width, sort: options.sort || '1', where: options.where });
55
+ }
56
+ catch (err) {
57
+ TableCommand_1.logger.error(err);
58
+ }
59
+ }
60
+ }
61
+ exports.TableDataCommand = TableDataCommand;
@@ -1,5 +1,5 @@
1
1
  import { Cmd } from "./Cmd";
2
- import { DBManager } from "@cyklang/core";
2
+ import { DBManager, DBRemote } from "@cyklang/core";
3
3
  export declare class UninstallCommand extends Cmd {
4
4
  /**
5
5
  * constructor
@@ -17,4 +17,4 @@ export declare class UninstallCommand extends Cmd {
17
17
  * function uninstallPackage
18
18
  * @param node_package
19
19
  */
20
- export declare function uninstallPackage(node_package: string, dbManager: DBManager): Promise<void>;
20
+ export declare function uninstallPackage(node_package: string, dbManager: DBManager, dbRemote: DBRemote): Promise<void>;
@@ -56,9 +56,9 @@ class UninstallCommand extends Cmd_1.Cmd {
56
56
  async uninstall(node_package, options) {
57
57
  try {
58
58
  await this.prologue(options);
59
- if (this.dbManager === undefined)
60
- throw 'dbManager undefined';
61
- await uninstallPackage(node_package, this.dbManager);
59
+ if (!this.dbManager || !this.dbRemote)
60
+ throw 'dbManager or dbRemote undefined';
61
+ await uninstallPackage(node_package, this.dbManager, this.dbRemote);
62
62
  }
63
63
  catch (err) {
64
64
  logger.error(err);
@@ -70,7 +70,7 @@ exports.UninstallCommand = UninstallCommand;
70
70
  * function uninstallPackage
71
71
  * @param node_package
72
72
  */
73
- async function uninstallPackage(node_package, dbManager) {
73
+ async function uninstallPackage(node_package, dbManager, dbRemote) {
74
74
  const uninstallScript = await lookupUninstallScript(node_package);
75
75
  if (uninstallScript) {
76
76
  /**
@@ -83,7 +83,7 @@ async function uninstallPackage(node_package, dbManager) {
83
83
  /**
84
84
  * default uninstall :
85
85
  */
86
- await defaultUninstallScript(node_package, dbManager);
86
+ await defaultUninstallScript(node_package, dbManager, dbRemote);
87
87
  }
88
88
  /**
89
89
  * uninstall the node package
@@ -95,13 +95,60 @@ exports.uninstallPackage = uninstallPackage;
95
95
  * method defaultUninstallScript
96
96
  * @param node_package
97
97
  */
98
- async function defaultUninstallScript(node_package, dbManager) {
98
+ async function defaultUninstallScript(node_package, dbManager, dbRemote) {
99
99
  console.log();
100
100
  console.log('Default uninstall script');
101
101
  /**
102
102
  * delete package modules from server
103
103
  */
104
104
  await deletePackageModules(node_package, dbManager);
105
+ /**
106
+ * delete package assets from server
107
+ */
108
+ await deletePackageAssets(node_package, dbManager, dbRemote);
109
+ }
110
+ /**
111
+ * function deletePackageAssets
112
+ * @param node_package
113
+ * @param dbManager
114
+ * @param dbRemote
115
+ */
116
+ async function deletePackageAssets(node_package, dbManager, dbRemote) {
117
+ const assetFolder = path.join('node_modules', node_package, 'asset');
118
+ if (!fs.existsSync(assetFolder) || !fs.statSync(assetFolder).isDirectory()) {
119
+ return;
120
+ }
121
+ console.log();
122
+ console.log('delete assets from server ...');
123
+ await browseFolder(assetFolder, async (filePath) => {
124
+ const route = '/' + path.relative(assetFolder, filePath);
125
+ const dbAsset = await dbManager.dbAssetExist(route);
126
+ if (!dbAsset) {
127
+ logger.info('asset ' + route + ' not found');
128
+ return;
129
+ }
130
+ await dbManager.dbAssetDelete(dbAsset);
131
+ logger.info('asset ' + route + ' deleted');
132
+ });
133
+ console.log((0, kolorist_1.green)('*') + ' delete assets from server');
134
+ }
135
+ /**
136
+ * browseFolder
137
+ * @param folder
138
+ * @param treatment
139
+ */
140
+ async function browseFolder(folder, treatment) {
141
+ const files = fs.readdirSync(folder);
142
+ for (let ind = 0; ind < files.length; ind++) {
143
+ const file = files[ind];
144
+ const pathName = folder + '/' + file;
145
+ if (fs.statSync(pathName).isDirectory()) {
146
+ await browseFolder(pathName, treatment);
147
+ }
148
+ else {
149
+ await treatment(pathName);
150
+ }
151
+ }
105
152
  }
106
153
  /**
107
154
  * function deletePackageModules
package/build/index.js CHANGED
@@ -16,11 +16,12 @@ const InstallCommand_1 = require("./InstallCommand");
16
16
  const AssetCommand_1 = require("./AssetCommand");
17
17
  const OpenCommand_1 = require("./OpenCommand");
18
18
  const UninstallCommand_1 = require("./UninstallCommand");
19
+ const TableDataCommand_1 = require("./TableDataCommand");
19
20
  const logger = loglevel_1.default.getLogger("index.ts");
20
21
  logger.setLevel("debug");
21
22
  const program = new commander_1.Command();
22
23
  program.name('cyk').description('cyklang CLI')
23
- .version('0.5.5');
24
+ .version('0.6.0');
24
25
  program.addCommand(new InstallCommand_1.InstallCommand('install'));
25
26
  program.addCommand(new InstallCommand_1.InstallCommand('i'));
26
27
  program.addCommand(new UninstallCommand_1.UninstallCommand('uninstall'));
@@ -34,6 +35,8 @@ program.addCommand(new QueryCommand_1.QueryCommand('query'));
34
35
  program.addCommand(new QueryCommand_1.QueryCommand('q'));
35
36
  program.addCommand(new TableCommand_1.TableCommand('table'));
36
37
  program.addCommand(new TableCommand_1.TableCommand('t'));
38
+ program.addCommand(new TableDataCommand_1.TableDataCommand('data', 'show table data'));
39
+ program.addCommand(new TableDataCommand_1.TableDataCommand('d', 'show table data'));
37
40
  program.addCommand(new TestCommand_1.TestCommand());
38
41
  program.addCommand(new RunCommand_1.RunCommand('run'));
39
42
  program.addCommand(new RunCommand_1.RunCommand('r'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyklang/cli",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
4
4
  "description": "cyklang CLI",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "author": "",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "@cyklang/core": "^0.5.3",
20
+ "@cyklang/core": "^0.5.4",
21
21
  "commander": "^9.4.0",
22
22
  "dotenv": "^16.0.1",
23
23
  "form-data": "^4.0.0",
@@ -366,9 +366,9 @@ function buildUploadList(dirName: string, dest: string, localList: FileDescripto
366
366
  const remoteDesc = remoteMap.get(route)
367
367
 
368
368
  if (remoteDesc === undefined || remoteDesc.mtime.getTime() + 1000 < localDesc.mtime.getTime()) {
369
- if (remoteDesc === undefined) logger.debug('remoteDesc undefined')
370
- else logger.debug('remoteDesc.mtime ' + remoteDesc.mtime.getTime(), 'localDesc.mtime ' + localDesc.mtime.getTime())
371
- logger.info(localDesc.path)
369
+ // if (remoteDesc === undefined) logger.debug('remoteDesc undefined')
370
+ // else logger.debug('remoteDesc.mtime ' + remoteDesc.mtime.getTime(), 'localDesc.mtime ' + localDesc.mtime.getTime())
371
+ // logger.info(localDesc.path)
372
372
  result.push(localDesc)
373
373
  }
374
374
  }
@@ -426,7 +426,7 @@ async function uploadFiles(dirName: string, uploadList: FileDescriptor[], dest:
426
426
  for (let ind = 0; ind < uploadList.length; ind++) {
427
427
  const upload = uploadList[ind]
428
428
  const route = dest + upload.path.substring(dirName.length)
429
- logger.debug('upload ' + upload.path + ' to ' + route)
429
+ // logger.debug('upload ' + upload.path + ' to ' + route)
430
430
  await uploadAsset(upload, route, dbManager, dbRemote, auth)
431
431
  }
432
432
  }
@@ -463,7 +463,7 @@ export async function uploadAsset(upload: FileDescriptor, route: string, dbManag
463
463
 
464
464
  if (dbAsset.id === undefined) {
465
465
  dbAsset.id = await dbManager?.dbAssetInsert(dbAsset)
466
- logger.info('inserted asset ' + dbAsset.id + ' route ' + dbAsset.route)
466
+ logger.info('inserted asset ' + dbAsset.route)
467
467
  }
468
468
  else {
469
469
  await dbManager?.dbAssetUpdate(dbAsset)
@@ -500,7 +500,7 @@ function mimetypeLookup(filename: string): string | false {
500
500
  * @param dbRemote
501
501
  */
502
502
  async function uploadAssetContent(dbAsset: DBAsset, fileName: string, dbRemote: DBRemote | undefined) {
503
- logger.debug('uploadAssetContent file ' + fileName + ' to path ' + path)
503
+ // logger.debug('uploadAssetContent file ' + fileName + ' to path ' + path)
504
504
  try {
505
505
  const file = fs.createReadStream(fileName)
506
506
  const form = new FormData()
@@ -48,7 +48,7 @@ export async function installPackage(node_package: string, dbManager: DBManager,
48
48
  /**
49
49
  * install the Node Package
50
50
  */
51
- await installNodePackage(node_package, dbManager)
51
+ await installNodePackage(node_package, dbManager, dbRemote)
52
52
 
53
53
  const installScript = await lookupInstallScript(node_package)
54
54
 
@@ -100,7 +100,6 @@ async function uploadPackageAssets(node_package: string, dbManager: DBManager, d
100
100
  console.log()
101
101
  console.log('upload assets to server ...')
102
102
 
103
- if (!dbManager) throw 'dbManager undefined'
104
103
  const items = fs.readdirSync(assetFolder)
105
104
  for (let ind = 0; ind < items.length; ind++) {
106
105
  const item = items[ind]
@@ -153,7 +152,7 @@ async function uploadPackageModules(node_package: string, dbManager: DBManager)
153
152
  * method installNodePackage
154
153
  * @param node_package
155
154
  */
156
- async function installNodePackage(node_package: string, dbManager: DBManager) {
155
+ async function installNodePackage(node_package: string, dbManager: DBManager, dbRemote: DBRemote) {
157
156
 
158
157
  try {
159
158
  const packageJson = await readPackageJson()
@@ -161,7 +160,7 @@ async function installNodePackage(node_package: string, dbManager: DBManager) {
161
160
  || packageJson.dependencies && packageJson.dependencies[node_package]) {
162
161
  console.log(node_package + ' already installed. We uninstall it first')
163
162
  if (!dbManager) throw 'dbManager undefined'
164
- await uninstallPackage(node_package, dbManager)
163
+ await uninstallPackage(node_package, dbManager, dbRemote)
165
164
  }
166
165
 
167
166
  await runShellCommand('npm', ['install', '--save-dev', node_package])
@@ -8,8 +8,10 @@ import { Cmd } from "./Cmd"
8
8
  import { DBClient } from "./DBClient"
9
9
  import { Stream } from "form-data"
10
10
  import FormData from 'form-data'
11
+ import inquirer from 'inquirer'
12
+ import { TableDataCommand } from "./TableDataCommand"
11
13
 
12
- const logger = loglevel.getLogger("TableCommand.ts")
14
+ export const logger = loglevel.getLogger("TableCommand.ts")
13
15
  logger.setLevel("debug")
14
16
 
15
17
  export class TableCommand extends Command {
@@ -20,8 +22,7 @@ export class TableCommand extends Command {
20
22
  this.addCommand(new TableImportCmd())
21
23
  this.addCommand(new TableList('list', 'list database tables'))
22
24
  this.addCommand(new TableList('l', '(l)ist database tables'))
23
- this.addCommand(new TableData('data', 'table (d)ata'))
24
- this.addCommand(new TableData('d', 'table (d)ata'))
25
+ this.addCommand(new TableDropCommand('drop', 'drop table'))
25
26
  this.addCommand(new TableUpdate('update', 'update table properties'))
26
27
  this.addCommand(new TableUpdate('u', 'shortcut for (u)pdate table properties'))
27
28
  }
@@ -40,12 +41,12 @@ class TableUpdate extends Cmd {
40
41
  constructor(name: string, description: string) {
41
42
  super(name)
42
43
  this.description(description)
43
- .option('-n --name <table_name>', 'name of the table whose properties are to be changed')
44
- .option('--auth <auth_schema>', 'authentication schema : basic | token | cookie | any | none, default is none')
45
- .option('--access <access>', 'access rights required')
46
- .action(async (options: any) => {
47
- await this.commandUpdate(options)
48
- })
44
+ .option('-n --name <table_name>', 'name of the table whose properties are to be changed')
45
+ .option('--auth <auth_schema>', 'authentication schema : basic | token | cookie | any | none, default is none')
46
+ .option('--access <access>', 'access rights required')
47
+ .action(async (options: any) => {
48
+ await this.commandUpdate(options)
49
+ })
49
50
  }
50
51
 
51
52
  async commandUpdate(options: any) {
@@ -53,10 +54,10 @@ class TableUpdate extends Cmd {
53
54
  await this.prologue(options)
54
55
  if (this.dbManager === undefined) throw 'dbManager undefined'
55
56
 
56
- if ( ! options.name ) throw '<table_name> is missing'
57
+ if (!options.name) throw '<table_name> is missing'
57
58
 
58
59
  const dbTable = await this.dbManager.dbTableExist(options.name)
59
- if ( ! dbTable ) throw 'Table ' + options.name + ' not found'
60
+ if (!dbTable) throw 'Table ' + options.name + ' not found'
60
61
 
61
62
  await this.updateAuthAccess('cyk_table', 'table', dbTable.id || '', options)
62
63
  }
@@ -319,63 +320,46 @@ class TableList extends Cmd {
319
320
  }
320
321
  }
321
322
 
322
- //--------------------------------------------------------------------------------------------------------------------
323
- // class TableData
324
- //--------------------------------------------------------------------------------------------------------------------
325
-
326
- class TableData extends Cmd {
327
-
323
+ class TableDropCommand extends Cmd {
328
324
  constructor(name: string, description: string) {
329
325
  super(name)
330
326
  this.description(description)
331
327
  .argument('<table>', 'table name')
332
- .option('--where <clause_where_sql>', 'criteria in SQL syntax')
333
- .option('-s --sort <columns>', 'sort by columns positions (begins by 0) separated by comma')
334
- .option('-w --width <colwidth>', 'columns widths separated by comma')
335
328
  .action(async (table, options) => {
336
- this.commandData(table, options)
329
+ await this.commandDrop(table, options)
337
330
  })
338
331
  }
339
332
 
340
- async commandData(table: string, options: any) {
333
+ async commandDrop(table: string, options: any) {
341
334
  try {
342
335
  await this.prologue(options)
343
- if (this.dbManager === undefined) throw 'dbManager undefined'
344
-
336
+ if (!this.dbManager) throw 'dbManager undefined'
337
+
345
338
  const dbTable = await this.dbManager.dbTableExist(table)
346
- if (dbTable === undefined) throw 'table ' + table + ' not found'
347
-
348
- let fields = ''
349
-
350
- for (let ind = 0; ind < dbTable.columns.length; ind++) {
351
- const dbColumn = dbTable.columns[ind]
352
- let ok = false
353
- let fieldName = dbColumn.name
354
- if (dbColumn.dbType === 'text' || dbColumn.dbType === 'bytea') {
355
- ok = false
356
- fieldName = 'length(' + dbColumn.name + ')'
357
- }
358
- else {
359
- ok = true
360
- }
361
- if (ok === true) {
362
- if (fields !== '') fields += ','
363
- fields += fieldName
364
- }
339
+ if (!dbTable) {
340
+ console.log('table ' + table + ' does not exist')
341
+ return
365
342
  }
366
-
367
- logger.debug('commandQuery', table)
368
- const dbClient = new DBClient(this.dbManager)
369
- let title = 'Table ' + table
370
- if (options.where !== undefined) {
371
- title += ' where ' + options.where
343
+ const reply = await inquirer.prompt({ type: 'confirm', name: 'confirm', message: 'Drop table ' + table + '?' })
344
+ if (reply.confirm && this.dbManager) {
345
+ await dropTable(table, this.dbManager)
372
346
  }
373
- dbClient.selectFromTable(title, table,
374
- { fields: fields, width: options.width, sort: options.sort || '1', where: options.where })
375
347
  }
376
- catch (err) {
348
+ catch(err) {
377
349
  logger.error(err)
378
350
  }
379
351
  }
380
352
  }
381
353
 
354
+ /**
355
+ * function dropTable
356
+ * @param table
357
+ * @param dbManager
358
+ */
359
+ export async function dropTable(table: string, dbManager: DBManager) {
360
+ const dbTable = await dbManager.dbTableExist(table)
361
+ if (dbTable)
362
+ await dbManager.dbTableDelete(dbTable)
363
+ }
364
+
365
+
@@ -0,0 +1,62 @@
1
+ import { Cmd } from "./Cmd";
2
+ import { DBClient } from "./DBClient";
3
+ import { logger } from "./TableCommand";
4
+
5
+ //--------------------------------------------------------------------------------------------------------------------
6
+ // class TableData
7
+ //--------------------------------------------------------------------------------------------------------------------
8
+ export class TableDataCommand extends Cmd {
9
+
10
+ constructor(name: string, description: string) {
11
+ super(name);
12
+ this.description(description)
13
+ .argument('<table>', 'table name')
14
+ .option('--where <clause_where_sql>', 'criteria in SQL syntax')
15
+ .option('-s --sort <columns>', 'sort by columns positions (begins by 0) separated by comma')
16
+ .option('-w --width <colwidth>', 'columns widths separated by comma')
17
+ .action(async (table, options) => {
18
+ this.commandData(table, options);
19
+ });
20
+ }
21
+
22
+ async commandData(table: string, options: any) {
23
+ try {
24
+ await this.prologue(options);
25
+ if (this.dbManager === undefined) throw 'dbManager undefined';
26
+
27
+ const dbTable = await this.dbManager.dbTableExist(table);
28
+ if (dbTable === undefined) throw 'table ' + table + ' not found';
29
+
30
+ let fields = '';
31
+
32
+ for (let ind = 0; ind < dbTable.columns.length; ind++) {
33
+ const dbColumn = dbTable.columns[ind];
34
+ let ok = false;
35
+ let fieldName = dbColumn.name;
36
+ if (dbColumn.dbType === 'text' || dbColumn.dbType === 'bytea') {
37
+ ok = false;
38
+ fieldName = 'length(' + dbColumn.name + ')';
39
+ }
40
+ else {
41
+ ok = true;
42
+ }
43
+ if (ok === true) {
44
+ if (fields !== '') fields += ',';
45
+ fields += fieldName;
46
+ }
47
+ }
48
+
49
+ logger.debug('commandQuery', table);
50
+ const dbClient = new DBClient(this.dbManager);
51
+ let title = 'Table ' + table;
52
+ if (options.where !== undefined) {
53
+ title += ' where ' + options.where;
54
+ }
55
+ dbClient.selectFromTable(title, table,
56
+ { fields: fields, width: options.width, sort: options.sort || '1', where: options.where });
57
+ }
58
+ catch (err) {
59
+ logger.error(err);
60
+ }
61
+ }
62
+ }
@@ -5,7 +5,7 @@ import { green, red, bold } from 'kolorist'
5
5
 
6
6
  import loglevel from 'loglevel'
7
7
  import { deleteModule } from "./ModuleCommand";
8
- import { DBManager } from "@cyklang/core";
8
+ import { DBManager, DBRemote } from "@cyklang/core";
9
9
  const logger = loglevel.getLogger('UninstallCommand.ts')
10
10
  logger.setLevel('debug')
11
11
 
@@ -31,9 +31,9 @@ export class UninstallCommand extends Cmd {
31
31
  async uninstall(node_package: string, options: any) {
32
32
  try {
33
33
  await this.prologue(options)
34
- if (this.dbManager === undefined) throw 'dbManager undefined'
34
+ if (! this.dbManager || ! this.dbRemote) throw 'dbManager or dbRemote undefined'
35
35
 
36
- await uninstallPackage(node_package, this.dbManager)
36
+ await uninstallPackage(node_package, this.dbManager, this.dbRemote)
37
37
  }
38
38
  catch (err) {
39
39
  logger.error(err)
@@ -45,7 +45,7 @@ export class UninstallCommand extends Cmd {
45
45
  * function uninstallPackage
46
46
  * @param node_package
47
47
  */
48
- export async function uninstallPackage(node_package: string, dbManager: DBManager) {
48
+ export async function uninstallPackage(node_package: string, dbManager: DBManager, dbRemote: DBRemote) {
49
49
 
50
50
  const uninstallScript = await lookupUninstallScript(node_package)
51
51
  if (uninstallScript) {
@@ -59,7 +59,7 @@ export async function uninstallPackage(node_package: string, dbManager: DBManage
59
59
  /**
60
60
  * default uninstall :
61
61
  */
62
- await defaultUninstallScript(node_package, dbManager)
62
+ await defaultUninstallScript(node_package, dbManager, dbRemote)
63
63
  }
64
64
 
65
65
  /**
@@ -72,14 +72,65 @@ export async function uninstallPackage(node_package: string, dbManager: DBManage
72
72
  * method defaultUninstallScript
73
73
  * @param node_package
74
74
  */
75
- async function defaultUninstallScript(node_package: string, dbManager: DBManager) {
75
+ async function defaultUninstallScript(node_package: string, dbManager: DBManager, dbRemote: DBRemote) {
76
76
  console.log()
77
77
  console.log('Default uninstall script')
78
78
  /**
79
79
  * delete package modules from server
80
80
  */
81
81
  await deletePackageModules(node_package, dbManager)
82
+ /**
83
+ * delete package assets from server
84
+ */
85
+ await deletePackageAssets(node_package, dbManager, dbRemote)
86
+
87
+ }
88
+
89
+ /**
90
+ * function deletePackageAssets
91
+ * @param node_package
92
+ * @param dbManager
93
+ * @param dbRemote
94
+ */
95
+ async function deletePackageAssets(node_package: string, dbManager: DBManager, dbRemote: DBRemote) {
96
+ const assetFolder = path.join('node_modules', node_package, 'asset')
97
+ if (!fs.existsSync(assetFolder) || !fs.statSync(assetFolder).isDirectory()) {
98
+ return
99
+ }
100
+ console.log()
101
+ console.log('delete assets from server ...')
102
+
103
+ await browseFolder(assetFolder, async (filePath: string) => {
104
+ const route = '/' + path.relative(assetFolder, filePath)
105
+ const dbAsset = await dbManager.dbAssetExist(route)
106
+ if (!dbAsset) {
107
+ logger.info('asset ' + route + ' not found')
108
+ return
109
+ }
110
+ await dbManager.dbAssetDelete(dbAsset)
111
+ logger.info('asset ' + route + ' deleted')
112
+ })
82
113
 
114
+ console.log(green('*') + ' delete assets from server')
115
+ }
116
+
117
+ /**
118
+ * browseFolder
119
+ * @param folder
120
+ * @param treatment
121
+ */
122
+ async function browseFolder(folder: string, treatment: (filePath: string) => Promise<void>) {
123
+ const files = fs.readdirSync(folder)
124
+ for(let ind = 0; ind < files.length; ind++) {
125
+ const file = files[ind]
126
+ const pathName = folder + '/' + file
127
+ if (fs.statSync(pathName).isDirectory()) {
128
+ await browseFolder(pathName, treatment)
129
+ }
130
+ else {
131
+ await treatment(pathName)
132
+ }
133
+ }
83
134
  }
84
135
 
85
136
  /**
package/src/index.ts CHANGED
@@ -11,12 +11,13 @@ import { InstallCommand } from './InstallCommand'
11
11
  import { AssetCommand } from './AssetCommand'
12
12
  import { OpenCommand } from './OpenCommand'
13
13
  import { UninstallCommand } from './UninstallCommand'
14
+ import { TableDataCommand } from './TableDataCommand'
14
15
  const logger = loglevel.getLogger("index.ts")
15
16
  logger.setLevel("debug")
16
17
 
17
18
  const program = new Command()
18
19
  program.name('cyk').description('cyklang CLI')
19
- .version('0.5.5')
20
+ .version('0.6.0')
20
21
 
21
22
  program.addCommand(new InstallCommand('install'))
22
23
  program.addCommand(new InstallCommand('i'))
@@ -31,6 +32,8 @@ program.addCommand(new QueryCommand('query'))
31
32
  program.addCommand(new QueryCommand('q'))
32
33
  program.addCommand(new TableCommand('table'))
33
34
  program.addCommand(new TableCommand('t'))
35
+ program.addCommand(new TableDataCommand('data', 'show table data'))
36
+ program.addCommand(new TableDataCommand('d', 'show table data'))
34
37
  program.addCommand(new TestCommand())
35
38
  program.addCommand(new RunCommand('run'))
36
39
  program.addCommand(new RunCommand('r'))