@adaptivestone/framework 5.0.0-alpha.24 → 5.0.0-alpha.26
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/CHANGELOG.md +5 -0
- package/commands/CreateUser.js +4 -0
- package/commands/Documentation.js +4 -0
- package/commands/GenerateRandomBytes.js +4 -0
- package/commands/GetOpenApiJson.js +4 -0
- package/modules/AbstractCommand.js +1 -1
- package/modules/BaseCli.js +23 -8
- package/package.json +1 -1
- package/commands/Generate.js +0 -14
package/CHANGELOG.md
CHANGED
package/commands/CreateUser.js
CHANGED
|
@@ -2,6 +2,10 @@ import AbstractCommand from '../modules/AbstractCommand.js';
|
|
|
2
2
|
|
|
3
3
|
// Example: node src/cli createuser --email=somemail@gmail.com --password=somePassword --roles=user,admin,someOtherRoles
|
|
4
4
|
class CreateUser extends AbstractCommand {
|
|
5
|
+
static get description() {
|
|
6
|
+
return 'Create user in a database';
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
async run() {
|
|
6
10
|
const User = this.app.getModel('User');
|
|
7
11
|
const { id, email, password, roles, update } = this.args;
|
|
@@ -2,6 +2,10 @@ import AbstractCommand from '../modules/AbstractCommand.js';
|
|
|
2
2
|
import ControllerManager from '../controllers/index.js';
|
|
3
3
|
|
|
4
4
|
class Documentation extends AbstractCommand {
|
|
5
|
+
static get description() {
|
|
6
|
+
return 'Generate documentation (internal)';
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
async run() {
|
|
6
10
|
const CM = new ControllerManager(this.app);
|
|
7
11
|
this.app.documentation = [];
|
|
@@ -2,6 +2,10 @@ import { randomBytes } from 'node:crypto';
|
|
|
2
2
|
import AbstractCommand from '../modules/AbstractCommand.js';
|
|
3
3
|
|
|
4
4
|
class GenerateRandomBytes extends AbstractCommand {
|
|
5
|
+
static get description() {
|
|
6
|
+
return 'Generate random bytes ising randomBytes from node:crypto';
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
async run() {
|
|
6
10
|
const sizes = [16, 32, 64, 128, 256];
|
|
7
11
|
for (const size of sizes) {
|
|
@@ -5,6 +5,10 @@ import AbstractCommand from '../modules/AbstractCommand.js';
|
|
|
5
5
|
* Command for generate documentation json file openApi
|
|
6
6
|
*/
|
|
7
7
|
class GetOpenApiJson extends AbstractCommand {
|
|
8
|
+
static get description() {
|
|
9
|
+
return 'Generate documentation (openApi) ';
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
async run() {
|
|
9
13
|
const { myDomain } = this.app.getConfig('http');
|
|
10
14
|
let jsonFile = process.env.npm_package_json;
|
package/modules/BaseCli.js
CHANGED
|
@@ -29,24 +29,39 @@ class Cli extends Base {
|
|
|
29
29
|
return true;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
async printComandTable() {
|
|
33
|
+
const commands = Object.keys(this.commands);
|
|
34
|
+
const maxLength = commands.reduce((max, c) => Math.max(max, c.length), 0);
|
|
35
|
+
console.log('Available commands:');
|
|
36
|
+
let commandsClasses = [];
|
|
37
|
+
for (const c of commands) {
|
|
38
|
+
// eslint-disable-next-line no-await-in-loop
|
|
39
|
+
commandsClasses.push(import(this.commands[c]));
|
|
40
|
+
// console.log(
|
|
41
|
+
// ` \x1b[36m${c.padEnd(maxLength)}\x1b[0m - ${f.default.description}`,
|
|
42
|
+
// );
|
|
43
|
+
}
|
|
44
|
+
commandsClasses = await Promise.all(commandsClasses);
|
|
45
|
+
for (const [key, c] of Object.entries(commands)) {
|
|
46
|
+
// eslint-disable-next-line no-await-in-loop
|
|
47
|
+
console.log(
|
|
48
|
+
` \x1b[36m${c.padEnd(maxLength)}\x1b[0m - ${commandsClasses[key].default.description}`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
32
53
|
async run(command, args) {
|
|
33
54
|
await this.loadCommands();
|
|
34
55
|
|
|
35
56
|
if (!command) {
|
|
36
57
|
console.log('Please provide command name');
|
|
37
|
-
|
|
38
|
-
'Availalble commands:',
|
|
39
|
-
Object.keys(this.commands).join(', '),
|
|
40
|
-
);
|
|
58
|
+
await this.printComandTable();
|
|
41
59
|
return false;
|
|
42
60
|
}
|
|
43
61
|
|
|
44
62
|
if (!this.commands[command]) {
|
|
45
63
|
console.log(`Command ${command} not found `);
|
|
46
|
-
|
|
47
|
-
'Availalble commands:',
|
|
48
|
-
Object.keys(this.commands).join(', '),
|
|
49
|
-
);
|
|
64
|
+
await this.printComandTable();
|
|
50
65
|
return false;
|
|
51
66
|
}
|
|
52
67
|
const { default: Command } = await import(this.commands[command]);
|
package/package.json
CHANGED
package/commands/Generate.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import AbstractCommand from '../modules/AbstractCommand.js';
|
|
2
|
-
|
|
3
|
-
class Generate extends AbstractCommand {
|
|
4
|
-
async run() {
|
|
5
|
-
if (!this.args.type) {
|
|
6
|
-
this.logger.error('Please provide type to generate "--type=model');
|
|
7
|
-
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default Generate;
|