@aerogel/cli 0.0.0-next.d4e50d20bf4c270c2068f0a4398e9304ee4a062e → 0.0.0-next.d803ba42263b449637ede53bb8ce9a147e781512

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