@cyklang/cli 0.2.1 → 0.2.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.
- package/build/AssetCommand.js +36 -15
- package/build/Cmd.js +18 -13
- package/build/DBClient.d.ts +1 -0
- package/build/DBClient.js +12 -0
- package/build/InitCommand.d.ts +6 -0
- package/build/InitCommand.js +36 -8
- package/build/ModuleCommand.js +9 -1
- package/build/TestCommand.js +1 -1
- package/docker.env +2 -2
- package/package.json +4 -2
- package/src/AssetCommand.ts +50 -26
- package/src/Cmd.ts +18 -12
- package/src/DBClient.ts +16 -0
- package/src/InitCommand.ts +39 -8
- package/src/ModuleCommand.ts +15 -9
- package/src/TestCommand.ts +1 -1
- package/test/t09.output +1 -1
- package/test/t09.xml +1 -1
- package/test/t17.output +2 -0
- package/test/t17.xml +3 -1
- package/test/t20.output +0 -0
- package/test/t20.xml +1 -1
- package/test/t21.xml +11 -5
- package/test/t22.output +0 -0
- package/test/t23.output +48 -0
- package/test/t23.xml +3 -3
- 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/src/InitCommand.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import * as fs from 'fs'
|
|
3
|
+
import inquirer from "inquirer";
|
|
3
4
|
import { getLogger } from "loglevel";
|
|
5
|
+
|
|
4
6
|
const logger = getLogger('InitCommand.ts')
|
|
5
7
|
|
|
6
8
|
logger.setLevel('debug')
|
|
7
9
|
|
|
8
10
|
export class InitCommand extends Command {
|
|
11
|
+
|
|
12
|
+
PGPORT="5432"
|
|
13
|
+
USER_NAME="cyk"
|
|
14
|
+
USER_PASSWORD="cyk"
|
|
15
|
+
USER_EMAIL="my-email@my-domain"
|
|
16
|
+
CYK_PORT="3000"
|
|
17
|
+
|
|
9
18
|
constructor(name: string) {
|
|
10
19
|
super(name)
|
|
11
20
|
this.description('initialize a folder with files necessary for a cyklang project')
|
|
@@ -15,6 +24,7 @@ export class InitCommand extends Command {
|
|
|
15
24
|
}
|
|
16
25
|
async commandInit(options: any) {
|
|
17
26
|
try {
|
|
27
|
+
await this.promptParameters()
|
|
18
28
|
await this.writeEnvFile()
|
|
19
29
|
await this.writeDockerComposeFile()
|
|
20
30
|
}
|
|
@@ -23,6 +33,26 @@ export class InitCommand extends Command {
|
|
|
23
33
|
}
|
|
24
34
|
}
|
|
25
35
|
|
|
36
|
+
async promptParameters() {
|
|
37
|
+
|
|
38
|
+
const reply = await inquirer.prompt([
|
|
39
|
+
|
|
40
|
+
{type: "number", name: 'PGPORT', default: this.PGPORT, message: 'Postgresql Port' },
|
|
41
|
+
{type: 'number', name: 'CYK_PORT', default: this.CYK_PORT, message: 'NodeJS Port'},
|
|
42
|
+
{type: 'input', name: 'USER_NAME', default: this.USER_NAME, message: 'Admin User Login'},
|
|
43
|
+
{type: 'input', name: 'USER_PASSWORD', default: this.USER_PASSWORD, message: 'Admin User Password'},
|
|
44
|
+
{type: 'input', name: 'USER_EMAIL', default: this.USER_EMAIL, message: 'Admin Use Email'},
|
|
45
|
+
{type: "confirm", name: 'confirm'}
|
|
46
|
+
])
|
|
47
|
+
// logger.debug(reply)
|
|
48
|
+
if (reply.confirm === false) throw 'Command cancelled'
|
|
49
|
+
this.PGPORT = reply.PGPORT
|
|
50
|
+
this.CYK_PORT = reply.CYK_PORT
|
|
51
|
+
this.USER_NAME = reply.USER_NAME
|
|
52
|
+
this.USER_PASSWORD = reply.USER_PASSWORD
|
|
53
|
+
this.USER_EMAIL = reply.USER_EMAIL
|
|
54
|
+
}
|
|
55
|
+
|
|
26
56
|
// developer.mozilla.org Math.random()
|
|
27
57
|
// On renvoie un entier aléatoire entre une valeur min (incluse)
|
|
28
58
|
// et une valeur max (exclue).
|
|
@@ -49,11 +79,12 @@ export class InitCommand extends Command {
|
|
|
49
79
|
logger.info(envFilename + ' file already exists. Remove it before launching init command')
|
|
50
80
|
return
|
|
51
81
|
}
|
|
82
|
+
|
|
52
83
|
Math.random()
|
|
53
84
|
const content = `# PostgreSql connection
|
|
54
85
|
# used by psql command line utility
|
|
55
86
|
PGHOST="localhost"
|
|
56
|
-
PGPORT="
|
|
87
|
+
PGPORT="${this.PGPORT}"
|
|
57
88
|
PGUSER="postgres"
|
|
58
89
|
PGPASSWORD="postgres"
|
|
59
90
|
|
|
@@ -64,9 +95,9 @@ POSTGRES_PASSWORD="postgres"
|
|
|
64
95
|
|
|
65
96
|
# admin user
|
|
66
97
|
# created at database initialization
|
|
67
|
-
ADMIN_NAME
|
|
68
|
-
ADMIN_PASSWORD
|
|
69
|
-
ADMIN_EMAIL
|
|
98
|
+
ADMIN_NAME=${this.USER_NAME}
|
|
99
|
+
ADMIN_PASSWORD=${this.USER_PASSWORD}
|
|
100
|
+
ADMIN_EMAIL=${this.USER_EMAIL}
|
|
70
101
|
|
|
71
102
|
# JWT token generation
|
|
72
103
|
# e.g. https://www.allkeysgenerator.com
|
|
@@ -83,10 +114,10 @@ LOGIN_APPLI="index"
|
|
|
83
114
|
|
|
84
115
|
# credential used by cyk CLI
|
|
85
116
|
|
|
86
|
-
USER_NAME
|
|
87
|
-
USER_PASSWORD
|
|
88
|
-
CYK_PORT="
|
|
89
|
-
DBREMOTE_URL="http://localhost
|
|
117
|
+
USER_NAME=${this.USER_NAME}
|
|
118
|
+
USER_PASSWORD=${this.USER_PASSWORD}
|
|
119
|
+
CYK_PORT="${this.CYK_PORT}"
|
|
120
|
+
DBREMOTE_URL="http://localhost:${this.CYK_PORT}"
|
|
90
121
|
`
|
|
91
122
|
fs.writeFileSync(envFilename, content)
|
|
92
123
|
logger.debug('created ' + envFilename)
|
package/src/ModuleCommand.ts
CHANGED
|
@@ -25,8 +25,9 @@ Otherwise, a new module is inserted in the database. To rename a module, use opt
|
|
|
25
25
|
// list
|
|
26
26
|
this.addCommand(new ModuleList('list', 'List modules'))
|
|
27
27
|
this.addCommand(new ModuleList('l', 'shortcut for (l)ist'))
|
|
28
|
-
// rename
|
|
29
|
-
|
|
28
|
+
// rename **TODO**
|
|
29
|
+
// delete
|
|
30
|
+
this.addCommand(new ModuleDelete('delete', 'delete module from database'))
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -197,10 +198,10 @@ class ModuleDelete extends Cmd {
|
|
|
197
198
|
constructor(name: string, description: string) {
|
|
198
199
|
super(name)
|
|
199
200
|
this.description(description)
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
.argument('[files...]', 'module(s) to delete from the database')
|
|
202
|
+
.action(async (files: any, options: any) => {
|
|
203
|
+
await this.commandDelete(files, options)
|
|
204
|
+
})
|
|
204
205
|
}
|
|
205
206
|
async commandDelete(files: string[], options: any) {
|
|
206
207
|
try {
|
|
@@ -208,12 +209,17 @@ class ModuleDelete extends Cmd {
|
|
|
208
209
|
if (this.dbManager === undefined) throw 'dbManager undefined'
|
|
209
210
|
|
|
210
211
|
if (files.length === 0) throw 'no module to delete'
|
|
211
|
-
|
|
212
|
+
const dbClient = new DBClient(this.dbManager)
|
|
213
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
214
|
+
const dbname = files.at(ind)
|
|
215
|
+
if (dbname !== undefined)
|
|
216
|
+
dbClient.deleteModule(dbname)
|
|
217
|
+
}
|
|
212
218
|
|
|
213
219
|
}
|
|
214
|
-
catch (err){
|
|
220
|
+
catch (err) {
|
|
215
221
|
logger.error(err)
|
|
216
|
-
}
|
|
222
|
+
}
|
|
217
223
|
}
|
|
218
224
|
}
|
|
219
225
|
|
package/src/TestCommand.ts
CHANGED
|
@@ -22,7 +22,7 @@ export class TestCommand extends Cmd {
|
|
|
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
|
}
|
package/test/t09.output
CHANGED
package/test/t09.xml
CHANGED
package/test/t17.output
CHANGED
package/test/t17.xml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<?xml-model href="cyklang.xsd" ?>
|
|
1
|
+
<?xml-model href="https://www.cyklang.net/schema/cyklang.xsd" ?>
|
|
2
2
|
<module>
|
|
3
3
|
<string name="d1">"2022-07-14"</string>
|
|
4
4
|
<print>"day : "+datepart("day", d1)+", month : "+datepart("month", d1)+", year : "+datepart("year", d1)</print>
|
|
@@ -18,4 +18,6 @@
|
|
|
18
18
|
if(entry.entry_debit == null || entry.entry_debit == undefined, 0, entry.entry_debit)
|
|
19
19
|
- if(entry.entry_credit == null || entry.entry_credit == undefined, 0, entry.entry_credit)
|
|
20
20
|
</print>
|
|
21
|
+
<print>"Expression with boolean terms"</print>
|
|
22
|
+
<print><![CDATA[ "TRUE = " + (true && "VRAI") ]]> </print>
|
|
21
23
|
</module>
|
package/test/t20.output
ADDED
|
File without changes
|
package/test/t20.xml
CHANGED
package/test/t21.xml
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
<?xml-model href="cyklang.xsd" ?>
|
|
1
|
+
<?xml-model href="https://www.cyklang.net/schema/cyklang.xsd" ?>
|
|
2
2
|
<module>
|
|
3
|
+
<string name="chaine"/>
|
|
4
|
+
<set name="chaine" literal="">A + B</set>
|
|
5
|
+
<print>"chaine = " +chaine</print>
|
|
6
|
+
|
|
3
7
|
<object name="params">
|
|
4
8
|
<string name="name">"Dupont"</string>
|
|
5
9
|
<string name="surname">"Jean"</string>
|
|
6
10
|
</object>
|
|
7
|
-
<module_object name="m_t20"
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
<module_object name="m_t20"/>
|
|
12
|
+
<set name="m_t20" module="t20">
|
|
13
|
+
<object name="settings">params</object>
|
|
14
|
+
</set>
|
|
15
|
+
|
|
10
16
|
<!-- <call object="m_t20" method="__init__">
|
|
11
17
|
<object name="settings">params</object>
|
|
12
18
|
</call> -->
|
|
@@ -56,7 +62,7 @@
|
|
|
56
62
|
<set name="bool">boolean("")</set>
|
|
57
63
|
<print>"bool : " + bool</print>
|
|
58
64
|
|
|
59
|
-
<
|
|
65
|
+
<set name="chaine">150</set>
|
|
60
66
|
<print>"chaine : " + chaine</print>
|
|
61
67
|
|
|
62
68
|
<object name="document">
|
package/test/t22.output
ADDED
|
File without changes
|
package/test/t23.output
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Client side : <string name="name" literal="">CYK</string>
|
|
2
|
+
<string name="surname" literal="">Philippe</string>
|
|
3
|
+
<object name="setting">
|
|
4
|
+
<object name="jnl_id">
|
|
5
|
+
<string name="stg_code" literal="">jnl_id</string>
|
|
6
|
+
<number name="stg_num">2</number>
|
|
7
|
+
<string name="stg_text">
|
|
8
|
+
</string>
|
|
9
|
+
<string name="stg_label" literal="">ID journal de Saisie</string>
|
|
10
|
+
</object>
|
|
11
|
+
<object name="month_begin">
|
|
12
|
+
<string name="stg_code" literal="">month_begin</string>
|
|
13
|
+
<number name="stg_num">
|
|
14
|
+
</number>
|
|
15
|
+
<string name="stg_text" literal="">2021-01-01</string>
|
|
16
|
+
<string name="stg_label" literal="">1er Jour du Mois de Saisie</string>
|
|
17
|
+
</object>
|
|
18
|
+
<object name="year">
|
|
19
|
+
<string name="stg_code" literal="">year</string>
|
|
20
|
+
<number name="stg_num">2021</number>
|
|
21
|
+
<string name="stg_text">
|
|
22
|
+
</string>
|
|
23
|
+
<string name="stg_label" literal="">Year</string>
|
|
24
|
+
</object>
|
|
25
|
+
<object name="acct_num">
|
|
26
|
+
<string name="stg_code" literal="">acct_num</string>
|
|
27
|
+
<number name="stg_num">
|
|
28
|
+
</number>
|
|
29
|
+
<string name="stg_text" literal="">10131</string>
|
|
30
|
+
<string name="stg_label" literal="">Numéro de Compte</string>
|
|
31
|
+
</object>
|
|
32
|
+
</object>
|
|
33
|
+
<object name="meta">
|
|
34
|
+
<string name="setting" literal=""><db.table name="setting" id="19">
|
|
35
|
+
<string name="stg_code" type="varchar(30)" primary="">
|
|
36
|
+
</string>
|
|
37
|
+
<number name="stg_num" type="int">
|
|
38
|
+
</number>
|
|
39
|
+
<string name="stg_text" type="varchar(255)">
|
|
40
|
+
</string>
|
|
41
|
+
<string name="stg_label" type="varchar(255)">
|
|
42
|
+
</string>
|
|
43
|
+
</db.table></string>
|
|
44
|
+
</object>
|
|
45
|
+
Third (1 sec)
|
|
46
|
+
Second (2 sec)
|
|
47
|
+
First (3 sec)
|
|
48
|
+
AFTER parallel
|
package/test/t23.xml
CHANGED
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
|
|
14
14
|
<call function="call_get_tables"/>
|
|
15
15
|
|
|
16
|
-
<print>now()</print>
|
|
16
|
+
<!-- <print>now()</print> -->
|
|
17
17
|
|
|
18
18
|
<function name="wait">
|
|
19
19
|
<number name="duration">1000</number>
|
|
20
20
|
<string name="message"/>
|
|
21
21
|
<block>
|
|
22
22
|
<sleep>duration</sleep>
|
|
23
|
-
<print>
|
|
23
|
+
<print>message</print>
|
|
24
24
|
</block>
|
|
25
25
|
</function>
|
|
26
26
|
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
</call>
|
|
40
40
|
</parallel>
|
|
41
41
|
|
|
42
|
-
<print>
|
|
42
|
+
<print>" AFTER parallel "</print>
|
|
43
43
|
|
|
44
44
|
</module>
|