vaderjs 2.3.14 ā 2.3.15
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 -21
- package/README.md +89 -0
- package/cli.ts +227 -227
- package/config/index.ts +3 -0
- package/jsconfig.json +7 -7
- package/main.ts +535 -0
- package/package.json +16 -16
- package/plugins/index.ts +72 -72
- package/README.MD +0 -99
- package/main.js +0 -750
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Pascal
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Pascal
|
|
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,89 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://vader-js.pages.dev">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="/icon.jpeg">
|
|
5
|
+
<img src="https://github.com/Postr-Inc/Vader.js/blob/main/logo.png" height="128">
|
|
6
|
+
</picture>
|
|
7
|
+
<h1 align="center">Vader.js</h1>
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
# Vader.js A reactive framework for building fast and scalable web applications
|
|
12
|
+
|
|
13
|
+
[](https://github.com/Postr-Inc/Vader.js/blob/main/LICENSE) [](https://www.npmjs.com/package/vaderjs)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Installation
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
bun install vaderjs @latest
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { useSate, e } from "vaderjs"
|
|
24
|
+
export default function(){
|
|
25
|
+
let [count, setCount] = useState(0)
|
|
26
|
+
return (
|
|
27
|
+
<div>
|
|
28
|
+
<p>Count is {count} </p>
|
|
29
|
+
<button onClick={()=>setCount(count++)}>
|
|
30
|
+
Increment +1
|
|
31
|
+
</button>
|
|
32
|
+
</div>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
# Project Setup
|
|
38
|
+
Create a pages folder - which allows you to have nextjs page like routing via buns file based router
|
|
39
|
+
|
|
40
|
+
Tip: Each folder can be deep nested up to 4 levels!
|
|
41
|
+
|
|
42
|
+
```md
|
|
43
|
+
|
|
44
|
+
/pages/index.jsx = /
|
|
45
|
+
/pages/home/[page].jsx = /home/:page
|
|
46
|
+
/pages/path/index.jsx = /path/
|
|
47
|
+
/pages/test/[[...catchall]]/index.jsx = /path/test/*
|
|
48
|
+
/pages/route/[param1]/[param2].jsx = /path/route/:param1/:param2
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
Keyword folders - all files are passed from these folders to the build folder
|
|
52
|
+
|
|
53
|
+
```md
|
|
54
|
+
1. pages - used for jsx route files
|
|
55
|
+
2. src - used for your jsx components / javascript -typescript files
|
|
56
|
+
3. public - used for anything / css / json etc
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# Define your config
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { defineConfig } from "vaderjs/config";
|
|
64
|
+
import cloudflare from "vaderjs/plugins/cloudflare/functions"
|
|
65
|
+
import tailwindcss from "vaderjs/plugins/tailwindcss"
|
|
66
|
+
export default defineConfig({
|
|
67
|
+
target: "web",
|
|
68
|
+
host: {
|
|
69
|
+
hostname: "localhost",
|
|
70
|
+
provider:'cloudflare' // used for ssg or ssr
|
|
71
|
+
},
|
|
72
|
+
env: {
|
|
73
|
+
PORT: 3000,
|
|
74
|
+
SSR: true,
|
|
75
|
+
apiRoute: "https://api.example.com"
|
|
76
|
+
},
|
|
77
|
+
Router: {
|
|
78
|
+
tls: {
|
|
79
|
+
cert: "cert.pem",
|
|
80
|
+
key: "key.pem"
|
|
81
|
+
},
|
|
82
|
+
headers: {
|
|
83
|
+
"cache-control": "public, max-age=0, must-revalidate"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
plugins: [cloudflare, tailwindcss],
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
```
|
package/cli.ts
CHANGED
|
@@ -1,228 +1,228 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
import fs from "fs/promises";
|
|
4
|
-
import fsSync from "fs";
|
|
5
|
-
import path from "path";
|
|
6
|
-
import readline from "readline";
|
|
7
|
-
|
|
8
|
-
const cwd = process.cwd();
|
|
9
|
-
|
|
10
|
-
/* ---------------------------------- utils --------------------------------- */
|
|
11
|
-
|
|
12
|
-
function ask(question) {
|
|
13
|
-
const rl = readline.createInterface({
|
|
14
|
-
input: process.stdin,
|
|
15
|
-
output: process.stdout,
|
|
16
|
-
});
|
|
17
|
-
return new Promise((resolve) =>
|
|
18
|
-
rl.question(question + " ", (answer) => {
|
|
19
|
-
rl.close();
|
|
20
|
-
resolve(answer.trim());
|
|
21
|
-
})
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function run(cmd, args = []) {
|
|
26
|
-
const proc = Bun.spawn([cmd, ...args], {
|
|
27
|
-
stdout: "inherit",
|
|
28
|
-
stderr: "inherit",
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const status = await proc.exited;
|
|
32
|
-
if (status !== 0) process.exit(status);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function logSection(title) {
|
|
36
|
-
console.log(`\n${title}`);
|
|
37
|
-
console.log("ā".repeat(title.length));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function getFlags() {
|
|
41
|
-
return new Set(process.argv.slice(2));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/* ---------------------------------- init ---------------------------------- */
|
|
45
|
-
|
|
46
|
-
export async function initProject(dir) {
|
|
47
|
-
const flags = getFlags();
|
|
48
|
-
const autoYes = flags.has("--yes");
|
|
49
|
-
|
|
50
|
-
console.log("š Initializing Vader.js project");
|
|
51
|
-
|
|
52
|
-
const projectDir = path.resolve(cwd, dir || ".");
|
|
53
|
-
if (!fsSync.existsSync(projectDir)) {
|
|
54
|
-
await fs.mkdir(projectDir, { recursive: true });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const files = fsSync.readdirSync(projectDir);
|
|
58
|
-
if (files.length && !autoYes) {
|
|
59
|
-
const confirm = await ask("Directory is not empty. Continue? (y/n):");
|
|
60
|
-
if (confirm !== "y") process.exit(0);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
logSection("š Creating folders");
|
|
64
|
-
|
|
65
|
-
for (const d of ["app", "public"]) {
|
|
66
|
-
const p = path.join(projectDir, d);
|
|
67
|
-
if (!fsSync.existsSync(p)) {
|
|
68
|
-
await fs.mkdir(p, { recursive: true });
|
|
69
|
-
console.log(`created ${d}/`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
logSection("š§± Writing files");
|
|
74
|
-
|
|
75
|
-
await fs.writeFile(
|
|
76
|
-
path.join(projectDir, "app/index.jsx"),
|
|
77
|
-
`import { component, useState } from "vaderjs";
|
|
78
|
-
|
|
79
|
-
export default component(() => {
|
|
80
|
-
const [count, setCount] = useState(0);
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<button onClick={() => setCount(c => c + 1)}>
|
|
84
|
-
Count: {count}
|
|
85
|
-
</button>
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
`
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
await fs.writeFile(
|
|
92
|
-
path.join(projectDir, "public/styles.css"),
|
|
93
|
-
`/* Global styles (optional) */`
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
await fs.writeFile(
|
|
97
|
-
path.join(projectDir, "vaderjs.config.ts"),
|
|
98
|
-
`import defineConfig from "vaderjs/config";
|
|
99
|
-
|
|
100
|
-
export default defineConfig({
|
|
101
|
-
port: 3000,
|
|
102
|
-
plugins: [],
|
|
103
|
-
});
|
|
104
|
-
`
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
if (!fsSync.existsSync(path.join(projectDir, "package.json"))) {
|
|
108
|
-
await fs.writeFile(
|
|
109
|
-
path.join(projectDir, "package.json"),
|
|
110
|
-
JSON.stringify(
|
|
111
|
-
{
|
|
112
|
-
name: path.basename(projectDir),
|
|
113
|
-
private: true,
|
|
114
|
-
scripts: {
|
|
115
|
-
dev: "vaderjs dev",
|
|
116
|
-
build: "vaderjs build",
|
|
117
|
-
start: "vaderjs serve",
|
|
118
|
-
},
|
|
119
|
-
dependencies: {
|
|
120
|
-
vaderjs: "latest",
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
null,
|
|
124
|
-
2
|
|
125
|
-
)
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
logSection("š¦ Installing dependencies");
|
|
130
|
-
await run("bun", ["install", "--force"]);
|
|
131
|
-
|
|
132
|
-
console.log("\nā
Project ready");
|
|
133
|
-
console.log("Run `bun run dev` to start");
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/* ---------------------------------- add ----------------------------------- */
|
|
137
|
-
|
|
138
|
-
export async function addPlugin(name) {
|
|
139
|
-
if (!name) {
|
|
140
|
-
console.error("Please specify a plugin to add.");
|
|
141
|
-
process.exit(1);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const flags = getFlags();
|
|
145
|
-
const force = flags.has("--force");
|
|
146
|
-
|
|
147
|
-
const pkgName = name.startsWith("vaderjs-") ? name : `vaderjs-${name}`;
|
|
148
|
-
const importName = pkgName.replace(/^vaderjs-/, "").replace(/-/g, "_");
|
|
149
|
-
|
|
150
|
-
logSection(`ā Adding plugin: ${pkgName}`);
|
|
151
|
-
|
|
152
|
-
const args = ["add", pkgName];
|
|
153
|
-
if (force) args.push("--force");
|
|
154
|
-
|
|
155
|
-
await run("bun", args);
|
|
156
|
-
|
|
157
|
-
const configPath = path.join(cwd, "vaderjs.config.ts");
|
|
158
|
-
if (!fsSync.existsSync(configPath)) {
|
|
159
|
-
console.warn("ā ļø vaderjs.config.ts not found, skipping registration");
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
let config = await fs.readFile(configPath, "utf8");
|
|
164
|
-
|
|
165
|
-
if (config.includes(`from "${pkgName}"`)) {
|
|
166
|
-
console.log("ā¹ļø Plugin already registered");
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
config =
|
|
171
|
-
`import ${importName} from "${pkgName}";\n` +
|
|
172
|
-
config.replace(/plugins:\s*\[/, `plugins: [${importName}, `);
|
|
173
|
-
|
|
174
|
-
await fs.writeFile(configPath, config);
|
|
175
|
-
console.log("ā Plugin registered");
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/* -------------------------------- remove ---------------------------------- */
|
|
179
|
-
|
|
180
|
-
export async function removePlugin(name) {
|
|
181
|
-
if (!name) {
|
|
182
|
-
console.error("Please specify a plugin to remove.");
|
|
183
|
-
process.exit(1);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const pkgName = name.startsWith("vaderjs-") ? name : `vaderjs-${name}`;
|
|
187
|
-
const importName = pkgName.replace(/^vaderjs-/, "").replace(/-/g, "_");
|
|
188
|
-
|
|
189
|
-
logSection(`ā Removing plugin: ${pkgName}`);
|
|
190
|
-
|
|
191
|
-
await run("bun", ["remove", pkgName]);
|
|
192
|
-
|
|
193
|
-
const configPath = path.join(cwd, "vaderjs.config.ts");
|
|
194
|
-
if (!fsSync.existsSync(configPath)) return;
|
|
195
|
-
|
|
196
|
-
let config = await fs.readFile(configPath, "utf8");
|
|
197
|
-
|
|
198
|
-
config = config
|
|
199
|
-
.replace(new RegExp(`import ${importName} from ".*?";\\n?`, "g"), "")
|
|
200
|
-
.replace(new RegExp(`\\b${importName},?\\s*`, "g"), "");
|
|
201
|
-
|
|
202
|
-
await fs.writeFile(configPath, config);
|
|
203
|
-
console.log("ā Plugin removed");
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/* ---------------------------------- list ---------------------------------- */
|
|
207
|
-
|
|
208
|
-
export async function listPlugins() {
|
|
209
|
-
const pkgPath = path.join(cwd, "package.json");
|
|
210
|
-
if (!fsSync.existsSync(pkgPath)) {
|
|
211
|
-
console.log("No package.json found.");
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const pkg = JSON.parse(await fs.readFile(pkgPath, "utf8"));
|
|
216
|
-
const deps = Object.keys(pkg.dependencies || {}).filter((d) =>
|
|
217
|
-
d.startsWith("vaderjs-")
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
if (!deps.length) {
|
|
221
|
-
console.log("No Vader plugins installed.");
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
logSection("š Installed Vader plugins");
|
|
226
|
-
deps.forEach((d) => console.log("ā¢", d));
|
|
227
|
-
}
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import fs from "fs/promises";
|
|
4
|
+
import fsSync from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import readline from "readline";
|
|
7
|
+
|
|
8
|
+
const cwd = process.cwd();
|
|
9
|
+
|
|
10
|
+
/* ---------------------------------- utils --------------------------------- */
|
|
11
|
+
|
|
12
|
+
function ask(question) {
|
|
13
|
+
const rl = readline.createInterface({
|
|
14
|
+
input: process.stdin,
|
|
15
|
+
output: process.stdout,
|
|
16
|
+
});
|
|
17
|
+
return new Promise((resolve) =>
|
|
18
|
+
rl.question(question + " ", (answer) => {
|
|
19
|
+
rl.close();
|
|
20
|
+
resolve(answer.trim());
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function run(cmd, args = []) {
|
|
26
|
+
const proc = Bun.spawn([cmd, ...args], {
|
|
27
|
+
stdout: "inherit",
|
|
28
|
+
stderr: "inherit",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const status = await proc.exited;
|
|
32
|
+
if (status !== 0) process.exit(status);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function logSection(title) {
|
|
36
|
+
console.log(`\n${title}`);
|
|
37
|
+
console.log("ā".repeat(title.length));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getFlags() {
|
|
41
|
+
return new Set(process.argv.slice(2));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* ---------------------------------- init ---------------------------------- */
|
|
45
|
+
|
|
46
|
+
export async function initProject(dir) {
|
|
47
|
+
const flags = getFlags();
|
|
48
|
+
const autoYes = flags.has("--yes");
|
|
49
|
+
|
|
50
|
+
console.log("š Initializing Vader.js project");
|
|
51
|
+
|
|
52
|
+
const projectDir = path.resolve(cwd, dir || ".");
|
|
53
|
+
if (!fsSync.existsSync(projectDir)) {
|
|
54
|
+
await fs.mkdir(projectDir, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const files = fsSync.readdirSync(projectDir);
|
|
58
|
+
if (files.length && !autoYes) {
|
|
59
|
+
const confirm = await ask("Directory is not empty. Continue? (y/n):");
|
|
60
|
+
if (confirm !== "y") process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
logSection("š Creating folders");
|
|
64
|
+
|
|
65
|
+
for (const d of ["app", "public"]) {
|
|
66
|
+
const p = path.join(projectDir, d);
|
|
67
|
+
if (!fsSync.existsSync(p)) {
|
|
68
|
+
await fs.mkdir(p, { recursive: true });
|
|
69
|
+
console.log(`created ${d}/`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
logSection("š§± Writing files");
|
|
74
|
+
|
|
75
|
+
await fs.writeFile(
|
|
76
|
+
path.join(projectDir, "app/index.jsx"),
|
|
77
|
+
`import { component, useState } from "vaderjs";
|
|
78
|
+
|
|
79
|
+
export default component(() => {
|
|
80
|
+
const [count, setCount] = useState(0);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<button onClick={() => setCount(c => c + 1)}>
|
|
84
|
+
Count: {count}
|
|
85
|
+
</button>
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
`
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
await fs.writeFile(
|
|
92
|
+
path.join(projectDir, "public/styles.css"),
|
|
93
|
+
`/* Global styles (optional) */`
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
await fs.writeFile(
|
|
97
|
+
path.join(projectDir, "vaderjs.config.ts"),
|
|
98
|
+
`import defineConfig from "vaderjs/config";
|
|
99
|
+
|
|
100
|
+
export default defineConfig({
|
|
101
|
+
port: 3000,
|
|
102
|
+
plugins: [],
|
|
103
|
+
});
|
|
104
|
+
`
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
if (!fsSync.existsSync(path.join(projectDir, "package.json"))) {
|
|
108
|
+
await fs.writeFile(
|
|
109
|
+
path.join(projectDir, "package.json"),
|
|
110
|
+
JSON.stringify(
|
|
111
|
+
{
|
|
112
|
+
name: path.basename(projectDir),
|
|
113
|
+
private: true,
|
|
114
|
+
scripts: {
|
|
115
|
+
dev: "vaderjs dev",
|
|
116
|
+
build: "vaderjs build",
|
|
117
|
+
start: "vaderjs serve",
|
|
118
|
+
},
|
|
119
|
+
dependencies: {
|
|
120
|
+
vaderjs: "latest",
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
null,
|
|
124
|
+
2
|
|
125
|
+
)
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
logSection("š¦ Installing dependencies");
|
|
130
|
+
await run("bun", ["install", "--force"]);
|
|
131
|
+
|
|
132
|
+
console.log("\nā
Project ready");
|
|
133
|
+
console.log("Run `bun run dev` to start");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* ---------------------------------- add ----------------------------------- */
|
|
137
|
+
|
|
138
|
+
export async function addPlugin(name) {
|
|
139
|
+
if (!name) {
|
|
140
|
+
console.error("Please specify a plugin to add.");
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const flags = getFlags();
|
|
145
|
+
const force = flags.has("--force");
|
|
146
|
+
|
|
147
|
+
const pkgName = name.startsWith("vaderjs-") ? name : `vaderjs-${name}`;
|
|
148
|
+
const importName = pkgName.replace(/^vaderjs-/, "").replace(/-/g, "_");
|
|
149
|
+
|
|
150
|
+
logSection(`ā Adding plugin: ${pkgName}`);
|
|
151
|
+
|
|
152
|
+
const args = ["add", pkgName];
|
|
153
|
+
if (force) args.push("--force");
|
|
154
|
+
|
|
155
|
+
await run("bun", args);
|
|
156
|
+
|
|
157
|
+
const configPath = path.join(cwd, "vaderjs.config.ts");
|
|
158
|
+
if (!fsSync.existsSync(configPath)) {
|
|
159
|
+
console.warn("ā ļø vaderjs.config.ts not found, skipping registration");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let config = await fs.readFile(configPath, "utf8");
|
|
164
|
+
|
|
165
|
+
if (config.includes(`from "${pkgName}"`)) {
|
|
166
|
+
console.log("ā¹ļø Plugin already registered");
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
config =
|
|
171
|
+
`import ${importName} from "${pkgName}";\n` +
|
|
172
|
+
config.replace(/plugins:\s*\[/, `plugins: [${importName}, `);
|
|
173
|
+
|
|
174
|
+
await fs.writeFile(configPath, config);
|
|
175
|
+
console.log("ā Plugin registered");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* -------------------------------- remove ---------------------------------- */
|
|
179
|
+
|
|
180
|
+
export async function removePlugin(name) {
|
|
181
|
+
if (!name) {
|
|
182
|
+
console.error("Please specify a plugin to remove.");
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const pkgName = name.startsWith("vaderjs-") ? name : `vaderjs-${name}`;
|
|
187
|
+
const importName = pkgName.replace(/^vaderjs-/, "").replace(/-/g, "_");
|
|
188
|
+
|
|
189
|
+
logSection(`ā Removing plugin: ${pkgName}`);
|
|
190
|
+
|
|
191
|
+
await run("bun", ["remove", pkgName]);
|
|
192
|
+
|
|
193
|
+
const configPath = path.join(cwd, "vaderjs.config.ts");
|
|
194
|
+
if (!fsSync.existsSync(configPath)) return;
|
|
195
|
+
|
|
196
|
+
let config = await fs.readFile(configPath, "utf8");
|
|
197
|
+
|
|
198
|
+
config = config
|
|
199
|
+
.replace(new RegExp(`import ${importName} from ".*?";\\n?`, "g"), "")
|
|
200
|
+
.replace(new RegExp(`\\b${importName},?\\s*`, "g"), "");
|
|
201
|
+
|
|
202
|
+
await fs.writeFile(configPath, config);
|
|
203
|
+
console.log("ā Plugin removed");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/* ---------------------------------- list ---------------------------------- */
|
|
207
|
+
|
|
208
|
+
export async function listPlugins() {
|
|
209
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
210
|
+
if (!fsSync.existsSync(pkgPath)) {
|
|
211
|
+
console.log("No package.json found.");
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const pkg = JSON.parse(await fs.readFile(pkgPath, "utf8"));
|
|
216
|
+
const deps = Object.keys(pkg.dependencies || {}).filter((d) =>
|
|
217
|
+
d.startsWith("vaderjs-")
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
if (!deps.length) {
|
|
221
|
+
console.log("No Vader plugins installed.");
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
logSection("š Installed Vader plugins");
|
|
226
|
+
deps.forEach((d) => console.log("ā¢", d));
|
|
227
|
+
}
|
|
228
228
|
|
package/config/index.ts
CHANGED
package/jsconfig.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"jsx": "react",
|
|
4
|
-
"jsxFactory": "
|
|
5
|
-
"jsxFragmentFactory": "Fragment"
|
|
6
|
-
}
|
|
7
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"jsx": "react",
|
|
4
|
+
"jsxFactory": "e",
|
|
5
|
+
"jsxFragmentFactory": "Fragment"
|
|
6
|
+
}
|
|
7
|
+
}
|