Skip to content

Commit 763633e

Browse files
authored
πŸŽ‰ feat: Init drupal-vite package (#162)
* πŸŽ‰ feat: Init drupal-vite package * ✨ feat: update vite plugin options
1 parent f771a28 commit 763633e

File tree

9 files changed

+710
-0
lines changed

9 files changed

+710
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# dependencies (bun install)
2+
node_modules
3+
4+
# output
5+
out
6+
dist
7+
*.tgz
8+
build
9+
10+
# code coverage
11+
coverage
12+
*.lcov
13+
# logs
14+
logs
15+
_.log
16+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
17+
18+
# dotenv environment variable files
19+
.env
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
.env.local
24+
25+
# caches
26+
.eslintcache
27+
.cache
28+
*.tsbuildinfo
29+
30+
# IntelliJ based IDEs
31+
.idea
32+
33+
# Finder (MacOS) folder config
34+
.DS_Store
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# drupal-vite
2+
3+
> A Vite plugin that streamlines Drupal integration with your frontend projects.
4+
5+
## Features
6+
7+
- Simplified Drupal API connection setup
8+
- OAuth authentication handling
9+
- Preconfigured GraphQL client
10+
- Flexible environment configuration options
11+
- Custom GraphQL client extensions
12+
13+
## Installation
14+
15+
```bash
16+
# Using npm
17+
npm install drupal-vite
18+
19+
# Using yarn
20+
yarn add drupal-vite
21+
22+
# Using pnpm
23+
pnpm add drupal-vite
24+
25+
# Using bun
26+
bun add drupal-vite
27+
```
28+
29+
## Quick Start
30+
31+
Add the plugin to your Vite configuration:
32+
33+
```typescript
34+
import { defineConfig } from "vite";
35+
import { drupal } from "drupal-vite";
36+
37+
export default defineConfig({
38+
plugins: [
39+
drupal(),
40+
// other plugins...
41+
],
42+
});
43+
```
44+
45+
## Configuration
46+
47+
The plugin offers several configuration approaches to suit your workflow:
48+
49+
### Using Environment Variables
50+
51+
Set these environment variables in your project:
52+
53+
```env
54+
DRUPAL_URL=https://your-drupal-site.com
55+
DRUPAL_CLIENT_ID=your-client-id
56+
DRUPAL_CLIENT_SECRET=your-client-secret
57+
```
58+
59+
### Using Custom Environment Variables
60+
61+
Reference your own environment variables:
62+
63+
```typescript
64+
drupal({
65+
drupalUrl: "MY_DRUPAL_URL", // Will use process.env.MY_DRUPAL_URL
66+
simple_oauth: {
67+
clientID: "MY_CLIENT_ID", // Will use process.env.MY_CLIENT_ID
68+
clientSecret: "MY_CLIENT_SECRET", // Will use process.env.MY_CLIENT_SECRET
69+
},
70+
});
71+
```
72+
73+
### Direct Configuration
74+
75+
Configure options directly in your Vite config file:
76+
77+
```typescript
78+
import { defineConfig } from "vite";
79+
import { drupal } from "drupal-vite";
80+
81+
export default defineConfig({
82+
plugins: [
83+
drupal({
84+
// Drupal instance URL
85+
drupalUrl: "https://your-drupal-site.com",
86+
87+
// OAuth credentials
88+
simple_oauth: {
89+
clientID: "your-client-id",
90+
clientSecret: "your-client-secret",
91+
},
92+
93+
// GraphQL settings
94+
graphql: {
95+
endpoint: "/graphql", // Default: /graphql
96+
},
97+
}),
98+
],
99+
});
100+
```
101+
102+
## Using the Client
103+
104+
After configuration, access the Drupal client in your code:
105+
106+
```typescript
107+
import { getDrupalClient } from 'drupal-vite/client';
108+
109+
// Get a preconfigured GraphQL client
110+
const client = await getDrupalClient();
111+
112+
const query = graphql(`
113+
query route($path: String!) {
114+
route(path: $path, revision: "CURRENT") {
115+
__typename
116+
}
117+
}`
118+
119+
// Execute GraphQL operations
120+
const result = await client.query(query, { path: "/example" });
121+
```
122+
123+
## Advanced Configuration
124+
125+
Create a `drupal-decoupled.config.ts` file in your project root to customize the [GraphQL urql client](https://nearform.com/open-source/urql):
126+
127+
```typescript
128+
// drupal-decoupled.config.ts
129+
import { fetchExchange, cacheExchange } from "@urql/core";
130+
131+
export default {
132+
exchanges: [cacheExchange, fetchExchange],
133+
};
134+
```
135+
136+
## Development
137+
138+
### Setup
139+
140+
```bash
141+
# Install dependencies
142+
bun install
143+
144+
# Build the package
145+
bun run build:all
146+
```
147+
148+
### Local Testing with yalc
149+
150+
Use [yalc](https://github.com/wclr/yalc) to test locally in another project:
151+
152+
1. Install yalc globally:
153+
154+
```bash
155+
npm install -g yalc
156+
# or
157+
bun install -g yalc
158+
```
159+
160+
2. Build and publish to your local yalc store:
161+
162+
```bash
163+
bun run yalc:publish
164+
```
165+
166+
3. Add the package to your test project:
167+
168+
```bash
169+
yalc add drupal-vite
170+
```
171+
172+
4. Push updates after making changes:
173+
```bash
174+
bun run yalc:publish --push
175+
```

β€Žpackages/drupal-vite/bun.lockβ€Ž

Lines changed: 167 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
declare module "drupal-vite/client" {
2+
import type { drupalAuthClient } from "drupal-auth-client";
3+
import type { Client } from "@urql/core";
4+
5+
/**
6+
* Gets the Drupal authentication token and related data
7+
*
8+
* @returns A promise resolving to the Drupal auth data
9+
*/
10+
export function getDrupalAuth(): ReturnType<typeof drupalAuthClient>;
11+
12+
/**
13+
* Gets a configured Drupal GraphQL client with authentication
14+
* Uses any custom configuration from drupal-decoupled.config.ts if available
15+
*
16+
* @returns A promise resolving to a configured URQL Client for Drupal
17+
*/
18+
export function getDrupalClient(): Promise<Client>;
19+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "drupal-vite",
3+
"version": "0.0.0",
4+
"description": "Vite plugin for Drupal integration",
5+
"module": "build/index.js",
6+
"main": "build/index.js",
7+
"types": "build/index.d.ts",
8+
"type": "module",
9+
"exports": {
10+
".": {
11+
"import": "./build/index.js",
12+
"types": "./build/index.d.ts"
13+
},
14+
"./client": {
15+
"types": "./build/client.d.ts"
16+
}
17+
},
18+
"typesVersions": {
19+
"*": {
20+
"client": ["./build/client.d.ts"]
21+
}
22+
},
23+
"files": [
24+
"build",
25+
"README.md"
26+
],
27+
"scripts": {
28+
"build": "bun build ./src/index.ts --outdir ./build --format esm --target node",
29+
"build:types": "tsc --emitDeclarationOnly --declaration --outDir build",
30+
"copy:dts": "cp client.d.ts build/client.d.ts",
31+
"build:all": "bun run build && bun run build:types && bun run copy:dts",
32+
"prepublishOnly": "bun run build:all",
33+
"yalc:publish": "bun run build:all && yalc publish"
34+
},
35+
"devDependencies": {
36+
"@types/bun": "latest",
37+
"vite": "^6.3.5"
38+
},
39+
"peerDependencies": {
40+
"typescript": "^5",
41+
"vite": "^6.0.0",
42+
"@urql/core": "^5.1.1"
43+
},
44+
"dependencies": {
45+
"@types/fs-extra": "^11.0.4",
46+
"drupal-auth-client": "^1.0.2",
47+
"fs-extra": "^11.3.0"
48+
},
49+
"keywords": [
50+
"vite-plugin",
51+
"drupal",
52+
"decoupled"
53+
]
54+
}

0 commit comments

Comments
Β (0)