usebecky 0.0.0-stage → 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 (135) hide show
  1. package/README.md +701 -2
  2. package/dist/analytics/client.d.ts +219 -0
  3. package/dist/analytics/client.js +923 -0
  4. package/dist/analytics/cmp.d.ts +20 -0
  5. package/dist/analytics/cmp.js +166 -0
  6. package/dist/analytics/context.d.ts +29 -0
  7. package/dist/analytics/context.js +97 -0
  8. package/dist/auth/client.d.ts +401 -0
  9. package/dist/auth/client.js +1081 -0
  10. package/dist/auth/webauthn.d.ts +18 -0
  11. package/dist/auth/webauthn.js +138 -0
  12. package/dist/cli/ai.d.ts +54 -0
  13. package/dist/cli/ai.js +202 -0
  14. package/dist/cli/analytics.d.ts +53 -0
  15. package/dist/cli/analytics.js +357 -0
  16. package/dist/cli/config.d.ts +75 -0
  17. package/dist/cli/config.js +718 -0
  18. package/dist/cli/db.d.ts +48 -0
  19. package/dist/cli/db.js +215 -0
  20. package/dist/cli/deploy-api.d.ts +168 -0
  21. package/dist/cli/deploy-api.js +177 -0
  22. package/dist/cli/deploy-ci.d.ts +15 -0
  23. package/dist/cli/deploy-ci.js +54 -0
  24. package/dist/cli/deploy-detect.d.ts +64 -0
  25. package/dist/cli/deploy-detect.js +249 -0
  26. package/dist/cli/deploy-files.d.ts +112 -0
  27. package/dist/cli/deploy-files.js +778 -0
  28. package/dist/cli/deploy.d.ts +10 -0
  29. package/dist/cli/deploy.js +430 -0
  30. package/dist/cli/emails.d.ts +29 -0
  31. package/dist/cli/emails.js +122 -0
  32. package/dist/cli/framework.d.ts +135 -0
  33. package/dist/cli/framework.js +459 -0
  34. package/dist/cli/functions.d.ts +59 -0
  35. package/dist/cli/functions.js +426 -0
  36. package/dist/cli/hosting.d.ts +4 -0
  37. package/dist/cli/hosting.js +532 -0
  38. package/dist/cli/index.d.ts +2 -0
  39. package/dist/cli/index.js +9 -0
  40. package/dist/cli/payments.d.ts +35 -0
  41. package/dist/cli/payments.js +176 -0
  42. package/dist/cli/push.d.ts +36 -0
  43. package/dist/cli/push.js +172 -0
  44. package/dist/cli/run.d.ts +65 -0
  45. package/dist/cli/run.js +850 -0
  46. package/dist/cli/social.d.ts +52 -0
  47. package/dist/cli/social.js +532 -0
  48. package/dist/cli/tokens.d.ts +28 -0
  49. package/dist/cli/tokens.js +114 -0
  50. package/dist/cli/ui.d.ts +38 -0
  51. package/dist/cli/ui.js +140 -0
  52. package/dist/client.d.ts +94 -0
  53. package/dist/client.js +156 -0
  54. package/dist/db/query.d.ts +162 -0
  55. package/dist/db/query.js +336 -0
  56. package/dist/db/types.d.ts +93 -0
  57. package/dist/db/types.js +4 -0
  58. package/dist/forms/client.d.ts +65 -0
  59. package/dist/forms/client.js +106 -0
  60. package/dist/functions/client.d.ts +37 -0
  61. package/dist/functions/client.js +76 -0
  62. package/dist/index.d.ts +17 -0
  63. package/dist/index.js +16 -0
  64. package/dist/lib/dashboard-paths.d.ts +4 -0
  65. package/dist/lib/dashboard-paths.js +8 -0
  66. package/dist/lib/env.d.ts +9 -0
  67. package/dist/lib/env.js +55 -0
  68. package/dist/lib/errors.d.ts +22 -0
  69. package/dist/lib/errors.js +90 -0
  70. package/dist/lib/hosted.d.ts +2 -0
  71. package/dist/lib/hosted.js +7 -0
  72. package/dist/lib/http.d.ts +59 -0
  73. package/dist/lib/http.js +172 -0
  74. package/dist/lib/jwt.d.ts +1 -0
  75. package/dist/lib/jwt.js +31 -0
  76. package/dist/lib/locale.d.ts +12 -0
  77. package/dist/lib/locale.js +51 -0
  78. package/dist/lib/pkce.d.ts +20 -0
  79. package/dist/lib/pkce.js +124 -0
  80. package/dist/lib/storage-adapter.d.ts +15 -0
  81. package/dist/lib/storage-adapter.js +91 -0
  82. package/dist/lib/types.d.ts +339 -0
  83. package/dist/lib/types.js +1 -0
  84. package/dist/newsletter/client.d.ts +140 -0
  85. package/dist/newsletter/client.js +85 -0
  86. package/dist/payments/client.d.ts +352 -0
  87. package/dist/payments/client.js +323 -0
  88. package/dist/push/client.d.ts +110 -0
  89. package/dist/push/client.js +179 -0
  90. package/dist/realtime/client.d.ts +131 -0
  91. package/dist/realtime/client.js +513 -0
  92. package/dist/server/analytics.d.ts +176 -0
  93. package/dist/server/analytics.js +49 -0
  94. package/dist/server/cache.d.ts +74 -0
  95. package/dist/server/cache.js +154 -0
  96. package/dist/server/emails.d.ts +142 -0
  97. package/dist/server/emails.js +123 -0
  98. package/dist/server/events.d.ts +357 -0
  99. package/dist/server/events.js +219 -0
  100. package/dist/server/functions.d.ts +40 -0
  101. package/dist/server/functions.js +1 -0
  102. package/dist/server/http-utils.d.ts +10 -0
  103. package/dist/server/http-utils.js +115 -0
  104. package/dist/server/index.d.ts +195 -0
  105. package/dist/server/index.js +314 -0
  106. package/dist/server/payments.d.ts +218 -0
  107. package/dist/server/payments.js +150 -0
  108. package/dist/server/push.d.ts +85 -0
  109. package/dist/server/push.js +37 -0
  110. package/dist/server/usage.d.ts +43 -0
  111. package/dist/server/usage.js +8 -0
  112. package/dist/storage/client.d.ts +143 -0
  113. package/dist/storage/client.js +224 -0
  114. package/package.json +52 -4
  115. package/skill/usebecky/SKILL.md +339 -0
  116. package/skill/usebecky/references/access-rules.md +307 -0
  117. package/skill/usebecky/references/addons.md +68 -0
  118. package/skill/usebecky/references/analytics.md +166 -0
  119. package/skill/usebecky/references/android.md +434 -0
  120. package/skill/usebecky/references/auth.md +379 -0
  121. package/skill/usebecky/references/cache.md +51 -0
  122. package/skill/usebecky/references/components.md +127 -0
  123. package/skill/usebecky/references/emails.md +105 -0
  124. package/skill/usebecky/references/expo.md +147 -0
  125. package/skill/usebecky/references/functions.md +99 -0
  126. package/skill/usebecky/references/hosting.md +119 -0
  127. package/skill/usebecky/references/http-api.md +233 -0
  128. package/skill/usebecky/references/ios.md +355 -0
  129. package/skill/usebecky/references/payments.md +493 -0
  130. package/skill/usebecky/references/realtime.md +143 -0
  131. package/skill/usebecky/references/scheduled-jobs.md +82 -0
  132. package/skill/usebecky/references/sdk.md +838 -0
  133. package/skill/usebecky/references/storage.md +210 -0
  134. package/skill/usebecky/references/templates.md +191 -0
  135. package/skill/usebecky/references/wordpress.md +87 -0
