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.
- package/bin/millas.js +12 -2
- package/package.json +2 -1
- package/src/cli.js +117 -20
- package/src/commands/call.js +1 -1
- package/src/commands/createsuperuser.js +137 -182
- package/src/commands/key.js +61 -83
- package/src/commands/lang.js +423 -515
- package/src/commands/make.js +88 -62
- package/src/commands/migrate.js +200 -279
- package/src/commands/new.js +55 -50
- package/src/commands/route.js +78 -80
- package/src/commands/schedule.js +52 -150
- package/src/commands/serve.js +158 -191
- package/src/console/AppCommand.js +106 -0
- package/src/console/BaseCommand.js +726 -0
- package/src/console/CommandContext.js +66 -0
- package/src/console/CommandRegistry.js +88 -0
- package/src/console/Style.js +123 -0
- package/src/console/index.js +12 -3
- package/src/container/AppInitializer.js +10 -0
- package/src/facades/DB.js +195 -0
- package/src/index.js +2 -1
- package/src/scaffold/maker.js +102 -42
- package/src/schematics/Collection.js +28 -0
- package/src/schematics/SchematicEngine.js +122 -0
- package/src/schematics/Template.js +99 -0
- package/src/schematics/index.js +7 -0
- package/src/templates/command/default.template.js +14 -0
- package/src/templates/command/schema.json +19 -0
- package/src/templates/controller/default.template.js +10 -0
- package/src/templates/controller/resource.template.js +59 -0
- package/src/templates/controller/schema.json +30 -0
- package/src/templates/job/default.template.js +11 -0
- package/src/templates/job/schema.json +19 -0
- package/src/templates/middleware/default.template.js +11 -0
- package/src/templates/middleware/schema.json +19 -0
- package/src/templates/migration/default.template.js +14 -0
- package/src/templates/migration/schema.json +19 -0
- package/src/templates/model/default.template.js +14 -0
- package/src/templates/model/migration.template.js +17 -0
- package/src/templates/model/schema.json +30 -0
- package/src/templates/service/default.template.js +12 -0
- package/src/templates/service/schema.json +19 -0
- package/src/templates/shape/default.template.js +11 -0
- package/src/templates/shape/schema.json +19 -0
- package/src/validation/BaseValidator.js +3 -0
- package/src/validation/types.js +3 -3
package/src/commands/key.js
CHANGED
|
@@ -1,97 +1,75 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const fs
|
|
5
|
-
const path
|
|
3
|
+
const BaseCommand = require('../console/BaseCommand');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
48
|
-
|
|
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
|
-
|
|
22
|
+
let key;
|
|
23
|
+
try {
|
|
24
|
+
key = Encrypter.generateKey(cipher);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
throw new Error(err.message);
|
|
27
|
+
}
|
|
54
28
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
29
|
+
if (show) {
|
|
30
|
+
this.logger.log('\n ' + this.style.info(key) + '\n');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
60
33
|
|
|
61
|
-
|
|
34
|
+
const envPath = path.resolve(this.cwd, '.env');
|
|
62
35
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
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
|
-
|
|
95
|
-
console.log(' ' + chalk.dim('APP_KEY=') + chalk.cyan(key) + '\n');
|
|
96
|
-
});
|
|
97
|
-
};
|
|
75
|
+
module.exports = KeyCommand;
|