create-trokky 0.1.3 → 0.1.5
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/cli.js +2 -0
- package/dist/config.js +2 -1
- package/dist/emit.js +13 -1
- package/dist/generate.js +16 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -86,6 +86,8 @@ async function main() {
|
|
|
86
86
|
console.log(` # ${secret.name}= (${secret.optional ? 'optional — ' : ''}${secret.why})`);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
+
if (config.target === 'workers')
|
|
90
|
+
console.log(' echo TROKKY_ENV=development >> .dev.vars');
|
|
89
91
|
console.log(' npm install');
|
|
90
92
|
console.log(config.target === 'workers' ? ' npm run build && npm run preview' : ' npm run dev');
|
|
91
93
|
}
|
package/dist/config.js
CHANGED
|
@@ -22,7 +22,8 @@ export function withDefaults(input) {
|
|
|
22
22
|
images: pick('images'),
|
|
23
23
|
parts: pick('parts'),
|
|
24
24
|
content: pick('content'),
|
|
25
|
-
|
|
25
|
+
// 3.6: TrokkyCore takes `env`, which the Workers entry passes
|
|
26
|
+
trokkyVersion: input.trokkyVersion ?? '^3.6.0',
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
export const hasStudio = (config) => config.parts !== 'api';
|
package/dist/emit.js
CHANGED
|
@@ -56,7 +56,8 @@ export function packageJson(config) {
|
|
|
56
56
|
else {
|
|
57
57
|
scripts.dev = 'tsx watch src/server.ts';
|
|
58
58
|
scripts.build = 'tsc -p tsconfig.json';
|
|
59
|
-
|
|
59
|
+
// rootDir is the project, so tsc mirrors src/ under dist/
|
|
60
|
+
scripts.start = 'node dist/src/server.js';
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
return JSON.stringify({
|
|
@@ -196,6 +197,8 @@ export interface TrokkyEnv {
|
|
|
196
197
|
MEDIA: R2Bucket
|
|
197
198
|
${config.images === 'cloudflare-images' ? ' IMAGES: ImagesBinding\n' : ''}${hasStudio(config) || config.content !== 'blank' ? ' ASSETS: { fetch(request: Request): Promise<Response> }\n' : ''} TROKKY_JWT_SECRET?: string
|
|
198
199
|
TROKKY_CLAIM_SECRET?: string
|
|
200
|
+
/** 'development' in .dev.vars for \`wrangler dev\`; unset when deployed */
|
|
201
|
+
TROKKY_ENV?: string
|
|
199
202
|
}
|
|
200
203
|
|
|
201
204
|
export const API_PATH = '/api'
|
|
@@ -226,6 +229,9 @@ ${mediaConfig} },
|
|
|
226
229
|
{
|
|
227
230
|
jwtSecret: env.TROKKY_JWT_SECRET,
|
|
228
231
|
claimSecret: env.TROKKY_CLAIM_SECRET,
|
|
232
|
+
// A Worker has no NODE_ENV: say production unless .dev.vars says otherwise, so a deploy
|
|
233
|
+
// without a real signing key refuses to start instead of signing with a random one
|
|
234
|
+
env: env.TROKKY_ENV === 'development' ? 'development' : 'production',
|
|
229
235
|
},
|
|
230
236
|
)
|
|
231
237
|
// Creates the image processor; nothing serves images without it.
|
|
@@ -451,6 +457,12 @@ export function envExample(config) {
|
|
|
451
457
|
for (const secret of secrets) {
|
|
452
458
|
lines.push(...comment(secret.why), `${secret.name}=`, '');
|
|
453
459
|
}
|
|
460
|
+
if (edge) {
|
|
461
|
+
// TROKKY_ENV=development is not listed here: the deploy button offers every line of this
|
|
462
|
+
// file as a value to set on the deployed Worker, which must run with the production checks.
|
|
463
|
+
// The README adds it to the local .dev.vars instead.
|
|
464
|
+
lines.push(...comment('For local development, also add TROKKY_ENV=development to your .dev.vars (the'), ...comment('README shows how). Never set it on the deployed Worker.'), '');
|
|
465
|
+
}
|
|
454
466
|
if (config.data === 'postgres-data')
|
|
455
467
|
lines.push('# Postgres connection string.', 'DATABASE_URL=', '');
|
|
456
468
|
// Only where something is actually written to disk. A Worker has none, and with s3-media the
|
package/dist/generate.js
CHANGED
|
@@ -99,6 +99,7 @@ Generated with \`npm create trokky@latest\`.
|
|
|
99
99
|
|
|
100
100
|
\`\`\`
|
|
101
101
|
${edge ? `cp .dev.vars.example .dev.vars # fill both secrets
|
|
102
|
+
echo TROKKY_ENV=development >> .dev.vars
|
|
102
103
|
npm install
|
|
103
104
|
npm run build && npm run preview` : `cp .env.example .env # fill both secrets
|
|
104
105
|
npm install
|
|
@@ -109,16 +110,28 @@ ${edge ? `## Deploy
|
|
|
109
110
|
|
|
110
111
|
\`\`\`
|
|
111
112
|
npm run build && npm run deploy
|
|
113
|
+
npx wrangler secret put TROKKY_CLAIM_SECRET
|
|
114
|
+
npx wrangler secret put TROKKY_JWT_SECRET
|
|
112
115
|
\`\`\`
|
|
113
116
|
|
|
117
|
+
\`.dev.vars\` is not uploaded, so the deployed Worker needs its own secrets; without
|
|
118
|
+
\`TROKKY_JWT_SECRET\` it answers with an error. Set the claim secret first: once the JWT secret
|
|
119
|
+
is in, the site answers, and an unset claim secret leaves the claim open.
|
|
120
|
+
|
|
114
121
|
Wrangler provisions the D1 database and R2 bucket named in \`wrangler.jsonc\` on first deploy.
|
|
115
122
|
\`database_id\` is intentionally empty: it is bound by name.
|
|
116
123
|
|
|
117
124
|
` : ''}## The first minute
|
|
118
125
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
126
|
+
${hasStudio(config) ? `Open \`/studio\`. Nobody owns this instance yet, so the first screen asks you to **claim** it:
|
|
127
|
+
pick a username, an email and a password, and paste \`TROKKY_CLAIM_SECRET\`.` : `Nobody owns this instance yet. **Claim** it over HTTP (on a deployed site, use its URL instead of
|
|
128
|
+
localhost); the response signs you in:
|
|
129
|
+
|
|
130
|
+
\`\`\`
|
|
131
|
+
curl -X POST http://localhost:${edge ? '8787' : '3000'}/api/auth/claim -H 'Content-Type: application/json' \\
|
|
132
|
+
-d '{"username":"admin","email":"you@example.com","password":"<a strong password>","secret":"<TROKKY_CLAIM_SECRET>"}'
|
|
133
|
+
\`\`\``}
|
|
134
|
+
${config.content === 'blank' ? '' : edge ? 'Sample content appears a moment after the claim — edit it or delete it.' : 'Sample content is written at the first start — edit it or delete it.'}
|
|
122
135
|
|
|
123
136
|
Without a claim secret the claim is open to whoever reaches the URL first. That is fine for the
|
|
124
137
|
minute between deploying and opening the link; it is not fine for an instance left sitting.
|