@cyklang/cli 0.18.16 → 0.19.1

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.
@@ -103,7 +103,7 @@ async function defaultInstallScript(node_package, dbManager, dbRemote) {
103
103
  /**
104
104
  * upload package modules to the server
105
105
  */
106
- await uploadPackageModules(node_package, dbManager);
106
+ await uploadPackageModules(node_package, dbManager, dbRemote);
107
107
  }
108
108
  /**
109
109
  * function uploadPackageAssets
@@ -138,7 +138,7 @@ async function uploadPackageAssets(node_package, dbManager, dbRemote) {
138
138
  * @param node_package
139
139
  * @param dbManager
140
140
  */
141
- async function uploadPackageModules(node_package, dbManager) {
141
+ async function uploadPackageModules(node_package, dbManager, dbRemote) {
142
142
  const moduleFolder = path.join('node_modules', node_package, 'module');
143
143
  if (!fs.existsSync(moduleFolder) || !fs.statSync(moduleFolder).isDirectory()) {
144
144
  return;
@@ -151,7 +151,7 @@ async function uploadPackageModules(node_package, dbManager) {
151
151
  const file = files[ind];
152
152
  if (!dbManager)
153
153
  throw 'dbManager undefined';
154
- await (0, ModuleCommand_1.uploadModule)(path.join(moduleFolder, file), dbManager);
154
+ await (0, ModuleCommand_1.uploadModule)(path.join(moduleFolder, file), dbManager, dbRemote);
155
155
  if (file.endsWith('_init.xml')) {
156
156
  initModule = file;
157
157
  }
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env ts-node
2
- import { DBManager } from "@cyklang/core";
2
+ import { DBManager, DBRemote } from "@cyklang/core";
3
3
  import { Command } from 'commander';
4
4
  export declare class ModuleCommand extends Command {
5
5
  constructor(name: string);
6
6
  }
7
7
  /**
8
8
  *
9
- * @param file
9
+ * @param fileName
10
10
  * @param dbManager
11
11
  */
12
- export declare function uploadModule(file: string, dbManager: DBManager): Promise<void>;
12
+ export declare function uploadModule(fileName: string, dbManager: DBManager, dbRemote: DBRemote | undefined): Promise<void>;
13
13
  /**
14
14
  * function deleteModule
15
15
  * @param dbname
@@ -36,6 +36,7 @@ const commander_1 = require("commander");
36
36
  const Cmd_1 = require("./Cmd");
37
37
  const DBClient_1 = require("./DBClient");
38
38
  const RunCommand_1 = require("./RunCommand");
39
+ const form_data_1 = __importDefault(require("form-data"));
39
40
  const logger = loglevel_1.default.getLogger("ModuleCommand.ts");
40
41
  logger.setLevel("debug");
41
42
  class ModuleCommand extends commander_1.Command {
@@ -130,21 +131,31 @@ class ModuleU extends Cmd_1.Cmd {
130
131
  if (files.length > 1)
131
132
  throw 'with --id option you can only specify 1 local file';
132
133
  const dbModule = await this.dbManager.getModule(options.id);
133
- dbModule.source = fs.readFileSync(files[0]).toString();
134
+ const fileName = files[0];
135
+ const source = fs.readFileSync(fileName).toString();
136
+ if (source.length < REQUEST_LIMIT) {
137
+ dbModule.source = source;
138
+ }
139
+ else {
140
+ dbModule.source = '';
141
+ }
134
142
  dbModule.dbname = getModuleDBName(files[0]);
135
- const tag = (0, core_1.parseXML)(dbModule.dbname, dbModule.source);
143
+ const tag = (0, core_1.parseXML)(dbModule.dbname, source);
136
144
  dbModule.access = tag.attributes.ACCESS;
137
145
  dbModule.description = tag.attributes.DESCRIPTION;
138
146
  await this.dbManager.dbModuleUpdate(dbModule);
147
+ if (source.length >= REQUEST_LIMIT) {
148
+ await uploadModuleSource(dbModule, fileName, this.dbRemote);
149
+ }
139
150
  }
140
151
  else {
141
152
  for (let ind = 0; ind < files.length; ind++) {
142
- const file = files[ind];
153
+ const fileName = files[ind];
143
154
  try {
144
- await uploadModule(file, this.dbManager);
155
+ await uploadModule(fileName, this.dbManager, this.dbRemote);
145
156
  }
146
157
  catch (err) {
147
- logger.error('Error uploading module ' + file, err);
158
+ logger.error('Error uploading module ' + fileName, err);
148
159
  throw err;
149
160
  }
150
161
  }
@@ -168,35 +179,50 @@ class ModuleU extends Cmd_1.Cmd {
168
179
  }
169
180
  }
170
181
  }
182
+ const REQUEST_LIMIT = 50000;
171
183
  /**
172
184
  *
173
- * @param file
185
+ * @param fileName
174
186
  * @param dbManager
175
187
  */
176
- async function uploadModule(file, dbManager) {
177
- const dbname = getModuleDBName(file);
178
- const source = fs.readFileSync(file).toString();
188
+ async function uploadModule(fileName, dbManager, dbRemote) {
189
+ const dbname = getModuleDBName(fileName);
190
+ const source = fs.readFileSync(fileName).toString();
179
191
  const tag = (0, core_1.parseXML)(dbname, source);
180
192
  const dbModuleExist = await dbManager.dbModuleExist(dbname);
181
193
  if (dbModuleExist === undefined) {
182
194
  // insert
183
195
  const dbModule = new core_1.DBModule();
184
- dbModule.source = source;
196
+ if (source.length < REQUEST_LIMIT) {
197
+ dbModule.source = source;
198
+ }
185
199
  dbModule.dbname = dbname;
186
200
  dbModule.access = tag.attributes.ACCESS;
187
201
  dbModule.description = tag.attributes.DESCRIPTION;
188
202
  // logger.debug('module insert ' + dbname + ' access ' + dbModule.access + ' description ' + dbModule.description)
189
203
  const id = await dbManager.dbModuleInsert(dbModule);
204
+ dbModule.id = id;
205
+ if (source.length >= REQUEST_LIMIT) {
206
+ await uploadModuleSource(dbModule, fileName, dbRemote);
207
+ }
190
208
  logger.info('module ' + dbname + ' added with ID ' + id);
191
209
  }
192
210
  else {
193
211
  logger.debug('module exists : ' + dbModuleExist.dbname + ', id ' + dbModuleExist.id);
194
212
  // update
195
- dbModuleExist.source = source;
213
+ if (source.length < REQUEST_LIMIT) {
214
+ dbModuleExist.source = source;
215
+ }
216
+ else {
217
+ dbModuleExist.source = '';
218
+ }
196
219
  dbModuleExist.access = tag.attributes.ACCESS;
197
220
  dbModuleExist.description = tag.attributes.DESCRIPTION;
198
221
  // logger.debug('module update ' + dbname + ' access ' + dbModuleExist.access + ' description ' + dbModuleExist.description)
199
222
  await dbManager.dbModuleUpdate(dbModuleExist);
223
+ if (source.length >= REQUEST_LIMIT) {
224
+ await uploadModuleSource(dbModuleExist, fileName, dbRemote);
225
+ }
200
226
  logger.info('module ' + dbname + ' updated');
201
227
  }
202
228
  }
@@ -315,3 +341,19 @@ async function deleteModule(dbname, dbManager) {
315
341
  await dbClient.deleteModule(dbname);
316
342
  }
317
343
  exports.deleteModule = deleteModule;
344
+ async function uploadModuleSource(dbModule, fileName, dbRemote) {
345
+ try {
346
+ const file = fs.createReadStream(fileName);
347
+ const form = new form_data_1.default();
348
+ form.append('uploadFile', file);
349
+ const route = `/api/admin/modules/${dbModule.id}/source`;
350
+ if (!dbRemote)
351
+ throw 'dbRemote undefined';
352
+ await dbRemote.apiServer.post(route, form);
353
+ logger.info(`module source uploaded by form : ${dbModule.dbname}`);
354
+ }
355
+ catch (err) {
356
+ logger.error(err);
357
+ throw err;
358
+ }
359
+ }
package/build/index.js CHANGED
@@ -182,7 +182,7 @@ class StopCommand extends commander_1.Command {
182
182
  */
183
183
  const program = new commander_1.Command();
184
184
  program.name('cyk').description('cyklang CLI')
185
- .version('0.18.15');
185
+ .version('0.19.1');
186
186
  program.addCommand(new StartCommand('start'));
187
187
  program.addCommand(new StopCommand('stop'));
188
188
  program.addCommand(new InstallCommand_1.InstallCommand('install'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyklang/cli",
3
- "version": "0.18.16",
3
+ "version": "0.19.1",
4
4
  "description": "cyklang CLI",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -19,7 +19,7 @@
19
19
  "author": "",
20
20
  "license": "ISC",
21
21
  "dependencies": {
22
- "@cyklang/core": "^0.62.0",
22
+ "@cyklang/core": "^0.64.0",
23
23
  "commander": "^9.4.0",
24
24
  "dotenv": "^16.0.1",
25
25
  "form-data": "^4.0.0",
@@ -84,7 +84,7 @@ async function defaultInstallScript(node_package: string, dbManager: DBManager,
84
84
  /**
85
85
  * upload package modules to the server
86
86
  */
87
- await uploadPackageModules(node_package, dbManager)
87
+ await uploadPackageModules(node_package, dbManager, dbRemote)
88
88
  }
89
89
 
90
90
  /**
@@ -123,7 +123,7 @@ async function uploadPackageAssets(node_package: string, dbManager: DBManager, d
123
123
  * @param node_package
124
124
  * @param dbManager
125
125
  */
126
- async function uploadPackageModules(node_package: string, dbManager: DBManager) {
126
+ async function uploadPackageModules(node_package: string, dbManager: DBManager, dbRemote: DBRemote) {
127
127
 
128
128
  const moduleFolder = path.join('node_modules', node_package, 'module')
129
129
  if (!fs.existsSync(moduleFolder) || !fs.statSync(moduleFolder).isDirectory()) {
@@ -136,7 +136,7 @@ async function uploadPackageModules(node_package: string, dbManager: DBManager)
136
136
  for (let ind = 0; ind < files.length; ind++) {
137
137
  const file = files[ind]
138
138
  if (!dbManager) throw 'dbManager undefined'
139
- await uploadModule(path.join(moduleFolder, file), dbManager)
139
+ await uploadModule(path.join(moduleFolder, file), dbManager, dbRemote)
140
140
  if (file.endsWith('_init.xml')) {
141
141
  initModule = file
142
142
  }
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ts-node
2
- import { DBManager, DBModule, parseXML } from "@cyklang/core"
2
+ import { DBManager, DBModule, DBRemote, parseXML } from "@cyklang/core"
3
3
  import * as fs from "fs"
4
4
  import loglevel from 'loglevel'
5
5
  import path from "path"
@@ -7,6 +7,7 @@ import { Command } from 'commander'
7
7
  import { Cmd } from "./Cmd"
8
8
  import { DBClient } from "./DBClient"
9
9
  import { runFile } from "./RunCommand"
10
+ import FormData from 'form-data'
10
11
  const logger = loglevel.getLogger("ModuleCommand.ts")
11
12
  logger.setLevel("debug")
12
13
 
@@ -110,21 +111,34 @@ class ModuleU extends Cmd {
110
111
  if (options.id !== undefined) {
111
112
  if (files.length > 1) throw 'with --id option you can only specify 1 local file'
112
113
  const dbModule = await this.dbManager.getModule(options.id)
113
- dbModule.source = fs.readFileSync(files[0]).toString()
114
+ const fileName = files[0]
115
+ const source = fs.readFileSync(fileName).toString()
116
+ if (source.length < REQUEST_LIMIT) {
117
+ dbModule.source = source
118
+ }
119
+ else {
120
+ dbModule.source = ''
121
+ }
122
+
114
123
  dbModule.dbname = getModuleDBName(files[0])
115
- const tag = parseXML(dbModule.dbname, dbModule.source)
124
+ const tag = parseXML(dbModule.dbname, source)
116
125
  dbModule.access = tag.attributes.ACCESS
117
126
  dbModule.description = tag.attributes.DESCRIPTION
127
+
118
128
  await this.dbManager.dbModuleUpdate(dbModule)
129
+
130
+ if (source.length >= REQUEST_LIMIT) {
131
+ await uploadModuleSource(dbModule, fileName, this.dbRemote)
132
+ }
119
133
  }
120
134
  else {
121
135
  for (let ind = 0; ind < files.length; ind++) {
122
- const file = files[ind]
136
+ const fileName = files[ind]
123
137
  try {
124
- await uploadModule(file, this.dbManager)
138
+ await uploadModule(fileName, this.dbManager, this.dbRemote)
125
139
  }
126
140
  catch (err) {
127
- logger.error('Error uploading module ' + file, err)
141
+ logger.error('Error uploading module ' + fileName, err)
128
142
  throw err
129
143
  }
130
144
  }
@@ -149,35 +163,57 @@ class ModuleU extends Cmd {
149
163
  }
150
164
  }
151
165
 
166
+ const REQUEST_LIMIT=50000
167
+
152
168
  /**
153
169
  *
154
- * @param file
170
+ * @param fileName
155
171
  * @param dbManager
156
172
  */
157
- export async function uploadModule(file: string, dbManager: DBManager) {
158
- const dbname = getModuleDBName(file)
159
- const source = fs.readFileSync(file).toString()
173
+ export async function uploadModule(fileName: string, dbManager: DBManager, dbRemote: DBRemote | undefined) {
174
+ const dbname = getModuleDBName(fileName)
175
+ const source = fs.readFileSync(fileName).toString()
160
176
  const tag = parseXML(dbname, source)
161
177
  const dbModuleExist = await dbManager.dbModuleExist(dbname)
162
178
  if (dbModuleExist === undefined) {
163
179
  // insert
164
180
  const dbModule = new DBModule()
165
- dbModule.source = source
181
+ if ( source.length < REQUEST_LIMIT ) {
182
+ dbModule.source = source
183
+ }
184
+
166
185
  dbModule.dbname = dbname
167
186
  dbModule.access = tag.attributes.ACCESS
168
187
  dbModule.description = tag.attributes.DESCRIPTION
169
188
  // logger.debug('module insert ' + dbname + ' access ' + dbModule.access + ' description ' + dbModule.description)
170
189
  const id = await dbManager.dbModuleInsert(dbModule)
190
+ dbModule.id = id
191
+
192
+ if ( source.length >= REQUEST_LIMIT ) {
193
+ await uploadModuleSource(dbModule, fileName, dbRemote)
194
+ }
195
+
171
196
  logger.info('module ' + dbname + ' added with ID ' + id)
172
197
  }
173
198
  else {
174
199
  logger.debug('module exists : ' + dbModuleExist.dbname + ', id ' + dbModuleExist.id)
175
200
  // update
176
- dbModuleExist.source = source
201
+ if (source.length < REQUEST_LIMIT) {
202
+ dbModuleExist.source = source
203
+ }
204
+ else {
205
+ dbModuleExist.source = ''
206
+ }
207
+
177
208
  dbModuleExist.access = tag.attributes.ACCESS
178
209
  dbModuleExist.description = tag.attributes.DESCRIPTION
179
210
  // logger.debug('module update ' + dbname + ' access ' + dbModuleExist.access + ' description ' + dbModuleExist.description)
180
211
  await dbManager.dbModuleUpdate(dbModuleExist)
212
+
213
+ if ( source.length >= REQUEST_LIMIT ) {
214
+ await uploadModuleSource(dbModuleExist, fileName, dbRemote)
215
+ }
216
+
181
217
  logger.info('module ' + dbname + ' updated')
182
218
  }
183
219
  }
@@ -309,3 +345,19 @@ export async function deleteModule(dbname: string, dbManager: DBManager) {
309
345
  await dbClient.deleteModule(dbname)
310
346
  }
311
347
 
348
+ async function uploadModuleSource(dbModule: DBModule, fileName: string, dbRemote: DBRemote | undefined) {
349
+ try {
350
+ const file = fs.createReadStream(fileName)
351
+ const form = new FormData()
352
+ form.append('uploadFile', file)
353
+
354
+ const route = `/api/admin/modules/${dbModule.id}/source`
355
+ if ( ! dbRemote ) throw 'dbRemote undefined'
356
+ await dbRemote.apiServer.post(route, form)
357
+ logger.info(`module source uploaded by form : ${dbModule.dbname}`)
358
+ }
359
+ catch (err) {
360
+ logger.error(err)
361
+ throw err
362
+ }
363
+ }
package/src/index.ts CHANGED
@@ -176,7 +176,7 @@ class StopCommand extends Command {
176
176
  */
177
177
  const program = new Command()
178
178
  program.name('cyk').description('cyklang CLI')
179
- .version('0.18.16')
179
+ .version('0.19.1')
180
180
  program.addCommand(new StartCommand('start'))
181
181
  program.addCommand(new StopCommand('stop'))
182
182
  program.addCommand(new InstallCommand('install'))
@@ -33,3 +33,7 @@ string(true) = true
33
33
  string(false) = false
34
34
  boolean('true') = true
35
35
  boolean('false') = true
36
+ typeof(chaine) = string
37
+ typeof(booleen) = boolean
38
+ typeof(nombre) = number
39
+ typeof(indéfini) = undefined
package/test/t37.xml CHANGED
@@ -66,4 +66,6 @@
66
66
  <print>format("result = {0}", result)</print>
67
67
  <print>format("columns = {0}", columns)</print>
68
68
 
69
+ <print>format("xlsx_has_sheet(Feuill1) = {0}",xlsx_has_sheet(bExcel, 'Feuill1'))</print>
70
+ <print>format("xlsx_has_sheet(Feuill2) = {0}",xlsx_has_sheet(bExcel, 'Feuill2'))</print>
69
71
  </module>
package/tsconfig.json CHANGED
@@ -3,6 +3,7 @@
3
3
  "target": "es2020",
4
4
  "module": "Node16",
5
5
  "declaration": true,
6
+ "rootDir": "./src",
6
7
  "outDir": "./build",
7
8
  "strict": true,
8
9
  "esModuleInterop": true,