@coreframe/scripts 0.1.18 → 0.1.20
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/dist/config.d.ts +2 -0
- package/dist/config.js +1 -1
- package/dist/coreframe.d.ts +84 -0
- package/dist/coreframe.js +2 -1
- package/dist/deploy.d.ts +2 -2
- package/dist/deploy.js +2 -1
- package/dist/dev-lock.js +1 -1
- package/dist/upgrade/sync-coreframe-packages.d.ts +8 -0
- package/dist/upgrade/sync-coreframe-packages.js +4 -0
- package/dist/worker-environment.d.ts +72 -0
- package/dist/worker-environment.js +1 -0
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { DatabaseDialect } from "./db/client.js";
|
|
2
2
|
import { DeployConfig } from "./deploy/config.js";
|
|
3
3
|
import { DevPlatform } from "./dev.js";
|
|
4
|
+
import { WorkerConfig } from "./worker-environment.js";
|
|
4
5
|
|
|
5
6
|
//#region config.d.ts
|
|
6
7
|
type CoreframeConfig = {
|
|
7
8
|
database?: DatabaseConfig;
|
|
8
9
|
deploy?: DeployConfig;
|
|
9
10
|
dev?: DevConfig;
|
|
11
|
+
worker?: WorkerConfig;
|
|
10
12
|
};
|
|
11
13
|
type DevConfig = {
|
|
12
14
|
platforms?: DevPlatform[];
|
package/dist/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{stat as e}from"node:fs/promises";import{resolve as t}from"node:path";import{pathToFileURL as n}from"node:url";function r(e){return e}async function i({cwd:r=process.cwd()}={}){let i=t(r,`coreframe.config.ts`),a;try{a=(await e(i,{bigint:!0})).mtimeNs}catch{return{}}let o=n(i);return o.searchParams.set(`modified`,a.toString()),(await import(o.href)).default??{}}export{r as defineConfig,i as readProjectConfig};
|
package/dist/coreframe.d.ts
CHANGED
|
@@ -62,6 +62,27 @@ declare const coreframeCli: Partial<import("cmd-ts/dist/cjs/argparser").Register
|
|
|
62
62
|
json: boolean;
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
|
+
} | {
|
|
66
|
+
command: "secrets";
|
|
67
|
+
args: {
|
|
68
|
+
command: "status";
|
|
69
|
+
args: {
|
|
70
|
+
environment: "staging" | "production" | undefined;
|
|
71
|
+
json: boolean;
|
|
72
|
+
};
|
|
73
|
+
} | {
|
|
74
|
+
command: "set";
|
|
75
|
+
args: {
|
|
76
|
+
environment: "staging" | "production";
|
|
77
|
+
name: string;
|
|
78
|
+
};
|
|
79
|
+
} | {
|
|
80
|
+
command: "discard";
|
|
81
|
+
args: {
|
|
82
|
+
environment: "staging" | "production";
|
|
83
|
+
name: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
65
86
|
} | {
|
|
66
87
|
command: "typecheck";
|
|
67
88
|
args: {};
|
|
@@ -96,6 +117,12 @@ declare const coreframeCli: Partial<import("cmd-ts/dist/cjs/argparser").Register
|
|
|
96
117
|
base: string | undefined;
|
|
97
118
|
apply: boolean;
|
|
98
119
|
};
|
|
120
|
+
} | {
|
|
121
|
+
command: "sync-coreframe-packages";
|
|
122
|
+
args: {
|
|
123
|
+
target: string;
|
|
124
|
+
apply: boolean;
|
|
125
|
+
};
|
|
99
126
|
};
|
|
100
127
|
} | {
|
|
101
128
|
command: "db";
|
|
@@ -206,6 +233,27 @@ declare const coreframeCli: Partial<import("cmd-ts/dist/cjs/argparser").Register
|
|
|
206
233
|
json: boolean;
|
|
207
234
|
};
|
|
208
235
|
};
|
|
236
|
+
} | {
|
|
237
|
+
command: "secrets";
|
|
238
|
+
args: {
|
|
239
|
+
command: "status";
|
|
240
|
+
args: {
|
|
241
|
+
environment: "staging" | "production" | undefined;
|
|
242
|
+
json: boolean;
|
|
243
|
+
};
|
|
244
|
+
} | {
|
|
245
|
+
command: "set";
|
|
246
|
+
args: {
|
|
247
|
+
environment: "staging" | "production";
|
|
248
|
+
name: string;
|
|
249
|
+
};
|
|
250
|
+
} | {
|
|
251
|
+
command: "discard";
|
|
252
|
+
args: {
|
|
253
|
+
environment: "staging" | "production";
|
|
254
|
+
name: string;
|
|
255
|
+
};
|
|
256
|
+
};
|
|
209
257
|
} | {
|
|
210
258
|
command: "typecheck";
|
|
211
259
|
args: {};
|
|
@@ -240,6 +288,12 @@ declare const coreframeCli: Partial<import("cmd-ts/dist/cjs/argparser").Register
|
|
|
240
288
|
base: string | undefined;
|
|
241
289
|
apply: boolean;
|
|
242
290
|
};
|
|
291
|
+
} | {
|
|
292
|
+
command: "sync-coreframe-packages";
|
|
293
|
+
args: {
|
|
294
|
+
target: string;
|
|
295
|
+
apply: boolean;
|
|
296
|
+
};
|
|
243
297
|
};
|
|
244
298
|
} | {
|
|
245
299
|
command: "db";
|
|
@@ -317,6 +371,18 @@ declare const coreframeCli: Partial<import("cmd-ts/dist/cjs/argparser").Register
|
|
|
317
371
|
command: "url";
|
|
318
372
|
value: Promise<void>;
|
|
319
373
|
};
|
|
374
|
+
} | {
|
|
375
|
+
command: "secrets";
|
|
376
|
+
value: {
|
|
377
|
+
command: "status";
|
|
378
|
+
value: Promise<void>;
|
|
379
|
+
} | {
|
|
380
|
+
command: "set";
|
|
381
|
+
value: Promise<void>;
|
|
382
|
+
} | {
|
|
383
|
+
command: "discard";
|
|
384
|
+
value: Promise<void>;
|
|
385
|
+
};
|
|
320
386
|
} | {
|
|
321
387
|
command: "typecheck";
|
|
322
388
|
value: Promise<void>;
|
|
@@ -334,6 +400,9 @@ declare const coreframeCli: Partial<import("cmd-ts/dist/cjs/argparser").Register
|
|
|
334
400
|
} | {
|
|
335
401
|
command: "fast-forward-template-files";
|
|
336
402
|
value: void;
|
|
403
|
+
} | {
|
|
404
|
+
command: "sync-coreframe-packages";
|
|
405
|
+
value: void;
|
|
337
406
|
};
|
|
338
407
|
} | {
|
|
339
408
|
command: "db";
|
|
@@ -402,6 +471,18 @@ declare const coreframeCli: Partial<import("cmd-ts/dist/cjs/argparser").Register
|
|
|
402
471
|
command: "url";
|
|
403
472
|
value: Promise<void>;
|
|
404
473
|
};
|
|
474
|
+
} | {
|
|
475
|
+
command: "secrets";
|
|
476
|
+
value: {
|
|
477
|
+
command: "status";
|
|
478
|
+
value: Promise<void>;
|
|
479
|
+
} | {
|
|
480
|
+
command: "set";
|
|
481
|
+
value: Promise<void>;
|
|
482
|
+
} | {
|
|
483
|
+
command: "discard";
|
|
484
|
+
value: Promise<void>;
|
|
485
|
+
};
|
|
405
486
|
} | {
|
|
406
487
|
command: "typecheck";
|
|
407
488
|
value: Promise<void>;
|
|
@@ -419,6 +500,9 @@ declare const coreframeCli: Partial<import("cmd-ts/dist/cjs/argparser").Register
|
|
|
419
500
|
} | {
|
|
420
501
|
command: "fast-forward-template-files";
|
|
421
502
|
value: void;
|
|
503
|
+
} | {
|
|
504
|
+
command: "sync-coreframe-packages";
|
|
505
|
+
value: void;
|
|
422
506
|
};
|
|
423
507
|
} | {
|
|
424
508
|
command: "db";
|
package/dist/coreframe.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{addAsset as e,buildAssets as t,checkAssets as n,printAssetResult as r,publishAssets as i}from"./assets.js";import{runDrizzleKitCommand as a}from"./db/drizzle-kit.js";import{seedLocalDb as o}from"./db/seed.js";import{migrateLocalDb as s}from"./db/migrate.js";import{resetLocalDb as c}from"./db/reset.js";import{setupLocalDb as l}from"./db/setup.js";import{ensureLocalDb as u}from"./db/ensure.js";import{migrateHeldMigrations as d}from"./db/migrate-held.js";import{checkSchemaPush as f}from"./db/schema-check.js";import{deployEnvironments as p,tauriReleasePlatforms as m}from"./deploy/config.js";import{discoverStagingUrl as h,reassignStagingHostname as g}from"./staging.js";import{deployProject as _}from"./deploy.js";import{checkDeployMigrations as v}from"./deploy/check-migrations.js";import{devPlatforms as y,runDevServer as b}from"./dev.js";import{run as x}from"./runner.js";import{typecheckProject as S}from"./typecheck.js";import{checkUpgradeSkillCurrent as C}from"./upgrade/check-skill-current.js";import{ensureTemplateRemote as w}from"./upgrade/ensure-template-remote.js";import{fastForwardTemplateFiles as T}from"./upgrade/fast-forward-template-files.js";import{array as E,command as D,extendType as O,flag as k,multioption as A,number as j,oneOf as M,option as N,optional as P,positional as F,rest as I,string as L,subcommands as R}from"cmd-ts";const z=[`Cookies and sessions are origin-scoped.`,`Exact-host passkeys may require re-registration unless a stable eligible parent RP ID was configured in advance.`,`External OAuth callbacks such as Google may need updating.`,`Database data and private backend resources are unchanged.`],B=O(L,{displayName:`widths`,description:`Comma-separated responsive variant widths.`,async from(e){let t=e.split(`,`).map(e=>Number(e));if(t.length===0||t.some(e=>!Number.isInteger(e)||e<=0)||t.some((e,n)=>n>0&&e<=t[n-1]))throw Error(`Widths must be positive, unique, strictly ascending integers.`);return t}}),V=R({name:`coreframe`,cmds:{assets:R({name:`assets`,cmds:{add:D({name:`add`,args:{file:F({type:L,displayName:`file`,description:`Source image to add to the asset library.`}),id:N({long:`id`,type:L,description:`Logical asset ID, such as blog/my-post/hero.`}),alt:N({long:`alt`,type:L,description:`Required alt text for the asset.`}),variantWidths:N({long:`widths`,type:P(B),description:`Generate exactly these comma-separated widths instead of the default ladder.`}),json:k({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({alt:t,file:n,id:i,json:a,variantWidths:o})=>r(await e({alt:t,file:n,id:i,json:a,variantWidths:o}),a)}),build:D({name:`build`,args:{id:N({long:`id`,type:P(L),description:`Build only one logical asset ID.`}),noPull:k({long:`no-pull`,description:`Do not perform targeted Git LFS pulls for missing source objects.`,defaultValue:()=>!1}),json:k({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({id:e,json:n,noPull:i})=>r(await t({id:e,json:n,pull:!i}),n)}),check:D({name:`check`,args:{fix:k({long:`fix`,description:`Build missing generated variants when possible.`,defaultValue:()=>!1}),json:k({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({fix:e,json:t})=>{let i=await n({fix:e,json:t});r(i,t),i.ok||(process.exitCode=1)}}),publish:D({name:`publish`,args:{outputDir:N({long:`output-dir`,type:P(L),description:`Root directory for additive local publish output. Defaults to COREFRAME_ASSETS_PUBLISH_DIR or release-upload.`}),json:k({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({json:e,outputDir:t})=>{let n=await i({json:e,outputDir:t});r(n,e),n.ok||(process.exitCode=1)}}),status:D({name:`status`,args:{json:k({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({json:e})=>{let t=await n({json:e});r(t,e),t.ok||(process.exitCode=1)}})}}),deploy:D({name:`deploy`,args:{environment:F({type:M(p),displayName:`environment`,description:`Deploy to the staging or production environment.`}),runMigrations:k({long:`run-migrations`,description:`Run pending deploy-safe database migrations before deploying.`,defaultValue:()=>!1}),skipMigrations:k({long:`skip-migrations`,description:`Deploy without running pending deploy-safe database migrations.`,defaultValue:()=>!1}),skipPostDeployChecks:k({long:`skip-post-deploy-checks`,description:`Skip post-deploy checks after Cloudflare deployment.`,defaultValue:()=>!1}),tauriLocalPlatforms:A({long:`tauri-local-platform`,type:E(M(m)),description:`Build one Tauri release platform locally. Repeat for multiple platforms.`,defaultValue:()=>[]}),tauriWorkflowName:N({long:`tauri-workflow-name`,type:P(L),description:`GitHub Actions workflow file or name for remote Tauri release builds.`}),tauriWorkflowPlatforms:A({long:`tauri-workflow-platform`,type:E(M(m)),description:`Build one Tauri release platform with GitHub Actions. Repeat for multiple platforms.`,defaultValue:()=>[]}),tauriWorkflowRef:N({long:`tauri-workflow-ref`,type:P(L),description:`Git ref used when dispatching remote Tauri release builds.`}),yes:k({long:`yes`,short:`y`,description:`Approve the production deployment confirmation.`,defaultValue:()=>!1})},handler:({environment:e,runMigrations:t,skipMigrations:n,skipPostDeployChecks:r,tauriLocalPlatforms:i,tauriWorkflowName:a,tauriWorkflowPlatforms:o,tauriWorkflowRef:s,yes:c})=>_([e,...t?[`--run-migrations`]:[],...n?[`--skip-migrations`]:[],...r?[`--skip-post-deploy-checks`]:[],...i.flatMap(e=>[`--tauri-local-platform`,e]),...a?[`--tauri-workflow-name`,a]:[],...o.flatMap(e=>[`--tauri-workflow-platform`,e]),...s?[`--tauri-workflow-ref`,s]:[],...c?[`--yes`]:[]])}),staging:R({name:`staging`,cmds:{reassign:D({name:`reassign`,args:{json:k({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({json:e})=>{let t=await g();if(e){console.log(JSON.stringify({...t,notices:z}));return}console.log(t.url),console.error(`Staging hostname reassigned. ${z.join(` `)}`)}}),url:D({name:`url`,args:{json:k({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({json:e})=>{let t=await h();console.log(e?JSON.stringify({url:t}):t)}})}}),typecheck:D({name:`typecheck`,args:{},handler:S}),dev:D({name:`dev`,args:{https:k({long:`https`,description:`Serve the web app over locally trusted HTTPS.`,defaultValue:()=>!1}),host:N({long:`host`,type:P(L),description:`Host address for the web development server.`}),managed:k({long:`managed`,description:`Run managed checkout synchronization even without an interactive terminal.`,defaultValue:()=>!1}),noManaged:k({long:`no-managed`,description:`Run without managed checkout synchronization for this invocation.`,defaultValue:()=>!1}),platform:F({type:P(M(y)),displayName:`platform`,description:`Development target platform. Defaults to web.`}),port:N({long:`port`,type:P(j),description:`Port for the web development server.`})},handler:({host:e,https:t,managed:n,noManaged:r,platform:i,port:a})=>b({host:e,https:t,managed:n,noManaged:r,platform:i??`web`,webPort:a})}),upgrade:R({name:`upgrade`,cmds:{"ensure-template-remote":D({name:`ensure-template-remote`,args:{remote:N({long:`remote`,type:L,defaultValue:()=>`template`,description:`Remote name to ensure.`}),noFetch:k({long:`no-fetch`,description:`Do not fetch the remote after ensuring it exists.`,defaultValue:()=>!1})},handler:({noFetch:e,remote:t})=>w({fetch:!e,remote:t})}),"check-skill-current":D({name:`check-skill-current`,args:{target:N({long:`target`,type:L,description:`Target Coreframe template git ref.`}),apply:k({long:`apply`,description:`Replace the local upgrade skill with the target version when it differs.`,defaultValue:()=>!1})},handler:({apply:e,target:t})=>{process.exitCode=C({apply:e,target:t})}}),"fast-forward-template-files":D({name:`fast-forward-template-files`,args:{target:N({long:`target`,type:L,description:`Target Coreframe template git ref.`}),base:N({long:`base`,type:P(L),description:`Previous Coreframe template git ref. Defaults to package.json engines.coreframe.`}),apply:k({long:`apply`,description:`Write clean fast-forwards to the worktree.`,defaultValue:()=>!1})},handler:({apply:e,base:t,target:n})=>T({apply:e,base:t,target:n})})}}),db:R({name:`db`,cmds:{ensure:D({name:`ensure`,args:{},handler:u}),generate:D({name:`generate`,args:{args:I({displayName:`drizzle-kit args`,description:`Additional arguments passed to drizzle-kit generate.`})},handler:({args:e})=>a(`generate`,e)}),migrate:D({name:`migrate`,args:{args:I({displayName:`drizzle-kit args`,description:`Additional arguments passed to drizzle-kit migrate.`})},handler:({args:e})=>a(`migrate`,e)}),"migrate-held":D({name:`migrate-held`,args:{confirm:N({long:`confirm`,type:P(M([`run-held-migrations`])),description:`Required confirmation value for held migrations.`})},handler:({confirm:e})=>d({argv:e?[`--confirm=${e}`]:[]})}),"migrate-local":D({name:`migrate-local`,args:{},handler:s}),"migrations-check":D({name:`migrations-check`,args:{},handler:v}),reset:D({name:`reset`,args:{},handler:c}),seed:D({name:`seed`,args:{},handler:()=>o()}),"schema-check":D({name:`schema-check`,args:{seed:k({long:`seed`,description:`Run the configured project seed against the throwaway database.`,defaultValue:()=>!1})},handler:({seed:e})=>f({seed:e})}),setup:D({name:`setup`,args:{},handler:()=>l()}),studio:D({name:`studio`,args:{args:I({displayName:`drizzle-kit args`,description:`Additional arguments passed to drizzle-kit studio.`})},handler:({args:e})=>a(`studio`,e)})}})}});import.meta.main&&x(V);export{V as coreframeCli};
|
|
2
|
+
import{addAsset as e,buildAssets as t,checkAssets as n,printAssetResult as r,publishAssets as i}from"./assets.js";import{runDrizzleKitCommand as a}from"./db/drizzle-kit.js";import{seedLocalDb as o}from"./db/seed.js";import{migrateLocalDb as s}from"./db/migrate.js";import{resetLocalDb as c}from"./db/reset.js";import{setupLocalDb as l}from"./db/setup.js";import{ensureLocalDb as u}from"./db/ensure.js";import{migrateHeldMigrations as d}from"./db/migrate-held.js";import{checkSchemaPush as f}from"./db/schema-check.js";import{deployEnvironments as p,tauriReleasePlatforms as m}from"./deploy/config.js";import{discoverStagingUrl as h,reassignStagingHostname as g}from"./staging.js";import{discardPendingWorkerSecret as _,inspectWorkerEnvironment as v,queueWorkerSecret as y}from"./worker-environment.js";import{deployProject as b}from"./deploy.js";import{checkDeployMigrations as x}from"./deploy/check-migrations.js";import{devPlatforms as S,runDevServer as C}from"./dev.js";import{run as w}from"./runner.js";import{typecheckProject as T}from"./typecheck.js";import{checkUpgradeSkillCurrent as E}from"./upgrade/check-skill-current.js";import{ensureTemplateRemote as D}from"./upgrade/ensure-template-remote.js";import{fastForwardTemplateFiles as O}from"./upgrade/fast-forward-template-files.js";import{syncCoreframePackages as k}from"./upgrade/sync-coreframe-packages.js";import*as A from"@clack/prompts";import{array as j,command as M,extendType as N,flag as P,multioption as F,number as I,oneOf as L,option as R,optional as z,positional as B,rest as V,string as H,subcommands as U}from"cmd-ts";const W=[`Cookies and sessions are origin-scoped.`,`Exact-host passkeys may require re-registration unless a stable eligible parent RP ID was configured in advance.`,`External OAuth callbacks such as Google may need updating.`,`Database data and private backend resources are unchanged.`],G=N(H,{displayName:`widths`,description:`Comma-separated responsive variant widths.`,async from(e){let t=e.split(`,`).map(e=>Number(e));if(t.length===0||t.some(e=>!Number.isInteger(e)||e<=0)||t.some((e,n)=>n>0&&e<=t[n-1]))throw Error(`Widths must be positive, unique, strictly ascending integers.`);return t}}),K=U({name:`coreframe`,cmds:{assets:U({name:`assets`,cmds:{add:M({name:`add`,args:{file:B({type:H,displayName:`file`,description:`Source image to add to the asset library.`}),id:R({long:`id`,type:H,description:`Logical asset ID, such as blog/my-post/hero.`}),alt:R({long:`alt`,type:H,description:`Required alt text for the asset.`}),variantWidths:R({long:`widths`,type:z(G),description:`Generate exactly these comma-separated widths instead of the default ladder.`}),json:P({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({alt:t,file:n,id:i,json:a,variantWidths:o})=>r(await e({alt:t,file:n,id:i,json:a,variantWidths:o}),a)}),build:M({name:`build`,args:{id:R({long:`id`,type:z(H),description:`Build only one logical asset ID.`}),noPull:P({long:`no-pull`,description:`Do not perform targeted Git LFS pulls for missing source objects.`,defaultValue:()=>!1}),json:P({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({id:e,json:n,noPull:i})=>r(await t({id:e,json:n,pull:!i}),n)}),check:M({name:`check`,args:{fix:P({long:`fix`,description:`Build missing generated variants when possible.`,defaultValue:()=>!1}),json:P({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({fix:e,json:t})=>{let i=await n({fix:e,json:t});r(i,t),i.ok||(process.exitCode=1)}}),publish:M({name:`publish`,args:{outputDir:R({long:`output-dir`,type:z(H),description:`Root directory for additive local publish output. Defaults to COREFRAME_ASSETS_PUBLISH_DIR or release-upload.`}),json:P({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({json:e,outputDir:t})=>{let n=await i({json:e,outputDir:t});r(n,e),n.ok||(process.exitCode=1)}}),status:M({name:`status`,args:{json:P({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({json:e})=>{let t=await n({json:e});r(t,e),t.ok||(process.exitCode=1)}})}}),deploy:M({name:`deploy`,args:{environment:B({type:L(p),displayName:`environment`,description:`Deploy to the staging or production environment.`}),runMigrations:P({long:`run-migrations`,description:`Run pending deploy-safe database migrations before deploying.`,defaultValue:()=>!1}),skipMigrations:P({long:`skip-migrations`,description:`Deploy without running pending deploy-safe database migrations.`,defaultValue:()=>!1}),skipPostDeployChecks:P({long:`skip-post-deploy-checks`,description:`Skip post-deploy checks after Cloudflare deployment.`,defaultValue:()=>!1}),tauriLocalPlatforms:F({long:`tauri-local-platform`,type:j(L(m)),description:`Build one Tauri release platform locally. Repeat for multiple platforms.`,defaultValue:()=>[]}),tauriWorkflowName:R({long:`tauri-workflow-name`,type:z(H),description:`GitHub Actions workflow file or name for remote Tauri release builds.`}),tauriWorkflowPlatforms:F({long:`tauri-workflow-platform`,type:j(L(m)),description:`Build one Tauri release platform with GitHub Actions. Repeat for multiple platforms.`,defaultValue:()=>[]}),tauriWorkflowRef:R({long:`tauri-workflow-ref`,type:z(H),description:`Git ref used when dispatching remote Tauri release builds.`}),yes:P({long:`yes`,short:`y`,description:`Approve the production deployment confirmation.`,defaultValue:()=>!1})},handler:({environment:e,runMigrations:t,skipMigrations:n,skipPostDeployChecks:r,tauriLocalPlatforms:i,tauriWorkflowName:a,tauriWorkflowPlatforms:o,tauriWorkflowRef:s,yes:c})=>b([e,...t?[`--run-migrations`]:[],...n?[`--skip-migrations`]:[],...r?[`--skip-post-deploy-checks`]:[],...i.flatMap(e=>[`--tauri-local-platform`,e]),...a?[`--tauri-workflow-name`,a]:[],...o.flatMap(e=>[`--tauri-workflow-platform`,e]),...s?[`--tauri-workflow-ref`,s]:[],...c?[`--yes`]:[]])}),staging:U({name:`staging`,cmds:{reassign:M({name:`reassign`,args:{json:P({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({json:e})=>{let t=await g();if(e){console.log(JSON.stringify({...t,notices:W}));return}console.log(t.url),console.error(`Staging hostname reassigned. ${W.join(` `)}`)}}),url:M({name:`url`,args:{json:P({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({json:e})=>{let t=await h();console.log(e?JSON.stringify({url:t}):t)}})}}),secrets:U({name:`secrets`,cmds:{status:M({name:`status`,args:{environment:B({type:z(L(p)),displayName:`environment`,description:`Inspect staging, production, or both when omitted.`}),json:P({long:`json`,description:`Print machine-readable JSON.`,defaultValue:()=>!1})},handler:async({environment:e,json:t})=>{let n=await v({environment:e});console.log(t?JSON.stringify(n):q(n))}}),set:M({name:`set`,args:{environment:B({type:L(p),displayName:`environment`,description:`Worker environment to update on its next deploy.`}),name:B({type:H,displayName:`name`,description:`Declared Worker secret name.`})},handler:async({environment:e,name:t})=>{await y({environment:e,name:t,value:await J(t)}),console.log(`Queued ${t} for ${e}. Run coreframe deploy ${e} to apply.`)}}),discard:M({name:`discard`,args:{environment:B({type:L(p),displayName:`environment`,description:`Worker environment with a queued secret update.`}),name:B({type:H,displayName:`name`,description:`Declared Worker secret name.`})},handler:async({environment:e,name:t})=>{let n=await _({environment:e,name:t});console.log(n?`Discarded the queued ${t} update for ${e}.`:`No ${t} update is queued for ${e}.`)}})}}),typecheck:M({name:`typecheck`,args:{},handler:T}),dev:M({name:`dev`,args:{https:P({long:`https`,description:`Serve the web app over locally trusted HTTPS.`,defaultValue:()=>!1}),host:R({long:`host`,type:z(H),description:`Host address for the web development server.`}),managed:P({long:`managed`,description:`Run managed checkout synchronization even without an interactive terminal.`,defaultValue:()=>!1}),noManaged:P({long:`no-managed`,description:`Run without managed checkout synchronization for this invocation.`,defaultValue:()=>!1}),platform:B({type:z(L(S)),displayName:`platform`,description:`Development target platform. Defaults to web.`}),port:R({long:`port`,type:z(I),description:`Port for the web development server.`})},handler:({host:e,https:t,managed:n,noManaged:r,platform:i,port:a})=>C({host:e,https:t,managed:n,noManaged:r,platform:i??`web`,webPort:a})}),upgrade:U({name:`upgrade`,cmds:{"ensure-template-remote":M({name:`ensure-template-remote`,args:{remote:R({long:`remote`,type:H,defaultValue:()=>`template`,description:`Remote name to ensure.`}),noFetch:P({long:`no-fetch`,description:`Do not fetch the remote after ensuring it exists.`,defaultValue:()=>!1})},handler:({noFetch:e,remote:t})=>D({fetch:!e,remote:t})}),"check-skill-current":M({name:`check-skill-current`,args:{target:R({long:`target`,type:H,description:`Target Coreframe template git ref.`}),apply:P({long:`apply`,description:`Replace the local upgrade skill with the target version when it differs.`,defaultValue:()=>!1})},handler:({apply:e,target:t})=>{process.exitCode=E({apply:e,target:t})}}),"fast-forward-template-files":M({name:`fast-forward-template-files`,args:{target:R({long:`target`,type:H,description:`Target Coreframe template git ref.`}),base:R({long:`base`,type:z(H),description:`Previous Coreframe template git ref. Defaults to package.json engines.coreframe.`}),apply:P({long:`apply`,description:`Write clean fast-forwards to the worktree.`,defaultValue:()=>!1})},handler:({apply:e,base:t,target:n})=>O({apply:e,base:t,target:n})}),"sync-coreframe-packages":M({name:`sync-coreframe-packages`,args:{target:R({long:`target`,type:H,description:`Target Coreframe template git ref.`}),apply:P({long:`apply`,description:`Update existing published Coreframe dependency specifications.`,defaultValue:()=>!1})},handler:({apply:e,target:t})=>k({apply:e,target:t})})}}),db:U({name:`db`,cmds:{ensure:M({name:`ensure`,args:{},handler:u}),generate:M({name:`generate`,args:{args:V({displayName:`drizzle-kit args`,description:`Additional arguments passed to drizzle-kit generate.`})},handler:({args:e})=>a(`generate`,e)}),migrate:M({name:`migrate`,args:{args:V({displayName:`drizzle-kit args`,description:`Additional arguments passed to drizzle-kit migrate.`})},handler:({args:e})=>a(`migrate`,e)}),"migrate-held":M({name:`migrate-held`,args:{confirm:R({long:`confirm`,type:z(L([`run-held-migrations`])),description:`Required confirmation value for held migrations.`})},handler:({confirm:e})=>d({argv:e?[`--confirm=${e}`]:[]})}),"migrate-local":M({name:`migrate-local`,args:{},handler:s}),"migrations-check":M({name:`migrations-check`,args:{},handler:x}),reset:M({name:`reset`,args:{},handler:c}),seed:M({name:`seed`,args:{},handler:()=>o()}),"schema-check":M({name:`schema-check`,args:{seed:P({long:`seed`,description:`Run the configured project seed against the throwaway database.`,defaultValue:()=>!1})},handler:({seed:e})=>f({seed:e})}),setup:M({name:`setup`,args:{},handler:()=>l()}),studio:M({name:`studio`,args:{args:V({displayName:`drizzle-kit args`,description:`Additional arguments passed to drizzle-kit studio.`})},handler:({args:e})=>a(`studio`,e)})}})}});import.meta.main&&w(K);function q(e){if(e.entries.length===0)return`No Worker environment values are declared in coreframe.config.ts.`;let t=e.entries.map(e=>[e.name,e.kind,e.local===`override`?`override`:`built-in default`,e.deployed.staging.replaceAll(`_`,` `),e.deployed.production.replaceAll(`_`,` `)]),n=[`Name`,`Kind`,`Local`,`Staging`,`Production`],r=n.map((e,n)=>Math.max(e.length,...t.map(e=>e[n].length))),i=e=>e.map((e,t)=>e.padEnd(r[t])).join(` `).trimEnd();return[i(n),i(r.map(e=>`-`.repeat(e))),...t].join(`
|
|
3
|
+
`)}async function J(e){if(!process.stdin.isTTY){let e=``;for await(let t of process.stdin)e+=t.toString();return e.replace(/\r?\n$/,``)}let t=await A.password({message:`Enter the new value for ${e}`});if(A.isCancel(t))throw A.cancel(`Secret update cancelled.`),Error(`Secret update cancelled.`);return t}export{K as coreframeCli};
|
package/dist/deploy.d.ts
CHANGED
|
@@ -16,6 +16,6 @@ type DeployArgs = {
|
|
|
16
16
|
declare function deployProject(argv?: string[], env?: NodeJS.ProcessEnv): Promise<void>;
|
|
17
17
|
declare function parseDeployArgs(argv: string[]): DeployArgs;
|
|
18
18
|
declare function resolveDeployUrl(config: ResolvedDeployConfig, environment: DeployEnvironment, discover?: () => Promise<string>): Promise<string>;
|
|
19
|
-
declare function
|
|
19
|
+
declare function resolveDashboardPassword(env: NodeJS.ProcessEnv, environment: DeployEnvironment): Promise<string>;
|
|
20
20
|
//#endregion
|
|
21
|
-
export { deployProject, parseDeployArgs, readProjectConfig,
|
|
21
|
+
export { deployProject, parseDeployArgs, readProjectConfig, resolveDashboardPassword, resolveDeployUrl };
|
package/dist/deploy.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{readProjectConfig as e}from"./config.js";import{createProjectDeployDatabase as t}from"./db/project.js";import{collectDeployMigrationFiles as n,formatMigrationList as r,formatMigrationScanFailures as i,scanDeployMigrationFiles as a}from"./deploy/migrations.js";import{runPostDeployChecks as
|
|
2
|
+
import{readProjectConfig as e}from"./config.js";import{createProjectDeployDatabase as t}from"./db/project.js";import{collectDeployMigrationFiles as n,formatMigrationList as r,formatMigrationScanFailures as i,scanDeployMigrationFiles as a}from"./deploy/migrations.js";import{runPostDeployChecks as ee}from"./deploy/checks.js";import{deployEnvironments as o,resolveDeployConfig as s}from"./deploy/config.js";import{filterPendingMigrations as c,readAppliedMigrationNames as l}from"./deploy/pending-migrations.js";import{parseTauriReleasePlatform as u,prepareTauriRelease as d,resolveTauriReleasePlan as f,restoreTauriReleaseMetadata as te,uploadTauriReleaseToB2 as ne,validateTauriReleasePlan as p,writeTauriReleaseMetadata as m}from"./deploy/tauri-release.js";import{readPackageJson as h,releaseName as g,resolveReleaseVersion as _,writePackageVersion as v}from"./deploy/version.js";import{discoverStagingUrl as y}from"./staging.js";import{clearAppliedPendingWorkerSecrets as b,readPendingWorkerSecretSnapshot as x}from"./worker-environment.js";import{mkdtemp as S,readFile as C,rm as w,writeFile as T}from"node:fs/promises";import{join as E}from"node:path";import D from"nano-spawn";import*as O from"@clack/prompts";import{tmpdir as k}from"node:os";import{parseEnv as A}from"node:util";const j=`package.json`;async function M(n=process.argv.slice(2),r=process.env){let o=N(n);V(o);let{packageJson:c,source:l}=await h(j),u=await e(),S=s(u.deploy??{},o.environment,r);K(r,[`POSTHOG_API_KEY`,`POSTHOG_PROJECT_ID`]);let C=await H(S,o.environment,()=>y({env:r})),w=f({args:o,config:o.environment===`production`?S.tauriRelease:{},env:r});G(o.environment,w.enabled),await p(w);let E=await x({environment:o.environment}),k=E.values.DASHBOARD_PASSWORD??await q(r,o.environment),A=await B(),M=_(o.environment,c.version,A),P=g(c.name,M),F=X(r,o.environment,P,c.name,M),I=o.environment===`production`,R=!1,U={files:[]};O.intro(`Deploy ${P} to ${o.environment}`);let Y=Object.keys(E.values).sort();Y.length>0&&O.note(Y.join(`
|
|
3
|
+
`),`Pending Worker secret updates`),await W(o);let Q=await L(await t({config:u.database,env:r})),$=await a(Q);if($.length>0)throw Error(`Pending deploy migrations contain unsafe SQL. Move unsafe statements to held migrations.\n${i($)}`);let re=await z(o,Q);try{I&&(await v(j,c,M),U=await m(w,M)),O.log.step(`Running pre-deploy build`),await D(`pnpm`,[`build`],{env:Z(F),stdio:`inherit`});let e=w.enabled?await d({env:Z(F),plan:w,releaseName:P,version:M}):void 0;O.log.step(`Running release build and uploading PostHog source maps`),R=!0,await D(`pnpm`,[`build`],{env:F,stdio:`inherit`}),re&&(O.log.step(`Running deploy-safe database migrations`),await D(`pnpm`,[`db`,`migrate`],{env:F,stdio:`inherit`})),O.log.step(`Deploying Worker and static assets to Cloudflare`);let t={...k?{DASHBOARD_PASSWORD:k}:{},...E.values},n=Object.keys(t).length>0?await J(t):void 0;try{await D(`pnpm`,[`exec`,`wrangler`,`deploy`,`--env`,o.environment,`--strict`,`--keep-vars`,`--tag`,P,`--message`,`Deploy ${P}`,`--var`,`DEPLOY_ENV:${o.environment}`,`--var`,`POSTHOG_RELEASE:${P}`,...n?[`--secrets-file`,n.path]:[]],{env:F,stdio:`inherit`}),await b(E)}finally{await n?.dispose()}o.skipPostDeployChecks||(O.log.step(`Running post-deploy checks`),await ee(S,{environment:o.environment,releaseName:P,url:C,version:M})),e&&(O.log.step(`Uploading Tauri release artifacts to Backblaze B2`),await ne(w,e)),O.outro(`Deployed ${P} to ${o.environment}`)}catch(e){throw!R&&I&&(await T(j,l),await te(U)),e}}function N(e){return{environment:P(e[0]),runMigrations:e.includes(`--run-migrations`),skipMigrations:e.includes(`--skip-migrations`),skipPostDeployChecks:e.includes(`--skip-post-deploy-checks`),tauriLocalPlatforms:F(e,`--tauri-local-platform`).map(e=>u(e)),tauriWorkflowName:I(e,`--tauri-workflow-name`),tauriWorkflowPlatforms:F(e,`--tauri-workflow-platform`).map(e=>u(e)),tauriWorkflowRef:I(e,`--tauri-workflow-ref`),yes:e.includes(`--yes`)}}function P(e){if(e&&o.includes(e))return e;throw Error(`Deploy environment must be one of: ${o.join(`, `)}.`)}function F(e,t){let n=[];for(let r=0;r<e.length;r+=1){let i=e[r];if(i===t){let i=e[r+1];if(!i||i.startsWith(`--`))throw Error(`${t} requires a value.`);n.push(...i.split(`,`).filter(Boolean)),r+=1;continue}i.startsWith(`${t}=`)&&n.push(...i.slice(t.length+1).split(`,`).filter(Boolean))}return n}function I(e,t){let n=F(e,t);if(n.length>1)throw Error(`${t} can only be provided once.`);return n[0]}async function L(e){try{return await R(e)}finally{await e.close?.()}}async function R(e){return c(await n(),await l(e))}async function z(e,t){if(t.length===0)return O.log.info(`No pending deploy migrations.`),!1;if(O.note(r(t),`Pending deploy migrations`),e.runMigrations)return!0;if(e.skipMigrations)return!1;if(!process.stdout.isTTY)throw Error(`Pending migrations require --run-migrations or --skip-migrations in noninteractive deploys.`);let n=await O.confirm({initialValue:!0,message:`Run these deploy-safe database migrations before Cloudflare deploy?`});if(O.isCancel(n))throw O.cancel(`Deploy cancelled.`),Error(`Deploy cancelled.`);return n}async function B(){let{stdout:e}=await D(`git`,[`status`,`--porcelain`],{stdin:`ignore`});if(e.trim().length>0)throw Error(`Deploy requires a clean git tree.`);let{stdout:t}=await D(`git`,[`rev-parse`,`--short=12`,`HEAD`],{stdin:`ignore`});return t.trim()}function V(e){if(e.runMigrations&&e.skipMigrations)throw Error(`Use only one of --run-migrations or --skip-migrations.`)}async function H(e,t,n=y){return e.url?U(e.url,t):t===`staging`&&e.stagingHostname?U(await n(),t):U(void 0,t)}function U(e,t){if(!e)throw Error(`Missing ${t} deploy URL. Set DEPLOY_URL or deploy.environments.${t}.url in coreframe.config.ts.`);let n;try{n=new URL(e)}catch{throw Error(`Invalid ${t} deploy URL "${e}". Expected an HTTP(S) URL.`)}if(n.protocol!==`http:`&&n.protocol!==`https:`)throw Error(`Invalid ${t} deploy URL "${e}". Expected an HTTP(S) URL.`);return n.toString()}async function W(e){if(e.environment!==`production`||e.yes)return;if(!process.stdout.isTTY)throw Error(`Production deploys require --yes in noninteractive environments.`);let t=await O.confirm({initialValue:!1,message:`Deploy to production?`});if(O.isCancel(t)||!t)throw O.cancel(`Deploy cancelled.`),Error(`Deploy cancelled.`)}function G(e,t){if(e===`staging`&&t)throw Error(`Tauri releases can only be published from production deploys.`)}function K(e,t){let n=t.filter(t=>!e[t]);if(n.length>0)throw Error(`Missing required deploy environment variables: ${n.join(`, `)}`);return Object.fromEntries(t.map(t=>[t,e[t]]))}async function q(e,t){let n=e.DASHBOARD_PASSWORD?.trim();if(n)return n;let r;try{r=A(await C(`.env`,`utf8`))}catch(e){throw Y(e)&&e.code===`ENOENT`?Error(`Missing ${t} dashboard password. Set DASHBOARD_PASSWORD in ".env".`):e}let i=r.DASHBOARD_PASSWORD?.trim();if(!i)throw Error(`Missing ${t} dashboard password. Set DASHBOARD_PASSWORD in ".env".`);return i}async function J(e){let t=await S(E(k(),`coreframe-deploy-secrets-`)),n=E(t,`secrets.json`);return await T(n,JSON.stringify(e),{mode:384}),{path:n,dispose:()=>w(t,{force:!0,recursive:!0})}}function Y(e){return e instanceof Error&&`code`in e}function X(e,t,n,r,i){return{...e,CLOUDFLARE_ENV:t,DEPLOY_ENV:t,POSTHOG_RELEASE:n,POSTHOG_RELEASE_NAME:e.POSTHOG_RELEASE_NAME??r,POSTHOG_RELEASE_VERSION:e.POSTHOG_RELEASE_VERSION??i}}function Z(e){let{POSTHOG_API_KEY:t,POSTHOG_PROJECT_ID:n,...r}=e;return r}export{M as deployProject,N as parseDeployArgs,e as readProjectConfig,q as resolveDashboardPassword,H as resolveDeployUrl};
|
package/dist/dev-lock.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomUUID as e}from"node:crypto";import{link as t,mkdir as n,readFile as r,unlink as i,writeFile as a}from"node:fs/promises";import o from"node:path";import s from"
|
|
1
|
+
import{randomUUID as e}from"node:crypto";import{link as t,mkdir as n,readFile as r,unlink as i,writeFile as a}from"node:fs/promises";import o from"node:path";import*as s from"@clack/prompts";import c from"node:process";const l={isRunning:m,stop(e){try{c.kill(e,`SIGTERM`)}catch(e){if(!_(e))throw e}},waitForExit:h};async function u({confirmStop:r=d,cwd:s=c.cwd(),interactive:u=c.stdin.isTTY===!0,pid:m=c.pid,processes:h=l}={}){let _=o.resolve(s,`.coreframe/dev.lock`),v={pid:m,token:e()},y=`${JSON.stringify(v)}\n`,b=`${_}.${v.token}.tmp`;await n(o.dirname(_),{recursive:!0}),await a(b,y,{flag:`wx`,mode:384});try{for(;;){try{return await t(b,_),{async release(){await p(_,y)}}}catch(e){if(!g(e))throw e}let e=await f(_);if(!e||!h.isRunning(e.owner.pid)){await p(_,e?.source);continue}if(!u)throw Error(`Coreframe dev is already running for this project (PID ${e.owner.pid}). Stop it before starting another.`);if(!await r(e.owner.pid))return;h.stop(e.owner.pid),await h.waitForExit(e.owner.pid),await p(_,e.source)}}finally{await i(b).catch(()=>void 0)}}async function d(e){let t=await s.confirm({initialValue:!1,message:`Coreframe dev is already running for this project (PID ${e}). Stop it and start here?`});return s.isCancel(t)||!t?(s.cancel(`Keeping the existing Coreframe dev process.`),!1):!0}async function f(e){try{let t=await r(e,`utf8`),n=JSON.parse(t);return!Number.isSafeInteger(n.pid)||Number(n.pid)<=0||!n.token?void 0:{owner:n,source:t}}catch{return}}async function p(e,t){let n=await r(e,`utf8`).catch(()=>void 0);(t===void 0||n===t)&&await i(e).catch(()=>void 0)}function m(e){try{return c.kill(e,0),!0}catch(e){return!_(e)}}async function h(e){let t=Date.now()+1e4;for(;m(e);){if(Date.now()>=t)throw Error(`Coreframe dev process ${e} did not stop within 10 seconds.`);await new Promise(e=>setTimeout(e,50))}}function g(e){return v(e)&&e.code===`EEXIST`}function _(e){return v(e)&&e.code===`ESRCH`}function v(e){return e instanceof Error}export{u as acquireDevLock};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region upgrade/sync-coreframe-packages.d.ts
|
|
2
|
+
type SyncCoreframePackagesOptions = {
|
|
3
|
+
apply: boolean;
|
|
4
|
+
target: string;
|
|
5
|
+
};
|
|
6
|
+
declare function syncCoreframePackages(args: SyncCoreframePackagesOptions): void;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { SyncCoreframePackagesOptions, syncCoreframePackages };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{coreframeGitRef as e}from"./template-ref.js";import{posix as t,resolve as n}from"node:path";import{readFileSync as r,writeFileSync as i}from"node:fs";import{spawnSync as a}from"node:child_process";const o=[`dependencies`,`devDependencies`];function s(e){let t=a(`git`,e,{encoding:`utf8`});if(t.status!==0){let n=t.stderr.trim()||t.stdout.trim();throw Error(`Git command failed: git ${e.join(` `)}${n?`\n${n}`:``}`)}return t.stdout}function c(e,t){try{return JSON.parse(e)}catch(e){throw Error(`Could not parse ${t}: ${e instanceof Error?e.message:e}`)}}function l(t,n){let r=`${e(t)}:${n}`;return c(s([`show`,r]),r)}function u(e){return e.startsWith(`@coreframe/`)}function d(e){return e.startsWith(`file:`)||e.startsWith(`link:`)||e.startsWith(`workspace:`)}function f(e){return e.startsWith(`file:`)||e.startsWith(`link:`)}function p(e,n){let r=e.indexOf(`:`),i=e.slice(r+1),a=t.normalize(t.join(`template`,i,`package.json`));if(i.length===0||t.isAbsolute(i)||a===`..`||a.startsWith(`../`))throw Error(`Invalid local template dependency for ${n}: ${e}`);return a}function m(t){let n=l(t,`template/package.json`),r=[],i=new Set;for(let a of o)for(let[o,s]of Object.entries(n[a]??{})){if(!u(o)||!f(s))continue;if(i.has(o))throw Error(`Target template declares ${o} more than once.`);let n=p(s,o),c=l(t,n);if(c.name!==o||typeof c.version!=`string`)throw Error(`${e(t)}:${n} must declare ${o} with a version.`);r.push({group:a,name:o,spec:`^${c.version}`}),i.add(o)}return r}function h(e,t){for(let n of o){let r=e[n]?.[t];if(r)return{group:n,spec:r}}}function g(e,t,n){let r=t.match(/\n([\t ]+)"/u)?.[1]??` `,a=t.endsWith(`
|
|
3
|
+
`)?`
|
|
4
|
+
`:``;i(e,`${JSON.stringify(n,null,r)}${a}`)}function _(e,t){if(t.length!==0){console.log(`${e}:`);for(let e of t)console.log(` ${e}`);console.log(``)}}function v(t){let i=n(s([`rev-parse`,`--show-toplevel`]).trim(),`package.json`),a=r(i,`utf8`),l=c(a,i),f=e(t.target),p=m(f),v=new Set(p.map(({name:e})=>e)),y=[],b=[],x=[],S=0;for(let e of p){let t=h(l,e.name);if(!t){b.push(`missing: ${e.name} ${e.spec} (${e.group})`);continue}if(d(t.spec)){x.push(`linked: ${e.name} ${t.spec}`);continue}if(t.spec===e.spec){S+=1;continue}y.push({...e,currentGroup:t.group,currentSpec:t.spec})}let C=o.flatMap(e=>Object.entries(l[e]??{}).filter(([e])=>u(e)&&!v.has(e)).map(([t,n])=>`review: ${t} ${n} (${e})`));if(t.apply&&y.length>0){for(let e of y)l[e.currentGroup][e.name]=e.spec;g(i,a,l)}console.log(`Coreframe package sync: ${f}`),console.log(``),_(t.apply?`Updated Coreframe packages`:`Would update Coreframe packages`,y.map(({currentSpec:e,name:t,spec:n})=>`update: ${t} ${e} -> ${n}`)),_(`Missing target Coreframe packages`,b),_(`Locally linked Coreframe packages`,x),_(`Downstream-only Coreframe packages`,C),S>0&&console.log(`${S} Coreframe package(s) already match the target versions.`),y.length===0?console.log(`No Coreframe package version updates found.`):t.apply||(console.log(``),console.log(`Run with --apply to write the ${y.length} package update(s).`))}export{v as syncCoreframePackages};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { DeployEnvironment } from "./deploy/config.js";
|
|
2
|
+
|
|
3
|
+
//#region worker-environment.d.ts
|
|
4
|
+
declare const workerEnvironmentKinds: readonly ["secret", "variable", "generated"];
|
|
5
|
+
type WorkerEnvironmentKind = (typeof workerEnvironmentKinds)[number];
|
|
6
|
+
type WorkerEnvironmentVariableConfig = {
|
|
7
|
+
description: string;
|
|
8
|
+
kind: WorkerEnvironmentKind;
|
|
9
|
+
requiredIn?: DeployEnvironment[];
|
|
10
|
+
};
|
|
11
|
+
type WorkerConfig = {
|
|
12
|
+
environment?: Record<string, WorkerEnvironmentVariableConfig>;
|
|
13
|
+
};
|
|
14
|
+
type LocalWorkerEnvironmentState = "default" | "override";
|
|
15
|
+
type DeployedWorkerEnvironmentState = "configured" | "declared" | "generated" | "missing" | "not_configured" | "pending_addition" | "pending_replacement" | "pending_update" | "unknown";
|
|
16
|
+
type WorkerEnvironmentEntryStatus = WorkerEnvironmentVariableConfig & {
|
|
17
|
+
name: string;
|
|
18
|
+
local: LocalWorkerEnvironmentState;
|
|
19
|
+
deployed: Record<DeployEnvironment, DeployedWorkerEnvironmentState>;
|
|
20
|
+
};
|
|
21
|
+
type WorkerEnvironmentProviderStatus = {
|
|
22
|
+
state: "available" | "not_checked" | "unavailable";
|
|
23
|
+
message?: string;
|
|
24
|
+
};
|
|
25
|
+
type WorkerEnvironmentStatus = {
|
|
26
|
+
entries: WorkerEnvironmentEntryStatus[];
|
|
27
|
+
providers: Record<DeployEnvironment, WorkerEnvironmentProviderStatus>;
|
|
28
|
+
undeclaredSecrets: Record<DeployEnvironment, string[]>;
|
|
29
|
+
};
|
|
30
|
+
type PendingWorkerSecretSnapshot = {
|
|
31
|
+
environment: DeployEnvironment;
|
|
32
|
+
values: Readonly<Record<string, string>>;
|
|
33
|
+
};
|
|
34
|
+
type InspectWorkerEnvironmentOptions = {
|
|
35
|
+
cwd?: string;
|
|
36
|
+
environment?: DeployEnvironment;
|
|
37
|
+
listSecrets?: (environment: DeployEnvironment, cwd: string) => Promise<string[]>;
|
|
38
|
+
};
|
|
39
|
+
type QueueWorkerSecretOptions = {
|
|
40
|
+
cwd?: string;
|
|
41
|
+
environment: DeployEnvironment;
|
|
42
|
+
name: string;
|
|
43
|
+
value: string;
|
|
44
|
+
ensureIgnored?: (environment: DeployEnvironment, cwd: string) => Promise<void>;
|
|
45
|
+
};
|
|
46
|
+
declare function inspectWorkerEnvironment({
|
|
47
|
+
cwd,
|
|
48
|
+
environment,
|
|
49
|
+
listSecrets
|
|
50
|
+
}?: InspectWorkerEnvironmentOptions): Promise<WorkerEnvironmentStatus>;
|
|
51
|
+
declare function queueWorkerSecret({
|
|
52
|
+
cwd,
|
|
53
|
+
environment,
|
|
54
|
+
name,
|
|
55
|
+
value,
|
|
56
|
+
ensureIgnored
|
|
57
|
+
}: QueueWorkerSecretOptions): Promise<void>;
|
|
58
|
+
declare function discardPendingWorkerSecret({
|
|
59
|
+
cwd,
|
|
60
|
+
environment,
|
|
61
|
+
name
|
|
62
|
+
}: Omit<QueueWorkerSecretOptions, "value" | "ensureIgnored">): Promise<boolean>;
|
|
63
|
+
declare function readPendingWorkerSecretSnapshot({
|
|
64
|
+
cwd,
|
|
65
|
+
environment
|
|
66
|
+
}: {
|
|
67
|
+
cwd?: string;
|
|
68
|
+
environment: DeployEnvironment;
|
|
69
|
+
}): Promise<PendingWorkerSecretSnapshot>;
|
|
70
|
+
declare function clearAppliedPendingWorkerSecrets(snapshot: PendingWorkerSecretSnapshot, cwd?: string): Promise<void>;
|
|
71
|
+
//#endregion
|
|
72
|
+
export { DeployedWorkerEnvironmentState, LocalWorkerEnvironmentState, PendingWorkerSecretSnapshot, WorkerConfig, WorkerEnvironmentEntryStatus, WorkerEnvironmentKind, WorkerEnvironmentProviderStatus, WorkerEnvironmentStatus, WorkerEnvironmentVariableConfig, clearAppliedPendingWorkerSecrets, discardPendingWorkerSecret, inspectWorkerEnvironment, queueWorkerSecret, readPendingWorkerSecretSnapshot, workerEnvironmentKinds };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readProjectConfig as e}from"./config.js";import{deployEnvironments as t}from"./deploy/config.js";import{randomUUID as n}from"node:crypto";import{chmod as r,mkdir as i,readFile as a,rename as o,rm as s,stat as c,writeFile as l}from"node:fs/promises";import{resolve as u}from"node:path";import d from"nano-spawn";import{parseEnv as f}from"node:util";const p=[`secret`,`variable`,`generated`],m=/^[A-Z][A-Z0-9_]*$/,h=`.coreframe/deploy-secrets`;async function g({cwd:n=process.cwd(),environment:r,listSecrets:i=A}={}){let a=x((await e({cwd:n})).worker?.environment),o=await C(n),s=r?[r]:t,c=new Map,l=new Map,u=Object.fromEntries(t.map(e=>[e,{state:`not_checked`}]));await Promise.all(s.map(async e=>{if(l.set(e,new Set(Object.keys((await y({cwd:n,environment:e})).values))),a.some(e=>e.kind===`secret`))try{c.set(e,new Set(await i(e,n))),u[e]={state:`available`}}catch{u[e]={state:`unavailable`,message:`Could not read ${e} Worker secrets. Check Wrangler authentication and whether the Worker exists.`}}}));let d=new Set(a.filter(e=>e.kind===`secret`).map(e=>e.name)),f=Object.fromEntries(t.map(e=>[e,[...c.get(e)??[]].filter(e=>!d.has(e)).sort()]));return{entries:a.map(e=>({...e,local:o.has(e.name)?`override`:`default`,deployed:Object.fromEntries(t.map(t=>[t,w(e,t,u[t],c.get(t),l.get(t))]))})),providers:u,undeclaredSecrets:f}}async function _({cwd:e=process.cwd(),environment:t,name:n,value:r,ensureIgnored:i=D}){if(await S(e,n),!r.trim())throw Error(`Worker secret values cannot be empty.`);await i(t,e),await E(e,t,{...(await y({cwd:e,environment:t})).values,[n]:r})}async function v({cwd:e=process.cwd(),environment:t,name:n}){await S(e,n);let r=await y({cwd:e,environment:t});if(!(n in r.values))return!1;let i={...r.values};return delete i[n],await E(e,t,i),!0}async function y({cwd:t=process.cwd(),environment:n}){let r=await T(t,n),i=x((await e({cwd:t})).worker?.environment),a=new Set(i.filter(e=>e.kind===`secret`).map(e=>e.name)),o=Object.keys(r).filter(e=>!a.has(e));if(o.length>0)throw Error(`Pending ${n} Worker secrets are not declared as secrets in coreframe.config.ts: ${o.join(`, `)}.`);return{environment:n,values:r}}async function b(e,t=process.cwd()){let n=await T(t,e.environment),r=Object.fromEntries(Object.entries(n).filter(([t,n])=>e.values[t]!==n));await E(t,e.environment,r)}function x(e){return Object.entries(e??{}).map(([e,t])=>{if(!m.test(e))throw Error(`Invalid Worker environment name ${JSON.stringify(e)} in coreframe.config.ts. Use uppercase letters, numbers, and underscores.`);return{...t,name:e,requiredIn:[...new Set(t.requiredIn??[])]}}).sort((e,t)=>e.name.localeCompare(t.name))}async function S(t,n){let r=x((await e({cwd:t})).worker?.environment).find(e=>e.name===n);if(!r)throw Error(`${n} is not declared in coreframe.config.ts.`);if(r.kind!==`secret`)throw Error(`${n} is declared as ${r.kind}, not a Worker secret.`)}async function C(e){try{let t=f(await a(u(e,`.env`),`utf8`));return new Set(Object.entries(t).filter(([,e])=>!!e?.trim()).map(([e])=>e))}catch(e){if(j(e)&&e.code===`ENOENT`)return new Set;throw e}}function w(e,t,n,r,i){return e.kind===`generated`?`generated`:e.kind===`variable`?`declared`:i?.has(e.name)?n.state!==`available`||!r?`pending_update`:r.has(e.name)?`pending_replacement`:`pending_addition`:n.state!==`available`||!r?`unknown`:r.has(e.name)?`configured`:e.requiredIn.includes(t)?`missing`:`not_configured`}async function T(e,t){let n=O(e,t);try{let e=await c(n);if(process.platform!==`win32`&&e.mode&63)throw Error(`Pending Worker secret file ${n} must use mode 0600.`);let t=JSON.parse(await a(n,`utf8`));if(!k(t))throw Error(`Pending Worker secret file ${n} must contain a JSON object of strings.`);return t}catch(e){if(j(e)&&e.code===`ENOENT`)return{};throw e}}async function E(e,t,a){let c=O(e,t);if(Object.keys(a).length===0){await s(c,{force:!0});return}let d=u(e,h);await i(d,{mode:448,recursive:!0}),process.platform!==`win32`&&await r(d,448);let f=`${c}.${process.pid}.${n()}.tmp`;try{await l(f,`${JSON.stringify(a,null,2)}\n`,{flag:`wx`,mode:384}),await o(f,c)}finally{await s(f,{force:!0})}process.platform!==`win32`&&await r(c,384)}async function D(e,t){let n=`${h}/${e}.json`,r=`${h}/.coreframe-ignore-check`;try{await d(`git`,[`check-ignore`,`--quiet`,r],{cwd:t,stdin:`ignore`,stdout:`ignore`,stderr:`ignore`})}catch{throw Error(`Refusing to store plaintext Worker secrets because ${n} is not git-ignored. Add .coreframe/ to .gitignore.`)}}function O(e,t){return u(e,h,`${t}.json`)}function k(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.entries(e).every(([e,t])=>m.test(e)&&typeof t==`string`&&t.length>0)}async function A(e,t){let{stdout:n}=await d(`pnpm`,[`exec`,`wrangler`,`secret`,`list`,`--env`,e,`--format`,`json`],{cwd:t,env:{CI:`true`},stdin:`ignore`,timeout:5e3}),r=JSON.parse(n);if(!Array.isArray(r))throw Error(`Wrangler returned an invalid secret list.`);return r.flatMap(e=>e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`?[e.name]:[])}function j(e){return e instanceof Error&&`code`in e}export{b as clearAppliedPendingWorkerSecrets,v as discardPendingWorkerSecret,g as inspectWorkerEnvironment,_ as queueWorkerSecret,y as readPendingWorkerSecretSnapshot,p as workerEnvironmentKinds};
|