@cyklang/cli 0.2.2 → 0.3.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/AssetCommand.js +63 -23
- package/build/Cmd.d.ts +2 -2
- package/build/Cmd.js +2 -1
- package/build/DBClient.d.ts +2 -0
- package/build/DBClient.js +16 -0
- package/build/ModuleCommand.js +11 -3
- package/build/QueryCommand.js +49 -39
- package/build/RunCommand.js +21 -28
- package/build/TableCommand.js +8 -8
- package/build/TestCommand.js +21 -2
- package/build/UserCommand.js +7 -1
- package/docker.env +2 -2
- package/package.json +3 -5
- package/src/AssetCommand.ts +82 -35
- package/src/Cmd.ts +10 -6
- package/src/DBClient.ts +24 -0
- package/src/ModuleCommand.ts +17 -11
- package/src/QueryCommand.ts +56 -39
- package/src/RunCommand.ts +33 -39
- package/src/TableCommand.ts +8 -8
- package/src/TestCommand.ts +28 -3
- package/src/UserCommand.ts +7 -1
- package/test/cyklang.xsd +870 -219
- package/test/t0.output +1 -1
- package/test/t0.xml +1 -1
- package/test/t01.output +16 -2
- package/test/t01.xml +46 -8
- package/test/t09.output +1 -1
- package/test/t09.xml +1 -1
- package/test/t0__us.output +4 -0
- package/test/t0__us.xml +7 -0
- package/test/t1.ts +8 -0
- package/test/t17.output +2 -0
- package/test/t17.xml +3 -1
- package/test/t20.output +0 -0
- package/test/t20.xml +17 -1
- package/test/t21.output +2 -0
- package/test/t21.xml +39 -9
- package/test/t22.output +0 -0
- package/test/t23.output +4 -0
- package/test/t23.xml +4 -4
- package/test/t24.output +1007 -0
- package/test/t24.xml +20 -0
- package/test/t25.output +4 -0
- package/test/t25.xml +23 -0
- package/test/t26.output +5 -0
- package/test/t26.xml +35 -0
package/src/RunCommand.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Structure, Script, XmlError, DBRemote, DBManager, ModuleInstruction, parseXML } from "@cyklang/core"
|
|
1
|
+
import { Structure, Script, XmlError, DBRemote, DBManager, ModuleInstruction, parseXML, MapData } from "@cyklang/core"
|
|
2
2
|
import * as fs from "fs"
|
|
3
3
|
import { errorconsole, PrintInstructionType } from "./console"
|
|
4
4
|
import loglevel from 'loglevel'
|
|
@@ -11,15 +11,15 @@ export class RunCommand extends Cmd {
|
|
|
11
11
|
constructor() {
|
|
12
12
|
super('run')
|
|
13
13
|
this.description('run module').version('0.2')
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
.argument('<files...>', 'local module file(s) to run')
|
|
15
|
+
.action(async (files: any, options: any) => {
|
|
16
|
+
await this.runFiles(files, options)
|
|
17
|
+
})
|
|
18
18
|
}
|
|
19
19
|
async runFiles(files: string[], options: any) {
|
|
20
20
|
try {
|
|
21
21
|
await this.prologue(options)
|
|
22
|
-
for (let ind=0; ind < files.length; ind++) {
|
|
22
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
23
23
|
const result = await runFile(files[ind])
|
|
24
24
|
// if (result === false) {
|
|
25
25
|
// logger.debug('*********** FAILURE ' + process.argv[ind] + ' ***************')
|
|
@@ -40,32 +40,46 @@ async function runFile(filename: string): Promise<void> {
|
|
|
40
40
|
filename = filename.substring(0, filename.indexOf("."))
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
// skip filename with double underscore
|
|
44
|
+
if (filename.indexOf("__") !== -1) return
|
|
45
|
+
|
|
43
46
|
let xmlfilename = filename + ".xml"
|
|
44
|
-
// let logfilename = filename + ".log"
|
|
45
|
-
// let outfilename = filename + ".output"
|
|
46
47
|
|
|
47
48
|
let xml = fs.readFileSync(xmlfilename)
|
|
48
|
-
|
|
49
|
-
// fs.writeFileSync(logfilename, "")
|
|
50
49
|
|
|
51
50
|
try {
|
|
52
51
|
if (process.env.DBREMOTE_URL === undefined) throw 'DBREMOTE_URL undefined'
|
|
53
|
-
logger.trace('DBREMOTE_URL '+process.env.DBREMOTE_URL)
|
|
52
|
+
logger.trace('DBREMOTE_URL ' + process.env.DBREMOTE_URL)
|
|
54
53
|
const structure = new Structure()
|
|
55
54
|
const nodeCrypto = new NodeCrypto()
|
|
56
55
|
const dbRemote = new DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto)
|
|
57
56
|
const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD)
|
|
58
57
|
const dbManager = new DBManager(structure.scope, dbRemote)
|
|
59
58
|
await dbManager.initialize()
|
|
60
|
-
const tag = parseXML(xmlfilename, xml.toString())
|
|
61
|
-
const moduleInstruction = new ModuleInstruction(tag, dbManager)
|
|
62
|
-
await moduleInstruction.parse(structure.scope)
|
|
63
|
-
await moduleInstruction.execute(structure.scope)
|
|
64
59
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
const user_lang = login.content.user_lang
|
|
61
|
+
if (user_lang && user_lang.trim() !== '') {
|
|
62
|
+
|
|
63
|
+
const langfilename = filename + "__" + user_lang + ".xml"
|
|
64
|
+
|
|
65
|
+
if (fs.existsSync(langfilename)) {
|
|
66
|
+
const langXml = fs.readFileSync(langfilename)
|
|
67
|
+
const tag = parseXML(xmlfilename, langXml.toString())
|
|
68
|
+
const modLang = new ModuleInstruction(tag, dbManager)
|
|
69
|
+
await modLang.parse(structure.scope)
|
|
70
|
+
await modLang.execute(structure.scope)
|
|
71
|
+
|
|
72
|
+
const langMap = modLang.objectData?.variables.getData(user_lang)
|
|
73
|
+
|
|
74
|
+
if (langMap !== null && langMap !== undefined) {
|
|
75
|
+
structure.mapLang = langMap as MapData
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let script = new Script(structure.scope, xmlfilename, xml.toString())
|
|
81
|
+
await script.parseInstructions()
|
|
82
|
+
await script.execute()
|
|
69
83
|
}
|
|
70
84
|
catch (err) {
|
|
71
85
|
|
|
@@ -75,24 +89,4 @@ async function runFile(filename: string): Promise<void> {
|
|
|
75
89
|
}
|
|
76
90
|
console.log(err)
|
|
77
91
|
}
|
|
78
|
-
|
|
79
|
-
// let log = fs.readFileSync(logfilename)
|
|
80
|
-
// if (fs.existsSync(outfilename) === true ) {
|
|
81
|
-
// let out = fs.readFileSync(outfilename)
|
|
82
|
-
|
|
83
|
-
// if (log.toString() === out.toString()) {
|
|
84
|
-
// console.log("test " + xmlfilename + " SUCCESS")
|
|
85
|
-
// result = true
|
|
86
|
-
// }
|
|
87
|
-
// else {
|
|
88
|
-
// console.log("test " + xmlfilename + " FAILURE")
|
|
89
|
-
// result = false
|
|
90
|
-
// }
|
|
91
|
-
// }
|
|
92
|
-
// else {
|
|
93
|
-
// console.log("test " + xmlfilename + " output file not found ")
|
|
94
|
-
// result = false
|
|
95
|
-
// }
|
|
96
|
-
|
|
97
|
-
// return result
|
|
98
92
|
}
|
package/src/TableCommand.ts
CHANGED
|
@@ -20,8 +20,8 @@ export class TableCommand extends Command {
|
|
|
20
20
|
this.addCommand(new TableImportCmd())
|
|
21
21
|
this.addCommand(new TableList('list', 'list database tables'))
|
|
22
22
|
this.addCommand(new TableList('l', '(l)ist database tables'))
|
|
23
|
-
this.addCommand(new
|
|
24
|
-
this.addCommand(new
|
|
23
|
+
this.addCommand(new TableData('data', 'table (d)ata'))
|
|
24
|
+
this.addCommand(new TableData('d', 'table (d)ata'))
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -273,30 +273,30 @@ class TableList extends Cmd {
|
|
|
273
273
|
|
|
274
274
|
const dbClient = new DBClient(this.dbManager)
|
|
275
275
|
dbClient.selectFromTable('List of Tables', 'cyk_table',
|
|
276
|
-
{ fields: 'table_id,table_name,
|
|
276
|
+
{ fields: 'table_id,table_name,table_auth,table_access,table_description', sort: options.sort || '1' }
|
|
277
277
|
)
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
//--------------------------------------------------------------------------------------------------------------------
|
|
282
|
-
// class
|
|
282
|
+
// class TableData
|
|
283
283
|
//--------------------------------------------------------------------------------------------------------------------
|
|
284
284
|
|
|
285
|
-
class
|
|
285
|
+
class TableData extends Cmd {
|
|
286
286
|
|
|
287
287
|
constructor(name: string, description: string) {
|
|
288
288
|
super(name)
|
|
289
289
|
this.description(description)
|
|
290
|
-
.argument('<table>', 'table
|
|
290
|
+
.argument('<table>', 'table name')
|
|
291
291
|
.option('--where <clause_where_sql>', 'criteria in SQL syntax')
|
|
292
292
|
.option('-s --sort <columns>', 'sort by columns positions (begins by 0) separated by comma')
|
|
293
293
|
.option('-w --width <colwidth>', 'columns widths separated by comma')
|
|
294
294
|
.action(async (table, options) => {
|
|
295
|
-
this.
|
|
295
|
+
this.commandData(table, options)
|
|
296
296
|
})
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
async
|
|
299
|
+
async commandData(table: string, options: any) {
|
|
300
300
|
try {
|
|
301
301
|
await this.prologue(options)
|
|
302
302
|
if (this.dbManager === undefined) throw 'dbManager undefined'
|
package/src/TestCommand.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Structure, Script, XmlError, DBRemote, DBManager } from "@cyklang/core"
|
|
1
|
+
import { Structure, Script, XmlError, DBRemote, DBManager, MapData, ModuleInstruction, parseXML } from "@cyklang/core"
|
|
2
2
|
import * as fs from "fs"
|
|
3
3
|
import { errorconsole, PrintInstructionType } from "./console"
|
|
4
4
|
import loglevel from 'loglevel'
|
|
@@ -18,11 +18,11 @@ export class TestCommand extends Cmd {
|
|
|
18
18
|
}
|
|
19
19
|
async testRun(files: string[], options: any) {
|
|
20
20
|
try {
|
|
21
|
-
await this.prologue(options)
|
|
21
|
+
const signinResponse = await this.prologue(options)
|
|
22
22
|
for (let ind=0; ind < files.length; ind++) {
|
|
23
23
|
const result = await testfile(files[ind])
|
|
24
24
|
if (result === false) {
|
|
25
|
-
logger.debug('*********** FAILURE ' +
|
|
25
|
+
logger.debug('*********** FAILURE ' + files[ind] + ' ***************')
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -41,6 +41,9 @@ async function testfile(filename: string): Promise<boolean> {
|
|
|
41
41
|
filename = filename.substring(0, filename.indexOf("."))
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
// skip filename with double underscore
|
|
45
|
+
if (filename.indexOf("__") !== -1) return true
|
|
46
|
+
|
|
44
47
|
let xmlfilename = filename + ".xml"
|
|
45
48
|
let logfilename = filename + ".log"
|
|
46
49
|
let outfilename = filename + ".output"
|
|
@@ -62,6 +65,28 @@ async function testfile(filename: string): Promise<boolean> {
|
|
|
62
65
|
await dbManager.initialize()
|
|
63
66
|
structure.scope.addInstructionType(new PrintInstructionType(logfilename))
|
|
64
67
|
let script = new Script(structure.scope, xmlfilename, xml.toString())
|
|
68
|
+
const user_lang = login.content.user_lang
|
|
69
|
+
if (user_lang && user_lang.trim() !== '') {
|
|
70
|
+
|
|
71
|
+
const langfilename = filename + "__" + user_lang + ".xml"
|
|
72
|
+
|
|
73
|
+
if (fs.existsSync(langfilename)) {
|
|
74
|
+
const langXml = fs.readFileSync(langfilename)
|
|
75
|
+
const tag = parseXML(xmlfilename, langXml.toString())
|
|
76
|
+
const modLang = new ModuleInstruction(tag, dbManager)
|
|
77
|
+
await modLang.parse(structure.scope)
|
|
78
|
+
await modLang.execute(structure.scope)
|
|
79
|
+
|
|
80
|
+
const langMap = modLang.objectData?.variables.getData(user_lang)
|
|
81
|
+
|
|
82
|
+
if (langMap !== null && langMap !== undefined) {
|
|
83
|
+
structure.mapLang = langMap as MapData
|
|
84
|
+
|
|
85
|
+
outfilename = filename + "__" + user_lang + ".output"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
65
90
|
await script.parseInstructions()
|
|
66
91
|
await script.execute()
|
|
67
92
|
// console.log(JSON.stringify(script.block.toString()))
|
package/src/UserCommand.ts
CHANGED
|
@@ -31,6 +31,7 @@ interface Options {
|
|
|
31
31
|
disable: boolean | undefined
|
|
32
32
|
env: string | undefined
|
|
33
33
|
sort: string | undefined
|
|
34
|
+
lang: string | undefined
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
class UserAddCmd extends Cmd {
|
|
@@ -43,6 +44,7 @@ class UserAddCmd extends Cmd {
|
|
|
43
44
|
.option('-a --access <acl>', 'access control list')
|
|
44
45
|
.option('-m --module <module_name>', 'module to launch by default')
|
|
45
46
|
.option('-d --disable', 'user not abled to connect')
|
|
47
|
+
.option('-l --lang <language>', 'user language')
|
|
46
48
|
.action(async (options: Options) => {
|
|
47
49
|
const dbUser = new DBUser()
|
|
48
50
|
dbUser.name = options.name
|
|
@@ -51,6 +53,7 @@ class UserAddCmd extends Cmd {
|
|
|
51
53
|
dbUser.access = options.access
|
|
52
54
|
dbUser.appli = options.module
|
|
53
55
|
dbUser.disable = options.disable || false
|
|
56
|
+
dbUser.lang = options.lang
|
|
54
57
|
await this.commandAdd(dbUser, options)
|
|
55
58
|
})
|
|
56
59
|
}
|
|
@@ -83,7 +86,7 @@ class UserListCmd extends Cmd {
|
|
|
83
86
|
|
|
84
87
|
const dbClient = new DBClient(this.dbManager)
|
|
85
88
|
dbClient.selectFromTable('List of users', 'cyk_user',
|
|
86
|
-
{ fields: 'user_id,user_name,user_email,user_access,user_appli,user_disable', sort: options.sort || '1' })
|
|
89
|
+
{ fields: 'user_id,user_name,user_email,user_access,user_appli,user_lang,user_disable', sort: options.sort || '1' })
|
|
87
90
|
|
|
88
91
|
}
|
|
89
92
|
catch (err) {
|
|
@@ -102,6 +105,7 @@ class UserUpdateCmd extends Cmd {
|
|
|
102
105
|
.option('-e --email <email>', 'user email address')
|
|
103
106
|
.option('-a --access <acl>', 'access control list')
|
|
104
107
|
.option('-m --module <module_name>', 'module to launch by default')
|
|
108
|
+
.option('-l --lang <language>', 'user language')
|
|
105
109
|
.option('-d --disable', 'user not able to connect')
|
|
106
110
|
.action(async (options: Options) => {
|
|
107
111
|
const dbUser = new DBUser()
|
|
@@ -110,6 +114,7 @@ class UserUpdateCmd extends Cmd {
|
|
|
110
114
|
dbUser.email = options.email
|
|
111
115
|
dbUser.access = options.access
|
|
112
116
|
dbUser.appli = options.module
|
|
117
|
+
dbUser.lang = options.lang
|
|
113
118
|
dbUser.disable = options.disable
|
|
114
119
|
await this.commandUpdate(dbUser, options)
|
|
115
120
|
})
|
|
@@ -126,6 +131,7 @@ class UserUpdateCmd extends Cmd {
|
|
|
126
131
|
if (dbUser2.email !== undefined) dbUser1.email = dbUser2.email
|
|
127
132
|
if (dbUser2.access !== undefined) dbUser1.access = dbUser2.access
|
|
128
133
|
if (dbUser2.appli !== undefined) dbUser1.appli = dbUser2.appli
|
|
134
|
+
if (dbUser2.lang !== undefined) dbUser1.lang = dbUser2.lang
|
|
129
135
|
if (dbUser2.disable !== undefined) dbUser1.disable = dbUser2.disable
|
|
130
136
|
// logger.debug('dbUser1 before dbUserUpdate : ', dbUser1)
|
|
131
137
|
await this.dbManager.dbUserUpdate(dbUser1)
|