millas 0.2.27 → 0.2.29

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.
Files changed (48) hide show
  1. package/bin/millas.js +12 -2
  2. package/package.json +2 -1
  3. package/src/cli.js +117 -20
  4. package/src/commands/call.js +1 -1
  5. package/src/commands/createsuperuser.js +137 -182
  6. package/src/commands/key.js +61 -83
  7. package/src/commands/lang.js +423 -515
  8. package/src/commands/make.js +88 -62
  9. package/src/commands/migrate.js +200 -279
  10. package/src/commands/new.js +55 -50
  11. package/src/commands/route.js +78 -80
  12. package/src/commands/schedule.js +52 -150
  13. package/src/commands/serve.js +158 -191
  14. package/src/console/AppCommand.js +106 -0
  15. package/src/console/BaseCommand.js +726 -0
  16. package/src/console/CommandContext.js +66 -0
  17. package/src/console/CommandRegistry.js +88 -0
  18. package/src/console/Style.js +123 -0
  19. package/src/console/index.js +12 -3
  20. package/src/container/AppInitializer.js +10 -0
  21. package/src/container/Application.js +2 -0
  22. package/src/facades/DB.js +195 -0
  23. package/src/index.js +2 -1
  24. package/src/scaffold/maker.js +102 -42
  25. package/src/schematics/Collection.js +28 -0
  26. package/src/schematics/SchematicEngine.js +122 -0
  27. package/src/schematics/Template.js +99 -0
  28. package/src/schematics/index.js +7 -0
  29. package/src/templates/command/default.template.js +14 -0
  30. package/src/templates/command/schema.json +19 -0
  31. package/src/templates/controller/default.template.js +10 -0
  32. package/src/templates/controller/resource.template.js +59 -0
  33. package/src/templates/controller/schema.json +30 -0
  34. package/src/templates/job/default.template.js +11 -0
  35. package/src/templates/job/schema.json +19 -0
  36. package/src/templates/middleware/default.template.js +11 -0
  37. package/src/templates/middleware/schema.json +19 -0
  38. package/src/templates/migration/default.template.js +14 -0
  39. package/src/templates/migration/schema.json +19 -0
  40. package/src/templates/model/default.template.js +14 -0
  41. package/src/templates/model/migration.template.js +17 -0
  42. package/src/templates/model/schema.json +30 -0
  43. package/src/templates/service/default.template.js +12 -0
  44. package/src/templates/service/schema.json +19 -0
  45. package/src/templates/shape/default.template.js +11 -0
  46. package/src/templates/shape/schema.json +19 -0
  47. package/src/validation/BaseValidator.js +3 -0
  48. package/src/validation/types.js +3 -3
@@ -1,75 +1,101 @@
1
1
  'use strict';
2
2
 
3
- const chalk = require('chalk');
4
- const { makeController, makeModel, makeMiddleware, makeService, makeJob, makeMigration, makeShape, makeCommand } = require('../scaffold/maker');
3
+ const path = require('path');
4
+ const BaseCommand = require('../console/BaseCommand');
5
+ const SchematicEngine = require('../schematics/SchematicEngine');
5
6
 
