@cyklang/cli 0.2.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,7 +42,7 @@ class AssetCommand extends commander_1.Command {
42
42
  this.description(description);
43
43
  this.addCommand(new AssetList('list', 'list assets'));
44
44
  this.addCommand(new AssetList('l', '(l)ist assets'));
45
- this.addCommand(new AssetUpload('upload', 'upload assets from current directory'));
45
+ this.addCommand(new AssetUpload('upload', 'upload assets from sources'));
46
46
  this.addCommand(new AssetUpload('u', '(u)pload assets'));
47
47
  }
48
48
  }
@@ -60,7 +60,7 @@ class AssetList extends Cmd_1.Cmd {
60
60
  if (this.dbManager === undefined)
61
61
  throw 'dbManager undefined';
62
62
  const dbClient = new DBClient_1.DBClient(this.dbManager);
63
- dbClient.selectFromTable('List of Assets', 'cyk_asset', { fields: 'asset_id,asset_route,asset_last_update,asset_mimetype', sort: options.sort || '1' });
63
+ dbClient.selectFromTable('List of Assets', 'cyk_asset', { fields: 'asset_id,asset_route,asset_auth,asset_access,asset_mimetype,asset_last_update', sort: options.sort || '1' });
64
64
  }
65
65
  catch (err) {
66
66
  logger.error(err);
@@ -75,7 +75,9 @@ class AssetUpload extends Cmd_1.Cmd {
75
75
  //----------------------------------------------------------------------------------------------
76
76
  this.ignorePatterns = ['.git', 'node_modules'];
77
77
  this.description(description)
78
- .option('-d --dest <destination>', 'route of destination')
78
+ .option('-a --auth <auth_schema>', 'authentication schema : basic | token | any, default is no authentication')
79
+ .option('-d --dest <destination>', 'destination path, directory name')
80
+ .option('-c --clean', 'clean destination path before uploading')
79
81
  .option('-y --yes', 'upload list is automatically confirmed')
80
82
  .argument('[sources...]', 'local files or directories to upload as assets to the server')
81
83
  .action(async (sources, options) => {
@@ -99,6 +101,11 @@ class AssetUpload extends Cmd_1.Cmd {
99
101
  throw 'dbManager undefined';
100
102
  if (sources.length === 0)
101
103
  throw 'no source to upload';
104
+ if (options.auth && ' basic | token | any '.indexOf(options.auth) === -1) {
105
+ throw 'valid authentication schemas are : basic | token | any';
106
+ }
107
+ logger.debug('options : ', options);
108
+ logger.debug('auth : ' + options.auth);
102
109
  let dest = "/";
103
110
  if (options.dest !== undefined)
104
111
  dest = options.dest;
@@ -106,6 +113,9 @@ class AssetUpload extends Cmd_1.Cmd {
106
113
  dest = '/' + dest;
107
114
  if (dest.substring(dest.length - 1) !== '/')
108
115
  dest = dest + '/';
116
+ if (options.clean) {
117
+ await this.cleanDestination(dest);
118
+ }
109
119
  for (let ind = 0; ind < sources.length; ind++) {
110
120
  const source = sources[ind];
111
121
  if (fs.existsSync(source) === false)
@@ -117,7 +127,7 @@ class AssetUpload extends Cmd_1.Cmd {
117
127
  else if (filestat.isFile() === true) {
118
128
  const base = path_1.default.parse(source).base;
119
129
  logger.debug('upload file ' + source + ' to ' + dest + base);
120
- await this.uploadAsset({ path: source, mtime: filestat.mtime }, dest + base);
130
+ await this.uploadAsset({ path: source, mtime: filestat.mtime }, dest + base, options.auth);
121
131
  }
122
132
  }
123
133
  }
@@ -126,6 +136,19 @@ class AssetUpload extends Cmd_1.Cmd {
126
136
  }
127
137
  }
128
138
  //----------------------------------------------------------------------------------------------
139
+ // cleanDestination
140
+ //----------------------------------------------------------------------------------------------
141
+ async cleanDestination(dest) {
142
+ const remoteList = await this.scanAssets();
143
+ for (let ind = 0; ind < remoteList.length; ind++) {
144
+ const fd = remoteList[ind];
145
+ if (fd.path.startsWith(dest)) {
146
+ const url = '/api/admin/assets/' + fd.id;
147
+ await this.dbRemote?.apiServer.delete(url);
148
+ }
149
+ }
150
+ }
151
+ //----------------------------------------------------------------------------------------------
129
152
  // uploadDirectory
130
153
  //----------------------------------------------------------------------------------------------
131
154
  async uploadDirectory(source, dest, options) {
@@ -140,8 +163,7 @@ class AssetUpload extends Cmd_1.Cmd {
140
163
  }
141
164
  logger.debug('options', options);
142
165
  this.scanDir(dirName, localList);
143
- const remoteList = [];
144
- await this.scanAssets(remoteList);
166
+ const remoteList = await this.scanAssets();
145
167
  const uploadList = this.buildUploadList(dirName, dest, localList, remoteList);
146
168
  // logger.info(fileNames.join('\n'))
147
169
  if (uploadList.length === 0)
@@ -153,7 +175,7 @@ class AssetUpload extends Cmd_1.Cmd {
153
175
  uploadConfirmed = true;
154
176
  }
155
177
  if (uploadConfirmed === true) {
156
- await this.uploadFiles(dirName, uploadList, dest);
178
+ await this.uploadFiles(dirName, uploadList, dest, options.auth);
157
179
  }
158
180
  // const rl = readline.createInterface(process.stdin, process.stdout)
159
181
  // rl.question('Do you want to upload this(these) ' + uploadList.length + ' file(s) (Y/N/y/n) ?', async (reply) => {
@@ -193,7 +215,8 @@ class AssetUpload extends Cmd_1.Cmd {
193
215
  //----------------------------------------------------------------------------------------------
194
216
  // scanAssets
195
217
  //----------------------------------------------------------------------------------------------
196
- async scanAssets(result) {
218
+ async scanAssets() {
219
+ const result = [];
197
220
  if (this.dbManager === undefined)
198
221
  throw 'dbManager undefined';
199
222
  const dbReq = new core_1.DBExecuteRequest();
@@ -209,11 +232,13 @@ class AssetUpload extends Cmd_1.Cmd {
209
232
  for (let ind = 0; ind < rows.list.length; ind++) {
210
233
  const { variable: row } = rows.list[ind];
211
234
  const record = row.data;
235
+ const asset_id = record.variables.getData('asset_id').value;
212
236
  const asset_route = record.variables.getData('asset_route').value;
213
- const asset_last_update = record.variables.getData('asset_last_update').value;
237
+ const asset_last_update = record.variables.getData('asset_last_update')?.value;
214
238
  // logger.debug('asset_route ' + asset_route,'asset_last_update ' + asset_last_update)
215
- result.push({ path: asset_route, mtime: asset_last_update });
239
+ result.push({ path: asset_route, mtime: asset_last_update, id: asset_id });
216
240
  }
241
+ return result;
217
242
  }
218
243
  //----------------------------------------------------------------------------------------------
219
244
  // scanDir
@@ -250,19 +275,19 @@ class AssetUpload extends Cmd_1.Cmd {
250
275
  //----------------------------------------------------------------------------------------------
251
276
  // uploadFiles
252
277
  //----------------------------------------------------------------------------------------------
253
- async uploadFiles(dirName, uploadList, dest) {
278
+ async uploadFiles(dirName, uploadList, dest, auth) {
254
279
  for (let ind = 0; ind < uploadList.length; ind++) {
255
280
  const upload = uploadList[ind];
256
281
  const route = dest + upload.path.substring(dirName.length);
257
282
  logger.debug('upload ' + upload.path + ' to ' + route);
258
- await this.uploadAsset(upload, route);
283
+ await this.uploadAsset(upload, route, auth);
259
284
  }
260
285
  }
261
286
  //----------------------------------------------------------------------------------------------
262
287
  // uploadAsset
263
288
  //----------------------------------------------------------------------------------------------
264
- async uploadAsset(upload, route) {
265
- logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path));
289
+ async uploadAsset(upload, route, auth) {
290
+ logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth);
266
291
  try {
267
292
  let dbAsset = await this.dbManager?.dbAssetExist(route);
268
293
  if (dbAsset === undefined) {
@@ -273,6 +298,7 @@ class AssetUpload extends Cmd_1.Cmd {
273
298
  throw 'mimetype false for ' + upload;
274
299
  dbAsset.mimetype = mimetype;
275
300
  dbAsset.route = route;
301
+ dbAsset.auth = auth;
276
302
  // const fstat = fs.statSync(fileName)
277
303
  dbAsset.last_update = upload.mtime;
278
304
  // const contentBuffer = fs.readFileSync(fileName)
@@ -301,7 +327,7 @@ class AssetUpload extends Cmd_1.Cmd {
301
327
  const file = fs.createReadStream(fileName);
302
328
  const form = new form_data_1.default();
303
329
  form.append('uploadFile', file);
304
- const route = '/upload/cyk_asset/asset_content?asset_id=' + dbAsset.id;
330
+ const route = '/api/upload/cyk_asset/asset_content?asset_id=' + dbAsset.id;
305
331
  const resp = await this.dbRemote?.apiServer.post(route, form);
306
332
  if (resp.status === 200) {
307
333
  logger.info(fileName + ' uploaded');
package/build/Cmd.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { DBManager, DBRemote } from "@cyklang/core";
1
+ import { DBManager, DBRemote, SigninResponse } from "@cyklang/core";
2
2
  import { Command } from "commander";
3
3
  export declare class Cmd extends Command {
4
4
  dbManager: DBManager | undefined;
5
5
  dbRemote: DBRemote | undefined;
6
6
  constructor(name: string);
7
- prologue(options: any): Promise<void>;
7
+ prologue(options: any): Promise<SigninResponse>;
8
8
  }
package/build/Cmd.js CHANGED
@@ -17,24 +17,20 @@ class Cmd extends commander_1.Command {
17
17
  this.option('--env <env>', 'path to the environment variables file');
18
18
  }
19
19
  async prologue(options) {
20
- try {
21
- const dotenvOutput = dotenv_1.default.config({ path: options.env });
22
- if (dotenvOutput.error !== undefined)
23
- throw dotenvOutput.error;
24
- const structure = new core_1.Structure();
25
- if (process.env.DBREMOTE_URL === undefined)
26
- throw 'DBREMOTE_URL undefined';
27
- logger.debug('Cmd.DBREMOTE_URL ' + process.env.DBREMOTE_URL);
28
- const nodeCrypto = new NodeCrypto_1.NodeCrypto();
29
- this.dbRemote = new core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto);
30
- const login = await this.dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
31
- // logger.debug(login)
32
- this.dbManager = new core_1.DBManager(structure.scope, this.dbRemote);
33
- await this.dbManager.initialize();
34
- }
35
- catch (err) {
36
- logger.error(err);
37
- }
20
+ const dotenvOutput = dotenv_1.default.config({ path: options.env });
21
+ if (dotenvOutput.error !== undefined)
22
+ throw dotenvOutput.error;
23
+ const structure = new core_1.Structure();
24
+ if (process.env.DBREMOTE_URL === undefined)
25
+ throw 'DBREMOTE_URL undefined';
26
+ logger.debug('Cmd.DBREMOTE_URL ' + process.env.DBREMOTE_URL);
27
+ const nodeCrypto = new NodeCrypto_1.NodeCrypto();
28
+ this.dbRemote = new core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto);
29
+ const login = await this.dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
30
+ // logger.debug(login)
31
+ this.dbManager = new core_1.DBManager(structure.scope, this.dbRemote);
32
+ await this.dbManager.initialize();
33
+ return login;
38
34
  }
39
35
  }
40
36
  exports.Cmd = Cmd;
@@ -2,6 +2,7 @@ import { DBManager } from "@cyklang/core";
2
2
  export declare class DBClient {
3
3
  dbManager: DBManager;
4
4
  constructor(dbManager: DBManager);
5
+ runQuery(): Promise<void>;
5
6
  selectFromTable(title: string, tableName: string, options: {
6
7
  fields: string;
7
8
  sort?: string | undefined;
package/build/DBClient.js CHANGED
@@ -13,6 +13,8 @@ class DBClient {
13
13
  constructor(dbManager) {
14
14
  this.dbManager = dbManager;
15
15
  }
16
+ async runQuery() {
17
+ }
16
18
  async selectFromTable(title, tableName, options) {
17
19
  try {
18
20
  const objectDataType = this.dbManager.scope.structure.objectDataType;
@@ -215,6 +217,8 @@ class List {
215
217
  else {
216
218
  result = value.toString();
217
219
  }
220
+ // replace \n with a space
221
+ result = result.replace(/\n/, ' ');
218
222
  if (width !== undefined && width !== 0) {
219
223
  if (result.length >= width) {
220
224
  result = result.substring(0, width);
@@ -59,7 +59,7 @@ function getModuleDBName(filePath) {
59
59
  // if (filePath.endsWith('.xml') === false) throw filePath + ' does not have .xml extension'
60
60
  // result = path.basename(filePath, '.xml')
61
61
  const result = path_1.default.parse(filePath).name;
62
- const identifierRegex = /^[_a-zA-Z][_a-zA-Z0-9]*$/;
62
+ const identifierRegex = /^[_a-zA-Z][-_a-zA-Z0-9]*$/;
63
63
  if (result.match(identifierRegex) === null)
64
64
  throw 'filename ' + result + ' does not match identifier syntax';
65
65
  return result;
@@ -196,7 +196,7 @@ class ModuleList extends Cmd_1.Cmd {
196
196
  if (this.dbManager === undefined)
197
197
  throw 'dbManager undefined';
198
198
  const dbClient = new DBClient_1.DBClient(this.dbManager);
199
- dbClient.selectFromTable('List of Modules', 'cyk_module', { fields: 'module_id,module_dbname,module_access,module_description', sort: options.sort || '1' });
199
+ dbClient.selectFromTable('List of Modules', 'cyk_module', { fields: 'module_id,module_dbname,module_auth,module_access,module_description', sort: options.sort || '1' });
200
200
  }
201
201
  catch (err) {
202
202
  logger.error(err);
@@ -5,58 +5,68 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.QueryCommand = void 0;
8
- const core_1 = require("@cyklang/core");
9
8
  const loglevel_1 = __importDefault(require("loglevel"));
9
+ const Cmd_1 = require("./Cmd");
10
10
  const commander_1 = require("commander");
11
+ const DBClient_1 = require("./DBClient");
11
12
  const logger = loglevel_1.default.getLogger("QueryCommand.ts");
12
13
  logger.setLevel("debug");
13
14
  class QueryCommand extends commander_1.Command {
14
15
  constructor(name) {
15
16
  super(name);
17
+ this.description('query management');
18
+ this.addCommand(new QueryList('list', 'list queries'));
19
+ this.addCommand(new QueryList('l', 'list queries'));
16
20
  }
17
21
  }
18
22
  exports.QueryCommand = QueryCommand;
19
- function parseXmlFile(filepath, basename, xmlSource) {
20
- const tag = (0, core_1.parseXML)(filepath, xmlSource);
21
- if (tag.name !== 'DB.QUERY') {
22
- throw Error('tag ' + tag.name + ', should be <db.query>');
23
- }
24
- const name = tag.attributes.NAME;
25
- if (name === undefined) {
26
- throw Error('name attribute is missing');
23
+ //--------------------------------------------------------------------------------------------------------------------
24
+ // class TableList
25
+ //--------------------------------------------------------------------------------------------------------------------
26
+ class QueryList extends Cmd_1.Cmd {
27
+ constructor(name, description) {
28
+ super(name);
29
+ this.description(description)
30
+ .option('-s --sort <columns>', 'sort list by column numbers (begins with 0) separated by comma')
31
+ .action(async (options) => {
32
+ await this.commandList(options);
33
+ });
27
34
  }
28
- if (basename !== name + '.xml') {
29
- throw Error('filename ' + filepath + ' and name ' + name + ' do not correspond');
35
+ async commandList(options) {
36
+ await this.prologue(options);
37
+ if (this.dbManager === undefined)
38
+ throw 'dbManager undefined';
39
+ const dbClient = new DBClient_1.DBClient(this.dbManager);
40
+ dbClient.selectFromTable('List of Queries', 'cyk_query', { fields: 'query_id,query_name,query_auth,query_access,query_description', sort: options.sort || '1' });
30
41
  }
31
- return tag;
32
42
  }
33
- async function executeXml(structure, tag, xmlSource) {
34
- try {
35
- logger.debug('executeXml ' + tag.attributes.NAME);
36
- // structure.setInstructionType("print", new PrintInstructionType(logfilename))
37
- const dbQueryInstructionType = structure.scope.getInstructionType('db.query');
38
- if (dbQueryInstructionType === undefined) {
39
- throw Error('dbQueryInstructionType not found');
40
- }
41
- const scopeParse = new core_1.Scope(structure, structure.scope, undefined);
42
- const dbQueryInst = await dbQueryInstructionType.parseInstruction(tag, scopeParse);
43
- dbQueryInst.source = xmlSource;
44
- const scopeExecute = new core_1.Scope(structure, structure.scope, undefined);
45
- await dbQueryInst.execute(scopeExecute);
43
+ //--------------------------------------------------------------------------------------------------------------------
44
+ // class queryData
45
+ //--------------------------------------------------------------------------------------------------------------------
46
+ class queryData extends Cmd_1.Cmd {
47
+ constructor(name, description) {
48
+ super(name);
49
+ this.description(description)
50
+ .argument('<query>', 'query name')
51
+ .option('--where <clause_where_sql>', 'criteria in SQL syntax')
52
+ .option('-s --sort <columns>', 'sort by columns positions (begins by 0) separated by comma')
53
+ .option('-w --width <colwidth>', 'columns widths separated by comma')
54
+ .action(async (query, options) => {
55
+ this.commandData(query, options);
56
+ });
46
57
  }
47
- catch (err) {
48
- logger.error(err);
58
+ async commandData(query, options) {
59
+ try {
60
+ await this.prologue(options);
61
+ if (this.dbManager === undefined)
62
+ throw 'dbManager undefined';
63
+ const dbQuery = await this.dbManager.dbQueryExist(query);
64
+ if (dbQuery === undefined)
65
+ throw 'query ' + query + ' not found';
66
+ //DBClient
67
+ }
68
+ catch (err) {
69
+ logger.error(err);
70
+ }
49
71
  }
50
72
  }
51
- async function testQuery(structure, queryName) {
52
- const xmlScript = `
53
- <block>
54
- <object name='result'/>
55
- <db.execute query='${queryName}' result='result' />
56
- <print>string(result)</print>
57
- </block>
58
- `;
59
- const script = new core_1.Script(structure.scope, 'test', xmlScript);
60
- await script.parseInstructions();
61
- await script.execute();
62
- }
@@ -61,11 +61,11 @@ async function runFile(filename) {
61
61
  if (filename.indexOf(".") !== -1) {
62
62
  filename = filename.substring(0, filename.indexOf("."));
63
63
  }
64
+ // skip filename with double underscore
65
+ if (filename.indexOf("__") !== -1)
66
+ return;
64
67
  let xmlfilename = filename + ".xml";
65
- // let logfilename = filename + ".log"
66
- // let outfilename = filename + ".output"
67
68
  let xml = fs.readFileSync(xmlfilename);
68
- // fs.writeFileSync(logfilename, "")
69
69
  try {
70
70
  if (process.env.DBREMOTE_URL === undefined)
71
71
  throw 'DBREMOTE_URL undefined';
@@ -76,14 +76,24 @@ async function runFile(filename) {
76
76
  const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
77
77
  const dbManager = new core_1.DBManager(structure.scope, dbRemote);
78
78
  await dbManager.initialize();
79
- const tag = (0, core_1.parseXML)(xmlfilename, xml.toString());
80
- const moduleInstruction = new core_1.ModuleInstruction(tag, dbManager);
81
- await moduleInstruction.parse(structure.scope);
82
- await moduleInstruction.execute(structure.scope);
83
- // structure.scope.addInstructionType(new PrintInstructionType(logfilename))
84
- // let script = new Script(structure.scope, xmlfilename, xml.toString())
85
- // await script.parseInstructions()
86
- // await script.execute()
79
+ const user_lang = login.content.user_lang;
80
+ if (user_lang && user_lang.trim() !== '') {
81
+ const langfilename = filename + "__" + user_lang + ".xml";
82
+ if (fs.existsSync(langfilename)) {
83
+ const langXml = fs.readFileSync(langfilename);
84
+ const tag = (0, core_1.parseXML)(xmlfilename, langXml.toString());
85
+ const modLang = new core_1.ModuleInstruction(tag, dbManager);
86
+ await modLang.parse(structure.scope);
87
+ await modLang.execute(structure.scope);
88
+ const langMap = modLang.objectData?.variables.getData(user_lang);
89
+ if (langMap !== null && langMap !== undefined) {
90
+ structure.mapLang = langMap;
91
+ }
92
+ }
93
+ }
94
+ let script = new core_1.Script(structure.scope, xmlfilename, xml.toString());
95
+ await script.parseInstructions();
96
+ await script.execute();
87
97
  }
88
98
  catch (err) {
89
99
  if (err instanceof core_1.XmlError) {
@@ -92,21 +102,4 @@ async function runFile(filename) {
92
102
  }
93
103
  console.log(err);
94
104
  }
95
- // let log = fs.readFileSync(logfilename)
96
- // if (fs.existsSync(outfilename) === true ) {
97
- // let out = fs.readFileSync(outfilename)
98
- // if (log.toString() === out.toString()) {
99
- // console.log("test " + xmlfilename + " SUCCESS")
100
- // result = true
101
- // }
102
- // else {
103
- // console.log("test " + xmlfilename + " FAILURE")
104
- // result = false
105
- // }
106
- // }
107
- // else {
108
- // console.log("test " + xmlfilename + " output file not found ")
109
- // result = false
110
- // }
111
- // return result
112
105
  }
@@ -41,8 +41,8 @@ class TableCommand extends commander_1.Command {
41
41
  this.addCommand(new TableImportCmd());
42
42
  this.addCommand(new TableList('list', 'list database tables'));
43
43
  this.addCommand(new TableList('l', '(l)ist database tables'));
44
- this.addCommand(new TableQuery('query', 'query select table content'));
45
- this.addCommand(new TableQuery('q', 'query select table content'));
44
+ this.addCommand(new TableData('data', 'table (d)ata'));
45
+ this.addCommand(new TableData('d', 'table (d)ata'));
46
46
  }
47
47
  }
48
48
  exports.TableCommand = TableCommand;
@@ -271,25 +271,25 @@ class TableList extends Cmd_1.Cmd {
271
271
  if (this.dbManager === undefined)
272
272
  throw 'dbManager undefined';
273
273
  const dbClient = new DBClient_1.DBClient(this.dbManager);
274
- dbClient.selectFromTable('List of Tables', 'cyk_table', { fields: 'table_id,table_name,table_description,table_access', sort: options.sort || '1' });
274
+ dbClient.selectFromTable('List of Tables', 'cyk_table', { fields: 'table_id,table_name,table_auth,table_access,table_description', sort: options.sort || '1' });
275
275
  }
276
276
  }
277
277
  //--------------------------------------------------------------------------------------------------------------------
278
- // class TableQuery
278
+ // class TableData
279
279
  //--------------------------------------------------------------------------------------------------------------------
280
- class TableQuery extends Cmd_1.Cmd {
280
+ class TableData extends Cmd_1.Cmd {
281
281
  constructor(name, description) {
282
282
  super(name);
283
283
  this.description(description)
284
- .argument('<table>', 'table to query')
284
+ .argument('<table>', 'table name')
285
285
  .option('--where <clause_where_sql>', 'criteria in SQL syntax')
286
286
  .option('-s --sort <columns>', 'sort by columns positions (begins by 0) separated by comma')
287
287
  .option('-w --width <colwidth>', 'columns widths separated by comma')
288
288
  .action(async (table, options) => {
289
- this.commandQuery(table, options);
289
+ this.commandData(table, options);
290
290
  });
291
291
  }
292
- async commandQuery(table, options) {
292
+ async commandData(table, options) {
293
293
  try {
294
294
  await this.prologue(options);
295
295
  if (this.dbManager === undefined)
@@ -42,7 +42,7 @@ class TestCommand extends Cmd_1.Cmd {
42
42
  }
43
43
  async testRun(files, options) {
44
44
  try {
45
- await this.prologue(options);
45
+ const signinResponse = await this.prologue(options);
46
46
  for (let ind = 0; ind < files.length; ind++) {
47
47
  const result = await testfile(files[ind]);
48
48
  if (result === false) {
@@ -61,6 +61,9 @@ async function testfile(filename) {
61
61
  if (filename.indexOf(".") !== -1) {
62
62
  filename = filename.substring(0, filename.indexOf("."));
63
63
  }
64
+ // skip filename with double underscore
65
+ if (filename.indexOf("__") !== -1)
66
+ return true;
64
67
  let xmlfilename = filename + ".xml";
65
68
  let logfilename = filename + ".log";
66
69
  let outfilename = filename + ".output";
@@ -80,6 +83,22 @@ async function testfile(filename) {
80
83
  await dbManager.initialize();
81
84
  structure.scope.addInstructionType(new console_1.PrintInstructionType(logfilename));
82
85
  let script = new core_1.Script(structure.scope, xmlfilename, xml.toString());
86
+ const user_lang = login.content.user_lang;
87
+ if (user_lang && user_lang.trim() !== '') {
88
+ const langfilename = filename + "__" + user_lang + ".xml";
89
+ if (fs.existsSync(langfilename)) {
90
+ const langXml = fs.readFileSync(langfilename);
91
+ const tag = (0, core_1.parseXML)(xmlfilename, langXml.toString());
92
+ const modLang = new core_1.ModuleInstruction(tag, dbManager);
93
+ await modLang.parse(structure.scope);
94
+ await modLang.execute(structure.scope);
95
+ const langMap = modLang.objectData?.variables.getData(user_lang);
96
+ if (langMap !== null && langMap !== undefined) {
97
+ structure.mapLang = langMap;
98
+ outfilename = filename + "__" + user_lang + ".output";
99
+ }
100
+ }
101
+ }
83
102
  await script.parseInstructions();
84
103
  await script.execute();
85
104
  // console.log(JSON.stringify(script.block.toString()))
@@ -16,7 +16,8 @@ class UserCommand extends commander_1.Command {
16
16
  constructor(name) {
17
17
  super(name);
18
18
  this.description('manage users in cyk_user table').version('0.1');
19
- this.addCommand(new UserAddCmd());
19
+ this.addCommand(new UserAddCmd('add', 'add a new user'));
20
+ this.addCommand(new UserAddCmd('a', 'add a new user'));
20
21
  this.addCommand(new UserUpdateCmd('update', 'update user by id all fields except password'));
21
22
  this.addCommand(new UserUpdateCmd('u', 'shortcut for (u)pdate'));
22
23
  this.addCommand(new UserDeleteCmd('delete', 'delete user by id and name. Both options are mandatory to avoid typing error'));
@@ -27,15 +28,16 @@ class UserCommand extends commander_1.Command {
27
28
  }
28
29
  exports.UserCommand = UserCommand;
29
30
  class UserAddCmd extends Cmd_1.Cmd {
30
- constructor() {
31
- super('add');
32
- this.description('add a new user')
31
+ constructor(name, description) {
32
+ super(name);
33
+ this.description(description)
33
34
  .requiredOption('-n --name <name>', 'user name')
34
35
  .option('-e --email <email>', 'user email address')
35
36
  .option('-p --passwd <password>', 'initial password')
36
37
  .option('-a --access <acl>', 'access control list')
37
38
  .option('-m --module <module_name>', 'module to launch by default')
38
39
  .option('-d --disable', 'user not abled to connect')
40
+ .option('-l --lang <language>', 'user language')
39
41
  .action(async (options) => {
40
42
  const dbUser = new core_1.DBUser();
41
43
  dbUser.name = options.name;
@@ -44,6 +46,7 @@ class UserAddCmd extends Cmd_1.Cmd {
44
46
  dbUser.access = options.access;
45
47
  dbUser.appli = options.module;
46
48
  dbUser.disable = options.disable || false;
49
+ dbUser.lang = options.lang;
47
50
  await this.commandAdd(dbUser, options);
48
51
  });
49
52
  }
@@ -75,7 +78,7 @@ class UserListCmd extends Cmd_1.Cmd {
75
78
  if (this.dbManager === undefined)
76
79
  throw 'dbManager undefined';
77
80
  const dbClient = new DBClient_1.DBClient(this.dbManager);
78
- dbClient.selectFromTable('List of users', 'cyk_user', { fields: 'user_id,user_name,user_email,user_access,user_appli,user_disable', sort: options.sort || '1' });
81
+ dbClient.selectFromTable('List of users', 'cyk_user', { fields: 'user_id,user_name,user_email,user_access,user_appli,user_lang,user_disable', sort: options.sort || '1' });
79
82
  }
80
83
  catch (err) {
81
84
  logger.error(err);
@@ -91,6 +94,7 @@ class UserUpdateCmd extends Cmd_1.Cmd {
91
94
  .option('-e --email <email>', 'user email address')
92
95
  .option('-a --access <acl>', 'access control list')
93
96
  .option('-m --module <module_name>', 'module to launch by default')
97
+ .option('-l --lang <language>', 'user language')
94
98
  .option('-d --disable', 'user not able to connect')
95
99
  .action(async (options) => {
96
100
  const dbUser = new core_1.DBUser();
@@ -99,6 +103,7 @@ class UserUpdateCmd extends Cmd_1.Cmd {
99
103
  dbUser.email = options.email;
100
104
  dbUser.access = options.access;
101
105
  dbUser.appli = options.module;
106
+ dbUser.lang = options.lang;
102
107
  dbUser.disable = options.disable;
103
108
  await this.commandUpdate(dbUser, options);
104
109
  });
@@ -122,6 +127,8 @@ class UserUpdateCmd extends Cmd_1.Cmd {
122
127
  dbUser1.access = dbUser2.access;
123
128
  if (dbUser2.appli !== undefined)
124
129
  dbUser1.appli = dbUser2.appli;
130
+ if (dbUser2.lang !== undefined)
131
+ dbUser1.lang = dbUser2.lang;
125
132
  if (dbUser2.disable !== undefined)
126
133
  dbUser1.disable = dbUser2.disable;
127
134
  // logger.debug('dbUser1 before dbUserUpdate : ', dbUser1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyklang/cli",
3
- "version": "0.2.3",
3
+ "version": "0.3.1",
4
4
  "description": "cyklang CLI",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -17,22 +17,20 @@
17
17
  "author": "",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "@cyklang/core": "^0.4.2",
20
+ "@cyklang/core": "^0.5.0",
21
21
  "commander": "^9.4.0",
22
22
  "dotenv": "^16.0.1",
23
23
  "form-data": "^4.0.0",
24
24
  "inquirer": "^8.2.5",
25
25
  "loglevel": "^1.8.0",
26
26
  "mime-types": "^2.1.35",
27
- "pako": "^2.0.4",
28
- "xml": "^1.0.1"
27
+ "pako": "^2.0.4"
29
28
  },
30
29
  "devDependencies": {
31
30
  "@types/inquirer": "^8.2.4",
32
31
  "@types/mime-types": "^2.1.1",
33
32
  "@types/pako": "^2.0.0",
34
33
  "@types/sax": "^1.2.4",
35
- "@types/xml": "^1.0.8",
36
34
  "nodemon": "^2.0.16",
37
35
  "ts-node": "^10.7.0",
38
36
  "typescript": "4.5.2"