@cyklang/cli 0.8.0 → 0.9.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.
- package/build/CronCommand.d.ts +4 -0
- package/build/CronCommand.js +113 -0
- package/build/QueryCommand.js +42 -0
- package/build/TestCommand.js +2 -1
- package/build/console.js +1 -0
- package/build/index.js +4 -1
- package/clean_test.sh +20 -0
- package/package.json +3 -3
- package/run_test.sh +3 -3
- package/src/CronCommand.ts +113 -0
- package/src/QueryCommand.ts +42 -0
- package/src/TestCommand.ts +11 -10
- package/src/console.ts +1 -0
- package/src/index.ts +4 -1
- package/test/db/schema.xsd +74 -0
- package/test/db/t10.xml +4 -25
- package/test/db/t13.xml +15 -2
- package/test/db/t14.xml +1 -1
- package/test/db/t15.output +8 -2
- package/test/db/t15.xml +12 -10
- package/test/db/test_schema.xml +15 -0
- package/test/t27.output +2 -0
- package/test/t27.xml +22 -1
- package/build/TableData.d.ts +0 -5
- package/build/TableData.js +0 -61
- package/build/TestCommand copy.d.ts +0 -5
- package/build/TestCommand copy.js +0 -111
- package/build/cykquery.d.ts +0 -2
- package/build/cykquery.js +0 -145
- package/build/cyktable.d.ts +0 -2
- package/build/cyktable.js +0 -133
- package/build/module.d.ts +0 -2
- package/build/module.js +0 -290
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
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
|
-
}
|