nurev 0.0.6 → 0.0.7
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/bun.lock +0 -5
- package/index.js +75 -35
- package/package.json +1 -1
- package/templates/base/frontend/server/utils/auth.ts +0 -2
- package/templates/pocketbase/.env.example +2 -2
- package/templates/pocketbase/README.md +8 -6
- package/utils/cmd.js +23 -0
- package/utils/file.js +25 -0
package/bun.lock
CHANGED
|
@@ -8,9 +8,6 @@
|
|
|
8
8
|
"fs-extra": "^11.3.4",
|
|
9
9
|
"prompts": "^2.4.2",
|
|
10
10
|
},
|
|
11
|
-
"peerDependencies": {
|
|
12
|
-
"typescript": "^5",
|
|
13
|
-
},
|
|
14
11
|
},
|
|
15
12
|
},
|
|
16
13
|
"packages": {
|
|
@@ -26,8 +23,6 @@
|
|
|
26
23
|
|
|
27
24
|
"sisteransi": ["sisteransi@1.0.5", "", {}, "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg=="],
|
|
28
25
|
|
|
29
|
-
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
|
30
|
-
|
|
31
26
|
"universalify": ["universalify@2.0.1", "", {}, "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw=="],
|
|
32
27
|
}
|
|
33
28
|
}
|
package/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import kleur from "kleur";
|
|
3
4
|
import { default as prompts } from "prompts";
|
|
4
5
|
import { default as fs } from "fs-extra";
|
|
5
6
|
import { fileURLToPath } from "url";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
7
|
+
import { spawnPromise } from "./utils/cmd.js";
|
|
8
|
+
import { writeEnvFile } from "./utils/file.js";
|
|
8
9
|
|
|
9
10
|
console.log(`${kleur.bgGreen().bold("[Nurev]")}`);
|
|
10
11
|
console.log("Template generator 'on demanding revalidation' with Nuxt");
|
|
11
12
|
|
|
12
|
-
const
|
|
13
|
+
const questionsBase = [
|
|
13
14
|
{
|
|
14
15
|
type: "select",
|
|
15
16
|
name: "manager",
|
|
@@ -48,49 +49,88 @@ const questions = [
|
|
|
48
49
|
},
|
|
49
50
|
];
|
|
50
51
|
|
|
52
|
+
const questionsPocketbase = [
|
|
53
|
+
{
|
|
54
|
+
type: "text",
|
|
55
|
+
name: "admin",
|
|
56
|
+
message: "Email address to assign to the Pocketbase superadmin",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: "text",
|
|
60
|
+
style: "password",
|
|
61
|
+
name: "adminpassword",
|
|
62
|
+
message: "Password for superadmin",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: "text",
|
|
66
|
+
name: "user",
|
|
67
|
+
message: "Email for the API user",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: "text",
|
|
71
|
+
style: "password",
|
|
72
|
+
name: "userpassword",
|
|
73
|
+
message: "Password for API user",
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
|
|
51
77
|
(async () => {
|
|
52
|
-
const
|
|
78
|
+
const responseBase = await prompts(questionsBase);
|
|
53
79
|
|
|
54
|
-
if (Object.keys(
|
|
80
|
+
if (Object.keys(questionsBase).length !== Object.keys(responseBase).length) {
|
|
55
81
|
console.log("Script finished");
|
|
56
82
|
return;
|
|
57
83
|
}
|
|
58
84
|
|
|
59
|
-
const
|
|
60
|
-
new URL("./templates/base", import.meta.url),
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
new URL(`./templates/${response.backend}`, import.meta.url),
|
|
64
|
-
);
|
|
65
|
-
const templatePackageManager = fileURLToPath(
|
|
66
|
-
new URL(
|
|
67
|
-
`./templates/${response.backend}-${response.manager}`,
|
|
68
|
-
import.meta.url,
|
|
85
|
+
const paths = {
|
|
86
|
+
base: fileURLToPath(new URL("./templates/base", import.meta.url)),
|
|
87
|
+
backend: fileURLToPath(
|
|
88
|
+
new URL(`./templates/${responseBase.backend}`, import.meta.url),
|
|
69
89
|
),
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
90
|
+
packageManager: fileURLToPath(
|
|
91
|
+
new URL(
|
|
92
|
+
`./templates/${responseBase.backend}-${responseBase.manager}`,
|
|
93
|
+
import.meta.url,
|
|
94
|
+
),
|
|
95
|
+
),
|
|
96
|
+
destination: process.cwd(),
|
|
97
|
+
destinationEnvExample: process.cwd() + "/.env.example",
|
|
98
|
+
destinationEnv: process.cwd() + "/.env",
|
|
99
|
+
};
|
|
77
100
|
|
|
78
|
-
|
|
101
|
+
if (responseBase.backend === "pocketbase") {
|
|
102
|
+
const responsePocketbase = await prompts(questionsPocketbase);
|
|
79
103
|
|
|
80
|
-
|
|
81
|
-
|
|
104
|
+
if (
|
|
105
|
+
Object.keys(questionsPocketbase).length !==
|
|
106
|
+
Object.keys(responsePocketbase).length
|
|
107
|
+
) {
|
|
108
|
+
console.log("Script finished");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
82
111
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.bold(`Template ${response.backend}-${response.manager} ready`),
|
|
88
|
-
);
|
|
89
|
-
});
|
|
112
|
+
for (const key in responsePocketbase) {
|
|
113
|
+
responseBase[key] = responsePocketbase[key];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
90
116
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
117
|
+
try {
|
|
118
|
+
await fs.copy(paths.base, paths.destination);
|
|
119
|
+
await fs.copy(paths.backend, paths.destination);
|
|
120
|
+
await fs.copy(paths.packageManager, paths.destination);
|
|
121
|
+
await spawnPromise("/usr/bin/make", ["install"]);
|
|
122
|
+
await fs.copy(paths.destinationEnvExample, paths.destinationEnv);
|
|
123
|
+
switch (responseBase.backend) {
|
|
124
|
+
case "pocketbase":
|
|
125
|
+
await writeEnvFile(paths.destinationEnv, {
|
|
126
|
+
NUXT_POCKETBASE_USER: responseBase.user,
|
|
127
|
+
NUXT_POCKETBASE_PASSWORD: responseBase.userpassword,
|
|
128
|
+
NUXT_JWT_SECRET: Buffer.from(
|
|
129
|
+
crypto.getRandomValues(new Uint8Array(32)),
|
|
130
|
+
).toString("hex"),
|
|
131
|
+
});
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
94
134
|
} catch (error) {
|
|
95
135
|
console.log(error);
|
|
96
136
|
}
|
package/package.json
CHANGED
|
@@ -38,10 +38,8 @@ export const defineAuthResponseHandler = <T extends EventHandlerRequest, D>(
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const response = await handler(event);
|
|
41
|
-
// do something after the route handler
|
|
42
41
|
return { response };
|
|
43
42
|
} catch (err) {
|
|
44
|
-
// Error handling
|
|
45
43
|
return { err };
|
|
46
44
|
}
|
|
47
45
|
});
|
|
@@ -9,7 +9,7 @@ Tech stack:
|
|
|
9
9
|
|
|
10
10
|
## Setup
|
|
11
11
|
|
|
12
|
-
1.
|
|
12
|
+
1. Check if your `.env` file is correct
|
|
13
13
|
|
|
14
14
|
- `TABLES_TRIGGER`: collections that trigger the Nuxt cache to be cleared when collections are updated, a new row is added or a row is removed
|
|
15
15
|
- **Example**
|
|
@@ -31,17 +31,17 @@ Tech stack:
|
|
|
31
31
|
```bash
|
|
32
32
|
NUXT_POCKETBASE_URL=http://localhost:8090
|
|
33
33
|
```
|
|
34
|
-
- `NUXT_POCKETBASE_USER`: PocketBase user created in `user` collection for login to the API
|
|
34
|
+
- `NUXT_POCKETBASE_USER`: PocketBase user created in `user` collection for login to the API (requested)
|
|
35
35
|
- **Example**
|
|
36
36
|
```bash
|
|
37
37
|
NUXT_POCKETBASE_USER=paco@paco.me
|
|
38
38
|
```
|
|
39
|
-
- `NUXT_POCKETBASE_PASSWORD`: PocketBase password user created in `user` collection for login to the API
|
|
39
|
+
- `NUXT_POCKETBASE_PASSWORD`: PocketBase password user created in `user` collection for login to the API (requested)
|
|
40
40
|
- **Example**
|
|
41
41
|
```bash
|
|
42
42
|
NUXT_POCKETBASE_PASSWORD=secretpassword
|
|
43
43
|
```
|
|
44
|
-
- `NUXT_JWT_SECRET`: JWT secret for signing and validating tokens
|
|
44
|
+
- `NUXT_JWT_SECRET`: JWT secret for signing and validating tokens (autogenerated)
|
|
45
45
|
- **Example**
|
|
46
46
|
```bash
|
|
47
47
|
NUXT_JWT_SECRET=secretjwt
|
|
@@ -63,9 +63,11 @@ make backend-dev
|
|
|
63
63
|
|
|
64
64
|
5. Create a user inside `users` collection with the same values inside `NUXT_POCKETBASE_USER` and `NUXT_POCKETBASE_PASSWORD`
|
|
65
65
|
|
|
66
|
-
6. Create a collection named `posts` and
|
|
66
|
+
6. Create a collection named `posts` and change API Rules for give permissions with `@request.auth.id != ""`
|
|
67
67
|
|
|
68
|
-
7.
|
|
68
|
+
7. Create a new post
|
|
69
|
+
|
|
70
|
+
8. Start frontend dev mode
|
|
69
71
|
|
|
70
72
|
```bash
|
|
71
73
|
make frontend-dev
|
package/utils/cmd.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
|
|
3
|
+
export function spawnPromise(command, args) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const processChild = spawn(command, args);
|
|
6
|
+
|
|
7
|
+
processChild.stdout.pipe(process.stdout);
|
|
8
|
+
processChild.stderr.pipe(process.stderr);
|
|
9
|
+
|
|
10
|
+
processChild.on("close", (code) => {
|
|
11
|
+
if (code === 0) {
|
|
12
|
+
resolve({ code });
|
|
13
|
+
} else {
|
|
14
|
+
reject(new Error(`Process exited with code ${code}`));
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
processChild.on("error", (err) => {
|
|
19
|
+
console.error(`Error: `, err);
|
|
20
|
+
reject(err);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
package/utils/file.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { default as fs } from "fs-extra";
|
|
2
|
+
|
|
3
|
+
export function writeEnvFile(filePath, params) {
|
|
4
|
+
return new Promise(async (resolve, reject) => {
|
|
5
|
+
try {
|
|
6
|
+
let content = await fs.readFile(filePath, "utf8");
|
|
7
|
+
|
|
8
|
+
for (const key in params) {
|
|
9
|
+
const value = params[key];
|
|
10
|
+
const regex = new RegExp(`^${key}=.*`, "m");
|
|
11
|
+
|
|
12
|
+
if (regex.test(content) === true) {
|
|
13
|
+
content = content.replace(regex, `${key}=${value}`);
|
|
14
|
+
} else {
|
|
15
|
+
reject(new Error(`Param ${key} not found inside .env`));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
await fs.writeFile(filePath, content, `utf8`);
|
|
20
|
+
resolve();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error(error);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|