6
- module.exports = function (program) {
7
+ class MakeCommand extends BaseCommand {
8
+ static description = 'Generate application scaffolding';
7
9
 
8
- program
9
- .command('make:controller <name>')
10
- .description('Generate a new controller')
11
- .option('--resource', 'Generate a resource controller with CRUD methods')
12
- .action(async (name, options) => {
13
- await run('Controller', () => makeController(name, options));
14
- });
10
+ #engine = new SchematicEngine(path.join(__dirname, '../templates'));
15
11
 
16
- program
17
- .command('make:model <name>')
18
- .description('Generate a new model')
19
- .option('-m, --migration', 'Also create a migration file')
20
- .action(async (name, options) => {
21
- await run('Model', () => makeModel(name, options));
22
- });
12
+ async onInit(register) {
13
+ register
14
+ .command(async (name, resource,model) => {
15
+ const result = await this.#generate('controller', name, {resource,model});
16
+ this.success(`Created: ${result.path}`);
17
+ })
18
+ .name('controller')
19
+ .arg('name')
20
+ .arg('--resource')
21
+ .arg('--model', v => v.string())
22
+ .description('Generate a new controller');
23
23
 
24
- program
25
- .command('make:middleware <name>')
26
- .description('Generate a new middleware')
27
- .action(async (name) => {
28
- await run('Middleware', () => makeMiddleware(name));
29
- });
24
+ register
25
+ .command(async (name, migration) => {
26
+ console.log(name,migration)
27
+ const timestamp = Date.now();
28
+ const results = await this.#generate('model', name, { migration, timestamp });
29
+ if (Array.isArray(results)) {
30
+ results.forEach(r => this.success(`Created: ${r.path}`));
31
+ } else {
32
+ this.success(`Created: ${results.path}`);
33
+ }
34
+ })
35
+ .name('model')
36
+ .arg('name')
37
+ .arg('--migration')
38
+ .description('Generate a new model');
30
39
 
31
- program
32
- .command('make:service <name>')
33
- .description('Generate a new service class')
34
- .action(async (name) => {
35
- await run('Service', () => makeService(name));
36
- });
40
+ register
41
+ .command(async (name) => {
42
+ const result = await this.#generate('middleware', name);
43
+ this.success(`Created: ${result.path}`);
44
+ })
45
+ .name('middleware')
46
+ .arg('name')
47
+ .description('Generate a new middleware');
37
48
 
38
- program
39
- .command('make:job <name>')
40
- .description('Generate a new background job')
41
- .action(async (name) => {
42
- await run('Job', () => makeJob(name));
43
- });
49
+ register
50
+ .command(async (name) => {
51
+ const result = await this.#generate('service', name);
52
+ this.success(`Created: ${result.path}`);
53
+ })
54
+ .name('service')
55
+ .arg('name')
56
+ .description('Generate a new service class');
44
57
 
45
- program
46
- .command('make:migration <name>')
47
- .description('Generate a blank migration file')
48
- .action(async (name) => {
49
- await run('Migration', () => makeMigration(name));
50
- });
58
+ register
59
+ .command(async (name) => {
60
+ const result = await this.#generate('job', name);
61
+ this.success(`Created: ${result.path}`);
62
+ })
63
+ .name('job')
64
+ .arg('name')
65
+ .description('Generate a new background job');
51
66
 
52
- program
53
- .command('make:shape <n>')
54
- .description('Generate a shape file with Create/Update contracts (app/shapes/)')
55
- .action(async (name) => {
56
- await run('Shape', () => makeShape(name));
57
- });
58
- program
59
- .command('make:command <n>')
60
- .description('Generate a new custom console command in app/commands/')
61
- .action(async (name) => {
62
- await run('Command', () => makeCommand(name));
63
- });
67
+ register
68
+ .command(async (name) => {
69
+ const timestamp = Date.now();
70
+ const result = await this.#generate('migration', name, {timestamp });
71
+ this.success(`Created: ${result.path}`);
72
+ })
73
+ .name('migration')
74
+ .arg('name')
75
+ .description('Generate a blank migration file');
64
76
 
65
- };
77
+ register
78
+ .command(async (name) => {
79
+ const result = await this.#generate('shape', name);
80
+ this.success(`Created: ${result.path}`);
81
+ })
82
+ .name('shape')
83
+ .arg('name')
84
+ .description('Generate a shape file with Create/Update contracts (app/shapes/)');
66
85
 
67
- async function run(type, fn) {
68
- try {
69
- const filePath = await fn();
70
- console.log(chalk.green(`\n ✔ ${type} created: `) + chalk.cyan(filePath) + '\n');
71
- } catch (err) {
72
- console.error(chalk.red(`\n ✖ Failed to create ${type}: ${err.message}\n`));
73
- process.exit(1);
86
+ register
87
+ .command(async (name) => {
88
+ const result = await this.#generate('command', name);
89
+ this.success(`Created: ${result.path}`);
90
+ })
91
+ .name('command')
92
+ .arg('name')
93
+ .description('Generate a new custom console command in app/commands/');
74
94
  }
75
- }
95
+
96
+ async #generate(type, name, options) {
97
+ return await this.#engine.generate(type, {name}, options);
98
+ }
99
+ }
100
+
101
+ module.exports = MakeCommand;