@content-collections/vite 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.
@@ -0,0 +1,14 @@
1
+
2
+ > @content-collections/vite@0.0.0 build /Users/sdorra/Projects/sdorra/content-collections/packages/vite
3
+ > tsup src/index.ts --format esm --dts -d dist
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v7.2.0
8
+ CLI Target: es2022
9
+ ESM Build start
10
+ ESM dist/index.js 1.56 KB
11
+ ESM ⚡️ Build success in 11ms
12
+ DTS Build start
13
+ DTS ⚡️ Build success in 510ms
14
+ DTS dist/index.d.ts 195.00 B
package/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # @content-collections/vite
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`52376e2`](https://github.com/sdorra/content-collections/commit/52376e2d7b5dff5c2376da57f76b273ef07e2af4) Thanks [@sdorra](https://github.com/sdorra)! - Add integration for Vite
8
+
9
+ ### Patch Changes
10
+
11
+ - [`842b7e0`](https://github.com/sdorra/content-collections/commit/842b7e0b221172eef51e203a833fbc256af4b501) Thanks [@sdorra](https://github.com/sdorra)! - Core should be a peer dependency of integrations
12
+
13
+ - Updated dependencies [[`52376e2`](https://github.com/sdorra/content-collections/commit/52376e2d7b5dff5c2376da57f76b273ef07e2af4), [`b4f640b`](https://github.com/sdorra/content-collections/commit/b4f640b26f18dbe9eb8b3913428010194d918ad1), [`a0d3bb0`](https://github.com/sdorra/content-collections/commit/a0d3bb0103371809a41bffd23f4dc5a43b474e4e), [`842b7e0`](https://github.com/sdorra/content-collections/commit/842b7e0b221172eef51e203a833fbc256af4b501)]:
14
+ - @content-collections/integrations@0.1.0
15
+ - @content-collections/core@0.1.1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Sebastian Sdorra
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 ADDED
@@ -0,0 +1,44 @@
1
+ ---
2
+ title: Vite Integration
3
+ ---
4
+
5
+ 1. Install required packages:
6
+
7
+ We have to install the following packages:
8
+
9
+ - `@content-collections/core`
10
+ - `@content-collections/vite`
11
+
12
+ ```bash
13
+ pnpm add -D @content-collections/core @content-collections/vite
14
+ ```
15
+
16
+ 1. Adjust your `tsconfig.json`:
17
+
18
+ ```json
19
+ {
20
+ "compilerOptions": {
21
+ // ...
22
+ "paths": {
23
+ "content-collections": ["./.content-collections/generated"]
24
+ }
25
+ }
26
+ }
27
+ ```
28
+
29
+ We require a path alias for the generated files.
30
+ This is necessary because we will generate the files in the `.content-collections/generated` folder.
31
+
32
+ 1. Modify your `vite.config.ts`:
33
+
34
+ ```ts
35
+ import { defineConfig } from "vite";
36
+ import contentCollections from "@content-collections/vite";
37
+
38
+ export default defineConfig({
39
+ plugins: [/** other plugins */, contentCollections()],
40
+ });
41
+
42
+ ```
43
+
44
+ Add the Content Collections plugin to your Vite config.
@@ -0,0 +1,8 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ type Options = {
4
+ configPath: string;
5
+ };
6
+ declare function contentCollectionsPlugin(options?: Options): Plugin;
7
+
8
+ export { contentCollectionsPlugin as default };
package/dist/index.js ADDED
@@ -0,0 +1,61 @@
1
+ // src/index.ts
2
+ import { createBuilder } from "@content-collections/core";
3
+ import path from "path";
4
+ import { configureLogging } from "@content-collections/integrations";
5
+ function resolveConfig(root, configPath) {
6
+ if (!path.isAbsolute(configPath)) {
7
+ configPath = path.resolve(root, configPath);
8
+ }
9
+ return configPath;
10
+ }
11
+ function contentCollectionsPlugin(options = {
12
+ configPath: "content-collections.ts"
13
+ }) {
14
+ let builder;
15
+ return {
16
+ name: "content-collections",
17
+ config(config) {
18
+ let configPath = resolveConfig(
19
+ config.root || process.cwd(),
20
+ options.configPath
21
+ );
22
+ const directory = path.dirname(configPath);
23
+ return {
24
+ optimizeDeps: {
25
+ exclude: ["content-collections"]
26
+ },
27
+ resolve: {
28
+ alias: {
29
+ "content-collections": path.resolve(
30
+ directory,
31
+ "./.content-collections/generated/index.js"
32
+ )
33
+ }
34
+ }
35
+ };
36
+ },
37
+ async configResolved(config) {
38
+ let configPath = resolveConfig(config.root, options.configPath);
39
+ console.log(
40
+ "Starting content-collections with config",
41
+ path.relative(process.cwd(), configPath)
42
+ );
43
+ builder = await createBuilder(configPath);
44
+ configureLogging(builder);
45
+ return;
46
+ },
47
+ async buildStart() {
48
+ console.log("Start initial build");
49
+ await builder.build();
50
+ return;
51
+ },
52
+ async configureServer() {
53
+ console.log("Start watching");
54
+ builder.watch();
55
+ return;
56
+ }
57
+ };
58
+ }
59
+ export {
60
+ contentCollectionsPlugin as default
61
+ };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@content-collections/vite",
3
+ "description": "Use content-collections with Vite",
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "dependencies": {
16
+ "@content-collections/integrations": "0.1.0"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "20.x",
20
+ "tsup": "^7.2.0",
21
+ "typescript": "^5.3.2",
22
+ "vite": "^5",
23
+ "@content-collections/core": "0.1.1"
24
+ },
25
+ "peerDependencies": {
26
+ "vite": "^5",
27
+ "@content-collections/core": "0.1.1"
28
+ },
29
+ "scripts": {
30
+ "build": "tsup src/index.ts --format esm --dts -d dist"
31
+ }
32
+ }
package/src/index.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { Builder, createBuilder } from "@content-collections/core";
2
+ import { Plugin } from "vite";
3
+ import path from "node:path";
4
+ import { configureLogging } from "@content-collections/integrations";
5
+
6
+ type Options = {
7
+ configPath: string;
8
+ };
9
+
10
+ function resolveConfig(root: string, configPath: string) {
11
+ if (!path.isAbsolute(configPath)) {
12
+ configPath = path.resolve(root, configPath);
13
+ }
14
+ return configPath;
15
+ }
16
+
17
+ export default function contentCollectionsPlugin(
18
+ options: Options = {
19
+ configPath: "content-collections.ts",
20
+ }
21
+ ): Plugin {
22
+ let builder: Builder;
23
+ return {
24
+ name: "content-collections",
25
+
26
+ config(config) {
27
+ let configPath = resolveConfig(
28
+ config.root || process.cwd(),
29
+ options.configPath
30
+ );
31
+ const directory = path.dirname(configPath);
32
+ return {
33
+ optimizeDeps: {
34
+ exclude: ["content-collections"],
35
+ },
36
+ resolve: {
37
+ alias: {
38
+ "content-collections": path.resolve(
39
+ directory,
40
+ "./.content-collections/generated/index.js"
41
+ ),
42
+ },
43
+ },
44
+ };
45
+ },
46
+
47
+ async configResolved(config: any) {
48
+ let configPath = resolveConfig(config.root, options.configPath);
49
+ console.log(
50
+ "Starting content-collections with config",
51
+ path.relative(process.cwd(), configPath)
52
+ );
53
+
54
+ builder = await createBuilder(configPath);
55
+ configureLogging(builder);
56
+
57
+ return;
58
+ },
59
+
60
+ async buildStart() {
61
+ console.log("Start initial build");
62
+ await builder.build();
63
+ return;
64
+ },
65
+
66
+ async configureServer() {
67
+ console.log("Start watching");
68
+ builder.watch();
69
+ return;
70
+ },
71
+ };
72
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Base Options: */
4
+ "esModuleInterop": true,
5
+ "skipLibCheck": true,
6
+ "target": "es2022",
7
+ "allowJs": true,
8
+ "resolveJsonModule": true,
9
+ "moduleDetection": "force",
10
+ "isolatedModules": true,
11
+ /* Strictness */
12
+ "strict": true,
13
+ "noUncheckedIndexedAccess": true,
14
+ /* ink */
15
+ "jsx": "react-jsx",
16
+ /* If transpiling with TypeScript: */
17
+ "moduleResolution": "NodeNext",
18
+ "module": "NodeNext",
19
+ "outDir": "dist",
20
+ "sourceMap": true,
21
+ /* If your code doesn't run in the DOM: */
22
+ "lib": ["es2022"]
23
+ }
24
+ }