nurev 0.0.8 → 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/README.md +52 -0
- package/bun.lock +84 -0
- package/index.js +16 -72
- package/package.json +3 -1
- package/templates/base/frontend/bun.lock +1480 -0
- package/templates/base/frontend/package.json +1 -1
- package/templates/base/frontend/server/plugins/pocketbase.ts +4 -1
- package/templates/pocketbase/.env.example +1 -1
- package/templates/pocketbase/README.md +8 -10
- package/templates/pocketbase/backend/go.mod +4 -4
- package/templates/pocketbase/backend/go.sum +8 -0
- package/templates/pocketbase-bun/Makefile +4 -4
- package/utils/sqlite.js +33 -0
- package/workflows/pocketbase/index.js +111 -0
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@ Template generator for [Nuxt](https://nuxt.com/) configured with “on-demand re
|
|
|
12
12
|
|
|
13
13
|
## How to use it?
|
|
14
14
|
|
|
15
|
+
1. Run the script
|
|
16
|
+
|
|
15
17
|
```bash
|
|
16
18
|
bunx nurev
|
|
17
19
|
```
|
|
@@ -23,3 +25,53 @@ npx nurev
|
|
|
23
25
|
```bash
|
|
24
26
|
pnpm dlx nurev
|
|
25
27
|
```
|
|
28
|
+
|
|
29
|
+
2. After the script completes, start the backend in dev mode
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
make backend-dev
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
3. Then start frontend in dev mode
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
make frontend-dev
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## How it works?
|
|
42
|
+
|
|
43
|
+
1. **Interactive prompts**: Asks you to choose a package manager (`bun`, `npm`, or `pnpm`) and a backend (`PocketBase`)
|
|
44
|
+
2. **Template copying**: Copies the base Nuxt template, backend-specific files, and package-manager-specific configuration to your current directory
|
|
45
|
+
3. **Installation & setup**: Runs `make install` to install dependencies and `make setup` to initialize the project
|
|
46
|
+
4. **Backend configuration**: Applies backend-specific setup (e.g., PocketBase configuration)
|
|
47
|
+
5. **Ready to use**: Your Nuxt project with on-demand revalidation is ready
|
|
48
|
+
|
|
49
|
+
## On-Demand Revalidation
|
|
50
|
+
|
|
51
|
+
The caching system uses a webhook pattern between PocketBase and Nuxt:
|
|
52
|
+
|
|
53
|
+
1. **Cache storage**: Nuxt routes use `defineCachedEventHandler` with `swr: true` (stale-while-revalidate) and `maxAge: 604800` (1 week). Route rules set `prerender: true` for `/` and `swr: true` for `/posts/**`
|
|
54
|
+
|
|
55
|
+
2. **Backend hooks**: Backend (PocketBase) registers hooks on `OnRecordAfterCreateSuccess`, `OnRecordAfterUpdateSuccess`, `OnRecordAfterDeleteSuccess`, `OnBackupCreate` and `OnBackupRestore` for collections defined in `TABLES_TRIGGER`
|
|
56
|
+
|
|
57
|
+
3. **Webhook notification**: When a record changes, PocketBase sends an authenticated POST (JWT Bearer token) to `/api/private/reloadcache` with the table name and record ID
|
|
58
|
+
|
|
59
|
+
4. **Selective invalidation**: The Nuxt endpoint validates the JWT and uses `useStorage("cache")` to remove only cache entries matching the changed table and record ID. Backup events trigger a full cache clear
|
|
60
|
+
|
|
61
|
+
5. **Next request**: Subsequent requests fetch fresh data and repopulate the cache
|
|
62
|
+
|
|
63
|
+
## Pros and Cons
|
|
64
|
+
|
|
65
|
+
### Pros
|
|
66
|
+
|
|
67
|
+
- ⚡ **Performance**: Cached responses are served instantly without hitting the database on each request
|
|
68
|
+
- 📉 **Reduced backend load**: Fewer API calls to PocketBase, lowering server resource usage
|
|
69
|
+
- 🔄 **Fresh data on demand**: Cache is invalidated only when data actually changes, avoiding stale content
|
|
70
|
+
- 🚀 **Scalability**: SWR (stale-while-revalidate) serves cached content while refreshing in the background, keeping response times low under high traffic
|
|
71
|
+
|
|
72
|
+
### Cons
|
|
73
|
+
|
|
74
|
+
- 🔗 **Tight coupling**: The backend must know the frontend URL and send webhooks, creating a dependency between services
|
|
75
|
+
- 🌐 **Network reliability**: If the webhook fails to reach Nuxt (network issues, downtime), the cache won't be invalidated and stale data persists
|
|
76
|
+
- 🖥️ **Single-server limitation**: Cache is stored in-memory/local storage, so this approach doesn't work well with multi-instance deployments without a shared cache layer (e.g., Redis)
|
|
77
|
+
- ⚙️ **Complexity**: Requires configuring JWT secrets, environment variables, and ensuring both services are running and communicating correctly
|
package/bun.lock
CHANGED
|
@@ -5,24 +5,108 @@
|
|
|
5
5
|
"": {
|
|
6
6
|
"name": "nurev",
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"bcrypt": "^6.0.0",
|
|
9
|
+
"better-sqlite3": "^12.8.0",
|
|
8
10
|
"fs-extra": "^11.3.4",
|
|
9
11
|
"prompts": "^2.4.2",
|
|
10
12
|
},
|
|
11
13
|
},
|
|
12
14
|
},
|
|
13
15
|
"packages": {
|
|
16
|
+
"base64-js": ["base64-js@1.5.1", "", {}, "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="],
|
|
17
|
+
|
|
18
|
+
"bcrypt": ["bcrypt@6.0.0", "", { "dependencies": { "node-addon-api": "^8.3.0", "node-gyp-build": "^4.8.4" } }, "sha512-cU8v/EGSrnH+HnxV2z0J7/blxH8gq7Xh2JFT6Aroax7UohdmiJJlxApMxtKfuI7z68NvvVcmR78k2LbT6efhRg=="],
|
|
19
|
+
|
|
20
|
+
"better-sqlite3": ["better-sqlite3@12.8.0", "", { "dependencies": { "bindings": "^1.5.0", "prebuild-install": "^7.1.1" } }, "sha512-RxD2Vd96sQDjQr20kdP+F+dK/1OUNiVOl200vKBZY8u0vTwysfolF6Hq+3ZK2+h8My9YvZhHsF+RSGZW2VYrPQ=="],
|
|
21
|
+
|
|
22
|
+
"bindings": ["bindings@1.5.0", "", { "dependencies": { "file-uri-to-path": "1.0.0" } }, "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ=="],
|
|
23
|
+
|
|
24
|
+
"bl": ["bl@4.1.0", "", { "dependencies": { "buffer": "^5.5.0", "inherits": "^2.0.4", "readable-stream": "^3.4.0" } }, "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w=="],
|
|
25
|
+
|
|
26
|
+
"buffer": ["buffer@5.7.1", "", { "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.1.13" } }, "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ=="],
|
|
27
|
+
|
|
28
|
+
"chownr": ["chownr@1.1.4", "", {}, "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg=="],
|
|
29
|
+
|
|
30
|
+
"decompress-response": ["decompress-response@6.0.0", "", { "dependencies": { "mimic-response": "^3.1.0" } }, "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ=="],
|
|
31
|
+
|
|
32
|
+
"deep-extend": ["deep-extend@0.6.0", "", {}, "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA=="],
|
|
33
|
+
|
|
34
|
+
"detect-libc": ["detect-libc@2.1.2", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="],
|
|
35
|
+
|
|
36
|
+
"end-of-stream": ["end-of-stream@1.4.5", "", { "dependencies": { "once": "^1.4.0" } }, "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg=="],
|
|
37
|
+
|
|
38
|
+
"expand-template": ["expand-template@2.0.3", "", {}, "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg=="],
|
|
39
|
+
|
|
40
|
+
"file-uri-to-path": ["file-uri-to-path@1.0.0", "", {}, "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="],
|
|
41
|
+
|
|
42
|
+
"fs-constants": ["fs-constants@1.0.0", "", {}, "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow=="],
|
|
43
|
+
|
|
14
44
|
"fs-extra": ["fs-extra@11.3.4", "", { "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" } }, "sha512-CTXd6rk/M3/ULNQj8FBqBWHYBVYybQ3VPBw0xGKFe3tuH7ytT6ACnvzpIQ3UZtB8yvUKC2cXn1a+x+5EVQLovA=="],
|
|
15
45
|
|
|
46
|
+
"github-from-package": ["github-from-package@0.0.0", "", {}, "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw=="],
|
|
47
|
+
|
|
16
48
|
"graceful-fs": ["graceful-fs@4.2.11", "", {}, "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="],
|
|
17
49
|
|
|
50
|
+
"ieee754": ["ieee754@1.2.1", "", {}, "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="],
|
|
51
|
+
|
|
52
|
+
"inherits": ["inherits@2.0.4", "", {}, "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="],
|
|
53
|
+
|
|
54
|
+
"ini": ["ini@1.3.8", "", {}, "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew=="],
|
|
55
|
+
|
|
18
56
|
"jsonfile": ["jsonfile@6.2.0", "", { "dependencies": { "universalify": "^2.0.0" }, "optionalDependencies": { "graceful-fs": "^4.1.6" } }, "sha512-FGuPw30AdOIUTRMC2OMRtQV+jkVj2cfPqSeWXv1NEAJ1qZ5zb1X6z1mFhbfOB/iy3ssJCD+3KuZ8r8C3uVFlAg=="],
|
|
19
57
|
|
|
20
58
|
"kleur": ["kleur@3.0.3", "", {}, "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w=="],
|
|
21
59
|
|
|
60
|
+
"mimic-response": ["mimic-response@3.1.0", "", {}, "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ=="],
|
|
61
|
+
|
|
62
|
+
"minimist": ["minimist@1.2.8", "", {}, "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="],
|
|
63
|
+
|
|
64
|
+
"mkdirp-classic": ["mkdirp-classic@0.5.3", "", {}, "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A=="],
|
|
65
|
+
|
|
66
|
+
"napi-build-utils": ["napi-build-utils@2.0.0", "", {}, "sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA=="],
|
|
67
|
+
|
|
68
|
+
"node-abi": ["node-abi@3.89.0", "", { "dependencies": { "semver": "^7.3.5" } }, "sha512-6u9UwL0HlAl21+agMN3YAMXcKByMqwGx+pq+P76vii5f7hTPtKDp08/H9py6DY+cfDw7kQNTGEj/rly3IgbNQA=="],
|
|
69
|
+
|
|
70
|
+
"node-addon-api": ["node-addon-api@8.7.0", "", {}, "sha512-9MdFxmkKaOYVTV+XVRG8ArDwwQ77XIgIPyKASB1k3JPq3M8fGQQQE3YpMOrKm6g//Ktx8ivZr8xo1Qmtqub+GA=="],
|
|
71
|
+
|
|
72
|
+
"node-gyp-build": ["node-gyp-build@4.8.4", "", { "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", "node-gyp-build-test": "build-test.js" } }, "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ=="],
|
|
73
|
+
|
|
74
|
+
"once": ["once@1.4.0", "", { "dependencies": { "wrappy": "1" } }, "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w=="],
|
|
75
|
+
|
|
76
|
+
"prebuild-install": ["prebuild-install@7.1.3", "", { "dependencies": { "detect-libc": "^2.0.0", "expand-template": "^2.0.3", "github-from-package": "0.0.0", "minimist": "^1.2.3", "mkdirp-classic": "^0.5.3", "napi-build-utils": "^2.0.0", "node-abi": "^3.3.0", "pump": "^3.0.0", "rc": "^1.2.7", "simple-get": "^4.0.0", "tar-fs": "^2.0.0", "tunnel-agent": "^0.6.0" }, "bin": { "prebuild-install": "bin.js" } }, "sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug=="],
|
|
77
|
+
|
|
22
78
|
"prompts": ["prompts@2.4.2", "", { "dependencies": { "kleur": "^3.0.3", "sisteransi": "^1.0.5" } }, "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q=="],
|
|
23
79
|
|
|
80
|
+
"pump": ["pump@3.0.4", "", { "dependencies": { "end-of-stream": "^1.1.0", "once": "^1.3.1" } }, "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA=="],
|
|
81
|
+
|
|
82
|
+
"rc": ["rc@1.2.8", "", { "dependencies": { "deep-extend": "^0.6.0", "ini": "~1.3.0", "minimist": "^1.2.0", "strip-json-comments": "~2.0.1" }, "bin": { "rc": "./cli.js" } }, "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw=="],
|
|
83
|
+
|
|
84
|
+
"readable-stream": ["readable-stream@3.6.2", "", { "dependencies": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", "util-deprecate": "^1.0.1" } }, "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA=="],
|
|
85
|
+
|
|
86
|
+
"safe-buffer": ["safe-buffer@5.2.1", "", {}, "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="],
|
|
87
|
+
|
|
88
|
+
"semver": ["semver@7.7.4", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA=="],
|
|
89
|
+
|
|
90
|
+
"simple-concat": ["simple-concat@1.0.1", "", {}, "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q=="],
|
|
91
|
+
|
|
92
|
+
"simple-get": ["simple-get@4.0.1", "", { "dependencies": { "decompress-response": "^6.0.0", "once": "^1.3.1", "simple-concat": "^1.0.0" } }, "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA=="],
|
|
93
|
+
|
|
24
94
|
"sisteransi": ["sisteransi@1.0.5", "", {}, "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg=="],
|
|
25
95
|
|
|
96
|
+
"string_decoder": ["string_decoder@1.3.0", "", { "dependencies": { "safe-buffer": "~5.2.0" } }, "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA=="],
|
|
97
|
+
|
|
98
|
+
"strip-json-comments": ["strip-json-comments@2.0.1", "", {}, "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ=="],
|
|
99
|
+
|
|
100
|
+
"tar-fs": ["tar-fs@2.1.4", "", { "dependencies": { "chownr": "^1.1.1", "mkdirp-classic": "^0.5.2", "pump": "^3.0.0", "tar-stream": "^2.1.4" } }, "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ=="],
|
|
101
|
+
|
|
102
|
+
"tar-stream": ["tar-stream@2.2.0", "", { "dependencies": { "bl": "^4.0.3", "end-of-stream": "^1.4.1", "fs-constants": "^1.0.0", "inherits": "^2.0.3", "readable-stream": "^3.1.1" } }, "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ=="],
|
|
103
|
+
|
|
104
|
+
"tunnel-agent": ["tunnel-agent@0.6.0", "", { "dependencies": { "safe-buffer": "^5.0.1" } }, "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w=="],
|
|
105
|
+
|
|
26
106
|
"universalify": ["universalify@2.0.1", "", {}, "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw=="],
|
|
107
|
+
|
|
108
|
+
"util-deprecate": ["util-deprecate@1.0.2", "", {}, "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="],
|
|
109
|
+
|
|
110
|
+
"wrappy": ["wrappy@1.0.2", "", {}, "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="],
|
|
27
111
|
}
|
|
28
112
|
}
|
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { default as prompts } from "prompts";
|
|
|
5
5
|
import { default as fs } from "fs-extra";
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
7
|
import { spawnPromise } from "./utils/cmd.js";
|
|
8
|
-
import {
|
|
8
|
+
import { setup as setupPocketbase } from "./workflows/pocketbase/index.js";
|
|
9
9
|
|
|
10
10
|
console.log(`\n${kleur.bgGreen().bold("🚀NUREV🚀")}`);
|
|
11
11
|
console.log("Template generator 'on demanding revalidation' with Nuxt\n");
|
|
@@ -49,35 +49,6 @@ const questionsBase = [
|
|
|
49
49
|
},
|
|
50
50
|
];
|
|
51
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
|
-
validate: (password) =>
|
|
64
|
-
password.length > 7 ? true : `8 characters needed or more`,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
type: "text",
|
|
68
|
-
name: "user",
|
|
69
|
-
message: "Email for the API user",
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
type: "text",
|
|
73
|
-
style: "password",
|
|
74
|
-
name: "userpassword",
|
|
75
|
-
message: "Password for API user",
|
|
76
|
-
validate: (userpassword) =>
|
|
77
|
-
userpassword.length > 7 ? true : `8 characters needed or more`,
|
|
78
|
-
},
|
|
79
|
-
];
|
|
80
|
-
|
|
81
52
|
(async () => {
|
|
82
53
|
const responseBase = await prompts(questionsBase);
|
|
83
54
|
|
|
@@ -87,16 +58,18 @@ const questionsPocketbase = [
|
|
|
87
58
|
}
|
|
88
59
|
|
|
89
60
|
const paths = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
61
|
+
templates: {
|
|
62
|
+
base: fileURLToPath(new URL("./templates/base", import.meta.url)),
|
|
63
|
+
backend: fileURLToPath(
|
|
64
|
+
new URL(`./templates/${responseBase.backend}`, import.meta.url),
|
|
65
|
+
),
|
|
66
|
+
packageManager: fileURLToPath(
|
|
67
|
+
new URL(
|
|
68
|
+
`./templates/${responseBase.backend}-${responseBase.manager}`,
|
|
69
|
+
import.meta.url,
|
|
70
|
+
),
|
|
98
71
|
),
|
|
99
|
-
|
|
72
|
+
},
|
|
100
73
|
destination: {
|
|
101
74
|
base: process.cwd(),
|
|
102
75
|
env: `${process.cwd()}/.env`,
|
|
@@ -104,45 +77,16 @@ const questionsPocketbase = [
|
|
|
104
77
|
},
|
|
105
78
|
};
|
|
106
79
|
|
|
107
|
-
if (responseBase.backend === "pocketbase") {
|
|
108
|
-
const responsePocketbase = await prompts(questionsPocketbase);
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
Object.keys(questionsPocketbase).length !==
|
|
112
|
-
Object.keys(responsePocketbase).length
|
|
113
|
-
) {
|
|
114
|
-
console.log("Script finished");
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
for (const key in responsePocketbase) {
|
|
119
|
-
responseBase[key] = responsePocketbase[key];
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
80
|
try {
|
|
124
|
-
await fs.copy(paths.base, paths.destination.base);
|
|
125
|
-
await fs.copy(paths.backend, paths.destination.base);
|
|
126
|
-
await fs.copy(paths.packageManager, paths.destination.base);
|
|
81
|
+
await fs.copy(paths.templates.base, paths.destination.base);
|
|
82
|
+
await fs.copy(paths.templates.backend, paths.destination.base);
|
|
83
|
+
await fs.copy(paths.templates.packageManager, paths.destination.base);
|
|
127
84
|
await spawnPromise("make", ["install"]);
|
|
128
85
|
await fs.copy(paths.destination.envExample, paths.destination.env);
|
|
129
86
|
await spawnPromise("make", ["setup"]);
|
|
130
87
|
switch (responseBase.backend) {
|
|
131
88
|
case "pocketbase":
|
|
132
|
-
await
|
|
133
|
-
NUXT_POCKETBASE_USER: responseBase.user,
|
|
134
|
-
NUXT_POCKETBASE_PASSWORD: responseBase.userpassword,
|
|
135
|
-
NUXT_JWT_SECRET: Buffer.from(
|
|
136
|
-
crypto.getRandomValues(new Uint8Array(32)),
|
|
137
|
-
).toString("hex"),
|
|
138
|
-
});
|
|
139
|
-
await spawnPromise("make", [
|
|
140
|
-
"-s",
|
|
141
|
-
"backend-superuser",
|
|
142
|
-
`email=${responseBase.admin}`,
|
|
143
|
-
`password=${responseBase.adminpassword}`,
|
|
144
|
-
]);
|
|
145
|
-
//TODO: ADD USERAPI AND POSTS TABLE
|
|
89
|
+
await setupPocketbase(paths);
|
|
146
90
|
break;
|
|
147
91
|
}
|
|
148
92
|
console.log("\n🎉 Your template is ready! 🎉\n");
|