@stacksjs/stx 0.0.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/README.md +800 -0
- package/dist/auth.d.ts +1 -0
- package/dist/bin/cli.js +633 -0
- package/dist/caching.d.ts +11 -0
- package/dist/chunk-04bqmpzb.js +7069 -0
- package/dist/chunk-0xkkmb8j.js +2502 -0
- package/dist/chunk-ywm063e4.js +20 -0
- package/dist/chunk-zhs1t2p5.js +4279 -0
- package/dist/client.d.ts +36 -0
- package/dist/client.js +90 -0
- package/dist/conditionals.d.ts +4 -0
- package/dist/config.d.ts +4 -0
- package/dist/custom-directives.d.ts +6 -0
- package/dist/docs.d.ts +20 -0
- package/dist/expressions.d.ts +9 -0
- package/dist/forms.d.ts +31 -0
- package/dist/i18n.d.ts +22 -0
- package/dist/includes.d.ts +21 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +14143 -0
- package/dist/loops.d.ts +3 -0
- package/dist/markdown.d.ts +2 -0
- package/dist/middleware.d.ts +5 -0
- package/dist/process.d.ts +11 -0
- package/dist/src/index.js +397 -0
- package/dist/streaming.d.ts +14 -0
- package/dist/types.d.ts +149 -0
- package/dist/utils.d.ts +9 -0
- package/dist/web-components.d.ts +16 -0
- package/package.json +74 -0
package/dist/loops.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function processMarkdownDirectives(template: string, context: Record<string, any>, filePath?: string): Promise<string>;
|
|
2
|
+
export declare function markdownDirectiveHandler(content: string, params: string[], _context: Record<string, any>, _filePath: string): Promise<string>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { StxOptions } from './types';
|
|
2
|
+
|
|
3
|
+
export declare function processMiddleware(template: string, context: Record<string, any>, filePath: string, options: StxOptions, timing: 'before' | 'after'): Promise<string>;
|
|
4
|
+
export declare function runPreProcessingMiddleware(template: string, context: Record<string, any>, filePath: string, options: StxOptions): Promise<string>;
|
|
5
|
+
export declare function runPostProcessingMiddleware(template: string, context: Record<string, any>, filePath: string, options: StxOptions): Promise<string>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { StxOptions } from './types';
|
|
2
|
+
|
|
3
|
+
export declare function processDirectives(template: string, context: Record<string, any>, filePath: string, options: StxOptions, dependencies: Set<string>): Promise<string>;
|
|
4
|
+
declare function processOtherDirectives(template: string, context: Record<string, any>, filePath: string, options: StxOptions, dependencies: Set<string>): Promise<string>;
|
|
5
|
+
declare function processComponentDirectives(template: string, context: Record<string, any>, filePath: string, componentsDir: string, options: StxOptions, dependencies: Set<string>): Promise<string>;
|
|
6
|
+
declare let props: {};
|
|
7
|
+
declare const propsFn: unknown;
|
|
8
|
+
declare const processedContent: unknown;
|
|
9
|
+
declare function processCustomElements(template: string, context: Record<string, any>, filePath: string, componentsDir: string, options: StxOptions, dependencies: Set<string>): Promise<string>;
|
|
10
|
+
export declare function processJsonDirective(template: string, context: Record<string, any>): string;
|
|
11
|
+
export declare function processOnceDirective(template: string): string;
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
buildWebComponents,
|
|
4
|
+
config,
|
|
5
|
+
defaultConfig,
|
|
6
|
+
docsCommand,
|
|
7
|
+
extractComponentDescription,
|
|
8
|
+
extractComponentProps,
|
|
9
|
+
findComponentFiles,
|
|
10
|
+
formatDocsAsHtml,
|
|
11
|
+
formatDocsAsJson,
|
|
12
|
+
formatDocsAsMarkdown,
|
|
13
|
+
generateComponentDoc,
|
|
14
|
+
generateComponentsDocs,
|
|
15
|
+
generateDirectivesDocs,
|
|
16
|
+
generateDocs,
|
|
17
|
+
generateTemplatesDocs,
|
|
18
|
+
webComponentDirectiveHandler
|
|
19
|
+
} from "../chunk-0xkkmb8j.js";
|
|
20
|
+
import {
|
|
21
|
+
applyFilters,
|
|
22
|
+
createDetailedErrorMessage,
|
|
23
|
+
createTranslateFilter,
|
|
24
|
+
defaultFilters,
|
|
25
|
+
escapeHtml,
|
|
26
|
+
evaluateAuthExpression,
|
|
27
|
+
evaluateExpression,
|
|
28
|
+
extractVariables,
|
|
29
|
+
fileExists,
|
|
30
|
+
getSourceLineInfo,
|
|
31
|
+
getTranslation,
|
|
32
|
+
loadTranslation,
|
|
33
|
+
markdownDirectiveHandler,
|
|
34
|
+
partialsCache,
|
|
35
|
+
processBasicFormDirectives,
|
|
36
|
+
processCustomDirectives,
|
|
37
|
+
processDirectives,
|
|
38
|
+
processErrorDirective,
|
|
39
|
+
processExpressions,
|
|
40
|
+
processFormDirectives,
|
|
41
|
+
processFormInputDirectives,
|
|
42
|
+
processForms,
|
|
43
|
+
processIncludes,
|
|
44
|
+
processJsonDirective,
|
|
45
|
+
processLoops,
|
|
46
|
+
processMarkdownDirectives,
|
|
47
|
+
processMiddleware,
|
|
48
|
+
processOnceDirective,
|
|
49
|
+
processStackPushDirectives,
|
|
50
|
+
processStackReplacements,
|
|
51
|
+
processTranslateDirective,
|
|
52
|
+
renderComponent,
|
|
53
|
+
resolveTemplatePath,
|
|
54
|
+
runPostProcessingMiddleware,
|
|
55
|
+
runPreProcessingMiddleware,
|
|
56
|
+
setGlobalContext,
|
|
57
|
+
unescapeHtml
|
|
58
|
+
} from "../chunk-zhs1t2p5.js";
|
|
59
|
+
import"../chunk-ywm063e4.js";
|
|
60
|
+
|
|
61
|
+
// ../bun-plugin/src/index.ts
|
|
62
|
+
import path from "path";
|
|
63
|
+
var plugin = {
|
|
64
|
+
name: "bun-plugin-stx",
|
|
65
|
+
async setup(build) {
|
|
66
|
+
const options = {
|
|
67
|
+
...defaultConfig,
|
|
68
|
+
...build.config?.stx
|
|
69
|
+
};
|
|
70
|
+
const allDependencies = new Set;
|
|
71
|
+
const webComponentsPath = options.webComponents?.enabled ? `./${path.relative(path.dirname(build.config?.outdir || "dist"), options.webComponents.outputDir || "dist/web-components")}` : "/web-components";
|
|
72
|
+
const builtComponents = [];
|
|
73
|
+
if (options.webComponents?.enabled) {
|
|
74
|
+
try {
|
|
75
|
+
const components = await buildWebComponents(options, allDependencies);
|
|
76
|
+
builtComponents.push(...components);
|
|
77
|
+
if (options.debug && components.length > 0) {
|
|
78
|
+
console.log(`Successfully built ${components.length} web components`);
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error("Failed to build web components:", error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
build.onLoad({ filter: /\.stx$/ }, async ({ path: filePath }) => {
|
|
85
|
+
try {
|
|
86
|
+
const dependencies = new Set;
|
|
87
|
+
if (options.cache && options.cachePath) {
|
|
88
|
+
const cachedOutput = await checkCache(filePath, options);
|
|
89
|
+
if (cachedOutput) {
|
|
90
|
+
if (options.debug) {
|
|
91
|
+
console.log(`Using cached version of ${filePath}`);
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
contents: cachedOutput,
|
|
95
|
+
loader: "html"
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const content = await Bun.file(filePath).text();
|
|
100
|
+
const scriptMatch = content.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);
|
|
101
|
+
const scriptContent = scriptMatch ? scriptMatch[1] : "";
|
|
102
|
+
const templateContent = content.replace(/<script\b[^>]*>[\s\S]*?<\/script>/i, "");
|
|
103
|
+
const context = {
|
|
104
|
+
__filename: filePath,
|
|
105
|
+
__dirname: path.dirname(filePath),
|
|
106
|
+
__stx: {
|
|
107
|
+
webComponentsPath,
|
|
108
|
+
builtComponents
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
await extractVariables(scriptContent, context, filePath);
|
|
112
|
+
let output = templateContent;
|
|
113
|
+
output = await processDirectives(output, context, filePath, options, dependencies);
|
|
114
|
+
dependencies.forEach((dep) => allDependencies.add(dep));
|
|
115
|
+
if (options.cache && options.cachePath) {
|
|
116
|
+
await cacheTemplate(filePath, output, dependencies, options);
|
|
117
|
+
if (options.debug) {
|
|
118
|
+
console.log(`Cached template ${filePath} with ${dependencies.size} dependencies`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
contents: output,
|
|
123
|
+
loader: "html"
|
|
124
|
+
};
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error("STX Plugin Error:", error);
|
|
127
|
+
return {
|
|
128
|
+
contents: `<!DOCTYPE html><html><body><h1>STX Rendering Error</h1><pre>${error.message || String(error)}</pre></body></html>`,
|
|
129
|
+
loader: "html"
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
// src/caching.ts
|
|
136
|
+
import fs from "fs";
|
|
137
|
+
import path2 from "path";
|
|
138
|
+
var templateCache = new Map;
|
|
139
|
+
async function checkCache(filePath, options) {
|
|
140
|
+
try {
|
|
141
|
+
const cachePath = path2.resolve(options.cachePath);
|
|
142
|
+
const cacheFile = path2.join(cachePath, `${hashFilePath(filePath)}.html`);
|
|
143
|
+
const metaFile = path2.join(cachePath, `${hashFilePath(filePath)}.meta.json`);
|
|
144
|
+
if (!await fileExists(cacheFile) || !await fileExists(metaFile))
|
|
145
|
+
return null;
|
|
146
|
+
const metaContent = await Bun.file(metaFile).text();
|
|
147
|
+
const meta = JSON.parse(metaContent);
|
|
148
|
+
if (meta.cacheVersion !== options.cacheVersion)
|
|
149
|
+
return null;
|
|
150
|
+
const stats = await fs.promises.stat(filePath);
|
|
151
|
+
if (stats.mtime.getTime() > meta.mtime)
|
|
152
|
+
return null;
|
|
153
|
+
for (const dep of meta.dependencies) {
|
|
154
|
+
if (await fileExists(dep)) {
|
|
155
|
+
const depStats = await fs.promises.stat(dep);
|
|
156
|
+
if (depStats.mtime.getTime() > meta.mtime)
|
|
157
|
+
return null;
|
|
158
|
+
} else {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return await Bun.file(cacheFile).text();
|
|
163
|
+
} catch (err) {
|
|
164
|
+
console.warn(`Cache error for ${filePath}:`, err);
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async function cacheTemplate(filePath, output, dependencies, options) {
|
|
169
|
+
try {
|
|
170
|
+
const cachePath = path2.resolve(options.cachePath);
|
|
171
|
+
await fs.promises.mkdir(cachePath, { recursive: true });
|
|
172
|
+
const cacheFile = path2.join(cachePath, `${hashFilePath(filePath)}.html`);
|
|
173
|
+
const metaFile = path2.join(cachePath, `${hashFilePath(filePath)}.meta.json`);
|
|
174
|
+
const stats = await fs.promises.stat(filePath);
|
|
175
|
+
await Bun.write(cacheFile, output);
|
|
176
|
+
const meta = {
|
|
177
|
+
sourcePath: filePath,
|
|
178
|
+
mtime: stats.mtime.getTime(),
|
|
179
|
+
dependencies: Array.from(dependencies),
|
|
180
|
+
cacheVersion: options.cacheVersion,
|
|
181
|
+
generatedAt: Date.now()
|
|
182
|
+
};
|
|
183
|
+
await Bun.write(metaFile, JSON.stringify(meta, null, 2));
|
|
184
|
+
templateCache.set(filePath, {
|
|
185
|
+
output,
|
|
186
|
+
mtime: stats.mtime.getTime(),
|
|
187
|
+
dependencies
|
|
188
|
+
});
|
|
189
|
+
} catch (err) {
|
|
190
|
+
console.warn(`Failed to cache template ${filePath}:`, err);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function hashFilePath(filePath) {
|
|
194
|
+
const hash = new Bun.CryptoHasher("sha1").update(filePath).digest("hex");
|
|
195
|
+
return hash.substring(0, 16);
|
|
196
|
+
}
|
|
197
|
+
// src/streaming.ts
|
|
198
|
+
import path3 from "path";
|
|
199
|
+
var defaultStreamingConfig = {
|
|
200
|
+
enabled: true,
|
|
201
|
+
bufferSize: 1024 * 16,
|
|
202
|
+
strategy: "auto",
|
|
203
|
+
timeout: 30000
|
|
204
|
+
};
|
|
205
|
+
var SECTION_PATTERN = /<!-- @section:([a-zA-Z0-9_-]+) -->([\s\S]*?)<!-- @endsection:\1 -->/g;
|
|
206
|
+
async function streamTemplate(templatePath, data = {}, options = {}) {
|
|
207
|
+
const fullOptions = {
|
|
208
|
+
...defaultConfig,
|
|
209
|
+
...options,
|
|
210
|
+
streaming: {
|
|
211
|
+
...defaultStreamingConfig,
|
|
212
|
+
...options.streaming
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
return new ReadableStream({
|
|
216
|
+
async start(controller) {
|
|
217
|
+
try {
|
|
218
|
+
const content = await Bun.file(templatePath).text();
|
|
219
|
+
const scriptMatch = content.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);
|
|
220
|
+
const scriptContent = scriptMatch ? scriptMatch[1] : "";
|
|
221
|
+
const templateContent = content.replace(/<script\b[^>]*>[\s\S]*?<\/script>/i, "");
|
|
222
|
+
const context = {
|
|
223
|
+
...data,
|
|
224
|
+
__filename: templatePath,
|
|
225
|
+
__dirname: path3.dirname(templatePath)
|
|
226
|
+
};
|
|
227
|
+
await extractVariables(scriptContent, context, templatePath);
|
|
228
|
+
const dependencies = new Set;
|
|
229
|
+
const output = await processDirectives(templateContent, context, templatePath, fullOptions, dependencies);
|
|
230
|
+
controller.enqueue(output);
|
|
231
|
+
controller.close();
|
|
232
|
+
} catch (error) {
|
|
233
|
+
controller.error(error);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
async function createStreamRenderer(templatePath, options = {}) {
|
|
239
|
+
const fullOptions = {
|
|
240
|
+
...defaultConfig,
|
|
241
|
+
...options,
|
|
242
|
+
streaming: {
|
|
243
|
+
...defaultStreamingConfig,
|
|
244
|
+
...options.streaming
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
let content = await Bun.file(templatePath).text();
|
|
248
|
+
const scriptMatch = content.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);
|
|
249
|
+
const scriptContent = scriptMatch ? scriptMatch[1] : "";
|
|
250
|
+
const templateContent = content.replace(/<script\b[^>]*>[\s\S]*?<\/script>/i, "");
|
|
251
|
+
const originalTemplate = templateContent;
|
|
252
|
+
const sections = {};
|
|
253
|
+
let match;
|
|
254
|
+
SECTION_PATTERN.lastIndex = 0;
|
|
255
|
+
while ((match = SECTION_PATTERN.exec(templateContent)) !== null) {
|
|
256
|
+
const sectionName = match[1];
|
|
257
|
+
const sectionContent = match[2];
|
|
258
|
+
sections[sectionName] = sectionContent;
|
|
259
|
+
}
|
|
260
|
+
let shellTemplate = templateContent.replace(SECTION_PATTERN, "");
|
|
261
|
+
const renderer = {
|
|
262
|
+
renderShell: async (data = {}) => {
|
|
263
|
+
const context = {
|
|
264
|
+
...data,
|
|
265
|
+
__filename: templatePath,
|
|
266
|
+
__dirname: path3.dirname(templatePath)
|
|
267
|
+
};
|
|
268
|
+
await extractVariables(scriptContent, context, templatePath);
|
|
269
|
+
const dependencies = new Set;
|
|
270
|
+
return processDirectives(shellTemplate, context, templatePath, fullOptions, dependencies);
|
|
271
|
+
},
|
|
272
|
+
renderSection: async (sectionName, data = {}) => {
|
|
273
|
+
try {
|
|
274
|
+
if (!sections[sectionName]) {
|
|
275
|
+
return `<div class="error-message">Section "${sectionName}" not found in template "${templatePath}"</div>`;
|
|
276
|
+
}
|
|
277
|
+
const context = {
|
|
278
|
+
...data,
|
|
279
|
+
__filename: templatePath,
|
|
280
|
+
__dirname: path3.dirname(templatePath)
|
|
281
|
+
};
|
|
282
|
+
await extractVariables(scriptContent, context, templatePath);
|
|
283
|
+
const dependencies = new Set;
|
|
284
|
+
return await processDirectives(sections[sectionName], context, templatePath, fullOptions, dependencies);
|
|
285
|
+
} catch (error) {
|
|
286
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
287
|
+
return createDetailedErrorMessage("Expression", errorMessage, templatePath, sections[sectionName] || "", 0, sections[sectionName] || "");
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
getSections: () => {
|
|
291
|
+
return Object.keys(sections);
|
|
292
|
+
},
|
|
293
|
+
getTemplate: () => {
|
|
294
|
+
return originalTemplate;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
return renderer;
|
|
298
|
+
}
|
|
299
|
+
var islandDirective = {
|
|
300
|
+
name: "island",
|
|
301
|
+
hasEndTag: true,
|
|
302
|
+
handler: (content, params, context, filePath) => {
|
|
303
|
+
if (!params || params.length === 0) {
|
|
304
|
+
throw new Error("Island directive requires a name parameter");
|
|
305
|
+
}
|
|
306
|
+
const islandName = params[0].replace(/['"`]/g, "");
|
|
307
|
+
const priority = params[1] ? params[1].replace(/['"`]/g, "") : "lazy";
|
|
308
|
+
const id = `island-${islandName}-${Math.random().toString(36).substring(2, 9)}`;
|
|
309
|
+
const propsMatch = content.match(/<script\s+props\s*>([\s\S]*?)<\/script>/i);
|
|
310
|
+
const propsScript = propsMatch ? propsMatch[1].trim() : "";
|
|
311
|
+
const contentWithoutProps = propsMatch ? content.replace(propsMatch[0], "") : content;
|
|
312
|
+
return `<div data-island="${islandName}" data-island-id="${id}" data-priority="${priority}">
|
|
313
|
+
${contentWithoutProps}
|
|
314
|
+
<script type="application/json" data-island-props="${id}">
|
|
315
|
+
${propsScript ? `{${propsScript}}` : "{}"}
|
|
316
|
+
</script>
|
|
317
|
+
</div>`;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
function registerStreamingDirectives(options = {}) {
|
|
321
|
+
const directives = [];
|
|
322
|
+
if (options.hydration?.enabled) {
|
|
323
|
+
directives.push(islandDirective);
|
|
324
|
+
}
|
|
325
|
+
return directives;
|
|
326
|
+
}
|
|
327
|
+
async function processSectionDirectives(content, context, filePath, options = {}) {
|
|
328
|
+
return content;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// src/index.ts
|
|
332
|
+
var src_default = plugin;
|
|
333
|
+
export {
|
|
334
|
+
webComponentDirectiveHandler,
|
|
335
|
+
unescapeHtml,
|
|
336
|
+
templateCache,
|
|
337
|
+
streamTemplate,
|
|
338
|
+
setGlobalContext,
|
|
339
|
+
runPreProcessingMiddleware,
|
|
340
|
+
runPostProcessingMiddleware,
|
|
341
|
+
resolveTemplatePath,
|
|
342
|
+
renderComponent,
|
|
343
|
+
registerStreamingDirectives,
|
|
344
|
+
processTranslateDirective,
|
|
345
|
+
processStackReplacements,
|
|
346
|
+
processStackPushDirectives,
|
|
347
|
+
processSectionDirectives,
|
|
348
|
+
processOnceDirective,
|
|
349
|
+
processMiddleware,
|
|
350
|
+
processMarkdownDirectives,
|
|
351
|
+
processLoops,
|
|
352
|
+
processJsonDirective,
|
|
353
|
+
processIncludes,
|
|
354
|
+
processForms,
|
|
355
|
+
processFormInputDirectives,
|
|
356
|
+
processFormDirectives,
|
|
357
|
+
processExpressions,
|
|
358
|
+
processErrorDirective,
|
|
359
|
+
processDirectives,
|
|
360
|
+
processCustomDirectives,
|
|
361
|
+
processBasicFormDirectives,
|
|
362
|
+
partialsCache,
|
|
363
|
+
markdownDirectiveHandler,
|
|
364
|
+
loadTranslation,
|
|
365
|
+
islandDirective,
|
|
366
|
+
hashFilePath,
|
|
367
|
+
getTranslation,
|
|
368
|
+
getSourceLineInfo,
|
|
369
|
+
generateTemplatesDocs,
|
|
370
|
+
generateDocs,
|
|
371
|
+
generateDirectivesDocs,
|
|
372
|
+
generateComponentsDocs,
|
|
373
|
+
generateComponentDoc,
|
|
374
|
+
formatDocsAsMarkdown,
|
|
375
|
+
formatDocsAsJson,
|
|
376
|
+
formatDocsAsHtml,
|
|
377
|
+
findComponentFiles,
|
|
378
|
+
fileExists,
|
|
379
|
+
extractVariables,
|
|
380
|
+
extractComponentProps,
|
|
381
|
+
extractComponentDescription,
|
|
382
|
+
evaluateExpression,
|
|
383
|
+
evaluateAuthExpression,
|
|
384
|
+
escapeHtml,
|
|
385
|
+
docsCommand,
|
|
386
|
+
defaultFilters,
|
|
387
|
+
defaultConfig,
|
|
388
|
+
src_default as default,
|
|
389
|
+
createTranslateFilter,
|
|
390
|
+
createStreamRenderer,
|
|
391
|
+
createDetailedErrorMessage,
|
|
392
|
+
config,
|
|
393
|
+
checkCache,
|
|
394
|
+
cacheTemplate,
|
|
395
|
+
buildWebComponents,
|
|
396
|
+
applyFilters
|
|
397
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CustomDirective, StreamRenderer, StreamingConfig, StxOptions } from './types';
|
|
2
|
+
|
|
3
|
+
declare const defaultStreamingConfig: StreamingConfig;
|
|
4
|
+
export declare function streamTemplate(templatePath: string,
|
|
5
|
+
data: Record<string, any> = {},
|
|
6
|
+
options: StxOptions = {},): Promise<ReadableStream<string>>;
|
|
7
|
+
export declare function createStreamRenderer(templatePath: string,
|
|
8
|
+
options: StxOptions = {},): Promise<StreamRenderer>;
|
|
9
|
+
export declare const islandDirective: CustomDirective;
|
|
10
|
+
export declare function registerStreamingDirectives(options: StxOptions = {}): CustomDirective[];
|
|
11
|
+
export declare function processSectionDirectives(content: string,
|
|
12
|
+
context: Record<string, any>,
|
|
13
|
+
filePath: string,
|
|
14
|
+
options: StxOptions = {},): Promise<string>;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
export declare type CustomDirectiveHandler = (
|
|
2
|
+
content: string,
|
|
3
|
+
params: string[],
|
|
4
|
+
context: Record<string, any>,
|
|
5
|
+
filePath: string
|
|
6
|
+
) => string | Promise<string>
|
|
7
|
+
|
|
8
|
+
export interface CustomDirective {
|
|
9
|
+
name: string
|
|
10
|
+
handler: CustomDirectiveHandler
|
|
11
|
+
hasEndTag?: boolean
|
|
12
|
+
description?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type MiddlewareHandler = (
|
|
16
|
+
template: string,
|
|
17
|
+
context: Record<string, any>,
|
|
18
|
+
filePath: string,
|
|
19
|
+
options: StxOptions
|
|
20
|
+
) => string | Promise<string>
|
|
21
|
+
|
|
22
|
+
export interface Middleware {
|
|
23
|
+
name: string
|
|
24
|
+
handler: MiddlewareHandler
|
|
25
|
+
timing: 'before' | 'after'
|
|
26
|
+
description?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface I18nConfig {
|
|
30
|
+
defaultLocale: string
|
|
31
|
+
locale: string
|
|
32
|
+
translationsDir: string
|
|
33
|
+
format: 'json' | 'yaml' | 'yml' | 'js'
|
|
34
|
+
fallbackToKey: boolean
|
|
35
|
+
cache: boolean
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface WebComponent {
|
|
39
|
+
name: string
|
|
40
|
+
tag: string
|
|
41
|
+
file: string
|
|
42
|
+
extends?: string
|
|
43
|
+
shadowDOM?: boolean
|
|
44
|
+
template?: boolean
|
|
45
|
+
styleSource?: string
|
|
46
|
+
attributes?: string[]
|
|
47
|
+
description?: string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface WebComponentConfig {
|
|
51
|
+
enabled: boolean
|
|
52
|
+
outputDir: string
|
|
53
|
+
components: WebComponent[]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type DocFormat = 'markdown' | 'html' | 'json'
|
|
57
|
+
|
|
58
|
+
export interface ComponentPropDoc {
|
|
59
|
+
name: string
|
|
60
|
+
type?: string
|
|
61
|
+
required?: boolean
|
|
62
|
+
default?: string
|
|
63
|
+
description?: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ComponentDoc {
|
|
67
|
+
name: string
|
|
68
|
+
path: string
|
|
69
|
+
description?: string
|
|
70
|
+
props: ComponentPropDoc[]
|
|
71
|
+
example?: string
|
|
72
|
+
isWebComponent?: boolean
|
|
73
|
+
tag?: string
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface TemplateDoc {
|
|
77
|
+
name: string
|
|
78
|
+
path: string
|
|
79
|
+
description?: string
|
|
80
|
+
components?: string[]
|
|
81
|
+
directives?: string[]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface DirectiveDoc {
|
|
85
|
+
name: string
|
|
86
|
+
description?: string
|
|
87
|
+
hasEndTag: boolean
|
|
88
|
+
example?: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface DocGeneratorConfig {
|
|
92
|
+
enabled: boolean
|
|
93
|
+
outputDir: string
|
|
94
|
+
format: DocFormat
|
|
95
|
+
components: boolean
|
|
96
|
+
templates: boolean
|
|
97
|
+
directives: boolean
|
|
98
|
+
extraContent?: string
|
|
99
|
+
template?: string
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface StreamingConfig {
|
|
103
|
+
enabled: boolean
|
|
104
|
+
bufferSize: number
|
|
105
|
+
strategy: 'auto' | 'manual' | 'sections'
|
|
106
|
+
timeout: number
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface StreamRenderer {
|
|
110
|
+
renderShell: (data?: Record<string, any>) => Promise<string>
|
|
111
|
+
renderSection: (section: string, data?: Record<string, any>) => Promise<string>
|
|
112
|
+
getSections: () => string[]
|
|
113
|
+
getTemplate: () => string
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface HydrationConfig {
|
|
117
|
+
enabled: boolean
|
|
118
|
+
mode: 'progressive' | 'islands'
|
|
119
|
+
clientEntry: string
|
|
120
|
+
autoMarkers: boolean
|
|
121
|
+
preload: 'none' | 'eager' | 'lazy'
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface Island {
|
|
125
|
+
id: string
|
|
126
|
+
component: string
|
|
127
|
+
props?: Record<string, any>
|
|
128
|
+
priority?: 'eager' | 'lazy'
|
|
129
|
+
shadowDOM?: boolean
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface StxConfig {
|
|
133
|
+
enabled: boolean
|
|
134
|
+
partialsDir: string
|
|
135
|
+
componentsDir: string
|
|
136
|
+
debug: boolean
|
|
137
|
+
cache: boolean
|
|
138
|
+
cachePath: string
|
|
139
|
+
cacheVersion: string
|
|
140
|
+
customDirectives?: CustomDirective[]
|
|
141
|
+
middleware?: Middleware[]
|
|
142
|
+
i18n?: Partial<I18nConfig>
|
|
143
|
+
webComponents?: Partial<WebComponentConfig>
|
|
144
|
+
docs?: Partial<DocGeneratorConfig>
|
|
145
|
+
streaming?: Partial<StreamingConfig>
|
|
146
|
+
hydration?: Partial<HydrationConfig>
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type StxOptions = Partial<StxConfig>
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StxOptions } from './types';
|
|
2
|
+
|
|
3
|
+
declare const componentsCache: (...args: any[]) => unknown;
|
|
4
|
+
export declare function renderComponent(componentPath: string, props: Record<string, any>, slotContent: string, componentsDir: string, parentContext: Record<string, any>, parentFilePath: string, options: StxOptions, processedComponents?: Set<string> | undefined, dependencies: Set<string>): Promise<string>;
|
|
5
|
+
export declare function fileExists(filePath: string): Promise<boolean>;
|
|
6
|
+
export declare function extractVariables(scriptContent: string, context: Record<string, any>, filePath: string): Promise<void>;
|
|
7
|
+
export declare function resolveTemplatePath(templatePath: string, currentFilePath: string, options: StxOptions, dependencies?: Set<string>): Promise<string | null>;
|
|
8
|
+
export declare function getSourceLineInfo(template: string, errorPosition?: number, errorPattern?: string): void;
|
|
9
|
+
export declare function createDetailedErrorMessage(errorType: string, errorMessage: string, filePath: string, template: string, errorPosition?: number, errorPattern?: string): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { StxOptions, WebComponent } from './types';
|
|
2
|
+
|
|
3
|
+
export declare function buildWebComponents(options: StxOptions, dependencies: Set<string>): Promise<string[]>;
|
|
4
|
+
declare function buildWebComponent(component: WebComponent, options: StxOptions, dependencies: Set<string>): Promise<string | null>;
|
|
5
|
+
declare interface WebComponentCodeOptions {
|
|
6
|
+
name: string
|
|
7
|
+
tag: string
|
|
8
|
+
baseElement?: string
|
|
9
|
+
source: string
|
|
10
|
+
shadowDOM: boolean
|
|
11
|
+
template: boolean
|
|
12
|
+
styleSource?: string
|
|
13
|
+
attributes?: string[]
|
|
14
|
+
}
|
|
15
|
+
declare function generateWebComponentCode(options: WebComponentCodeOptions): string;
|
|
16
|
+
export declare function webComponentDirectiveHandler(content: string, params: string[], context: Record<string, any>, _filePath: string): string;
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stacksjs/stx",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
|
|
6
|
+
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/stacksjs/stx#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/stacksjs/stx.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/stacksjs/stx/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"blade",
|
|
18
|
+
"css",
|
|
19
|
+
"bun",
|
|
20
|
+
"stx",
|
|
21
|
+
"plugin",
|
|
22
|
+
"generation",
|
|
23
|
+
"typescript",
|
|
24
|
+
"stacks"
|
|
25
|
+
],
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./*": {
|
|
32
|
+
"import": "./dist/*"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"module": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"bin": {
|
|
38
|
+
"stx": "./dist/bin/cli.js"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"LICENSE.md",
|
|
42
|
+
"README.md",
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "bun --bun build.ts && bun run compile",
|
|
47
|
+
"compile": "bun build ./bin/cli.ts --compile --minify --outfile ./bin/stx",
|
|
48
|
+
"compile:all": "bun run compile:linux-x64 && bun run compile:linux-arm64 && bun run compile:windows-x64 && bun run compile:darwin-x64 && bun run compile:darwin-arm64",
|
|
49
|
+
"compile:linux-x64": "bun build ./bin/cli.ts --compile --minify --target=bun-linux-x64 --outfile ./bin/stx-linux-x64",
|
|
50
|
+
"compile:linux-arm64": "bun build ./bin/cli.ts --compile --minify --target=bun-linux-arm64 --outfile ./bin/stx-linux-arm64",
|
|
51
|
+
"compile:windows-x64": "bun build ./bin/cli.ts --compile --minify --target=bun-windows-x64 --outfile ./bin/stx-windows-x64.exe",
|
|
52
|
+
"compile:darwin-x64": "bun build ./bin/cli.ts --compile --minify --target=bun-darwin-x64 --outfile ./bin/stx-darwin-x64",
|
|
53
|
+
"compile:darwin-arm64": "bun build ./bin/cli.ts --compile --minify --target=bun-darwin-arm64 --outfile ./bin/stx-darwin-arm64",
|
|
54
|
+
"zip": "bun run zip:all",
|
|
55
|
+
"zip:all": "bun run zip:linux-x64 && bun run zip:linux-arm64 && bun run zip:windows-x64 && bun run zip:darwin-x64 && bun run zip:darwin-arm64",
|
|
56
|
+
"zip:linux-x64": "zip -j bin/stx-linux-x64.zip bin/stx-linux-x64",
|
|
57
|
+
"zip:linux-arm64": "zip -j bin/stx-linux-arm64.zip bin/stx-linux-arm64",
|
|
58
|
+
"zip:windows-x64": "zip -j bin/stx-windows-x64.zip bin/stx-windows-x64.exe",
|
|
59
|
+
"zip:darwin-x64": "zip -j bin/stx-darwin-x64.zip bin/stx-darwin-x64",
|
|
60
|
+
"zip:darwin-arm64": "zip -j bin/stx-darwin-arm64.zip bin/stx-darwin-arm64",
|
|
61
|
+
"lint": "bunx eslint .",
|
|
62
|
+
"lint:fix": "bunx eslint . --fix",
|
|
63
|
+
"fresh": "bunx rimraf node_modules/ bun.lock && bun i",
|
|
64
|
+
"changelog": "bunx changelogen --output CHANGELOG.md",
|
|
65
|
+
"prepublishOnly": "bun run build",
|
|
66
|
+
"release": "bun run changelog && bunx bumpp package.json --all",
|
|
67
|
+
"test": "bun test",
|
|
68
|
+
"typecheck": "bun tsc --noEmit"
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"marked": "^15.0.11",
|
|
72
|
+
"yaml": "^2.7.1"
|
|
73
|
+
}
|
|
74
|
+
}
|