@contentrail/vite 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +65 -2
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ContentRail contributors
|
|
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/README.md
CHANGED
|
@@ -1,3 +1,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@contentrail/vite`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Vite plugin that loads and validates ContentRail local JSON at build/dev time.
|
|
4
|
+
|
|
5
|
+
- **Node.js ≥ 22**
|
|
6
|
+
- Peer: `vite@^6.0.0 || ^7.0.0 || ^8.0.0` (verified with Vite **8.3.5**)
|
|
7
|
+
- Depends on `@contentrail/core` and `@contentrail/reader`
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
> **Not on the public npm registry yet.** See `docs/PUBLISHING.md`.
|
|
12
|
+
|
|
13
|
+
### Monorepo (current)
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
pnpm install
|
|
17
|
+
pnpm --filter @contentrail/vite build
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Intended after first public `0.1.0` release
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
pnpm add @contentrail/core @contentrail/reader @contentrail/vite zod
|
|
24
|
+
pnpm add -D vite@^8
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
// vite.config.ts
|
|
31
|
+
import { defineConfig } from "vite";
|
|
32
|
+
import { contentrail } from "@contentrail/vite";
|
|
33
|
+
import { articles } from "./content/config";
|
|
34
|
+
|
|
35
|
+
export default defineConfig({
|
|
36
|
+
plugins: [
|
|
37
|
+
contentrail({
|
|
38
|
+
rootDir: "content",
|
|
39
|
+
collections: { articles },
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// browser / app code
|
|
47
|
+
import { entries } from "virtual:contentrail/articles";
|
|
48
|
+
// entries: { id: string; data: Article }[]
|
|
49
|
+
// sourcePath and filesystem details are not included
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Add a TypeScript declaration:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
declare module "virtual:contentrail/articles" {
|
|
56
|
+
import type { InferEntry } from "@contentrail/core";
|
|
57
|
+
import type { articles } from "../content/config";
|
|
58
|
+
export const entries: Array<{
|
|
59
|
+
id: string;
|
|
60
|
+
data: InferEntry<typeof articles>;
|
|
61
|
+
}>;
|
|
62
|
+
export default entries;
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Invalid JSON or schema failures throw during `vite build` / `vite dev` transform.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ContentCollection } from "@contentrail/core";
|
|
2
|
+
import { ContentReadError, type LoadCollectionOptions } from "@contentrail/reader";
|
|
3
|
+
import type { Plugin } from "vite";
|
|
4
|
+
export interface ContentrailViteOptions {
|
|
5
|
+
/** Path to the content root (resolved against Vite `root`). */
|
|
6
|
+
readonly rootDir: string;
|
|
7
|
+
/** Map of virtual module name → collection definition. */
|
|
8
|
+
readonly collections: Readonly<Record<string, ContentCollection>>;
|
|
9
|
+
readonly loadOptions?: LoadCollectionOptions;
|
|
10
|
+
}
|
|
11
|
+
export interface PublicContentEntry<TData> {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly data: TData;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns the virtual module id for a configured collection name.
|
|
17
|
+
* Example: `contentrailVirtual("articles")` → `virtual:contentrail/articles`
|
|
18
|
+
*/
|
|
19
|
+
export declare function contentrailVirtual(collectionKey: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Vite plugin that validates local JSON at build/dev time and exposes
|
|
22
|
+
* browser-safe `{ id, data }[]` modules (no filesystem paths).
|
|
23
|
+
*/
|
|
24
|
+
export declare function contentrail(options: ContentrailViteOptions): Plugin;
|
|
25
|
+
export { ContentReadError };
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAc,MAAM,mBAAmB,CAAC;AACvE,OAAO,EACL,gBAAgB,EAGhB,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAKnC,MAAM,WAAW,sBAAsB;IACrC,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,0DAA0D;IAC1D,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAClE,QAAQ,CAAC,WAAW,CAAC,EAAE,qBAAqB,CAAC;CAC9C;AAED,MAAM,WAAW,kBAAkB,CAAC,KAAK;IACvC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,CA+CnE;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { ContentReadError, createLocalJsonSource, loadCollection, } from "@contentrail/reader";
|
|
3
|
+
const VIRTUAL_PREFIX = "virtual:contentrail/";
|
|
4
|
+
const RESOLVED_PREFIX = `\0${VIRTUAL_PREFIX}`;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the virtual module id for a configured collection name.
|
|
7
|
+
* Example: `contentrailVirtual("articles")` → `virtual:contentrail/articles`
|
|
8
|
+
*/
|
|
9
|
+
export function contentrailVirtual(collectionKey) {
|
|
10
|
+
return `${VIRTUAL_PREFIX}${collectionKey}`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Vite plugin that validates local JSON at build/dev time and exposes
|
|
14
|
+
* browser-safe `{ id, data }[]` modules (no filesystem paths).
|
|
15
|
+
*/
|
|
16
|
+
export function contentrail(options) {
|
|
17
|
+
let viteRoot = process.cwd();
|
|
18
|
+
return {
|
|
19
|
+
name: "contentrail",
|
|
20
|
+
configResolved(config) {
|
|
21
|
+
viteRoot = config.root;
|
|
22
|
+
},
|
|
23
|
+
resolveId(id) {
|
|
24
|
+
if (id.startsWith(VIRTUAL_PREFIX)) {
|
|
25
|
+
return `\0${id}`;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
},
|
|
29
|
+
async load(id) {
|
|
30
|
+
if (!id.startsWith(RESOLVED_PREFIX)) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const collectionKey = id.slice(RESOLVED_PREFIX.length);
|
|
34
|
+
const collection = options.collections[collectionKey];
|
|
35
|
+
if (collection === undefined) {
|
|
36
|
+
throw new ContentReadError("MISSING_COLLECTION", `No ContentRail collection configured for virtual module "${collectionKey}".`, { collection: collectionKey });
|
|
37
|
+
}
|
|
38
|
+
const absoluteRoot = path.resolve(viteRoot, options.rootDir);
|
|
39
|
+
const source = await createLocalJsonSource({ rootDir: absoluteRoot });
|
|
40
|
+
const entries = await loadCollection(source, collection, options.loadOptions);
|
|
41
|
+
const publicEntries = entries.map((entry) => ({
|
|
42
|
+
id: entry.id,
|
|
43
|
+
data: entry.data,
|
|
44
|
+
}));
|
|
45
|
+
return `export const entries = ${JSON.stringify(publicEntries)};\nexport default entries;\n`;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export { ContentReadError };
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACr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E,YAAY,EAAE,CAAC,CAAC;YACtE,MAAM,OAAO,GAAG,MAAM,cAAc,CAClC,MAAM,EACN,UAAU,EACV,OAAO,CAAC,WAAW,CACpB,CAAC;YAEF,MAAM,aAAa,GAEf,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBAC1B,EAAE,EAAE,KAAK,CAAC,EAAE;gBACZ,IAAI,EAAE,KAAK,CAAC,IAAI;aACjB,CAAC,CAAC,CAAC;YAEJ,OAAO,0BAA0B,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,8BAA8B,CAAC;QAC/F,CAAC;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentrail/vite",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Vite plugin that loads ContentRail local JSON at build time.",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=22"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"node": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@contentrail/reader": "0.1.0",
|
|
27
|
+
"@contentrail/core": "0.1.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^22.20.5",
|
|
34
|
+
"typescript": "5.9.3",
|
|
35
|
+
"vite": "8.3.5",
|
|
36
|
+
"zod": "3.25.76"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/Hridhin-k/contentrail.git",
|
|
41
|
+
"directory": "packages/vite"
|
|
42
|
+
},
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/Hridhin-k/contentrail/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/Hridhin-k/contentrail#readme",
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc -p tsconfig.json",
|
|
52
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
53
|
+
"test": "pnpm run build && tsc -p tsconfig.test.json && node --test test-dist/**/*.test.js"
|
|
54
|
+
}
|
|
6
55
|
}
|