@fastly/compute-js-static-publish 8.0.1 → 8.1.0-beta.1
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/DOCUMENTATION.md +779 -22
- package/README.md +2 -2
- package/README.short.md +2 -2
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +12 -7
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +29 -13
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +6 -1
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +47 -7
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +67 -20
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +10 -11
- package/build/cli/cli/commands/manage/deploy.d.ts +2 -0
- package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/deploy.js +194 -0
- package/build/cli/cli/commands/manage/dev.d.ts +2 -0
- package/build/cli/cli/commands/manage/dev.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/dev.js +77 -0
- package/build/cli/cli/commands/manage/eject.d.ts +2 -0
- package/build/cli/cli/commands/manage/eject.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/eject.js +155 -0
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +37 -1
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +78 -33
- package/build/cli/cli/commands/manage/status.d.ts +2 -0
- package/build/cli/cli/commands/manage/status.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/status.js +162 -0
- package/build/cli/cli/commands/manage/template/index.d.ts +2 -0
- package/build/cli/cli/commands/manage/template/index.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/template/index.js +42 -0
- package/build/cli/cli/commands/manage/template/init.d.ts +13 -0
- package/build/cli/cli/commands/manage/template/init.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/template/init.js +172 -0
- package/build/cli/cli/commands/manage/upgrade.d.ts +2 -0
- package/build/cli/cli/commands/manage/upgrade.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/upgrade.js +59 -0
- package/build/cli/cli/commands/run-dev-watch.d.ts +8 -0
- package/build/cli/cli/commands/run-dev-watch.d.ts.map +1 -0
- package/build/cli/cli/commands/run-dev-watch.js +41 -0
- package/build/cli/cli/commands/run-template-hook.d.ts +2 -0
- package/build/cli/cli/commands/run-template-hook.d.ts.map +1 -0
- package/build/cli/cli/commands/run-template-hook.js +28 -0
- package/build/cli/cli/commands/scaffold/app-template.d.ts +17 -0
- package/build/cli/cli/commands/scaffold/app-template.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/app-template.js +54 -0
- package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts +5 -0
- package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/fastly-toml-sections.js +154 -0
- package/build/cli/cli/commands/scaffold/generate-app.d.ts +47 -0
- package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/generate-app.js +164 -0
- package/build/cli/cli/commands/scaffold/index.d.ts +6 -0
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +208 -290
- package/build/cli/cli/commands/scaffold/render.d.ts +7 -0
- package/build/cli/cli/commands/scaffold/render.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/render.js +72 -0
- package/build/cli/cli/hono/build.d.ts +43 -0
- package/build/cli/cli/hono/build.d.ts.map +1 -0
- package/build/cli/cli/hono/build.js +297 -0
- package/build/cli/cli/index.js +98 -5
- package/build/cli/cli/managed/app.d.ts +21 -0
- package/build/cli/cli/managed/app.d.ts.map +1 -0
- package/build/cli/cli/managed/app.js +162 -0
- package/build/cli/cli/managed/command-helpers.d.ts +6 -0
- package/build/cli/cli/managed/command-helpers.d.ts.map +1 -0
- package/build/cli/cli/managed/command-helpers.js +81 -0
- package/build/cli/cli/managed/eject.d.ts +6 -0
- package/build/cli/cli/managed/eject.d.ts.map +1 -0
- package/build/cli/cli/managed/eject.js +68 -0
- package/build/cli/cli/managed/fastly-service.d.ts +8 -0
- package/build/cli/cli/managed/fastly-service.d.ts.map +1 -0
- package/build/cli/cli/managed/fastly-service.js +21 -0
- package/build/cli/cli/managed/fingerprint.d.ts +13 -0
- package/build/cli/cli/managed/fingerprint.d.ts.map +1 -0
- package/build/cli/cli/managed/fingerprint.js +60 -0
- package/build/cli/cli/managed/lockfile.d.ts +31 -0
- package/build/cli/cli/managed/lockfile.d.ts.map +1 -0
- package/build/cli/cli/managed/lockfile.js +62 -0
- package/build/cli/cli/managed/project-edit.d.ts +3 -0
- package/build/cli/cli/managed/project-edit.d.ts.map +1 -0
- package/build/cli/cli/managed/project-edit.js +35 -0
- package/build/cli/cli/managed/project-file.d.ts +16 -0
- package/build/cli/cli/managed/project-file.d.ts.map +1 -0
- package/build/cli/cli/managed/project-file.js +119 -0
- package/build/cli/cli/managed/template-init.d.ts +12 -0
- package/build/cli/cli/managed/template-init.d.ts.map +1 -0
- package/build/cli/cli/managed/template-init.js +120 -0
- package/build/cli/cli/managed/version-check.d.ts +25 -0
- package/build/cli/cli/managed/version-check.d.ts.map +1 -0
- package/build/cli/cli/managed/version-check.js +84 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +1 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-local-provider.js +6 -3
- package/build/cli/cli/storage/kv-store-provider.d.ts +1 -0
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +9 -1
- package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +4 -0
- package/build/cli/cli/storage/storage-provider.d.ts +3 -0
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/storage-provider.js +32 -0
- package/build/cli/cli/util/api-token.d.ts.map +1 -1
- package/build/cli/cli/util/collection-name.d.ts +3 -0
- package/build/cli/cli/util/collection-name.d.ts.map +1 -0
- package/build/cli/cli/util/collection-name.js +24 -0
- package/build/cli/cli/util/collection-selection-flags.d.ts +13 -0
- package/build/cli/cli/util/collection-selection-flags.d.ts.map +1 -0
- package/build/cli/cli/util/collection-selection-flags.js +131 -0
- package/build/cli/cli/util/config.d.ts +13 -0
- package/build/cli/cli/util/config.d.ts.map +1 -1
- package/build/cli/cli/util/config.js +172 -38
- package/build/cli/cli/util/data.d.ts.map +1 -1
- package/build/cli/cli/util/global-options.d.ts +13 -0
- package/build/cli/cli/util/global-options.d.ts.map +1 -0
- package/build/cli/cli/util/global-options.js +53 -0
- package/build/cli/cli/util/kv-store-items.d.ts +1 -0
- package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-items.js +16 -40
- package/build/cli/cli/util/kv-store-local-server.d.ts +1 -1
- package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-local-server.js +4 -2
- package/build/cli/cli/util/output.d.ts +31 -0
- package/build/cli/cli/util/output.d.ts.map +1 -0
- package/build/cli/cli/util/output.js +139 -0
- package/build/cli/cli/util/package.d.ts +3 -0
- package/build/cli/cli/util/package.d.ts.map +1 -1
- package/build/cli/cli/util/package.js +12 -0
- package/build/cli/cli/util/progress.d.ts.map +1 -1
- package/build/cli/cli/util/purge.d.ts +6 -2
- package/build/cli/cli/util/purge.d.ts.map +1 -1
- package/build/cli/cli/util/purge.js +7 -2
- package/build/cli/cli/util/resources.d.ts +2 -0
- package/build/cli/cli/util/resources.d.ts.map +1 -0
- package/build/cli/cli/util/resources.js +8 -0
- package/build/cli/cli/util/service-id.d.ts +1 -0
- package/build/cli/cli/util/service-id.d.ts.map +1 -1
- package/build/cli/cli/util/service-id.js +5 -1
- package/build/cli/cli/util/variants.d.ts.map +1 -1
- package/build/cli/models/assets/index.d.ts +6 -0
- package/build/cli/models/assets/index.d.ts.map +1 -1
- package/build/cli/models/assets/index.js +24 -0
- package/build/cli/models/collections/index.d.ts +3 -0
- package/build/cli/models/collections/index.d.ts.map +1 -0
- package/build/cli/models/collections/index.js +15 -0
- package/build/cli/models/compression/index.d.ts +1 -1
- package/build/cli/models/compression/index.d.ts.map +1 -1
- package/build/cli/models/config/collection-selection.d.ts +55 -0
- package/build/cli/models/config/collection-selection.d.ts.map +1 -0
- package/build/cli/models/config/collection-selection.js +238 -0
- package/build/cli/models/config/item-patterns.d.ts +4 -0
- package/build/cli/models/config/item-patterns.d.ts.map +1 -0
- package/build/cli/models/config/item-patterns.js +43 -0
- package/build/cli/models/config/publish-content-config.d.ts +6 -1
- package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-project.d.ts +23 -0
- package/build/cli/models/config/static-publish-project.d.ts.map +1 -0
- package/build/cli/models/config/static-publish-project.js +11 -0
- package/build/cli/models/config/static-publish-rc.d.ts +25 -0
- package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-rc.js +31 -0
- package/build/cli/models/config/template-settings.d.ts +10 -0
- package/build/cli/models/config/template-settings.d.ts.map +1 -0
- package/build/cli/models/config/template-settings.js +72 -0
- package/build/cli/models/server/index.d.ts.map +1 -1
- package/build/cli/models/server/index.js +6 -2
- package/build/server/hono/extensions.d.ts +48 -0
- package/build/server/hono/extensions.d.ts.map +1 -0
- package/build/server/hono/extensions.js +65 -0
- package/build/server/hono/index.d.ts +30 -0
- package/build/server/hono/index.d.ts.map +1 -0
- package/build/server/hono/index.js +72 -0
- package/build/server/hono/path.d.ts +7 -0
- package/build/server/hono/path.d.ts.map +1 -0
- package/build/server/hono/path.js +32 -0
- package/build/server/models/assets/index.d.ts +6 -0
- package/build/server/models/assets/index.d.ts.map +1 -1
- package/build/server/models/assets/index.js +24 -0
- package/build/server/models/collections/index.d.ts +3 -0
- package/build/server/models/collections/index.d.ts.map +1 -0
- package/build/server/models/collections/index.js +15 -0
- package/build/server/models/compression/index.d.ts +1 -1
- package/build/server/models/compression/index.d.ts.map +1 -1
- package/build/server/models/config/collection-selection.d.ts +55 -0
- package/build/server/models/config/collection-selection.d.ts.map +1 -0
- package/build/server/models/config/collection-selection.js +238 -0
- package/build/server/models/config/item-patterns.d.ts +4 -0
- package/build/server/models/config/item-patterns.d.ts.map +1 -0
- package/build/server/models/config/item-patterns.js +43 -0
- package/build/server/models/config/publish-content-config.d.ts +6 -1
- package/build/server/models/config/publish-content-config.d.ts.map +1 -1
- package/build/server/models/config/static-publish-project.d.ts +23 -0
- package/build/server/models/config/static-publish-project.d.ts.map +1 -0
- package/build/server/models/config/static-publish-project.js +11 -0
- package/build/server/models/config/static-publish-rc.d.ts +25 -0
- package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/server/models/config/static-publish-rc.js +31 -0
- package/build/server/models/server/index.d.ts.map +1 -1
- package/build/server/models/server/index.js +6 -2
- package/build/server/server/collection-selection/index.d.ts +11 -0
- package/build/server/server/collection-selection/index.d.ts.map +1 -0
- package/build/server/server/collection-selection/index.js +192 -0
- package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -1
- package/build/server/server/collection-selector/from-cookie.js +6 -8
- package/build/server/server/collection-selector/from-request.d.ts.map +1 -1
- package/build/server/server/index.d.ts +4 -1
- package/build/server/server/index.d.ts.map +1 -1
- package/build/server/server/index.js +3 -1
- package/build/server/server/publisher-server/accept-html.d.ts +2 -0
- package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
- package/build/server/server/publisher-server/accept-html.js +50 -0
- package/build/server/server/publisher-server/index.d.ts +59 -7
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +362 -145
- package/build/server/server/publisher-server/response-cache.d.ts +3 -0
- package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
- package/build/server/server/publisher-server/response-cache.js +24 -1
- package/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/storage-provider.d.ts.map +1 -1
- package/build/server/server/util/body-length.d.ts.map +1 -1
- package/build/server/server/util/server-timing.d.ts.map +1 -1
- package/package.json +21 -3
- package/resources/app/fastly.toml.njk +58 -0
- package/resources/app/gitignore.njk +9 -0
- package/resources/app/publish-content.config.from-project.js.njk +9 -0
- package/resources/app/publish-content.config.js.njk +35 -0
- package/resources/app/static-publish.project.js.njk +83 -0
- package/resources/app/static-publish.rc.js.njk +43 -0
- package/resources/template-init/hono/_example.ts +22 -0
- package/resources/template-init/hono/tsconfig.json +17 -0
- package/resources/templates/hono/package-lock.json +4123 -0
- package/resources/templates/hono/package.json +15 -0
- package/resources/templates/hono/scripts/template_postinstall.js +10 -0
- package/resources/templates/hono/scripts/template_prebuild.js +8 -0
- package/resources/templates/hono/scripts/template_watch.js +15 -0
- package/resources/templates/hono/src/hono-extensions.generated.d.ts +5 -0
- package/resources/templates/hono/src/index.ts +53 -0
- package/resources/templates/hono/tsconfig.json +17 -0
- package/resources/templates/plain/package-lock.json +4088 -0
- package/resources/templates/plain/package.json +10 -0
- package/resources/templates/plain/src/index.js +34 -0
package/README.md
CHANGED
|
@@ -18,13 +18,13 @@ This CLI tool helps you:
|
|
|
18
18
|
Create a directory for your project, place your static files in `./public`, then type:
|
|
19
19
|
|
|
20
20
|
```sh
|
|
21
|
-
npx @fastly/compute-js-static-publish@
|
|
21
|
+
npx @fastly/compute-js-static-publish@beta --root-dir=./public --kv-store-name=site-content
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
**New in v8:** S3-compatible storage (such as Fastly Object Storage) is also supported (Beta). To use this mode, type:
|
|
25
25
|
|
|
26
26
|
```sh
|
|
27
|
-
npx @fastly/compute-js-static-publish@
|
|
27
|
+
npx @fastly/compute-js-static-publish@beta --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
If the storage needs a custom endpoint, as Fastly Object Storage does, add `--s3-endpoint=<endpoint>` (for example, `--s3-endpoint=https://us-east-1.object.fastlystorage.app`).
|
package/README.short.md
CHANGED
|
@@ -18,13 +18,13 @@ This CLI tool helps you:
|
|
|
18
18
|
Create a directory for your project, place your static files in `./public`, then type:
|
|
19
19
|
|
|
20
20
|
```sh
|
|
21
|
-
npx @fastly/compute-js-static-publish@
|
|
21
|
+
npx @fastly/compute-js-static-publish@beta --root-dir=./public --kv-store-name=site-content
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
**New in v8:** S3-compatible storage (such as Fastly Object Storage) is also supported (Beta). To use this mode, type:
|
|
25
25
|
|
|
26
26
|
```sh
|
|
27
|
-
npx @fastly/compute-js-static-publish@
|
|
27
|
+
npx @fastly/compute-js-static-publish@beta --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
If the storage needs a custom endpoint, as Fastly Object Storage does, add `--s3-endpoint=<endpoint>` (for example, `--s3-endpoint=https://us-east-1.object.fastlystorage.app`).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"AA+DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0NhD"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
import path from 'node:path';
|
|
6
5
|
import { decodeIndexMetadata } from '../../../models/server/index.js';
|
|
7
6
|
import { isExpired } from '../../../models/time/index.js';
|
|
8
7
|
import { parseCommandLine } from '../../util/args.js';
|
|
9
|
-
import {
|
|
8
|
+
import { errorCodeOf, recordFailure } from '../../util/output.js';
|
|
9
|
+
import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../util/config.js';
|
|
10
10
|
import { loadStorageProviderFromStaticPublishRc } from '../../storage/storage-provider.js';
|
|
11
11
|
function help() {
|
|
12
12
|
console.log(`\
|
|
@@ -18,6 +18,11 @@ Description:
|
|
|
18
18
|
Cleans up expired or unreferenced items in storage.
|
|
19
19
|
This can include expired collection indexes and orphaned content assets.
|
|
20
20
|
|
|
21
|
+
Do not run clean while publish-content can run for the same storage.
|
|
22
|
+
clean can delete files that a publish uses before the publish writes its
|
|
23
|
+
index. In CI, put the jobs that publish and the job that cleans in the same
|
|
24
|
+
concurrency group.
|
|
25
|
+
|
|
21
26
|
Options:
|
|
22
27
|
--delete-expired-collections If set, expired collection index files will be deleted.
|
|
23
28
|
|
|
@@ -58,7 +63,7 @@ export async function action(actionArgs) {
|
|
|
58
63
|
if (parsed.error != null) {
|
|
59
64
|
console.error(String(parsed.error));
|
|
60
65
|
console.error();
|
|
61
|
-
|
|
66
|
+
recordFailure('usage', String(parsed.error));
|
|
62
67
|
}
|
|
63
68
|
help();
|
|
64
69
|
return;
|
|
@@ -66,7 +71,7 @@ export async function action(actionArgs) {
|
|
|
66
71
|
const { verbose, ['delete-expired-collections']: deleteExpiredCollections, ['dry-run']: dryRun, local: localMode, ['fastly-api-token']: fastlyApiToken, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
|
|
67
72
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
68
73
|
// in other words, the directory that contains `fastly.toml`.
|
|
69
|
-
const computeAppDir =
|
|
74
|
+
const computeAppDir = getComputeAppDir();
|
|
70
75
|
console.log(`🧹 Cleaning storage entries...`);
|
|
71
76
|
// #### load config
|
|
72
77
|
let staticPublisherRc;
|
|
@@ -74,14 +79,14 @@ export async function action(actionArgs) {
|
|
|
74
79
|
staticPublisherRc = await loadStaticPublisherRcFile();
|
|
75
80
|
}
|
|
76
81
|
catch (err) {
|
|
77
|
-
console.error(
|
|
82
|
+
console.error(`❌ Can't load ${configFileName()}`);
|
|
78
83
|
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
79
84
|
if (err instanceof LoadConfigError) {
|
|
80
85
|
for (const error of err.errors) {
|
|
81
86
|
console.error(error);
|
|
82
87
|
}
|
|
83
88
|
}
|
|
84
|
-
|
|
89
|
+
recordFailure('config-invalid', `Can't load ${configFileName()}.`);
|
|
85
90
|
return;
|
|
86
91
|
}
|
|
87
92
|
const publishId = staticPublisherRc.publishId;
|
|
@@ -104,7 +109,7 @@ export async function action(actionArgs) {
|
|
|
104
109
|
catch (err) {
|
|
105
110
|
console.error(`❌ Could not instantiate store provider`);
|
|
106
111
|
console.error(String(err));
|
|
107
|
-
|
|
112
|
+
recordFailure(errorCodeOf(err), String(err));
|
|
108
113
|
return;
|
|
109
114
|
}
|
|
110
115
|
// ### Asset keys to delete
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"AAuEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAiLhD"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
import path from 'node:path';
|
|
6
5
|
import { parseCommandLine } from '../../../util/args.js';
|
|
7
|
-
import {
|
|
6
|
+
import { errorCodeOf, fail, recordFailure, setJsonResult } from '../../../util/output.js';
|
|
7
|
+
import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../../util/config.js';
|
|
8
8
|
import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
|
|
9
9
|
import { loadPurgeTarget, purgeCollection } from '../../../util/purge.js';
|
|
10
10
|
function help() {
|
|
@@ -73,7 +73,7 @@ export async function action(actionArgs) {
|
|
|
73
73
|
if (parsed.error != null) {
|
|
74
74
|
console.error(String(parsed.error));
|
|
75
75
|
console.error();
|
|
76
|
-
|
|
76
|
+
recordFailure('usage', String(parsed.error));
|
|
77
77
|
}
|
|
78
78
|
help();
|
|
79
79
|
return;
|
|
@@ -81,10 +81,9 @@ export async function action(actionArgs) {
|
|
|
81
81
|
const { verbose, ['collection-name']: collectionNameValue, ['fastly-api-token']: fastlyApiToken, ['fastly-service-id']: fastlyServiceId, ['purge-environment']: purgeEnvironmentValues, local: localMode, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
|
|
82
82
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
83
83
|
// in other words, the directory that contains `fastly.toml`.
|
|
84
|
-
const computeAppDir =
|
|
84
|
+
const computeAppDir = getComputeAppDir();
|
|
85
85
|
if (collectionNameValue == null) {
|
|
86
|
-
|
|
87
|
-
process.exitCode = 1;
|
|
86
|
+
fail('usage', "Required argument '--collection-name' not specified.");
|
|
88
87
|
return;
|
|
89
88
|
}
|
|
90
89
|
console.log(`🧹 Deleting storage collection...`);
|
|
@@ -94,14 +93,14 @@ export async function action(actionArgs) {
|
|
|
94
93
|
staticPublisherRc = await loadStaticPublisherRcFile();
|
|
95
94
|
}
|
|
96
95
|
catch (err) {
|
|
97
|
-
console.error(
|
|
96
|
+
console.error(`❌ Can't load ${configFileName()}`);
|
|
98
97
|
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
99
98
|
if (err instanceof LoadConfigError) {
|
|
100
99
|
for (const error of err.errors) {
|
|
101
100
|
console.error(error);
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
|
-
|
|
103
|
+
recordFailure('config-invalid', `Can't load ${configFileName()}.`);
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
107
106
|
const publishId = staticPublisherRc.publishId;
|
|
@@ -124,13 +123,12 @@ export async function action(actionArgs) {
|
|
|
124
123
|
catch (err) {
|
|
125
124
|
console.error(`❌ Could not instantiate store provider`);
|
|
126
125
|
console.error(String(err));
|
|
127
|
-
|
|
126
|
+
recordFailure(errorCodeOf(err), String(err));
|
|
128
127
|
return;
|
|
129
128
|
}
|
|
130
129
|
const collectionName = collectionNameValue;
|
|
131
130
|
if (collectionName === defaultCollectionName) {
|
|
132
|
-
|
|
133
|
-
process.exitCode = 1;
|
|
131
|
+
fail('usage', `Cannot delete default collection: ${collectionName}`);
|
|
134
132
|
return;
|
|
135
133
|
}
|
|
136
134
|
console.log(`✔️ Collection to delete: ${collectionName}`);
|
|
@@ -147,7 +145,7 @@ export async function action(actionArgs) {
|
|
|
147
145
|
}
|
|
148
146
|
catch (err) {
|
|
149
147
|
console.error(String(err));
|
|
150
|
-
|
|
148
|
+
recordFailure(errorCodeOf(err), String(err));
|
|
151
149
|
return;
|
|
152
150
|
}
|
|
153
151
|
// ### Asset Keys to delete
|
|
@@ -172,14 +170,32 @@ export async function action(actionArgs) {
|
|
|
172
170
|
}
|
|
173
171
|
}
|
|
174
172
|
}
|
|
173
|
+
// A collection that does not exist is not an error: there is nothing to
|
|
174
|
+
// delete. The purge still runs, in case an earlier delete did not purge.
|
|
175
|
+
if (assetKeysToDelete.size === 0) {
|
|
176
|
+
console.log(`✔️ Collection '${collectionName}' does not exist. Nothing to delete.`);
|
|
177
|
+
}
|
|
175
178
|
// ### Delete items that have been flagged
|
|
176
179
|
const items = [...assetKeysToDelete].map(key => ({ key }));
|
|
177
180
|
await storageProvider.doConcurrentParallel(items, async (_, key) => {
|
|
178
181
|
console.log(`Deleting key from storage: ${key}`);
|
|
179
182
|
await storageProvider.deleteStorageEntry(key);
|
|
180
183
|
}, undefined, true);
|
|
184
|
+
const purgeResults = [];
|
|
181
185
|
if (purgeTarget != null) {
|
|
182
|
-
await purgeCollection(purgeTarget, publishId, collectionName);
|
|
186
|
+
purgeResults.push(...await purgeCollection(purgeTarget, publishId, collectionName));
|
|
183
187
|
}
|
|
184
188
|
console.log("✅ Completed.");
|
|
189
|
+
setJsonResult({
|
|
190
|
+
collection: collectionName,
|
|
191
|
+
publishId,
|
|
192
|
+
deleted: assetKeysToDelete.size > 0,
|
|
193
|
+
...(assetKeysToDelete.size === 0 ? { reason: 'not-found' } : {}),
|
|
194
|
+
// null: no purge (--local, or no Service ID).
|
|
195
|
+
purge: purgeTarget != null ? {
|
|
196
|
+
ok: purgeResults.every(x => x.result !== 'failed'),
|
|
197
|
+
serviceId: purgeTarget.serviceId,
|
|
198
|
+
environments: purgeResults,
|
|
199
|
+
} : null,
|
|
200
|
+
});
|
|
185
201
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"AAqDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA8BhD"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import { getCommandAndArgs } from '../../../util/args.js';
|
|
6
|
+
import { fail, isJsonMode, recordFailure } from '../../../util/output.js';
|
|
6
7
|
import * as deleteCommand from './delete.js';
|
|
7
8
|
import * as listCommand from './list.js';
|
|
8
9
|
import * as promoteCommand from './promote.js';
|
|
@@ -60,11 +61,15 @@ export async function action(actionArgs) {
|
|
|
60
61
|
console.error(commandAndArgs.error);
|
|
61
62
|
console.error(`Specify one of the following sub-commands: ${Object.keys(modes).join(', ')}`);
|
|
62
63
|
console.error();
|
|
63
|
-
|
|
64
|
+
recordFailure('usage', commandAndArgs.error);
|
|
64
65
|
}
|
|
65
66
|
help();
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
69
|
const { command, argv, } = commandAndArgs;
|
|
70
|
+
if (isJsonMode() && !['list', 'delete', 'promote'].includes(command)) {
|
|
71
|
+
fail('json-not-supported', `--json is not supported for 'collections ${command}'.`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
69
74
|
await modes[command].action(argv);
|
|
70
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAoLhD"}
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import { countHiddenEntries } from '../../../../models/assets/index.js';
|
|
6
6
|
import { decodeIndexMetadata, getUnsupportedIndexFeatures } from '../../../../models/server/index.js';
|
|
7
7
|
import { isExpired } from '../../../../models/time/index.js';
|
|
8
8
|
import { parseCommandLine } from '../../../util/args.js';
|
|
9
|
-
import {
|
|
9
|
+
import { errorCodeOf, recordFailure, setJsonResult } from '../../../util/output.js';
|
|
10
|
+
import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../../util/config.js';
|
|
10
11
|
import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
|
|
11
12
|
function help() {
|
|
12
13
|
console.log(`\
|
|
@@ -50,7 +51,7 @@ export async function action(actionArgs) {
|
|
|
50
51
|
if (parsed.error != null) {
|
|
51
52
|
console.error(String(parsed.error));
|
|
52
53
|
console.error();
|
|
53
|
-
|
|
54
|
+
recordFailure('usage', String(parsed.error));
|
|
54
55
|
}
|
|
55
56
|
help();
|
|
56
57
|
return;
|
|
@@ -58,7 +59,7 @@ export async function action(actionArgs) {
|
|
|
58
59
|
const { verbose, local: localMode, ['fastly-api-token']: fastlyApiToken, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
|
|
59
60
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
60
61
|
// in other words, the directory that contains `fastly.toml`.
|
|
61
|
-
const computeAppDir =
|
|
62
|
+
const computeAppDir = getComputeAppDir();
|
|
62
63
|
console.log(`📃 Listing collections...`);
|
|
63
64
|
// #### load config
|
|
64
65
|
let staticPublisherRc;
|
|
@@ -66,14 +67,14 @@ export async function action(actionArgs) {
|
|
|
66
67
|
staticPublisherRc = await loadStaticPublisherRcFile();
|
|
67
68
|
}
|
|
68
69
|
catch (err) {
|
|
69
|
-
console.error(
|
|
70
|
+
console.error(`❌ Can't load ${configFileName()}`);
|
|
70
71
|
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
71
72
|
if (err instanceof LoadConfigError) {
|
|
72
73
|
for (const error of err.errors) {
|
|
73
74
|
console.error(error);
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
|
-
|
|
77
|
+
recordFailure('config-invalid', `Can't load ${configFileName()}.`);
|
|
77
78
|
return;
|
|
78
79
|
}
|
|
79
80
|
const publishId = staticPublisherRc.publishId;
|
|
@@ -96,7 +97,7 @@ export async function action(actionArgs) {
|
|
|
96
97
|
catch (err) {
|
|
97
98
|
console.error(`❌ Could not instantiate store provider`);
|
|
98
99
|
console.error(String(err));
|
|
99
|
-
|
|
100
|
+
recordFailure(errorCodeOf(err), String(err));
|
|
100
101
|
return;
|
|
101
102
|
}
|
|
102
103
|
// ### List all indexes ###
|
|
@@ -107,6 +108,8 @@ export async function action(actionArgs) {
|
|
|
107
108
|
}
|
|
108
109
|
// ### Found collections ###
|
|
109
110
|
const foundCollections = indexKeys.map(x => x.slice(indexesPrefix.length));
|
|
111
|
+
// For --json.
|
|
112
|
+
const collectionInfos = [];
|
|
110
113
|
if (foundCollections.length === 0) {
|
|
111
114
|
console.log('No collections found.');
|
|
112
115
|
}
|
|
@@ -125,16 +128,48 @@ export async function action(actionArgs) {
|
|
|
125
128
|
throw new Error(`❌ Can't load storage entry ${indexesPrefix + collection}`);
|
|
126
129
|
}
|
|
127
130
|
let indexMetadata = decodeIndexMetadata(indexEntryInfo.metadata);
|
|
131
|
+
const info = {
|
|
132
|
+
name: collection,
|
|
133
|
+
isDefault: collection === defaultCollectionName,
|
|
134
|
+
publishedAt: null,
|
|
135
|
+
expiresAt: null,
|
|
136
|
+
expired: false,
|
|
137
|
+
requires: [],
|
|
138
|
+
unsupported: [],
|
|
139
|
+
files: null,
|
|
140
|
+
hidden: null,
|
|
141
|
+
};
|
|
142
|
+
collectionInfos.push(info);
|
|
128
143
|
if (indexMetadata == null) {
|
|
129
144
|
console.log(` No metadata found.`);
|
|
130
145
|
continue;
|
|
131
146
|
}
|
|
147
|
+
if (indexMetadata.publishedTime != null) {
|
|
148
|
+
info.publishedAt = new Date(indexMetadata.publishedTime * 1000).toISOString();
|
|
149
|
+
}
|
|
150
|
+
if (indexMetadata.expirationTime != null) {
|
|
151
|
+
info.expiresAt = new Date(indexMetadata.expirationTime * 1000).toISOString();
|
|
152
|
+
// The expiration time is not enforced for the default collection.
|
|
153
|
+
info.expired = collection !== defaultCollectionName && isExpired(indexMetadata.expirationTime);
|
|
154
|
+
}
|
|
155
|
+
info.requires = indexMetadata.requires ?? [];
|
|
156
|
+
info.unsupported = getUnsupportedIndexFeatures(indexMetadata);
|
|
132
157
|
if (indexMetadata.publishedTime == null) {
|
|
133
158
|
console.log(' Published : unknown');
|
|
134
159
|
}
|
|
135
160
|
else {
|
|
136
161
|
console.log(` Published : ${new Date(indexMetadata.publishedTime * 1000)}`);
|
|
137
162
|
}
|
|
163
|
+
try {
|
|
164
|
+
const assetEntryMap = (await new Response(indexEntryInfo.data).json());
|
|
165
|
+
const fileCount = Object.keys(assetEntryMap).length;
|
|
166
|
+
info.files = fileCount;
|
|
167
|
+
info.hidden = countHiddenEntries(assetEntryMap);
|
|
168
|
+
console.log(` Files : ${fileCount} (${countHiddenEntries(assetEntryMap)} hidden)`);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
console.log(' Files : unknown (cannot read the index)');
|
|
172
|
+
}
|
|
138
173
|
if (indexMetadata.requires != null) {
|
|
139
174
|
console.log(` Requires : ${indexMetadata.requires.join(', ')}`);
|
|
140
175
|
const unsupportedFeatures = getUnsupportedIndexFeatures(indexMetadata);
|
|
@@ -159,4 +194,9 @@ export async function action(actionArgs) {
|
|
|
159
194
|
}
|
|
160
195
|
}
|
|
161
196
|
console.log("✅ Completed.");
|
|
197
|
+
setJsonResult({
|
|
198
|
+
publishId,
|
|
199
|
+
defaultCollection: defaultCollectionName,
|
|
200
|
+
collections: collectionInfos,
|
|
201
|
+
});
|
|
162
202
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"AAyFA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0NhD"}
|
|
@@ -6,9 +6,12 @@ import fs from 'node:fs';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import { decodeIndexMetadata, encodeIndexMetadata } from '../../../../models/server/index.js';
|
|
8
8
|
import { calcExpirationTime } from '../../../../models/time/index.js';
|
|
9
|
-
import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
9
|
+
import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../../util/config.js';
|
|
10
10
|
import { parseCommandLine } from '../../../util/args.js';
|
|
11
|
+
import { errorCodeOf, fail, recordFailure, setJsonResult } from '../../../util/output.js';
|
|
12
|
+
import { checkCollectionNameForWrite } from '../../../util/collection-name.js';
|
|
11
13
|
import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
|
|
14
|
+
import { loadPurgeTarget, purgeCollection } from '../../../util/purge.js';
|
|
12
15
|
function help() {
|
|
13
16
|
console.log(`\
|
|
14
17
|
|
|
@@ -21,6 +24,9 @@ Usage:
|
|
|
21
24
|
Description:
|
|
22
25
|
Copies an existing collection (content + config) to a new collection name.
|
|
23
26
|
|
|
27
|
+
If a Service ID is found, the tool then purges the cached responses of the target
|
|
28
|
+
collection from that service.
|
|
29
|
+
|
|
24
30
|
Required:
|
|
25
31
|
--collection-name=<name> The name of the collection to promote
|
|
26
32
|
--to=<name> The name of the new (target) collection to create or overwrite
|
|
@@ -45,10 +51,21 @@ KV Store Options:
|
|
|
45
51
|
with the local development environment.
|
|
46
52
|
KV Store mode only. In S3 mode, --local is an error.
|
|
47
53
|
|
|
48
|
-
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
54
|
+
--fastly-api-token=<token> Fastly API token for KV Store or cache access.
|
|
49
55
|
If not set, the tool uses the FASTLY_API_TOKEN
|
|
50
56
|
environment variable.
|
|
51
57
|
|
|
58
|
+
Purge Options:
|
|
59
|
+
--fastly-service-id=<id> Fastly Service ID to purge after promoting (not with --local).
|
|
60
|
+
If not set, the tool will check:
|
|
61
|
+
1. FASTLY_SERVICE_ID environment variable
|
|
62
|
+
2. service_id in fastly.toml
|
|
63
|
+
If none is found, the purge is skipped.
|
|
64
|
+
|
|
65
|
+
--purge-environment=<env> Environment to purge: production, staging, or a
|
|
66
|
+
comma-separated list of both. Can be repeated.
|
|
67
|
+
Default: production
|
|
68
|
+
|
|
52
69
|
S3 Storage Options (BETA):
|
|
53
70
|
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
54
71
|
--s3-secret-access-key=<key> interface with S3 or compatible storage.
|
|
@@ -69,6 +86,8 @@ export async function action(actionArgs) {
|
|
|
69
86
|
{ name: 'expires-never', type: Boolean },
|
|
70
87
|
{ name: 'local', type: Boolean },
|
|
71
88
|
{ name: 'fastly-api-token', type: String, },
|
|
89
|
+
{ name: 'fastly-service-id', type: String, },
|
|
90
|
+
{ name: 'purge-environment', type: String, multiple: true, },
|
|
72
91
|
{ name: 's3-access-key-id', type: String, },
|
|
73
92
|
{ name: 's3-secret-access-key', type: String, },
|
|
74
93
|
];
|
|
@@ -77,23 +96,21 @@ export async function action(actionArgs) {
|
|
|
77
96
|
if (parsed.error != null) {
|
|
78
97
|
console.error(String(parsed.error));
|
|
79
98
|
console.error();
|
|
80
|
-
|
|
99
|
+
recordFailure('usage', String(parsed.error));
|
|
81
100
|
}
|
|
82
101
|
help();
|
|
83
102
|
return;
|
|
84
103
|
}
|
|
85
|
-
const { verbose, ['collection-name']: collectionNameValue, to: toCollectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
|
|
104
|
+
const { verbose, ['collection-name']: collectionNameValue, to: toCollectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['fastly-service-id']: fastlyServiceId, ['purge-environment']: purgeEnvironmentValues, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
|
|
86
105
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
87
106
|
// in other words, the directory that contains `fastly.toml`.
|
|
88
|
-
const computeAppDir =
|
|
107
|
+
const computeAppDir = getComputeAppDir();
|
|
89
108
|
if (collectionNameValue == null) {
|
|
90
|
-
|
|
91
|
-
process.exitCode = 1;
|
|
109
|
+
fail('usage', "Required argument '--collection-name' not specified.");
|
|
92
110
|
return;
|
|
93
111
|
}
|
|
94
112
|
if (toCollectionNameValue == null) {
|
|
95
|
-
|
|
96
|
-
process.exitCode = 1;
|
|
113
|
+
fail('usage', "Required argument '--to' not specified.");
|
|
97
114
|
return;
|
|
98
115
|
}
|
|
99
116
|
let expirationTime;
|
|
@@ -103,7 +120,7 @@ export async function action(actionArgs) {
|
|
|
103
120
|
catch (err) {
|
|
104
121
|
console.error(`❌ Cannot process expiration time`);
|
|
105
122
|
console.error(String(err));
|
|
106
|
-
process
|
|
123
|
+
recordFailure('usage', `Cannot process expiration time: ${String(err)}`);
|
|
107
124
|
return;
|
|
108
125
|
}
|
|
109
126
|
console.log(`📃 Promoting collection...`);
|
|
@@ -113,14 +130,14 @@ export async function action(actionArgs) {
|
|
|
113
130
|
staticPublisherRc = await loadStaticPublisherRcFile();
|
|
114
131
|
}
|
|
115
132
|
catch (err) {
|
|
116
|
-
console.error(
|
|
133
|
+
console.error(`❌ Can't load ${configFileName()}`);
|
|
117
134
|
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
118
135
|
if (err instanceof LoadConfigError) {
|
|
119
136
|
for (const error of err.errors) {
|
|
120
137
|
console.error(error);
|
|
121
138
|
}
|
|
122
139
|
}
|
|
123
|
-
|
|
140
|
+
recordFailure('config-invalid', `Can't load ${configFileName()}.`);
|
|
124
141
|
return;
|
|
125
142
|
}
|
|
126
143
|
const publishId = staticPublisherRc.publishId;
|
|
@@ -143,13 +160,32 @@ export async function action(actionArgs) {
|
|
|
143
160
|
catch (err) {
|
|
144
161
|
console.error(`❌ Could not instantiate store provider`);
|
|
145
162
|
console.error(String(err));
|
|
146
|
-
|
|
163
|
+
recordFailure(errorCodeOf(err), String(err));
|
|
147
164
|
return;
|
|
148
165
|
}
|
|
149
166
|
const sourceCollectionName = collectionNameValue;
|
|
150
167
|
console.log(`✔️ Collection to copy: ${sourceCollectionName}`);
|
|
168
|
+
// Purge target: checked now, so that a missing API token fails before anything is written.
|
|
169
|
+
let purgeTarget;
|
|
170
|
+
try {
|
|
171
|
+
purgeTarget = loadPurgeTarget({
|
|
172
|
+
localMode: localMode ?? false,
|
|
173
|
+
computeAppDir,
|
|
174
|
+
fastlyServiceId,
|
|
175
|
+
fastlyApiToken,
|
|
176
|
+
purgeEnvironments: purgeEnvironmentValues,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
console.error(String(err));
|
|
181
|
+
process.exitCode = 1;
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
151
184
|
const targetCollectionName = toCollectionNameValue;
|
|
152
185
|
console.log(`✔️ Collection to promote to: ${targetCollectionName}`);
|
|
186
|
+
if (!await checkCollectionNameForWrite(storageProvider, publishId, targetCollectionName)) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
153
189
|
if (expirationTime === undefined) {
|
|
154
190
|
console.log(`✔️ Not updating expiration timestamp.`);
|
|
155
191
|
}
|
|
@@ -170,11 +206,9 @@ export async function action(actionArgs) {
|
|
|
170
206
|
storageProvider.getStorageEntry(sourceCollectionIndexKey),
|
|
171
207
|
storageProvider.getStorageEntry(sourceCollectionSettingsKey),
|
|
172
208
|
]);
|
|
173
|
-
if (!indexEntryInfo) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (!settingsEntryInfo) {
|
|
177
|
-
throw new Error(`Error querying settings for '${collectionNameValue}' in storage`);
|
|
209
|
+
if (!indexEntryInfo || !settingsEntryInfo) {
|
|
210
|
+
fail('collection-not-found', `Collection '${collectionNameValue}' does not exist.`);
|
|
211
|
+
return;
|
|
178
212
|
}
|
|
179
213
|
let indexMetadata = decodeIndexMetadata(indexEntryInfo.metadata) ?? {};
|
|
180
214
|
if (indexMetadata.publishedTime == null) {
|
|
@@ -191,11 +225,24 @@ export async function action(actionArgs) {
|
|
|
191
225
|
console.log(`Uploading to storage: '${targetCollectionName}'`);
|
|
192
226
|
const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
|
|
193
227
|
fs.mkdirSync(storageContentDir, { recursive: true });
|
|
194
|
-
|
|
228
|
+
// The files have the name of the target collection, as in publish-content. In
|
|
229
|
+
// --local mode, kvstore.json refers to them, so the target must not share a
|
|
230
|
+
// file with the source.
|
|
231
|
+
const indexFileName = `index_${targetCollectionName}.json`;
|
|
195
232
|
const indexFilePath = path.resolve(storageContentDir, indexFileName);
|
|
196
233
|
await storageProvider.submitStorageEntry(targetCollectionIndexKey, indexFilePath, indexEntryInfo.data, encodeIndexMetadata(indexMetadata));
|
|
197
|
-
const settingsFileName = `settings_${
|
|
234
|
+
const settingsFileName = `settings_${targetCollectionName}.json`;
|
|
198
235
|
const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
|
|
199
236
|
await storageProvider.submitStorageEntry(targetCollectionSettingsKey, settingsFilePath, settingsEntryInfo.data);
|
|
237
|
+
if (purgeTarget != null) {
|
|
238
|
+
await purgeCollection(purgeTarget, publishId, targetCollectionName);
|
|
239
|
+
}
|
|
200
240
|
console.log("✅ Completed.");
|
|
241
|
+
setJsonResult({
|
|
242
|
+
from: sourceCollectionName,
|
|
243
|
+
to: targetCollectionName,
|
|
244
|
+
publishId,
|
|
245
|
+
// The expiration time of the target, after the promote. null: it does not expire.
|
|
246
|
+
expiresAt: indexMetadata.expirationTime != null ? new Date(indexMetadata.expirationTime * 1000).toISOString() : null,
|
|
247
|
+
});
|
|
201
248
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"AAqEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAwJhD"}
|
|
@@ -6,8 +6,9 @@ import fs from 'node:fs';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import { decodeIndexMetadata, encodeIndexMetadata } from '../../../../models/server/index.js';
|
|
8
8
|
import { calcExpirationTime } from '../../../../models/time/index.js';
|
|
9
|
-
import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
9
|
+
import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../../util/config.js';
|
|
10
10
|
import { parseCommandLine } from '../../../util/args.js';
|
|
11
|
+
import { errorCodeOf, fail, recordFailure } from '../../../util/output.js';
|
|
11
12
|
import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
|
|
12
13
|
function help() {
|
|
13
14
|
console.log(`\
|
|
@@ -72,7 +73,7 @@ export async function action(actionArgs) {
|
|
|
72
73
|
if (parsed.error != null) {
|
|
73
74
|
console.error(String(parsed.error));
|
|
74
75
|
console.error();
|
|
75
|
-
|
|
76
|
+
recordFailure('usage', String(parsed.error));
|
|
76
77
|
}
|
|
77
78
|
help();
|
|
78
79
|
return;
|
|
@@ -80,10 +81,9 @@ export async function action(actionArgs) {
|
|
|
80
81
|
const { verbose, ['collection-name']: collectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
|
|
81
82
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
82
83
|
// in other words, the directory that contains `fastly.toml`.
|
|
83
|
-
const computeAppDir =
|
|
84
|
+
const computeAppDir = getComputeAppDir();
|
|
84
85
|
if (collectionNameValue == null) {
|
|
85
|
-
|
|
86
|
-
process.exitCode = 1;
|
|
86
|
+
fail('usage', "Required argument '--collection-name' not specified.");
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
let expirationTime;
|
|
@@ -93,12 +93,11 @@ export async function action(actionArgs) {
|
|
|
93
93
|
catch (err) {
|
|
94
94
|
console.error(`❌ Cannot process expiration time`);
|
|
95
95
|
console.error(String(err));
|
|
96
|
-
process
|
|
96
|
+
recordFailure('usage', `Cannot process expiration time: ${String(err)}`);
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
99
|
if (expirationTime === undefined) {
|
|
100
|
-
|
|
101
|
-
process.exitCode = 1;
|
|
100
|
+
fail('usage', "Exactly one of '--expires-in', '--expires-at', or '--expires-never' is required.");
|
|
102
101
|
return;
|
|
103
102
|
}
|
|
104
103
|
console.log(`📃 Promoting collection...`);
|
|
@@ -108,14 +107,14 @@ export async function action(actionArgs) {
|
|
|
108
107
|
staticPublisherRc = await loadStaticPublisherRcFile();
|
|
109
108
|
}
|
|
110
109
|
catch (err) {
|
|
111
|
-
console.error(
|
|
110
|
+
console.error(`❌ Can't load ${configFileName()}`);
|
|
112
111
|
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
113
112
|
if (err instanceof LoadConfigError) {
|
|
114
113
|
for (const error of err.errors) {
|
|
115
114
|
console.error(error);
|
|
116
115
|
}
|
|
117
116
|
}
|
|
118
|
-
|
|
117
|
+
recordFailure('config-invalid', `Can't load ${configFileName()}.`);
|
|
119
118
|
return;
|
|
120
119
|
}
|
|
121
120
|
const publishId = staticPublisherRc.publishId;
|
|
@@ -138,7 +137,7 @@ export async function action(actionArgs) {
|
|
|
138
137
|
catch (err) {
|
|
139
138
|
console.error(`❌ Could not instantiate store provider`);
|
|
140
139
|
console.error(String(err));
|
|
141
|
-
|
|
140
|
+
recordFailure(errorCodeOf(err), String(err));
|
|
142
141
|
return;
|
|
143
142
|
}
|
|
144
143
|
const collectionName = collectionNameValue;
|