@stacksjs/actions 0.70.258 → 0.70.259
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/dist/action.js +1 -80
- package/dist/actions.js +1 -2
- package/dist/add.js +1 -20
- package/dist/ai/request-model-access.js +1 -10
- package/dist/auth/client.js +2 -44
- package/dist/auth/prune.js +1 -35
- package/dist/auth/setup.js +33 -153
- package/dist/auth/token.js +1 -10
- package/dist/blog-admin.js +3 -151
- package/dist/blog.js +33 -271
- package/dist/build/cli.js +1 -6
- package/dist/build/component-library.js +1 -36
- package/dist/build/component-libs.js +1 -2
- package/dist/build/core.js +1 -55
- package/dist/build/desktop.js +4 -61
- package/dist/build/dmg.js +4 -68
- package/dist/build/docs.js +1 -5
- package/dist/build/frontend-static.js +6 -122
- package/dist/build/server.js +1 -6
- package/dist/build/stacks.js +1 -8
- package/dist/build/views.js +1 -16
- package/dist/build-web-component-lib.js +1 -2
- package/dist/build.js +1 -57
- package/dist/bump.js +9 -210
- package/dist/changelog.js +1 -27
- package/dist/check/ports.js +1 -16
- package/dist/clean.js +1 -4
- package/dist/commit.js +1 -12
- package/dist/copy-types.js +1 -9
- package/dist/database/seed.js +1 -26
- package/dist/deploy/create-receipt-rule.js +1 -36
- package/dist/deploy/index.js +29 -1306
- package/dist/dev/api.js +3 -94
- package/dist/dev/components.js +1 -7
- package/dist/dev/csrf.js +1 -28
- package/dist/dev/dashboard-request-routing.js +1 -10
- package/dist/dev/dashboard-utils.js +1 -380
- package/dist/dev/dashboard.js +7 -422
- package/dist/dev/desktop.js +1 -1
- package/dist/dev/docs.js +1 -24
- package/dist/dev/exit-with-parent.d.ts +6 -0
- package/dist/dev/exit-with-parent.js +1 -0
- package/dist/dev/index.js +1 -29
- package/dist/dev/migrate-watcher.js +1 -74
- package/dist/dev/system-tray.js +2 -172
- package/dist/dev/views.js +1 -169
- package/dist/discover-packages.js +1 -32
- package/dist/domains/add.js +1 -61
- package/dist/domains/purchase.js +1 -66
- package/dist/domains/remove.js +1 -24
- package/dist/examples.js +1 -34
- package/dist/find-projects.js +1 -16
- package/dist/fresh.js +1 -17
- package/dist/generate/action-types.js +3 -9
- package/dist/generate/component-meta.js +1 -9
- package/dist/generate/custom-cli-file.js +2 -20
- package/dist/generate/env-files.js +5 -46
- package/dist/generate/ide-helpers.js +1 -8
- package/dist/generate/images.js +1 -26
- package/dist/generate/index.js +1 -166
- package/dist/generate/lib-entries.js +1 -16
- package/dist/generate/pantry-file.js +1 -46
- package/dist/generate/symlink-core.js +1 -2
- package/dist/generate/types.js +1 -3
- package/dist/generate/vschema.js +2 -47
- package/dist/generate/vscode-custom-data.js +1 -9
- package/dist/helpers/api-host.js +1 -7
- package/dist/helpers/component-meta.js +5 -295
- package/dist/helpers/index.js +1 -1
- package/dist/helpers/lib-entries.js +3 -73
- package/dist/helpers/package-json.js +2 -34
- package/dist/helpers/utils.js +1 -130
- package/dist/helpers/vscode-custom-data.js +3 -57
- package/dist/index.js +1 -51
- package/dist/key-generate.js +1 -24
- package/dist/lint/fix.js +1 -4
- package/dist/lint/index.js +1 -4
- package/dist/lint/lint.js +1 -34
- package/dist/lint/stx-gate.js +3 -175
- package/dist/make-command.js +4 -55
- package/dist/make-job.js +3 -29
- package/dist/make-policy.js +4 -53
- package/dist/make-resource.js +3 -33
- package/dist/make.js +7 -323
- package/dist/migrate/database.js +1 -16
- package/dist/migrate/fresh.js +1 -36
- package/dist/prepublish.js +1 -16
- package/dist/queue/clear.js +1 -42
- package/dist/queue/dlq-purge.js +1 -28
- package/dist/queue/dlq-retry.js +1 -35
- package/dist/queue/dlq.js +4 -55
- package/dist/queue/failed.js +4 -69
- package/dist/queue/flush.js +2 -49
- package/dist/queue/inspect.js +7 -154
- package/dist/queue/list.js +4 -69
- package/dist/queue/monitor.js +5 -94
- package/dist/queue/pause.js +1 -28
- package/dist/queue/quarantine.js +2 -42
- package/dist/queue/resume.js +1 -27
- package/dist/queue/retry.js +1 -41
- package/dist/queue/schedule-list.js +4 -33
- package/dist/queue/schedule.js +1 -12
- package/dist/queue/status.js +4 -68
- package/dist/queue/table.js +1 -10
- package/dist/queue/unquarantine.js +1 -27
- package/dist/queue/work.js +1 -57
- package/dist/release-preflight.js +3 -61
- package/dist/release.js +1 -29
- package/dist/route/list.js +2 -78
- package/dist/run-action.js +1 -1
- package/dist/saas/setup.js +1 -9
- package/dist/scaffold-crud.js +12 -137
- package/dist/schedule/run.js +1 -7
- package/dist/search/flush.js +1 -10
- package/dist/search/import.js +1 -10
- package/dist/search/settings-list.js +1 -10
- package/dist/search/settings.js +1 -9
- package/dist/serve/api.js +1 -37
- package/dist/setup/index.js +1 -1
- package/dist/setup/ssl.js +2 -268
- package/dist/stacks.js +1 -316
- package/dist/templates.js +20 -40
- package/dist/test/feature.js +1 -2
- package/dist/test/index.js +1 -2
- package/dist/test/runner.js +1 -38
- package/dist/test/runner.test.js +1 -29
- package/dist/test/ui.js +1 -2
- package/dist/test/unit.js +1 -2
- package/dist/typecheck.js +1 -4
- package/dist/types.js +1 -16
- package/dist/upgrade/binary.js +1 -29
- package/dist/upgrade/framework-hooks.js +1 -40
- package/dist/upgrade/framework-utils.js +2 -259
- package/dist/upgrade/framework.js +11 -484
- package/dist/upgrade/index.js +1 -17
- package/dist/upgrade/package-project.js +1 -150
- package/dist/upgrade/packages.js +17 -243
- package/dist/upgrade/shell.js +3 -40
- package/dist/upgrade.js +1 -38
- package/package.json +18 -18
|
@@ -1,295 +1,5 @@
|
|
|
1
|
-
import { frameworkPath, join,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (parseMarkdownFn)
|
|
7
|
-
return parseMarkdownFn;
|
|
8
|
-
try {
|
|
9
|
-
parseMarkdownFn = (await import("@stacksjs/ts-md")).parseMarkdown;
|
|
10
|
-
} catch {
|
|
11
|
-
parseMarkdownFn = (s) => s;
|
|
12
|
-
}
|
|
13
|
-
return parseMarkdownFn;
|
|
14
|
-
}
|
|
15
|
-
function renderDescription(raw) {
|
|
16
|
-
if (!raw)
|
|
17
|
-
return "";
|
|
18
|
-
return parseMarkdownFn ? parseMarkdownFn(raw) : raw;
|
|
19
|
-
}
|
|
20
|
-
export async function generateComponentMeta() {
|
|
21
|
-
await getMarkdownParser();
|
|
22
|
-
const components = globSync([
|
|
23
|
-
"components/*.stx",
|
|
24
|
-
"components/**/*.stx",
|
|
25
|
-
"resources/components/**/*.stx",
|
|
26
|
-
"storage/framework/defaults/resources/components/**/*.stx"
|
|
27
|
-
], { cwd: projectPath(), absolute: !0 }), metaDirPath = frameworkPath("component-meta");
|
|
28
|
-
if (!existsSync(metaDirPath))
|
|
29
|
-
mkdirSync(metaDirPath, { recursive: !0 });
|
|
30
|
-
for (const componentPath of components) {
|
|
31
|
-
const componentExportName = path.parse(componentPath).name, meta = parseStxComponentMeta(componentPath), metaJsonFilePath = join(metaDirPath, `${componentExportName}.json`);
|
|
32
|
-
writeFileSync(metaJsonFilePath, JSON.stringify(meta, null, 2));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export function parseStxComponentMeta(componentPath) {
|
|
36
|
-
const source = readFileSync(componentPath, "utf8"), scriptBlock = extractFirstScriptBlock(source), templateBlock = extractTemplate(source), props = scriptBlock ? extractProps(scriptBlock) : [], events = scriptBlock ? extractEvents(scriptBlock) : [], slots = extractSlots(templateBlock);
|
|
37
|
-
return { props, events, slots };
|
|
38
|
-
}
|
|
39
|
-
function extractFirstScriptBlock(source) {
|
|
40
|
-
const serverMatch = /<script\b[^>]*\bserver\b[^>]*>([\s\S]*?)<\/script>/i.exec(source);
|
|
41
|
-
if (serverMatch?.[1])
|
|
42
|
-
return serverMatch[1];
|
|
43
|
-
return /<script\b[^>]*>([\s\S]*?)<\/script>/i.exec(source)?.[1] ?? null;
|
|
44
|
-
}
|
|
45
|
-
function extractTemplate(source) {
|
|
46
|
-
const templateMatch = /<template\b[^>]*>([\s\S]*?)<\/template>/i.exec(source);
|
|
47
|
-
if (templateMatch?.[1])
|
|
48
|
-
return templateMatch[1];
|
|
49
|
-
return source.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, "");
|
|
50
|
-
}
|
|
51
|
-
function extractProps(script) {
|
|
52
|
-
const interfaces = collectInterfaces(script), propsTypeBody = locatePropsType(script, interfaces);
|
|
53
|
-
if (!propsTypeBody)
|
|
54
|
-
return [];
|
|
55
|
-
const fields = parseTypeBody(propsTypeBody, interfaces), defaults = extractDefaults(script);
|
|
56
|
-
return fields.map((field) => {
|
|
57
|
-
return {
|
|
58
|
-
name: field.required ? field.name : `${field.name}?`,
|
|
59
|
-
description: renderDescription(field.description),
|
|
60
|
-
type: field.type,
|
|
61
|
-
default: defaults[field.name] ?? field.default ?? "unknown",
|
|
62
|
-
required: field.required
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
function collectInterfaces(script) {
|
|
67
|
-
const interfaces = new Map, ifaceRe = /(?:export\s+)?interface\s+([A-Z][\w$]*)\s*(?:extends\s+[\w$,\s]+)?\s*\{/g;
|
|
68
|
-
let m;
|
|
69
|
-
while ((m = ifaceRe.exec(script)) !== null) {
|
|
70
|
-
const name = m[1];
|
|
71
|
-
if (!name)
|
|
72
|
-
continue;
|
|
73
|
-
const start = m.index + m[0].length, body = sliceBalanced(script, start - 1, "{", "}");
|
|
74
|
-
if (body !== null)
|
|
75
|
-
interfaces.set(name, body);
|
|
76
|
-
}
|
|
77
|
-
const typeAliasRe = /(?:export\s+)?type\s+([A-Z][\w$]*)\s*=\s*\{/g;
|
|
78
|
-
while ((m = typeAliasRe.exec(script)) !== null) {
|
|
79
|
-
const name = m[1];
|
|
80
|
-
if (!name)
|
|
81
|
-
continue;
|
|
82
|
-
const start = m.index + m[0].length, body = sliceBalanced(script, start - 1, "{", "}");
|
|
83
|
-
if (body !== null)
|
|
84
|
-
interfaces.set(name, body);
|
|
85
|
-
}
|
|
86
|
-
return interfaces;
|
|
87
|
-
}
|
|
88
|
-
function locatePropsType(script, interfaces) {
|
|
89
|
-
const match = /defineProps\s*<\s*([\s\S]+?)\s*>\s*\(/.exec(script), generic = match?.[1]?.trim();
|
|
90
|
-
if (!match || !generic)
|
|
91
|
-
return null;
|
|
92
|
-
if (generic.startsWith("{")) {
|
|
93
|
-
const braceStart = script.indexOf("{", match.index);
|
|
94
|
-
return sliceBalanced(script, braceStart, "{", "}");
|
|
95
|
-
}
|
|
96
|
-
const ref = generic.replace(/[<>(].*$/, "").split("&")[0]?.trim();
|
|
97
|
-
if (!ref)
|
|
98
|
-
return null;
|
|
99
|
-
return interfaces.get(ref) ?? null;
|
|
100
|
-
}
|
|
101
|
-
function parseTypeBody(body, interfaces) {
|
|
102
|
-
const fields = [], statements = splitTopLevel(body, [";", `
|
|
103
|
-
`]);
|
|
104
|
-
let pendingDoc = "";
|
|
105
|
-
for (const raw of statements) {
|
|
106
|
-
const stmt = raw.trim();
|
|
107
|
-
if (!stmt)
|
|
108
|
-
continue;
|
|
109
|
-
const docMatch = /^\/\*\*([\s\S]*?)\*\/\s*([\s\S]*)$/.exec(stmt);
|
|
110
|
-
if (docMatch) {
|
|
111
|
-
pendingDoc = (docMatch[1] ?? "").split(`
|
|
112
|
-
`).map((l) => l.replace(/^\s*\*\s?/, "")).join(`
|
|
113
|
-
`).trim();
|
|
114
|
-
const remainder = (docMatch[2] ?? "").trim();
|
|
115
|
-
if (!remainder)
|
|
116
|
-
continue;
|
|
117
|
-
const field = parseFieldLine(remainder, pendingDoc, interfaces);
|
|
118
|
-
if (field)
|
|
119
|
-
fields.push(field);
|
|
120
|
-
pendingDoc = "";
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
if (stmt.startsWith("//")) {
|
|
124
|
-
pendingDoc = stmt.replace(/^\/\/\s?/, "");
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
const field = parseFieldLine(stmt, pendingDoc, interfaces);
|
|
128
|
-
if (field)
|
|
129
|
-
fields.push(field);
|
|
130
|
-
pendingDoc = "";
|
|
131
|
-
}
|
|
132
|
-
return fields;
|
|
133
|
-
}
|
|
134
|
-
function parseFieldLine(line, description, _interfaces) {
|
|
135
|
-
if (/^[a-zA-Z_$][\w$]*\s*\(/.test(line.trimStart()))
|
|
136
|
-
return null;
|
|
137
|
-
const m = /^([a-zA-Z_$][\w$]*)\s*(\??)\s*:\s*([\s\S]+?)\s*[;,]?\s*$/.exec(line);
|
|
138
|
-
if (!m)
|
|
139
|
-
return null;
|
|
140
|
-
const name = m[1], optional = m[2] ?? "", type = m[3];
|
|
141
|
-
if (!name || !type)
|
|
142
|
-
return null;
|
|
143
|
-
return {
|
|
144
|
-
name,
|
|
145
|
-
type: collapseWhitespace(type),
|
|
146
|
-
required: optional !== "?",
|
|
147
|
-
description
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function extractDefaults(script) {
|
|
151
|
-
const defaults = {}, destructRe = /const\s*\{\s*([\s\S]*?)\s*\}\s*=\s*(?:withDefaults\s*\(\s*)?defineProps/g;
|
|
152
|
-
let m;
|
|
153
|
-
while ((m = destructRe.exec(script)) !== null)
|
|
154
|
-
if (m[1])
|
|
155
|
-
parseDestructDefaults(m[1], defaults);
|
|
156
|
-
const withDefaultsIdx = script.indexOf("withDefaults(");
|
|
157
|
-
if (withDefaultsIdx >= 0) {
|
|
158
|
-
const afterDefine = script.indexOf("defineProps", withDefaultsIdx);
|
|
159
|
-
if (afterDefine > 0) {
|
|
160
|
-
const generic = script.indexOf(">", afterDefine), closeParen = script.indexOf(")", generic >= 0 ? generic : afterDefine);
|
|
161
|
-
if (closeParen > 0) {
|
|
162
|
-
const commaIdx = script.indexOf(",", closeParen), objStart = commaIdx >= 0 ? script.indexOf("{", commaIdx) : -1;
|
|
163
|
-
if (objStart > 0) {
|
|
164
|
-
const body = sliceBalanced(script, objStart, "{", "}");
|
|
165
|
-
if (body)
|
|
166
|
-
parseObjectDefaults(body, defaults);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return defaults;
|
|
172
|
-
}
|
|
173
|
-
function parseDestructDefaults(destructBody, out) {
|
|
174
|
-
for (const part of splitTopLevel(destructBody, [","])) {
|
|
175
|
-
const m = /^\s*([a-zA-Z_$][\w$]*)\s*=\s*([\s\S]+?)\s*$/.exec(part), key = m?.[1], value = m?.[2];
|
|
176
|
-
if (key && value)
|
|
177
|
-
out[key] = collapseWhitespace(value);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
function parseObjectDefaults(objectBody, out) {
|
|
181
|
-
for (const part of splitTopLevel(objectBody, [","])) {
|
|
182
|
-
const m = /^\s*([a-zA-Z_$][\w$]*)\s*:\s*([\s\S]+?)\s*$/.exec(part.trim()), key = m?.[1], value = m?.[2];
|
|
183
|
-
if (key && value)
|
|
184
|
-
out[key] = collapseWhitespace(value);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function extractEvents(script) {
|
|
188
|
-
const m = /defineEmits\s*<\s*\{([\s\S]*?)\}\s*>\s*\(/.exec(script);
|
|
189
|
-
if (!m?.[1])
|
|
190
|
-
return [];
|
|
191
|
-
const events = [];
|
|
192
|
-
for (const part of splitTopLevel(m[1], [";", `
|
|
193
|
-
`])) {
|
|
194
|
-
const trimmed = part.trim();
|
|
195
|
-
if (!trimmed)
|
|
196
|
-
continue;
|
|
197
|
-
const tuple = /^['"]?([\w-]+)['"]?\s*:\s*\[(.*?)\]\s*$/.exec(trimmed);
|
|
198
|
-
if (tuple) {
|
|
199
|
-
const name = tuple[1];
|
|
200
|
-
if (!name)
|
|
201
|
-
continue;
|
|
202
|
-
events.push({ name, type: tuple[2]?.trim() || "void", description: "" });
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
const fn = /^([a-zA-Z_$][\w$]*)\s*\(([\s\S]*?)\)\s*:\s*([\s\S]+)$/.exec(trimmed);
|
|
206
|
-
if (fn) {
|
|
207
|
-
const name = fn[1];
|
|
208
|
-
if (!name)
|
|
209
|
-
continue;
|
|
210
|
-
events.push({ name, type: fn[2]?.trim() || "void", description: "" });
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return events;
|
|
214
|
-
}
|
|
215
|
-
function extractSlots(template) {
|
|
216
|
-
const slots = [], seen = new Set, slotRe = /<slot\b([^>]*)>/g;
|
|
217
|
-
let m;
|
|
218
|
-
while ((m = slotRe.exec(template)) !== null) {
|
|
219
|
-
const attrs = m[1] ?? "", name = /\bname\s*=\s*["']([^"']+)["']/.exec(attrs)?.[1] ?? "default";
|
|
220
|
-
if (seen.has(name))
|
|
221
|
-
continue;
|
|
222
|
-
seen.add(name);
|
|
223
|
-
slots.push({ name, description: "" });
|
|
224
|
-
}
|
|
225
|
-
return slots;
|
|
226
|
-
}
|
|
227
|
-
function sliceBalanced(source, openIdx, open, close) {
|
|
228
|
-
if (source[openIdx] !== open)
|
|
229
|
-
return null;
|
|
230
|
-
let depth = 0, i = openIdx, inString = null;
|
|
231
|
-
while (i < source.length) {
|
|
232
|
-
const ch = source[i];
|
|
233
|
-
if (ch === void 0)
|
|
234
|
-
break;
|
|
235
|
-
if (inString) {
|
|
236
|
-
if (ch === "\\") {
|
|
237
|
-
i += 2;
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
if (ch === inString)
|
|
241
|
-
inString = null;
|
|
242
|
-
i++;
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
if (ch === '"' || ch === "'" || ch === "`") {
|
|
246
|
-
inString = ch;
|
|
247
|
-
i++;
|
|
248
|
-
continue;
|
|
249
|
-
}
|
|
250
|
-
if (ch === open)
|
|
251
|
-
depth++;
|
|
252
|
-
else if (ch === close) {
|
|
253
|
-
depth--;
|
|
254
|
-
if (depth === 0)
|
|
255
|
-
return source.slice(openIdx + 1, i);
|
|
256
|
-
}
|
|
257
|
-
i++;
|
|
258
|
-
}
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
|
-
function splitTopLevel(source, separators) {
|
|
262
|
-
const out = [], sepSet = new Set(separators);
|
|
263
|
-
let depth = 0, inString = null, start = 0;
|
|
264
|
-
for (let i = 0;i < source.length; i++) {
|
|
265
|
-
const ch = source[i];
|
|
266
|
-
if (ch === void 0)
|
|
267
|
-
break;
|
|
268
|
-
if (inString) {
|
|
269
|
-
if (ch === "\\") {
|
|
270
|
-
i++;
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
if (ch === inString)
|
|
274
|
-
inString = null;
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
|
-
if (ch === '"' || ch === "'" || ch === "`") {
|
|
278
|
-
inString = ch;
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
if (ch === "{" || ch === "[" || ch === "(" || ch === "<")
|
|
282
|
-
depth++;
|
|
283
|
-
else if (ch === "}" || ch === "]" || ch === ")" || ch === ">")
|
|
284
|
-
depth--;
|
|
285
|
-
else if (depth === 0 && sepSet.has(ch)) {
|
|
286
|
-
out.push(source.slice(start, i));
|
|
287
|
-
start = i + 1;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
out.push(source.slice(start));
|
|
291
|
-
return out;
|
|
292
|
-
}
|
|
293
|
-
function collapseWhitespace(s) {
|
|
294
|
-
return s.replace(/\s+/g, " ").trim();
|
|
295
|
-
}
|
|
1
|
+
import{frameworkPath,join,path,projectPath}from"@stacksjs/path";import{existsSync,globSync,mkdirSync,writeFileSync}from"@stacksjs/storage";import{readFileSync}from"node:fs";let parseMarkdownFn=null;async function getMarkdownParser(){if(parseMarkdownFn)return parseMarkdownFn;try{parseMarkdownFn=(await import("@stacksjs/ts-md")).parseMarkdown}catch{parseMarkdownFn=(s)=>s}return parseMarkdownFn}function renderDescription(raw){if(!raw)return"";return parseMarkdownFn?parseMarkdownFn(raw):raw}export async function generateComponentMeta(){await getMarkdownParser();const components=globSync(["components/*.stx","components/**/*.stx","resources/components/**/*.stx","storage/framework/defaults/resources/components/**/*.stx"],{cwd:projectPath(),absolute:!0}),metaDirPath=frameworkPath("component-meta");if(!existsSync(metaDirPath))mkdirSync(metaDirPath,{recursive:!0});for(const componentPath of components){const componentExportName=path.parse(componentPath).name,meta=parseStxComponentMeta(componentPath),metaJsonFilePath=join(metaDirPath,`${componentExportName}.json`);writeFileSync(metaJsonFilePath,JSON.stringify(meta,null,2))}}export function parseStxComponentMeta(componentPath){const source=readFileSync(componentPath,"utf8"),scriptBlock=extractFirstScriptBlock(source),templateBlock=extractTemplate(source),props=scriptBlock?extractProps(scriptBlock):[],events=scriptBlock?extractEvents(scriptBlock):[],slots=extractSlots(templateBlock);return{props,events,slots}}function extractFirstScriptBlock(source){const serverMatch=/<script\b[^>]*\bserver\b[^>]*>([\s\S]*?)<\/script>/i.exec(source);if(serverMatch?.[1])return serverMatch[1];return/<script\b[^>]*>([\s\S]*?)<\/script>/i.exec(source)?.[1]??null}function extractTemplate(source){const templateMatch=/<template\b[^>]*>([\s\S]*?)<\/template>/i.exec(source);if(templateMatch?.[1])return templateMatch[1];return source.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"")}function extractProps(script){const interfaces=collectInterfaces(script),propsTypeBody=locatePropsType(script,interfaces);if(!propsTypeBody)return[];const fields=parseTypeBody(propsTypeBody,interfaces),defaults=extractDefaults(script);return fields.map((field)=>{return{name:field.required?field.name:`${field.name}?`,description:renderDescription(field.description),type:field.type,default:defaults[field.name]??field.default??"unknown",required:field.required}})}function collectInterfaces(script){const interfaces=new Map,ifaceRe=/(?:export\s+)?interface\s+([A-Z][\w$]*)\s*(?:extends\s+[\w$,\s]+)?\s*\{/g;let m;while((m=ifaceRe.exec(script))!==null){const name=m[1];if(!name)continue;const start=m.index+m[0].length,body=sliceBalanced(script,start-1,"{","}");if(body!==null)interfaces.set(name,body)}const typeAliasRe=/(?:export\s+)?type\s+([A-Z][\w$]*)\s*=\s*\{/g;while((m=typeAliasRe.exec(script))!==null){const name=m[1];if(!name)continue;const start=m.index+m[0].length,body=sliceBalanced(script,start-1,"{","}");if(body!==null)interfaces.set(name,body)}return interfaces}function locatePropsType(script,interfaces){const match=/defineProps\s*<\s*([\s\S]+?)\s*>\s*\(/.exec(script),generic=match?.[1]?.trim();if(!match||!generic)return null;if(generic.startsWith("{")){const braceStart=script.indexOf("{",match.index);return sliceBalanced(script,braceStart,"{","}")}const ref=generic.replace(/[<>(].*$/,"").split("&")[0]?.trim();if(!ref)return null;return interfaces.get(ref)??null}function parseTypeBody(body,interfaces){const fields=[],statements=splitTopLevel(body,[";",`
|
|
2
|
+
`]);let pendingDoc="";for(const raw of statements){const stmt=raw.trim();if(!stmt)continue;const docMatch=/^\/\*\*([\s\S]*?)\*\/\s*([\s\S]*)$/.exec(stmt);if(docMatch){pendingDoc=(docMatch[1]??"").split(`
|
|
3
|
+
`).map((l)=>l.replace(/^\s*\*\s?/,"")).join(`
|
|
4
|
+
`).trim();const remainder=(docMatch[2]??"").trim();if(!remainder)continue;const field=parseFieldLine(remainder,pendingDoc,interfaces);if(field)fields.push(field);pendingDoc="";continue}if(stmt.startsWith("//")){pendingDoc=stmt.replace(/^\/\/\s?/,"");continue}const field=parseFieldLine(stmt,pendingDoc,interfaces);if(field)fields.push(field);pendingDoc=""}return fields}function parseFieldLine(line,description,_interfaces){if(/^[a-zA-Z_$][\w$]*\s*\(/.test(line.trimStart()))return null;const m=/^([a-zA-Z_$][\w$]*)\s*(\??)\s*:\s*([\s\S]+?)\s*[;,]?\s*$/.exec(line);if(!m)return null;const name=m[1],optional=m[2]??"",type=m[3];if(!name||!type)return null;return{name,type:collapseWhitespace(type),required:optional!=="?",description}}function extractDefaults(script){const defaults={},destructRe=/const\s*\{\s*([\s\S]*?)\s*\}\s*=\s*(?:withDefaults\s*\(\s*)?defineProps/g;let m;while((m=destructRe.exec(script))!==null)if(m[1])parseDestructDefaults(m[1],defaults);const withDefaultsIdx=script.indexOf("withDefaults(");if(withDefaultsIdx>=0){const afterDefine=script.indexOf("defineProps",withDefaultsIdx);if(afterDefine>0){const generic=script.indexOf(">",afterDefine),closeParen=script.indexOf(")",generic>=0?generic:afterDefine);if(closeParen>0){const commaIdx=script.indexOf(",",closeParen),objStart=commaIdx>=0?script.indexOf("{",commaIdx):-1;if(objStart>0){const body=sliceBalanced(script,objStart,"{","}");if(body)parseObjectDefaults(body,defaults)}}}}return defaults}function parseDestructDefaults(destructBody,out){for(const part of splitTopLevel(destructBody,[","])){const m=/^\s*([a-zA-Z_$][\w$]*)\s*=\s*([\s\S]+?)\s*$/.exec(part),key=m?.[1],value=m?.[2];if(key&&value)out[key]=collapseWhitespace(value)}}function parseObjectDefaults(objectBody,out){for(const part of splitTopLevel(objectBody,[","])){const m=/^\s*([a-zA-Z_$][\w$]*)\s*:\s*([\s\S]+?)\s*$/.exec(part.trim()),key=m?.[1],value=m?.[2];if(key&&value)out[key]=collapseWhitespace(value)}}function extractEvents(script){const m=/defineEmits\s*<\s*\{([\s\S]*?)\}\s*>\s*\(/.exec(script);if(!m?.[1])return[];const events=[];for(const part of splitTopLevel(m[1],[";",`
|
|
5
|
+
`])){const trimmed=part.trim();if(!trimmed)continue;const tuple=/^['"]?([\w-]+)['"]?\s*:\s*\[(.*?)\]\s*$/.exec(trimmed);if(tuple){const name=tuple[1];if(!name)continue;events.push({name,type:tuple[2]?.trim()||"void",description:""});continue}const fn=/^([a-zA-Z_$][\w$]*)\s*\(([\s\S]*?)\)\s*:\s*([\s\S]+)$/.exec(trimmed);if(fn){const name=fn[1];if(!name)continue;events.push({name,type:fn[2]?.trim()||"void",description:""})}}return events}function extractSlots(template){const slots=[],seen=new Set,slotRe=/<slot\b([^>]*)>/g;let m;while((m=slotRe.exec(template))!==null){const attrs=m[1]??"",name=/\bname\s*=\s*["']([^"']+)["']/.exec(attrs)?.[1]??"default";if(seen.has(name))continue;seen.add(name);slots.push({name,description:""})}return slots}function sliceBalanced(source,openIdx,open,close){if(source[openIdx]!==open)return null;let depth=0,i=openIdx,inString=null;while(i<source.length){const ch=source[i];if(ch===void 0)break;if(inString){if(ch==="\\"){i+=2;continue}if(ch===inString)inString=null;i++;continue}if(ch==='"'||ch==="'"||ch==="`"){inString=ch;i++;continue}if(ch===open)depth++;else if(ch===close){depth--;if(depth===0)return source.slice(openIdx+1,i)}i++}return null}function splitTopLevel(source,separators){const out=[],sepSet=new Set(separators);let depth=0,inString=null,start=0;for(let i=0;i<source.length;i++){const ch=source[i];if(ch===void 0)break;if(inString){if(ch==="\\"){i++;continue}if(ch===inString)inString=null;continue}if(ch==='"'||ch==="'"||ch==="`"){inString=ch;continue}if(ch==="{"||ch==="["||ch==="("||ch==="<")depth++;else if(ch==="}"||ch==="]"||ch===")"||ch===">")depth--;else if(depth===0&&sepSet.has(ch)){out.push(source.slice(start,i));start=i+1}}out.push(source.slice(start));return out}function collapseWhitespace(s){return s.replace(/\s+/g," ").trim()}
|
package/dist/helpers/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export*from"./utils";
|
|
@@ -1,73 +1,3 @@
|
|
|
1
|
-
import process from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { componentsPath, functionsPath, libraryEntryPath } from "@stacksjs/path";
|
|
5
|
-
import { writeTextFile } from "@stacksjs/storage";
|
|
6
|
-
import { kebabCase } from "@stacksjs/strings";
|
|
7
|
-
import { ExitCode } from "@stacksjs/types";
|
|
8
|
-
import { determineResetPreset } from "@stacksjs/utils";
|
|
9
|
-
export async function generateLibEntry(type) {
|
|
10
|
-
await createLibraryEntryPoint(type);
|
|
11
|
-
}
|
|
12
|
-
export async function createLibraryEntryPoint(type) {
|
|
13
|
-
if (type === "web-components")
|
|
14
|
-
await createWebComponentLibraryEntryPoint();
|
|
15
|
-
if (type === "functions")
|
|
16
|
-
await createFunctionLibraryEntryPoint();
|
|
17
|
-
}
|
|
18
|
-
export async function createWebComponentLibraryEntryPoint(type = "web-components") {
|
|
19
|
-
log.info("Ensuring Web Component Library Entry Point...");
|
|
20
|
-
await writeTextFile({
|
|
21
|
-
path: libraryEntryPath(type),
|
|
22
|
-
data: generateEntryPointData(type)
|
|
23
|
-
}).catch((err) => {
|
|
24
|
-
log.error("There was an error generating the Web Component library entry point", err);
|
|
25
|
-
process.exit(ExitCode.FatalError);
|
|
26
|
-
});
|
|
27
|
-
log.success("Created Web Component Library Entry Point");
|
|
28
|
-
}
|
|
29
|
-
export async function createFunctionLibraryEntryPoint(type = "functions") {
|
|
30
|
-
log.info("Ensuring Function Library Entry Point...");
|
|
31
|
-
await writeTextFile({
|
|
32
|
-
path: libraryEntryPath(type),
|
|
33
|
-
data: generateEntryPointData(type)
|
|
34
|
-
}).catch((err) => {
|
|
35
|
-
log.error("There was an error generating Function Library Entry Point", err);
|
|
36
|
-
process.exit(ExitCode.FatalError);
|
|
37
|
-
});
|
|
38
|
-
log.success("Created Functions Library Entry Point");
|
|
39
|
-
}
|
|
40
|
-
export function generateEntryPointData(type) {
|
|
41
|
-
let arr = [];
|
|
42
|
-
if (type === "functions") {
|
|
43
|
-
if (!library.functions?.files) {
|
|
44
|
-
log.error(Error("There are no functions defined to be built. Please check your config/library.ts file for potential adjustments"));
|
|
45
|
-
process.exit(ExitCode.FatalError);
|
|
46
|
-
}
|
|
47
|
-
for (const fx of library.functions.files)
|
|
48
|
-
if (Array.isArray(fx))
|
|
49
|
-
arr.push(`export * as ${fx[1]} from '${functionsPath(fx[0])}'`);
|
|
50
|
-
else
|
|
51
|
-
arr.push(`export * from '${functionsPath(fx)}'`);
|
|
52
|
-
return arr.join(`\r
|
|
53
|
-
`);
|
|
54
|
-
}
|
|
55
|
-
arr = determineResetPreset();
|
|
56
|
-
const imports = [...arr, "import { defineCustomElement } from '@stacksjs/stx'"], declarations = [], definitions = [];
|
|
57
|
-
if (!library.webComponents?.tags) {
|
|
58
|
-
log.error(Error("There are no components defined to be built. Please check your config/library.ts file for potential adjustments"));
|
|
59
|
-
process.exit(ExitCode.FatalError);
|
|
60
|
-
}
|
|
61
|
-
for (const component of library.webComponents.tags.map((tag) => tag.name))
|
|
62
|
-
if (Array.isArray(component)) {
|
|
63
|
-
imports.push(`import ${component[1]} from '${componentsPath(component[0])}.stx'`);
|
|
64
|
-
declarations.push(`const ${component[1]}CustomElement = defineCustomElement(${component[1]})`);
|
|
65
|
-
definitions.push(`customElements.define('${kebabCase(component[1])}', ${component[1]}CustomElement)`);
|
|
66
|
-
} else {
|
|
67
|
-
imports.push(`import ${component} from '${componentsPath(component)}.stx'`);
|
|
68
|
-
declarations.push(`const ${component}CustomElement = defineCustomElement(${component})`);
|
|
69
|
-
definitions.push(`customElements.define('${kebabCase(component)}', ${component}CustomElement)`);
|
|
70
|
-
}
|
|
71
|
-
return [...imports, ...declarations, ...definitions].join(`\r
|
|
72
|
-
`);
|
|
73
|
-
}
|
|
1
|
+
import process from"node:process";import{library}from"@stacksjs/config";import{log}from"@stacksjs/logging";import{componentsPath,functionsPath,libraryEntryPath}from"@stacksjs/path";import{writeTextFile}from"@stacksjs/storage";import{kebabCase}from"@stacksjs/strings";import{ExitCode}from"@stacksjs/types";import{determineResetPreset}from"@stacksjs/utils";export async function generateLibEntry(type){await createLibraryEntryPoint(type)}export async function createLibraryEntryPoint(type){if(type==="web-components")await createWebComponentLibraryEntryPoint();if(type==="functions")await createFunctionLibraryEntryPoint()}export async function createWebComponentLibraryEntryPoint(type="web-components"){log.info("Ensuring Web Component Library Entry Point...");await writeTextFile({path:libraryEntryPath(type),data:generateEntryPointData(type)}).catch((err)=>{log.error("There was an error generating the Web Component library entry point",err);process.exit(ExitCode.FatalError)});log.success("Created Web Component Library Entry Point")}export async function createFunctionLibraryEntryPoint(type="functions"){log.info("Ensuring Function Library Entry Point...");await writeTextFile({path:libraryEntryPath(type),data:generateEntryPointData(type)}).catch((err)=>{log.error("There was an error generating Function Library Entry Point",err);process.exit(ExitCode.FatalError)});log.success("Created Functions Library Entry Point")}export function generateEntryPointData(type){let arr=[];if(type==="functions"){if(!library.functions?.files){log.error(Error("There are no functions defined to be built. Please check your config/library.ts file for potential adjustments"));process.exit(ExitCode.FatalError)}for(const fx of library.functions.files)if(Array.isArray(fx))arr.push(`export * as ${fx[1]} from '${functionsPath(fx[0])}'`);else arr.push(`export * from '${functionsPath(fx)}'`);return arr.join(`\r
|
|
2
|
+
`)}arr=determineResetPreset();const imports=[...arr,"import { defineCustomElement } from '@stacksjs/stx'"],declarations=[],definitions=[];if(!library.webComponents?.tags){log.error(Error("There are no components defined to be built. Please check your config/library.ts file for potential adjustments"));process.exit(ExitCode.FatalError)}for(const component of library.webComponents.tags.map((tag)=>tag.name))if(Array.isArray(component)){imports.push(`import ${component[1]} from '${componentsPath(component[0])}.stx'`);declarations.push(`const ${component[1]}CustomElement = defineCustomElement(${component[1]})`);definitions.push(`customElements.define('${kebabCase(component[1])}', ${component[1]}CustomElement)`)}else{imports.push(`import ${component} from '${componentsPath(component)}.stx'`);declarations.push(`const ${component}CustomElement = defineCustomElement(${component})`);definitions.push(`customElements.define('${kebabCase(component)}', ${component}CustomElement)`)}return[...imports,...declarations,...definitions].join(`\r
|
|
3
|
+
`)}
|
|
@@ -1,26 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { log } from "@stacksjs/logging";
|
|
3
|
-
import { packageJsonPath } from "@stacksjs/path";
|
|
4
|
-
import { writeTextFile } from "@stacksjs/storage";
|
|
5
|
-
export async function generatePackageJson(type) {
|
|
6
|
-
let name, description, directory, keywords, config, prettyName;
|
|
7
|
-
if (type === "web-components") {
|
|
8
|
-
name = library.webComponents?.name;
|
|
9
|
-
description = library.webComponents?.description;
|
|
10
|
-
directory = "components";
|
|
11
|
-
keywords = library.webComponents?.keywords;
|
|
12
|
-
config = "web-components";
|
|
13
|
-
} else if (type === "functions") {
|
|
14
|
-
name = library.functions?.name;
|
|
15
|
-
description = library.functions?.description;
|
|
16
|
-
directory = "functions";
|
|
17
|
-
keywords = library.functions?.keywords;
|
|
18
|
-
config = "functions";
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
await writeTextFile({
|
|
22
|
-
path: packageJsonPath(type),
|
|
23
|
-
data: `{
|
|
1
|
+
import{library}from"@stacksjs/config";import{log}from"@stacksjs/logging";import{packageJsonPath}from"@stacksjs/path";import{writeTextFile}from"@stacksjs/storage";export async function generatePackageJson(type){let name,description,directory,keywords,config,prettyName;if(type==="web-components"){name=library.webComponents?.name;description=library.webComponents?.description;directory="components";keywords=library.webComponents?.keywords;config="web-components"}else if(type==="functions"){name=library.functions?.name;description=library.functions?.description;directory="functions";keywords=library.functions?.keywords;config="functions"}try{await writeTextFile({path:packageJsonPath(type),data:`{
|
|
24
2
|
"name": "${name}",
|
|
25
3
|
"type": "module",
|
|
26
4
|
"version": "",
|
|
@@ -61,14 +39,4 @@ export async function generatePackageJson(type) {
|
|
|
61
39
|
"stacks": "workspace:*"
|
|
62
40
|
}
|
|
63
41
|
}
|
|
64
|
-
`
|
|
65
|
-
});
|
|
66
|
-
if (type === "web-components")
|
|
67
|
-
prettyName = "Web Component library";
|
|
68
|
-
else if (type === "functions")
|
|
69
|
-
prettyName = "Function Library";
|
|
70
|
-
log.success(`Created ${prettyName} package.json file`);
|
|
71
|
-
} catch (err) {
|
|
72
|
-
log.error(`There was an error creating the ${prettyName} package.json`, err);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
42
|
+
`});if(type==="web-components")prettyName="Web Component library";else if(type==="functions")prettyName="Function Library";log.success(`Created ${prettyName} package.json file`)}catch(err){log.error(`There was an error creating the ${prettyName} package.json`,err)}}
|
package/dist/helpers/utils.js
CHANGED
|
@@ -1,130 +1 @@
|
|
|
1
|
-
var {require}=import.meta;import { existsSync }
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import process from "node:process";
|
|
5
|
-
import { buddyOptions, runCommand } from "@stacksjs/cli";
|
|
6
|
-
import { err } from "@stacksjs/error-handling";
|
|
7
|
-
import { log } from "@stacksjs/logging";
|
|
8
|
-
import * as p from "@stacksjs/path";
|
|
9
|
-
export function publishedActionCandidates(action, packageRoot) {
|
|
10
|
-
let root = packageRoot;
|
|
11
|
-
if (!root)
|
|
12
|
-
try {
|
|
13
|
-
const pkgUrl = import.meta.resolve("@stacksjs/actions/package.json");
|
|
14
|
-
if (pkgUrl) {
|
|
15
|
-
const pkgPath = new URL(pkgUrl).pathname;
|
|
16
|
-
root = pkgPath.slice(0, pkgPath.lastIndexOf("/"));
|
|
17
|
-
}
|
|
18
|
-
} catch {
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
if (!root)
|
|
22
|
-
return [];
|
|
23
|
-
return [
|
|
24
|
-
`${root}/dist/${action}.js`,
|
|
25
|
-
`${root}/dist/src/${action}.js`,
|
|
26
|
-
`${root}/src/${action}.ts`
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
export function developmentConditionForProject(projectRoot) {
|
|
30
|
-
return existsSync(join(projectRoot, "storage/framework/core")) && existsSync(join(projectRoot, "node_modules/@stacksjs/env/src/index.ts")) ? "--conditions development" : "";
|
|
31
|
-
}
|
|
32
|
-
async function resolveActionFile(action, projectRoot) {
|
|
33
|
-
const candidates = [];
|
|
34
|
-
if (projectRoot)
|
|
35
|
-
candidates.push(join(projectRoot, `storage/framework/core/actions/src/${action}.ts`));
|
|
36
|
-
candidates.push(p.actionsPath(`src/${action}.ts`));
|
|
37
|
-
candidates.push(...publishedActionCandidates(action));
|
|
38
|
-
for (const candidate of candidates)
|
|
39
|
-
if (await Bun.file(candidate).exists())
|
|
40
|
-
return candidate;
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
export async function runAction(action, options) {
|
|
44
|
-
log.debug(`[action] Running: ${action}`);
|
|
45
|
-
if (action === "dev/views")
|
|
46
|
-
try {
|
|
47
|
-
const pantryPath = p.projectPath("pantry");
|
|
48
|
-
if (!process.env.NODE_PATH?.includes(pantryPath)) {
|
|
49
|
-
process.env.NODE_PATH = process.env.NODE_PATH ? `${pantryPath}:${process.env.NODE_PATH}` : pantryPath;
|
|
50
|
-
require("module").Module._initPaths?.();
|
|
51
|
-
}
|
|
52
|
-
const viewsEntries = [
|
|
53
|
-
p.projectPath("storage/framework/core/actions/src/dev/views.ts"),
|
|
54
|
-
p.frameworkPath("actions/src/dev/views.ts"),
|
|
55
|
-
...publishedActionCandidates("dev/views")
|
|
56
|
-
];
|
|
57
|
-
for (const entry of viewsEntries)
|
|
58
|
-
if (existsSync(entry)) {
|
|
59
|
-
await import(entry);
|
|
60
|
-
return { ok: !0, value: {} };
|
|
61
|
-
}
|
|
62
|
-
return err("dev/views entry not found");
|
|
63
|
-
} catch (error) {
|
|
64
|
-
return err(`Failed to start dev server: ${error}`);
|
|
65
|
-
}
|
|
66
|
-
const isLikelyCoreAction = action.includes("/") || ["dev", "build", "install", "upgrade", "migrate"].some((prefix) => action.startsWith(prefix)), userActionsBase = options?.cwd ? join(String(options.cwd), "app/Actions") : p.userActionsPath();
|
|
67
|
-
if (!isLikelyCoreAction && existsSync(userActionsBase)) {
|
|
68
|
-
const glob = new Bun.Glob("**/*.{ts,js}"), scanOptions = { cwd: userActionsBase, onlyFiles: !0, absolute: !0 }, matchingFiles = [], basePath = userActionsBase;
|
|
69
|
-
for await (const file of glob.scan(scanOptions)) {
|
|
70
|
-
if (file.replace(`${basePath}/`, "").replace(/\.(ts|js)$/, "") === action || file.endsWith(`${action}.ts`) || file.endsWith(`${action}.js`)) {
|
|
71
|
-
log.debug(`[action] Resolved: ${action} \u2192 ${file}`);
|
|
72
|
-
return await (await import(file)).default.handle(void 0);
|
|
73
|
-
}
|
|
74
|
-
matchingFiles.push(file);
|
|
75
|
-
}
|
|
76
|
-
for (const file of matchingFiles)
|
|
77
|
-
try {
|
|
78
|
-
const a = await import(file);
|
|
79
|
-
if (a.name === action) {
|
|
80
|
-
log.debug(`[action] Resolved: ${action} \u2192 ${file}`);
|
|
81
|
-
return await a.handle();
|
|
82
|
-
}
|
|
83
|
-
} catch (error) {}
|
|
84
|
-
}
|
|
85
|
-
const path = await resolveActionFile(action, options?.cwd ? String(options.cwd) : void 0);
|
|
86
|
-
if (!path)
|
|
87
|
-
return err(`Action '${action}' not found in storage/framework/core/actions/src or @stacksjs/actions`);
|
|
88
|
-
log.debug(`[action] Resolved: ${action} \u2192 ${path}`);
|
|
89
|
-
const isDevAction = action.startsWith("dev/"), watchFlag = isDevAction ? "--watch" : "", developmentCondition = developmentConditionForProject(p.projectPath()), opts = isDevAction ? "" : buddyOptions(options) || "", cmd = ["bun", developmentCondition, watchFlag, path, opts].filter(Boolean).join(" "), pantryNodePath = p.projectPath("pantry"), existingNodePath = process.env.NODE_PATH, nodePath = existingNodePath ? `${pantryNodePath}:${existingNodePath}` : pantryNodePath, shouldInherit = options?.verbose || isDevAction && !options?.quiet, optionsWithCwd = {
|
|
90
|
-
cwd: options?.cwd || p.projectPath(),
|
|
91
|
-
...options,
|
|
92
|
-
stdout: shouldInherit ? "inherit" : void 0,
|
|
93
|
-
stderr: shouldInherit ? "inherit" : void 0,
|
|
94
|
-
env: { ...options?.env, NODE_PATH: nodePath, ...isDevAction ? { STACKS_DEV_SERVER: "1" } : {} }
|
|
95
|
-
}, result = await runCommand(cmd, optionsWithCwd);
|
|
96
|
-
log.debug(`[action] Completed: ${action}`);
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
export async function runActions(actions, options) {
|
|
100
|
-
if (!actions.length)
|
|
101
|
-
return err("No actions were specified");
|
|
102
|
-
for (const action of actions)
|
|
103
|
-
if (!hasAction(action))
|
|
104
|
-
return err(`The specified action "${action}" does not exist`);
|
|
105
|
-
return await runActionSequence(actions, options);
|
|
106
|
-
}
|
|
107
|
-
export async function runActionSequence(actions, options, runner = runAction) {
|
|
108
|
-
let result;
|
|
109
|
-
for (const action of actions) {
|
|
110
|
-
result = await runner(action, options);
|
|
111
|
-
if (result?.isErr)
|
|
112
|
-
return result;
|
|
113
|
-
}
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
export function hasAction(action) {
|
|
117
|
-
const userActionPatterns = [
|
|
118
|
-
`${action}.ts`,
|
|
119
|
-
`${action}`,
|
|
120
|
-
`Dashboard/${action}.ts`,
|
|
121
|
-
`Dashboard/${action}`,
|
|
122
|
-
`Buddy/${action}.ts`,
|
|
123
|
-
`Buddy/${action}`
|
|
124
|
-
], actionPatterns = [`src/${action}.ts`, `src/${action}`, `${action}.ts`, `${action}`];
|
|
125
|
-
return [
|
|
126
|
-
...userActionPatterns.map((pattern) => p.userActionsPath(pattern)),
|
|
127
|
-
...actionPatterns.map((pattern) => p.actionsPath(pattern)),
|
|
128
|
-
...publishedActionCandidates(action)
|
|
129
|
-
].some((candidate) => existsSync(candidate));
|
|
130
|
-
}
|
|
1
|
+
var {require}=import.meta;import{existsSync}from"node:fs";import{homedir}from"node:os";import{join}from"node:path";import process from"node:process";import{buddyOptions,runCommand}from"@stacksjs/cli";import{err}from"@stacksjs/error-handling";import{log}from"@stacksjs/logging";import*as p from"@stacksjs/path";export function publishedActionCandidates(action,packageRoot){let root=packageRoot;if(!root)try{const pkgUrl=import.meta.resolve("@stacksjs/actions/package.json");if(pkgUrl){const pkgPath=new URL(pkgUrl).pathname;root=pkgPath.slice(0,pkgPath.lastIndexOf("/"))}}catch{return[]}if(!root)return[];return[`${root}/dist/${action}.js`,`${root}/dist/src/${action}.js`,`${root}/src/${action}.ts`]}export function developmentConditionForProject(projectRoot){return existsSync(join(projectRoot,"storage/framework/core"))&&existsSync(join(projectRoot,"node_modules/@stacksjs/env/src/index.ts"))?"--conditions development":""}async function resolveActionFile(action,projectRoot){const candidates=[];if(projectRoot)candidates.push(join(projectRoot,`storage/framework/core/actions/src/${action}.ts`));candidates.push(p.actionsPath(`src/${action}.ts`));candidates.push(...publishedActionCandidates(action));for(const candidate of candidates)if(await Bun.file(candidate).exists())return candidate;return null}export async function runAction(action,options){log.debug(`[action] Running: ${action}`);if(action==="dev/views")try{const pantryPath=p.projectPath("pantry");if(!process.env.NODE_PATH?.includes(pantryPath)){process.env.NODE_PATH=process.env.NODE_PATH?`${pantryPath}:${process.env.NODE_PATH}`:pantryPath;require("module").Module._initPaths?.()}const viewsEntries=[p.projectPath("storage/framework/core/actions/src/dev/views.ts"),p.frameworkPath("actions/src/dev/views.ts"),...publishedActionCandidates("dev/views")];for(const entry of viewsEntries)if(existsSync(entry)){await import(entry);return{ok:!0,value:{}}}return err("dev/views entry not found")}catch(error){return err(`Failed to start dev server: ${error}`)}const isLikelyCoreAction=action.includes("/")||["dev","build","install","upgrade","migrate"].some((prefix)=>action.startsWith(prefix)),userActionsBase=options?.cwd?join(String(options.cwd),"app/Actions"):p.userActionsPath();if(!isLikelyCoreAction&&existsSync(userActionsBase)){const glob=new Bun.Glob("**/*.{ts,js}"),scanOptions={cwd:userActionsBase,onlyFiles:!0,absolute:!0},matchingFiles=[],basePath=userActionsBase;for await(const file of glob.scan(scanOptions)){if(file.replace(`${basePath}/`,"").replace(/\.(ts|js)$/,"")===action||file.endsWith(`${action}.ts`)||file.endsWith(`${action}.js`)){log.debug(`[action] Resolved: ${action} \u2192 ${file}`);return await(await import(file)).default.handle(void 0)}matchingFiles.push(file)}for(const file of matchingFiles)try{const a=await import(file);if(a.name===action){log.debug(`[action] Resolved: ${action} \u2192 ${file}`);return await a.handle()}}catch(error){}}const path=await resolveActionFile(action,options?.cwd?String(options.cwd):void 0);if(!path)return err(`Action '${action}' not found in storage/framework/core/actions/src or @stacksjs/actions`);log.debug(`[action] Resolved: ${action} \u2192 ${path}`);const isDevAction=action.startsWith("dev/"),watchFlag=isDevAction?"--watch":"",developmentCondition=developmentConditionForProject(p.projectPath()),opts=isDevAction?"":buddyOptions(options)||"",cmd=["bun",developmentCondition,watchFlag,path,opts].filter(Boolean).join(" "),pantryNodePath=p.projectPath("pantry"),existingNodePath=process.env.NODE_PATH,nodePath=existingNodePath?`${pantryNodePath}:${existingNodePath}`:pantryNodePath,shouldInherit=options?.verbose||isDevAction&&!options?.quiet,optionsWithCwd={cwd:options?.cwd||p.projectPath(),...options,stdout:shouldInherit?"inherit":void 0,stderr:shouldInherit?"inherit":void 0,env:{...options?.env,NODE_PATH:nodePath,...isDevAction?{STACKS_DEV_SERVER:"1"}:{}}},result=await runCommand(cmd,optionsWithCwd);log.debug(`[action] Completed: ${action}`);return result}export async function runActions(actions,options){if(!actions.length)return err("No actions were specified");for(const action of actions)if(!hasAction(action))return err(`The specified action "${action}" does not exist`);return await runActionSequence(actions,options)}export async function runActionSequence(actions,options,runner=runAction){let result;for(const action of actions){result=await runner(action,options);if(result?.isErr)return result}return result}export function hasAction(action){const userActionPatterns=[`${action}.ts`,`${action}`,`Dashboard/${action}.ts`,`Dashboard/${action}`,`Buddy/${action}.ts`,`Buddy/${action}`],actionPatterns=[`src/${action}.ts`,`src/${action}`,`${action}.ts`,`${action}`];return[...userActionPatterns.map((pattern)=>p.userActionsPath(pattern)),...actionPatterns.map((pattern)=>p.actionsPath(pattern)),...publishedActionCandidates(action)].some((candidate)=>existsSync(candidate))}
|
|
@@ -1,60 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { err, ok } from "@stacksjs/error-handling";
|
|
3
|
-
import { log } from "@stacksjs/logging";
|
|
4
|
-
import { customElementsDataPath, frameworkPath } from "@stacksjs/path";
|
|
5
|
-
import { writeTextFile } from "@stacksjs/storage";
|
|
6
|
-
function generateComponentInfoData() {
|
|
7
|
-
return `{
|
|
1
|
+
import{library}from"@stacksjs/config";import{err,ok}from"@stacksjs/error-handling";import{log}from"@stacksjs/logging";import{customElementsDataPath,frameworkPath}from"@stacksjs/path";import{writeTextFile}from"@stacksjs/storage";function generateComponentInfoData(){return`{
|
|
8
2
|
"version": 1.1,
|
|
9
3
|
"tags": ${JSON.stringify(library.webComponents?.tags)}
|
|
10
4
|
}
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
export async function generateVsCodeCustomData() {
|
|
14
|
-
try {
|
|
15
|
-
log.info("Generating custom-elements.json...");
|
|
16
|
-
await writeTextFile({
|
|
17
|
-
path: customElementsDataPath(),
|
|
18
|
-
data: generateComponentInfoData()
|
|
19
|
-
});
|
|
20
|
-
log.success("Generated custom-elements.json for IDEs.");
|
|
21
|
-
return ok(void 0);
|
|
22
|
-
} catch (e) {
|
|
23
|
-
log.error("There was an error generating the custom-elements.json file.", e);
|
|
24
|
-
return err("There was an error generating the custom-elements.json file.");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export async function generateWebTypes() {
|
|
28
|
-
log.info("Generating web-types.json...");
|
|
29
|
-
await writeTextFile({
|
|
30
|
-
path: frameworkPath("core/web-types.json"),
|
|
31
|
-
data: generateWebTypesData()
|
|
32
|
-
});
|
|
33
|
-
log.success("Generated web-types.json for IDEs.");
|
|
34
|
-
}
|
|
35
|
-
export function generateWebTypesData() {
|
|
36
|
-
const tags = (library.webComponents?.tags ?? []).map((tag) => {
|
|
37
|
-
const sourceName = Array.isArray(tag.name) ? tag.name[0] : tag.name;
|
|
38
|
-
return {
|
|
39
|
-
name: Array.isArray(tag.name) ? tag.name[1] : tag.name,
|
|
40
|
-
description: tag.description ?? "",
|
|
41
|
-
attributes: tag.attributes ?? [],
|
|
42
|
-
source: {
|
|
43
|
-
module: `../../defaults/resources/components/${sourceName}.stx`,
|
|
44
|
-
symbol: "default"
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
return `${JSON.stringify({
|
|
49
|
-
framework: "stx",
|
|
50
|
-
name: library.name,
|
|
51
|
-
contributions: {
|
|
52
|
-
html: {
|
|
53
|
-
"description-markup": "markdown",
|
|
54
|
-
"types-syntax": "typescript",
|
|
55
|
-
tags
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}, null, 2)}
|
|
59
|
-
`;
|
|
60
|
-
}
|
|
5
|
+
`}export async function generateVsCodeCustomData(){try{log.info("Generating custom-elements.json...");await writeTextFile({path:customElementsDataPath(),data:generateComponentInfoData()});log.success("Generated custom-elements.json for IDEs.");return ok(void 0)}catch(e){log.error("There was an error generating the custom-elements.json file.",e);return err("There was an error generating the custom-elements.json file.")}}export async function generateWebTypes(){log.info("Generating web-types.json...");await writeTextFile({path:frameworkPath("core/web-types.json"),data:generateWebTypesData()});log.success("Generated web-types.json for IDEs.")}export function generateWebTypesData(){const tags=(library.webComponents?.tags??[]).map((tag)=>{const sourceName=Array.isArray(tag.name)?tag.name[0]:tag.name;return{name:Array.isArray(tag.name)?tag.name[1]:tag.name,description:tag.description??"",attributes:tag.attributes??[],source:{module:`../../defaults/resources/components/${sourceName}.stx`,symbol:"default"}}});return`${JSON.stringify({framework:"stx",name:library.name,contributions:{html:{"description-markup":"markdown","types-syntax":"typescript",tags}}},null,2)}
|
|
6
|
+
`}
|