@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.
@@ -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="4321"
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=cyk
68
- ADMIN_PASSWORD=cyk
69
- ADMIN_EMAIL=my-email@my-domain
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=cyk
87
- USER_PASSWORD=cyk
88
- CYK_PORT="3000"
89
- DBREMOTE_URL="http://localhost:3000"
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)
@@ -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
- .argument('[files...]', 'module(s) to delete from the database')
201
- .action(async(files: any, options: any) => {
202
- await this.commandDelete(files, options)
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
 
@@ -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 ' + process.argv[ind] + ' ***************')
25
+ logger.debug('*********** FAILURE ' + files[ind] + ' ***************')
26
26
  }
27
27
  }
28
28
  }
package/test/t09.output CHANGED
@@ -1,4 +1,4 @@
1
- date of birth : 1963-11-04 00:00:00 GMT+0400, now : 2022-07-22 15:31:35 GMT+0400
1
+ date of birth : 1963-11-04 00:00:00 GMT+0100
2
2
  french true
3
3
  150
4
4
  160
package/test/t09.xml CHANGED
@@ -6,7 +6,7 @@
6
6
  <boolean name="french">true</boolean>
7
7
  </object>
8
8
 
9
- <print>"date of birth : " + dates.datebirth + ", now : "+dates.datenow</print>
9
+ <print>"date of birth : " + dates.datebirth </print>
10
10
  <print>"french " + dates.french </print>
11
11
 
12
12
  <number name="num1"/>
package/test/t17.output CHANGED
@@ -3,3 +3,5 @@ d2 : 2022-06-26
3
3
  DEBIT NULL OR UNDEFINED
4
4
  100
5
5
  -100
6
+ Expression with boolean terms
7
+ TRUE = VRAI
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>
File without changes
package/test/t20.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml-model href="cyklang.xsd" ?>
2
- <module name="t20" dbname="t20">
2
+ <module>
3
3
  <object name="settings"/>
4
4
  <function name="__init__">
5
5
  <object name="settings"/>
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" dbname="t20">
8
- <object name="settings">params</object>
9
- </module_object>
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
- <string name="chaine">150</string>
65
+ <set name="chaine">150</set>
60
66
  <print>"chaine : " + chaine</print>
61
67
 
62
68
  <object name="document">
File without changes
@@ -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="">&lt;db.table name=&quot;setting&quot; id=&quot;19&quot;&gt;
35
+ &lt;string name=&quot;stg_code&quot; type=&quot;varchar(30)&quot; primary=&quot;&quot;&gt;
36
+ &lt;/string&gt;
37
+ &lt;number name=&quot;stg_num&quot; type=&quot;int&quot;&gt;
38
+ &lt;/number&gt;
39
+ &lt;string name=&quot;stg_text&quot; type=&quot;varchar(255)&quot;&gt;
40
+ &lt;/string&gt;
41
+ &lt;string name=&quot;stg_label&quot; type=&quot;varchar(255)&quot;&gt;
42
+ &lt;/string&gt;
43
+ &lt;/db.table&gt;</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>now() + ' ' + message</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>now() + " AFTER parallel "</print>
42
+ <print>" AFTER parallel "</print>
43
43
 
44
44
  </module>