millas 0.2.28 → 0.2.30

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 (47) 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/facades/DB.js +195 -0
  22. package/src/index.js +2 -1
  23. package/src/scaffold/maker.js +102 -42
  24. package/src/schematics/Collection.js +28 -0
  25. package/src/schematics/SchematicEngine.js +122 -0
  26. package/src/schematics/Template.js +99 -0
  27. package/src/schematics/index.js +7 -0
  28. package/src/templates/command/default.template.js +14 -0
  29. package/src/templates/command/schema.json +19 -0
  30. package/src/templates/controller/default.template.js +10 -0
  31. package/src/templates/controller/resource.template.js +59 -0
  32. package/src/templates/controller/schema.json +30 -0
  33. package/src/templates/job/default.template.js +11 -0
  34. package/src/templates/job/schema.json +19 -0
  35. package/src/templates/middleware/default.template.js +11 -0
  36. package/src/templates/middleware/schema.json +19 -0
  37. package/src/templates/migration/default.template.js +14 -0
  38. package/src/templates/migration/schema.json +19 -0
  39. package/src/templates/model/default.template.js +14 -0
  40. package/src/templates/model/migration.template.js +17 -0
  41. package/src/templates/model/schema.json +30 -0
  42. package/src/templates/service/default.template.js +12 -0
  43. package/src/templates/service/schema.json +19 -0
  44. package/src/templates/shape/default.template.js +11 -0
  45. package/src/templates/shape/schema.json +19 -0
  46. package/src/validation/BaseValidator.js +3 -0
  47. package/src/validation/types.js +3 -3
@@ -1,97 +1,75 @@
1
1
  'use strict';
2
2
 
3
- const chalk = require('chalk');
4
- const fs = require('fs');
5
- const path = require('path');
3
+ const BaseCommand = require('../console/BaseCommand');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
6
 
