@cyklang/cli 0.4.0 → 0.5.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 +120 -40
- package/build/DBClient.d.ts +1 -1
- package/build/DBClient.js +8 -2
- package/build/InitCommand.js +5 -1
- package/build/ModuleCommand.js +5 -1
- package/build/OpenCommand.d.ts +5 -0
- package/build/OpenCommand.js +34 -0
- package/build/RunCommand.js +5 -1
- package/build/TableCommand.js +5 -1
- package/build/TestCommand.js +5 -1
- package/build/console.js +5 -1
- package/build/index.js +2 -0
- package/package.json +5 -4
- package/src/AssetCommand.ts +129 -41
- package/src/DBClient.ts +16 -8
- package/src/OpenCommand.ts +31 -0
- package/src/index.ts +2 -0
- package/test/t27.output +2 -0
- package/test/t27.xml +18 -0
- package/tsconfig.json +1 -1
package/build/AssetCommand.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -36,6 +40,35 @@ const core_1 = require("@cyklang/core");
|
|
|
36
40
|
const form_data_1 = __importDefault(require("form-data"));
|
|
37
41
|
const logger = (0, loglevel_1.getLogger)('AssetCommand.ts');
|
|
38
42
|
logger.setLevel('debug');
|
|
43
|
+
//----------------------------------------------------------------------------------------------
|
|
44
|
+
// scanAssets
|
|
45
|
+
//----------------------------------------------------------------------------------------------
|
|
46
|
+
const scanAssets = async (dbManager, dest) => {
|
|
47
|
+
const result = [];
|
|
48
|
+
if (dbManager === undefined)
|
|
49
|
+
throw 'dbManager undefined';
|
|
50
|
+
const dbReq = new core_1.DBExecuteRequest();
|
|
51
|
+
dbReq.selectFromTable = 'cyk_asset';
|
|
52
|
+
const pFields = dbReq.parameters.addVariable('fields', dbManager.scope.structure.stringDataType);
|
|
53
|
+
pFields.data = new core_1.PrimitiveData(dbManager.scope.structure.stringDataType, "asset_id,asset_route,asset_last_update,asset_mimetype");
|
|
54
|
+
const xmlResult = await dbManager.dbExecute(dbReq);
|
|
55
|
+
if (xmlResult === undefined || xmlResult === null)
|
|
56
|
+
throw 'xmlResult null or undefined';
|
|
57
|
+
const tag = (0, core_1.parseXML)('scanAssets', xmlResult);
|
|
58
|
+
const objResult = await dbManager.scope.structure.objectDataType.parseData(tag, dbManager.scope);
|
|
59
|
+
const rows = objResult.variables.getData('cyk_asset').variables;
|
|
60
|
+
for (let ind = 0; ind < rows.list.length; ind++) {
|
|
61
|
+
const { variable: row } = rows.list[ind];
|
|
62
|
+
const record = row.data;
|
|
63
|
+
const asset_id = record.variables.getData('asset_id').value;
|
|
64
|
+
const asset_route = record.variables.getData('asset_route').value;
|
|
65
|
+
const asset_last_update = record.variables.getData('asset_last_update')?.value;
|
|
66
|
+
// logger.debug('asset_route ' + asset_route,'asset_last_update ' + asset_last_update)
|
|
67
|
+
if (!dest || asset_route.startsWith(dest))
|
|
68
|
+
result.push({ path: asset_route, mtime: asset_last_update, id: asset_id });
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
39
72
|
class AssetCommand extends commander_1.Command {
|
|
40
73
|
constructor(name, description) {
|
|
41
74
|
super(name);
|
|
@@ -45,9 +78,82 @@ class AssetCommand extends commander_1.Command {
|
|
|
45
78
|
this.addCommand(new AssetU('upload', 'upload asset content from source files to a <destination> path'));
|
|
46
79
|
this.addCommand(new AssetU('update', 'update properties of asset identified by its <id>'));
|
|
47
80
|
this.addCommand(new AssetU('u', '(u)pload assets content from sources or (u)pdate asset properties'));
|
|
81
|
+
this.addCommand(new AssetDelete('delete', 'delete an asset'));
|
|
48
82
|
}
|
|
49
83
|
}
|
|
50
84
|
exports.AssetCommand = AssetCommand;
|
|
85
|
+
/**
|
|
86
|
+
* class AssetDelete
|
|
87
|
+
*/
|
|
88
|
+
class AssetDelete extends Cmd_1.Cmd {
|
|
89
|
+
constructor(name, description) {
|
|
90
|
+
super(name);
|
|
91
|
+
this.description(description)
|
|
92
|
+
.option('-i --id <id_pathname>', 'asset id or pathname to delete')
|
|
93
|
+
.option('-d --dest <destination>', 'delete all assets whose pathname begins with dest')
|
|
94
|
+
.action(async (options) => {
|
|
95
|
+
if (options.id)
|
|
96
|
+
await this.commandDeleteOne(options);
|
|
97
|
+
else if (options.dest) {
|
|
98
|
+
await this.commandDeletePathname(options);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
logger.error('one of --id or --dest options is required');
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @param options
|
|
108
|
+
*/
|
|
109
|
+
async commandDeleteOne(options) {
|
|
110
|
+
try {
|
|
111
|
+
await this.prologue(options);
|
|
112
|
+
if (this.dbManager === undefined)
|
|
113
|
+
throw 'dbManager undefined';
|
|
114
|
+
if (options.id === undefined)
|
|
115
|
+
throw '<id_or_pathname> of asset to delete is missing';
|
|
116
|
+
if (!options.id.startsWith('/'))
|
|
117
|
+
throw '-i --id only pathname is supported at the moment';
|
|
118
|
+
const dbAsset = await this.dbManager.dbAssetExist(options.id);
|
|
119
|
+
if (dbAsset === undefined)
|
|
120
|
+
throw 'Asset ' + options.id + ' not found';
|
|
121
|
+
await this.dbManager.dbAssetDelete(dbAsset);
|
|
122
|
+
logger.info('asset ' + dbAsset.id + ' ' + dbAsset.route + ' deleted');
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
logger.error(err);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
*
|
|
130
|
+
* @param options
|
|
131
|
+
*/
|
|
132
|
+
async commandDeletePathname(options) {
|
|
133
|
+
try {
|
|
134
|
+
await this.prologue(options);
|
|
135
|
+
if (!this.dbManager)
|
|
136
|
+
throw 'dbManager undefined';
|
|
137
|
+
const dbClient = new DBClient_1.DBClient(this.dbManager);
|
|
138
|
+
const list = await dbClient.selectFromTable('Assets to delete', 'cyk_asset', {
|
|
139
|
+
fields: 'asset_id,asset_route,asset_auth,asset_access,asset_mimetype,asset_last_update', sort: options.sort || '1',
|
|
140
|
+
where: (options.dest ? "asset_route like '" + options.dest + "%'" : undefined)
|
|
141
|
+
});
|
|
142
|
+
const reply = await inquirer_1.default.prompt({ type: 'confirm', name: 'confirm', message: 'Do you want to delete these ' + list.length + ' file(s)' });
|
|
143
|
+
if (reply.confirm) {
|
|
144
|
+
for (let ind = 0; ind < list.length; ind++) {
|
|
145
|
+
const asset = list[ind];
|
|
146
|
+
logger.info('delete ' + asset.asset_route);
|
|
147
|
+
const url = '/api/admin/assets/' + asset.asset_id;
|
|
148
|
+
await this.dbRemote?.apiServer.delete(url);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
logger.error(err);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
51
157
|
class AssetList extends Cmd_1.Cmd {
|
|
52
158
|
constructor(name, description) {
|
|
53
159
|
super(name);
|
|
@@ -83,7 +189,7 @@ class AssetU extends Cmd_1.Cmd {
|
|
|
83
189
|
//----------------------------------------------------------------------------------------------
|
|
84
190
|
this.ignorePatterns = ['.git', 'node_modules'];
|
|
85
191
|
this.description(description)
|
|
86
|
-
.option('-i --id <id>', 'asset id
|
|
192
|
+
.option('-i --id <id>', 'asset id or pathname whose properties are updated')
|
|
87
193
|
.option('--auth <auth_schema>', 'authentication schema : basic | token | cookie | any | none, default is none')
|
|
88
194
|
.option('--access <access>', 'access rights required')
|
|
89
195
|
.option('-d --dest <destination>', 'destination path, directory name')
|
|
@@ -112,12 +218,12 @@ class AssetU extends Cmd_1.Cmd {
|
|
|
112
218
|
async commandU(sources, options) {
|
|
113
219
|
if (sources.length > 0) {
|
|
114
220
|
// upload
|
|
115
|
-
logger.debug('upload sources :', sources)
|
|
221
|
+
// logger.debug('upload sources :', sources)
|
|
116
222
|
await this.commandUpload(sources, options);
|
|
117
223
|
}
|
|
118
224
|
else {
|
|
119
225
|
// update
|
|
120
|
-
logger.debug('update', options)
|
|
226
|
+
// logger.debug('update', options)
|
|
121
227
|
await this.commandUpdate(options);
|
|
122
228
|
}
|
|
123
229
|
}
|
|
@@ -131,11 +237,13 @@ class AssetU extends Cmd_1.Cmd {
|
|
|
131
237
|
if (this.dbManager === undefined)
|
|
132
238
|
throw 'dbManager undefined';
|
|
133
239
|
if (options.id === undefined)
|
|
134
|
-
throw '<
|
|
240
|
+
throw '<id_or_pathname> of asset to update is missing';
|
|
241
|
+
if (!options.id.startsWith('/'))
|
|
242
|
+
throw '-i --id only pathname is supported at the moment';
|
|
135
243
|
const dbAsset = await this.dbManager.dbAssetExist(options.id);
|
|
136
244
|
if (dbAsset === undefined)
|
|
137
245
|
throw 'Asset ' + options.id + ' not found';
|
|
138
|
-
await this.updateAuthAccess('cyk_asset', '
|
|
246
|
+
await this.updateAuthAccess('cyk_asset', 'asset', dbAsset.id || '', options);
|
|
139
247
|
}
|
|
140
248
|
catch (err) {
|
|
141
249
|
logger.error(err);
|
|
@@ -156,8 +264,8 @@ class AssetU extends Cmd_1.Cmd {
|
|
|
156
264
|
if (options.auth && ' basic | token | cookie | any | none'.indexOf(options.auth) === -1) {
|
|
157
265
|
throw 'valid authentication schemas are : basic | token | cookie | any | none';
|
|
158
266
|
}
|
|
159
|
-
logger.debug('options : ', options)
|
|
160
|
-
logger.debug('auth : ' + options.auth)
|
|
267
|
+
// logger.debug('options : ', options)
|
|
268
|
+
// logger.debug('auth : ' + options.auth)
|
|
161
269
|
let dest = "/";
|
|
162
270
|
if (options.dest !== undefined)
|
|
163
271
|
dest = options.dest;
|
|
@@ -191,7 +299,7 @@ class AssetU extends Cmd_1.Cmd {
|
|
|
191
299
|
// cleanDestination
|
|
192
300
|
//----------------------------------------------------------------------------------------------
|
|
193
301
|
async cleanDestination(dest) {
|
|
194
|
-
const remoteList = await this.
|
|
302
|
+
const remoteList = await scanAssets(this.dbManager);
|
|
195
303
|
for (let ind = 0; ind < remoteList.length; ind++) {
|
|
196
304
|
const fd = remoteList[ind];
|
|
197
305
|
if (fd.path.startsWith(dest)) {
|
|
@@ -213,9 +321,9 @@ class AssetU extends Cmd_1.Cmd {
|
|
|
213
321
|
else {
|
|
214
322
|
dirName = source + '/';
|
|
215
323
|
}
|
|
216
|
-
logger.debug('options', options)
|
|
324
|
+
// logger.debug('options', options)
|
|
217
325
|
this.scanDir(dirName, localList);
|
|
218
|
-
const remoteList = await this.
|
|
326
|
+
const remoteList = await scanAssets(this.dbManager);
|
|
219
327
|
const uploadList = this.buildUploadList(dirName, dest, localList, remoteList);
|
|
220
328
|
// logger.info(fileNames.join('\n'))
|
|
221
329
|
if (uploadList.length === 0)
|
|
@@ -265,34 +373,6 @@ class AssetU extends Cmd_1.Cmd {
|
|
|
265
373
|
return result;
|
|
266
374
|
}
|
|
267
375
|
//----------------------------------------------------------------------------------------------
|
|
268
|
-
// scanAssets
|
|
269
|
-
//----------------------------------------------------------------------------------------------
|
|
270
|
-
async scanAssets() {
|
|
271
|
-
const result = [];
|
|
272
|
-
if (this.dbManager === undefined)
|
|
273
|
-
throw 'dbManager undefined';
|
|
274
|
-
const dbReq = new core_1.DBExecuteRequest();
|
|
275
|
-
dbReq.selectFromTable = 'cyk_asset';
|
|
276
|
-
const pFields = dbReq.parameters.addVariable('fields', this.dbManager.scope.structure.stringDataType);
|
|
277
|
-
pFields.data = new core_1.PrimitiveData(this.dbManager.scope.structure.stringDataType, "asset_id,asset_route,asset_last_update,asset_mimetype");
|
|
278
|
-
const xmlResult = await this.dbManager.dbExecute(dbReq);
|
|
279
|
-
if (xmlResult === undefined || xmlResult === null)
|
|
280
|
-
throw 'xmlResult null or undefined';
|
|
281
|
-
const tag = (0, core_1.parseXML)('scanAssets', xmlResult);
|
|
282
|
-
const objResult = await this.dbManager.scope.structure.objectDataType.parseData(tag, this.dbManager.scope);
|
|
283
|
-
const rows = objResult.variables.getData('cyk_asset').variables;
|
|
284
|
-
for (let ind = 0; ind < rows.list.length; ind++) {
|
|
285
|
-
const { variable: row } = rows.list[ind];
|
|
286
|
-
const record = row.data;
|
|
287
|
-
const asset_id = record.variables.getData('asset_id').value;
|
|
288
|
-
const asset_route = record.variables.getData('asset_route').value;
|
|
289
|
-
const asset_last_update = record.variables.getData('asset_last_update')?.value;
|
|
290
|
-
// logger.debug('asset_route ' + asset_route,'asset_last_update ' + asset_last_update)
|
|
291
|
-
result.push({ path: asset_route, mtime: asset_last_update, id: asset_id });
|
|
292
|
-
}
|
|
293
|
-
return result;
|
|
294
|
-
}
|
|
295
|
-
//----------------------------------------------------------------------------------------------
|
|
296
376
|
// scanDir
|
|
297
377
|
//----------------------------------------------------------------------------------------------
|
|
298
378
|
scanDir(dirName, result) {
|
|
@@ -339,7 +419,7 @@ class AssetU extends Cmd_1.Cmd {
|
|
|
339
419
|
// uploadAsset
|
|
340
420
|
//----------------------------------------------------------------------------------------------
|
|
341
421
|
async uploadAsset(upload, route, auth) {
|
|
342
|
-
logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth)
|
|
422
|
+
// logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth)
|
|
343
423
|
try {
|
|
344
424
|
let dbAsset = await this.dbManager?.dbAssetExist(route);
|
|
345
425
|
if (dbAsset === undefined) {
|
package/build/DBClient.d.ts
CHANGED
package/build/DBClient.js
CHANGED
|
@@ -48,6 +48,7 @@ class DBClient {
|
|
|
48
48
|
async runQuery() {
|
|
49
49
|
}
|
|
50
50
|
async selectFromTable(title, tableName, options) {
|
|
51
|
+
let result = [];
|
|
51
52
|
try {
|
|
52
53
|
const objectDataType = this.dbManager.scope.structure.objectDataType;
|
|
53
54
|
const stringDataType = this.dbManager.scope.structure.stringDataType;
|
|
@@ -101,14 +102,19 @@ class DBClient {
|
|
|
101
102
|
}
|
|
102
103
|
const objDataset = objXmlResult.variables.getData(tableName);
|
|
103
104
|
for (let ind = 0; ind < objDataset.variables.length(); ind++) {
|
|
104
|
-
const
|
|
105
|
-
|
|
105
|
+
const variable = objDataset.variables.at(ind);
|
|
106
|
+
if (variable) {
|
|
107
|
+
const record = variable?.data;
|
|
108
|
+
list.addObjectData(record);
|
|
109
|
+
result.push((0, core_1.variable2json)(variable));
|
|
110
|
+
}
|
|
106
111
|
}
|
|
107
112
|
logger.info(list.renderList(title));
|
|
108
113
|
}
|
|
109
114
|
catch (err) {
|
|
110
115
|
logger.error(err);
|
|
111
116
|
}
|
|
117
|
+
return result;
|
|
112
118
|
}
|
|
113
119
|
async deleteModule(dbname) {
|
|
114
120
|
try {
|
package/build/InitCommand.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/build/ModuleCommand.js
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
6
10
|
}) : (function(o, m, k, k2) {
|
|
7
11
|
if (k2 === undefined) k2 = k;
|
|
8
12
|
o[k2] = m[k];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OpenCommand = void 0;
|
|
7
|
+
const Cmd_1 = require("./Cmd");
|
|
8
|
+
const loglevel_1 = __importDefault(require("loglevel"));
|
|
9
|
+
const logger = loglevel_1.default.getLogger('OpenCommand.ts');
|
|
10
|
+
logger.setLevel('debug');
|
|
11
|
+
class OpenCommand extends Cmd_1.Cmd {
|
|
12
|
+
constructor() {
|
|
13
|
+
super('open');
|
|
14
|
+
this.description('open browser').version('0.1')
|
|
15
|
+
.argument('<module>', 'module to execute')
|
|
16
|
+
.action(async (module, options) => {
|
|
17
|
+
await this.openBrowser(module, options);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async openBrowser(module, options) {
|
|
21
|
+
try {
|
|
22
|
+
await this.prologue(options);
|
|
23
|
+
if (process.env.DBREMOTE_URL === undefined)
|
|
24
|
+
throw 'DBREMOTE_URL undefined';
|
|
25
|
+
const url = process.env.DBREMOTE_URL + '/cyk/#/run/' + module;
|
|
26
|
+
const open = await import('open');
|
|
27
|
+
open.default(url);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
logger.error(err);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.OpenCommand = OpenCommand;
|
package/build/RunCommand.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/build/TableCommand.js
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
6
10
|
}) : (function(o, m, k, k2) {
|
|
7
11
|
if (k2 === undefined) k2 = k;
|
|
8
12
|
o[k2] = m[k];
|
package/build/TestCommand.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/build/console.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/build/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const TestCommand_1 = require("./TestCommand");
|
|
|
14
14
|
const RunCommand_1 = require("./RunCommand");
|
|
15
15
|
const InitCommand_1 = require("./InitCommand");
|
|
16
16
|
const AssetCommand_1 = require("./AssetCommand");
|
|
17
|
+
const OpenCommand_1 = require("./OpenCommand");
|
|
17
18
|
const logger = loglevel_1.default.getLogger("index.ts");
|
|
18
19
|
logger.setLevel("debug");
|
|
19
20
|
const program = new commander_1.Command();
|
|
@@ -32,4 +33,5 @@ program.addCommand(new TableCommand_1.TableCommand('table'));
|
|
|
32
33
|
program.addCommand(new TableCommand_1.TableCommand('t'));
|
|
33
34
|
program.addCommand(new TestCommand_1.TestCommand());
|
|
34
35
|
program.addCommand(new RunCommand_1.RunCommand());
|
|
36
|
+
program.addCommand(new OpenCommand_1.OpenCommand());
|
|
35
37
|
program.parse();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyklang/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "cyklang CLI",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,13 +17,14 @@
|
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@cyklang/core": "^0.5.
|
|
20
|
+
"@cyklang/core": "^0.5.2",
|
|
21
21
|
"commander": "^9.4.0",
|
|
22
22
|
"dotenv": "^16.0.1",
|
|
23
23
|
"form-data": "^4.0.0",
|
|
24
24
|
"inquirer": "^8.2.5",
|
|
25
25
|
"loglevel": "^1.8.0",
|
|
26
26
|
"mime-types": "^2.1.35",
|
|
27
|
+
"open": "^9.1.0",
|
|
27
28
|
"pako": "^2.0.4"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
@@ -32,8 +33,8 @@
|
|
|
32
33
|
"@types/pako": "^2.0.0",
|
|
33
34
|
"@types/sax": "^1.2.4",
|
|
34
35
|
"nodemon": "^2.0.16",
|
|
35
|
-
"ts-node": "^10.
|
|
36
|
-
"typescript": "
|
|
36
|
+
"ts-node": "^10.9.1",
|
|
37
|
+
"typescript": "^5.2.2"
|
|
37
38
|
},
|
|
38
39
|
"bin": {
|
|
39
40
|
"cyk": "build/index.js"
|
package/src/AssetCommand.ts
CHANGED
|
@@ -7,12 +7,44 @@ import path from "path"
|
|
|
7
7
|
import mime from 'mime-types'
|
|
8
8
|
import inquirer from 'inquirer'
|
|
9
9
|
// import readline from 'readline'
|
|
10
|
-
import { DBAsset, DBExecuteRequest, ObjectData, parseXML, PrimitiveData } from "@cyklang/core"
|
|
10
|
+
import { DBAsset, DBExecuteRequest, DBManager, ObjectData, parseXML, PrimitiveData } from "@cyklang/core"
|
|
11
11
|
import FormData from 'form-data'
|
|
12
12
|
|
|
13
13
|
const logger = getLogger('AssetCommand.ts')
|
|
14
14
|
logger.setLevel('debug')
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
//----------------------------------------------------------------------------------------------
|
|
18
|
+
// scanAssets
|
|
19
|
+
//----------------------------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
const scanAssets = async (dbManager: DBManager | undefined, dest?: string): Promise<FileDescriptor[]> => {
|
|
22
|
+
|
|
23
|
+
const result: FileDescriptor[] = []
|
|
24
|
+
if (dbManager === undefined) throw 'dbManager undefined'
|
|
25
|
+
const dbReq = new DBExecuteRequest()
|
|
26
|
+
dbReq.selectFromTable = 'cyk_asset'
|
|
27
|
+
const pFields = dbReq.parameters.addVariable('fields', dbManager.scope.structure.stringDataType)
|
|
28
|
+
pFields.data = new PrimitiveData(dbManager.scope.structure.stringDataType, "asset_id,asset_route,asset_last_update,asset_mimetype")
|
|
29
|
+
const xmlResult = await dbManager.dbExecute(dbReq)
|
|
30
|
+
if (xmlResult === undefined || xmlResult === null) throw 'xmlResult null or undefined'
|
|
31
|
+
const tag = parseXML('scanAssets', xmlResult)
|
|
32
|
+
const objResult = await dbManager.scope.structure.objectDataType.parseData(tag, dbManager.scope) as ObjectData
|
|
33
|
+
const rows = (objResult.variables.getData('cyk_asset') as ObjectData).variables
|
|
34
|
+
for (let ind = 0; ind < rows.list.length; ind++) {
|
|
35
|
+
const { variable: row } = rows.list[ind]
|
|
36
|
+
const record = row.data as ObjectData
|
|
37
|
+
const asset_id = (record.variables.getData('asset_id') as PrimitiveData).value as number
|
|
38
|
+
const asset_route = (record.variables.getData('asset_route') as PrimitiveData).value as string
|
|
39
|
+
const asset_last_update = (record.variables.getData('asset_last_update') as PrimitiveData)?.value as Date
|
|
40
|
+
// logger.debug('asset_route ' + asset_route,'asset_last_update ' + asset_last_update)
|
|
41
|
+
|
|
42
|
+
if (!dest || asset_route.startsWith(dest))
|
|
43
|
+
result.push({ path: asset_route, mtime: asset_last_update, id: asset_id })
|
|
44
|
+
}
|
|
45
|
+
return result
|
|
46
|
+
}
|
|
47
|
+
|
|
16
48
|
export class AssetCommand extends Command {
|
|
17
49
|
constructor(name: string, description: string) {
|
|
18
50
|
super(name)
|
|
@@ -22,9 +54,92 @@ export class AssetCommand extends Command {
|
|
|
22
54
|
this.addCommand(new AssetU('upload', 'upload asset content from source files to a <destination> path'))
|
|
23
55
|
this.addCommand(new AssetU('update', 'update properties of asset identified by its <id>'))
|
|
24
56
|
this.addCommand(new AssetU('u', '(u)pload assets content from sources or (u)pdate asset properties'))
|
|
57
|
+
this.addCommand(new AssetDelete('delete', 'delete an asset'))
|
|
25
58
|
}
|
|
26
59
|
}
|
|
27
60
|
|
|
61
|
+
/**
|
|
62
|
+
* class AssetDelete
|
|
63
|
+
*/
|
|
64
|
+
class AssetDelete extends Cmd {
|
|
65
|
+
constructor(name: string, description: string) {
|
|
66
|
+
super(name)
|
|
67
|
+
this.description(description)
|
|
68
|
+
.option('-i --id <id_pathname>', 'asset id or pathname to delete')
|
|
69
|
+
.option('-d --dest <destination>', 'delete all assets whose pathname begins with dest')
|
|
70
|
+
.action(async (options: any) => {
|
|
71
|
+
if (options.id)
|
|
72
|
+
await this.commandDeleteOne(options)
|
|
73
|
+
else if (options.dest) {
|
|
74
|
+
await this.commandDeletePathname(options)
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
logger.error('one of --id or --dest options is required')
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param options
|
|
85
|
+
*/
|
|
86
|
+
async commandDeleteOne(options: any) {
|
|
87
|
+
try {
|
|
88
|
+
await this.prologue(options)
|
|
89
|
+
if (this.dbManager === undefined) throw 'dbManager undefined'
|
|
90
|
+
|
|
91
|
+
if (options.id === undefined) throw '<id_or_pathname> of asset to delete is missing'
|
|
92
|
+
|
|
93
|
+
if (!options.id.startsWith('/')) throw '-i --id only pathname is supported at the moment'
|
|
94
|
+
|
|
95
|
+
const dbAsset = await this.dbManager.dbAssetExist(options.id)
|
|
96
|
+
if (dbAsset === undefined) throw 'Asset ' + options.id + ' not found'
|
|
97
|
+
|
|
98
|
+
await this.dbManager.dbAssetDelete(dbAsset)
|
|
99
|
+
|
|
100
|
+
logger.info('asset ' + dbAsset.id + ' ' + dbAsset.route + ' deleted')
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
logger.error(err)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
*
|
|
109
|
+
* @param options
|
|
110
|
+
*/
|
|
111
|
+
async commandDeletePathname(options: any) {
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
await this.prologue(options)
|
|
115
|
+
if (! this.dbManager) throw 'dbManager undefined'
|
|
116
|
+
const dbClient = new DBClient(this.dbManager)
|
|
117
|
+
const list = await dbClient.selectFromTable('Assets to delete', 'cyk_asset',
|
|
118
|
+
{
|
|
119
|
+
fields: 'asset_id,asset_route,asset_auth,asset_access,asset_mimetype,asset_last_update', sort: options.sort || '1',
|
|
120
|
+
where: (options.dest ? "asset_route like '" + options.dest + "%'" : undefined)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
);
|
|
124
|
+
const reply = await inquirer.prompt({type: 'confirm', name: 'confirm', message: 'Do you want to delete these ' + list.length + ' file(s)'})
|
|
125
|
+
if (reply.confirm) {
|
|
126
|
+
for(let ind = 0; ind < list.length; ind++) {
|
|
127
|
+
const asset = list[ind]
|
|
128
|
+
logger.info('delete ' + asset.asset_route)
|
|
129
|
+
const url = '/api/admin/assets/' + asset.asset_id
|
|
130
|
+
await this.dbRemote?.apiServer.delete(url)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
logger.error(err)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
28
143
|
class AssetList extends Cmd {
|
|
29
144
|
constructor(name: string, description: string) {
|
|
30
145
|
super(name)
|
|
@@ -66,7 +181,7 @@ class AssetU extends Cmd {
|
|
|
66
181
|
constructor(name: string, description: string) {
|
|
67
182
|
super(name)
|
|
68
183
|
this.description(description)
|
|
69
|
-
.option('-i --id <id>', 'asset id
|
|
184
|
+
.option('-i --id <id>', 'asset id or pathname whose properties are updated')
|
|
70
185
|
.option('--auth <auth_schema>', 'authentication schema : basic | token | cookie | any | none, default is none')
|
|
71
186
|
.option('--access <access>', 'access rights required')
|
|
72
187
|
.option('-d --dest <destination>', 'destination path, directory name')
|
|
@@ -97,12 +212,12 @@ class AssetU extends Cmd {
|
|
|
97
212
|
async commandU(sources: string[], options: any) {
|
|
98
213
|
if (sources.length > 0) {
|
|
99
214
|
// upload
|
|
100
|
-
logger.debug('upload sources :', sources)
|
|
215
|
+
// logger.debug('upload sources :', sources)
|
|
101
216
|
await this.commandUpload(sources, options)
|
|
102
217
|
}
|
|
103
218
|
else {
|
|
104
219
|
// update
|
|
105
|
-
logger.debug('update', options)
|
|
220
|
+
// logger.debug('update', options)
|
|
106
221
|
await this.commandUpdate(options)
|
|
107
222
|
}
|
|
108
223
|
}
|
|
@@ -116,12 +231,14 @@ class AssetU extends Cmd {
|
|
|
116
231
|
await this.prologue(options)
|
|
117
232
|
if (this.dbManager === undefined) throw 'dbManager undefined'
|
|
118
233
|
|
|
119
|
-
if (options.id === undefined) throw '<
|
|
234
|
+
if (options.id === undefined) throw '<id_or_pathname> of asset to update is missing'
|
|
235
|
+
|
|
236
|
+
if (!options.id.startsWith('/')) throw '-i --id only pathname is supported at the moment'
|
|
120
237
|
|
|
121
238
|
const dbAsset = await this.dbManager.dbAssetExist(options.id)
|
|
122
239
|
if (dbAsset === undefined) throw 'Asset ' + options.id + ' not found'
|
|
123
240
|
|
|
124
|
-
await this.updateAuthAccess('cyk_asset', '
|
|
241
|
+
await this.updateAuthAccess('cyk_asset', 'asset', dbAsset.id || '', options)
|
|
125
242
|
|
|
126
243
|
}
|
|
127
244
|
catch (err) {
|
|
@@ -145,8 +262,8 @@ class AssetU extends Cmd {
|
|
|
145
262
|
if (options.auth && ' basic | token | cookie | any | none'.indexOf(options.auth) === -1) {
|
|
146
263
|
throw 'valid authentication schemas are : basic | token | cookie | any | none'
|
|
147
264
|
}
|
|
148
|
-
logger.debug('options : ', options)
|
|
149
|
-
logger.debug('auth : ' + options.auth)
|
|
265
|
+
// logger.debug('options : ', options)
|
|
266
|
+
// logger.debug('auth : ' + options.auth)
|
|
150
267
|
|
|
151
268
|
let dest = "/"
|
|
152
269
|
if (options.dest !== undefined) dest = options.dest
|
|
@@ -182,7 +299,7 @@ class AssetU extends Cmd {
|
|
|
182
299
|
|
|
183
300
|
async cleanDestination(dest: string) {
|
|
184
301
|
|
|
185
|
-
const remoteList = await this.
|
|
302
|
+
const remoteList = await scanAssets(this.dbManager)
|
|
186
303
|
for (let ind = 0; ind < remoteList.length; ind++) {
|
|
187
304
|
const fd = remoteList[ind]
|
|
188
305
|
if (fd.path.startsWith(dest)) {
|
|
@@ -208,11 +325,11 @@ class AssetU extends Cmd {
|
|
|
208
325
|
dirName = source + '/'
|
|
209
326
|
}
|
|
210
327
|
|
|
211
|
-
logger.debug('options', options)
|
|
328
|
+
// logger.debug('options', options)
|
|
212
329
|
|
|
213
330
|
this.scanDir(dirName, localList)
|
|
214
331
|
|
|
215
|
-
const remoteList = await this.
|
|
332
|
+
const remoteList = await scanAssets(this.dbManager)
|
|
216
333
|
|
|
217
334
|
const uploadList = this.buildUploadList(dirName, dest, localList, remoteList)
|
|
218
335
|
|
|
@@ -268,35 +385,6 @@ class AssetU extends Cmd {
|
|
|
268
385
|
return result
|
|
269
386
|
}
|
|
270
387
|
|
|
271
|
-
|
|
272
|
-
//----------------------------------------------------------------------------------------------
|
|
273
|
-
// scanAssets
|
|
274
|
-
//----------------------------------------------------------------------------------------------
|
|
275
|
-
|
|
276
|
-
async scanAssets() {
|
|
277
|
-
const result: FileDescriptor[] = []
|
|
278
|
-
if (this.dbManager === undefined) throw 'dbManager undefined'
|
|
279
|
-
const dbReq = new DBExecuteRequest()
|
|
280
|
-
dbReq.selectFromTable = 'cyk_asset'
|
|
281
|
-
const pFields = dbReq.parameters.addVariable('fields', this.dbManager.scope.structure.stringDataType)
|
|
282
|
-
pFields.data = new PrimitiveData(this.dbManager.scope.structure.stringDataType, "asset_id,asset_route,asset_last_update,asset_mimetype")
|
|
283
|
-
const xmlResult = await this.dbManager.dbExecute(dbReq)
|
|
284
|
-
if (xmlResult === undefined || xmlResult === null) throw 'xmlResult null or undefined'
|
|
285
|
-
const tag = parseXML('scanAssets', xmlResult)
|
|
286
|
-
const objResult = await this.dbManager.scope.structure.objectDataType.parseData(tag, this.dbManager.scope) as ObjectData
|
|
287
|
-
const rows = (objResult.variables.getData('cyk_asset') as ObjectData).variables
|
|
288
|
-
for (let ind = 0; ind < rows.list.length; ind++) {
|
|
289
|
-
const { variable: row } = rows.list[ind]
|
|
290
|
-
const record = row.data as ObjectData
|
|
291
|
-
const asset_id = (record.variables.getData('asset_id') as PrimitiveData).value as number
|
|
292
|
-
const asset_route = (record.variables.getData('asset_route') as PrimitiveData).value as string
|
|
293
|
-
const asset_last_update = (record.variables.getData('asset_last_update') as PrimitiveData)?.value as Date
|
|
294
|
-
// logger.debug('asset_route ' + asset_route,'asset_last_update ' + asset_last_update)
|
|
295
|
-
result.push({ path: asset_route, mtime: asset_last_update, id: asset_id })
|
|
296
|
-
}
|
|
297
|
-
return result
|
|
298
|
-
}
|
|
299
|
-
|
|
300
388
|
//----------------------------------------------------------------------------------------------
|
|
301
389
|
// scanDir
|
|
302
390
|
//----------------------------------------------------------------------------------------------
|
|
@@ -354,7 +442,7 @@ class AssetU extends Cmd {
|
|
|
354
442
|
//----------------------------------------------------------------------------------------------
|
|
355
443
|
|
|
356
444
|
async uploadAsset(upload: FileDescriptor, route: string, auth?: string) {
|
|
357
|
-
logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth)
|
|
445
|
+
// logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth)
|
|
358
446
|
|
|
359
447
|
try {
|
|
360
448
|
let dbAsset: DBAsset | undefined = await this.dbManager?.dbAssetExist(route)
|
package/src/DBClient.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasicType, DBColumn, DBExecuteRequest, DBManager, DBTable, ObjectData, parseXML, PrimitiveData, Script, XmlError } from "@cyklang/core";
|
|
1
|
+
import { BasicType, DBColumn, DBExecuteRequest, DBManager, DBTable, ObjectData, parseXML, PrimitiveData, Script, variable2json, XmlError } from "@cyklang/core";
|
|
2
2
|
import loglevel from "loglevel";
|
|
3
3
|
import { errorconsole } from "./console";
|
|
4
4
|
const logger = loglevel.getLogger('DBClient.ts')
|
|
@@ -47,9 +47,11 @@ export class DBClient {
|
|
|
47
47
|
async runQuery() {
|
|
48
48
|
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
async selectFromTable(title: string, tableName: string, options:
|
|
52
|
-
{ fields: string, sort?: string | undefined, where?: string | undefined, width?: string | undefined }) {
|
|
52
|
+
{ fields: string, sort?: string | undefined, where?: string | undefined, width?: string | undefined }): Promise<any[]> {
|
|
53
|
+
|
|
54
|
+
let result: any[] = []
|
|
53
55
|
|
|
54
56
|
try {
|
|
55
57
|
|
|
@@ -107,8 +109,13 @@ export class DBClient {
|
|
|
107
109
|
|
|
108
110
|
const objDataset = objXmlResult.variables.getData(tableName) as ObjectData
|
|
109
111
|
for (let ind = 0; ind < objDataset.variables.length(); ind++) {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
+
const variable = objDataset.variables.at(ind)
|
|
113
|
+
if (variable) {
|
|
114
|
+
const record = (variable?.data as ObjectData)
|
|
115
|
+
list.addObjectData(record)
|
|
116
|
+
result.push(variable2json(variable))
|
|
117
|
+
}
|
|
118
|
+
|
|
112
119
|
}
|
|
113
120
|
logger.info(list.renderList(title))
|
|
114
121
|
|
|
@@ -116,6 +123,7 @@ export class DBClient {
|
|
|
116
123
|
catch (err) {
|
|
117
124
|
logger.error(err)
|
|
118
125
|
}
|
|
126
|
+
return result
|
|
119
127
|
}
|
|
120
128
|
|
|
121
129
|
async deleteModule(dbname: string) {
|
|
@@ -124,7 +132,7 @@ export class DBClient {
|
|
|
124
132
|
const dbModule = await this.dbManager.dbModuleExist(dbname)
|
|
125
133
|
|
|
126
134
|
if (dbModule === undefined) {
|
|
127
|
-
|
|
135
|
+
throw ('Module ' + dbname + ' not found')
|
|
128
136
|
}
|
|
129
137
|
await this.dbManager.dbModuleDelete(dbModule)
|
|
130
138
|
}
|
|
@@ -217,7 +225,7 @@ class List {
|
|
|
217
225
|
}
|
|
218
226
|
this.lines.push(this.renderSeparator())
|
|
219
227
|
this.lines.push('Number of lines : ' + this.rows.length)
|
|
220
|
-
|
|
228
|
+
|
|
221
229
|
return this.lines.join('\n')
|
|
222
230
|
}
|
|
223
231
|
|
|
@@ -272,7 +280,7 @@ class List {
|
|
|
272
280
|
}
|
|
273
281
|
|
|
274
282
|
// replace \n with a space
|
|
275
|
-
result = result.replace(/\n/, ' ')
|
|
283
|
+
result = result.replace(/\n/, ' ')
|
|
276
284
|
|
|
277
285
|
if (width !== undefined && width !== 0) {
|
|
278
286
|
if (result.length >= width) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Cmd } from "./Cmd";
|
|
2
|
+
|
|
3
|
+
import loglevel from 'loglevel'
|
|
4
|
+
const logger = loglevel.getLogger('OpenCommand.ts')
|
|
5
|
+
logger.setLevel('debug')
|
|
6
|
+
|
|
7
|
+
export class OpenCommand extends Cmd {
|
|
8
|
+
constructor() {
|
|
9
|
+
super('open')
|
|
10
|
+
this.description('open browser').version('0.1')
|
|
11
|
+
.argument('<module>', 'module to execute')
|
|
12
|
+
.action(async (module: any, options: any) => {
|
|
13
|
+
await this.openBrowser(module, options)
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async openBrowser(module: string, options: any) {
|
|
18
|
+
try {
|
|
19
|
+
await this.prologue(options)
|
|
20
|
+
|
|
21
|
+
if (process.env.DBREMOTE_URL === undefined) throw 'DBREMOTE_URL undefined'
|
|
22
|
+
const url = process.env.DBREMOTE_URL + '/cyk/#/run/' + module;
|
|
23
|
+
const open = await import('open');
|
|
24
|
+
open.default(url)
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
logger.error(err)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { TestCommand } from './TestCommand'
|
|
|
9
9
|
import { RunCommand } from './RunCommand'
|
|
10
10
|
import { InitCommand } from './InitCommand'
|
|
11
11
|
import { AssetCommand } from './AssetCommand'
|
|
12
|
+
import { OpenCommand } from './OpenCommand'
|
|
12
13
|
const logger = loglevel.getLogger("index.ts")
|
|
13
14
|
logger.setLevel("debug")
|
|
14
15
|
|
|
@@ -29,5 +30,6 @@ program.addCommand(new TableCommand('table'))
|
|
|
29
30
|
program.addCommand(new TableCommand('t'))
|
|
30
31
|
program.addCommand(new TestCommand())
|
|
31
32
|
program.addCommand(new RunCommand())
|
|
33
|
+
program.addCommand(new OpenCommand())
|
|
32
34
|
|
|
33
35
|
program.parse()
|
package/test/t27.output
ADDED
package/test/t27.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?xml-model href="https://www.cyklang.net/schema/cyklang.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
|
2
|
+
<module>
|
|
3
|
+
<print>objson('150')</print>
|
|
4
|
+
<string name="chaine" literal=""><![CDATA[
|
|
5
|
+
{
|
|
6
|
+
"user_id": 1,
|
|
7
|
+
"user_name": "cyk",
|
|
8
|
+
"user_email": "cyk@gmail.com",
|
|
9
|
+
"user_password": "$2b$10$Et1b0DodTNKxW/jvUFC8be8JrRXULHWC5RnwOjVhUXmVKv.CyfFW.",
|
|
10
|
+
"user_access": "admin",
|
|
11
|
+
"user_appli": null,
|
|
12
|
+
"user_disable": false,
|
|
13
|
+
"user_lang": null
|
|
14
|
+
}
|
|
15
|
+
]]>
|
|
16
|
+
</string>
|
|
17
|
+
<print>json(objson(chaine))</print>
|
|
18
|
+
</module>
|