@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 CHANGED
@@ -1,3 +1,8 @@
1
+ ### 5.0.0-alpha.26
2
+
3
+ [UPDATE] update deps
4
+ [UPDATE] new commands view in CLI
5
+
1
6
  ### 5.0.0-alpha.24
2
7
 
3
8
  [UPDATE] update deps
@@ -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;
@@ -8,7 +8,7 @@ class AbstractCommand extends Base {
8
8
  }
9
9
 
10
10
  static get description() {
11
- return 'Command description';
11
+ return 'Command description. PLEASE PROVIDE IT';
12
12
  }
13
13
 
14
14
  /**
@@ -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
- console.log(
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
- console.log(
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "5.0.0-alpha.24",
3
+ "version": "5.0.0-alpha.26",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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;