@fastly/compute-js-static-publish 8.0.1 → 8.1.0-beta.2
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 +792 -35
- package/README.md +13 -3
- package/README.short.md +13 -3
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +14 -8
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +32 -15
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +10 -4
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +49 -8
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +69 -21
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +12 -12
- 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 +78 -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 +42 -5
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +83 -37
- 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 +43 -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 +298 -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 +6 -0
- package/build/cli/cli/util/package.d.ts.map +1 -1
- package/build/cli/cli/util/package.js +23 -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
|
@@ -6,14 +6,18 @@ 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 { cliCommand } from '../../../util/package.js';
|
|
15
|
+
import { loadPurgeTarget, purgeCollection } from '../../../util/purge.js';
|
|
12
16
|
function help() {
|
|
13
17
|
console.log(`\
|
|
14
18
|
|
|
15
19
|
Usage:
|
|
16
|
-
|
|
20
|
+
${cliCommand()} collections promote
|
|
17
21
|
--collection-name=<name> \\
|
|
18
22
|
--to=name> \\
|
|
19
23
|
[options]
|
|
@@ -21,6 +25,9 @@ Usage:
|
|
|
21
25
|
Description:
|
|
22
26
|
Copies an existing collection (content + config) to a new collection name.
|
|
23
27
|
|
|
28
|
+
If a Service ID is found, the tool then purges the cached responses of the target
|
|
29
|
+
collection from that service.
|
|
30
|
+
|
|
24
31
|
Required:
|
|
25
32
|
--collection-name=<name> The name of the collection to promote
|
|
26
33
|
--to=<name> The name of the new (target) collection to create or overwrite
|
|
@@ -45,10 +52,21 @@ KV Store Options:
|
|
|
45
52
|
with the local development environment.
|
|
46
53
|
KV Store mode only. In S3 mode, --local is an error.
|
|
47
54
|
|
|
48
|
-
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
55
|
+
--fastly-api-token=<token> Fastly API token for KV Store or cache access.
|
|
49
56
|
If not set, the tool uses the FASTLY_API_TOKEN
|
|
50
57
|
environment variable.
|
|
51
58
|
|
|
59
|
+
Purge Options:
|
|
60
|
+
--fastly-service-id=<id> Fastly Service ID to purge after promoting (not with --local).
|
|
61
|
+
If not set, the tool will check:
|
|
62
|
+
1. FASTLY_SERVICE_ID environment variable
|
|
63
|
+
2. service_id in fastly.toml
|
|
64
|
+
If none is found, the purge is skipped.
|
|
65
|
+
|
|
66
|
+
--purge-environment=<env> Environment to purge: production, staging, or a
|
|
67
|
+
comma-separated list of both. Can be repeated.
|
|
68
|
+
Default: production
|
|
69
|
+
|
|
52
70
|
S3 Storage Options (BETA):
|
|
53
71
|
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
54
72
|
--s3-secret-access-key=<key> interface with S3 or compatible storage.
|
|
@@ -69,6 +87,8 @@ export async function action(actionArgs) {
|
|
|
69
87
|
{ name: 'expires-never', type: Boolean },
|
|
70
88
|
{ name: 'local', type: Boolean },
|
|
71
89
|
{ name: 'fastly-api-token', type: String, },
|
|
90
|
+
{ name: 'fastly-service-id', type: String, },
|
|
91
|
+
{ name: 'purge-environment', type: String, multiple: true, },
|
|
72
92
|
{ name: 's3-access-key-id', type: String, },
|
|
73
93
|
{ name: 's3-secret-access-key', type: String, },
|
|
74
94
|
];
|
|
@@ -77,23 +97,21 @@ export async function action(actionArgs) {
|
|
|
77
97
|
if (parsed.error != null) {
|
|
78
98
|
console.error(String(parsed.error));
|
|
79
99
|
console.error();
|
|
80
|
-
|
|
100
|
+
recordFailure('usage', String(parsed.error));
|
|
81
101
|
}
|
|
82
102
|
help();
|
|
83
103
|
return;
|
|
84
104
|
}
|
|
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;
|
|
105
|
+
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
106
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
87
107
|
// in other words, the directory that contains `fastly.toml`.
|
|
88
|
-
const computeAppDir =
|
|
108
|
+
const computeAppDir = getComputeAppDir();
|
|
89
109
|
if (collectionNameValue == null) {
|
|
90
|
-
|
|
91
|
-
process.exitCode = 1;
|
|
110
|
+
fail('usage', "Required argument '--collection-name' not specified.");
|
|
92
111
|
return;
|
|
93
112
|
}
|
|
94
113
|
if (toCollectionNameValue == null) {
|
|
95
|
-
|
|
96
|
-
process.exitCode = 1;
|
|
114
|
+
fail('usage', "Required argument '--to' not specified.");
|
|
97
115
|
return;
|
|
98
116
|
}
|
|
99
117
|
let expirationTime;
|
|
@@ -103,7 +121,7 @@ export async function action(actionArgs) {
|
|
|
103
121
|
catch (err) {
|
|
104
122
|
console.error(`❌ Cannot process expiration time`);
|
|
105
123
|
console.error(String(err));
|
|
106
|
-
process
|
|
124
|
+
recordFailure('usage', `Cannot process expiration time: ${String(err)}`);
|
|
107
125
|
return;
|
|
108
126
|
}
|
|
109
127
|
console.log(`📃 Promoting collection...`);
|
|
@@ -113,14 +131,14 @@ export async function action(actionArgs) {
|
|
|
113
131
|
staticPublisherRc = await loadStaticPublisherRcFile();
|
|
114
132
|
}
|
|
115
133
|
catch (err) {
|
|
116
|
-
console.error(
|
|
134
|
+
console.error(`❌ Can't load ${configFileName()}`);
|
|
117
135
|
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
118
136
|
if (err instanceof LoadConfigError) {
|
|
119
137
|
for (const error of err.errors) {
|
|
120
138
|
console.error(error);
|
|
121
139
|
}
|
|
122
140
|
}
|
|
123
|
-
|
|
141
|
+
recordFailure('config-invalid', `Can't load ${configFileName()}.`);
|
|
124
142
|
return;
|
|
125
143
|
}
|
|
126
144
|
const publishId = staticPublisherRc.publishId;
|
|
@@ -143,13 +161,32 @@ export async function action(actionArgs) {
|
|
|
143
161
|
catch (err) {
|
|
144
162
|
console.error(`❌ Could not instantiate store provider`);
|
|
145
163
|
console.error(String(err));
|
|
146
|
-
|
|
164
|
+
recordFailure(errorCodeOf(err), String(err));
|
|
147
165
|
return;
|
|
148
166
|
}
|
|
149
167
|
const sourceCollectionName = collectionNameValue;
|
|
150
168
|
console.log(`✔️ Collection to copy: ${sourceCollectionName}`);
|
|
169
|
+
// Purge target: checked now, so that a missing API token fails before anything is written.
|
|
170
|
+
let purgeTarget;
|
|
171
|
+
try {
|
|
172
|
+
purgeTarget = loadPurgeTarget({
|
|
173
|
+
localMode: localMode ?? false,
|
|
174
|
+
computeAppDir,
|
|
175
|
+
fastlyServiceId,
|
|
176
|
+
fastlyApiToken,
|
|
177
|
+
purgeEnvironments: purgeEnvironmentValues,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
console.error(String(err));
|
|
182
|
+
process.exitCode = 1;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
151
185
|
const targetCollectionName = toCollectionNameValue;
|
|
152
186
|
console.log(`✔️ Collection to promote to: ${targetCollectionName}`);
|
|
187
|
+
if (!await checkCollectionNameForWrite(storageProvider, publishId, targetCollectionName)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
153
190
|
if (expirationTime === undefined) {
|
|
154
191
|
console.log(`✔️ Not updating expiration timestamp.`);
|
|
155
192
|
}
|
|
@@ -170,11 +207,9 @@ export async function action(actionArgs) {
|
|
|
170
207
|
storageProvider.getStorageEntry(sourceCollectionIndexKey),
|
|
171
208
|
storageProvider.getStorageEntry(sourceCollectionSettingsKey),
|
|
172
209
|
]);
|
|
173
|
-
if (!indexEntryInfo) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (!settingsEntryInfo) {
|
|
177
|
-
throw new Error(`Error querying settings for '${collectionNameValue}' in storage`);
|
|
210
|
+
if (!indexEntryInfo || !settingsEntryInfo) {
|
|
211
|
+
fail('collection-not-found', `Collection '${collectionNameValue}' does not exist.`);
|
|
212
|
+
return;
|
|
178
213
|
}
|
|
179
214
|
let indexMetadata = decodeIndexMetadata(indexEntryInfo.metadata) ?? {};
|
|
180
215
|
if (indexMetadata.publishedTime == null) {
|
|
@@ -191,11 +226,24 @@ export async function action(actionArgs) {
|
|
|
191
226
|
console.log(`Uploading to storage: '${targetCollectionName}'`);
|
|
192
227
|
const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
|
|
193
228
|
fs.mkdirSync(storageContentDir, { recursive: true });
|
|
194
|
-
|
|
229
|
+
// The files have the name of the target collection, as in publish-content. In
|
|
230
|
+
// --local mode, kvstore.json refers to them, so the target must not share a
|
|
231
|
+
// file with the source.
|
|
232
|
+
const indexFileName = `index_${targetCollectionName}.json`;
|
|
195
233
|
const indexFilePath = path.resolve(storageContentDir, indexFileName);
|
|
196
234
|
await storageProvider.submitStorageEntry(targetCollectionIndexKey, indexFilePath, indexEntryInfo.data, encodeIndexMetadata(indexMetadata));
|
|
197
|
-
const settingsFileName = `settings_${
|
|
235
|
+
const settingsFileName = `settings_${targetCollectionName}.json`;
|
|
198
236
|
const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
|
|
199
237
|
await storageProvider.submitStorageEntry(targetCollectionSettingsKey, settingsFilePath, settingsEntryInfo.data);
|
|
238
|
+
if (purgeTarget != null) {
|
|
239
|
+
await purgeCollection(purgeTarget, publishId, targetCollectionName);
|
|
240
|
+
}
|
|
200
241
|
console.log("✅ Completed.");
|
|
242
|
+
setJsonResult({
|
|
243
|
+
from: sourceCollectionName,
|
|
244
|
+
to: targetCollectionName,
|
|
245
|
+
publishId,
|
|
246
|
+
// The expiration time of the target, after the promote. null: it does not expire.
|
|
247
|
+
expiresAt: indexMetadata.expirationTime != null ? new Date(indexMetadata.expirationTime * 1000).toISOString() : null,
|
|
248
|
+
});
|
|
201
249
|
}
|
|
@@ -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":"AAsEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAwJhD"}
|
|
@@ -6,14 +6,16 @@ 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';
|
|
13
|
+
import { cliCommand } from '../../../util/package.js';
|
|
12
14
|
function help() {
|
|
13
15
|
console.log(`\
|
|
14
16
|
|
|
15
17
|
Usage:
|
|
16
|
-
|
|
18
|
+
${cliCommand()} collections update-expiration \\
|
|
17
19
|
--collection-name=<name> \\
|
|
18
20
|
[options]
|
|
19
21
|
|
|
@@ -72,7 +74,7 @@ export async function action(actionArgs) {
|
|
|
72
74
|
if (parsed.error != null) {
|
|
73
75
|
console.error(String(parsed.error));
|
|
74
76
|
console.error();
|
|
75
|
-
|
|
77
|
+
recordFailure('usage', String(parsed.error));
|
|
76
78
|
}
|
|
77
79
|
help();
|
|
78
80
|
return;
|
|
@@ -80,10 +82,9 @@ export async function action(actionArgs) {
|
|
|
80
82
|
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
83
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
82
84
|
// in other words, the directory that contains `fastly.toml`.
|
|
83
|
-
const computeAppDir =
|
|
85
|
+
const computeAppDir = getComputeAppDir();
|
|
84
86
|
if (collectionNameValue == null) {
|
|
85
|
-
|
|
86
|
-
process.exitCode = 1;
|
|
87
|
+
fail('usage', "Required argument '--collection-name' not specified.");
|
|
87
88
|
return;
|
|
88
89
|
}
|
|
89
90
|
let expirationTime;
|
|
@@ -93,12 +94,11 @@ export async function action(actionArgs) {
|
|
|
93
94
|
catch (err) {
|
|
94
95
|
console.error(`❌ Cannot process expiration time`);
|
|
95
96
|
console.error(String(err));
|
|
96
|
-
process
|
|
97
|
+
recordFailure('usage', `Cannot process expiration time: ${String(err)}`);
|
|
97
98
|
return;
|
|
98
99
|
}
|
|
99
100
|
if (expirationTime === undefined) {
|
|
100
|
-
|
|
101
|
-
process.exitCode = 1;
|
|
101
|
+
fail('usage', "Exactly one of '--expires-in', '--expires-at', or '--expires-never' is required.");
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
104
|
console.log(`📃 Promoting collection...`);
|
|
@@ -108,14 +108,14 @@ export async function action(actionArgs) {
|
|
|
108
108
|
staticPublisherRc = await loadStaticPublisherRcFile();
|
|
109
109
|
}
|
|
110
110
|
catch (err) {
|
|
111
|
-
console.error(
|
|
111
|
+
console.error(`❌ Can't load ${configFileName()}`);
|
|
112
112
|
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
113
113
|
if (err instanceof LoadConfigError) {
|
|
114
114
|
for (const error of err.errors) {
|
|
115
115
|
console.error(error);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
recordFailure('config-invalid', `Can't load ${configFileName()}.`);
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
121
|
const publishId = staticPublisherRc.publishId;
|
|
@@ -138,7 +138,7 @@ export async function action(actionArgs) {
|
|
|
138
138
|
catch (err) {
|
|
139
139
|
console.error(`❌ Could not instantiate store provider`);
|
|
140
140
|
console.error(String(err));
|
|
141
|
-
|
|
141
|
+
recordFailure(errorCodeOf(err), String(err));
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
144
144
|
const collectionName = collectionNameValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/deploy.ts"],"names":[],"mappings":"AAuEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAqJhD"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import child_process from 'node:child_process';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { managedAppState, prepareManagedApp } from '../../managed/app.js';
|
|
9
|
+
import { checkVersionForCommand, loadManagedProject, showTemplateFolderHint } from '../../managed/command-helpers.js';
|
|
10
|
+
import { getActiveVersion, getVersionDomains } from '../../managed/fastly-service.js';
|
|
11
|
+
import { formatVersionComment, parseVersionComment } from '../../managed/fingerprint.js';
|
|
12
|
+
import { writeBackServiceId } from '../../managed/project-edit.js';
|
|
13
|
+
import { loadApiToken } from '../../util/api-token.js';
|
|
14
|
+
import { parseCommandLine } from '../../util/args.js';
|
|
15
|
+
import { detectProjectMode } from '../../util/config.js';
|
|
16
|
+
import { readServiceId } from '../../util/fastly-toml.js';
|
|
17
|
+
import { cliCommand, getOwnPackageDir, getOwnVersion } from '../../util/package.js';
|
|
18
|
+
import { fail, isJsonMode, isNonInteractive, recordFailure, setJsonResult } from '../../util/output.js';
|
|
19
|
+
import { loadServiceId } from '../../util/service-id.js';
|
|
20
|
+
import { isS3StorageConfigRc } from '../../../models/config/static-publish-rc.js';
|
|
21
|
+
import { PROJECT_FILE_NAME } from '../../../models/config/static-publish-project.js';
|
|
22
|
+
function help() {
|
|
23
|
+
console.log(`\
|
|
24
|
+
|
|
25
|
+
Usage:
|
|
26
|
+
${cliCommand()} deploy [options]
|
|
27
|
+
|
|
28
|
+
Description:
|
|
29
|
+
Deploys the app of a managed project, only if it changed: generates the app,
|
|
30
|
+
installs its dependencies if necessary, and runs 'fastly compute build' and
|
|
31
|
+
'fastly compute deploy'. The comment of the new service version has the
|
|
32
|
+
fingerprint of the app, so that 'status' and the next deploy can compare it.
|
|
33
|
+
|
|
34
|
+
After the first deploy, the Service ID is written into managed.serviceId in
|
|
35
|
+
${PROJECT_FILE_NAME}.
|
|
36
|
+
|
|
37
|
+
In an ejected app, this runs 'fastly compute publish'.
|
|
38
|
+
|
|
39
|
+
Options:
|
|
40
|
+
--force Deploy also when the fingerprint did not change.
|
|
41
|
+
--auto-upgrade If the CLI is newer than managed.staticPublishVersion,
|
|
42
|
+
set it to the version that runs, and continue.
|
|
43
|
+
--comment=<text> Added to the comment of the service version,
|
|
44
|
+
for example a commit SHA.
|
|
45
|
+
--fastly-service-id=<id> The service. Default: FASTLY_SERVICE_ID, then
|
|
46
|
+
managed.serviceId. Without one, the Fastly CLI
|
|
47
|
+
makes a new service.
|
|
48
|
+
--fastly-api-token=<token> Default: FASTLY_API_TOKEN.
|
|
49
|
+
|
|
50
|
+
Global Options:
|
|
51
|
+
-h, --help Show this help message and exit.
|
|
52
|
+
`);
|
|
53
|
+
}
|
|
54
|
+
function runFastly(appDir, args, apiToken) {
|
|
55
|
+
const appFastly = path.resolve(appDir, 'node_modules/.bin/fastly');
|
|
56
|
+
const fastly = fs.existsSync(appFastly) ? appFastly : 'fastly';
|
|
57
|
+
console.log(`▶️ fastly ${args.join(' ')}`);
|
|
58
|
+
return child_process.spawnSync(fastly, args, {
|
|
59
|
+
cwd: appDir,
|
|
60
|
+
env: { ...process.env, FASTLY_API_TOKEN: apiToken },
|
|
61
|
+
// With --json, stdout is for the JSON object only.
|
|
62
|
+
stdio: [isNonInteractive() ? 'ignore' : 'inherit', isJsonMode() ? process.stderr : 'inherit', 'inherit'],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export async function action(actionArgs) {
|
|
66
|
+
const optionDefinitions = [
|
|
67
|
+
{ name: 'force', type: Boolean },
|
|
68
|
+
{ name: 'auto-upgrade', type: Boolean },
|
|
69
|
+
{ name: 'comment', type: String },
|
|
70
|
+
{ name: 'fastly-service-id', type: String },
|
|
71
|
+
{ name: 'fastly-api-token', type: String },
|
|
72
|
+
];
|
|
73
|
+
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
74
|
+
if (parsed.needHelp) {
|
|
75
|
+
if (parsed.error != null) {
|
|
76
|
+
console.error(String(parsed.error));
|
|
77
|
+
console.error();
|
|
78
|
+
recordFailure('usage', String(parsed.error));
|
|
79
|
+
}
|
|
80
|
+
help();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const { force, ['auto-upgrade']: autoUpgrade, comment, ['fastly-service-id']: fastlyServiceId, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
84
|
+
if (detectProjectMode() === 'ejected') {
|
|
85
|
+
if (isJsonMode()) {
|
|
86
|
+
fail('json-not-supported', `--json is not supported for 'deploy' in an ejected app.`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const result = child_process.spawnSync('fastly', ['compute', 'publish'], { stdio: 'inherit' });
|
|
90
|
+
if (result.error != null || result.status !== 0) {
|
|
91
|
+
fail('deploy-failed', `'fastly compute publish' failed.`);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const project = await loadManagedProject('deploy', '');
|
|
96
|
+
if (project == null) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
showTemplateFolderHint(project);
|
|
100
|
+
if (!checkVersionForCommand(project, autoUpgrade === true)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const apiToken = loadApiToken({ commandLine: fastlyApiToken });
|
|
104
|
+
if (apiToken == null) {
|
|
105
|
+
fail('credentials-missing', 'Fastly API Token not provided. Set the FASTLY_API_TOKEN environment variable to an API token that can deploy the service.');
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const context = { apiToken: apiToken.apiToken };
|
|
109
|
+
const serviceIdResult = loadServiceId({
|
|
110
|
+
commandLine: fastlyServiceId,
|
|
111
|
+
fastlyTomlPath: path.resolve('.static-publish/app/fastly.toml'),
|
|
112
|
+
projectServiceId: project.managed.serviceId,
|
|
113
|
+
});
|
|
114
|
+
let serviceId = serviceIdResult?.serviceId ?? null;
|
|
115
|
+
if (serviceId != null) {
|
|
116
|
+
console.log(`✔️ Service ID from ${serviceIdResult.source}: ${serviceId}`);
|
|
117
|
+
}
|
|
118
|
+
// The Fastly CLI cannot make the Secret Store of an S3 app without prompts.
|
|
119
|
+
if (serviceId == null && isS3StorageConfigRc(project.rc) && isNonInteractive()) {
|
|
120
|
+
fail('first-deploy-manual', 'The first deploy of an app with S3 storage must be done by hand: run deploy on your computer (the Fastly CLI asks for the S3 credentials), ' +
|
|
121
|
+
'or give the ID of a service that is already set up (--fastly-service-id, FASTLY_SERVICE_ID, or managed.serviceId).');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// A CLI run from the npx cache puts paths of the home directory into the Wasm binary.
|
|
125
|
+
if (getOwnPackageDir().includes(`${path.sep}_npx${path.sep}`)) {
|
|
126
|
+
console.warn(`⚠️ This CLI runs from the npx cache. The paths of the cache (in your home directory) go into the deployed Wasm binary.`);
|
|
127
|
+
console.warn(` * Add @fastly/compute-js-static-publish as a dev dependency of the project, and run it from there.`);
|
|
128
|
+
}
|
|
129
|
+
const { fingerprint } = await managedAppState(path.resolve(), project);
|
|
130
|
+
const staticPublishVersion = getOwnVersion();
|
|
131
|
+
if (serviceId != null && !force) {
|
|
132
|
+
const active = await getActiveVersion(context, serviceId);
|
|
133
|
+
const deployed = parseVersionComment(active?.comment);
|
|
134
|
+
if (active != null && deployed?.fingerprint === fingerprint) {
|
|
135
|
+
console.log(`✅ The active version ${active.number} already has this app (fingerprint ${fingerprint}). Nothing to deploy. Use --force to deploy anyway.`);
|
|
136
|
+
setJsonResult({
|
|
137
|
+
deployed: false,
|
|
138
|
+
reason: 'up-to-date',
|
|
139
|
+
serviceId,
|
|
140
|
+
version: active.number,
|
|
141
|
+
domain: (await getVersionDomains(context, serviceId, active.number))[0] ?? null,
|
|
142
|
+
fingerprint,
|
|
143
|
+
staticPublishVersion,
|
|
144
|
+
});
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const { appDir } = await prepareManagedApp(path.resolve(), project);
|
|
149
|
+
const build = runFastly(appDir, ['compute', 'build'], apiToken.apiToken);
|
|
150
|
+
if (build.error != null || build.status !== 0) {
|
|
151
|
+
fail('deploy-failed', `'fastly compute build' failed.`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const deployArgs = ['compute', 'deploy', '--comment', formatVersionComment(staticPublishVersion, fingerprint, comment)];
|
|
155
|
+
if (serviceId != null) {
|
|
156
|
+
deployArgs.push('--service-id', serviceId);
|
|
157
|
+
}
|
|
158
|
+
if (isNonInteractive()) {
|
|
159
|
+
deployArgs.push('--non-interactive');
|
|
160
|
+
}
|
|
161
|
+
const deploy = runFastly(appDir, deployArgs, apiToken.apiToken);
|
|
162
|
+
if (deploy.error != null || deploy.status !== 0) {
|
|
163
|
+
fail('deploy-failed', `'fastly compute deploy' failed.`);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// After the first deploy, the Fastly CLI has written service_id into fastly.toml.
|
|
167
|
+
serviceId ??= readServiceId(path.resolve(appDir, 'fastly.toml')) ?? null;
|
|
168
|
+
if (serviceId == null) {
|
|
169
|
+
fail('deploy-failed', 'The deploy finished, but the Service ID is not known.');
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (project.managed.serviceId == null) {
|
|
173
|
+
const projectFilePath = path.resolve(PROJECT_FILE_NAME);
|
|
174
|
+
const updated = writeBackServiceId(fs.readFileSync(projectFilePath, 'utf-8'), serviceId);
|
|
175
|
+
if (updated != null) {
|
|
176
|
+
fs.writeFileSync(projectFilePath, updated, 'utf-8');
|
|
177
|
+
console.log(`✔️ Wrote managed.serviceId "${serviceId}" into ${PROJECT_FILE_NAME}. Commit it.`);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
console.log(`⚠️ Set managed.serviceId to "${serviceId}" in ${PROJECT_FILE_NAME}. (The line 'serviceId: undefined,' was not found, so the CLI did not change the file.)`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const active = await getActiveVersion(context, serviceId);
|
|
184
|
+
const domain = active != null ? (await getVersionDomains(context, serviceId, active.number))[0] ?? null : null;
|
|
185
|
+
console.log(`🎉 Deployed ${serviceId}${active != null ? ` version ${active.number}` : ''}${domain != null ? ` (https://${domain}/)` : ''}.`);
|
|
186
|
+
setJsonResult({
|
|
187
|
+
deployed: true,
|
|
188
|
+
serviceId,
|
|
189
|
+
version: active?.number ?? null,
|
|
190
|
+
domain,
|
|
191
|
+
fingerprint,
|
|
192
|
+
staticPublishVersion,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/dev.ts"],"names":[],"mappings":"AAgDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAwChD"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { prepareManagedApp } from '../../managed/app.js';
|
|
7
|
+
import { parseCommandLine } from '../../util/args.js';
|
|
8
|
+
import { fail, recordFailure } from '../../util/output.js';
|
|
9
|
+
import { checkVersionForCommand, loadManagedProject, showTemplateFolderHint } from '../../managed/command-helpers.js';
|
|
10
|
+
import { PROJECT_FILE_NAME } from '../../../models/config/static-publish-project.js';
|
|
11
|
+
import { serveApp } from '../run-dev-watch.js';
|
|
12
|
+
import { cliCommand } from '../../util/package.js';
|
|
13
|
+
function help() {
|
|
14
|
+
console.log(`\
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
${cliCommand()} dev [-- <options of fastly compute serve>]
|
|
18
|
+
|
|
19
|
+
Description:
|
|
20
|
+
Runs the app of a managed project on your computer. Generates the app in
|
|
21
|
+
.static-publish/app from ${PROJECT_FILE_NAME}, installs its dependencies
|
|
22
|
+
if they changed, and runs 'fastly compute serve' in it.
|
|
23
|
+
|
|
24
|
+
The app serves the content of the local KV Store. To publish content to it,
|
|
25
|
+
run 'publish-content --local' first.
|
|
26
|
+
|
|
27
|
+
Only in a managed project. In an ejected app, run 'npm run dev:start', or
|
|
28
|
+
'npm run dev:watch' (fastly compute serve --watch).
|
|
29
|
+
|
|
30
|
+
Options:
|
|
31
|
+
--auto-upgrade If the CLI is newer than managed.staticPublishVersion,
|
|
32
|
+
set it to the version that runs, and continue.
|
|
33
|
+
-- <options> Options after -- go to 'fastly compute serve',
|
|
34
|
+
for example: dev -- --addr=127.0.0.1:8080
|
|
35
|
+
With -- --watch, a change in the app builds and
|
|
36
|
+
restarts it. If the template has a watch script,
|
|
37
|
+
it runs next to 'fastly compute serve'.
|
|
38
|
+
|
|
39
|
+
Global Options:
|
|
40
|
+
-h, --help Show this help message and exit.
|
|
41
|
+
`);
|
|
42
|
+
}
|
|
43
|
+
export async function action(actionArgs) {
|
|
44
|
+
// Options after -- go to fastly compute serve.
|
|
45
|
+
const separator = actionArgs.indexOf('--');
|
|
46
|
+
const serveArgs = separator === -1 ? [] : actionArgs.slice(separator + 1);
|
|
47
|
+
const ownArgs = separator === -1 ? actionArgs : actionArgs.slice(0, separator);
|
|
48
|
+
const optionDefinitions = [
|
|
49
|
+
{ name: 'auto-upgrade', type: Boolean },
|
|
50
|
+
];
|
|
51
|
+
const parsed = parseCommandLine(ownArgs, optionDefinitions);
|
|
52
|
+
if (parsed.needHelp) {
|
|
53
|
+
if (parsed.error != null) {
|
|
54
|
+
console.error(String(parsed.error));
|
|
55
|
+
console.error();
|
|
56
|
+
recordFailure('usage', String(parsed.error));
|
|
57
|
+
}
|
|
58
|
+
help();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const project = await loadManagedProject('dev', `In an ejected app, run 'npm run dev:start'.`);
|
|
62
|
+
if (project == null) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
showTemplateFolderHint(project);
|
|
66
|
+
if (!checkVersionForCommand(project, parsed.commandLineOptions['auto-upgrade'] === true)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const { appDir } = await prepareManagedApp(path.resolve(), project);
|
|
70
|
+
const result = await serveApp(appDir, serveArgs);
|
|
71
|
+
if (result.error != null) {
|
|
72
|
+
fail('failed', `Could not run 'fastly compute serve': ${String(result.error)}`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (result.status !== 0 && result.signal == null) {
|
|
76
|
+
fail('failed', `'fastly compute serve' exited with ${result.status}.`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eject.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/eject.ts"],"names":[],"mappings":"AA+DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAoHhD"}
|