@aerogel/cli 0.0.0-next.7e89f52eb37d9154f4879a5ccd058d27d476dada → 0.0.0-next.7f369b50c025aaa1a8024b6e53c659a6d7d617b5

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 (76) hide show
  1. package/bin/gel +4 -0
  2. package/dist/aerogel-cli.d.ts +2 -2
  3. package/dist/aerogel-cli.js +754 -0
  4. package/dist/aerogel-cli.js.map +1 -0
  5. package/package.json +26 -32
  6. package/src/cli.ts +26 -8
  7. package/src/commands/Command.ts +14 -9
  8. package/src/commands/create.test.ts +3 -17
  9. package/src/commands/create.ts +19 -20
  10. package/src/commands/generate-component.test.ts +1 -14
  11. package/src/commands/generate-component.ts +20 -50
  12. package/src/commands/generate-model.test.ts +2 -2
  13. package/src/commands/generate-model.ts +13 -14
  14. package/src/commands/generate-service.test.ts +2 -2
  15. package/src/commands/generate-service.ts +16 -17
  16. package/src/commands/info.ts +15 -0
  17. package/src/commands/install.test.ts +21 -4
  18. package/src/commands/install.ts +12 -11
  19. package/src/lib/App.ts +45 -49
  20. package/src/lib/Editor.ts +19 -13
  21. package/src/lib/File.mock.ts +7 -11
  22. package/src/lib/File.ts +14 -3
  23. package/src/lib/Log.mock.ts +4 -8
  24. package/src/lib/Log.test.ts +4 -4
  25. package/src/lib/Log.ts +7 -7
  26. package/src/lib/Shell.mock.ts +3 -3
  27. package/src/lib/Shell.ts +2 -2
  28. package/src/lib/Template.ts +24 -17
  29. package/src/lib/utils/app.ts +3 -3
  30. package/src/lib/utils/edit.ts +2 -2
  31. package/src/lib/utils/paths.ts +16 -8
  32. package/src/plugins/LocalFirst.ts +9 -0
  33. package/src/plugins/Plugin.ts +49 -14
  34. package/src/plugins/Solid.ts +48 -42
  35. package/src/plugins/Soukai.ts +6 -6
  36. package/src/testing/setup.ts +36 -31
  37. package/templates/app/README.md +3 -0
  38. package/templates/service/[service.name].ts +1 -1
  39. package/.eslintrc.js +0 -7
  40. package/bin/ag +0 -4
  41. package/dist/aerogel-cli.cjs.js +0 -2
  42. package/dist/aerogel-cli.cjs.js.map +0 -1
  43. package/dist/aerogel-cli.esm.js +0 -2
  44. package/dist/aerogel-cli.esm.js.map +0 -1
  45. package/noeldemartin.config.js +0 -14
  46. package/src/lib/utils/format.test.ts +0 -33
  47. package/src/lib/utils/format.ts +0 -38
  48. package/templates/app/.eslintrc.js +0 -3
  49. package/templates/app/.github/workflows/ci.yml +0 -17
  50. package/templates/app/.gitignore.template +0 -2
  51. package/templates/app/.nvmrc +0 -1
  52. package/templates/app/.vscode/launch.json +0 -16
  53. package/templates/app/.vscode/settings.json +0 -10
  54. package/templates/app/cypress/e2e/app.cy.ts +0 -9
  55. package/templates/app/cypress/support/e2e.ts +0 -3
  56. package/templates/app/cypress/tsconfig.json +0 -12
  57. package/templates/app/cypress.config.ts +0 -12
  58. package/templates/app/index.html +0 -12
  59. package/templates/app/package.json +0 -54
  60. package/templates/app/postcss.config.js +0 -6
  61. package/templates/app/prettier.config.js +0 -5
  62. package/templates/app/src/App.vue +0 -12
  63. package/templates/app/src/assets/styles.css +0 -3
  64. package/templates/app/src/lang/en.yaml +0 -3
  65. package/templates/app/src/main.test.ts +0 -9
  66. package/templates/app/src/main.ts +0 -13
  67. package/templates/app/src/types/globals.d.ts +0 -2
  68. package/templates/app/src/types/shims.d.ts +0 -7
  69. package/templates/app/src/types/ts-reset.d.ts +0 -1
  70. package/templates/app/tailwind.config.js +0 -5
  71. package/templates/app/tsconfig.json +0 -18
  72. package/templates/app/vite.config.ts +0 -23
  73. package/templates/component-story/[component.name].story.vue +0 -7
  74. package/tsconfig.json +0 -11
  75. package/vite.config.ts +0 -14
  76. /package/src/{main.ts → index.ts} +0 -0
