@cyklang/cli 0.4.0 → 0.5.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.
- package/build/AssetCommand.js +120 -40
- package/build/Cmd.js +1 -1
- package/build/DBClient.d.ts +1 -1
- package/build/DBClient.js +8 -2
- package/build/InitCommand.js +5 -1
- package/build/InstallCommand.d.ts +10 -0
- package/build/InstallCommand.js +87 -0
- package/build/ModuleCommand.d.ts +7 -0
- package/build/ModuleCommand.js +39 -26
- package/build/OpenCommand.d.ts +5 -0
- package/build/OpenCommand.js +34 -0
- package/build/RunCommand.d.ts +1 -1
- package/build/RunCommand.js +7 -3
- package/build/TableCommand.js +5 -1
- package/build/TestCommand.js +5 -1
- package/build/console.js +5 -1
- package/build/index.js +8 -3
- package/package.json +5 -4
- package/src/AssetCommand.ts +129 -41
- package/src/Cmd.ts +1 -1
- package/src/DBClient.ts +16 -8
- package/src/InstallCommand.ts +71 -0
- package/src/ModuleCommand.ts +34 -25
- package/src/OpenCommand.ts +31 -0
- package/src/RunCommand.ts +2 -2
- package/src/index.ts +8 -3
- 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/Cmd.js
CHANGED
|
@@ -24,7 +24,7 @@ class Cmd extends commander_1.Command {
|
|
|
24
24
|
const structure = new core_1.Structure();
|
|
25
25
|
if (process.env.DBREMOTE_URL === undefined)
|
|
26
26
|
throw 'DBREMOTE_URL undefined';
|
|
27
|
-
logger.
|
|
27
|
+
logger.info('Cyk server: ' + process.env.DBREMOTE_URL);
|
|
28
28
|
const nodeCrypto = new NodeCrypto_1.NodeCrypto();
|
|
29
29
|
this.dbRemote = new core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto);
|
|
30
30
|
const login = await this.dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
|
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];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Cmd } from "./Cmd";
|
|
2
|
+
export declare class InstallCommand extends Cmd {
|
|
3
|
+
constructor(name: string);
|
|
4
|
+
install(node_package: string, options: any): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* method verifyPackageJson
|
|
7
|
+
* @param node_package
|
|
8
|
+
*/
|
|
9
|
+
verifyPackageJson(node_package: string): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.InstallCommand = void 0;
|
|
30
|
+
const Cmd_1 = require("./Cmd");
|
|
31
|
+
const fs = __importStar(require("fs"));
|
|
32
|
+
const path = __importStar(require("path"));
|
|
33
|
+
const loglevel_1 = __importDefault(require("loglevel"));
|
|
34
|
+
const ModuleCommand_1 = require("./ModuleCommand");
|
|
35
|
+
const logger = loglevel_1.default.getLogger('InstallCommand.ts');
|
|
36
|
+
logger.setLevel('debug');
|
|
37
|
+
class InstallCommand extends Cmd_1.Cmd {
|
|
38
|
+
constructor(name) {
|
|
39
|
+
super(name);
|
|
40
|
+
this.description('upload Cyk modules to a Cyk server from a Node package downloaded by "npm install" ')
|
|
41
|
+
.argument('<node_package>', 'Node Package installed as dependency')
|
|
42
|
+
.action(async (node_package, options) => {
|
|
43
|
+
await this.install(node_package, options);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async install(node_package, options) {
|
|
47
|
+
try {
|
|
48
|
+
await this.prologue(options);
|
|
49
|
+
if (this.dbManager === undefined)
|
|
50
|
+
throw 'dbManager undefined';
|
|
51
|
+
await this.verifyPackageJson(node_package);
|
|
52
|
+
const xmlFolder = path.join('node_modules', node_package, 'xml');
|
|
53
|
+
if (!fs.existsSync(xmlFolder) || !fs.statSync(xmlFolder).isDirectory()) {
|
|
54
|
+
throw 'xml folder not found ( ' + xmlFolder + ' )';
|
|
55
|
+
}
|
|
56
|
+
const files = fs.readdirSync(xmlFolder);
|
|
57
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
58
|
+
const file = files[ind];
|
|
59
|
+
await (0, ModuleCommand_1.uploadModule)(path.join(xmlFolder, file), this.dbManager);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
logger.error(err);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* method verifyPackageJson
|
|
68
|
+
* @param node_package
|
|
69
|
+
*/
|
|
70
|
+
async verifyPackageJson(node_package) {
|
|
71
|
+
let packageJson;
|
|
72
|
+
try {
|
|
73
|
+
// Lecture du contenu du fichier package.json en tant que chaîne de caractères
|
|
74
|
+
const packageJsonContent = fs.readFileSync('package.json', 'utf8');
|
|
75
|
+
// Analyse du contenu en tant qu'objet JSON
|
|
76
|
+
packageJson = JSON.parse(packageJsonContent);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
console.error('Error loading package.json file :', error);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
if (!packageJson.dependencies || !packageJson.dependencies[node_package]) {
|
|
83
|
+
throw node_package + ' not installed in the current project. Install it first with "npm install"';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.InstallCommand = InstallCommand;
|
package/build/ModuleCommand.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env ts-node
|
|
2
|
+
import { DBManager } from "@cyklang/core";
|
|
2
3
|
import { Command } from 'commander';
|
|
3
4
|
export declare class ModuleCommand extends Command {
|
|
4
5
|
constructor(name: string);
|
|
5
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param file
|
|
10
|
+
* @param dbManager
|
|
11
|
+
*/
|
|
12
|
+
export declare function uploadModule(file: string, dbManager: DBManager): Promise<void>;
|
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];
|
|
@@ -23,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
28
|
};
|
|
25
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ModuleCommand = void 0;
|
|
30
|
+
exports.uploadModule = exports.ModuleCommand = void 0;
|
|
27
31
|
const core_1 = require("@cyklang/core");
|
|
28
32
|
const fs = __importStar(require("fs"));
|
|
29
33
|
const loglevel_1 = __importDefault(require("loglevel"));
|
|
@@ -131,30 +135,7 @@ class ModuleU extends Cmd_1.Cmd {
|
|
|
131
135
|
else {
|
|
132
136
|
for (let ind = 0; ind < files.length; ind++) {
|
|
133
137
|
const file = files[ind];
|
|
134
|
-
|
|
135
|
-
const source = fs.readFileSync(file).toString();
|
|
136
|
-
const tag = (0, core_1.parseXML)(dbname, source);
|
|
137
|
-
const dbModuleExist = await this.dbManager.dbModuleExist(dbname);
|
|
138
|
-
if (dbModuleExist === undefined) {
|
|
139
|
-
// insert
|
|
140
|
-
const dbModule = new core_1.DBModule();
|
|
141
|
-
dbModule.source = source;
|
|
142
|
-
dbModule.dbname = dbname;
|
|
143
|
-
dbModule.access = tag.attributes.ACCESS;
|
|
144
|
-
dbModule.description = tag.attributes.DESCRIPTION;
|
|
145
|
-
logger.debug('module insert ' + dbname + ' access ' + dbModule.access + ' description ' + dbModule.description);
|
|
146
|
-
const id = await this.dbManager.dbModuleInsert(dbModule);
|
|
147
|
-
logger.info('module ' + dbname + ' added with ID ' + id);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
// update
|
|
151
|
-
dbModuleExist.source = source;
|
|
152
|
-
dbModuleExist.access = tag.attributes.ACCESS;
|
|
153
|
-
dbModuleExist.description = tag.attributes.DESCRIPTION;
|
|
154
|
-
logger.debug('module update ' + dbname + ' access ' + dbModuleExist.access + ' description ' + dbModuleExist.description);
|
|
155
|
-
await this.dbManager.dbModuleUpdate(dbModuleExist);
|
|
156
|
-
logger.info('module ' + dbname + ' updated');
|
|
157
|
-
}
|
|
138
|
+
await uploadModule(file, this.dbManager);
|
|
158
139
|
}
|
|
159
140
|
}
|
|
160
141
|
}
|
|
@@ -163,6 +144,38 @@ class ModuleU extends Cmd_1.Cmd {
|
|
|
163
144
|
}
|
|
164
145
|
}
|
|
165
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
*
|
|
149
|
+
* @param file
|
|
150
|
+
* @param dbManager
|
|
151
|
+
*/
|
|
152
|
+
async function uploadModule(file, dbManager) {
|
|
153
|
+
const dbname = getModuleDBName(file);
|
|
154
|
+
const source = fs.readFileSync(file).toString();
|
|
155
|
+
const tag = (0, core_1.parseXML)(dbname, source);
|
|
156
|
+
const dbModuleExist = await dbManager.dbModuleExist(dbname);
|
|
157
|
+
if (dbModuleExist === undefined) {
|
|
158
|
+
// insert
|
|
159
|
+
const dbModule = new core_1.DBModule();
|
|
160
|
+
dbModule.source = source;
|
|
161
|
+
dbModule.dbname = dbname;
|
|
162
|
+
dbModule.access = tag.attributes.ACCESS;
|
|
163
|
+
dbModule.description = tag.attributes.DESCRIPTION;
|
|
164
|
+
// logger.debug('module insert ' + dbname + ' access ' + dbModule.access + ' description ' + dbModule.description)
|
|
165
|
+
const id = await dbManager.dbModuleInsert(dbModule);
|
|
166
|
+
logger.info('module ' + dbname + ' added with ID ' + id);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// update
|
|
170
|
+
dbModuleExist.source = source;
|
|
171
|
+
dbModuleExist.access = tag.attributes.ACCESS;
|
|
172
|
+
dbModuleExist.description = tag.attributes.DESCRIPTION;
|
|
173
|
+
// logger.debug('module update ' + dbname + ' access ' + dbModuleExist.access + ' description ' + dbModuleExist.description)
|
|
174
|
+
await dbManager.dbModuleUpdate(dbModuleExist);
|
|
175
|
+
logger.info('module ' + dbname + ' updated');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.uploadModule = uploadModule;
|
|
166
179
|
class ModuleDownload extends Cmd_1.Cmd {
|
|
167
180
|
constructor(name, description) {
|
|
168
181
|
super(name);
|
|
@@ -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(name) {
|
|
13
|
+
super(name);
|
|
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.d.ts
CHANGED
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];
|
|
@@ -32,8 +36,8 @@ const Cmd_1 = require("./Cmd");
|
|
|
32
36
|
loglevel_1.default.setLevel('debug');
|
|
33
37
|
const logger = loglevel_1.default.getLogger('RunCommand.ts');
|
|
34
38
|
class RunCommand extends Cmd_1.Cmd {
|
|
35
|
-
constructor() {
|
|
36
|
-
super(
|
|
39
|
+
constructor(name) {
|
|
40
|
+
super(name);
|
|
37
41
|
this.description('run module').version('0.2')
|
|
38
42
|
.argument('<files...>', 'local module file(s) to run')
|
|
39
43
|
.action(async (files, options) => {
|
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
|
@@ -12,14 +12,16 @@ const QueryCommand_1 = require("./QueryCommand");
|
|
|
12
12
|
const TableCommand_1 = require("./TableCommand");
|
|
13
13
|
const TestCommand_1 = require("./TestCommand");
|
|
14
14
|
const RunCommand_1 = require("./RunCommand");
|
|
15
|
-
const
|
|
15
|
+
const InstallCommand_1 = require("./InstallCommand");
|
|
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();
|
|
20
21
|
program.name('cyk').description('cyklang CLI')
|
|
21
22
|
.version('0.2');
|
|
22
|
-
program.addCommand(new
|
|
23
|
+
program.addCommand(new InstallCommand_1.InstallCommand('install'));
|
|
24
|
+
program.addCommand(new InstallCommand_1.InstallCommand('i'));
|
|
23
25
|
program.addCommand(new AssetCommand_1.AssetCommand('asset', 'manage assets'));
|
|
24
26
|
program.addCommand(new AssetCommand_1.AssetCommand('a', 'manage assets'));
|
|
25
27
|
program.addCommand(new ModuleCommand_1.ModuleCommand('module'));
|
|
@@ -31,5 +33,8 @@ program.addCommand(new QueryCommand_1.QueryCommand('q'));
|
|
|
31
33
|
program.addCommand(new TableCommand_1.TableCommand('table'));
|
|
32
34
|
program.addCommand(new TableCommand_1.TableCommand('t'));
|
|
33
35
|
program.addCommand(new TestCommand_1.TestCommand());
|
|
34
|
-
program.addCommand(new RunCommand_1.RunCommand());
|
|
36
|
+
program.addCommand(new RunCommand_1.RunCommand('run'));
|
|
37
|
+
program.addCommand(new RunCommand_1.RunCommand('r'));
|
|
38
|
+
program.addCommand(new OpenCommand_1.OpenCommand('open'));
|
|
39
|
+
program.addCommand(new OpenCommand_1.OpenCommand('o'));
|
|
35
40
|
program.parse();
|