@cyklang/cli 0.3.0 → 0.3.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 +14 -7
- package/build/UserCommand.js +5 -4
- package/package.json +1 -1
- package/src/AssetCommand.ts +15 -7
- package/src/UserCommand.ts +5 -4
package/build/AssetCommand.js
CHANGED
|
@@ -42,7 +42,7 @@ class AssetCommand extends commander_1.Command {
|
|
|
42
42
|
this.description(description);
|
|
43
43
|
this.addCommand(new AssetList('list', 'list assets'));
|
|
44
44
|
this.addCommand(new AssetList('l', '(l)ist assets'));
|
|
45
|
-
this.addCommand(new AssetUpload('upload', 'upload assets from
|
|
45
|
+
this.addCommand(new AssetUpload('upload', 'upload assets from sources'));
|
|
46
46
|
this.addCommand(new AssetUpload('u', '(u)pload assets'));
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -75,6 +75,7 @@ class AssetUpload extends Cmd_1.Cmd {
|
|
|
75
75
|
//----------------------------------------------------------------------------------------------
|
|
76
76
|
this.ignorePatterns = ['.git', 'node_modules'];
|
|
77
77
|
this.description(description)
|
|
78
|
+
.option('-a --auth <auth_schema>', 'authentication schema : basic | token | any, default is no authentication')
|
|
78
79
|
.option('-d --dest <destination>', 'destination path, directory name')
|
|
79
80
|
.option('-c --clean', 'clean destination path before uploading')
|
|
80
81
|
.option('-y --yes', 'upload list is automatically confirmed')
|
|
@@ -100,6 +101,11 @@ class AssetUpload extends Cmd_1.Cmd {
|
|
|
100
101
|
throw 'dbManager undefined';
|
|
101
102
|
if (sources.length === 0)
|
|
102
103
|
throw 'no source to upload';
|
|
104
|
+
if (options.auth && ' basic | token | any '.indexOf(options.auth) === -1) {
|
|
105
|
+
throw 'valid authentication schemas are : basic | token | any';
|
|
106
|
+
}
|
|
107
|
+
logger.debug('options : ', options);
|
|
108
|
+
logger.debug('auth : ' + options.auth);
|
|
103
109
|
let dest = "/";
|
|
104
110
|
if (options.dest !== undefined)
|
|
105
111
|
dest = options.dest;
|
|
@@ -121,7 +127,7 @@ class AssetUpload extends Cmd_1.Cmd {
|
|
|
121
127
|
else if (filestat.isFile() === true) {
|
|
122
128
|
const base = path_1.default.parse(source).base;
|
|
123
129
|
logger.debug('upload file ' + source + ' to ' + dest + base);
|
|
124
|
-
await this.uploadAsset({ path: source, mtime: filestat.mtime }, dest + base);
|
|
130
|
+
await this.uploadAsset({ path: source, mtime: filestat.mtime }, dest + base, options.auth);
|
|
125
131
|
}
|
|
126
132
|
}
|
|
127
133
|
}
|
|
@@ -169,7 +175,7 @@ class AssetUpload extends Cmd_1.Cmd {
|
|
|
169
175
|
uploadConfirmed = true;
|
|
170
176
|
}
|
|
171
177
|
if (uploadConfirmed === true) {
|
|
172
|
-
await this.uploadFiles(dirName, uploadList, dest);
|
|
178
|
+
await this.uploadFiles(dirName, uploadList, dest, options.auth);
|
|
173
179
|
}
|
|
174
180
|
// const rl = readline.createInterface(process.stdin, process.stdout)
|
|
175
181
|
// rl.question('Do you want to upload this(these) ' + uploadList.length + ' file(s) (Y/N/y/n) ?', async (reply) => {
|
|
@@ -269,19 +275,19 @@ class AssetUpload extends Cmd_1.Cmd {
|
|
|
269
275
|
//----------------------------------------------------------------------------------------------
|
|
270
276
|
// uploadFiles
|
|
271
277
|
//----------------------------------------------------------------------------------------------
|
|
272
|
-
async uploadFiles(dirName, uploadList, dest) {
|
|
278
|
+
async uploadFiles(dirName, uploadList, dest, auth) {
|
|
273
279
|
for (let ind = 0; ind < uploadList.length; ind++) {
|
|
274
280
|
const upload = uploadList[ind];
|
|
275
281
|
const route = dest + upload.path.substring(dirName.length);
|
|
276
282
|
logger.debug('upload ' + upload.path + ' to ' + route);
|
|
277
|
-
await this.uploadAsset(upload, route);
|
|
283
|
+
await this.uploadAsset(upload, route, auth);
|
|
278
284
|
}
|
|
279
285
|
}
|
|
280
286
|
//----------------------------------------------------------------------------------------------
|
|
281
287
|
// uploadAsset
|
|
282
288
|
//----------------------------------------------------------------------------------------------
|
|
283
|
-
async uploadAsset(upload, route) {
|
|
284
|
-
logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path));
|
|
289
|
+
async uploadAsset(upload, route, auth) {
|
|
290
|
+
logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth);
|
|
285
291
|
try {
|
|
286
292
|
let dbAsset = await this.dbManager?.dbAssetExist(route);
|
|
287
293
|
if (dbAsset === undefined) {
|
|
@@ -292,6 +298,7 @@ class AssetUpload extends Cmd_1.Cmd {
|
|
|
292
298
|
throw 'mimetype false for ' + upload;
|
|
293
299
|
dbAsset.mimetype = mimetype;
|
|
294
300
|
dbAsset.route = route;
|
|
301
|
+
dbAsset.auth = auth;
|
|
295
302
|
// const fstat = fs.statSync(fileName)
|
|
296
303
|
dbAsset.last_update = upload.mtime;
|
|
297
304
|
// const contentBuffer = fs.readFileSync(fileName)
|
package/build/UserCommand.js
CHANGED
|
@@ -16,7 +16,8 @@ class UserCommand extends commander_1.Command {
|
|
|
16
16
|
constructor(name) {
|
|
17
17
|
super(name);
|
|
18
18
|
this.description('manage users in cyk_user table').version('0.1');
|
|
19
|
-
this.addCommand(new UserAddCmd());
|
|
19
|
+
this.addCommand(new UserAddCmd('add', 'add a new user'));
|
|
20
|
+
this.addCommand(new UserAddCmd('a', 'add a new user'));
|
|
20
21
|
this.addCommand(new UserUpdateCmd('update', 'update user by id all fields except password'));
|
|
21
22
|
this.addCommand(new UserUpdateCmd('u', 'shortcut for (u)pdate'));
|
|
22
23
|
this.addCommand(new UserDeleteCmd('delete', 'delete user by id and name. Both options are mandatory to avoid typing error'));
|
|
@@ -27,9 +28,9 @@ class UserCommand extends commander_1.Command {
|
|
|
27
28
|
}
|
|
28
29
|
exports.UserCommand = UserCommand;
|
|
29
30
|
class UserAddCmd extends Cmd_1.Cmd {
|
|
30
|
-
constructor() {
|
|
31
|
-
super(
|
|
32
|
-
this.description(
|
|
31
|
+
constructor(name, description) {
|
|
32
|
+
super(name);
|
|
33
|
+
this.description(description)
|
|
33
34
|
.requiredOption('-n --name <name>', 'user name')
|
|
34
35
|
.option('-e --email <email>', 'user email address')
|
|
35
36
|
.option('-p --passwd <password>', 'initial password')
|
package/package.json
CHANGED
package/src/AssetCommand.ts
CHANGED
|
@@ -19,7 +19,7 @@ export class AssetCommand extends Command {
|
|
|
19
19
|
this.description(description)
|
|
20
20
|
this.addCommand(new AssetList('list', 'list assets'))
|
|
21
21
|
this.addCommand(new AssetList('l', '(l)ist assets'))
|
|
22
|
-
this.addCommand(new AssetUpload('upload', 'upload assets from
|
|
22
|
+
this.addCommand(new AssetUpload('upload', 'upload assets from sources'))
|
|
23
23
|
this.addCommand(new AssetUpload('u', '(u)pload assets'))
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -61,6 +61,7 @@ class AssetUpload extends Cmd {
|
|
|
61
61
|
constructor(name: string, description: string) {
|
|
62
62
|
super(name)
|
|
63
63
|
this.description(description)
|
|
64
|
+
.option('-a --auth <auth_schema>', 'authentication schema : basic | token | any, default is no authentication')
|
|
64
65
|
.option('-d --dest <destination>', 'destination path, directory name')
|
|
65
66
|
.option('-c --clean', 'clean destination path before uploading')
|
|
66
67
|
.option('-y --yes', 'upload list is automatically confirmed')
|
|
@@ -89,6 +90,12 @@ class AssetUpload extends Cmd {
|
|
|
89
90
|
|
|
90
91
|
if (sources.length === 0) throw 'no source to upload'
|
|
91
92
|
|
|
93
|
+
if ( options.auth && ' basic | token | any '.indexOf(options.auth) === -1 ) {
|
|
94
|
+
throw 'valid authentication schemas are : basic | token | any'
|
|
95
|
+
}
|
|
96
|
+
logger.debug('options : ', options)
|
|
97
|
+
logger.debug('auth : ' + options.auth)
|
|
98
|
+
|
|
92
99
|
let dest = "/"
|
|
93
100
|
if (options.dest !== undefined) dest = options.dest
|
|
94
101
|
if (dest.substring(0, 1) !== '/') dest = '/' + dest
|
|
@@ -108,7 +115,7 @@ class AssetUpload extends Cmd {
|
|
|
108
115
|
else if (filestat.isFile() === true) {
|
|
109
116
|
const base = path.parse(source).base
|
|
110
117
|
logger.debug('upload file ' + source + ' to ' + dest + base)
|
|
111
|
-
await this.uploadAsset({ path: source, mtime: filestat.mtime }, dest + base)
|
|
118
|
+
await this.uploadAsset({ path: source, mtime: filestat.mtime }, dest + base, options.auth)
|
|
112
119
|
}
|
|
113
120
|
}
|
|
114
121
|
}
|
|
@@ -168,7 +175,7 @@ class AssetUpload extends Cmd {
|
|
|
168
175
|
}
|
|
169
176
|
|
|
170
177
|
if (uploadConfirmed === true) {
|
|
171
|
-
await this.uploadFiles(dirName, uploadList, dest)
|
|
178
|
+
await this.uploadFiles(dirName, uploadList, dest, options.auth)
|
|
172
179
|
}
|
|
173
180
|
|
|
174
181
|
// const rl = readline.createInterface(process.stdin, process.stdout)
|
|
@@ -281,12 +288,12 @@ class AssetUpload extends Cmd {
|
|
|
281
288
|
// uploadFiles
|
|
282
289
|
//----------------------------------------------------------------------------------------------
|
|
283
290
|
|
|
284
|
-
async uploadFiles(dirName: string, uploadList: FileDescriptor[], dest: string) {
|
|
291
|
+
async uploadFiles(dirName: string, uploadList: FileDescriptor[], dest: string, auth: string | undefined) {
|
|
285
292
|
for (let ind = 0; ind < uploadList.length; ind++) {
|
|
286
293
|
const upload = uploadList[ind]
|
|
287
294
|
const route = dest + upload.path.substring(dirName.length)
|
|
288
295
|
logger.debug('upload ' + upload.path + ' to ' + route)
|
|
289
|
-
await this.uploadAsset(upload, route)
|
|
296
|
+
await this.uploadAsset(upload, route, auth)
|
|
290
297
|
}
|
|
291
298
|
}
|
|
292
299
|
|
|
@@ -294,8 +301,8 @@ class AssetUpload extends Cmd {
|
|
|
294
301
|
// uploadAsset
|
|
295
302
|
//----------------------------------------------------------------------------------------------
|
|
296
303
|
|
|
297
|
-
async uploadAsset(upload: FileDescriptor, route: string) {
|
|
298
|
-
logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path))
|
|
304
|
+
async uploadAsset(upload: FileDescriptor, route: string, auth?: string) {
|
|
305
|
+
logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth)
|
|
299
306
|
|
|
300
307
|
try {
|
|
301
308
|
let dbAsset: DBAsset | undefined = await this.dbManager?.dbAssetExist(route)
|
|
@@ -306,6 +313,7 @@ class AssetUpload extends Cmd {
|
|
|
306
313
|
if (mimetype === false) throw 'mimetype false for ' + upload
|
|
307
314
|
dbAsset.mimetype = mimetype
|
|
308
315
|
dbAsset.route = route
|
|
316
|
+
dbAsset.auth = auth
|
|
309
317
|
|
|
310
318
|
// const fstat = fs.statSync(fileName)
|
|
311
319
|
dbAsset.last_update = upload.mtime
|
package/src/UserCommand.ts
CHANGED
|
@@ -11,7 +11,8 @@ export class UserCommand extends Command {
|
|
|
11
11
|
constructor(name: string) {
|
|
12
12
|
super(name)
|
|
13
13
|
this.description('manage users in cyk_user table').version('0.1')
|
|
14
|
-
this.addCommand(new UserAddCmd())
|
|
14
|
+
this.addCommand(new UserAddCmd('add', 'add a new user'))
|
|
15
|
+
this.addCommand(new UserAddCmd('a', 'add a new user'))
|
|
15
16
|
this.addCommand(new UserUpdateCmd('update', 'update user by id all fields except password'))
|
|
16
17
|
this.addCommand(new UserUpdateCmd('u', 'shortcut for (u)pdate'))
|
|
17
18
|
this.addCommand(new UserDeleteCmd('delete', 'delete user by id and name. Both options are mandatory to avoid typing error'))
|
|
@@ -35,9 +36,9 @@ interface Options {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
class UserAddCmd extends Cmd {
|
|
38
|
-
constructor() {
|
|
39
|
-
super(
|
|
40
|
-
this.description(
|
|
39
|
+
constructor(name: string, description: string) {
|
|
40
|
+
super(name)
|
|
41
|
+
this.description(description)
|
|
41
42
|
.requiredOption('-n --name <name>', 'user name')
|
|
42
43
|
.option('-e --email <email>', 'user email address')
|
|
43
44
|
.option('-p --passwd <password>', 'initial password')
|