@@ -0,0 +1,754 @@
1
+ var H = Object.defineProperty;
2
+ var Q = (r, e, t) => e in r ? H(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var a = (r, e, t) => Q(r, typeof e != "symbol" ? e + "" : e, t);
4
+ import { Command as X } from "commander";
5
+ import { existsSync as N, lstatSync as E, readFileSync as J, readdirSync as Z, mkdirSync as W, writeFileSync as _ } from "node:fs";
6
+ import { facade as P, stringMatchAll as ee, toString as te, stringMatch as ie, arrayFrom as L, stringToTitleCase as se, stringToSlug as ne, stringToStudlyCase as re, formatCodeBlock as T, stringToCamelCase as M, fail as ae } from "@noeldemartin/utils";
7
+ import { fileURLToPath as w, URL as k } from "node:url";
8
+ import { resolve as F, dirname as R, basename as oe } from "node:path";
9
+ import A from "chalk";
10
+ import { cursorTo as ce, clearLine as le } from "node:readline";
11
+ import pe from "mustache";
12
+ import { Project as de, SyntaxKind as j, Node as p } from "ts-morph";
13
+ import { exec as ue } from "node:child_process";
14
+ import { simpleGit as ge } from "simple-git";
15
+ class me {
16
+ contains(e, t) {
17
+ var i;
18
+ return !!((i = this.read(e)) != null && i.includes(t));
19
+ }
20
+ exists(e) {
21
+ return N(e);
22
+ }
23
+ isSymlink(e) {
24
+ return E(e).isSymbolicLink();
25
+ }
26
+ read(e) {
27
+ return this.isFile(e) ? J(e).toString() : null;
28
+ }
29
+ replace(e, t, i) {
30
+ const s = this.read(e);
31
+ s && this.write(e, s.replaceAll(t, i));
32
+ }
33
+ getFiles(e) {
34
+ const t = Z(e, { withFileTypes: !0 }), i = [];
35
+ for (const s of t) {
36
+ const n = F(e, s.name);
37
+ s.isDirectory() ? i.push(...this.getFiles(n)) : i.push(n);
38
+ }
39
+ return i;
40
+ }
41
+ isDirectory(e) {
42
+ return this.exists(e) && E(e).isDirectory();
43
+ }
44
+ isFile(e) {
45
+ return this.exists(e) && E(e).isFile();
46
+ }
47
+ isEmptyDirectory(e) {
48
+ return this.isDirectory(e) ? this.getFiles(e).length === 0 : !1;
49
+ }
50
+ makeDirectory(e) {
51
+ W(e, { recursive: !0 });
52
+ }
53
+ write(e, t) {
54
+ N(R(e)) || W(R(e), { recursive: !0 }), _(e, t);
55
+ }
56
+ }
57
+ const c = P(me);
58
+ class fe {
59
+ constructor() {
60
+ a(this, "renderInfo", A.hex("#00ffff"));
61
+ a(this, "renderSuccess", A.hex("#00ff00"));
62
+ a(this, "renderError", A.hex("#ff0000"));
63
+ }
64
+ async animate(e, t) {
65
+ const i = (g = "", v = !1) => {
66
+ const O = this.renderInfo(this.renderMarkdown(e) + (v ? "..." : ".".repeat(s % 4))) + g;
67
+ this.stdout(O);
68
+ };
69
+ let s = 0;
70
+ i();
71
+ const n = setInterval(() => (s++, i()), 1e3), l = await t();
72
+ return clearInterval(n), i(`
73
+ `, !0), l;
74
+ }
75
+ info(e) {
76
+ this.log(this.renderMarkdown(e), this.renderInfo);
77
+ }
78
+ error(e) {
79
+ this.log(this.renderMarkdown(e), this.renderError);
80
+ }
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ fail(e) {
83
+ this.error(e), process.exit(1);
84
+ }
85
+ success(e) {
86
+ this.log(this.renderMarkdown(e), this.renderSuccess);
87
+ }
88
+ renderMarkdown(e) {
89
+ const t = ee(e, /\*\*(.*)\*\*/g);
90
+ for (const i of t)
91
+ e = e.replace(i[0], A.bold(i[1]));
92
+ return e;
93
+ }
94
+ log(e, t) {
95
+ this.formatMessage(e).forEach((i) => {
96
+ this.logLine(t ? t(i) : i);
97
+ });
98
+ }
99
+ formatMessage(e) {
100
+ var t;
101
+ if (e[0] === `
102
+ `) {
103
+ e = e.slice(1).trimEnd();
104
+ const i = e.split(`
105
+ `), s = e.trim()[0] ?? "", n = ((t = i.find((l) => l.trim().length > 0)) == null ? void 0 : t.indexOf(s)) ?? 0;
106
+ return i.map((l) => l.slice(n));
107
+ }
108
+ return [e];
109
+ }
110
+ logLine(e) {
111
+ console.log(e);
112
+ }
113
+ stdout(e) {
114
+ ce(process.stdout, 0), le(process.stdout, 0), process.stdout.write(e);
115
+ }
116
+ }
117
+ const o = P(fe);
118
+ class S {
119
+ constructor(e) {
120
+ this.path = e;
121
+ }
122
+ static instantiate(e, t = "./", i = {}) {
123
+ return new S(e).instantiate(t, i);
124
+ }
125
+ instantiate(e, t = {}) {
126
+ const i = this.getFilenameReplacements(t), s = [];
127
+ e = `${e}/`.replace(/\/\//, "/");
128
+ for (const n of c.getFiles(this.path)) {
129
+ const l = Object.entries(i).reduce(
130
+ (O, [Y, G]) => O.replaceAll(Y, G),
131
+ n.substring(this.path.length + 1)
132
+ ), g = J(n).toString(), v = e + (l.endsWith(".template") ? l.slice(0, -9) : l);
133
+ c.write(v, pe.render(g, t, void 0, ["<%", "%>"])), s.push(v);
134
+ }
135
+ return s;
136
+ }
137
+ getFilenameReplacements(e, t = "") {
138
+ return Object.entries(e).reduce(
139
+ (i, [s, n]) => (typeof n == "object" ? Object.assign(
140
+ i,
141
+ this.getFilenameReplacements(n, `${s}.`)
142
+ ) : i[`[${t}${s}]`] = te(n), i),
143
+ {}
144
+ );
145
+ }
146
+ }
147
+ function he(r = "") {
148
+ if (c.contains(
149
+ w(new k(
150
+ /* @vite-ignore */
151
+ "../../../package.json",
152
+ import.meta.url
153
+ )),
154
+ '"packages/create-aerogel"'
155
+ ))
156
+ return F(w(new k(
157
+ /* @vite-ignore */
158
+ "../",
159
+ import.meta.url
160
+ )), r);
161
+ const e = c.read(
162
+ w(new k(
163
+ /* @vite-ignore */
164
+ "../../../../package.json",
165
+ import.meta.url
166
+ ))
167
+ ), t = ie(e ?? "", /"@aerogel\/core": "file:(.*)\/aerogel-core-[\d.]*\.tgz"/), i = (t == null ? void 0 : t[1]) ?? o.fail("Could not determine base path");
168
+ return F(i, r);
169
+ }
170
+ function f(r) {
171
+ return o.fail(`Could not find ${r} pack file, did you run 'npm pack'?`);
172
+ }
173
+ function h(r) {
174
+ return c.getFiles(m(r)).find((e) => e.endsWith(".tgz")) ?? null;
175
+ }
176
+ function m(r) {
177
+ return he(`../${r}`);
178
+ }
179
+ function C(r) {
180
+ return w(new k(
181
+ /* @vite-ignore */
182
+ `../templates/${r}`,
183
+ import.meta.url
184
+ ));
185
+ }
186
+ class ye {
187
+ constructor() {
188
+ a(this, "cwd", null);
189
+ }
190
+ setWorkingDirectory(e) {
191
+ this.cwd = e;
192
+ }
193
+ async run(e) {
194
+ await new Promise((t, i) => {
195
+ ue(e, { cwd: this.cwd ?? void 0 }, (s) => {
196
+ if (s) {
197
+ i(s);
198
+ return;
199
+ }
200
+ t();
201
+ });
202
+ });
203
+ }
204
+ }
205
+ const d = P(ye);
206
+ class ve {
207
+ constructor() {
208
+ a(this, "project");
209
+ a(this, "modifiedFiles");
210
+ this.project = new de({ tsConfigFilePath: "tsconfig.json" }), this.modifiedFiles = /* @__PURE__ */ new Set(), this.project.addSourceFilesAtPaths("src/**/*.ts"), this.project.addSourceFilesAtPaths("vite.config.ts"), this.project.addSourceFilesAtPaths("package.json");
211
+ }
212
+ addSourceFile(e) {
213
+ this.project.addSourceFilesAtPaths(e);
214
+ }
215
+ requireSourceFile(e) {
216
+ return this.project.getSourceFileOrThrow(e);
217
+ }
218
+ async format() {
219
+ await o.animate("Formatting modified files", async () => {
220
+ const e = c.exists("prettier.config.js") || c.contains("package.json", '"prettier": {'), t = c.exists(".eslintrc.js") || c.contains("package.json", '"eslintConfig"'), s = c.contains("package.json", '"prettier-eslint-cli"') ? (n) => d.run(`npx prettier-eslint ${n} --write`) : async (n) => {
221
+ e && await d.run(`npx prettier ${n} --write`), n.match(/\.(ts|js|vue)$/) && t && await d.run(`npx eslint ${n} --fix`);
222
+ };
223
+ await Promise.all(L(this.modifiedFiles).map(async (n) => s(n)));
224
+ });
225
+ }
226
+ async save(e) {
227
+ await e.save(), this.addModifiedFile(e.getFilePath());
228
+ }
229
+ addModifiedFile(e) {
230
+ this.modifiedFiles.add(e);
231
+ }
232
+ }
233
+ class V {
234
+ constructor(e, t = {}) {
235
+ this.name = e, this.options = t;
236
+ }
237
+ async create(e) {
238
+ c.exists(e) && (!c.isDirectory(e) || !c.isEmptyDirectory(e)) && o.fail(`Folder at '${e}' already exists!`), await ge().clone("https://github.com/NoelDeMartin/aerogel-template.git", e);
239
+ const t = this.getDependencies();
240
+ c.replace(
241
+ F(e, "vite.config.ts"),
242
+ "Aerogel({ name: 'Aerogel' })",
243
+ `Aerogel({ name: '${this.name}' })`
244
+ );
245
+ for (const [i, s] of Object.entries(t))
246
+ c.replace(F(e, "package.json"), new RegExp(`"${i}": ".*?"`, "g"), `"${i}": "${s}"`);
247
+ S.instantiate(C("app"), e, { app: { name: this.name } });
248
+ }
249
+ edit() {
250
+ return new ve();
251
+ }
252
+ getDependencies() {
253
+ const e = (t) => Object.entries(t).reduce(
254
+ (i, [s, n]) => Object.assign(i, { [s]: `file:${n}` }),
255
+ {}
256
+ );
257
+ return this.options.linkedLocal ? e({
258
+ "@aerogel/cli": m("cli"),
259
+ "@aerogel/core": m("core"),
260
+ "@aerogel/cypress": m("cypress"),
261
+ "@aerogel/plugin-i18n": m("plugin-i18n"),
262
+ "@aerogel/plugin-soukai": m("plugin-soukai"),
263
+ "@aerogel/vite": m("vite")
264
+ }) : this.options.local ? e({
265
+ "@aerogel/cli": h("cli") ?? f("cli"),
266
+ "@aerogel/core": h("core") ?? f("core"),
267
+ "@aerogel/cypress": h("cypress") ?? f("cypress"),
268
+ "@aerogel/plugin-i18n": h("plugin-i18n") ?? f("plugin-i18n"),
269
+ "@aerogel/plugin-soukai": h("plugin-soukai") ?? f("plugin-soukai"),
270
+ "@aerogel/vite": h("vite") ?? f("vite")
271
+ }) : {};
272
+ }
273
+ }
274
+ class u {
275
+ static define(e) {
276
+ e = e.command(this.command).description(this.description);
277
+ for (const [t, i] of this.parameters)
278
+ e = e.argument(`<${t}>`, i);
279
+ for (const [t, i] of Object.entries(this.options)) {
280
+ const s = typeof i == "string" ? i : i.description, n = typeof i == "string" ? "string" : i.type ?? "string";
281
+ e = e.option(n === "boolean" ? `--${t}` : `--${t} <${n}>`, s);
282
+ }
283
+ e = e.action((...t) => this.run.call(this, ...t));
284
+ }
285
+ static async run(...e) {
286
+ const t = new this(...e);
287
+ await t.validate(), await t.run();
288
+ }
289
+ async validate() {
290
+ }
291
+ async run() {
292
+ }
293
+ assertAerogelOrDirectory(e) {
294
+ const t = c.read("package.json");
295
+ if (t != null && t.includes("@aerogel/core") || e && c.isDirectory(e))
296
+ return;
297
+ const i = e ? `${e} folder does not exist.` : "package.json does not contain @aerogel/core.";
298
+ o.fail(`${i} Are you sure this is an Aerogel app?`);
299
+ }
300
+ }
301
+ a(u, "command", ""), a(u, "description", ""), a(u, "parameters", []), a(u, "options", {});
302
+ class x extends u {
303
+ constructor(t, i = {}) {
304
+ super();
305
+ a(this, "path");
306
+ a(this, "options");
307
+ this.path = t, this.options = i;
308
+ }
309
+ async run() {
310
+ const t = this.path, i = this.options.name ?? se(oe(t));
311
+ d.setWorkingDirectory(t), await this.createApp(i, t), await this.initializeGit(), o.success(`
312
+
313
+ That's it! You can start working on **${i}** doing the following:
314
+
315
+ cd ${t}
316
+ npm install
317
+ npm run dev
318
+
319
+ Have fun!
320
+ `);
321
+ }
322
+ async createApp(t, i) {
323
+ o.info(`Creating **${t}**...`), await new V(t, {
324
+ local: this.options.local,
325
+ linkedLocal: this.options.local && !this.options.copy
326
+ }).create(i);
327
+ }
328
+ async initializeGit() {
329
+ await o.animate("Initializing git", async () => {
330
+ await d.run("git init"), await d.run("git add ."), await d.run('git commit -m "Start"');
331
+ });
332
+ }
333
+ }
334
+ a(x, "command", "create"), a(x, "description", "Create AerogelJS app"), a(x, "parameters", [["path", "Application path"]]), a(x, "options", {
335
+ name: "Application name",
336
+ local: {
337
+ type: "boolean",
338
+ description: "Whether to create an app using local Aerogel packages (used for core development)"
339
+ },
340
+ copy: {
341
+ type: "boolean",
342
+ description: "Whether to create an app linked to local Aerogel packages (used in CI)"
343
+ }
344
+ });
345
+ function z() {
346
+ return new V("");
347
+ }
348
+ function we() {
349
+ return c.contains("package.json", '"@aerogel/core": "file:');
350
+ }
351
+ function ke() {
352
+ return c.isSymlink("node_modules/@aerogel/core");
353
+ }
354
+ function y(r, e = {}) {
355
+ if (!r)
356
+ return;
357
+ const t = e.guard ?? (() => !0), i = e.validate ?? (() => !0), s = L(e.skip ?? []);
358
+ return r.forEachDescendant((n, l) => {
359
+ if (t(n) && i(n))
360
+ return n;
361
+ const g = n.getKind();
362
+ s.includes(g) && l.skip();
363
+ });
364
+ }
365
+ function K(r, e) {
366
+ if (!(!r || !e(r)))
367
+ return r;
368
+ }
369
+ class D extends u {
370
+ constructor(t) {
371
+ super();
372
+ a(this, "path");
373
+ this.path = t;
374
+ }
375
+ async run() {
376
+ this.assertAerogelOrDirectory("src/components");
377
+ const t = /* @__PURE__ */ new Set(), [i, s] = this.parsePathComponents();
378
+ await this.createComponent(i, s, t), await this.declareComponents();
379
+ const n = L(t).map((l) => `- ${l}`).join(`
380
+ `);
381
+ o.info(`${s} component created successfully! The following files were created:
382
+
383
+ ${n}`);
384
+ }
385
+ async createComponent(t, i, s) {
386
+ await o.animate("Creating component", async () => {
387
+ c.exists(`src/components/${this.path}.vue`) && o.fail(`${this.path} component already exists!`), S.instantiate(C("component"), `src/components/${t}`, {
388
+ component: {
389
+ name: i,
390
+ slug: ne(i)
391
+ }
392
+ }).forEach((l) => s.add(l));
393
+ });
394
+ }
395
+ async declareComponents() {
396
+ const t = z().edit(), i = t.requireSourceFile("vite.config.ts"), s = this.getComponentDirsArray(i);
397
+ if (!s)
398
+ return o.fail("Could not find component dirs declaration in vite config!");
399
+ s.getDescendantsOfKind(j.StringLiteral).some((n) => n.getText() === "'src/components'") || (await o.animate("Updating vite config", async () => {
400
+ s.addElement("'src/components'"), await t.save(i);
401
+ }), await t.format());
402
+ }
403
+ getComponentDirsArray(t) {
404
+ const i = y(t, {
405
+ guard: p.isCallExpression,
406
+ validate: (l) => l.getText().startsWith("Components("),
407
+ skip: j.ImportDeclaration
408
+ });
409
+ if (!i)
410
+ return null;
411
+ const s = y(i, {
412
+ guard: p.isPropertyAssignment,
413
+ validate: (l) => l.getName() === "dirs"
414
+ }), n = s == null ? void 0 : s.getInitializer();
415
+ return p.isArrayLiteralExpression(n) ? n : this.declareComponentDirsArray(i);
416
+ }
417
+ declareComponentDirsArray(t) {
418
+ const i = y(t, { guard: p.isObjectLiteralExpression }), s = i == null ? void 0 : i.addPropertyAssignment({
419
+ name: "dirs",
420
+ initializer: "[]"
421
+ });
422
+ return (s == null ? void 0 : s.getInitializer()) ?? null;
423
+ }
424
+ parsePathComponents() {
425
+ const t = this.path.lastIndexOf("/");
426
+ return t === -1 ? ["", this.path] : [this.path.substring(0, t), this.path.substring(t + 1)];
427
+ }
428
+ }
429
+ a(D, "command", "generate:component"), a(D, "description", "Generate an AerogelJS Component"), a(D, "parameters", [
430
+ ["path", "Component path (relative to components folder; extension not necessary)"]
431
+ ]);
432
+ class $ extends u {
433
+ constructor(t, i = {}) {
434
+ super();
435
+ a(this, "name");
436
+ a(this, "options");
437
+ this.name = t, this.options = i;
438
+ }
439
+ async run() {
440
+ this.assertAerogelOrDirectory("src/models"), c.exists(`src/models/${this.name}.ts`) && o.fail(`${this.name} model already exists!`), this.assertSoukaiInstalled();
441
+ const t = await o.animate("Creating model", async () => S.instantiate(C("model"), "src/models", {
442
+ model: {
443
+ name: this.name,
444
+ fieldsDefinition: this.getFieldsDefinition()
445
+ },
446
+ soukaiImports: this.options.fields ? "FieldType, defineModelSchema" : "defineModelSchema"
447
+ }).map((s) => `- ${s}`).join(`
448
+ `));
449
+ o.info(`${this.name} model created successfully! The following files were created:
450
+
451
+ ${t}`);
452
+ }
453
+ getFieldsDefinition() {
454
+ if (!this.options.fields)
455
+ return " //";
456
+ const t = this.options.fields.split(",").map((i) => {
457
+ const [s, n, l] = i.split(":");
458
+ return {
459
+ name: s,
460
+ type: re(n ?? "string"),
461
+ required: l === "required"
462
+ };
463
+ }).reduce((i, s) => {
464
+ const n = s.required ? T(`
465
+ ${s.name}: {
466
+ type: FieldType.${s.type},
467
+ required: true,
468
+ }
469
+ `) : `${s.name}: FieldType.${s.type}`;
470
+ return i + `
471
+ ${n},`;
472
+ }, "");
473
+ return T(t, { indent: 8 });
474
+ }
475
+ assertSoukaiInstalled() {
476
+ !c.contains("package.json", '"soukai"') && !c.contains("package.json", '"@aerogel/plugin-soukai"') && o.fail(`
477
+ Soukai is not installed yet! You can install it running:
478
+ npx gel install soukai
479
+ `);
480
+ }
481
+ }
482
+ a($, "command", "generate:model"), a($, "description", "Generate an AerogelJS Model"), a($, "parameters", [["name", "Model name"]]), a($, "options", {
483
+ fields: "Create model with the given fields"
484
+ });
485
+ class b extends u {
486
+ constructor(t) {
487
+ super();
488
+ a(this, "name");
489
+ this.name = t;
490
+ }
491
+ async run() {
492
+ this.assertAerogelOrDirectory("src/services");
493
+ const t = /* @__PURE__ */ new Set(), i = z().edit();
494
+ await this.createService(t), await this.registerService(i), await i.format();
495
+ const s = L(t).map((n) => `- ${n}`).join(`
496
+ `);
497
+ o.info(`${this.name} service created successfully! The following files were created:
498
+
499
+ ${s}`);
500
+ }
501
+ async createService(t) {
502
+ await o.animate("Creating service", async () => {
503
+ c.exists(`src/services/${this.name}.ts`) && o.fail(`${this.name} service already exists!`), S.instantiate(C("service"), "src/services", {
504
+ service: {
505
+ name: this.name
506
+ }
507
+ }).forEach((s) => t.add(s));
508
+ });
509
+ }
510
+ async registerService(t) {
511
+ await o.animate("Registering service", async () => {
512
+ c.exists("src/services/index.ts") || await this.createServicesIndex(t);
513
+ const i = t.requireSourceFile("src/services/index.ts"), s = this.getServicesObject(i);
514
+ if (!s)
515
+ return o.fail("Could not find services object in services config, please add it manually.");
516
+ i.addImportDeclaration({
517
+ defaultImport: this.name,
518
+ moduleSpecifier: `./${this.name}`
519
+ }), s.addPropertyAssignment({
520
+ name: `$${M(this.name)}`,
521
+ initializer: this.name
522
+ }), await t.save(i);
523
+ });
524
+ }
525
+ async createServicesIndex(t) {
526
+ c.write(
527
+ "src/services/index.ts",
528
+ T(`
529
+ export const services = {};
530
+
531
+ export type AppServices = typeof services;
532
+
533
+ declare module '@aerogel/core' {
534
+ interface Services extends AppServices {}
535
+ }
536
+ `)
537
+ ), t.addSourceFile("src/services/index.ts");
538
+ const i = t.requireSourceFile("src/main.ts"), s = this.getBootstrapOptions(i);
539
+ if (!s)
540
+ return o.fail("Could not find options object in bootstrap config, please add the services manually.");
541
+ s.insertShorthandPropertyAssignment(0, { name: "services" }), i.addImportDeclaration({
542
+ namedImports: ["services"],
543
+ moduleSpecifier: "./services"
544
+ }), await t.save(i);
545
+ }
546
+ getBootstrapOptions(t) {
547
+ const i = y(t, {
548
+ guard: p.isCallExpression,
549
+ validate: (n) => n.getExpression().getText() === "bootstrap",
550
+ skip: j.ImportDeclaration
551
+ }), s = i == null ? void 0 : i.getArguments()[1];
552
+ return p.isObjectLiteralExpression(s) ? s : null;
553
+ }
554
+ getServicesObject(t) {
555
+ const i = y(t, {
556
+ guard: p.isVariableDeclaration,
557
+ validate: (n) => n.getName() === "services"
558
+ }), s = i == null ? void 0 : i.getInitializer();
559
+ return p.isObjectLiteralExpression(s) ? s : null;
560
+ }
561
+ }
562
+ a(b, "command", "generate:service"), a(b, "description", "Generate an AerogelJS Service"), a(b, "parameters", [["name", "Service name"]]);
563
+ class B extends u {
564
+ async run() {
565
+ o.info("[AerogelJS CLI info]"), o.info("Installation directory: " + w(new k(
566
+ /* @vite-ignore */
567
+ "./",
568
+ import.meta.url
569
+ )));
570
+ }
571
+ }
572
+ a(B, "command", "info"), a(B, "description", "Show debugging information about the CLI");
573
+ class q {
574
+ constructor(e) {
575
+ a(this, "name");
576
+ this.name = e;
577
+ }
578
+ async install() {
579
+ this.assertNotInstalled(), await this.beforeInstall(), await this.installDependencies();
580
+ {
581
+ const e = z().edit();
582
+ await this.updateFiles(e), await e.format();
583
+ }
584
+ await this.afterInstall(), o.info(`Plugin ${this.name} installed!`);
585
+ }
586
+ assertNotInstalled() {
587
+ c.contains("package.json", `"${this.getNpmPackageName()}"`) && o.fail(`${this.name} is already installed!`);
588
+ }
589
+ async beforeInstall() {
590
+ }
591
+ async afterInstall() {
592
+ }
593
+ async installDependencies() {
594
+ await o.animate("Installing plugin dependencies", async () => {
595
+ await this.installNpmDependencies();
596
+ });
597
+ }
598
+ async updateFiles(e) {
599
+ this.isForDevelopment() || await this.updateBootstrapConfig(e);
600
+ }
601
+ async installNpmDependencies() {
602
+ const e = this.isForDevelopment() ? "--save-dev" : "";
603
+ if (ke()) {
604
+ await d.run(`npm install file:${m(this.getLocalPackageName())} ${e}`);
605
+ return;
606
+ }
607
+ if (we()) {
608
+ const t = h(this.getLocalPackageName()) ?? f(this.getLocalPackageName());
609
+ await d.run(`npm install file:${t} ${e}`);
610
+ return;
611
+ }
612
+ await d.run(`npm install ${this.getNpmPackageName()}@next --save-exact ${e}`);
613
+ }
614
+ async updateBootstrapConfig(e) {
615
+ await o.animate("Injecting plugin in bootstrap configuration", async () => {
616
+ const t = e.requireSourceFile("src/main.ts"), i = this.getBootstrapPluginsDeclaration(t);
617
+ if (!i)
618
+ return o.fail(`
619
+ Could not find plugins array in bootstrap config, please add the following manually:
620
+
621
+ ${this.getBootstrapConfig()}
622
+ `);
623
+ t.addImportDeclaration(this.getBootstrapImport()), i.addElement(this.getBootstrapConfig()), await e.save(t);
624
+ });
625
+ }
626
+ getBootstrapPluginsDeclaration(e) {
627
+ var l, g;
628
+ const t = y(e, {
629
+ guard: p.isCallExpression,
630
+ validate: (v) => v.getExpression().getText() === "bootstrap",
631
+ skip: j.ImportDeclaration
632
+ }), i = t == null ? void 0 : t.getArguments()[1], s = (l = K(i, p.isObjectLiteralExpression)) == null ? void 0 : l.getProperty("plugins"), n = (g = K(s, p.isPropertyAssignment)) == null ? void 0 : g.getInitializer();
633
+ return p.isArrayLiteralExpression(n) ? n : null;
634
+ }
635
+ getTailwindContentArray(e) {
636
+ const t = y(e, {
637
+ guard: p.isPropertyAssignment,
638
+ validate: (s) => s.getName() === "content",
639
+ skip: j.JSDoc
640
+ }), i = t == null ? void 0 : t.getInitializer();
641
+ return p.isArrayLiteralExpression(i) ? i : null;
642
+ }
643
+ getBootstrapImport() {
644
+ return {
645
+ defaultImport: M(this.name),
646
+ moduleSpecifier: `@aerogel/plugin-${this.name}`
647
+ };
648
+ }
649
+ getNpmPackageName() {
650
+ return `@aerogel/${this.getLocalPackageName()}`;
651
+ }
652
+ getLocalPackageName() {
653
+ return `plugin-${this.name}`;
654
+ }
655
+ isForDevelopment() {
656
+ return !1;
657
+ }
658
+ getBootstrapConfig() {
659
+ return `${M(this.name)}()`;
660
+ }
661
+ }
662
+ class Se extends q {
663
+ constructor() {
664
+ super("local-first");
665
+ }
666
+ }
667
+ class xe extends q {
668
+ constructor() {
669
+ super("solid");
670
+ }
671
+ async updateFiles(e) {
672
+ await this.updateNpmScripts(e), await this.updateGitIgnore(), await super.updateFiles(e);
673
+ }
674
+ async installNpmDependencies() {
675
+ await d.run("npm install soukai-solid@next --save-exact"), await d.run("npm install @noeldemartin/solid-utils@next --save-exact"), await d.run("npm install @solid/community-server@7.1.6 --save-dev -E"), await super.installNpmDependencies();
676
+ }
677
+ async updateNpmScripts(e) {
678
+ o.info("Updating npm scripts...");
679
+ const t = c.read("package.json");
680
+ if (!t)
681
+ return o.fail("Could not find package.json file");
682
+ c.write(
683
+ "package.json",
684
+ t.replace(
685
+ '"cy:dev": "concurrently --kill-others \\"npm run test:serve-app\\" \\"npm run cy:open\\"",',
686
+ '"cy:dev": "concurrently --kill-others \\"npm run test:serve-app\\" \\"npm run test:serve-pod\\" \\"npm run cy:open\\"",'
687
+ ).replace(
688
+ '"cy:test": "start-server-and-test test:serve-app http-get://localhost:5001 cy:run",',
689
+ '"cy:test": "start-server-and-test test:serve-app http-get://localhost:5001 test:serve-pod http-get://localhost:3000 cy:run",'
690
+ ).replace(
691
+ '"dev": "vite",',
692
+ `"dev": "vite",
693
+ "dev:serve-pod": "community-solid-server -c @css:config/file.json -f ./solid",`
694
+ ).replace(
695
+ '"test:serve-app": "vite --port 5001 --mode testing"',
696
+ `"test:serve-app": "vite --port 5001 --mode testing",
697
+ "test:serve-pod": "community-solid-server -l warn"`
698
+ )
699
+ ), e.addModifiedFile("package.json");
700
+ }
701
+ async updateGitIgnore() {
702
+ o.info("Updating .gitignore");
703
+ const e = c.read(".gitignore") ?? "";
704
+ c.write(".gitignore", `${e}/solid
705
+ `);
706
+ }
707
+ }
708
+ class $e extends q {
709
+ constructor() {
710
+ super("soukai");
711
+ }
712
+ async installNpmDependencies() {
713
+ await d.run("npm install soukai@next --save-exact"), await super.installNpmDependencies();
714
+ }
715
+ getBootstrapConfig() {
716
+ return "soukai({ models: import.meta.glob('@/models/*', { eager: true }) })";
717
+ }
718
+ }
719
+ const U = [new $e(), new xe(), new Se()].reduce(
720
+ (r, e) => Object.assign(r, { [e.name]: e }),
721
+ {}
722
+ );
723
+ class I extends u {
724
+ constructor(t) {
725
+ super();
726
+ a(this, "plugin");
727
+ this.plugin = U[t] ?? o.fail(`Plugin '${t}' doesn't exist. Available plugins: ${Object.keys(U).join(", ")}`);
728
+ }
729
+ async run() {
730
+ await this.plugin.install();
731
+ }
732
+ }
733
+ a(I, "command", "install"), a(I, "description", "Install an AerogelJS plugin"), a(I, "parameters", [["plugin", "Plugin to install"]]);
734
+ class Fe {
735
+ run(e) {
736
+ const t = new X();
737
+ t.name("gel").description("AerogelJS CLI").version(this.getVersion()), x.define(t), D.define(t), $.define(t), b.define(t), B.define(t), I.define(t), t.parse(e);
738
+ }
739
+ getVersion() {
740
+ const e = "Could not find CLI's version, please report this bug.", t = w(new k(
741
+ /* @vite-ignore */
742
+ "../package.json",
743
+ import.meta.url
744
+ ));
745
+ if (!N(t))
746
+ throw new Error(e);
747
+ return JSON.parse(J(t).toString()).version ?? ae(e);
748
+ }
749
+ }
750
+ const Me = P(Fe);
751
+ export {
752
+ Me as CLI
753
+ };
754
+ //# sourceMappingURL=aerogel-cli.js.map