7
- /**
8
- * `millas key:generate`
9
- *
10
- * Generates a cryptographically random APP_KEY and writes it into the
11
- * project's .env file — exactly like Laravel's `php artisan key:generate`.
12
- *
13
- * ── Behaviour ────────────────────────────────────────────────────────────────
14
- *
15
- * - Reads the .env file in the current working directory
16
- * - Replaces (or appends) the APP_KEY= line with the new key
17
- * - Prints the key to stdout
18
- * - Use --show to print the key without writing to .env
19
- * - Use --force to overwrite an existing non-empty APP_KEY without prompting
20
- *
21
- * ── Examples ─────────────────────────────────────────────────────────────────
22
- *
23
- * millas key:generate — generate and write to .env
24
- * millas key:generate --show — print only, don't write
25
- * millas key:generate --force — overwrite existing key without prompt
26
- * millas key:generate --cipher AES-128-CBC
27
- */
28
- module.exports = function (program) {
29
- program
30
- .command('key:generate')
31
- .description('Generate a new application key and write it to .env')
32
- .option('--show', 'Print the key without writing to .env')
33
- .option('--force', 'Overwrite existing APP_KEY without confirmation')
34
- .option('--cipher <cipher>', 'Cipher to use (default: AES-256-CBC)', 'AES-256-CBC')
35
- .action(async (options) => {
36
- const { Encrypter } = require('../encryption/Encrypter');
7
+ class KeyCommand extends BaseCommand {
8
+ static description = 'Manage application encryption keys';
37
9
 
38
- // Generate the key
39
- let key;
40
- try {
41
- key = Encrypter.generateKey(options.cipher);
42
- } catch (err) {
43
- process.stderr.write(chalk.red(`\n ✖ ${err.message}\n\n`));
44
- process.exit(1);
45
- }
10
+ async onInit(register) {
11
+ register
12
+ .command(this.generate)
13
+ .arg('--show', 'Print the key without writing to .env')
14
+ .arg('--force', 'Overwrite existing APP_KEY without confirmation')
15
+ .arg('--cipher', v=>v.string(),'Cipher to use (default: AES-256-CBC)')
16
+ .description('Generate a new application key and write it to .env');
17
+ }
46
18
 
47
- // --show: just print, don't touch .env
48
- if (options.show) {
49
- console.log('\n ' + chalk.cyan(key) + '\n');
50
- return;
51
- }
19
+ async generate(show, force, cipher = 'AES-256-CBC') {
20
+ const { Encrypter } = require('../encryption/Encrypter');
52
21
 
53
- const envPath = path.resolve(process.cwd(), '.env');
22
+ let key;
23
+ try {
24
+ key = Encrypter.generateKey(cipher);
25
+ } catch (err) {
26
+ throw new Error(err.message);
27
+ }
54
28
 
55
- if (!fs.existsSync(envPath)) {
56
- process.stderr.write(chalk.red('\n .env file not found.\n'));
57
- process.stderr.write(chalk.dim(' Run: millas new <project> or create a .env file first.\n\n'));
58
- process.exit(1);
59
- }
29
+ if (show) {
30
+ this.logger.log('\n ' + this.style.info(key) + '\n');
31
+ return;
32
+ }
60
33
 
61
- let envContent = fs.readFileSync(envPath, 'utf8');
34
+ const envPath = path.resolve(this.cwd, '.env');
62
35
 
63
- // Check if APP_KEY already has a value
64
- const existing = envContent.match(/^APP_KEY=(.+)$/m);
65
- const hasValue = existing && existing[1] && existing[1].trim() !== '';
36
+ if (!fs.existsSync(envPath)) {
37
+ this.error('.env file not found.');
38
+ this.logger.error(this.style.muted(' Run: millas new <project> or create a .env file first.\n\n'));
39
+ throw new Error('.env file not found');
40
+ }
66
41
 
67
- if (hasValue && !options.force) {
68
- // Prompt for confirmation
69
- const readline = require('readline');
70
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
71
- const answer = await new Promise(resolve => {
72
- rl.question(
73
- chalk.yellow('\n ⚠ APP_KEY already set. Overwrite? (y/N) '),
74
- ans => { rl.close(); resolve(ans); }
75
- );
76
- });
77
- if ((answer || '').trim().toLowerCase() !== 'y') {
78
- console.log(chalk.dim('\n Key not changed.\n'));
79
- return;
80
- }
81
- }
42
+ let envContent = fs.readFileSync(envPath, 'utf8');
82
43
 
83
- // Write the key into .env
84
- if (/^APP_KEY=/m.test(envContent)) {
85
- // Replace existing line
86
- envContent = envContent.replace(/^APP_KEY=.*$/m, `APP_KEY=${key}`);
87
- } else {
88
- // Append if APP_KEY line is missing entirely
89
- envContent += `\nAPP_KEY=${key}\n`;
44
+ const existing = envContent.match(/^APP_KEY=(.+)$/m);
45
+ const hasValue = existing && existing[1] && existing[1].trim() !== '';
46
+
47
+ if (hasValue && !force) {
48
+ const readline = require('readline');
49
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
50
+ const answer = await new Promise(resolve => {
51
+ rl.question(
52
+ this.style.warning('\n ⚠ APP_KEY already set. Overwrite? (y/N) '),
53
+ ans => { rl.close(); resolve(ans); }
54
+ );
55
+ });
56
+ if ((answer || '').trim().toLowerCase() !== 'y') {
57
+ this.logger.log(this.style.muted('\n Key not changed.\n'));
58
+ return;
90
59
  }
60
+ }
61
+
62
+ if (/^APP_KEY=/m.test(envContent)) {
63
+ envContent = envContent.replace(/^APP_KEY=.*$/m, `APP_KEY=${key}`);
64
+ } else {
65
+ envContent += `\nAPP_KEY=${key}\n`;
66
+ }
67
+
68
+ fs.writeFileSync(envPath, envContent, 'utf8');
91
69
 
92
- fs.writeFileSync(envPath, envContent, 'utf8');
70
+ this.success('Application key set.');
71
+ this.logger.log(' ' + this.style.muted('APP_KEY=') + this.style.info(key) + '\n');
72
+ }
73
+ }
93
74
 
94
- console.log(chalk.green('\n ✔ Application key set.\n'));
95
- console.log(' ' + chalk.dim('APP_KEY=') + chalk.cyan(key) + '\n');
96
- });
97
- };
75
+ module.exports = KeyCommand;