@cyklang/cli 0.7.5 → 0.8.3

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.
Files changed (58) hide show
  1. package/build/Cmd.js +11 -5
  2. package/build/CronCommand.d.ts +4 -0
  3. package/build/CronCommand.js +43 -0
  4. package/build/QueryCommand.js +42 -0
  5. package/build/TableCommand.js +12 -3
  6. package/build/TestCommand.js +2 -1
  7. package/build/console.js +1 -0
  8. package/build/index.js +4 -1
  9. package/clean_test.sh +20 -0
  10. package/package.json +3 -3
  11. package/run_test.sh +11 -0
  12. package/src/Cmd.ts +8 -3
  13. package/src/CronCommand.ts +40 -0
  14. package/src/QueryCommand.ts +42 -0
  15. package/src/TableCommand.ts +16 -6
  16. package/src/TestCommand.ts +11 -10
  17. package/src/console.ts +1 -0
  18. package/src/index.ts +4 -1
  19. package/test/db/schema.xsd +74 -0
  20. package/test/db/t10.output +23 -0
  21. package/test/{t10.xml → db/t10.xml} +25 -24
  22. package/test/db/t13.output +2 -0
  23. package/test/db/t13.xml +36 -0
  24. package/test/{t14.output → db/t14.output} +2 -0
  25. package/test/{t14.xml → db/t14.xml} +2 -2
  26. package/test/db/t15.output +10 -0
  27. package/test/db/t15.xml +47 -0
  28. package/test/db/t16.output +16 -0
  29. package/test/{t16.xml → db/t16.xml} +6 -6
  30. package/test/{t20.xml → db/t20.xml} +1 -1
  31. package/test/{t22.xml → db/t22.xml} +7 -7
  32. package/test/{t23.xml → db/t23.xml} +4 -4
  33. package/test/db/test_schema.xml +15 -0
  34. package/test/t09.output +1 -1
  35. package/test/t09.xml +1 -1
  36. package/test/t27.output +2 -0
  37. package/test/t27.xml +22 -1
  38. package/build/TableData.d.ts +0 -5
  39. package/build/TableData.js +0 -61
  40. package/build/TestCommand copy.d.ts +0 -5
  41. package/build/TestCommand copy.js +0 -111
  42. package/build/cykquery.d.ts +0 -2
  43. package/build/cykquery.js +0 -145
  44. package/build/cyktable.d.ts +0 -2
  45. package/build/cyktable.js +0 -133
  46. package/build/module.d.ts +0 -2
  47. package/build/module.js +0 -290
  48. package/test/cyklang.xsd +0 -1090
  49. package/test/t13.xml +0 -23
  50. package/test/t15.xml +0 -47
  51. package/test/t16.output +0 -49
  52. package/test/t19.xml +0 -234
  53. /package/test/{t14.xsd → db/t14.xsd} +0 -0
  54. /package/test/{t20.output → db/t20.output} +0 -0
  55. /package/test/{t21.output → db/t21.output} +0 -0
  56. /package/test/{t21.xml → db/t21.xml} +0 -0
  57. /package/test/{t22.output → db/t22.output} +0 -0
  58. /package/test/{t23.output → db/t23.output} +0 -0
