@h3ravel/console 11.0.3 → 11.0.4
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/run.cjs +10 -866
- package/bin/run.js +10 -858
- package/package.json +3 -3
package/bin/run.cjs
CHANGED
|
@@ -1,280 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var nodepath = require('path');
|
|
9
|
-
var fs = require('fs');
|
|
10
|
-
var dayjs = require('dayjs');
|
|
11
|
-
var arquebus = require('@h3ravel/arquebus');
|
|
12
|
-
var child_process = require('child_process');
|
|
13
|
-
var commander = require('commander');
|
|
14
|
-
var config = require('@h3ravel/config');
|
|
15
|
-
var database = require('@h3ravel/database');
|
|
16
|
-
|
|
17
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
-
|
|
19
|
-
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
20
|
-
var nodepath__default = /*#__PURE__*/_interopDefault(nodepath);
|
|
21
|
-
var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
|
|
22
|
-
|
|
23
|
-
var __defProp = Object.defineProperty;
|
|
24
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
25
|
-
function sync_default(start, callback) {
|
|
26
|
-
let dir = nodepath.resolve(".", start);
|
|
27
|
-
let tmp, stats = fs.statSync(dir);
|
|
28
|
-
if (!stats.isDirectory()) {
|
|
29
|
-
dir = nodepath.dirname(dir);
|
|
30
|
-
}
|
|
31
|
-
while (true) {
|
|
32
|
-
tmp = callback(dir, fs.readdirSync(dir));
|
|
33
|
-
if (tmp) return nodepath.resolve(dir, tmp);
|
|
34
|
-
dir = nodepath.dirname(tmp = dir);
|
|
35
|
-
if (tmp === dir) break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
__name(sync_default, "default");
|
|
39
|
-
var join = nodepath__default.default.join;
|
|
40
|
-
var Utils = class {
|
|
41
|
-
static {
|
|
42
|
-
__name(this, "Utils");
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Wraps text with chalk
|
|
46
|
-
*
|
|
47
|
-
* @param txt
|
|
48
|
-
* @param color
|
|
49
|
-
* @returns
|
|
50
|
-
*/
|
|
51
|
-
static textFormat(txt, color) {
|
|
52
|
-
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Ouput formater object
|
|
56
|
-
*
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
static output() {
|
|
60
|
-
return {
|
|
61
|
-
success: /* @__PURE__ */ __name((msg, exit = false) => {
|
|
62
|
-
console.log(chalk__default.default.green("\u2713"), this.textFormat(msg, chalk__default.default.bgGreen), "\n");
|
|
63
|
-
if (exit) process.exit(0);
|
|
64
|
-
}, "success"),
|
|
65
|
-
info: /* @__PURE__ */ __name((msg, exit = false) => {
|
|
66
|
-
console.log(chalk__default.default.blue("\u2139"), this.textFormat(msg, chalk__default.default.bgBlue), "\n");
|
|
67
|
-
if (exit) process.exit(0);
|
|
68
|
-
}, "info"),
|
|
69
|
-
error: /* @__PURE__ */ __name((msg, exit = true) => {
|
|
70
|
-
if (msg instanceof Error) {
|
|
71
|
-
if (msg.message) {
|
|
72
|
-
console.error(chalk__default.default.red("\u2716"), this.textFormat("ERROR:" + msg.message, chalk__default.default.bgRed));
|
|
73
|
-
}
|
|
74
|
-
console.error(chalk__default.default.red(`${msg.detail ? `${msg.detail}
|
|
75
|
-
` : ""}${msg.stack}`), "\n");
|
|
76
|
-
} else {
|
|
77
|
-
console.error(chalk__default.default.red("\u2716"), this.textFormat(msg, chalk__default.default.bgRed), "\n");
|
|
78
|
-
}
|
|
79
|
-
if (exit) process.exit(1);
|
|
80
|
-
}, "error"),
|
|
81
|
-
split: /* @__PURE__ */ __name((name, value, status, exit = false) => {
|
|
82
|
-
status ??= "info";
|
|
83
|
-
const color = {
|
|
84
|
-
success: chalk__default.default.bgGreen,
|
|
85
|
-
info: chalk__default.default.bgBlue,
|
|
86
|
-
error: chalk__default.default.bgRed
|
|
87
|
-
};
|
|
88
|
-
const regex = /\x1b\[\d+m/g;
|
|
89
|
-
const width = Math.min(process.stdout.columns, 100);
|
|
90
|
-
const dots = Math.max(width - name.replace(regex, "").length - value.replace(regex, "").length - 10, 0);
|
|
91
|
-
console.log(this.textFormat(name, color[status]), chalk__default.default.gray(".".repeat(dots)), value);
|
|
92
|
-
if (exit) process.exit(0);
|
|
93
|
-
}, "split"),
|
|
94
|
-
quiet: /* @__PURE__ */ __name(() => {
|
|
95
|
-
process.exit(0);
|
|
96
|
-
}, "quiet")
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
static findModulePkg(moduleId, cwd) {
|
|
100
|
-
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
101
|
-
let packageName = "";
|
|
102
|
-
if (parts.length > 0 && parts[0][0] === "@") {
|
|
103
|
-
packageName += parts.shift() + "/";
|
|
104
|
-
}
|
|
105
|
-
packageName += parts.shift();
|
|
106
|
-
const packageJson = nodepath__default.default.join(cwd ?? process.cwd(), "node_modules", packageName);
|
|
107
|
-
const resolved = this.findUpConfig(packageJson, "package", [
|
|
108
|
-
"json"
|
|
109
|
-
]);
|
|
110
|
-
if (!resolved) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
return nodepath__default.default.join(nodepath__default.default.dirname(resolved), parts.join("/"));
|
|
114
|
-
}
|
|
115
|
-
static async getMigrationPaths(cwd, migrator, defaultPath, path3) {
|
|
116
|
-
if (path3) {
|
|
117
|
-
return [
|
|
118
|
-
join(cwd, path3)
|
|
119
|
-
];
|
|
120
|
-
}
|
|
121
|
-
return [
|
|
122
|
-
...migrator.getPaths(),
|
|
123
|
-
join(cwd, defaultPath)
|
|
124
|
-
];
|
|
125
|
-
}
|
|
126
|
-
static twoColumnDetail(name, value) {
|
|
127
|
-
const regex = /\x1b\[\d+m/g;
|
|
128
|
-
const width = Math.min(process.stdout.columns, 100);
|
|
129
|
-
const dots = Math.max(width - name.replace(regex, "").length - value.replace(regex, "").length - 10, 0);
|
|
130
|
-
return console.log(name, chalk__default.default.gray(".".repeat(dots)), value);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Check if file exists
|
|
134
|
-
*
|
|
135
|
-
* @param path
|
|
136
|
-
* @returns
|
|
137
|
-
*/
|
|
138
|
-
static async fileExists(path3) {
|
|
139
|
-
try {
|
|
140
|
-
await promises.access(path3);
|
|
141
|
-
return true;
|
|
142
|
-
} catch {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
static findUpConfig(cwd, name, extensions) {
|
|
147
|
-
return sync_default(cwd, (_dir, names) => {
|
|
148
|
-
for (const ext of extensions) {
|
|
149
|
-
const filename = `${name}.${ext}`;
|
|
150
|
-
if (names.includes(filename)) {
|
|
151
|
-
return filename;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return false;
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
var TableGuesser = class TableGuesser2 {
|
|
159
|
-
static {
|
|
160
|
-
__name(this, "TableGuesser");
|
|
161
|
-
}
|
|
162
|
-
static CREATE_PATTERNS = [
|
|
163
|
-
/^create_(\w+)_table$/,
|
|
164
|
-
/^create_(\w+)$/
|
|
165
|
-
];
|
|
166
|
-
static CHANGE_PATTERNS = [
|
|
167
|
-
/.+_(to|from|in)_(\w+)_table$/,
|
|
168
|
-
/.+_(to|from|in)_(\w+)$/
|
|
169
|
-
];
|
|
170
|
-
static guess(migration) {
|
|
171
|
-
for (const pattern of TableGuesser2.CREATE_PATTERNS) {
|
|
172
|
-
const matches = migration.match(pattern);
|
|
173
|
-
if (matches) {
|
|
174
|
-
return [
|
|
175
|
-
matches[1],
|
|
176
|
-
true
|
|
177
|
-
];
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
for (const pattern of TableGuesser2.CHANGE_PATTERNS) {
|
|
181
|
-
const matches = migration.match(pattern);
|
|
182
|
-
if (matches) {
|
|
183
|
-
return [
|
|
184
|
-
matches[2],
|
|
185
|
-
false
|
|
186
|
-
];
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return [];
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
// src/Commands/Command.ts
|
|
194
|
-
var Command = class {
|
|
195
|
-
static {
|
|
196
|
-
__name(this, "Command");
|
|
197
|
-
}
|
|
198
|
-
app;
|
|
199
|
-
kernel;
|
|
200
|
-
constructor(app, kernel) {
|
|
201
|
-
this.app = app;
|
|
202
|
-
this.kernel = kernel;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* The name and signature of the console command.
|
|
206
|
-
*
|
|
207
|
-
* @var string
|
|
208
|
-
*/
|
|
209
|
-
signature;
|
|
210
|
-
/**
|
|
211
|
-
* A dictionary of signatures or what not.
|
|
212
|
-
*
|
|
213
|
-
* @var object
|
|
214
|
-
*/
|
|
215
|
-
dictionary = {};
|
|
216
|
-
/**
|
|
217
|
-
* The console command description.
|
|
218
|
-
*
|
|
219
|
-
* @var string
|
|
220
|
-
*/
|
|
221
|
-
description;
|
|
222
|
-
/**
|
|
223
|
-
* The console command input.
|
|
224
|
-
*
|
|
225
|
-
* @var object
|
|
226
|
-
*/
|
|
227
|
-
input = {
|
|
228
|
-
options: {},
|
|
229
|
-
arguments: {}
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* Execute the console command.
|
|
233
|
-
*/
|
|
234
|
-
async handle(..._args) {
|
|
235
|
-
}
|
|
236
|
-
setApplication(app) {
|
|
237
|
-
this.app = app;
|
|
238
|
-
}
|
|
239
|
-
setInput(options, args, regArgs, dictionary) {
|
|
240
|
-
this.dictionary = dictionary;
|
|
241
|
-
this.input.options = options;
|
|
242
|
-
this.input.arguments = regArgs.map((e, i) => ({
|
|
243
|
-
[e.name()]: args[i]
|
|
244
|
-
})).reduce((e, x) => Object.assign(e, x), {});
|
|
245
|
-
}
|
|
246
|
-
getSignature() {
|
|
247
|
-
return this.signature;
|
|
248
|
-
}
|
|
249
|
-
getDescription() {
|
|
250
|
-
return this.description;
|
|
251
|
-
}
|
|
252
|
-
option(key, def) {
|
|
253
|
-
return this.input.options[key] ?? def;
|
|
254
|
-
}
|
|
255
|
-
options(key) {
|
|
256
|
-
if (key) {
|
|
257
|
-
return this.input.options[key];
|
|
258
|
-
}
|
|
259
|
-
return this.input.options;
|
|
260
|
-
}
|
|
261
|
-
argument(key, def) {
|
|
262
|
-
return this.input.arguments[key] ?? def;
|
|
263
|
-
}
|
|
264
|
-
arguments() {
|
|
265
|
-
return this.input.arguments;
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
var MakeCommand = class extends Command {
|
|
269
|
-
static {
|
|
270
|
-
__name(this, "MakeCommand");
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* The name and signature of the console command.
|
|
274
|
-
*
|
|
275
|
-
* @var string
|
|
276
|
-
*/
|
|
277
|
-
signature = `#make:
|
|
2
|
+
'use strict';var events=require('events'),core=require('@h3ravel/core'),promises=require('fs/promises'),d=require('chalk'),g=require('path'),fs=require('fs'),te=require('dayjs'),arquebus=require('@h3ravel/arquebus'),child_process=require('child_process'),commander=require('commander'),config=require('@h3ravel/config'),database=require('@h3ravel/database');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var d__default=/*#__PURE__*/_interopDefault(d);var g__default=/*#__PURE__*/_interopDefault(g);var te__default=/*#__PURE__*/_interopDefault(te);var Z=Object.defineProperty;var c=(m,e)=>Z(m,"name",{value:e,configurable:true});function F(m,e){let t=g.resolve(".",m),s;for(fs.statSync(t).isDirectory()||(t=g.dirname(t));;){if(s=e(t,fs.readdirSync(t)),s)return g.resolve(t,s);if(t=g.dirname(s=t),s===t)break}}c(F,"default");var Y=g__default.default.join,f=class{static{c(this,"Utils");}static textFormat(e,t){return String(e).split(":").map((s,i,r)=>i==0&&r.length>1?t(" "+s+": "):s).join("")}static output(){return {success:c((e,t=false)=>{console.log(d__default.default.green("\u2713"),this.textFormat(e,d__default.default.bgGreen),`
|
|
3
|
+
`),t&&process.exit(0);},"success"),info:c((e,t=false)=>{console.log(d__default.default.blue("\u2139"),this.textFormat(e,d__default.default.bgBlue),`
|
|
4
|
+
`),t&&process.exit(0);},"info"),error:c((e,t=true)=>{e instanceof Error?(e.message&&console.error(d__default.default.red("\u2716"),this.textFormat("ERROR:"+e.message,d__default.default.bgRed)),console.error(d__default.default.red(`${e.detail?`${e.detail}
|
|
5
|
+
`:""}${e.stack}`),`
|
|
6
|
+
`)):console.error(d__default.default.red("\u2716"),this.textFormat(e,d__default.default.bgRed),`
|
|
7
|
+
`),t&&process.exit(1);},"error"),split:c((e,t,s,i=false)=>{s??="info";let r={success:d__default.default.bgGreen,info:d__default.default.bgBlue,error:d__default.default.bgRed},a=/\x1b\[\d+m/g,n=Math.min(process.stdout.columns,100),o=Math.max(n-e.replace(a,"").length-t.replace(a,"").length-10,0);console.log(this.textFormat(e,r[s]),d__default.default.gray(".".repeat(o)),t),i&&process.exit(0);},"split"),quiet:c(()=>{process.exit(0);},"quiet")}}static findModulePkg(e,t){let s=e.replace(/\\/g,"/").split("/"),i="";s.length>0&&s[0][0]==="@"&&(i+=s.shift()+"/"),i+=s.shift();let r=g__default.default.join(t??process.cwd(),"node_modules",i),a=this.findUpConfig(r,"package",["json"]);if(a)return g__default.default.join(g__default.default.dirname(a),s.join("/"))}static async getMigrationPaths(e,t,s,i){return i?[Y(e,i)]:[...t.getPaths(),Y(e,s)]}static twoColumnDetail(e,t){let s=/\x1b\[\d+m/g,i=Math.min(process.stdout.columns,100),r=Math.max(i-e.replace(s,"").length-t.replace(s,"").length-10,0);return console.log(e,d__default.default.gray(".".repeat(r)),t)}static async fileExists(e){try{return await promises.access(e),!0}catch{return false}}static findUpConfig(e,t,s){return F(e,(i,r)=>{for(let a of s){let n=`${t}.${a}`;if(r.includes(n))return n}return false})}},J=class D{static{c(this,"TableGuesser");}static CREATE_PATTERNS=[/^create_(\w+)_table$/,/^create_(\w+)$/];static CHANGE_PATTERNS=[/.+_(to|from|in)_(\w+)_table$/,/.+_(to|from|in)_(\w+)$/];static guess(e){for(let t of D.CREATE_PATTERNS){let s=e.match(t);if(s)return [s[1],true]}for(let t of D.CHANGE_PATTERNS){let s=e.match(t);if(s)return [s[2],false]}return []}};var k=class{static{c(this,"Command");}app;kernel;constructor(e,t){this.app=e,this.kernel=t;}signature;dictionary={};description;input={options:{},arguments:{}};async handle(...e){}setApplication(e){this.app=e;}setInput(e,t,s,i){this.dictionary=i,this.input.options=e,this.input.arguments=s.map((r,a)=>({[r.name()]:t[a]})).reduce((r,a)=>Object.assign(r,a),{});}getSignature(){return this.signature}getDescription(){return this.description}option(e,t){return this.input.options[e]??t}options(e){return e?this.input.options[e]:this.input.options}argument(e,t){return this.input.arguments[e]??t}arguments(){return this.input.arguments}};var I=class extends k{static{c(this,"MakeCommand");}signature=`#make:
|
|
278
8
|
{controller : Generates a new controller class. | {--a|api : Generate an API resource controller} | {--force : Overide existing controller.} }
|
|
279
9
|
{resource : Generates a new API resource class.}
|
|
280
10
|
{migration : Generates a new database migration class. | {--l|type=ts : The file type to generate} | {--t|table : The table to migrate} | {--c|create : The table to be created} }
|
|
@@ -282,129 +12,7 @@ var MakeCommand = class extends Command {
|
|
|
282
12
|
{seeder : Generates a new database seeder class.}
|
|
283
13
|
{model : Generates a new Arquebus model class. | {--t|type=ts : The file type to generate}}
|
|
284
14
|
{^name : The name of the [name] to generate}
|
|
285
|
-
`;
|
|
286
|
-
/**
|
|
287
|
-
* The console command description.
|
|
288
|
-
*
|
|
289
|
-
* @var string
|
|
290
|
-
*/
|
|
291
|
-
description = "Generate component classes";
|
|
292
|
-
async handle() {
|
|
293
|
-
const command = this.dictionary.baseCommand;
|
|
294
|
-
const methods = {
|
|
295
|
-
controller: "makeController",
|
|
296
|
-
resource: "makeResource",
|
|
297
|
-
migration: "makeMigration",
|
|
298
|
-
factory: "makeFactory",
|
|
299
|
-
seeder: "makeSeeder",
|
|
300
|
-
model: "makeModel"
|
|
301
|
-
};
|
|
302
|
-
try {
|
|
303
|
-
await this?.[methods[command]]();
|
|
304
|
-
} catch (e) {
|
|
305
|
-
this.kernel.output.error(e);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Generate a new controller class.
|
|
310
|
-
*/
|
|
311
|
-
async makeController() {
|
|
312
|
-
const type = this.option("api") ? "-resource" : "";
|
|
313
|
-
const name = this.argument("name");
|
|
314
|
-
const force = this.option("force");
|
|
315
|
-
const path3 = nodepath__default.default.join(app_path("Http/Controllers"), name + ".ts");
|
|
316
|
-
const dbPath = Utils.findModulePkg("@h3ravel/http", this.kernel.cwd) ?? "";
|
|
317
|
-
const stubPath = nodepath__default.default.join(dbPath, `dist/stubs/controller${type}.stub`);
|
|
318
|
-
if (!force && fs.existsSync(path3)) {
|
|
319
|
-
this.kernel.output.error(`ERORR: ${name} controller already exists`);
|
|
320
|
-
}
|
|
321
|
-
let stub = await promises.readFile(stubPath, "utf-8");
|
|
322
|
-
stub = stub.replace(/{{ name }}/g, name);
|
|
323
|
-
await promises.writeFile(path3, stub);
|
|
324
|
-
this.kernel.output.split(`INFO: Controller Created`, chalk__default.default.gray(nodepath__default.default.basename(path3)));
|
|
325
|
-
}
|
|
326
|
-
makeResource() {
|
|
327
|
-
this.kernel.output.success(`Resource support is not yet available`);
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Generate a new database migration class
|
|
331
|
-
*/
|
|
332
|
-
async makeMigration() {
|
|
333
|
-
const name = this.argument("name");
|
|
334
|
-
const datePrefix = dayjs__default.default().format("YYYY_MM_DD_HHmmss");
|
|
335
|
-
const path3 = nodepath__default.default.join(database_path("migrations"), `${datePrefix}_${name}.ts`);
|
|
336
|
-
const dbPath = Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
|
|
337
|
-
let create = this.option("create", false);
|
|
338
|
-
let table = this.option("table");
|
|
339
|
-
if (!table && typeof create === "string") {
|
|
340
|
-
table = create;
|
|
341
|
-
create = true;
|
|
342
|
-
}
|
|
343
|
-
if (!table) {
|
|
344
|
-
const guessed = TableGuesser.guess(name);
|
|
345
|
-
table = guessed[0];
|
|
346
|
-
create = !!guessed[1];
|
|
347
|
-
}
|
|
348
|
-
const stubPath = nodepath__default.default.join(dbPath, this.getMigrationStubName(table, create));
|
|
349
|
-
let stub = await promises.readFile(stubPath, "utf-8");
|
|
350
|
-
if (table !== null) {
|
|
351
|
-
stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
|
|
352
|
-
}
|
|
353
|
-
this.kernel.output.info("INFO: Creating Migration");
|
|
354
|
-
await this.kernel.ensureDirectoryExists(nodepath__default.default.dirname(path3));
|
|
355
|
-
await promises.writeFile(path3, stub);
|
|
356
|
-
this.kernel.output.split(`INFO: Migration Created`, chalk__default.default.gray(nodepath__default.default.basename(path3)));
|
|
357
|
-
}
|
|
358
|
-
makeFactory() {
|
|
359
|
-
this.kernel.output.success(`Factory support is not yet available`);
|
|
360
|
-
}
|
|
361
|
-
makeSeeder() {
|
|
362
|
-
this.kernel.output.success(`Seeder support is not yet available`);
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Generate a new Arquebus model class
|
|
366
|
-
*/
|
|
367
|
-
async makeModel() {
|
|
368
|
-
const type = this.option("type", "ts");
|
|
369
|
-
const name = this.argument("name");
|
|
370
|
-
const path3 = nodepath__default.default.join(app_path("Models"), name.toLowerCase() + "." + type);
|
|
371
|
-
const dbPath = Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
|
|
372
|
-
const stubPath = nodepath__default.default.join(dbPath, `dist/stubs/model-${type}.stub`);
|
|
373
|
-
let stub = await promises.readFile(stubPath, "utf-8");
|
|
374
|
-
stub = stub.replace(/{{ name }}/g, name);
|
|
375
|
-
await promises.writeFile(path3, stub);
|
|
376
|
-
this.kernel.output.split(`INFO: Model Created`, chalk__default.default.gray(nodepath__default.default.basename(path3)));
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Ge the database migration file name
|
|
380
|
-
*
|
|
381
|
-
* @param table
|
|
382
|
-
* @param create
|
|
383
|
-
* @param type
|
|
384
|
-
* @returns
|
|
385
|
-
*/
|
|
386
|
-
getMigrationStubName(table, create = false, type = "ts") {
|
|
387
|
-
let stub;
|
|
388
|
-
if (!table) {
|
|
389
|
-
stub = `migration-${type}.stub`;
|
|
390
|
-
} else if (create) {
|
|
391
|
-
stub = `migration.create-${type}.stub`;
|
|
392
|
-
} else {
|
|
393
|
-
stub = `migration.update-${type}.stub`;
|
|
394
|
-
}
|
|
395
|
-
return "dist/stubs/" + stub;
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
var MigrateCommand = class extends Command {
|
|
399
|
-
static {
|
|
400
|
-
__name(this, "MigrateCommand");
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* The name and signature of the console command.
|
|
404
|
-
*
|
|
405
|
-
* @var string
|
|
406
|
-
*/
|
|
407
|
-
signature = `migrate:
|
|
15
|
+
`;description="Generate component classes";async handle(){let e=this.dictionary.baseCommand,t={controller:"makeController",resource:"makeResource",migration:"makeMigration",factory:"makeFactory",seeder:"makeSeeder",model:"makeModel"};try{await this?.[t[e]]();}catch(s){this.kernel.output.error(s);}}async makeController(){let e=this.option("api")?"-resource":"",t=this.argument("name"),s=this.option("force"),i=g__default.default.join(app_path("Http/Controllers"),t+".ts"),r=f.findModulePkg("@h3ravel/http",this.kernel.cwd)??"",a=g__default.default.join(r,`dist/stubs/controller${e}.stub`);!s&&fs.existsSync(i)&&this.kernel.output.error(`ERORR: ${t} controller already exists`);let n=await promises.readFile(a,"utf-8");n=n.replace(/{{ name }}/g,t),await promises.writeFile(i,n),this.kernel.output.split("INFO: Controller Created",d__default.default.gray(g__default.default.basename(i)));}makeResource(){this.kernel.output.success("Resource support is not yet available");}async makeMigration(){let e=this.argument("name"),t=te__default.default().format("YYYY_MM_DD_HHmmss"),s=g__default.default.join(database_path("migrations"),`${t}_${e}.ts`),i=f.findModulePkg("@h3ravel/database",this.kernel.cwd)??"",r=this.option("create",false),a=this.option("table");if(!a&&typeof r=="string"&&(a=r,r=true),!a){let l=J.guess(e);a=l[0],r=!!l[1];}let n=g__default.default.join(i,this.getMigrationStubName(a,r)),o=await promises.readFile(n,"utf-8");a!==null&&(o=o.replace(/DummyTable|{{\s*table\s*}}/g,a)),this.kernel.output.info("INFO: Creating Migration"),await this.kernel.ensureDirectoryExists(g__default.default.dirname(s)),await promises.writeFile(s,o),this.kernel.output.split("INFO: Migration Created",d__default.default.gray(g__default.default.basename(s)));}makeFactory(){this.kernel.output.success("Factory support is not yet available");}makeSeeder(){this.kernel.output.success("Seeder support is not yet available");}async makeModel(){let e=this.option("type","ts"),t=this.argument("name"),s=g__default.default.join(app_path("Models"),t.toLowerCase()+"."+e),i=f.findModulePkg("@h3ravel/database",this.kernel.cwd)??"",r=g__default.default.join(i,`dist/stubs/model-${e}.stub`),a=await promises.readFile(r,"utf-8");a=a.replace(/{{ name }}/g,t),await promises.writeFile(s,a),this.kernel.output.split("INFO: Model Created",d__default.default.gray(g__default.default.basename(s)));}getMigrationStubName(e,t=false,s="ts"){let i;return e?t?i=`migration.create-${s}.stub`:i=`migration.update-${s}.stub`:i=`migration-${s}.stub`,"dist/stubs/"+i}};var E=class extends k{static{c(this,"MigrateCommand");}signature=`migrate:
|
|
408
16
|
{fresh : Drop all tables and re-run all migrations.}
|
|
409
17
|
{install : Create the migration repository.}
|
|
410
18
|
{refresh : Reset and re-run all migrations.}
|
|
@@ -413,470 +21,6 @@ var MigrateCommand = class extends Command {
|
|
|
413
21
|
{status : Show the status of each migration.}
|
|
414
22
|
{publish : Publish any migration files from installed packages.}
|
|
415
23
|
{^--s|seed : Seed the database}
|
|
416
|
-
`;
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
*
|
|
420
|
-
* @var string
|
|
421
|
-
*/
|
|
422
|
-
description = "Run all pending migrations.";
|
|
423
|
-
/**
|
|
424
|
-
* Execute the console command.
|
|
425
|
-
*/
|
|
426
|
-
async handle() {
|
|
427
|
-
const command = this.dictionary.name ?? this.dictionary.baseCommand;
|
|
428
|
-
const methods = {
|
|
429
|
-
migrate: "migrateRun",
|
|
430
|
-
fresh: "migrateFresh",
|
|
431
|
-
install: "migrateInstall",
|
|
432
|
-
refresh: "migrateRefresh",
|
|
433
|
-
reset: "migrateReset",
|
|
434
|
-
rollback: "migrateRollback",
|
|
435
|
-
status: "migrateStatus",
|
|
436
|
-
publish: "migratePublish"
|
|
437
|
-
};
|
|
438
|
-
await this?.[methods[command]]();
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Run all pending migrations.
|
|
442
|
-
*/
|
|
443
|
-
async migrateRun() {
|
|
444
|
-
this.kernel.output.success(`Running migrations are not yet supported.`);
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Drop all tables and re-run all migrations.
|
|
448
|
-
*/
|
|
449
|
-
async migrateFresh() {
|
|
450
|
-
this.kernel.output.success(`Drop all tables and re-run all migrations.`);
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* Create the migration repository.
|
|
454
|
-
*/
|
|
455
|
-
async migrateInstall() {
|
|
456
|
-
this.kernel.output.success(`Create the migration repository.`);
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Reset and re-run all migrations.
|
|
460
|
-
*/
|
|
461
|
-
async migrateRefresh() {
|
|
462
|
-
this.kernel.output.success(`Resetting and re-running migrations is not yet supported.`);
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* Rollback all database migrations.
|
|
466
|
-
*/
|
|
467
|
-
async migrateReset() {
|
|
468
|
-
this.kernel.output.success(`Rolling back all migration is not yet supported.`);
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Rollback the last database migration.
|
|
472
|
-
*/
|
|
473
|
-
async migrateRollback() {
|
|
474
|
-
this.kernel.output.success(`Rolling back the last migration is not yet supported.`);
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Show the status of each migration.
|
|
478
|
-
*/
|
|
479
|
-
async migrateStatus() {
|
|
480
|
-
app_path();
|
|
481
|
-
console.log(arquebus.arquebus.connection());
|
|
482
|
-
this.kernel.output.success(`Show the status of each migration.`);
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Publish any migration files from installed packages.
|
|
486
|
-
*/
|
|
487
|
-
async migratePublish() {
|
|
488
|
-
this.kernel.output.success(`Publish any migration files from installed packages.`);
|
|
489
|
-
}
|
|
490
|
-
};
|
|
491
|
-
var ServeCommand = class extends Command {
|
|
492
|
-
static {
|
|
493
|
-
__name(this, "ServeCommand");
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* The name and signature of the console command.
|
|
497
|
-
*
|
|
498
|
-
* @var string
|
|
499
|
-
*/
|
|
500
|
-
signature = "serve";
|
|
501
|
-
/**
|
|
502
|
-
* The console command description.
|
|
503
|
-
*
|
|
504
|
-
* @var string
|
|
505
|
-
*/
|
|
506
|
-
description = "Start the Developement Server";
|
|
507
|
-
async handle() {
|
|
508
|
-
try {
|
|
509
|
-
await this.serve();
|
|
510
|
-
} catch (e) {
|
|
511
|
-
this.kernel.output.error(e);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
async serve() {
|
|
515
|
-
const child = child_process.spawn("tsup-node", {
|
|
516
|
-
stdio: "inherit",
|
|
517
|
-
shell: true,
|
|
518
|
-
env: Object.assign({}, process.env, {
|
|
519
|
-
NODE_ENV: "development"
|
|
520
|
-
}),
|
|
521
|
-
detached: true
|
|
522
|
-
});
|
|
523
|
-
const cleanup = /* @__PURE__ */ __name(() => {
|
|
524
|
-
console.log(111);
|
|
525
|
-
if (child.pid) {
|
|
526
|
-
process.kill(child.pid, "SIGTERM");
|
|
527
|
-
}
|
|
528
|
-
}, "cleanup");
|
|
529
|
-
process.on("SIGINT", () => child.kill("SIGINT"));
|
|
530
|
-
process.on("SIGTERM", () => child.kill("SIGTERM"));
|
|
531
|
-
process.on("SIGINT", () => {
|
|
532
|
-
cleanup();
|
|
533
|
-
process.exit(0);
|
|
534
|
-
});
|
|
535
|
-
process.on("SIGTERM", () => {
|
|
536
|
-
cleanup();
|
|
537
|
-
process.exit(0);
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
};
|
|
541
|
-
|
|
542
|
-
// src/Signature.ts
|
|
543
|
-
var Signature = class _Signature {
|
|
544
|
-
static {
|
|
545
|
-
__name(this, "Signature");
|
|
546
|
-
}
|
|
547
|
-
/**
|
|
548
|
-
* Helper to parse options inside a block of text
|
|
549
|
-
*
|
|
550
|
-
* @param block
|
|
551
|
-
* @returns
|
|
552
|
-
*/
|
|
553
|
-
static parseOptions(block) {
|
|
554
|
-
const options = [];
|
|
555
|
-
const regex = /\{([^{}]+(?:\{[^{}]*\}[^{}]*)*)\}/g;
|
|
556
|
-
let match;
|
|
557
|
-
while ((match = regex.exec(block)) !== null) {
|
|
558
|
-
const shared = "^" === match[1][0] || /:[#^]/.test(match[1]);
|
|
559
|
-
const isHidden = ([
|
|
560
|
-
"#",
|
|
561
|
-
"^"
|
|
562
|
-
].includes(match[1][0]) || /:[#^]/.test(match[1])) && !shared;
|
|
563
|
-
const content = match[1].trim().replace(/[#^]/, "");
|
|
564
|
-
const colonIndex = content.indexOf(":");
|
|
565
|
-
if (colonIndex === -1) {
|
|
566
|
-
options.push({
|
|
567
|
-
name: content
|
|
568
|
-
});
|
|
569
|
-
continue;
|
|
570
|
-
}
|
|
571
|
-
const namePart = content.substring(0, colonIndex).trim();
|
|
572
|
-
let rest = content.substring(colonIndex + 1).trim();
|
|
573
|
-
let description = rest;
|
|
574
|
-
let nestedOptions;
|
|
575
|
-
const pipeIndex = rest.indexOf("|");
|
|
576
|
-
if (pipeIndex !== -1) {
|
|
577
|
-
description = rest.substring(0, pipeIndex).trim();
|
|
578
|
-
const nestedText = rest.substring(pipeIndex + 1).trim();
|
|
579
|
-
const cleanedNestedText = nestedText.replace(/^\{/, "").trim();
|
|
580
|
-
nestedOptions = _Signature.parseOptions("{" + cleanedNestedText + "}");
|
|
581
|
-
} else {
|
|
582
|
-
description = description.trim();
|
|
583
|
-
}
|
|
584
|
-
let name = namePart;
|
|
585
|
-
let required = /[^a-zA-Z0-9_|-]/.test(name);
|
|
586
|
-
let multiple = false;
|
|
587
|
-
if (name.endsWith("?*")) {
|
|
588
|
-
required = false;
|
|
589
|
-
multiple = true;
|
|
590
|
-
name = name.slice(0, -2);
|
|
591
|
-
} else if (name.endsWith("*")) {
|
|
592
|
-
multiple = true;
|
|
593
|
-
name = name.slice(0, -1);
|
|
594
|
-
} else if (name.endsWith("?")) {
|
|
595
|
-
required = false;
|
|
596
|
-
name = name.slice(0, -1);
|
|
597
|
-
}
|
|
598
|
-
const isFlag = name.startsWith("--");
|
|
599
|
-
let flags;
|
|
600
|
-
let defaultValue;
|
|
601
|
-
if (isFlag) {
|
|
602
|
-
const flagParts = name.split("|").map((s) => s.trim());
|
|
603
|
-
flags = [];
|
|
604
|
-
for (let part of flagParts) {
|
|
605
|
-
if (part.startsWith("--") && part.slice(2).length === 1) {
|
|
606
|
-
part = "-" + part.slice(2);
|
|
607
|
-
} else if (part.startsWith("-") && !part.startsWith("--") && part.slice(1).length > 1) {
|
|
608
|
-
part = "--" + part.slice(1);
|
|
609
|
-
} else if (!part.startsWith("-") && part.slice(1).length > 1) {
|
|
610
|
-
part = "--" + part;
|
|
611
|
-
}
|
|
612
|
-
const eqIndex = part.indexOf("=");
|
|
613
|
-
if (eqIndex !== -1) {
|
|
614
|
-
flags.push(part.substring(0, eqIndex));
|
|
615
|
-
const val = part.substring(eqIndex + 1);
|
|
616
|
-
if (val === "*") {
|
|
617
|
-
defaultValue = [];
|
|
618
|
-
} else if (val === "true" || val === "false" || !val && !required) {
|
|
619
|
-
defaultValue = val === "true";
|
|
620
|
-
} else if (!isNaN(Number(val))) {
|
|
621
|
-
defaultValue = Number(val);
|
|
622
|
-
} else {
|
|
623
|
-
defaultValue = val;
|
|
624
|
-
}
|
|
625
|
-
} else {
|
|
626
|
-
flags.push(part);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
options.push({
|
|
631
|
-
name: isFlag ? flags[flags.length - 1] : name,
|
|
632
|
-
required,
|
|
633
|
-
multiple,
|
|
634
|
-
description,
|
|
635
|
-
flags,
|
|
636
|
-
shared,
|
|
637
|
-
isFlag,
|
|
638
|
-
isHidden,
|
|
639
|
-
defaultValue,
|
|
640
|
-
nestedOptions
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
return options;
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Helper to parse a command's signature
|
|
647
|
-
*
|
|
648
|
-
* @param signature
|
|
649
|
-
* @param commandClass
|
|
650
|
-
* @returns
|
|
651
|
-
*/
|
|
652
|
-
static parseSignature(signature, commandClass) {
|
|
653
|
-
const lines = signature.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
|
|
654
|
-
const isHidden = [
|
|
655
|
-
"#",
|
|
656
|
-
"^"
|
|
657
|
-
].includes(lines[0][0]) || /:[#^]/.test(lines[0]);
|
|
658
|
-
const baseCommand = lines[0].replace(/[^\w=:-]/g, "");
|
|
659
|
-
const description = commandClass.getDescription();
|
|
660
|
-
const isNamespaceCommand = baseCommand.endsWith(":");
|
|
661
|
-
const rest = lines.slice(1).join(" ");
|
|
662
|
-
const allOptions = _Signature.parseOptions(rest);
|
|
663
|
-
if (isNamespaceCommand) {
|
|
664
|
-
return {
|
|
665
|
-
baseCommand: baseCommand.slice(0, -1),
|
|
666
|
-
isNamespaceCommand,
|
|
667
|
-
subCommands: allOptions.filter((e) => !e.flags && !e.isHidden),
|
|
668
|
-
description,
|
|
669
|
-
commandClass,
|
|
670
|
-
options: allOptions.filter((e) => !!e.flags),
|
|
671
|
-
isHidden
|
|
672
|
-
};
|
|
673
|
-
} else {
|
|
674
|
-
return {
|
|
675
|
-
baseCommand,
|
|
676
|
-
isNamespaceCommand,
|
|
677
|
-
options: allOptions,
|
|
678
|
-
description,
|
|
679
|
-
commandClass,
|
|
680
|
-
isHidden
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
};
|
|
685
|
-
var Musket = class _Musket {
|
|
686
|
-
static {
|
|
687
|
-
__name(this, "Musket");
|
|
688
|
-
}
|
|
689
|
-
app;
|
|
690
|
-
kernel;
|
|
691
|
-
output = Utils.output();
|
|
692
|
-
commands = [];
|
|
693
|
-
constructor(app, kernel) {
|
|
694
|
-
this.app = app;
|
|
695
|
-
this.kernel = kernel;
|
|
696
|
-
}
|
|
697
|
-
async build() {
|
|
698
|
-
this.loadBaseCommands();
|
|
699
|
-
await this.loadDiscoveredCommands();
|
|
700
|
-
return this.initialize();
|
|
701
|
-
}
|
|
702
|
-
loadBaseCommands() {
|
|
703
|
-
const commands = [
|
|
704
|
-
new ServeCommand(this.app, this.kernel),
|
|
705
|
-
new MakeCommand(this.app, this.kernel),
|
|
706
|
-
new MigrateCommand(this.app, this.kernel)
|
|
707
|
-
];
|
|
708
|
-
commands.forEach((e) => this.addCommand(e));
|
|
709
|
-
}
|
|
710
|
-
async loadDiscoveredCommands() {
|
|
711
|
-
const commands = [];
|
|
712
|
-
commands.forEach((e) => this.addCommand(e));
|
|
713
|
-
}
|
|
714
|
-
addCommand(command) {
|
|
715
|
-
this.commands.push(Signature.parseSignature(command.getSignature(), command));
|
|
716
|
-
}
|
|
717
|
-
initialize() {
|
|
718
|
-
const cliVersion = [
|
|
719
|
-
"H3ravel Version:",
|
|
720
|
-
chalk__default.default.green(this.kernel.consolePackage.version)
|
|
721
|
-
].join(" ");
|
|
722
|
-
const localVersion = [
|
|
723
|
-
"Musket Version:",
|
|
724
|
-
chalk__default.default.green(this.kernel.modulePackage.version || "None")
|
|
725
|
-
].join(" ");
|
|
726
|
-
commander.program.name("musket").version(`${cliVersion}
|
|
727
|
-
${localVersion}`);
|
|
728
|
-
commander.program.command("init").description("Initialize H3ravel.").action(async () => {
|
|
729
|
-
this.output.success(`Initialized: H3ravel has been initialized!`);
|
|
730
|
-
});
|
|
731
|
-
for (let i = 0; i < this.commands.length; i++) {
|
|
732
|
-
const command = this.commands[i];
|
|
733
|
-
const instance = command.commandClass;
|
|
734
|
-
if (command.isNamespaceCommand && command.subCommands) {
|
|
735
|
-
const cmd = command.isHidden ? commander.program : commander.program.command(command.baseCommand).description(command.description ?? "").action(async () => {
|
|
736
|
-
instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command);
|
|
737
|
-
await instance.handle();
|
|
738
|
-
});
|
|
739
|
-
if ((command.options?.length ?? 0) > 0) {
|
|
740
|
-
command.options?.filter((v, i2, a) => a.findIndex((t) => t.name === v.name) === i2).forEach((opt) => {
|
|
741
|
-
this.makeOption(opt, cmd);
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
command.subCommands.filter((v, i2, a) => !v.shared && a.findIndex((t) => t.name === v.name) === i2).forEach((sub) => {
|
|
745
|
-
const cmd2 = commander.program.command(`${command.baseCommand}:${sub.name}`).description(sub.description || "").action(async () => {
|
|
746
|
-
instance.setInput(cmd2.opts(), cmd2.args, cmd2.registeredArguments, sub);
|
|
747
|
-
await instance.handle();
|
|
748
|
-
});
|
|
749
|
-
command.subCommands?.filter((e) => e.shared).forEach((opt) => {
|
|
750
|
-
this.makeOption(opt, cmd2, false, sub);
|
|
751
|
-
});
|
|
752
|
-
command.options?.filter((e) => e.shared).forEach((opt) => {
|
|
753
|
-
this.makeOption(opt, cmd2, false, sub);
|
|
754
|
-
});
|
|
755
|
-
if (sub.nestedOptions) {
|
|
756
|
-
sub.nestedOptions.filter((v, i2, a) => a.findIndex((t) => t.name === v.name) === i2).forEach((opt) => {
|
|
757
|
-
this.makeOption(opt, cmd2);
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
});
|
|
761
|
-
} else {
|
|
762
|
-
const cmd = commander.program.command(command.baseCommand).description(command.description ?? "");
|
|
763
|
-
command?.options?.filter((v, i2, a) => a.findIndex((t) => t.name === v.name) === i2).forEach((opt) => {
|
|
764
|
-
this.makeOption(opt, cmd, true);
|
|
765
|
-
});
|
|
766
|
-
cmd.action(async () => {
|
|
767
|
-
instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command);
|
|
768
|
-
await instance.handle();
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
return commander.program;
|
|
773
|
-
}
|
|
774
|
-
makeOption(opt, cmd, parse, parent) {
|
|
775
|
-
const description = opt.description?.replace(/\[(\w+)\]/g, (_, k) => parent?.[k] ?? `[${k}]`) ?? "";
|
|
776
|
-
const type = opt.name.replaceAll("-", "");
|
|
777
|
-
if (opt.isFlag) {
|
|
778
|
-
if (parse) {
|
|
779
|
-
const flags = opt.flags?.map((f) => f.length === 1 ? `-${f}` : `--${f}`).join(", ");
|
|
780
|
-
cmd.option(flags || "", description, String(opt.defaultValue) || void 0);
|
|
781
|
-
} else {
|
|
782
|
-
cmd.option(opt.flags?.join(", ") + (opt.required ? ` <${type}>` : ""), description, opt.defaultValue);
|
|
783
|
-
}
|
|
784
|
-
} else {
|
|
785
|
-
cmd.argument(opt.required ? `<${opt.name}>` : `[${opt.name}]`, description, opt.defaultValue);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
static async parse(kernel) {
|
|
789
|
-
return (await new _Musket(kernel.app, kernel).build()).parseAsync();
|
|
790
|
-
}
|
|
791
|
-
};
|
|
792
|
-
var Kernel = class _Kernel {
|
|
793
|
-
static {
|
|
794
|
-
__name(this, "Kernel");
|
|
795
|
-
}
|
|
796
|
-
app;
|
|
797
|
-
cwd;
|
|
798
|
-
output = Utils.output();
|
|
799
|
-
basePath = "";
|
|
800
|
-
modulePath;
|
|
801
|
-
consolePath;
|
|
802
|
-
modulePackage;
|
|
803
|
-
consolePackage;
|
|
804
|
-
constructor(app, basePath) {
|
|
805
|
-
this.app = app;
|
|
806
|
-
}
|
|
807
|
-
static init(app) {
|
|
808
|
-
const instance = new _Kernel(app);
|
|
809
|
-
Promise.all([
|
|
810
|
-
instance.loadRequirements()
|
|
811
|
-
]).then(([e]) => e.run());
|
|
812
|
-
}
|
|
813
|
-
async run() {
|
|
814
|
-
await Musket.parse(this);
|
|
815
|
-
process.exit(0);
|
|
816
|
-
}
|
|
817
|
-
async ensureDirectoryExists(dir) {
|
|
818
|
-
await promises.mkdir(dir, {
|
|
819
|
-
recursive: true
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
async loadRequirements() {
|
|
823
|
-
this.cwd = nodepath__default.default.join(process.cwd(), this.basePath);
|
|
824
|
-
this.modulePath = Utils.findModulePkg("@h3ravel/core", this.cwd) ?? "";
|
|
825
|
-
this.consolePath = Utils.findModulePkg("@h3ravel/console", this.cwd) ?? "";
|
|
826
|
-
try {
|
|
827
|
-
this.modulePackage = await import(nodepath__default.default.join(this.modulePath, "package.json"));
|
|
828
|
-
} catch {
|
|
829
|
-
this.modulePackage = {
|
|
830
|
-
version: "N/A"
|
|
831
|
-
};
|
|
832
|
-
}
|
|
833
|
-
try {
|
|
834
|
-
this.consolePackage = await import(nodepath__default.default.join(this.consolePath, "package.json"));
|
|
835
|
-
} catch {
|
|
836
|
-
this.consolePackage = {
|
|
837
|
-
version: "N/A"
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
return this;
|
|
841
|
-
}
|
|
842
|
-
};
|
|
843
|
-
var ConsoleServiceProvider = class extends core.ServiceProvider {
|
|
844
|
-
static {
|
|
845
|
-
__name(this, "ConsoleServiceProvider");
|
|
846
|
-
}
|
|
847
|
-
static priority = 992;
|
|
848
|
-
register() {
|
|
849
|
-
Kernel.init(this.app);
|
|
850
|
-
}
|
|
851
|
-
};
|
|
852
|
-
|
|
853
|
-
// src/IO/providers.ts
|
|
854
|
-
var providers_default = [
|
|
855
|
-
config.ConfigServiceProvider,
|
|
856
|
-
database.DatabaseServiceProvider,
|
|
857
|
-
ConsoleServiceProvider
|
|
858
|
-
];
|
|
859
|
-
|
|
860
|
-
// src/IO/app.ts
|
|
861
|
-
var app_default = class {
|
|
862
|
-
static {
|
|
863
|
-
__name(this, "default");
|
|
864
|
-
}
|
|
865
|
-
async bootstrap() {
|
|
866
|
-
const app = new core.Application(process.cwd());
|
|
867
|
-
app.registerProviders(providers_default);
|
|
868
|
-
await app.registerConfiguredProviders();
|
|
869
|
-
await app.boot();
|
|
870
|
-
new events.EventEmitter().once("SIGINT", () => process.exit(0));
|
|
871
|
-
process.on("SIGINT", () => {
|
|
872
|
-
process.exit(0);
|
|
873
|
-
});
|
|
874
|
-
process.on("SIGTERM", () => {
|
|
875
|
-
process.exit(0);
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
|
-
};
|
|
879
|
-
|
|
880
|
-
// src/run.ts
|
|
881
|
-
new app_default().bootstrap();
|
|
882
|
-
new events.EventEmitter().once("SIGINT", () => process.exit(0));
|
|
24
|
+
`;description="Run all pending migrations.";async handle(){let e=this.dictionary.name??this.dictionary.baseCommand;await this?.[{migrate:"migrateRun",fresh:"migrateFresh",install:"migrateInstall",refresh:"migrateRefresh",reset:"migrateReset",rollback:"migrateRollback",status:"migrateStatus",publish:"migratePublish"}[e]]();}async migrateRun(){this.kernel.output.success("Running migrations are not yet supported.");}async migrateFresh(){this.kernel.output.success("Drop all tables and re-run all migrations.");}async migrateInstall(){this.kernel.output.success("Create the migration repository.");}async migrateRefresh(){this.kernel.output.success("Resetting and re-running migrations is not yet supported.");}async migrateReset(){this.kernel.output.success("Rolling back all migration is not yet supported.");}async migrateRollback(){this.kernel.output.success("Rolling back the last migration is not yet supported.");}async migrateStatus(){app_path();console.log(arquebus.arquebus.connection()),this.kernel.output.success("Show the status of each migration.");}async migratePublish(){this.kernel.output.success("Publish any migration files from installed packages.");}};var T=class extends k{static{c(this,"ServeCommand");}signature="serve";description="Start the Developement Server";async handle(){try{await this.serve();}catch(e){this.kernel.output.error(e);}}async serve(){let e=child_process.spawn("tsup-node",{stdio:"inherit",shell:true,env:Object.assign({},process.env,{NODE_ENV:"development"}),detached:true}),t=c(()=>{console.log(111),e.pid&&process.kill(e.pid,"SIGTERM");},"cleanup");process.on("SIGINT",()=>e.kill("SIGINT")),process.on("SIGTERM",()=>e.kill("SIGTERM")),process.on("SIGINT",()=>{t(),process.exit(0);}),process.on("SIGTERM",()=>{t(),process.exit(0);});}};var N=class m{static{c(this,"Signature");}static parseOptions(e){let t=[],s=/\{([^{}]+(?:\{[^{}]*\}[^{}]*)*)\}/g,i;for(;(i=s.exec(e))!==null;){let r=i[1][0]==="^"||/:[#^]/.test(i[1]),a=(["#","^"].includes(i[1][0])||/:[#^]/.test(i[1]))&&!r,n=i[1].trim().replace(/[#^]/,""),o=n.indexOf(":");if(o===-1){t.push({name:n});continue}let l=n.substring(0,o).trim(),p=n.substring(o+1).trim(),x=p,R,G=p.indexOf("|");if(G!==-1){x=p.substring(0,G).trim();let u=p.substring(G+1).trim().replace(/^\{/,"").trim();R=m.parseOptions("{"+u+"}");}else x=x.trim();let h=l,v=/[^a-zA-Z0-9_|-]/.test(h),O=false;h.endsWith("?*")?(v=false,O=true,h=h.slice(0,-2)):h.endsWith("*")?(O=true,h=h.slice(0,-1)):h.endsWith("?")&&(v=false,h=h.slice(0,-1));let A=h.startsWith("--"),w,C;if(A){let z=h.split("|").map(u=>u.trim());w=[];for(let u of z){u.startsWith("--")&&u.slice(2).length===1?u="-"+u.slice(2):u.startsWith("-")&&!u.startsWith("--")&&u.slice(1).length>1?u="--"+u.slice(1):!u.startsWith("-")&&u.slice(1).length>1&&(u="--"+u);let _=u.indexOf("=");if(_!==-1){w.push(u.substring(0,_));let b=u.substring(_+1);b==="*"?C=[]:b==="true"||b==="false"||!b&&!v?C=b==="true":isNaN(Number(b))?C=b:C=Number(b);}else w.push(u);}}t.push({name:A?w[w.length-1]:h,required:v,multiple:O,description:x,flags:w,shared:r,isFlag:A,isHidden:a,defaultValue:C,nestedOptions:R});}return t}static parseSignature(e,t){let s=e.split(`
|
|
25
|
+
`).map(p=>p.trim()).filter(p=>p.length>0),i=["#","^"].includes(s[0][0])||/:[#^]/.test(s[0]),r=s[0].replace(/[^\w=:-]/g,""),a=t.getDescription(),n=r.endsWith(":"),o=s.slice(1).join(" "),l=m.parseOptions(o);return n?{baseCommand:r.slice(0,-1),isNamespaceCommand:n,subCommands:l.filter(p=>!p.flags&&!p.isHidden),description:a,commandClass:t,options:l.filter(p=>!!p.flags),isHidden:i}:{baseCommand:r,isNamespaceCommand:n,options:l,description:a,commandClass:t,isHidden:i}}};var M=class m{static{c(this,"Musket");}app;kernel;output=f.output();commands=[];constructor(e,t){this.app=e,this.kernel=t;}async build(){return this.loadBaseCommands(),await this.loadDiscoveredCommands(),this.initialize()}loadBaseCommands(){[new T(this.app,this.kernel),new I(this.app,this.kernel),new E(this.app,this.kernel)].forEach(t=>this.addCommand(t));}async loadDiscoveredCommands(){[].forEach(t=>this.addCommand(t));}addCommand(e){this.commands.push(N.parseSignature(e.getSignature(),e));}initialize(){let e=["H3ravel Version:",d__default.default.green(this.kernel.consolePackage.version)].join(" "),t=["Musket Version:",d__default.default.green(this.kernel.modulePackage.version||"None")].join(" ");commander.program.name("musket").version(`${e}
|
|
26
|
+
${t}`),commander.program.command("init").description("Initialize H3ravel.").action(async()=>{this.output.success("Initialized: H3ravel has been initialized!");});for(let s=0;s<this.commands.length;s++){let i=this.commands[s],r=i.commandClass;if(i.isNamespaceCommand&&i.subCommands){let a=i.isHidden?commander.program:commander.program.command(i.baseCommand).description(i.description??"").action(async()=>{r.setInput(a.opts(),a.args,a.registeredArguments,i),await r.handle();});(i.options?.length??0)>0&&i.options?.filter((n,o,l)=>l.findIndex(p=>p.name===n.name)===o).forEach(n=>{this.makeOption(n,a);}),i.subCommands.filter((n,o,l)=>!n.shared&&l.findIndex(p=>p.name===n.name)===o).forEach(n=>{let o=commander.program.command(`${i.baseCommand}:${n.name}`).description(n.description||"").action(async()=>{r.setInput(o.opts(),o.args,o.registeredArguments,n),await r.handle();});i.subCommands?.filter(l=>l.shared).forEach(l=>{this.makeOption(l,o,false,n);}),i.options?.filter(l=>l.shared).forEach(l=>{this.makeOption(l,o,false,n);}),n.nestedOptions&&n.nestedOptions.filter((l,p,x)=>x.findIndex(R=>R.name===l.name)===p).forEach(l=>{this.makeOption(l,o);});});}else {let a=commander.program.command(i.baseCommand).description(i.description??"");i?.options?.filter((n,o,l)=>l.findIndex(p=>p.name===n.name)===o).forEach(n=>{this.makeOption(n,a,true);}),a.action(async()=>{r.setInput(a.opts(),a.args,a.registeredArguments,i),await r.handle();});}}return commander.program}makeOption(e,t,s,i){let r=e.description?.replace(/\[(\w+)\]/g,(n,o)=>i?.[o]??`[${o}]`)??"",a=e.name.replaceAll("-","");if(e.isFlag)if(s){let n=e.flags?.map(o=>o.length===1?`-${o}`:`--${o}`).join(", ");t.option(n||"",r,String(e.defaultValue)||void 0);}else t.option(e.flags?.join(", ")+(e.required?` <${a}>`:""),r,e.defaultValue);else t.argument(e.required?`<${e.name}>`:`[${e.name}]`,r,e.defaultValue);}static async parse(e){return (await new m(e.app,e).build()).parseAsync()}};var P=class m{static{c(this,"Kernel");}app;cwd;output=f.output();basePath="";modulePath;consolePath;modulePackage;consolePackage;constructor(e,t){this.app=e;}static init(e){let t=new m(e);Promise.all([t.loadRequirements()]).then(([s])=>s.run());}async run(){await M.parse(this),process.exit(0);}async ensureDirectoryExists(e){await promises.mkdir(e,{recursive:true});}async loadRequirements(){this.cwd=g__default.default.join(process.cwd(),this.basePath),this.modulePath=f.findModulePkg("@h3ravel/core",this.cwd)??"",this.consolePath=f.findModulePkg("@h3ravel/console",this.cwd)??"";try{this.modulePackage=await import(g__default.default.join(this.modulePath,"package.json"));}catch{this.modulePackage={version:"N/A"};}try{this.consolePackage=await import(g__default.default.join(this.consolePath,"package.json"));}catch{this.consolePackage={version:"N/A"};}return this}};var $=class extends core.ServiceProvider{static{c(this,"ConsoleServiceProvider");}static priority=992;register(){P.init(this.app);}};var L=[config.ConfigServiceProvider,database.DatabaseServiceProvider,$];var j=class{static{c(this,"default");}async bootstrap(){let m=new core.Application(process.cwd());m.registerProviders(L),await m.registerConfiguredProviders(),await m.boot(),new events.EventEmitter().once("SIGINT",()=>process.exit(0)),process.on("SIGINT",()=>{process.exit(0);}),process.on("SIGTERM",()=>{process.exit(0);});}};new j().bootstrap();new events.EventEmitter().once("SIGINT",()=>process.exit(0));
|