@seip/bluebird-js 0.1.6 → 0.2.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.
Files changed (152) hide show
  1. package/.vscode/extensions.json +7 -7
  2. package/.vscode/settings.json +10 -10
  3. package/AGENTS.md +266 -116
  4. package/README.md +258 -245
  5. package/app/models/user.js +19 -0
  6. package/app/resources/html/home.html +137 -0
  7. package/app/resources/html/layouts/main.html +54 -0
  8. package/app/resources/html/notFound.html +14 -0
  9. package/app/resources/html/terms.html +46 -0
  10. package/app/resources/index.html +27 -0
  11. package/app/resources/layouts/AppLayout.jsx +89 -0
  12. package/app/resources/main.jsx +18 -0
  13. package/app/resources/pages/Dashboard.jsx +98 -0
  14. package/app/resources/pages/Home.jsx +140 -0
  15. package/app/resources/pages/Login.jsx +35 -0
  16. package/app/resources/pages/NotFound.jsx +16 -0
  17. package/app/resources/pages/Register.jsx +55 -0
  18. package/app/resources/routes.jsx +54 -0
  19. package/app/resources/spa.js +67 -0
  20. package/app/resources/styles.css +9 -0
  21. package/app/routes/api.js +85 -50
  22. package/app/routes/auth.js +209 -0
  23. package/app/routes/web.js +49 -37
  24. package/core/ai.d.ts +151 -151
  25. package/core/ai.js +1071 -1051
  26. package/core/app.d.ts +2 -18
  27. package/core/app.js +978 -792
  28. package/core/auth.d.ts +2 -13
  29. package/core/auth.js +444 -326
  30. package/core/cli/backup.js +167 -167
  31. package/core/cli/build.js +37 -0
  32. package/core/cli/dev.js +155 -0
  33. package/core/cli/doctor.js +37 -2
  34. package/core/cli/export.js +191 -0
  35. package/core/cli/init.js +101 -332
  36. package/core/cli/nginx.js +1 -1
  37. package/core/cli/templates.js +139 -0
  38. package/core/cli/view.js +73 -136
  39. package/core/config.js +44 -2
  40. package/core/csrf.js +156 -24
  41. package/core/database.js +737 -684
  42. package/core/debug.js +1 -1
  43. package/core/html.js +8 -1
  44. package/core/index.d.ts +1286 -1431
  45. package/core/paths.js +55 -0
  46. package/core/ratelimit.js +10 -1
  47. package/core/react/client/api.js +237 -0
  48. package/core/react/client/auth.js +236 -0
  49. package/core/react/client/components.js +1321 -0
  50. package/core/react/client/i18n.js +338 -0
  51. package/core/react/client/index.d.ts +249 -0
  52. package/core/react/client/index.js +49 -0
  53. package/core/react/client/router.js +26 -0
  54. package/core/react/client/theme.css +512 -0
  55. package/core/render-cache.js +250 -212
  56. package/core/render.d.ts +25 -21
  57. package/core/render.js +613 -603
  58. package/core/router.d.ts +2 -3
  59. package/core/router.js +171 -171
  60. package/core/seo.js +10 -0
  61. package/core/spa.js +599 -0
  62. package/core/view-loader.js +81 -455
  63. package/core/vite-plugin.d.ts +18 -0
  64. package/core/vite-plugin.js +162 -0
  65. package/core/vite.js +250 -145
  66. package/index.js +22 -18
  67. package/jsconfig.json +5 -3
  68. package/package.json +114 -92
  69. package/production.md +8 -3
  70. package/public/js/bluebird.js +1160 -0
  71. package/templates/_auth/app/database.js +19 -0
  72. package/templates/_auth/app/models/user.js +22 -0
  73. package/templates/_auth/app/routes/auth-router.js +304 -0
  74. package/templates/_base/app/resources/html/layouts/main.html +55 -0
  75. package/templates/_base/app/resources/html/notFound.html +14 -0
  76. package/templates/_base/app/resources/index.html +27 -0
  77. package/templates/_base/app/resources/styles.css +9 -0
  78. package/templates/api/app/models/note.js +18 -0
  79. package/templates/api/app/routes/api.js +82 -0
  80. package/templates/api/app/routes/auth.js +11 -0
  81. package/templates/api/index.js +19 -0
  82. package/templates/api/template.json +13 -0
  83. package/templates/auth/app/mail.js +11 -0
  84. package/templates/auth/app/models/password_reset.js +18 -0
  85. package/templates/auth/app/resources/html/home.html +21 -0
  86. package/templates/auth/app/resources/html/partials/nav.html +2 -0
  87. package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
  88. package/templates/auth/app/resources/main.jsx +18 -0
  89. package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
  90. package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
  91. package/templates/auth/app/resources/pages/Login.jsx +36 -0
  92. package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
  93. package/templates/auth/app/resources/pages/Profile.jsx +99 -0
  94. package/templates/auth/app/resources/pages/Register.jsx +50 -0
  95. package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
  96. package/templates/auth/app/resources/routes.jsx +54 -0
  97. package/templates/auth/app/resources/spa.js +29 -0
  98. package/templates/auth/app/routes/api.js +17 -0
  99. package/templates/auth/app/routes/auth.js +13 -0
  100. package/templates/auth/app/routes/web.js +21 -0
  101. package/templates/auth/index.js +19 -0
  102. package/templates/auth/template.json +15 -0
  103. package/templates/blank/app/models/.gitkeep +0 -0
  104. package/templates/blank/app/resources/html/home.html +27 -0
  105. package/templates/blank/app/resources/html/partials/nav.html +1 -0
  106. package/templates/blank/app/resources/main.jsx +16 -0
  107. package/templates/blank/app/resources/pages/Home.jsx +42 -0
  108. package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
  109. package/templates/blank/app/resources/routes.jsx +15 -0
  110. package/templates/blank/app/resources/spa.js +24 -0
  111. package/templates/blank/app/routes/api.js +11 -0
  112. package/templates/blank/app/routes/web.js +21 -0
  113. package/templates/blank/index.js +13 -0
  114. package/templates/blank/template.json +12 -0
  115. package/templates/blog/app/lib/blog.js +149 -0
  116. package/templates/blog/app/models/post.js +22 -0
  117. package/templates/blog/app/resources/html/home.html +28 -0
  118. package/templates/blog/app/resources/html/not-found.html +5 -0
  119. package/templates/blog/app/resources/html/partials/nav.html +2 -0
  120. package/templates/blog/app/resources/html/partials/post-card.html +9 -0
  121. package/templates/blog/app/resources/html/post.html +8 -0
  122. package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
  123. package/templates/blog/app/resources/main.jsx +18 -0
  124. package/templates/blog/app/resources/pages/Login.jsx +31 -0
  125. package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
  126. package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
  127. package/templates/blog/app/resources/pages/Posts.jsx +83 -0
  128. package/templates/blog/app/resources/pages/Register.jsx +43 -0
  129. package/templates/blog/app/resources/routes.jsx +51 -0
  130. package/templates/blog/app/resources/spa.js +25 -0
  131. package/templates/blog/app/resources/styles.css +40 -0
  132. package/templates/blog/app/routes/api.js +77 -0
  133. package/templates/blog/app/routes/auth.js +10 -0
  134. package/templates/blog/app/routes/web.js +114 -0
  135. package/templates/blog/index.js +21 -0
  136. package/templates/blog/template.json +14 -0
  137. package/vite.config.js +11 -0
  138. package/app/views/about.jsx +0 -98
  139. package/app/views/components/Header.jsx +0 -42
  140. package/app/views/components/LiveCounter.jsx +0 -66
  141. package/app/views/dashboard.jsx +0 -300
  142. package/app/views/index.jsx +0 -123
  143. package/app/views/layouts/main/view.jsx +0 -201
  144. package/app/views/legal/terms.html +0 -29
  145. package/app/views/login.jsx +0 -141
  146. package/core/actions.d.ts +0 -4
  147. package/core/actions.js +0 -329
  148. package/core/jsx.d.ts +0 -38
  149. package/core/jsx.js +0 -1432
  150. package/core/vite.d.ts +0 -3
  151. package/public/js/bluebird-client.js +0 -3161
  152. package/public/js/tailwind.js +0 -8
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { pathToFileURL } from "node:url";
6
+ import colors from "../util/colors.js";
7
+
8
+ try {
9
+ process.loadEnvFile?.();
10
+ } catch {}
11
+
12
+ const PROTECTED_DIRS = new Set(["app", "core", "public", "node_modules", "database", ".git"]);
13
+ const HELP = `Usage: npx bluebird-js export [options]
14
+
15
+ Builds the React SPA (app/resources/) into a 100% static HTML/JS/CSS folder for Electron, Capacitor,
16
+ Tauri, or any static host. The same index.html shell, spa.js metadata, and React code used by router.spa().
17
+
18
+ Options:
19
+ --out <dir> Output directory (default: dist/client)
20
+ --api <url> API server URL used by api() (default: EXPORT_API_URL or APP_URL from .env)
21
+ --router <mode> hash | browser | memory (default: hash, works with file://)
22
+ --base <path> Asset base URL (default: ./ for hash/memory, / for browser)
23
+ --basename <path> Browser router basename (default: /)
24
+ --auth <mode> token | cookie (default: token, Authorization: Bearer)
25
+ --config <file> SPA config module (default: app/resources/spa.js)
26
+ --no-public Do not copy public/ into the output directory`;
27
+
28
+ /**
29
+ * Parses `--flag value` and `--flag=value` CLI arguments.
30
+ * @param {string[]} argv
31
+ * @returns {Record<string, string|boolean>}
32
+ */
33
+ function parseArgs(argv) {
34
+ const out = {};
35
+ for (let i = 0; i < argv.length; i++) {
36
+ const arg = argv[i];
37
+ if (!arg.startsWith("--")) continue;
38
+ const [key, inline] = arg.slice(2).split("=");
39
+ if (inline !== undefined) out[key] = inline;
40
+ else if (argv[i + 1] && !argv[i + 1].startsWith("--")) out[key] = argv[++i];
41
+ else out[key] = true;
42
+ }
43
+ return out;
44
+ }
45
+
46
+ /**
47
+ * Rejects output directories that would wipe the project or its sources when emptied.
48
+ * @param {string} root
49
+ * @param {string} outDir
50
+ */
51
+ function assertSafeOutDir(root, outDir) {
52
+ const rel = path.relative(root, outDir);
53
+ const isAncestor = root === outDir || root.startsWith(outDir + path.sep);
54
+ const first = rel.split(/[\\/]/)[0];
55
+ if (rel === "" || isAncestor || PROTECTED_DIRS.has(first)) {
56
+ throw new Error(`Refusing to export into '${outDir}': choose a dedicated folder such as dist/client.`);
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Loads the SPA configuration module (default export) when present.
62
+ * @param {string} file
63
+ * @returns {Promise<Object|null>}
64
+ */
65
+ async function loadSpaConfig(file) {
66
+ if (!fs.existsSync(file)) return null;
67
+ const mod = await import(pathToFileURL(file).href);
68
+ return mod.default || mod.spa || null;
69
+ }
70
+
71
+ /**
72
+ * Rewrites root-absolute `src` / `href` attributes (e.g. `/images/favicon.ico`) to the export base.
73
+ * @param {string} html
74
+ * @param {string} base
75
+ * @returns {string}
76
+ */
77
+ function rebaseLocalUrls(html, base) {
78
+ if (base === "/") return html;
79
+ return html.replace(/(\s(?:src|href)=["'])\/(?!\/)/g, `$1${base}`);
80
+ }
81
+
82
+ /**
83
+ * `npx bluebird-js export`: static client build of the React SPA.
84
+ */
85
+ async function exportSpa() {
86
+ const args = parseArgs(process.argv.slice(3));
87
+ if (args.help || args.h) {
88
+ console.log(HELP);
89
+ return;
90
+ }
91
+
92
+ delete process.env.DEBUG;
93
+ process.env.NODE_ENV = process.env.NODE_ENV || "production";
94
+
95
+ const root = process.cwd();
96
+ const { default: ViteBridge } = await import("../vite.js");
97
+ const { PATHS } = await import("../paths.js");
98
+ const { compileMetaTree, renderSpaDocument, resolveSpaMeta, spaAssetEntries } = await import("../spa.js");
99
+ delete process.env.DEBUG;
100
+
101
+ const router = ["hash", "browser", "memory"].includes(args.router) ? args.router : "hash";
102
+ const base = typeof args.base === "string" ? args.base.replace(/\/?$/, "/") : router === "browser" ? "/" : "./";
103
+ const auth = args.auth === "cookie" ? "cookie" : "token";
104
+ const apiUrl = String(
105
+ (typeof args.api === "string" && args.api) || process.env.EXPORT_API_URL || process.env.APP_URL || ""
106
+ ).replace(/\/+$/, "");
107
+ const outDir = path.resolve(root, typeof args.out === "string" ? args.out : "dist/client");
108
+ assertSafeOutDir(root, outDir);
109
+
110
+ const configFile = path.resolve(root, typeof args.config === "string" ? args.config : PATHS.spaConfig);
111
+ const options = (await loadSpaConfig(configFile)) || {};
112
+ if (!fs.existsSync(configFile)) {
113
+ console.log(colors.yellow(`[WARN] ${path.relative(root, configFile)} not found: exporting with index.html defaults only.`));
114
+ }
115
+
116
+ const mount = options.mount || "/";
117
+ const compiled = compileMetaTree(options.meta || {}, mount);
118
+ const stubReq = { params: {}, query: {}, headers: {}, cookies: {}, path: mount, lang: options.lang || "en" };
119
+ let merged;
120
+ try {
121
+ merged = await resolveSpaMeta(options, compiled, "/", stubReq);
122
+ } catch (err) {
123
+ console.log(colors.yellow(`[WARN] Dynamic meta for '/' failed (${err.message}); using base options.`));
124
+ merged = await resolveSpaMeta(options, { wildcard: null, routes: [] }, "/", stubReq);
125
+ }
126
+ merged.canonical = typeof merged.canonical === "string" ? merged.canonical : false;
127
+
128
+ const entries = spaAssetEntries(merged, root);
129
+ const missing = entries.filter((rel) => !fs.existsSync(path.join(root, rel)));
130
+ if (missing.length > 0) {
131
+ throw new Error(`Missing SPA entry files: ${missing.join(", ")}`);
132
+ }
133
+
134
+ const exportConfig = { apiUrl, router, auth, basename: typeof args.basename === "string" ? args.basename : "/" };
135
+ const bridge = new ViteBridge({ root, base });
136
+ const viteConfig = await bridge.inlineConfig();
137
+ const { build: viteBuild } = await import("vite");
138
+ const started = Date.now();
139
+
140
+ console.log(colors.cyan("[EXPORT] Static client build ->"), path.relative(root, outDir) || outDir);
141
+ await viteBuild({
142
+ ...viteConfig,
143
+ mode: "production",
144
+ logLevel: "warn",
145
+ base,
146
+ publicDir: false,
147
+ define: { __BLUEBIRD_EXPORT__: JSON.stringify(exportConfig) },
148
+ build: {
149
+ outDir,
150
+ emptyOutDir: true,
151
+ manifest: true,
152
+ rollupOptions: { input: entries.map((rel) => path.join(root, rel)) },
153
+ },
154
+ });
155
+
156
+ if (!args["no-public"]) {
157
+ const publicDir = path.join(root, "public");
158
+ if (fs.existsSync(publicDir)) {
159
+ fs.cpSync(publicDir, outDir, {
160
+ recursive: true,
161
+ force: false,
162
+ filter: (src) => path.relative(publicDir, src).split(/[\\/]/)[0] !== "build",
163
+ });
164
+ }
165
+ }
166
+
167
+ const manifestFile = path.join(outDir, ".vite/manifest.json");
168
+ bridge.manifest = JSON.parse(fs.readFileSync(manifestFile, "utf-8"));
169
+ bridge.mode = "build";
170
+ const assets = bridge.assetTags(entries);
171
+
172
+ const html = await renderSpaDocument(merged, { fullPath: mount, assets, root, lang: options.lang });
173
+ fs.writeFileSync(path.join(outDir, "index.html"), rebaseLocalUrls(html, base), "utf-8");
174
+ fs.rmSync(path.join(outDir, ".vite"), { recursive: true, force: true });
175
+
176
+ const relOut = path.relative(root, outDir).replace(/\\/g, "/") || ".";
177
+ console.log(colors.green(`[OK] Exported in ${((Date.now() - started) / 1000).toFixed(1)}s -> ${relOut}/index.html`));
178
+ console.log(colors.gray(` router: ${router} | base: ${base} | auth: ${auth} | api: ${apiUrl || "(same origin)"}`));
179
+ if (!apiUrl) {
180
+ console.log(colors.yellow(" [WARN] No API URL: pass --api https://your-server.com for Electron/Capacitor builds."));
181
+ }
182
+ console.log(colors.white("Next steps:"));
183
+ console.log(colors.cyan(` Electron : mainWindow.loadFile("${relOut}/index.html")`));
184
+ console.log(colors.cyan(` Capacitor: set "webDir": "${relOut}" in capacitor.config.json, then npx cap sync`));
185
+ console.log(colors.cyan(" Server : allow the app origin in new App({ cors }) (default origin \"*\" already works with bearer tokens)"));
186
+ }
187
+
188
+ exportSpa().catch((err) => {
189
+ console.error(colors.red("[EXPORT ERROR]"), err?.message || err);
190
+ process.exit(1);
191
+ });