@cyklang/cli 0.2.3 → 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 +27 -8
- package/build/Cmd.d.ts +2 -2
- package/build/Cmd.js +14 -18
- package/build/DBClient.d.ts +1 -0
- package/build/DBClient.js +4 -0
- package/build/ModuleCommand.js +2 -2
- package/build/QueryCommand.js +49 -39
- package/build/RunCommand.js +21 -28
- package/build/TableCommand.js +8 -8
- package/build/TestCommand.js +20 -1
- package/build/UserCommand.js +7 -1
- package/package.json +3 -5
- package/src/AssetCommand.ts +33 -10
- package/src/Cmd.ts +20 -22
- package/src/DBClient.ts +8 -0
- package/src/ModuleCommand.ts +2 -2
- package/src/QueryCommand.ts +56 -39
- package/src/RunCommand.ts +33 -39
- package/src/TableCommand.ts +8 -8
- package/src/TestCommand.ts +27 -2
- 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/t0__us.output +4 -0
- package/test/t0__us.xml +7 -0
- package/test/t1.ts +8 -0
- package/test/t20.xml +16 -0
- package/test/t21.output +2 -0
- package/test/t21.xml +31 -7
- package/test/t23.output +0 -44
- package/test/t23.xml +1 -1
- package/test/t26.output +5 -0
- package/test/t26.xml +35 -0
package/src/AssetCommand.ts
CHANGED
|
@@ -38,7 +38,7 @@ class AssetList extends Cmd {
|
|
|
38
38
|
|
|
39
39
|
const dbClient = new DBClient(this.dbManager)
|
|
40
40
|
dbClient.selectFromTable('List of Assets', 'cyk_asset',
|
|
41
|
-
{ fields: 'asset_id,asset_route,
|
|
41
|
+
{ fields: 'asset_id,asset_route,asset_auth,asset_access,asset_mimetype,asset_last_update', sort: options.sort || '1' }
|
|
42
42
|
)
|
|
43
43
|
}
|
|
44
44
|
catch (err) {
|
|
@@ -54,13 +54,15 @@ class AssetList extends Cmd {
|
|
|
54
54
|
interface FileDescriptor {
|
|
55
55
|
path: string
|
|
56
56
|
mtime: Date
|
|
57
|
+
id?: number
|
|
57
58
|
}
|
|
58
59
|
class AssetUpload extends Cmd {
|
|
59
60
|
|
|
60
61
|
constructor(name: string, description: string) {
|
|
61
62
|
super(name)
|
|
62
63
|
this.description(description)
|
|
63
|
-
.option('-d --dest <destination>', '
|
|
64
|
+
.option('-d --dest <destination>', 'destination path, directory name')
|
|
65
|
+
.option('-c --clean', 'clean destination path before uploading')
|
|
64
66
|
.option('-y --yes', 'upload list is automatically confirmed')
|
|
65
67
|
.argument('[sources...]', 'local files or directories to upload as assets to the server')
|
|
66
68
|
.action(async (sources: any, options: any) => {
|
|
@@ -92,6 +94,10 @@ class AssetUpload extends Cmd {
|
|
|
92
94
|
if (dest.substring(0, 1) !== '/') dest = '/' + dest
|
|
93
95
|
if (dest.substring(dest.length - 1) !== '/') dest = dest + '/'
|
|
94
96
|
|
|
97
|
+
if (options.clean) {
|
|
98
|
+
await this.cleanDestination(dest)
|
|
99
|
+
}
|
|
100
|
+
|
|
95
101
|
for (let ind = 0; ind < sources.length; ind++) {
|
|
96
102
|
const source = sources[ind]
|
|
97
103
|
if (fs.existsSync(source) === false) throw 'source ' + source + ' does not exist'
|
|
@@ -111,6 +117,22 @@ class AssetUpload extends Cmd {
|
|
|
111
117
|
}
|
|
112
118
|
}
|
|
113
119
|
|
|
120
|
+
//----------------------------------------------------------------------------------------------
|
|
121
|
+
// cleanDestination
|
|
122
|
+
//----------------------------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
async cleanDestination(dest: string) {
|
|
125
|
+
|
|
126
|
+
const remoteList = await this.scanAssets()
|
|
127
|
+
for(let ind = 0; ind < remoteList.length; ind++) {
|
|
128
|
+
const fd = remoteList[ind]
|
|
129
|
+
if (fd.path.startsWith(dest)) {
|
|
130
|
+
const url = '/api/admin/assets/' + fd.id
|
|
131
|
+
await this.dbRemote?.apiServer.delete(url)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
114
136
|
//----------------------------------------------------------------------------------------------
|
|
115
137
|
// uploadDirectory
|
|
116
138
|
//----------------------------------------------------------------------------------------------
|
|
@@ -131,8 +153,7 @@ class AssetUpload extends Cmd {
|
|
|
131
153
|
|
|
132
154
|
this.scanDir(dirName, localList)
|
|
133
155
|
|
|
134
|
-
const remoteList
|
|
135
|
-
await this.scanAssets(remoteList)
|
|
156
|
+
const remoteList = await this.scanAssets()
|
|
136
157
|
|
|
137
158
|
const uploadList = this.buildUploadList(dirName, dest, localList, remoteList)
|
|
138
159
|
|
|
@@ -193,8 +214,8 @@ class AssetUpload extends Cmd {
|
|
|
193
214
|
// scanAssets
|
|
194
215
|
//----------------------------------------------------------------------------------------------
|
|
195
216
|
|
|
196
|
-
async scanAssets(
|
|
197
|
-
|
|
217
|
+
async scanAssets() {
|
|
218
|
+
const result: FileDescriptor[] = []
|
|
198
219
|
if (this.dbManager === undefined) throw 'dbManager undefined'
|
|
199
220
|
const dbReq = new DBExecuteRequest()
|
|
200
221
|
dbReq.selectFromTable = 'cyk_asset'
|
|
@@ -208,11 +229,13 @@ class AssetUpload extends Cmd {
|
|
|
208
229
|
for (let ind = 0; ind < rows.list.length; ind++) {
|
|
209
230
|
const { variable: row } = rows.list[ind]
|
|
210
231
|
const record = row.data as ObjectData
|
|
232
|
+
const asset_id = (record.variables.getData('asset_id') as PrimitiveData).value as number
|
|
211
233
|
const asset_route = (record.variables.getData('asset_route') as PrimitiveData).value as string
|
|
212
|
-
const asset_last_update = (record.variables.getData('asset_last_update') as PrimitiveData)
|
|
234
|
+
const asset_last_update = (record.variables.getData('asset_last_update') as PrimitiveData)?.value as Date
|
|
213
235
|
// logger.debug('asset_route ' + asset_route,'asset_last_update ' + asset_last_update)
|
|
214
|
-
result.push({ path: asset_route, mtime: asset_last_update })
|
|
236
|
+
result.push({ path: asset_route, mtime: asset_last_update, id: asset_id })
|
|
215
237
|
}
|
|
238
|
+
return result
|
|
216
239
|
}
|
|
217
240
|
|
|
218
241
|
//----------------------------------------------------------------------------------------------
|
|
@@ -283,7 +306,7 @@ class AssetUpload extends Cmd {
|
|
|
283
306
|
if (mimetype === false) throw 'mimetype false for ' + upload
|
|
284
307
|
dbAsset.mimetype = mimetype
|
|
285
308
|
dbAsset.route = route
|
|
286
|
-
|
|
309
|
+
|
|
287
310
|
// const fstat = fs.statSync(fileName)
|
|
288
311
|
dbAsset.last_update = upload.mtime
|
|
289
312
|
|
|
@@ -318,7 +341,7 @@ class AssetUpload extends Cmd {
|
|
|
318
341
|
const form = new FormData()
|
|
319
342
|
form.append('uploadFile', file)
|
|
320
343
|
|
|
321
|
-
const route = '/upload/cyk_asset/asset_content?asset_id=' + dbAsset.id
|
|
344
|
+
const route = '/api/upload/cyk_asset/asset_content?asset_id=' + dbAsset.id
|
|
322
345
|
const resp = await this.dbRemote?.apiServer.post(route, form)
|
|
323
346
|
if (resp.status === 200) {
|
|
324
347
|
logger.info(fileName + ' uploaded')
|
package/src/Cmd.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DBManager, DBRemote, Structure } from "@cyklang/core";
|
|
1
|
+
import { DBManager, DBRemote, SigninResponse, Structure } from "@cyklang/core";
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import dotenv from 'dotenv'
|
|
4
4
|
import loglevel from 'loglevel'
|
|
@@ -14,27 +14,25 @@ export class Cmd extends Command {
|
|
|
14
14
|
super(name);
|
|
15
15
|
this.option('--env <env>', 'path to the environment variables file')
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
async prologue(options: any) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
logger.error(err)
|
|
37
|
-
}
|
|
17
|
+
|
|
18
|
+
async prologue(options: any): Promise<SigninResponse> {
|
|
19
|
+
|
|
20
|
+
const dotenvOutput = dotenv.config({ path: options.env })
|
|
21
|
+
if (dotenvOutput.error !== undefined) throw dotenvOutput.error
|
|
22
|
+
|
|
23
|
+
const structure = new Structure()
|
|
24
|
+
if (process.env.DBREMOTE_URL === undefined) throw 'DBREMOTE_URL undefined'
|
|
25
|
+
logger.debug('Cmd.DBREMOTE_URL ' + process.env.DBREMOTE_URL)
|
|
26
|
+
const nodeCrypto = new NodeCrypto()
|
|
27
|
+
this.dbRemote = new DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto)
|
|
28
|
+
const login = await this.dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD)
|
|
29
|
+
// logger.debug(login)
|
|
30
|
+
|
|
31
|
+
this.dbManager = new DBManager(structure.scope, this.dbRemote)
|
|
32
|
+
await this.dbManager.initialize()
|
|
33
|
+
|
|
34
|
+
return login
|
|
35
|
+
|
|
38
36
|
|
|
39
37
|
}
|
|
40
38
|
}
|
package/src/DBClient.ts
CHANGED
|
@@ -10,6 +10,10 @@ export class DBClient {
|
|
|
10
10
|
this.dbManager = dbManager
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
async runQuery() {
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
async selectFromTable(title: string, tableName: string, options:
|
|
14
18
|
{ fields: string, sort?: string | undefined, where?: string | undefined, width?: string | undefined }) {
|
|
15
19
|
|
|
@@ -232,6 +236,10 @@ class List {
|
|
|
232
236
|
else {
|
|
233
237
|
result = value.toString()
|
|
234
238
|
}
|
|
239
|
+
|
|
240
|
+
// replace \n with a space
|
|
241
|
+
result = result.replace(/\n/, ' ')
|
|
242
|
+
|
|
235
243
|
if (width !== undefined && width !== 0) {
|
|
236
244
|
if (result.length >= width) {
|
|
237
245
|
result = result.substring(0, width)
|
package/src/ModuleCommand.ts
CHANGED
|
@@ -37,7 +37,7 @@ function getModuleDBName(filePath: string): string {
|
|
|
37
37
|
// result = path.basename(filePath, '.xml')
|
|
38
38
|
|
|
39
39
|
const result = path.parse(filePath).name
|
|
40
|
-
const identifierRegex = /^[_a-zA-Z][_a-zA-Z0-9]*$/
|
|
40
|
+
const identifierRegex = /^[_a-zA-Z][-_a-zA-Z0-9]*$/
|
|
41
41
|
if (result.match(identifierRegex) === null) throw 'filename ' + result + ' does not match identifier syntax'
|
|
42
42
|
return result
|
|
43
43
|
}
|
|
@@ -185,7 +185,7 @@ class ModuleList extends Cmd {
|
|
|
185
185
|
|
|
186
186
|
const dbClient = new DBClient(this.dbManager)
|
|
187
187
|
dbClient.selectFromTable('List of Modules', 'cyk_module',
|
|
188
|
-
{ fields: 'module_id,module_dbname,module_access,module_description', sort: options.sort || '1' })
|
|
188
|
+
{ fields: 'module_id,module_dbname,module_auth,module_access,module_description', sort: options.sort || '1' })
|
|
189
189
|
|
|
190
190
|
}
|
|
191
191
|
catch (err) {
|
package/src/QueryCommand.ts
CHANGED
|
@@ -4,59 +4,76 @@ import * as fs from "fs"
|
|
|
4
4
|
import loglevel from 'loglevel'
|
|
5
5
|
import { Cmd } from './Cmd'
|
|
6
6
|
import { Command } from 'commander'
|
|
7
|
+
import { DBClient } from "./DBClient"
|
|
7
8
|
const logger = loglevel.getLogger("QueryCommand.ts")
|
|
8
9
|
logger.setLevel("debug")
|
|
9
10
|
|
|
10
11
|
export class QueryCommand extends Command {
|
|
11
12
|
constructor(name: string) {
|
|
12
13
|
super(name)
|
|
14
|
+
this.description('query management')
|
|
15
|
+
this.addCommand(new QueryList('list', 'list queries'))
|
|
16
|
+
this.addCommand(new QueryList('l', 'list queries'))
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
//--------------------------------------------------------------------------------------------------------------------
|
|
21
|
+
// class TableList
|
|
22
|
+
//--------------------------------------------------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
class QueryList extends Cmd {
|
|
25
|
+
constructor(name: string, description: string) {
|
|
26
|
+
super(name)
|
|
27
|
+
this.description(description)
|
|
28
|
+
.option('-s --sort <columns>', 'sort list by column numbers (begins with 0) separated by comma')
|
|
29
|
+
.action(async (options: any) => {
|
|
30
|
+
await this.commandList(options)
|
|
31
|
+
})
|
|
24
32
|
}
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
|
|
34
|
+
async commandList(options: any) {
|
|
35
|
+
await this.prologue(options)
|
|
36
|
+
if (this.dbManager === undefined) throw 'dbManager undefined'
|
|
37
|
+
|
|
38
|
+
const dbClient = new DBClient(this.dbManager)
|
|
39
|
+
dbClient.selectFromTable('List of Queries', 'cyk_query',
|
|
40
|
+
{ fields: 'query_id,query_name,query_auth,query_access,query_description', sort: options.sort || '1' }
|
|
41
|
+
)
|
|
27
42
|
}
|
|
28
|
-
return tag
|
|
29
43
|
}
|
|
30
44
|
|
|
31
|
-
async function executeXml(structure: Structure, tag: Tag, xmlSource: string) {
|
|
32
|
-
try {
|
|
33
|
-
logger.debug('executeXml ' + tag.attributes.NAME)
|
|
34
|
-
// structure.setInstructionType("print", new PrintInstructionType(logfilename))
|
|
35
|
-
const dbQueryInstructionType = structure.scope.getInstructionType('db.query')
|
|
36
|
-
if (dbQueryInstructionType === undefined) {
|
|
37
|
-
throw Error('dbQueryInstructionType not found')
|
|
38
|
-
}
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
|
|
47
|
+
//--------------------------------------------------------------------------------------------------------------------
|
|
48
|
+
// class queryData
|
|
49
|
+
//--------------------------------------------------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
class queryData extends Cmd {
|
|
52
|
+
|
|
53
|
+
constructor(name: string, description: string) {
|
|
54
|
+
super(name)
|
|
55
|
+
this.description(description)
|
|
56
|
+
.argument('<query>', 'query name')
|
|
57
|
+
.option('--where <clause_where_sql>', 'criteria in SQL syntax')
|
|
58
|
+
.option('-s --sort <columns>', 'sort by columns positions (begins by 0) separated by comma')
|
|
59
|
+
.option('-w --width <colwidth>', 'columns widths separated by comma')
|
|
60
|
+
.action(async (query, options) => {
|
|
61
|
+
this.commandData(query, options)
|
|
62
|
+
})
|
|
48
63
|
}
|
|
49
|
-
}
|
|
50
64
|
|
|
51
|
-
async
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
async commandData(query: string, options: any) {
|
|
66
|
+
try {
|
|
67
|
+
await this.prologue(options)
|
|
68
|
+
if (this.dbManager === undefined) throw 'dbManager undefined'
|
|
69
|
+
|
|
70
|
+
const dbQuery = await this.dbManager.dbQueryExist(query)
|
|
71
|
+
if (dbQuery === undefined) throw 'query ' + query + ' not found'
|
|
72
|
+
|
|
73
|
+
//DBClient
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
logger.error(err)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
62
79
|
}
|
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,7 +18,7 @@ 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) {
|
|
@@ -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)
|