@@ -0,0 +1,54 @@
1
+ // The GitHub Actions workflow for usebecky Hosting. usebecky's own repository is private, so there is no
2
+ // `uses: usebecky/...` action to reference, and GitHub can't run an action from an npm package: customers use a
3
+ // workflow file that runs the published CLI (`npx usebecky deploy`) with a deploy token. `npx usebecky hosting github`
4
+ // writes it, the dashboard shows the same file (apps/dashboard/src/pages/project/hosting/logic.ts, kept equal by
5
+ // apps/dashboard/test/hosting.test.ts) and docs/guide/guides/hosting.md explains it.
6
+ /** Where `npx usebecky hosting github` writes the workflow. */
7
+ export const WORKFLOW_PATH = '.github/workflows/usebecky-deploy.yml';
8
+ /** The repository secret the workflow reads. */
9
+ export const DEPLOY_TOKEN_SECRET = 'USEBECKY_DEPLOY_TOKEN';
10
+ /**
11
+ * The workflow file: pushes to main go live, pull requests get a preview address.
12
+ * `packageManager` null: no package.json (a plain HTML folder), so nothing to install.
13
+ */
14
+ export function githubWorkflow(opts) {
15
+ const pm = opts.packageManager === undefined ? 'npm' : opts.packageManager;
16
+ const branch = opts.branch ?? 'main';
17
+ const setup = [];
18
+ if (pm === 'pnpm')
19
+ setup.push(' - uses: pnpm/action-setup@v4');
20
+ setup.push(' - uses: actions/setup-node@v4', ' with:', ' node-version: 24');
21
+ if (pm === 'bun')
22
+ setup.push(' - uses: oven-sh/setup-bun@v2');
23
+ const install = {
24
+ npm: 'npm ci',
25
+ pnpm: 'pnpm install --frozen-lockfile',
26
+ yarn: 'yarn install --frozen-lockfile',
27
+ bun: 'bun install --frozen-lockfile',
28
+ };
29
+ return [
30
+ `# ${WORKFLOW_PATH}`,
31
+ `# Deploys to usebecky Hosting: pushes to ${branch} go live, pull requests get a preview address.`,
32
+ `# Needs the repository secret ${DEPLOY_TOKEN_SECRET} (Dashboard → Hosting → Deploy tokens).`,
33
+ 'name: Deploy to usebecky',
34
+ '',
35
+ 'on:',
36
+ ' push:',
37
+ ` branches: [${branch}]`,
38
+ ' pull_request:',
39
+ '',
40
+ 'jobs:',
41
+ ' deploy:',
42
+ " # Pull requests from forks can't read your secrets, so they are skipped.",
43
+ ' if: github.event_name == \'push\' || github.event.pull_request.head.repo.full_name == github.repository',
44
+ ' runs-on: ubuntu-latest',
45
+ ' steps:',
46
+ ' - uses: actions/checkout@v4',
47
+ ...setup,
48
+ ...(pm ? [` - run: ${install[pm]}`] : []),
49
+ ` - run: npx --yes usebecky deploy --project ${opts.project} --site ${opts.site} \${{ github.event_name == 'push' && '--prod' || '' }}`,
50
+ ' env:',
51
+ ` ${DEPLOY_TOKEN_SECRET}: \${{ secrets.${DEPLOY_TOKEN_SECRET} }}`,
52
+ '',
53
+ ].join('\n');
54
+ }
@@ -0,0 +1,64 @@
1
+ import type { PackageManager } from './deploy-ci.ts';
2
+ export type SiteKind = 'static' | 'node';
3
+ /** How a Node.js bundle is put together (packages/sdk/src/cli/deploy-files.ts packs it). */
4
+ export type NodeBundle =
5
+ /** Next.js `output: 'standalone'`: .next/standalone, plus .next/static and public copied in; start `node server.js`. */
6
+ {
7
+ type: 'next-standalone';
8
+ }
9
+ /** A folder that already has everything (Nuxt's .output); start command relative to it. */
10
+ | {
11
+ type: 'folder';
12
+ root: string;
13
+ start: string;
14
+ }
15
+ /**
16
+ * The app folder: `include` (null = everything except the usual leftovers) plus production node_modules.
17
+ * `start` replaces package.json's start script (null: keep the app's own start script or main).
18
+ */
19
+ | {
20
+ type: 'app';
21
+ include: string[] | null;
22
+ start: string | null;
23
+ };
24
+ export interface DeployPlan {
25
+ /** e.g. 'vite', 'next-standalone', 'node'. */
26
+ framework: string;
27
+ /** For people: "React + Vite", "Next.js (server)". */
28
+ label: string;
29
+ kind: SiteKind;
30
+ /** package.json script to run first ('build', 'generate'), or null when nothing needs building. */
31
+ buildScript: string | null;
32
+ /** Static sites: the folders to upload, first one that exists after the build wins. */
33
+ outputs: string[];
34
+ bundle?: NodeBundle;
35
+ /** It can't be deployed as it is: what's wrong and the one change that fixes it. */
36
+ problem?: {
37
+ message: string;
38
+ fix: string;
39
+ };
40
+ }
41
+ export declare function readJsonFile(file: string): any;
42
+ /** The lock file says which package manager runs the build (also one or two folders up, for monorepos). */
43
+ export declare function detectPackageManager(dir: string): PackageManager;
44
+ /** The command that runs a package.json script, as people would type it. */
45
+ export declare function scriptCommand(pm: PackageManager, script: string): {
46
+ command: string;
47
+ args: string[];
48
+ text: string;
49
+ };
50
+ /**
51
+ * Work out how to deploy the app in `dir`. `siteKind` is the existing site's kind, for frameworks that can be
52
+ * either (Nuxt: `nuxt build` for a Node.js site, `nuxt generate` for a static one).
53
+ */
54
+ export declare function detectDeploy(dir: string, siteKind?: SiteKind | null): DeployPlan;
55
+ /** The output folder of a static plan that exists now (after the build), or null. */
56
+ export declare function existingOutput(dir: string, plan: DeployPlan): string | null;
57
+ /** Site names: 3–40 lowercase letters, numbers and dashes; no dash at either end, no "--" (previews use it). */
58
+ export declare const SITE_NAME_RE: RegExp;
59
+ /** Names usebecky keeps for itself (the API has the full list). The same list as the dashboard (pages/project/hosting/logic.ts). */
60
+ export declare const RESERVED_SITE_NAMES: string[];
61
+ /** Why a site name can't be used, in plain words, or null (taken names are only known by the API). The dashboard's words. */
62
+ export declare function siteNameProblem(name: string): string | null;
63
+ /** A first suggestion for the name: from package.json's name or the folder name. */
64
+ export declare function suggestSiteName(dir: string): string;
@@ -0,0 +1,249 @@
1
+ // `npx usebecky deploy`: what kind of app is in a folder, how it is built and what gets uploaded.
2
+ // Pure functions over a directory (no network, no child processes) so they are easy to test.
3
+ // The table in docs/guide/guides/hosting.md ("How each framework is built") describes exactly this.
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ export function readJsonFile(file) {
7
+ try {
8
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
9
+ }
10
+ catch {
11
+ return null;
12
+ }
13
+ }
14
+ function readFirst(dir, names) {
15
+ for (const n of names) {
16
+ try {
17
+ return fs.readFileSync(path.join(dir, n), 'utf8');
18
+ }
19
+ catch { }
20
+ }
21
+ return '';
22
+ }
23
+ const CONFIG_EXT = ['.ts', '.mts', '.js', '.mjs', '.cjs'];
24
+ const configText = (dir, base) => readFirst(dir, CONFIG_EXT.map((e) => base + e));
25
+ /** A string option in a config file, like `outDir: 'build'` (comments aren't parsed: good enough for defaults). */
26
+ function stringOption(text, name) {
27
+ const m = new RegExp(`\\b${name}\\s*:\\s*['"\`]([^'"\`]+)['"\`]`).exec(text);
28
+ return m ? m[1] : null;
29
+ }
30
+ /** The lock file says which package manager runs the build (also one or two folders up, for monorepos). */
31
+ export function detectPackageManager(dir) {
32
+ let d = path.resolve(dir);
33
+ for (let i = 0; i < 4; i++) {
34
+ if (fs.existsSync(path.join(d, 'pnpm-lock.yaml')))
35
+ return 'pnpm';
36
+ if (fs.existsSync(path.join(d, 'yarn.lock')))
37
+ return 'yarn';
38
+ if (fs.existsSync(path.join(d, 'bun.lockb')) || fs.existsSync(path.join(d, 'bun.lock')))
39
+ return 'bun';
40
+ if (fs.existsSync(path.join(d, 'package-lock.json')))
41
+ return 'npm';
42
+ const up = path.dirname(d);
43
+ if (up === d)
44
+ break;
45
+ d = up;
46
+ }
47
+ return 'npm';
48
+ }
49
+ /** The command that runs a package.json script, as people would type it. */
50
+ export function scriptCommand(pm, script) {
51
+ const args = pm === 'yarn' ? [script] : ['run', script];
52
+ return { command: pm, args, text: `${pm} ${args.join(' ')}` };
53
+ }
54
+ /**
55
+ * Work out how to deploy the app in `dir`. `siteKind` is the existing site's kind, for frameworks that can be
56
+ * either (Nuxt: `nuxt build` for a Node.js site, `nuxt generate` for a static one).
57
+ */
58
+ export function detectDeploy(dir, siteKind) {
59
+ const pkg = readJsonFile(path.join(dir, 'package.json'));
60
+ if (!pkg) {
61
+ const html = fs.existsSync(path.join(dir, 'index.html'));
62
+ return html
63
+ ? { framework: 'html', label: 'a static website (HTML files)', kind: 'static', buildScript: null, outputs: ['.'] }
64
+ : {
65
+ framework: 'none',
66
+ label: 'nothing to deploy',
67
+ kind: 'static',
68
+ buildScript: null,
69
+ outputs: ['.'],
70
+ problem: {
71
+ message: 'No app found in this folder: there is no package.json and no index.html.',
72
+ fix: 'Run the command in your app’s folder, or pass the folder with your built website: npx usebecky deploy dist',
73
+ },
74
+ };
75
+ }
76
+ const deps = { ...(pkg.devDependencies ?? {}), ...(pkg.dependencies ?? {}) };
77
+ const has = (name) => Object.prototype.hasOwnProperty.call(deps, name);
78
+ const scripts = pkg.scripts ?? {};
79
+ const build = scripts.build ? 'build' : null;
80
+ if (has('next')) {
81
+ const cfg = configText(dir, 'next.config');
82
+ const output = /\boutput\s*:\s*['"`](export|standalone)['"`]/.exec(cfg)?.[1];
83
+ const distDir = stringOption(cfg, 'distDir');
84
+ if (output === 'export')
85
+ return { framework: 'next-export', label: 'Next.js (static export)', kind: 'static', buildScript: build, outputs: ['out'] };
86
+ if (output === 'standalone' && !distDir)
87
+ return { framework: 'next-standalone', label: 'Next.js (server)', kind: 'node', buildScript: build, outputs: [], bundle: { type: 'next-standalone' } };
88
+ return {
89
+ framework: 'next',
90
+ label: 'Next.js',
91
+ kind: 'node',
92
+ buildScript: build,
93
+ outputs: [],
94
+ problem: distDir
95
+ ? { message: `Your next.config sets distDir: '${distDir}'. usebecky deploys the standard .next folder.`, fix: 'Remove distDir from next.config, then deploy again.' }
96
+ : {
97
+ message: 'Next.js needs one setting before it can be deployed.',
98
+ fix: "Add output: 'standalone' to next.config (a server, for server components, API routes and server actions) or output: 'export' (a static site), then deploy again.",
99
+ },
100
+ };
101
+ }
102
+ if (has('nuxt') || has('nuxt3')) {
103
+ if (siteKind === 'static') {
104
+ return scripts.generate
105
+ ? { framework: 'nuxt-static', label: 'Nuxt (static site)', kind: 'static', buildScript: 'generate', outputs: ['.output/public', 'dist'] }
106
+ : {
107
+ framework: 'nuxt-static',
108
+ label: 'Nuxt (static site)',
109
+ kind: 'static',
110
+ buildScript: null,
111
+ outputs: ['.output/public'],
112
+ problem: { message: 'This site is a static site, and a static Nuxt site is made with `nuxt generate`.', fix: 'Add "generate": "nuxt generate" to the scripts in package.json, then deploy again.' },
113
+ };
114
+ }
115
+ return { framework: 'nuxt', label: 'Nuxt', kind: 'node', buildScript: build, outputs: [], bundle: { type: 'folder', root: '.output', start: 'node server/index.mjs' } };
116
+ }
117
+ if (has('@sveltejs/kit')) {
118
+ const cfg = configText(dir, 'svelte.config');
119
+ if (has('@sveltejs/adapter-static') || /adapter-static/.test(cfg)) {
120
+ const pages = stringOption(cfg, 'pages') ?? 'build';
121
+ return { framework: 'sveltekit-static', label: 'SvelteKit (static)', kind: 'static', buildScript: build, outputs: [pages] };
122
+ }
123
+ if (has('@sveltejs/adapter-node') || /adapter-node/.test(cfg)) {
124
+ const out = stringOption(cfg, 'out') ?? 'build';
125
+ return { framework: 'sveltekit-node', label: 'SvelteKit (server)', kind: 'node', buildScript: build, outputs: [], bundle: { type: 'app', include: [out, 'package.json'], start: `node ${out}/index.js` } };
126
+ }
127
+ return {
128
+ framework: 'sveltekit',
129
+ label: 'SvelteKit',
130
+ kind: 'node',
131
+ buildScript: build,
132
+ outputs: [],
133
+ problem: {
134
+ message: 'SvelteKit needs an adapter that says how your app runs. adapter-auto only works on a few other hosts.',
135
+ fix: 'npm install -D @sveltejs/adapter-node (a server) or @sveltejs/adapter-static (a static site), use it in svelte.config.js, then deploy again.',
136
+ },
137
+ };
138
+ }
139
+ if (has('astro')) {
140
+ if (has('@astrojs/node'))
141
+ return { framework: 'astro-node', label: 'Astro (server)', kind: 'node', buildScript: build, outputs: [], bundle: { type: 'app', include: ['dist', 'package.json'], start: 'node ./dist/server/entry.mjs' } };
142
+ const outDir = stringOption(configText(dir, 'astro.config'), 'outDir') ?? 'dist';
143
+ return { framework: 'astro', label: 'Astro', kind: 'static', buildScript: build, outputs: [outDir.replace(/^\.\//, '')] };
144
+ }
145
+ // Remix / React Router with their Node.js server (remix-serve / react-router-serve), or as a single-page app.
146
+ const serve = has('@remix-run/serve') ? '@remix-run/serve' : has('@react-router/serve') ? '@react-router/serve' : null;
147
+ const rr = Object.keys(deps).some((d) => d.startsWith('@remix-run/')) || has('@react-router/dev');
148
+ if (rr) {
149
+ const label = Object.keys(deps).some((d) => d.startsWith('@remix-run/')) ? 'Remix' : 'React Router';
150
+ if (serve) {
151
+ return scripts.start
152
+ ? { framework: 'remix-node', label: `${label} (server)`, kind: 'node', buildScript: build, outputs: [], bundle: { type: 'app', include: ['build', 'public', 'package.json'], start: null } }
153
+ : {
154
+ framework: 'remix-node',
155
+ label: `${label} (server)`,
156
+ kind: 'node',
157
+ buildScript: build,
158
+ outputs: [],
159
+ problem: { message: 'package.json has no start script, so usebecky doesn’t know how to start your server.', fix: `Add "start": "${serve === '@remix-run/serve' ? 'remix-serve' : 'react-router-serve'} ./build/server/index.js" to the scripts in package.json, then deploy again.` },
160
+ };
161
+ }
162
+ return { framework: 'remix-spa', label: `${label} (single-page app)`, kind: 'static', buildScript: build, outputs: ['build/client'] };
163
+ }
164
+ if (has('gatsby'))
165
+ return { framework: 'gatsby', label: 'Gatsby', kind: 'static', buildScript: build, outputs: ['public'] };
166
+ if (has('@angular/core') && fs.existsSync(path.join(dir, 'angular.json'))) {
167
+ const ng = readJsonFile(path.join(dir, 'angular.json'));
168
+ const project = ng?.projects ? (ng.defaultProject ?? Object.keys(ng.projects)[0]) : null;
169
+ const opt = project ? ng.projects[project]?.architect?.build?.options?.outputPath : null;
170
+ const base = typeof opt === 'string' ? opt : typeof opt?.base === 'string' ? opt.base : project ? `dist/${project}` : 'dist';
171
+ return { framework: 'angular', label: 'Angular', kind: 'static', buildScript: build, outputs: [`${base}/browser`, base] };
172
+ }
173
+ if (has('vite')) {
174
+ const outDir = stringOption(configText(dir, 'vite.config'), 'outDir') ?? 'dist';
175
+ const ui = has('react') ? 'React + Vite' : has('vue') ? 'Vue + Vite' : has('svelte') ? 'Svelte + Vite' : has('solid-js') ? 'Solid + Vite' : 'Vite';
176
+ return { framework: 'vite', label: ui, kind: 'static', buildScript: build, outputs: [outDir.replace(/^\.\//, '')] };
177
+ }
178
+ if (has('react-scripts'))
179
+ return { framework: 'cra', label: 'Create React App', kind: 'static', buildScript: build, outputs: ['build'] };
180
+ // A Node.js server: Express, Hono, Fastify, Koa or plain node, started by `npm start` (or package.json "main").
181
+ if (scripts.start || pkg.main) {
182
+ const server = ['express', 'hono', 'fastify', 'koa', '@nestjs/core'].find(has);
183
+ const names = { express: 'Express', hono: 'Hono', fastify: 'Fastify', koa: 'Koa', '@nestjs/core': 'NestJS' };
184
+ return { framework: 'node', label: server ? `Node.js (${names[server]})` : 'Node.js', kind: 'node', buildScript: build, outputs: [], bundle: { type: 'app', include: null, start: null } };
185
+ }
186
+ // Something else with a build script that writes a website (Parcel, webpack, Eleventy, ...): look for its folder.
187
+ if (build)
188
+ return { framework: 'static-build', label: 'a static website', kind: 'static', buildScript: build, outputs: ['dist', 'build', 'out', 'public', '_site'] };
189
+ return {
190
+ framework: 'unknown',
191
+ label: 'an app usebecky doesn’t know yet',
192
+ kind: 'static',
193
+ buildScript: null,
194
+ outputs: [],
195
+ problem: {
196
+ message: 'Couldn’t tell what to deploy: package.json has no start script, no build script and no framework usebecky knows.',
197
+ fix: 'For a server, add a "start" script to package.json. For a website, build it and deploy the folder: npx usebecky deploy dist',
198
+ },
199
+ };
200
+ }
201
+ /** The output folder of a static plan that exists now (after the build), or null. */
202
+ export function existingOutput(dir, plan) {
203
+ for (const o of plan.outputs) {
204
+ const p = path.resolve(dir, o);
205
+ try {
206
+ if (fs.statSync(p).isDirectory())
207
+ return p;
208
+ }
209
+ catch { }
210
+ }
211
+ return null;
212
+ }
213
+ /** Site names: 3–40 lowercase letters, numbers and dashes; no dash at either end, no "--" (previews use it). */
214
+ export const SITE_NAME_RE = /^[a-z0-9](?:[a-z0-9]|-(?!-)){1,38}[a-z0-9]$/;
215
+ /** Names usebecky keeps for itself (the API has the full list). The same list as the dashboard (pages/project/hosting/logic.ts). */
216
+ export const RESERVED_SITE_NAMES = ['www', 'api', 'admin', 'app', 'dashboard', 'docs', 'mail', 'status', 'hosting', 'usebecky', 'domains', 'help', 'support', 'blog'];
217
+ /** Why a site name can't be used, in plain words, or null (taken names are only known by the API). The dashboard's words. */
218
+ export function siteNameProblem(name) {
219
+ if (!name)
220
+ return 'Give your site a name.';
221
+ if (/[^a-z0-9-]/.test(name))
222
+ return 'Use only lowercase letters, numbers and dashes.';
223
+ if (name.length < 3)
224
+ return 'Use at least 3 characters.';
225
+ if (name.length > 40)
226
+ return 'Use at most 40 characters.';
227
+ if (name.startsWith('-') || name.endsWith('-'))
228
+ return 'Start and end with a letter or a number.';
229
+ if (name.includes('--'))
230
+ return 'Use single dashes. Two in a row are kept for preview addresses.';
231
+ if (RESERVED_SITE_NAMES.includes(name))
232
+ return `“${name}” is kept for usebecky. Try another name.`;
233
+ return null;
234
+ }
235
+ /** A first suggestion for the name: from package.json's name or the folder name. */
236
+ export function suggestSiteName(dir) {
237
+ const pkgName = String(readJsonFile(path.join(dir, 'package.json'))?.name ?? '').replace(/^@[^/]+\//, '');
238
+ const raw = pkgName || path.basename(path.resolve(dir));
239
+ let s = raw
240
+ .toLowerCase()
241
+ .replace(/[^a-z0-9]+/g, '-')
242
+ .replace(/-+/g, '-')
243
+ .replace(/^-|-$/g, '')
244
+ .slice(0, 40)
245
+ .replace(/-$/, '');
246
+ if (s.length < 3)
247
+ s = `${s || 'my'}-site`;
248
+ return siteNameProblem(s) ? `${s.slice(0, 34).replace(/-$/, '')}-site` : s;
249
+ }
@@ -0,0 +1,112 @@
1
+ import type { NodeBundle } from './deploy-detect.ts';
2
+ export declare const IGNORE_FILE = ".usebeckyignore";
3
+ /** Why a file is never uploaded, or null. Checked on every folder level. */
4
+ export declare function skipReason(rel: string): string | null;
5
+ /**
6
+ * `.usebeckyignore` lines (gitignore-style: `name`, `folder/`, `*.log`, `path/**`, `/only-at-the-top`, `!keep`)
7
+ * → a test for a path. The last matching line wins.
8
+ */
9
+ export declare function ignoreMatcher(text: string): (rel: string) => boolean;
10
+ /**
11
+ * A symbolic link in the folder being deployed that points outside it. Its target is never read: deploying a folder
12
+ * must never upload a file from elsewhere on the computer (a link to ~/.ssh or to the app's .env, say).
13
+ */
14
+ export declare class LinkOutsideError extends Error {
15
+ /** Where the link is (relative to the app folder when it's inside it). */
16
+ readonly link: string;
17
+ /** Where it really points (absolute). */
18
+ readonly target: string;
19
+ /** `.usebeckyignore` can leave it out (static sites, the app's own files; not node_modules or Next.js' output). */
20
+ readonly ignorable: boolean;
21
+ constructor(link: string, target: string, ignorable?: boolean);
22
+ }
23
+ /** The plain-words problem for a link pointing outside (the CLI prints the message and the fix). */
24
+ export declare function linkOutsideProblem(e: LinkOutsideError): {
25
+ message: string;
26
+ fix: string;
27
+ };
28
+ export interface LocalFile {
29
+ /** Relative, with forward slashes: `assets/app-1a2b.js`. */
30
+ path: string;
31
+ abs: string;
32
+ size: number;
33
+ sha256?: string;
34
+ }
35
+ /**
36
+ * Every file of a static site under `root`. A symbolic link to something inside `root` is followed (a folder linked
37
+ * from two places is uploaded at both; a folder that links back into itself and broken links are skipped); a link to
38
+ * anything outside `root` stops the collection with `problem` (LinkOutsideError), and nothing is uploaded.
39
+ * `.usebeckyignore` is read from `root` and from `appDir` (the app folder, when `root` is its build output); an ignored
40
+ * link is never looked at.
41
+ */
42
+ export declare function collectStaticFiles(root: string, appDir?: string): {
43
+ files: LocalFile[];
44
+ skipped: {
45
+ path: string;
46
+ reason: string;
47
+ }[];
48
+ problem?: {
49
+ message: string;
50
+ fix: string;
51
+ };
52
+ };
53
+ export declare function sha256(data: Buffer | Uint8Array): string;
54
+ export declare function sha256File(abs: string): Promise<string>;
55
+ /** Run `fn` over `items` with at most `limit` at a time; results keep the input order. */
56
+ export declare function pool<T, R>(items: T[], limit: number, fn: (item: T, index: number) => Promise<R>): Promise<R[]>;
57
+ export interface BundleEntry {
58
+ /** Path inside the bundle (forward slashes). */
59
+ path: string;
60
+ type: 'file' | 'symlink';
61
+ /** Where to read a file from (or `data`). */
62
+ abs?: string;
63
+ data?: Buffer;
64
+ linkname?: string;
65
+ mode: number;
66
+ }
67
+ export interface NodeBundleResult {
68
+ entries: BundleEntry[];
69
+ /** Files inside node_modules ending in .node (native code built for this computer). */
70
+ nativeModules: string[];
71
+ /** The start command the bundle's package.json says (for the summary). */
72
+ start: string | null;
73
+ /** node_modules was copied whole (production packages couldn't be listed). */
74
+ allModules: boolean;
75
+ /** What's missing (no package.json, no build output, ...), in plain words. */
76
+ problem?: {
77
+ message: string;
78
+ fix: string;
79
+ };
80
+ }
81
+ /** The package a file in node_modules belongs to: `node_modules/@a/b/lib/x.js` → `node_modules/@a/b`. */
82
+ export declare function owningPackage(rel: string): string | null;
83
+ /**
84
+ * The installed production packages of the app in `dir`, as absolute folders (`npm ls --omit=dev`), or null when
85
+ * they can't be listed (no npm, yarn PnP, ...). Works for npm, yarn classic and bun, which all write a plain node_modules.
86
+ */
87
+ export declare function listProductionPackages(dir: string): Promise<string[] | null>;
88
+ /** What a server bundle never takes (node_modules is wanted here, unlike static sites; .env files stay home). */
89
+ export declare function bundleSkip(rel: string): boolean;
90
+ /**
91
+ * Put the Node.js server bundle together (after the build). `listPackages` lists production packages
92
+ * (default: `npm ls --omit=dev`; tests pass a fake).
93
+ */
94
+ export declare function buildNodeBundle(dir: string, bundle: NodeBundle, listPackages?: (dir: string) => Promise<string[] | null>): Promise<NodeBundleResult>;
95
+ /** Bytes of every file in the bundle (before compression). */
96
+ export declare function bundleBytes(entries: BundleEntry[]): number;
97
+ /** The bundle as a gzip-compressed tar (folders first-mentioned before their files, sorted, mtime 0). */
98
+ export declare function packTarGz(entries: BundleEntry[]): Promise<Buffer>;
99
+ /** Read a (gzip-compressed) tar back: [{ path, type, mode, data, linkname }]. For tests and checks. */
100
+ export declare function readTar(buf: Buffer): {
101
+ path: string;
102
+ type: string;
103
+ mode: number;
104
+ data: Buffer;
105
+ linkname: string;
106
+ }[];
107
+ /** The file a `node [flags] file` start command runs, or null for anything else (`remix-serve …`, `tsx …`). */
108
+ export declare function startFile(start: string | null): string | null;
109
+ /** Does the entry file mention process.env.PORT? (Node.js sites must listen on it.) null: couldn't tell. */
110
+ export declare function mentionsPort(entries: BundleEntry[], start: string | null): boolean | null;
111
+ /** `node --env-file=.env …` fails on usebecky: .env is never uploaded (`--env-file-if-exists` is fine). */
112
+ export declare function startNeedsEnvFile(start: string | null): boolean;