@fastly/compute-js-static-publish 8.1.0-beta.2 → 8.1.0-beta.4
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/CHANGELOG.md +601 -0
- package/DOCUMENTATION.md +28 -19
- package/README.md +18 -5
- package/README.short.md +18 -5
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +8 -10
- package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/deploy.js +68 -12
- package/build/cli/cli/commands/manage/eject.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/eject.js +22 -5
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +9 -4
- package/build/cli/cli/commands/manage/status.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/status.js +6 -0
- package/build/cli/cli/commands/manage/template/init.js +6 -6
- package/build/cli/cli/commands/run-dev-watch.d.ts +1 -0
- package/build/cli/cli/commands/run-dev-watch.d.ts.map +1 -1
- package/build/cli/cli/commands/run-dev-watch.js +45 -9
- package/build/cli/cli/commands/scaffold/generate-app.d.ts +10 -3
- package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/generate-app.js +17 -1
- package/build/cli/cli/commands/scaffold/index.d.ts +3 -3
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +27 -24
- package/build/cli/cli/managed/app.d.ts +1 -1
- package/build/cli/cli/managed/app.d.ts.map +1 -1
- package/build/cli/cli/managed/app.js +5 -3
- package/build/cli/cli/managed/lockfile.js +1 -1
- package/build/cli/cli/managed/project-file.d.ts.map +1 -1
- package/build/cli/cli/managed/project-file.js +13 -4
- package/build/cli/cli/managed/template-init.d.ts.map +1 -1
- package/build/cli/cli/managed/template-init.js +3 -1
- package/build/cli/cli/util/collection-selection-flags.d.ts +1 -1
- package/build/cli/cli/util/collection-selection-flags.d.ts.map +1 -1
- package/build/cli/cli/util/collection-selection-flags.js +31 -5
- package/build/cli/cli/util/config.d.ts.map +1 -1
- package/build/cli/cli/util/config.js +9 -0
- package/build/cli/cli/util/fastly-options.d.ts +2 -0
- package/build/cli/cli/util/fastly-options.d.ts.map +1 -0
- package/build/cli/cli/util/fastly-options.js +52 -0
- package/build/cli/cli/util/global-options.js +1 -1
- package/build/cli/cli/util/package.d.ts +2 -1
- package/build/cli/cli/util/package.d.ts.map +1 -1
- package/build/cli/cli/util/package.js +47 -9
- package/build/cli/cli/util/s3.d.ts +10 -4
- package/build/cli/cli/util/s3.d.ts.map +1 -1
- package/build/cli/cli/util/s3.js +13 -35
- package/build/cli/models/config/collection-selection.d.ts +2 -0
- package/build/cli/models/config/collection-selection.d.ts.map +1 -1
- package/build/cli/models/config/collection-selection.js +48 -8
- package/build/cli/models/config/publish-content-config.d.ts +1 -0
- package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
- package/build/cli/models/config/s3-storage-config.d.ts +1 -0
- package/build/cli/models/config/s3-storage-config.d.ts.map +1 -1
- package/build/cli/models/config/s3-storage-config.js +1 -0
- package/build/cli/models/config/static-publish-rc.d.ts +1 -0
- package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-rc.js +3 -1
- package/build/cli/models/server/index.d.ts +2 -0
- package/build/cli/models/server/index.d.ts.map +1 -1
- package/build/cli/models/server/index.js +13 -1
- package/build/server/hono/extensions.d.ts.map +1 -1
- package/build/server/hono/extensions.js +12 -7
- package/build/server/models/config/collection-selection.d.ts +2 -0
- package/build/server/models/config/collection-selection.d.ts.map +1 -1
- package/build/server/models/config/collection-selection.js +48 -8
- package/build/server/models/config/publish-content-config.d.ts +1 -0
- package/build/server/models/config/publish-content-config.d.ts.map +1 -1
- package/build/server/models/config/s3-storage-config.d.ts +1 -0
- package/build/server/models/config/s3-storage-config.d.ts.map +1 -1
- package/build/server/models/config/s3-storage-config.js +1 -0
- package/build/server/models/config/static-publish-rc.d.ts +1 -0
- package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/server/models/config/static-publish-rc.js +3 -1
- package/build/server/models/server/index.d.ts +2 -0
- package/build/server/models/server/index.d.ts.map +1 -1
- package/build/server/models/server/index.js +13 -1
- package/build/server/server/collection-selection/index.d.ts.map +1 -1
- package/build/server/server/collection-selection/index.js +16 -6
- package/build/server/server/storage/s3-storage-provider.d.ts +2 -1
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.js +15 -7
- package/package.json +2 -1
- package/resources/app/fastly.toml.njk +8 -8
- package/resources/app/publish-content.config.js.njk +1 -0
- package/resources/app/static-publish.project.js.njk +6 -0
- package/resources/app/static-publish.rc.js.njk +6 -0
- package/resources/template-init/hono/gitignore +1 -0
- package/resources/templates/hono/src/index.ts +0 -1
- package/resources/templates/plain/src/index.js +12 -2
|
@@ -290,7 +290,7 @@ export async function action(actionArgs) {
|
|
|
290
290
|
console.warn(`⚠️ Cannot parse hiddenItems item index ${i}: '${x}', skipping...`);
|
|
291
291
|
});
|
|
292
292
|
if (hiddenItems.length > 0) {
|
|
293
|
-
console.log(`✔️ Hidden items: ${publishContentConfig.
|
|
293
|
+
console.log(`✔️ Hidden items: ${publishContentConfig.hiddenItemsAsWritten.join(', ')}`);
|
|
294
294
|
}
|
|
295
295
|
// ### Collection name that we're currently publishing
|
|
296
296
|
// for example, live, staging
|
|
@@ -499,11 +499,13 @@ export async function action(actionArgs) {
|
|
|
499
499
|
}
|
|
500
500
|
console.log(`✅ Scan complete.`);
|
|
501
501
|
console.log(` | ${Object.keys(assetsIndex).length} file(s) in the index, ${hiddenCount} of them hidden.`);
|
|
502
|
+
// Counted before applyBatch(), which can split the entries into chunks.
|
|
503
|
+
const uploadedVariantCount = batch.storageProviderBatchEntries.length;
|
|
502
504
|
if (existingKeys != null) {
|
|
503
|
-
console.log(` | ${existingVariantCount} variant(s) already in storage, ${
|
|
505
|
+
console.log(` | ${existingVariantCount} variant(s) already in storage, ${uploadedVariantCount} to upload.`);
|
|
504
506
|
}
|
|
505
507
|
else {
|
|
506
|
-
console.log(` | ${
|
|
508
|
+
console.log(` | ${uploadedVariantCount} variant(s) to upload.`);
|
|
507
509
|
}
|
|
508
510
|
await storageProvider.applyBatch(batch, { existingKeys, verbose });
|
|
509
511
|
// #### INDEX FILE
|
|
@@ -514,6 +516,9 @@ export async function action(actionArgs) {
|
|
|
514
516
|
expirationTime: expirationTime ?? undefined,
|
|
515
517
|
// A server that does not support hidden files must not serve this collection.
|
|
516
518
|
requires: hiddenCount > 0 ? [HIDDEN_INDEX_FEATURE] : undefined,
|
|
519
|
+
// For collections list, which then reads only the metadata.
|
|
520
|
+
fileCount: Object.keys(assetsIndex).length,
|
|
521
|
+
hiddenFileCount: hiddenCount,
|
|
517
522
|
};
|
|
518
523
|
const indexFileName = `index_${collectionName}.json`;
|
|
519
524
|
const indexFilePath = path.resolve(storageContentDir, indexFileName);
|
|
@@ -603,7 +608,7 @@ export async function action(actionArgs) {
|
|
|
603
608
|
},
|
|
604
609
|
// Each file, and each compressed variant that is kept.
|
|
605
610
|
storageItems: {
|
|
606
|
-
uploaded:
|
|
611
|
+
uploaded: uploadedVariantCount,
|
|
607
612
|
reused: existingVariantCount,
|
|
608
613
|
},
|
|
609
614
|
expiresAt: expirationTime != null ? new Date(expirationTime * 1000).toISOString() : null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/status.ts"],"names":[],"mappings":"AAgDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/status.ts"],"names":[],"mappings":"AAgDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAsIhD"}
|
|
@@ -115,6 +115,12 @@ export async function action(actionArgs) {
|
|
|
115
115
|
reasons.push(deployed.staticPublishVersion !== running ?
|
|
116
116
|
`The version of this package changed: ${deployed.staticPublishVersion} → ${running}.` :
|
|
117
117
|
'The generated app changed.');
|
|
118
|
+
if (versionCheck.result === 'newer-cli' || versionCheck.result === 'missing') {
|
|
119
|
+
reasons.push(`Run 'upgrade' first, or deploy with --auto-upgrade: managed.staticPublishVersion (${versionCheck.recorded ?? 'missing'}) is not the version that runs (${running}).`);
|
|
120
|
+
}
|
|
121
|
+
else if (versionCheck.result !== 'same') {
|
|
122
|
+
reasons.push(`deploy refuses: this project uses a newer version (${versionCheck.recorded}) than the version that runs (${running}).`);
|
|
123
|
+
}
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
126
|
}
|
|
@@ -27,14 +27,14 @@ Description:
|
|
|
27
27
|
The template is managed.template in ${PROJECT_FILE_NAME}, or
|
|
28
28
|
generatedFrom.template in ${RC_FILE_NAME}.
|
|
29
29
|
|
|
30
|
-
A new folder gets package.json, tsconfig.json, and inactive
|
|
31
|
-
folder that exists, it updates only the peer dependencies on
|
|
32
|
-
that the app provides, and adds the starter files that are
|
|
33
|
-
changes your modules. Then run npm install in the folder.
|
|
30
|
+
A new folder gets package.json, tsconfig.json, .gitignore, and an inactive
|
|
31
|
+
example. In a folder that exists, it updates only the peer dependencies on
|
|
32
|
+
the packages that the app provides, and adds the starter files that are
|
|
33
|
+
missing. It never changes your modules. Then run npm install in the folder.
|
|
34
34
|
|
|
35
35
|
Options:
|
|
36
|
-
--reset Also write the starter files again (tsconfig.json
|
|
37
|
-
and the
|
|
36
|
+
--reset Also write the starter files again (tsconfig.json,
|
|
37
|
+
.gitignore, and the example). Asks before it replaces a file,
|
|
38
38
|
or needs --force in non-interactive mode.
|
|
39
39
|
--force With --reset: replace without a question.
|
|
40
40
|
--check Change nothing. Fail (template-init-needed) if
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-dev-watch.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/run-dev-watch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-dev-watch.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/run-dev-watch.ts"],"names":[],"mappings":"AAaA,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGvD;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;IAC9B,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAOF,wBAAsB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CA8CxF;AAKD,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAQjE"}
|
|
@@ -6,26 +6,62 @@ import * as child_process from 'node:child_process';
|
|
|
6
6
|
import * as fs from 'node:fs';
|
|
7
7
|
import * as path from 'node:path';
|
|
8
8
|
import { TEMPLATE_WATCH_SCRIPT } from './scaffold/generate-app.js';
|
|
9
|
+
// The Fastly CLI of the app (its node_modules/.bin/fastly) if it has one, or
|
|
10
|
+
// else fastly from the PATH.
|
|
11
|
+
export function appFastlyCommand(appDir) {
|
|
12
|
+
const appFastly = path.resolve(appDir, 'node_modules/.bin/fastly');
|
|
13
|
+
return fs.existsSync(appFastly) ? appFastly : 'fastly';
|
|
14
|
+
}
|
|
9
15
|
// Runs `fastly compute serve` in the app dir. With --watch, the watch script
|
|
10
16
|
// (if the app has one) runs next to it, until the Fastly CLI stops. The script
|
|
11
17
|
// can watch files outside the app dir: when they change, it writes a file in
|
|
12
18
|
// the app dir, and then the Fastly CLI builds the app again. The Fastly CLI of
|
|
13
19
|
// the app is used, if it has one.
|
|
14
20
|
export async function serveApp(appDir, serveArgs) {
|
|
15
|
-
const
|
|
16
|
-
const fastly = fs.existsSync(appFastly) ? appFastly : 'fastly';
|
|
21
|
+
const fastly = appFastlyCommand(appDir);
|
|
17
22
|
const watchScript = path.resolve(appDir, TEMPLATE_WATCH_SCRIPT);
|
|
18
23
|
const watcher = serveArgs.includes('--watch') && fs.existsSync(watchScript) ?
|
|
19
24
|
child_process.spawn(process.execPath, [watchScript], { cwd: appDir, stdio: 'inherit' }) :
|
|
20
25
|
undefined;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const child = child_process.spawn(fastly, ['compute', 'serve', ...serveArgs], { cwd: appDir, stdio: 'inherit' });
|
|
24
|
-
child.on('error', error => resolve({ status: null, signal: null, error }));
|
|
25
|
-
child.on('exit', (status, signal) => resolve({ status, signal }));
|
|
26
|
+
watcher?.on('error', error => {
|
|
27
|
+
console.error(`❌ Could not run ${TEMPLATE_WATCH_SCRIPT}: ${String(error)}`);
|
|
26
28
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
console.log(`▶️ fastly compute serve ${serveArgs.join(' ')}`);
|
|
30
|
+
// The Fastly CLI of the app is a Node.js wrapper that starts the fastly
|
|
31
|
+
// binary, which starts Viceroy. The wrapper does not forward signals. Thus
|
|
32
|
+
// the Fastly CLI runs in its own process group, and a signal goes to the
|
|
33
|
+
// whole group.
|
|
34
|
+
const child = child_process.spawn(fastly, ['compute', 'serve', ...serveArgs], { cwd: appDir, stdio: 'inherit', detached: true });
|
|
35
|
+
// A signal to this process (for example SIGTERM from a process manager, or
|
|
36
|
+
// SIGINT from Ctrl+C) goes to the Fastly CLI and to the watch script, so that
|
|
37
|
+
// nothing stays running. This process waits until the Fastly CLI stops.
|
|
38
|
+
const forward = (signal) => {
|
|
39
|
+
if (child.pid != null) {
|
|
40
|
+
try {
|
|
41
|
+
process.kill(-child.pid, signal);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// The process group has already stopped.
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
watcher?.kill(signal);
|
|
48
|
+
};
|
|
49
|
+
const signals = ['SIGINT', 'SIGTERM', 'SIGHUP'];
|
|
50
|
+
for (const signal of signals) {
|
|
51
|
+
process.on(signal, forward);
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
return await new Promise(resolve => {
|
|
55
|
+
child.on('error', error => resolve({ status: null, signal: null, error }));
|
|
56
|
+
child.on('exit', (status, signal) => resolve({ status, signal }));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
for (const signal of signals) {
|
|
61
|
+
process.off(signal, forward);
|
|
62
|
+
}
|
|
63
|
+
watcher?.kill();
|
|
64
|
+
}
|
|
29
65
|
}
|
|
30
66
|
// The dev:watch script of every app calls this: `fastly compute serve --watch`
|
|
31
67
|
// in the current directory, with the watch script of the app. The arguments
|
|
@@ -4,9 +4,9 @@ import { type GeneratedFrom, type StaticPublishTemplateOptions } from '../../../
|
|
|
4
4
|
import { type AppTemplate } from './app-template.js';
|
|
5
5
|
export type AppConfig = {
|
|
6
6
|
appDir: string;
|
|
7
|
-
name: string
|
|
8
|
-
author: string
|
|
9
|
-
description: string
|
|
7
|
+
name: string;
|
|
8
|
+
author: string;
|
|
9
|
+
description: string;
|
|
10
10
|
serviceId: string | undefined;
|
|
11
11
|
storage: {
|
|
12
12
|
mode: 'kv-store';
|
|
@@ -17,6 +17,8 @@ export type AppConfig = {
|
|
|
17
17
|
bucket: string;
|
|
18
18
|
endpointUrl: string;
|
|
19
19
|
endpointGenerated: boolean;
|
|
20
|
+
fastlyBackendName?: string;
|
|
21
|
+
secretStoreLinkName?: string;
|
|
20
22
|
};
|
|
21
23
|
publishId: string;
|
|
22
24
|
defaultCollectionName: string;
|
|
@@ -43,5 +45,10 @@ export type AppConfig = {
|
|
|
43
45
|
};
|
|
44
46
|
export declare const TEMPLATE_HOOKS: readonly ['prebuild', 'postbuild', 'postinstall'];
|
|
45
47
|
export declare const TEMPLATE_WATCH_SCRIPT = "scripts/template_watch.js";
|
|
48
|
+
export declare const DEFAULT_APP_INFO: {
|
|
49
|
+
name: string;
|
|
50
|
+
author: string;
|
|
51
|
+
description: string;
|
|
52
|
+
};
|
|
46
53
|
export declare function generateApp(config: AppConfig): Record<string, string>;
|
|
47
54
|
//# sourceMappingURL=generate-app.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-app.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/generate-app.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAC1F,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAGpH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMrD,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"generate-app.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/generate-app.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAC1F,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAGpH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMrD,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EACH;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GACzC;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,iBAAiB,EAAE,OAAO,CAAC;QAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAAC,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9J,SAAS,EAAE,MAAM,CAAC;IAClB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,yBAAyB,EAAE,MAAM,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,wBAAwB,EAAE,MAAM,CAAC;IAEjC,QAAQ,EAAE,WAAW,CAAC;IAEtB,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAEzC,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAE1C,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAGhC,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE;YAAE,aAAa,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAG7C,eAAe,CAAC,EAAE,4BAA4B,CAAC;IAE/C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAIF,eAAO,MAAM,cAAc,YAAK,UAAU,EAAE,WAAW,EAAE,aAAa,CAAW,CAAC;AAKlF,eAAO,MAAM,qBAAqB,8BAA8B,CAAC;AAIjE,eAAO,MAAM,gBAAgB;IAC3B,IAAI;IACJ,MAAM;IACN,WAAW;CACZ,CAAC;AAKF,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA+LrE"}
|
|
@@ -14,6 +14,13 @@ export const TEMPLATE_HOOKS = ['prebuild', 'postbuild', 'postinstall'];
|
|
|
14
14
|
// `fastly compute serve --watch` (npm run dev:watch, or dev -- --watch), until
|
|
15
15
|
// it is stopped.
|
|
16
16
|
export const TEMPLATE_WATCH_SCRIPT = 'scripts/template_watch.js';
|
|
17
|
+
// The name, author, and description of an app when the flags or the project
|
|
18
|
+
// file do not give them.
|
|
19
|
+
export const DEFAULT_APP_INFO = {
|
|
20
|
+
name: 'compute-js-static-site',
|
|
21
|
+
author: 'you@example.com',
|
|
22
|
+
description: 'Fastly Compute static site',
|
|
23
|
+
};
|
|
17
24
|
// Makes the files of the app, keyed by the path relative to the app dir.
|
|
18
25
|
// It does not write files or use the network, so that tests can compare its
|
|
19
26
|
// output. It reads only the resources/ directory of this package.
|
|
@@ -54,10 +61,13 @@ export function generateApp(config) {
|
|
|
54
61
|
type: 'module',
|
|
55
62
|
devDependencies: {
|
|
56
63
|
...template.devDependencies,
|
|
57
|
-
'@fastly/compute-js-static-publish': staticPublishVersionSpec,
|
|
58
64
|
},
|
|
65
|
+
// This package is a dependency, not a dev dependency: the code of the app
|
|
66
|
+
// imports it, and the postinstall script runs it, also with
|
|
67
|
+
// npm ci --omit=dev.
|
|
59
68
|
dependencies: {
|
|
60
69
|
...template.dependencies,
|
|
70
|
+
'@fastly/compute-js-static-publish': staticPublishVersionSpec,
|
|
61
71
|
},
|
|
62
72
|
engines: {
|
|
63
73
|
node: '>=20.11.0',
|
|
@@ -72,6 +82,8 @@ export function generateApp(config) {
|
|
|
72
82
|
let localServerKvStorePath;
|
|
73
83
|
let s3EndpointUrl;
|
|
74
84
|
let s3EndpointHostname;
|
|
85
|
+
let s3BackendName;
|
|
86
|
+
let s3SecretStoreLinkName;
|
|
75
87
|
if (storage.mode === 'kv-store') {
|
|
76
88
|
localServerKvStorePath = dotRelative(computeJsDir, path.resolve(staticPublisherWorkingDir, 'kvstore.json'));
|
|
77
89
|
// kvstore.json
|
|
@@ -81,6 +93,8 @@ export function generateApp(config) {
|
|
|
81
93
|
const url = new URL(storage.endpointUrl);
|
|
82
94
|
s3EndpointUrl = String(url);
|
|
83
95
|
s3EndpointHostname = url.hostname;
|
|
96
|
+
s3BackendName = storage.fastlyBackendName ?? 's3_storage';
|
|
97
|
+
s3SecretStoreLinkName = storage.secretStoreLinkName ?? 'S3_CREDENTIALS';
|
|
84
98
|
}
|
|
85
99
|
resourceFiles['fastly.toml'] = addFastlyTomlSections(renderAppResource('fastly.toml', {
|
|
86
100
|
author,
|
|
@@ -91,6 +105,8 @@ export function generateApp(config) {
|
|
|
91
105
|
localServerKvStorePath,
|
|
92
106
|
s3EndpointUrl,
|
|
93
107
|
s3EndpointHostname,
|
|
108
|
+
s3BackendName,
|
|
109
|
+
s3SecretStoreLinkName,
|
|
94
110
|
}), fastlyToml);
|
|
95
111
|
// static-publish.rc.js
|
|
96
112
|
resourceFiles['static-publish.rc.js'] = renderAppResource('static-publish.rc.js', {
|
|
@@ -8,9 +8,9 @@ export type InitAppOptions = {
|
|
|
8
8
|
notFoundPage: string | undefined;
|
|
9
9
|
autoIndex: string[];
|
|
10
10
|
autoExt: string[];
|
|
11
|
-
name: string
|
|
12
|
-
author: string
|
|
13
|
-
description: string
|
|
11
|
+
name: string;
|
|
12
|
+
author: string;
|
|
13
|
+
description: string;
|
|
14
14
|
serviceId: string | undefined;
|
|
15
15
|
publishId: string | undefined;
|
|
16
16
|
defaultCollectionName: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAoGA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAoGA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA2UF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA4iBhD;AASD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAehH"}
|
|
@@ -18,7 +18,7 @@ import { templateHasInit } from '../../managed/template-init.js';
|
|
|
18
18
|
import { findHostnameForAwsS3RegionAndBucket } from '../../util/s3.js';
|
|
19
19
|
import { APP_TEMPLATE_NAMES, DEFAULT_APP_TEMPLATE_NAME, isAppTemplateName, loadAppTemplate, } from './app-template.js';
|
|
20
20
|
import { COLLECTION_SELECTION_FLAGS_HELP, collectionSelectionFromFlags } from '../../util/collection-selection-flags.js';
|
|
21
|
-
import { generateApp } from './generate-app.js';
|
|
21
|
+
import { DEFAULT_APP_INFO, generateApp } from './generate-app.js';
|
|
22
22
|
import { renderProjectFile } from '../../managed/project-file.js';
|
|
23
23
|
import { dotRelative } from '../../util/files.js';
|
|
24
24
|
import { checkStaticPublisherWorkingDir } from '../../../models/config/static-publish-rc.js';
|
|
@@ -96,9 +96,9 @@ const defaultOptions = {
|
|
|
96
96
|
notFoundPage: undefined,
|
|
97
97
|
autoIndex: ['index.html', 'index.htm'],
|
|
98
98
|
autoExt: ['.html', '.htm'],
|
|
99
|
-
author:
|
|
100
|
-
name:
|
|
101
|
-
description:
|
|
99
|
+
author: DEFAULT_APP_INFO.author,
|
|
100
|
+
name: DEFAULT_APP_INFO.name,
|
|
101
|
+
description: DEFAULT_APP_INFO.description,
|
|
102
102
|
serviceId: undefined,
|
|
103
103
|
publishId: undefined,
|
|
104
104
|
defaultCollectionName: undefined,
|
|
@@ -115,13 +115,14 @@ function buildOptions(packageJson, commandLineOptions) {
|
|
|
115
115
|
// 2. package.json
|
|
116
116
|
// 3. command-line args
|
|
117
117
|
const options = structuredClone(defaultOptions);
|
|
118
|
-
|
|
118
|
+
// Only string values: in a package.json, author can also be an object.
|
|
119
|
+
if (typeof packageJson?.name === 'string') {
|
|
119
120
|
options.name = packageJson.name;
|
|
120
121
|
}
|
|
121
|
-
if (packageJson?.author
|
|
122
|
+
if (typeof packageJson?.author === 'string') {
|
|
122
123
|
options.author = packageJson.author;
|
|
123
124
|
}
|
|
124
|
-
if (packageJson?.description
|
|
125
|
+
if (typeof packageJson?.description === 'string') {
|
|
125
126
|
options.description = packageJson.description;
|
|
126
127
|
}
|
|
127
128
|
{
|
|
@@ -655,18 +656,15 @@ export async function action(actionArgs) {
|
|
|
655
656
|
}
|
|
656
657
|
let s3Endpoint = options.s3Endpoint;
|
|
657
658
|
if (s3Endpoint == null || s3Endpoint === '') {
|
|
658
|
-
//
|
|
659
|
-
//
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
if (s3Endpoint) {
|
|
664
|
-
console.log('✅ S3 endpoint resolved:', s3Endpoint);
|
|
665
|
-
}
|
|
666
|
-
else {
|
|
667
|
-
fail('failed', `Unable to resolve S3 endpoint from region '${s3Region}' and bucket '${s3Bucket}'.`);
|
|
659
|
+
// Without an endpoint, the bucket is on AWS. The app needs its host name
|
|
660
|
+
// for the backend in the Compute service.
|
|
661
|
+
const hostname = findHostnameForAwsS3RegionAndBucket(s3Region, s3Bucket);
|
|
662
|
+
if (hostname == null) {
|
|
663
|
+
fail('usage', `The bucket name '${s3Bucket}' has a dot, so it cannot be a host name of AWS S3 under HTTPS. Set --s3-endpoint, for example --s3-endpoint=https://s3.${s3Region}.amazonaws.com. Then the bucket is in the path of the URL.`);
|
|
668
664
|
return;
|
|
669
665
|
}
|
|
666
|
+
s3Endpoint = hostname;
|
|
667
|
+
console.log('✅ S3 endpoint resolved:', s3Endpoint);
|
|
670
668
|
s3EndpointUrl = new URL(`https://${s3Endpoint}/`);
|
|
671
669
|
s3EndpointGenerated = true;
|
|
672
670
|
}
|
|
@@ -776,7 +774,6 @@ export async function action(actionArgs) {
|
|
|
776
774
|
}
|
|
777
775
|
console.log("Initializing Compute Application in " + computeJsDir + "...");
|
|
778
776
|
fs.mkdirSync(computeJsDir);
|
|
779
|
-
fs.mkdirSync(path.resolve(computeJsDir, './src'));
|
|
780
777
|
const resourceFiles = generateApp(appConfig);
|
|
781
778
|
// Write out the files
|
|
782
779
|
for (const [filename, content] of Object.entries(resourceFiles)) {
|
|
@@ -842,6 +839,7 @@ To build and deploy to your Compute service:
|
|
|
842
839
|
|
|
843
840
|
The application reads the S3 credentials from the Secret Store that has the resource
|
|
844
841
|
link name 'S3_CREDENTIALS' on the service. The Secret Store can have a different name.
|
|
842
|
+
To use another resource link name, set s3.secretStoreLinkName in static-publish.rc.js.
|
|
845
843
|
|
|
846
844
|
To deploy to an existing service, do these steps first:
|
|
847
845
|
1. Create a Secret Store with the values 'S3_ACCESS_KEY_ID' and 'S3_SECRET_ACCESS_KEY'.
|
|
@@ -860,8 +858,8 @@ To build and deploy to your Compute service:
|
|
|
860
858
|
|
|
861
859
|
If a Secret Store named 'S3_CREDENTIALS' already exists, the Fastly CLI asks for a
|
|
862
860
|
different name. If you leave it empty, it uses the existing Secret Store. If you give
|
|
863
|
-
a different name, the Fastly CLI uses it for the resource link too. Then
|
|
864
|
-
|
|
861
|
+
a different name, the Fastly CLI uses it for the resource link too. Then set
|
|
862
|
+
s3.secretStoreLinkName in static-publish.rc.js to that name, and deploy again.
|
|
865
863
|
|
|
866
864
|
After the deploy, fastly.toml has the service ID, so s3:publish also purges the
|
|
867
865
|
service's cache. For this purge, s3:publish needs FASTLY_API_TOKEN too.
|
|
@@ -871,9 +869,12 @@ To build and deploy to your Compute service:
|
|
|
871
869
|
}
|
|
872
870
|
// The lines that scaffold --managed adds to the .gitignore of the project dir.
|
|
873
871
|
const GITIGNORE_COMMENT = '# @fastly/compute-js-static-publish';
|
|
872
|
+
// A line is present also without its leading or trailing '/': for example,
|
|
873
|
+
// 'node_modules' in the file also ignores the directory of '/node_modules/'.
|
|
874
|
+
const gitignoreKey = (line) => line.trim().replace(/^\//, '').replace(/\/$/, '');
|
|
874
875
|
export function addGitignoreLines(existing, lines) {
|
|
875
|
-
const present = new Set((existing ?? '').split(/\r?\n/).map(
|
|
876
|
-
const added = lines.filter(line => !present.has(line));
|
|
876
|
+
const present = new Set((existing ?? '').split(/\r?\n/).map(gitignoreKey));
|
|
877
|
+
const added = lines.filter(line => !present.has(gitignoreKey(line)));
|
|
877
878
|
if (added.length === 0) {
|
|
878
879
|
return { content: existing ?? '', added };
|
|
879
880
|
}
|
|
@@ -891,11 +892,13 @@ function writeManagedProject(appConfig, projectDir) {
|
|
|
891
892
|
const projectFilePath = path.resolve(projectDir, PROJECT_FILE_NAME);
|
|
892
893
|
fs.writeFileSync(projectFilePath, renderProjectFile(appConfig, projectDir, getOwnVersion()), 'utf-8');
|
|
893
894
|
console.log(`🚀 Managed project created: ${rootRelative(projectFilePath)}`);
|
|
894
|
-
// Ignore the
|
|
895
|
+
// Ignore the node_modules of the project (this package can be a dev
|
|
896
|
+
// dependency of the project), the generated app, and the working dir. Never
|
|
897
|
+
// change the customer's lines.
|
|
895
898
|
const gitignorePath = path.resolve(projectDir, '.gitignore');
|
|
896
899
|
const existing = fs.existsSync(gitignorePath) ? fs.readFileSync(gitignorePath, 'utf-8') : null;
|
|
897
900
|
const workingDir = path.relative(projectDir, appConfig.staticPublisherWorkingDir).split(path.sep).join('/');
|
|
898
|
-
const lines = ['/.static-publish/'];
|
|
901
|
+
const lines = ['/node_modules/', '/.static-publish/'];
|
|
899
902
|
if (!workingDir.startsWith('..')) {
|
|
900
903
|
lines.push(`/${workingDir}/`);
|
|
901
904
|
}
|
|
@@ -11,7 +11,7 @@ export declare function managedAppState(projectDir: string, project: StaticPubli
|
|
|
11
11
|
files: Record<string, string>;
|
|
12
12
|
fingerprint: string;
|
|
13
13
|
}>;
|
|
14
|
-
export declare function prepareManagedApp(projectDir: string, project: StaticPublishProjectNormalized): Promise<{
|
|
14
|
+
export declare function prepareManagedApp(projectDir: string, project: StaticPublishProjectNormalized, state?: Awaited<ReturnType<typeof managedAppState>>): Promise<{
|
|
15
15
|
appDir: string;
|
|
16
16
|
appConfig: AppConfig;
|
|
17
17
|
files: Record<string, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/app.ts"],"names":[],"mappings":"AAUA,OAAO,EAAiC,KAAK,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AAGvG,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,sCAAsC,CAAC;AAYnF,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,8BAA8B,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CA+B/I;AAKD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,EAAE,CAe5F;AAcD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGpD;AAID,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAezD;AAMD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmB7F;AAED,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,8BAA8B;;;;;GAqBhG;
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/app.ts"],"names":[],"mappings":"AAUA,OAAO,EAAiC,KAAK,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AAGvG,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,sCAAsC,CAAC;AAYnF,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,8BAA8B,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CA+B/I;AAKD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,EAAE,CAe5F;AAcD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGpD;AAID,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAezD;AAMD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmB7F;AAED,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,8BAA8B;;;;;GAqBhG;AAMD,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,8BAA8B,EACvC,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;;;;;;GAUpD"}
|
|
@@ -149,9 +149,11 @@ export async function managedAppState(projectDir, project) {
|
|
|
149
149
|
return { appDir: appConfig.appDir, appConfig, files, fingerprint };
|
|
150
150
|
}
|
|
151
151
|
// Generate the app of a managed project in .static-publish/app, and install
|
|
152
|
-
// its dependencies if necessary.
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
// its dependencies if necessary. A command that already has the result of
|
|
153
|
+
// managedAppState() passes it, so that it is not computed again (in S3 mode
|
|
154
|
+
// without s3.endpoint, that is a network lookup).
|
|
155
|
+
export async function prepareManagedApp(projectDir, project, state) {
|
|
156
|
+
const { appConfig, files, fingerprint } = state ?? await managedAppState(projectDir, project);
|
|
155
157
|
console.log(`🛠️ Generating the app in ${MANAGED_APP_DIR}...`);
|
|
156
158
|
const written = writeManagedAppFiles(appConfig.appDir, files);
|
|
157
159
|
if (written.length > 0) {
|
|
@@ -43,7 +43,7 @@ export function buildManagedLockfile(templateLock, options) {
|
|
|
43
43
|
root.name = options.appName;
|
|
44
44
|
}
|
|
45
45
|
root.version = options.appVersion;
|
|
46
|
-
root.
|
|
46
|
+
root.dependencies = { ...root.dependencies, [THIS_PACKAGE]: spec };
|
|
47
47
|
lock.packages[''] = root;
|
|
48
48
|
lock.packages[`node_modules/${THIS_PACKAGE}`] = {
|
|
49
49
|
resolved: linkPath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-file.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/project-file.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,8BAA8B,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EAAE,KAAK,eAAe,EAA0D,MAAM,0CAA0C,CAAC;AAGxI,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"project-file.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/project-file.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,8BAA8B,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EAAE,KAAK,eAAe,EAA0D,MAAM,0CAA0C,CAAC;AAGxI,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,sCAAsC,CAAC;AAMxF,eAAO,MAAM,2BAA2B,8BAA8B,CAAC;AAKvE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAyC7G;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB,EAAE,MAAM,CAAC;IACjC,QAAQ,EAAE,WAAW,CAAC;IAGtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAIF,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,8BAA8B,EAC9C,OAAO,EAAE,2BAA2B,EACpC,OAAO,EAAE,2BAA2B,GACnC,SAAS,CAqEX"}
|
|
@@ -6,6 +6,7 @@ import * as path from 'node:path';
|
|
|
6
6
|
import { isS3StorageConfigRc } from '../../models/config/static-publish-rc.js';
|
|
7
7
|
import { DEFAULT_HONO_EXTENSIONS_DIR } from '../hono/build.js';
|
|
8
8
|
import { getKvStoreConfigFromRc } from '../../models/config/kv-store-config.js';
|
|
9
|
+
import { DEFAULT_APP_INFO } from '../commands/scaffold/generate-app.js';
|
|
9
10
|
import { renderAppResource } from '../commands/scaffold/render.js';
|
|
10
11
|
import { dotRelative } from '../util/files.js';
|
|
11
12
|
// The line in the managed section that deploy replaces with the service ID
|
|
@@ -77,16 +78,24 @@ export function appConfigFromProject(rc, publishContent, managed, options) {
|
|
|
77
78
|
else {
|
|
78
79
|
throw new Error('The S3 endpoint of the project is not resolved.');
|
|
79
80
|
}
|
|
80
|
-
storage = {
|
|
81
|
+
storage = {
|
|
82
|
+
mode: 's3',
|
|
83
|
+
region: rc.s3.region,
|
|
84
|
+
bucket: rc.s3.bucket,
|
|
85
|
+
endpointUrl,
|
|
86
|
+
endpointGenerated: rc.s3.endpoint == null,
|
|
87
|
+
...(rc.s3.fastlyBackendName != null ? { fastlyBackendName: rc.s3.fastlyBackendName } : {}),
|
|
88
|
+
...(rc.s3.secretStoreLinkName != null ? { secretStoreLinkName: rc.s3.secretStoreLinkName } : {}),
|
|
89
|
+
};
|
|
81
90
|
}
|
|
82
91
|
else {
|
|
83
92
|
storage = { mode: 'kv-store', kvStoreName: getKvStoreConfigFromRc(rc).kvStoreName };
|
|
84
93
|
}
|
|
85
94
|
return {
|
|
86
95
|
appDir,
|
|
87
|
-
name: managed.name,
|
|
88
|
-
author: managed.authors?.[0],
|
|
89
|
-
description: managed.description,
|
|
96
|
+
name: managed.name ?? DEFAULT_APP_INFO.name,
|
|
97
|
+
author: managed.authors?.[0] ?? DEFAULT_APP_INFO.author,
|
|
98
|
+
description: managed.description ?? DEFAULT_APP_INFO.description,
|
|
90
99
|
serviceId: managed.serviceId,
|
|
91
100
|
storage,
|
|
92
101
|
publishId: rc.publishId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-init.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/template-init.ts"],"names":[],"mappings":"AAoBA,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAE7D;
|
|
1
|
+
{"version":3,"file":"template-init.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/template-init.ts"],"names":[],"mappings":"AAoBA,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAE7D;AA0BD,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAexI;AAED,MAAM,MAAM,gBAAgB,GAAG;IAE7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAKF,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,gBAAgB,CAsDzJ;AAGD,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,QAM1E"}
|
|
@@ -17,6 +17,8 @@ export function templateHasInit(templateName) {
|
|
|
17
17
|
return fs.existsSync(path.resolve(resourcesDir, 'template-init', templateName));
|
|
18
18
|
}
|
|
19
19
|
// The starter files of a template, keyed by the path relative to its folder.
|
|
20
|
+
// The file 'gitignore' is written as '.gitignore', because npm leaves a file
|
|
21
|
+
// named .gitignore out of the published package.
|
|
20
22
|
function starterFiles(templateName) {
|
|
21
23
|
const dir = path.resolve(resourcesDir, 'template-init', templateName);
|
|
22
24
|
const files = {};
|
|
@@ -27,7 +29,7 @@ function starterFiles(templateName) {
|
|
|
27
29
|
walk(rel);
|
|
28
30
|
}
|
|
29
31
|
else {
|
|
30
|
-
files[rel] = fs.readFileSync(path.resolve(dir, rel), 'utf-8');
|
|
32
|
+
files[rel === 'gitignore' ? '.gitignore' : rel] = fs.readFileSync(path.resolve(dir, rel), 'utf-8');
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
};
|
|
@@ -5,7 +5,7 @@ export type CollectionSelectionFlags = {
|
|
|
5
5
|
onMissing?: string;
|
|
6
6
|
noindex?: string;
|
|
7
7
|
};
|
|
8
|
-
export declare const COLLECTION_SELECTION_FLAGS_HELP = " --collection-selection <source> Select the collection of a request, for example for\n previews. Can be repeated; the sources are tried in order.\n host:<pattern> host:{collection}.preview.example.com\n path:<prefix>[,sticky] path:/_preview/{collection},sticky\n query:<param>[,sticky] query:collection,sticky\n cookie[:<name>][,maxAge=<seconds>][,activatePath=<path>][,resetPath=<path>]\n header:<name> header:x-publisher-collection\n 'sticky' also sets the cookie of the cookie source, so it needs a cookie source.\n --collection-allow <patterns> The collections that can be selected, for example \"pr-*,staging\".\n Default: any collection.\n --collection-on-missing <value> When the selected collection is not published or has\n expired: 'not-found' (default: a 404 response) or\n 'default' (serve the default collection).\n --collection-noindex <true|false> Add 'X-Robots-Tag: noindex' to the responses of a collection\n that is not the default collection. Default: true.";
|
|
8
|
+
export declare const COLLECTION_SELECTION_FLAGS_HELP = " --collection-selection <source> Select the collection of a request, for example for\n previews. Can be repeated; the sources are tried in order.\n host:<pattern> host:{collection}.preview.example.com\n host:<host>,value=<name> host:stag.example.com,value=staging\n path:<prefix>[,sticky] path:/_preview/{collection},sticky\n path:<prefix>,value=<name> path:/_staging,value=staging,sticky\n query:<param>[,sticky] query:collection,sticky\n cookie[:<name>][,maxAge=<seconds>][,activatePath=<path>][,resetPath=<path>]\n header:<name> header:x-publisher-collection\n 'sticky' also sets the cookie of the cookie source, so it needs a cookie source.\n 'value' gives one collection for a hostname or a prefix without {collection}.\n --collection-allow <patterns> The collections that can be selected, for example \"pr-*,staging\".\n Default: any collection.\n --collection-on-missing <value> When the selected collection is not published or has\n expired: 'not-found' (default: a 404 response) or\n 'default' (serve the default collection).\n --collection-noindex <true|false> Add 'X-Robots-Tag: noindex' to the responses of a collection\n that is not the default collection. Default: true.";
|
|
9
9
|
export declare function collectionSelectionFromFlags(flags: CollectionSelectionFlags): {
|
|
10
10
|
collectionSelection: CollectionSelection | undefined;
|
|
11
11
|
errors: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection-selection-flags.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/collection-selection-flags.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,mBAAmB,EAIzB,MAAM,6CAA6C,CAAC;AAcrD,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,+BAA+B,
|
|
1
|
+
{"version":3,"file":"collection-selection-flags.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/collection-selection-flags.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,mBAAmB,EAIzB,MAAM,6CAA6C,CAAC;AAcrD,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,+BAA+B,oxDAkB+C,CAAC;AA+F5F,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,wBAAwB,GAAG;IAC7E,mBAAmB,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACrD,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAqCA"}
|
|
@@ -7,11 +7,14 @@ export const COLLECTION_SELECTION_FLAGS_HELP = `\
|
|
|
7
7
|
--collection-selection <source> Select the collection of a request, for example for
|
|
8
8
|
previews. Can be repeated; the sources are tried in order.
|
|
9
9
|
host:<pattern> host:{collection}.preview.example.com
|
|
10
|
+
host:<host>,value=<name> host:stag.example.com,value=staging
|
|
10
11
|
path:<prefix>[,sticky] path:/_preview/{collection},sticky
|
|
12
|
+
path:<prefix>,value=<name> path:/_staging,value=staging,sticky
|
|
11
13
|
query:<param>[,sticky] query:collection,sticky
|
|
12
14
|
cookie[:<name>][,maxAge=<seconds>][,activatePath=<path>][,resetPath=<path>]
|
|
13
15
|
header:<name> header:x-publisher-collection
|
|
14
16
|
'sticky' also sets the cookie of the cookie source, so it needs a cookie source.
|
|
17
|
+
'value' gives one collection for a hostname or a prefix without {collection}.
|
|
15
18
|
--collection-allow <patterns> The collections that can be selected, for example "pr-*,staging".
|
|
16
19
|
Default: any collection.
|
|
17
20
|
--collection-on-missing <value> When the selected collection is not published or has
|
|
@@ -31,6 +34,23 @@ function parseSource(spec, errors) {
|
|
|
31
34
|
}
|
|
32
35
|
return true;
|
|
33
36
|
};
|
|
37
|
+
// The options of a host or path source: value=<collection>, and sticky
|
|
38
|
+
// (only if allowSticky).
|
|
39
|
+
const valueAndSticky = (allowSticky) => {
|
|
40
|
+
const result = {};
|
|
41
|
+
for (const option of options) {
|
|
42
|
+
if (allowSticky && option === 'sticky') {
|
|
43
|
+
result.sticky = 'cookie';
|
|
44
|
+
}
|
|
45
|
+
else if (option.startsWith('value=')) {
|
|
46
|
+
result.value = option.slice('value='.length);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
errors.push(`--collection-selection ${type}: unknown option '${option}'.`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
34
54
|
const sticky = () => {
|
|
35
55
|
let result;
|
|
36
56
|
for (const option of options) {
|
|
@@ -49,12 +69,18 @@ function parseSource(spec, errors) {
|
|
|
49
69
|
}
|
|
50
70
|
};
|
|
51
71
|
switch (type) {
|
|
52
|
-
case 'host':
|
|
53
|
-
|
|
54
|
-
return needValue('pattern') ? { type, pattern: value } : null;
|
|
72
|
+
case 'host': {
|
|
73
|
+
const o = valueAndSticky(false);
|
|
74
|
+
return needValue('pattern') ? { type, pattern: value, ...(o.value != null ? { value: o.value } : {}) } : null;
|
|
75
|
+
}
|
|
55
76
|
case 'path': {
|
|
56
|
-
const
|
|
57
|
-
return needValue('prefix') ? {
|
|
77
|
+
const o = valueAndSticky(true);
|
|
78
|
+
return needValue('prefix') ? {
|
|
79
|
+
type,
|
|
80
|
+
prefix: value,
|
|
81
|
+
...(o.value != null ? { value: o.value } : {}),
|
|
82
|
+
...(o.sticky != null ? { sticky: o.sticky } : {}),
|
|
83
|
+
} : null;
|
|
58
84
|
}
|
|
59
85
|
case 'query': {
|
|
60
86
|
const s = sticky();
|