package/build/cykquery.js DELETED
@@ -1,145 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
- }) : (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- o[k2] = m[k];
9
- }));
10
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
- Object.defineProperty(o, "default", { enumerable: true, value: v });
12
- }) : function(o, v) {
13
- o["default"] = v;
14
- });
15
- var __importStar = (this && this.__importStar) || function (mod) {
16
- if (mod && mod.__esModule) return mod;
17
- var result = {};
18
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
- __setModuleDefault(result, mod);
20
- return result;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const cyk_core_1 = require("@cyk-language/cyk-core");
27
- const fs = __importStar(require("fs"));
28
- const loglevel_1 = __importDefault(require("loglevel"));
29
- const path_1 = __importDefault(require("path"));
30
- const dotenv_1 = __importDefault(require("dotenv"));
31
- const logger = loglevel_1.default.getLogger("model.ts");
32
- logger.setLevel("debug");
33
- dotenv_1.default.config();
34
- const main = async () => {
35
- const structure = new cyk_core_1.Structure();
36
- if (process.env.DBREMOTE_URL === undefined)
37
- throw 'DBREMOTE_URL undefined';
38
- logger.debug('DBREMOTE_URL ' + process.env.DBREMOTE_URL);
39
- const dbRemote = new cyk_core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL);
40
- const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
41
- logger.debug(login);
42
- const dbManager = new cyk_core_1.DBManager(structure.scope, dbRemote);
43
- await dbManager.initialize();
44
- const { command, filepath, basename } = parseCommandLine();
45
- const xmlSource = fs.readFileSync(filepath).toString();
46
- let tag = parseXmlFile(filepath, basename, xmlSource);
47
- if (command === Command.Exec || command === Command.ExecTest) {
48
- await executeXml(structure, tag, xmlSource);
49
- }
50
- if (command === Command.Test || command === Command.ExecTest) {
51
- await testQuery(structure, tag.attributes.NAME);
52
- }
53
- };
54
- main().then(() => logger.debug('finished'));
55
- var Command;
56
- (function (Command) {
57
- Command["Exec"] = "exec";
58
- Command["ExecTest"] = "exectest";
59
- Command["Test"] = "test";
60
- })(Command || (Command = {}));
61
- function syntax() {
62
- console.log(`
63
- ----------------------------------------------------------------------------------
64
- cykquery executes a <db.query> to the server (DBREMOTE_URL environment variable)
65
- syntax :
66
- cykquery [ exec | test | exectest ] filename
67
- cykquery filename (option exectest by default)
68
- ----------------------------------------------------------------------------------
69
- `);
70
- }
71
- function parseCommandLine() {
72
- let command;
73
- let filepath;
74
- if (process.argv.length < 3 || process.argv.length > 4) {
75
- syntax();
76
- throw Error('nb of command line arguments : ' + process.argv.length);
77
- }
78
- if (process.argv.length === 3) {
79
- filepath = process.argv[2];
80
- command = Command.ExecTest;
81
- }
82
- else {
83
- const option = process.argv[2].toLowerCase();
84
- if (option === 'test' || option === 'exec' || option === 'exectest') {
85
- command = option;
86
- }
87
- else {
88
- syntax();
89
- throw Error('command unknown ' + process.argv[2]);
90
- }
91
- filepath = process.argv[3];
92
- }
93
- logger.trace('cykquery filepath : ' + filepath);
94
- const basename = path_1.default.basename(filepath);
95
- const extname = path_1.default.extname(filepath);
96
- logger.trace('basename ' + basename + ', extname ' + extname);
97
- if (extname.toLowerCase() !== '.xml') {
98
- throw Error('filepath argument ' + filepath + ' should have xml extension');
99
- }
100
- return { command, filepath, basename };
101
- }
102
- function parseXmlFile(filepath, basename, xmlSource) {
103
- const tag = (0, cyk_core_1.parseXML)(filepath, xmlSource);
104
- if (tag.name !== 'DB.QUERY') {
105
- throw Error('tag ' + tag.name + ', should be <db.query>');
106
- }
107
- const name = tag.attributes.NAME;
108
- if (name === undefined) {
109
- throw Error('name attribute is missing');
110
- }
111
- if (basename !== name + '.xml') {
112
- throw Error('filename ' + filepath + ' and name ' + name + ' do not correspond');
113
- }
114
- return tag;
115
- }
116
- async function executeXml(structure, tag, xmlSource) {
117
- try {
118
- logger.debug('executeXml ' + tag.attributes.NAME);
119
- // structure.setInstructionType("print", new PrintInstructionType(logfilename))
120
- const dbQueryInstructionType = structure.scope.getInstructionType('db.query');
121
- if (dbQueryInstructionType === undefined) {
122
- throw Error('dbQueryInstructionType not found');
123
- }
124
- const scopeParse = new cyk_core_1.Scope(structure, structure.scope, undefined);
125
- const dbQueryInst = await dbQueryInstructionType.parseInstruction(tag, scopeParse);
126
- dbQueryInst.source = xmlSource;
127
- const scopeExecute = new cyk_core_1.Scope(structure, structure.scope, undefined);
128
- await dbQueryInst.execute(scopeExecute);
129
- }
130
- catch (err) {
131
- logger.error(err);
132
- }
133
- }
134
- async function testQuery(structure, queryName) {
135
- const xmlScript = `
136
- <block>
137
- <object name='result'/>
138
- <db.execute query='${queryName}' result='result' />
139
- <print>string(result)</print>
140
- </block>
141
- `;
142
- const script = new cyk_core_1.Script(structure.scope, 'test', xmlScript);
143
- await script.parseInstructions();
144
- await script.execute();
145
- }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- export {};
package/build/cyktable.js DELETED
@@ -1,133 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
- }) : (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- o[k2] = m[k];
9
- }));
10
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
- Object.defineProperty(o, "default", { enumerable: true, value: v });
12
- }) : function(o, v) {
13
- o["default"] = v;
14
- });
15
- var __importStar = (this && this.__importStar) || function (mod) {
16
- if (mod && mod.__esModule) return mod;
17
- var result = {};
18
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
- __setModuleDefault(result, mod);
20
- return result;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const cyk_core_1 = require("@cyk-language/cyk-core");
27
- const fs = __importStar(require("fs"));
28
- const loglevel_1 = __importDefault(require("loglevel"));
29
- const dotenv_1 = __importDefault(require("dotenv"));
30
- const commander_1 = require("commander");
31
- const child_process_1 = require("child_process");
32
- const logger = loglevel_1.default.getLogger("cyktable.ts");
33
- logger.setLevel("debug");
34
- const program = new commander_1.Command();
35
- program.name('cyktable').description('import/export table rows')
36
- .version('0.2');
37
- program.command('export').description('export to CSV file(s)')
38
- .argument('<tables...>', 'table(s) to export')
39
- .option('-e --env <env>', 'path to the environment variables file')
40
- .option('-f --file <file>', 'name of the file to create, defaults to <table_name>.csv')
41
- .option('-d --dir <directory>', 'name of the directory where to create exported files')
42
- .action(async (tables, options) => commandImportExport('to', tables, options));
43
- program.command('import').description('export to CSV file(s)')
44
- .argument('<tables...>', 'table(s) to export')
45
- .option('-e --env <env>', 'path to the environment variables file')
46
- .option('-f --file <file>', 'name of the file to create, defaults to <table_name>.csv')
47
- .option('-d --dir <directory>', 'name of the directory where to create exported files')
48
- .action(async (tables, options) => commandImportExport('from', tables, options));
49
- const getDBManager = async () => {
50
- const structure = new cyk_core_1.Structure();
51
- if (process.env.DBREMOTE_URL === undefined)
52
- throw 'DBREMOTE_URL undefined';
53
- logger.debug('DBREMOTE_URL ' + process.env.DBREMOTE_URL);
54
- const dbRemote = new cyk_core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL);
55
- const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
56
- // logger.debug(login)
57
- const dbManager = new cyk_core_1.DBManager(structure.scope, dbRemote);
58
- await dbManager.initialize();
59
- return dbManager;
60
- };
61
- const commandImportExport = async (direction, tables, options) => {
62
- logger.debug('tables : ', tables, 'options : ', options);
63
- try {
64
- const dotenvOutput = dotenv_1.default.config({ path: options.env });
65
- if (dotenvOutput.error !== undefined)
66
- throw dotenvOutput.error;
67
- if (options.file === undefined && options.dir === undefined)
68
- throw '--file or --dir mandatory';
69
- if (options.file !== undefined && options.dir !== undefined)
70
- throw '--file and --dir are mutually exclusive';
71
- if (tables.length === 0)
72
- throw 'at least one table name is mandatory';
73
- if (tables.length > 1 && options.dir === undefined)
74
- throw 'for multiple tables, --dir is mandatory';
75
- const dbManager = await getDBManager();
76
- for (let indi = 0; indi < tables.length; indi++) {
77
- const tableName = tables[indi];
78
- const dbTable = await dbManager.dbTableExist(tableName);
79
- if (dbTable === undefined) {
80
- logger.info('table ' + tableName + ' not found');
81
- continue;
82
- }
83
- let lcols;
84
- for (let indj = 0; indj < dbTable.columns.length; indj++) {
85
- const dbColumn = dbTable.columns[indj];
86
- if (lcols === undefined) {
87
- lcols = "(";
88
- }
89
- else {
90
- lcols += ",";
91
- }
92
- lcols += dbColumn.name;
93
- }
94
- lcols += ")";
95
- let psql_cmd = "psql -c";
96
- if (process.env.HEROKU_CLI !== undefined) {
97
- psql_cmd = process.env.HEROKU_CLI + ' -c ';
98
- }
99
- let filename;
100
- if (options.file !== undefined) {
101
- if (fs.existsSync(options.file) && fs.lstatSync(options.file).isDirectory())
102
- throw '--file ' + options.file + ' is a directory';
103
- filename = options.file;
104
- }
105
- else if (options.dir === undefined)
106
- throw '--file and --dir unspecified';
107
- else if (fs.existsSync(options.dir) === false)
108
- throw 'directory ' + options.dir + ' does not exist';
109
- else if (fs.lstatSync(options.dir).isFile()) {
110
- logger.debug("--dir " + options.dir + " is a file ");
111
- }
112
- else {
113
- let directory = options.dir.trim();
114
- if (directory[directory.length - 1] !== '/') {
115
- directory += '/';
116
- }
117
- filename = directory + tableName + '.csv';
118
- }
119
- let copy_cmd = "\\copy " + tableName + lcols + direction + " '" + filename + "' csv header";
120
- const shell_cmd = psql_cmd + '"' + copy_cmd + '"';
121
- logger.debug(shell_cmd);
122
- const child = (0, child_process_1.spawn)(shell_cmd.trim(), { stdio: 'inherit', shell: true });
123
- // exec(shell_cmd.trim(), (error, stdout, stderr) => {
124
- // if (error) throw error
125
- // logger.debug(stdout, stderr)
126
- // })
127
- }
128
- }
129
- catch (err) {
130
- logger.error(err);
131
- }
132
- };
133
- program.parse();
package/build/module.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- export {};
package/build/module.js DELETED
@@ -1,290 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
- }) : (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- o[k2] = m[k];
9
- }));
10
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
- Object.defineProperty(o, "default", { enumerable: true, value: v });
12
- }) : function(o, v) {
13
- o["default"] = v;
14
- });
15
- var __importStar = (this && this.__importStar) || function (mod) {
16
- if (mod && mod.__esModule) return mod;
17
- var result = {};
18
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
- __setModuleDefault(result, mod);
20
- return result;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const core_1 = require("@cyklang/core");
27
- const fs = __importStar(require("fs"));
28
- const loglevel_1 = __importDefault(require("loglevel"));
29
- const path_1 = __importDefault(require("path"));
30
- const dotenv_1 = __importDefault(require("dotenv"));
31
- const commander_1 = require("commander");
32
- const NodeCrypto_1 = require("./NodeCrypto");
33
- const logger = loglevel_1.default.getLogger("cykmodule.ts");
34
- logger.setLevel("debug");
35
- const program = new commander_1.Command();
36
- program.name('cyk').description('manage modules in cyk_module table')
37
- .version('0.2');
38
- program.command('add').description('add modules')
39
- .argument('<files...>', 'local module file(s) to upload to the server')
40
- .option('-n --name <dbname>', 'module dbname')
41
- .option('-d --desc <description>', 'description')
42
- .option('-a --access <access>', 'access control list')
43
- .option('-e --env <env>', 'path to the environment variables file')
44
- .action(async (files, options) => {
45
- await commandAdd(files, options);
46
- });
47
- program.command('update').description('update module')
48
- .option('-i --id <id>', 'module ID')
49
- .option('-n --name <dbname>', 'module dbname')
50
- .option('-d --desc <description>', 'description')
51
- .option('-a --access <access>', 'access control list')
52
- .option('-e --env <env>', 'path to the environment variables file')
53
- .argument('[files...]', 'local module file(s) to upload to the server')
54
- .action(async (files, options) => {
55
- await commandUpdate(files, options);
56
- });
57
- program.command('run').description('execute/run a local module file')
58
- .argument('<file>', 'local module file to run')
59
- .option('-e --env <env>', 'path to the environment variables file')
60
- .action(async (file, options) => {
61
- await commandRun(file, options);
62
- });
63
- const getDBManager = async () => {
64
- const structure = new core_1.Structure();
65
- if (process.env.DBREMOTE_URL === undefined)
66
- throw 'DBREMOTE_URL undefined';
67
- logger.debug('DBREMOTE_URL ' + process.env.DBREMOTE_URL);
68
- const nodeCrypto = new NodeCrypto_1.NodeCrypto();
69
- const dbRemote = new core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto);
70
- const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
71
- // logger.debug(login)
72
- const dbManager = new core_1.DBManager(structure.scope, dbRemote);
73
- await dbManager.initialize();
74
- return dbManager;
75
- };
76
- const commandAdd = async (files, options) => {
77
- // logger.debug('options : ', options, ', files : ', files)
78
- try {
79
- const dotenvOutput = dotenv_1.default.config({ path: options.env });
80
- if (dotenvOutput.error !== undefined)
81
- throw dotenvOutput.error;
82
- const dbManager = await getDBManager();
83
- if (options.id !== undefined)
84
- throw '--id option is not available';
85
- if (files.length === 0)
86
- throw 'file(s) name(s) missing';
87
- if (files.length > 1 && (options.name !== undefined))
88
- throw '--name option cannot be specified with more than 1 file';
89
- for (let ind = 0; ind < files.length; ind++) {
90
- const file = files[ind];
91
- const dbModule = new core_1.DBModule();
92
- dbModule.source = fs.readFileSync(file).toString();
93
- dbModule.dbname = path_1.default.basename(file, '.xml');
94
- if (options.name !== undefined)
95
- dbModule.dbname = options.name;
96
- if (options.desc !== undefined)
97
- dbModule.description = options.desc;
98
- if (options.access !== undefined)
99
- dbModule.access = options.access;
100
- const moduleExist = await dbManager.dbModuleExist(dbModule.dbname);
101
- if (moduleExist !== undefined)
102
- throw 'module ' + moduleExist.dbname + ' already exists with id ' + moduleExist.id;
103
- const id = await dbManager.dbModuleInsert(dbModule);
104
- logger.info('module ' + dbModule.dbname + ' added with id ' + id);
105
- }
106
- }
107
- catch (err) {
108
- logger.error(err);
109
- }
110
- };
111
- const commandUpdate = async (files, options) => {
112
- // logger.debug('files : ', files, ', options : ', options)
113
- try {
114
- const dotenvOutput = dotenv_1.default.config({ path: options.env });
115
- if (dotenvOutput.error !== undefined)
116
- throw dotenvOutput.error;
117
- const dbManager = await getDBManager();
118
- if (options.id !== undefined) {
119
- if (files.length > 1)
120
- throw 'with --id option you can only specify 1 local file';
121
- const dbModule = await dbManager.getModule(options.id);
122
- if (options.name !== undefined)
123
- dbModule.dbname = options.name;
124
- if (options.desc !== undefined)
125
- dbModule.description = options.desc;
126
- if (options.access !== undefined)
127
- dbModule.access = options.access;
128
- if (files.length === 1) {
129
- dbModule.source = fs.readFileSync(files[0]).toString();
130
- }
131
- await dbManager.dbModuleUpdate(dbModule);
132
- }
133
- else {
134
- if (files.length === 0)
135
- throw 'without --id option you need to specify at least 1 local file';
136
- for (let ind = 0; ind < files.length; ind++) {
137
- const file = files[ind];
138
- const dbname = path_1.default.basename(file, '.xml');
139
- const dbModule = await dbManager.dbModuleExist(dbname);
140
- if (dbModule === undefined) {
141
- logger.info('local file ' + file + ', module ' + dbname + ' not found');
142
- continue;
143
- }
144
- dbModule.source = fs.readFileSync(file).toString();
145
- logger.debug('dbModule update from ' + file);
146
- if (options.desc !== undefined)
147
- dbModule.description = options.desc;
148
- if (options.access !== undefined)
149
- dbModule.access = options.access;
150
- await dbManager.dbModuleUpdate(dbModule);
151
- }
152
- }
153
- }
154
- catch (err) {
155
- logger.error(err);
156
- }
157
- };
158
- const commandRun = async (file, options) => {
159
- try {
160
- logger.debug('options', options);
161
- const dotenvOutput = dotenv_1.default.config({ path: options.env });
162
- if (dotenvOutput.error !== undefined)
163
- throw dotenvOutput.error;
164
- const dbManager = await getDBManager();
165
- const source = fs.readFileSync(file).toString();
166
- const tag = (0, core_1.parseXML)(file, source);
167
- const moduleInstruction = new core_1.ModuleInstruction(tag, dbManager);
168
- const scopeRun = new core_1.Scope(dbManager.scope.structure, dbManager.scope, undefined);
169
- await moduleInstruction.parseInstructions(tag, scopeRun);
170
- await moduleInstruction.execute(scopeRun);
171
- }
172
- catch (err) {
173
- logger.error(err);
174
- }
175
- };
176
- program.parse();
177
- // const main = async () => {
178
- // const { command, filepath, basename } = parseCommandLine()
179
- // const xmlSource = fs.readFileSync(filepath).toString()
180
- // let dbModule: DBModule | undefined
181
- // let tag = parseXmlFile(filepath, basename, xmlSource)
182
- // if (command === Command.Test || command === Command.TestSave) {
183
- // dbModule = await testXml(structure, tag)
184
- // }
185
- // else if (command === Command.Save) {
186
- // dbModule = await dbManager.dbModuleExist(tag.attributes.DBNAME)
187
- // if (dbModule === undefined) {
188
- // dbModule = new DBModule(tag.attributes.DBNAME)
189
- // }
190
- // }
191
- // if (dbModule !== undefined && (command === Command.Save || command === Command.TestSave)) {
192
- // dbModule.source = xmlSource
193
- // await saveModule(dbManager, dbModule)
194
- // }
195
- // }
196
- // main().then(() => logger.debug('finished'))
197
- // enum Command {
198
- // Test = 'test',
199
- // Save = 'save',
200
- // TestSave = 'testsave'
201
- // }
202
- // function syntax() {
203
- // console.log(`
204
- // ----------------------------------------------------------------------------------
205
- // cykmodule writes a module file to the server (DBREMOTE_URL environment variable)
206
- // syntax :
207
- // cykmodule [ save | test | testsave ] filename
208
- // cykmodule filename ( option testsave if omitted )
209
- // ----------------------------------------------------------------------------------
210
- // `)
211
- // }
212
- // function parseCommandLine(): { command: Command, filepath: string, basename: string } {
213
- // let command = Command.TestSave
214
- // let filepath
215
- // if (process.argv.length < 3 || process.argv.length > 4) {
216
- // syntax()
217
- // throw Error('nb of command line arguments : ' + process.argv.length)
218
- // }
219
- // if (process.argv.length === 3) {
220
- // filepath = process.argv[2]
221
- // command = Command.TestSave
222
- // }
223
- // else {
224
- // const option = process.argv[2].toLowerCase()
225
- // if ( option === 'test' || option === 'save' || option === 'testsave') {
226
- // command = <Command> option
227
- // }
228
- // else {
229
- // syntax()
230
- // throw Error('command unknown ' + process.argv[2])
231
- // }
232
- // filepath = process.argv[3]
233
- // }
234
- // logger.trace('dbmodule filepath : ' + filepath)
235
- // const basename = path.basename(filepath)
236
- // const extname = path.extname(filepath)
237
- // logger.trace('basename ' + basename + ', extname ' + extname)
238
- // if (extname.toLowerCase() !== '.xml') {
239
- // throw Error('filepath argument ' + filepath + ' should have xml extension')
240
- // }
241
- // return { command, filepath, basename }
242
- // }
243
- function parseXmlFile(filepath, basename, xmlSource) {
244
- const tag = (0, core_1.parseXML)(filepath, xmlSource);
245
- if (tag.name !== 'MODULE') {
246
- throw Error('tag ' + tag.name + ', should be <module>');
247
- }
248
- const dbname = tag.attributes.DBNAME;
249
- // if (dbname === undefined) {
250
- // throw Error('dbname attribute is missing')
251
- // }
252
- if (dbname !== undefined && basename !== dbname + '.xml') {
253
- throw Error('filename ' + filepath + ' and dbname ' + dbname + ' do not correspond');
254
- }
255
- return tag;
256
- }
257
- async function testXml(structure, tag) {
258
- let result;
259
- try {
260
- logger.debug('testXml dbname : ' + tag.attributes.DBNAME);
261
- // structure.setInstructionType("print", new PrintInstructionType(logfilename))
262
- const moduleInstructionType = structure.scope.getInstructionType('module');
263
- if (moduleInstructionType === undefined) {
264
- throw Error('moduleInstructionType not found');
265
- }
266
- const scopeParse = new core_1.Scope(structure, structure.scope, undefined);
267
- const moduleInst = await moduleInstructionType.parseInstruction(tag, scopeParse);
268
- const scopeExecute = new core_1.Scope(structure, structure.scope, undefined);
269
- await moduleInst.execute(scopeExecute);
270
- result = moduleInst.dbModule;
271
- // if (result === undefined) {
272
- // throw Error('moduleInst.dbModule undefined')
273
- // }
274
- }
275
- catch (err) {
276
- logger.error(err);
277
- }
278
- return result;
279
- }
280
- async function saveModule(dbManager, dbModule) {
281
- logger.debug('saveModule ' + dbModule.dbname + ', description ; ' + dbModule.description);
282
- if (dbModule.id === undefined) {
283
- // dbModuleInsert
284
- await dbManager.dbModuleInsert(dbModule);
285
- }
286
- else {
287
- // dbModuleUpdate
288
- await dbManager.dbModuleUpdate(dbModule);
289
- }
290
- }