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