@cyklang/cli 0.1.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.
Files changed (51) hide show
  1. package/README.md +1 -0
  2. package/aws-ecs.env +38 -0
  3. package/build/Cmd.d.ts +7 -0
  4. package/build/Cmd.js +35 -0
  5. package/build/DBClient.d.ts +10 -0
  6. package/build/DBClient.js +205 -0
  7. package/build/InitCommand.d.ts +9 -0
  8. package/build/InitCommand.js +122 -0
  9. package/build/ModuleCommand.d.ts +5 -0
  10. package/build/ModuleCommand.js +202 -0
  11. package/build/NodeCrypto.d.ts +5 -0
  12. package/build/NodeCrypto.js +49 -0
  13. package/build/QueryCommand.d.ts +5 -0
  14. package/build/QueryCommand.js +62 -0
  15. package/build/RunCommand.d.ts +5 -0
  16. package/build/RunCommand.js +112 -0
  17. package/build/TableCommand.d.ts +5 -0
  18. package/build/TableCommand.js +140 -0
  19. package/build/TestCommand copy.d.ts +5 -0
  20. package/build/TestCommand copy.js +111 -0
  21. package/build/TestCommand.d.ts +5 -0
  22. package/build/TestCommand.js +111 -0
  23. package/build/UserCommand.d.ts +5 -0
  24. package/build/UserCommand.js +202 -0
  25. package/build/console.d.ts +13 -0
  26. package/build/console.js +109 -0
  27. package/build/cykquery.d.ts +2 -0
  28. package/build/cykquery.js +145 -0
  29. package/build/cyktable.d.ts +2 -0
  30. package/build/cyktable.js +133 -0
  31. package/build/index.d.ts +2 -0
  32. package/build/index.js +32 -0
  33. package/build/module.d.ts +2 -0
  34. package/build/module.js +290 -0
  35. package/docker-compose.ecs.yml +44 -0
  36. package/docker-compose.yml +43 -0
  37. package/docker.env +38 -0
  38. package/package.json +38 -0
  39. package/src/Cmd.ts +33 -0
  40. package/src/DBClient.ts +220 -0
  41. package/src/InitCommand.ts +107 -0
  42. package/src/ModuleCommand.ts +192 -0
  43. package/src/NodeCrypto.ts +60 -0
  44. package/src/QueryCommand.ts +62 -0
  45. package/src/RunCommand.ts +98 -0
  46. package/src/TableCommand.ts +127 -0
  47. package/src/TestCommand.ts +98 -0
  48. package/src/UserCommand.ts +203 -0
  49. package/src/console.ts +97 -0
  50. package/src/index.ts +30 -0
  51. package/tsconfig.json +12 -0
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NodeCrypto = void 0;
7
+ const crypto_1 = require("crypto");
8
+ const loglevel_1 = require("loglevel");
9
+ const core_1 = require("@cyklang/core");
10
+ const pako_1 = __importDefault(require("pako"));
11
+ const util_1 = require("util");
12
+ const logger = (0, loglevel_1.getLogger)('NodeCrypto.ts');
13
+ logger.setLevel('debug');
14
+ const algorithm = 'aes-128-cbc';
15
+ const iv_length = 16;
16
+ class NodeCrypto {
17
+ // last_iv: Buffer | undefined
18
+ async encrypt(plain) {
19
+ const deflatedData = pako_1.default.deflate(plain);
20
+ // logger.debug('deflatedData : ', deflatedData[0], deflatedData[1])
21
+ const iv = (0, crypto_1.randomBytes)(iv_length);
22
+ // this.last_iv = iv
23
+ // logger.debug("encrypt iv " + iv.toString('hex'))
24
+ const cipher = (0, crypto_1.createCipheriv)(algorithm, core_1.cipherKey, iv);
25
+ let result = cipher.update(deflatedData, undefined, "hex");
26
+ result += cipher.final("hex");
27
+ result += iv.toString('hex');
28
+ return result;
29
+ }
30
+ async decrypt(encoded) {
31
+ const iv_hex = encoded.substring(encoded.length - 2 * iv_length);
32
+ const encryptedData = encoded.substring(0, encoded.length - 2 * iv_length);
33
+ // logger.debug("decrypt iv " + iv_hex)
34
+ const iv = Buffer.from(iv_hex, 'hex');
35
+ // if (this.last_iv === undefined) throw 'last_iv undefined'
36
+ // if (Buffer.compare(iv, this.last_iv) !== 0) throw 'iv and last_iv are different'
37
+ const decipher = (0, crypto_1.createDecipheriv)(algorithm, core_1.cipherKey, iv);
38
+ let deflatedData1 = decipher.update(encryptedData, 'hex');
39
+ const deflatedData2 = decipher.final();
40
+ const deflatedData = Buffer.concat([deflatedData1, deflatedData2]);
41
+ let inflatedData = deflatedData;
42
+ if (deflatedData[0] === 0x78 && deflatedData[1] === 0x9c) {
43
+ inflatedData = Buffer.from(pako_1.default.inflate(deflatedData));
44
+ }
45
+ const result = (new util_1.TextDecoder()).decode(inflatedData);
46
+ return result;
47
+ }
48
+ }
49
+ exports.NodeCrypto = NodeCrypto;
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ts-node
2
+ import { Command } from 'commander';
3
+ export declare class QueryCommand extends Command {
4
+ constructor(name: string);
5
+ }
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ts-node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.QueryCommand = void 0;
8
+ const core_1 = require("@cyklang/core");
9
+ const loglevel_1 = __importDefault(require("loglevel"));
10
+ const commander_1 = require("commander");
11
+ const logger = loglevel_1.default.getLogger("QueryCommand.ts");
12
+ logger.setLevel("debug");
13
+ class QueryCommand extends commander_1.Command {
14
+ constructor(name) {
15
+ super(name);
16
+ }
17
+ }
18
+ 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');
27
+ }
28
+ if (basename !== name + '.xml') {
29
+ throw Error('filename ' + filepath + ' and name ' + name + ' do not correspond');
30
+ }
31
+ return tag;
32
+ }
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);
46
+ }
47
+ catch (err) {
48
+ logger.error(err);
49
+ }
50
+ }
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
+ }
@@ -0,0 +1,5 @@
1
+ import { Cmd } from "./Cmd";
2
+ export declare class RunCommand extends Cmd {
3
+ constructor();
4
+ runFiles(files: string[], options: any): Promise<void>;
5
+ }
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.RunCommand = void 0;
26
+ const core_1 = require("@cyklang/core");
27
+ const fs = __importStar(require("fs"));
28
+ const console_1 = require("./console");
29
+ const loglevel_1 = __importDefault(require("loglevel"));
30
+ const NodeCrypto_1 = require("./NodeCrypto");
31
+ const Cmd_1 = require("./Cmd");
32
+ loglevel_1.default.setLevel('debug');
33
+ const logger = loglevel_1.default.getLogger('RunCommand.ts');
34
+ class RunCommand extends Cmd_1.Cmd {
35
+ constructor() {
36
+ super('run');
37
+ this.description('run module').version('0.2')
38
+ .argument('<files...>', 'local module file(s) to run')
39
+ .action(async (files, options) => {
40
+ await this.runFiles(files, options);
41
+ });
42
+ }
43
+ async runFiles(files, options) {
44
+ try {
45
+ await this.prologue(options);
46
+ for (let ind = 0; ind < files.length; ind++) {
47
+ const result = await runFile(files[ind]);
48
+ // if (result === false) {
49
+ // logger.debug('*********** FAILURE ' + process.argv[ind] + ' ***************')
50
+ // }
51
+ }
52
+ }
53
+ catch (err) {
54
+ logger.error(err);
55
+ }
56
+ }
57
+ }
58
+ exports.RunCommand = RunCommand;
59
+ async function runFile(filename) {
60
+ let result;
61
+ if (filename.indexOf(".") !== -1) {
62
+ filename = filename.substring(0, filename.indexOf("."));
63
+ }
64
+ let xmlfilename = filename + ".xml";
65
+ // let logfilename = filename + ".log"
66
+ // let outfilename = filename + ".output"
67
+ let xml = fs.readFileSync(xmlfilename);
68
+ // fs.writeFileSync(logfilename, "")
69
+ try {
70
+ if (process.env.DBREMOTE_URL === undefined)
71
+ throw 'DBREMOTE_URL undefined';
72
+ logger.trace('DBREMOTE_URL ' + process.env.DBREMOTE_URL);
73
+ const structure = new core_1.Structure();
74
+ const nodeCrypto = new NodeCrypto_1.NodeCrypto();
75
+ const dbRemote = new core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto);
76
+ const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
77
+ const dbManager = new core_1.DBManager(structure.scope, dbRemote);
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()
87
+ }
88
+ catch (err) {
89
+ if (err instanceof core_1.XmlError) {
90
+ let xmlError = err;
91
+ (0, console_1.errorconsole)(xmlError);
92
+ }
93
+ console.log(err);
94
+ }
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
+ }
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ts-node
2
+ import { Command } from "commander";
3
+ export declare class TableCommand extends Command {
4
+ constructor(name: string);
5
+ }
@@ -0,0 +1,140 @@
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
+ exports.TableCommand = void 0;
27
+ const fs = __importStar(require("fs"));
28
+ const loglevel_1 = __importDefault(require("loglevel"));
29
+ const commander_1 = require("commander");
30
+ const child_process_1 = require("child_process");
31
+ const Cmd_1 = require("./Cmd");
32
+ const logger = loglevel_1.default.getLogger("TableCommand.ts");
33
+ logger.setLevel("debug");
34
+ class TableCommand extends commander_1.Command {
35
+ constructor(name) {
36
+ super(name);
37
+ this.description('import/export table rows').version('0.1');
38
+ this.addCommand(new TableExportCmd());
39
+ }
40
+ }
41
+ exports.TableCommand = TableCommand;
42
+ class TableExportCmd extends Cmd_1.Cmd {
43
+ constructor() {
44
+ super('export');
45
+ this.description('export to CSV file(s)')
46
+ .argument('<tables...>', 'table(s) to export')
47
+ .option('-f --file <file>', 'name of the file to create, defaults to <table_name>.csv')
48
+ .option('-d --dir <directory>', 'name of the directory where to create exported files')
49
+ .action(async (tables, options) => this.commandExport(tables, options));
50
+ }
51
+ async commandExport(tables, options) {
52
+ await this.prologue(options);
53
+ if (this.dbManager === undefined)
54
+ throw 'dbManager undefined';
55
+ await commandImportExport(this.dbManager, 'to', tables, options);
56
+ }
57
+ }
58
+ class TableImportCmd extends Cmd_1.Cmd {
59
+ constructor() {
60
+ super('import');
61
+ this.description('import from CSV file(s)')
62
+ .option('-f --file <file>', 'name of the file to import, defaults to <table_name>.csv')
63
+ .option('-d --dir <directory>', 'name of the directory where to find files to import')
64
+ .action(async (tables, options) => this.commandImport(tables, options));
65
+ }
66
+ async commandImport(tables, options) {
67
+ await this.prologue(options);
68
+ if (this.dbManager === undefined)
69
+ throw 'dbManager undefined';
70
+ await commandImportExport(this.dbManager, 'from', tables, options);
71
+ }
72
+ }
73
+ const commandImportExport = async (dbManager, direction, tables, options) => {
74
+ logger.debug('tables : ', tables, 'options : ', options);
75
+ try {
76
+ if (options.file === undefined && options.dir === undefined)
77
+ throw '--file or --dir mandatory';
78
+ if (options.file !== undefined && options.dir !== undefined)
79
+ throw '--file and --dir are mutually exclusive';
80
+ if (tables.length === 0)
81
+ throw 'at least one table name is mandatory';
82
+ if (tables.length > 1 && options.dir === undefined)
83
+ throw 'for multiple tables, --dir is mandatory';
84
+ for (let indi = 0; indi < tables.length; indi++) {
85
+ const tableName = tables[indi];
86
+ const dbTable = await dbManager.dbTableExist(tableName);
87
+ if (dbTable === undefined) {
88
+ logger.info('table ' + tableName + ' not found');
89
+ continue;
90
+ }
91
+ let lcols;
92
+ for (let indj = 0; indj < dbTable.columns.length; indj++) {
93
+ const dbColumn = dbTable.columns[indj];
94
+ if (lcols === undefined) {
95
+ lcols = "(";
96
+ }
97
+ else {
98
+ lcols += ",";
99
+ }
100
+ lcols += dbColumn.name;
101
+ }
102
+ lcols += ")";
103
+ let psql_cmd = "psql -c";
104
+ if (process.env.HEROKU_CLI !== undefined) {
105
+ psql_cmd = process.env.HEROKU_CLI + ' -c ';
106
+ }
107
+ let filename;
108
+ if (options.file !== undefined) {
109
+ if (fs.existsSync(options.file) && fs.lstatSync(options.file).isDirectory())
110
+ throw '--file ' + options.file + ' is a directory';
111
+ filename = options.file;
112
+ }
113
+ else if (options.dir === undefined)
114
+ throw '--file and --dir unspecified';
115
+ else if (fs.existsSync(options.dir) === false)
116
+ throw 'directory ' + options.dir + ' does not exist';
117
+ else if (fs.lstatSync(options.dir).isFile()) {
118
+ logger.debug("--dir " + options.dir + " is a file ");
119
+ }
120
+ else {
121
+ let directory = options.dir.trim();
122
+ if (directory[directory.length - 1] !== '/') {
123
+ directory += '/';
124
+ }
125
+ filename = directory + tableName + '.csv';
126
+ }
127
+ let copy_cmd = "\\copy " + tableName + lcols + direction + " '" + filename + "' csv header";
128
+ const shell_cmd = psql_cmd + '"' + copy_cmd + '"';
129
+ logger.debug(shell_cmd);
130
+ const child = (0, child_process_1.spawn)(shell_cmd.trim(), { stdio: 'inherit', shell: true });
131
+ // exec(shell_cmd.trim(), (error, stdout, stderr) => {
132
+ // if (error) throw error
133
+ // logger.debug(stdout, stderr)
134
+ // })
135
+ }
136
+ }
137
+ catch (err) {
138
+ logger.error(err);
139
+ }
140
+ };
@@ -0,0 +1,5 @@
1
+ import { Cmd } from "./Cmd";
2
+ export declare class TestCommand extends Cmd {
3
+ constructor();
4
+ testRun(files: string[], options: any): Promise<void>;
5
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.TestCommand = void 0;
26
+ const core_1 = require("@cyklang/core");
27
+ const fs = __importStar(require("fs"));
28
+ const console_1 = require("./console");
29
+ const loglevel_1 = __importDefault(require("loglevel"));
30
+ const NodeCrypto_1 = require("./NodeCrypto");
31
+ const Cmd_1 = require("./Cmd");
32
+ loglevel_1.default.setLevel('debug');
33
+ const logger = loglevel_1.default.getLogger('TestCommand.ts');
34
+ class TestCommand extends Cmd_1.Cmd {
35
+ constructor() {
36
+ super('test');
37
+ this.description('test script').version('0.1')
38
+ .argument('<files...>', 'local module file(s) to test run')
39
+ .action(async (files, options) => {
40
+ await this.testRun(files, options);
41
+ });
42
+ }
43
+ async testRun(files, options) {
44
+ try {
45
+ await this.prologue(options);
46
+ for (let ind = 0; ind < files.length; ind++) {
47
+ const result = await testfile(files[ind]);
48
+ if (result === false) {
49
+ logger.debug('*********** FAILURE ' + process.argv[ind] + ' ***************');
50
+ }
51
+ }
52
+ }
53
+ catch (err) {
54
+ logger.error(err);
55
+ }
56
+ }
57
+ }
58
+ exports.TestCommand = TestCommand;
59
+ async function testfile(filename) {
60
+ let result;
61
+ if (filename.indexOf(".") !== -1) {
62
+ filename = filename.substring(0, filename.indexOf("."));
63
+ }
64
+ let xmlfilename = filename + ".xml";
65
+ let logfilename = filename + ".log";
66
+ let outfilename = filename + ".output";
67
+ let xml = fs.readFileSync(xmlfilename);
68
+ fs.writeFileSync(logfilename, "");
69
+ //console.log(xml.toString())
70
+ try {
71
+ if (process.env.DBREMOTE_URL === undefined)
72
+ throw 'DBREMOTE_URL undefined';
73
+ logger.trace('DBREMOTE_URL ' + process.env.DBREMOTE_URL);
74
+ const structure = new core_1.Structure();
75
+ const nodeCrypto = new NodeCrypto_1.NodeCrypto();
76
+ const dbRemote = new core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto);
77
+ const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
78
+ //const dbRemote = new DBRemote(structure, 'https://cyk-postgres.herokuapp.com')
79
+ const dbManager = new core_1.DBManager(structure.scope, dbRemote);
80
+ await dbManager.initialize();
81
+ structure.scope.addInstructionType(new console_1.PrintInstructionType(logfilename));
82
+ let script = new core_1.Script(structure.scope, xmlfilename, xml.toString());
83
+ await script.parseInstructions();
84
+ await script.execute();
85
+ // console.log(JSON.stringify(script.block.toString()))
86
+ }
87
+ catch (err) {
88
+ if (err instanceof core_1.XmlError) {
89
+ let xmlError = err;
90
+ (0, console_1.errorconsole)(xmlError);
91
+ }
92
+ console.log(err);
93
+ }
94
+ let log = fs.readFileSync(logfilename);
95
+ if (fs.existsSync(outfilename) === true) {
96
+ let out = fs.readFileSync(outfilename);
97
+ if (log.toString() === out.toString()) {
98
+ console.log("test " + xmlfilename + " SUCCESS");
99
+ result = true;
100
+ }
101
+ else {
102
+ console.log("test " + xmlfilename + " FAILURE");
103
+ result = false;
104
+ }
105
+ }
106
+ else {
107
+ console.log("test " + xmlfilename + " output file not found ");
108
+ result = false;
109
+ }
110
+ return result;
111
+ }
@@ -0,0 +1,5 @@
1
+ import { Cmd } from "./Cmd";
2
+ export declare class TestCommand extends Cmd {
3
+ constructor();
4
+ testRun(files: string[], options: any): Promise<void>;
5
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.TestCommand = void 0;
26
+ const core_1 = require("@cyklang/core");
27
+ const fs = __importStar(require("fs"));
28
+ const console_1 = require("./console");
29
+ const loglevel_1 = __importDefault(require("loglevel"));
30
+ const NodeCrypto_1 = require("./NodeCrypto");
31
+ const Cmd_1 = require("./Cmd");
32
+ loglevel_1.default.setLevel('debug');
33
+ const logger = loglevel_1.default.getLogger('TestCommand.ts');
34
+ class TestCommand extends Cmd_1.Cmd {
35
+ constructor() {
36
+ super('test');
37
+ this.description('test script').version('0.1')
38
+ .argument('<files...>', 'local module file(s) to test run')
39
+ .action(async (files, options) => {
40
+ await this.testRun(files, options);
41
+ });
42
+ }
43
+ async testRun(files, options) {
44
+ try {
45
+ await this.prologue(options);
46
+ for (let ind = 0; ind < files.length; ind++) {
47
+ const result = await testfile(files[ind]);
48
+ if (result === false) {
49
+ logger.debug('*********** FAILURE ' + process.argv[ind] + ' ***************');
50
+ }
51
+ }
52
+ }
53
+ catch (err) {
54
+ logger.error(err);
55
+ }
56
+ }
57
+ }
58
+ exports.TestCommand = TestCommand;
59
+ async function testfile(filename) {
60
+ let result;
61
+ if (filename.indexOf(".") !== -1) {
62
+ filename = filename.substring(0, filename.indexOf("."));
63
+ }
64
+ let xmlfilename = filename + ".xml";
65
+ let logfilename = filename + ".log";
66
+ let outfilename = filename + ".output";
67
+ let xml = fs.readFileSync(xmlfilename);
68
+ fs.writeFileSync(logfilename, "");
69
+ //console.log(xml.toString())
70
+ try {
71
+ if (process.env.DBREMOTE_URL === undefined)
72
+ throw 'DBREMOTE_URL undefined';
73
+ logger.trace('DBREMOTE_URL ' + process.env.DBREMOTE_URL);
74
+ const structure = new core_1.Structure();
75
+ const nodeCrypto = new NodeCrypto_1.NodeCrypto();
76
+ const dbRemote = new core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto);
77
+ const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
78
+ //const dbRemote = new DBRemote(structure, 'https://cyk-postgres.herokuapp.com')
79
+ const dbManager = new core_1.DBManager(structure.scope, dbRemote);
80
+ await dbManager.initialize();
81
+ structure.scope.addInstructionType(new console_1.PrintInstructionType(logfilename));
82
+ let script = new core_1.Script(structure.scope, xmlfilename, xml.toString());
83
+ await script.parseInstructions();
84
+ await script.execute();
85
+ // console.log(JSON.stringify(script.block.toString()))
86
+ }
87
+ catch (err) {
88
+ if (err instanceof core_1.XmlError) {
89
+ let xmlError = err;
90
+ (0, console_1.errorconsole)(xmlError);
91
+ }
92
+ console.log(err);
93
+ }
94
+ let log = fs.readFileSync(logfilename);
95
+ if (fs.existsSync(outfilename) === true) {
96
+ let out = fs.readFileSync(outfilename);
97
+ if (log.toString() === out.toString()) {
98
+ console.log("test " + xmlfilename + " SUCCESS");
99
+ result = true;
100
+ }
101
+ else {
102
+ console.log("test " + xmlfilename + " FAILURE");
103
+ result = false;
104
+ }
105
+ }
106
+ else {
107
+ console.log("test " + xmlfilename + " output file not found ");
108
+ result = false;
109
+ }
110
+ return result;
111
+ }
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ts-node
2
+ import { Command } from 'commander';
3
+ export declare class UserCommand extends Command {
4
+ constructor(name: string);
5
+ }