@123ishatest/test-2 0.0.2 → 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/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const louter = 4;
1
+ export { louter } from './louter.js';
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
- // Reexport your entry components here
2
- export const louter = 4;
1
+ export { louter } from './louter.js';
@@ -0,0 +1,10 @@
1
+ import { type Plugin } from 'vite';
2
+ import { type ZodType } from 'zod';
3
+ export interface ContentPluginOptions {
4
+ schemas: Record<string, ZodType>;
5
+ contentDir?: string;
6
+ moduleTypesId?: string;
7
+ schemaOutputDir?: string;
8
+ typesOutputDir?: string;
9
+ }
10
+ export default function louter(options: ContentPluginOptions): Plugin;
package/dist/louter.js ADDED
@@ -0,0 +1,63 @@
1
+ import {} from 'vite';
2
+ import { parse } from 'yaml';
3
+ import fg from 'fast-glob';
4
+ import { mkdirSync, readFileSync, writeFileSync } from 'fs';
5
+ import { resolve } from 'path';
6
+ import { z } from 'zod';
7
+ export default function louter(options) {
8
+ const { schemas, contentDir = 'src/content', moduleTypesId = 'virtual:content-types', schemaOutputDir = 'src/generated/schemas', typesOutputDir = 'src/generated/types' } = options;
9
+ let generatedTypes = '';
10
+ return {
11
+ name: 'content-loader',
12
+ async buildStart() {
13
+ const files = await fg(`${contentDir}/**/*.yaml`);
14
+ const idsByKind = {};
15
+ // Ensure output dirs exist
16
+ mkdirSync(schemaOutputDir, { recursive: true });
17
+ mkdirSync(typesOutputDir, { recursive: true });
18
+ // Generate JSON Schema + TS types for each schema
19
+ for (const [kind, schema] of Object.entries(schemas)) {
20
+ const jsonSchema = z.toJSONSchema(schema);
21
+ // const ts = zodToTs(schema, kind);
22
+ writeFileSync(resolve(schemaOutputDir, `${kind}.schema.json`), JSON.stringify(jsonSchema, null, 2));
23
+ // writeFileSync(
24
+ // resolve(typesOutputDir, `${kind}.d.ts`),
25
+ // ts.node,
26
+ // );
27
+ }
28
+ // Parse content files
29
+ for (const file of files) {
30
+ const raw = readFileSync(file, 'utf8');
31
+ const data = parse(raw);
32
+ const fileName = file.split('/').pop();
33
+ const parts = fileName.split('.');
34
+ const kind = parts[parts.length - 2];
35
+ const schema = schemas[kind];
36
+ if (!schema)
37
+ continue;
38
+ const parsed = schema.parse(data);
39
+ idsByKind[kind] ??= [];
40
+ idsByKind[kind].push(parsed.id);
41
+ }
42
+ // Generate TypeScript ID unions
43
+ generatedTypes = Object.entries(idsByKind)
44
+ .map(([kind, ids]) => {
45
+ const typeName = `${capitalize(kind)}Id`;
46
+ const union = ids.map((id) => `"${id}"`).join(' | ');
47
+ return `export type ${typeName} = ${union};`;
48
+ })
49
+ .join('\n');
50
+ },
51
+ resolveId(id) {
52
+ if (id === moduleTypesId)
53
+ return id;
54
+ },
55
+ load(id) {
56
+ if (id === moduleTypesId)
57
+ return generatedTypes;
58
+ }
59
+ };
60
+ }
61
+ function capitalize(s) {
62
+ return s.charAt(0).toUpperCase() + s.slice(1);
63
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@123ishatest/test-2",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",
@@ -29,6 +29,7 @@
29
29
  ".": {
30
30
  "types": "./dist/index.d.ts",
31
31
  "svelte": "./dist/index.js",
32
+ "import": "./dist/index.js",
32
33
  "default": "./dist/index.js"
33
34
  }
34
35
  },
@@ -59,5 +60,9 @@
59
60
  },
60
61
  "keywords": [
61
62
  "svelte"
62
- ]
63
+ ],
64
+ "dependencies": {
65
+ "fast-glob": "^3.3.3",
66
+ "zod": "^4.3.6"
67
+ }
63
68
  }