create-fornix 0.0.3 → 0.0.4
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/LICENSE +21 -0
- package/dist/index.js +49 -16
- package/dist/index.js.map +1 -1
- package/package.json +18 -18
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kama kama
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -213,7 +213,7 @@ function topologicalSort(blocks, manifests) {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
// src/scaffold/structure-generator.ts
|
|
216
|
-
function generateStructure(config) {
|
|
216
|
+
function generateStructure(config, manifests = []) {
|
|
217
217
|
const files = {};
|
|
218
218
|
const adapterDeps = getAdapterDependencies(config);
|
|
219
219
|
const pkg = {
|
|
@@ -278,16 +278,35 @@ pnpm-debug.log*
|
|
|
278
278
|
.DS_Store
|
|
279
279
|
Thumbs.db
|
|
280
280
|
`.trim() + "\n";
|
|
281
|
-
|
|
281
|
+
const blockImports = [];
|
|
282
|
+
const blockComponents = [];
|
|
283
|
+
if (manifests.length > 0) {
|
|
284
|
+
for (const manifest2 of manifests) {
|
|
285
|
+
if (manifest2.type !== "section") continue;
|
|
286
|
+
const mainFile = manifest2.files.find((f) => f.destination.endsWith(".astro") || f.destination.endsWith(".tsx"));
|
|
287
|
+
if (mainFile) {
|
|
288
|
+
const componentName = manifest2.name.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
289
|
+
let importPath = mainFile.destination;
|
|
290
|
+
if (importPath.startsWith("src/")) {
|
|
291
|
+
importPath = "../" + importPath.substring(4);
|
|
292
|
+
}
|
|
293
|
+
blockImports.push(`import ${componentName} from '${importPath}';`);
|
|
294
|
+
blockComponents.push(` <${componentName} />`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const indexAstroContent = `
|
|
282
299
|
---
|
|
283
300
|
import Layout from '../layouts/Layout.astro';
|
|
301
|
+
${blockImports.join("\n")}
|
|
284
302
|
---
|
|
285
|
-
<Layout title="Welcome to
|
|
303
|
+
<Layout title="Welcome to ${config.projectName}.">
|
|
286
304
|
<main>
|
|
287
|
-
<h1>Welcome to <span class="text-gradient">${config.projectName}</span></h1
|
|
305
|
+
${blockComponents.length > 0 ? blockComponents.join("\n") : ` <h1>Welcome to <span class="text-gradient">${config.projectName}</span></h1>`}
|
|
288
306
|
</main>
|
|
289
307
|
</Layout>
|
|
290
|
-
`.trim() + "
|
|
308
|
+
`.trim() + "\\n";
|
|
309
|
+
files["src/pages/index.astro"] = indexAstroContent;
|
|
291
310
|
files["src/layouts/Layout.astro"] = `
|
|
292
311
|
---
|
|
293
312
|
interface Props {
|
|
@@ -584,11 +603,12 @@ function generateContentConfig(blocks) {
|
|
|
584
603
|
'import { defineCollection, z } from "astro:content";'
|
|
585
604
|
];
|
|
586
605
|
const collections = [];
|
|
606
|
+
const dataCollections = /* @__PURE__ */ new Map();
|
|
587
607
|
for (const block of blocks) {
|
|
588
608
|
if (block.collections && block.collections.length > 0) {
|
|
589
609
|
for (const col of block.collections) {
|
|
590
610
|
const importName = `${block.name.replace(/-/g, "")}${col.name}Schema`;
|
|
591
|
-
const importPath = col.schemaSource.replace(
|
|
611
|
+
const importPath = col.schemaSource.replace(/\\.ts$/, "");
|
|
592
612
|
imports.push(`import { schema as ${importName} } from "${importPath}";`);
|
|
593
613
|
collections.push(
|
|
594
614
|
` "${col.name}": defineCollection({
|
|
@@ -600,17 +620,30 @@ function generateContentConfig(blocks) {
|
|
|
600
620
|
}
|
|
601
621
|
const slots = block.ai?.contentSlots;
|
|
602
622
|
if (slots && Object.keys(slots).length > 0) {
|
|
603
|
-
const schemaFields = Object.entries(slots).map(([name, slot]) => `
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
623
|
+
const schemaFields = Object.entries(slots).map(([name, slot]) => ` ${name}: ${zodTypeForSlot(slot)}.optional(),`).join("\n");
|
|
624
|
+
const subdirectory = TYPE_DIRECTORY[block.type] ?? block.type;
|
|
625
|
+
if (!dataCollections.has(subdirectory)) {
|
|
626
|
+
dataCollections.set(subdirectory, []);
|
|
627
|
+
}
|
|
628
|
+
dataCollections.get(subdirectory).push(
|
|
629
|
+
` // ${block.name}
|
|
630
|
+
z.object({
|
|
608
631
|
${schemaFields}
|
|
609
|
-
})
|
|
610
|
-
})`
|
|
632
|
+
})`
|
|
611
633
|
);
|
|
612
634
|
}
|
|
613
635
|
}
|
|
636
|
+
for (const [colName, schemas] of dataCollections.entries()) {
|
|
637
|
+
const schemaStr = schemas.length === 1 ? schemas[0] : `z.union([
|
|
638
|
+
${schemas.join(",\n")}
|
|
639
|
+
])`;
|
|
640
|
+
collections.push(
|
|
641
|
+
` "${colName}": defineCollection({
|
|
642
|
+
type: "data",
|
|
643
|
+
schema: ${schemaStr},
|
|
644
|
+
})`
|
|
645
|
+
);
|
|
646
|
+
}
|
|
614
647
|
const lines = [
|
|
615
648
|
...imports,
|
|
616
649
|
"",
|
|
@@ -789,13 +822,13 @@ function scaffold(input) {
|
|
|
789
822
|
const selectedBlockNames = config.blocks.map((block) => block.name);
|
|
790
823
|
const dependencyResult = resolveDependencies(selectedBlockNames, manifests);
|
|
791
824
|
if (!isOk(dependencyResult)) {
|
|
792
|
-
return err(new Error(
|
|
825
|
+
return err(Object.assign(new Error(dependencyResult.error.message), dependencyResult.error));
|
|
793
826
|
}
|
|
794
827
|
const resolvedBlockNames = dependencyResult.value;
|
|
795
828
|
const files = {};
|
|
796
|
-
const structureFiles = generateStructure(config);
|
|
797
|
-
Object.assign(files, structureFiles);
|
|
798
829
|
const resolvedManifests = resolvedBlockNames.filter((name) => manifests[name] !== void 0).map((name) => manifests[name]);
|
|
830
|
+
const structureFiles = generateStructure(config, resolvedManifests);
|
|
831
|
+
Object.assign(files, structureFiles);
|
|
799
832
|
const astroConfigResult = generateAstroConfig(config, resolvedManifests);
|
|
800
833
|
if (!isOk(astroConfigResult)) {
|
|
801
834
|
return err(astroConfigResult.error);
|