@fastly/compute-js-static-publish 7.0.0-beta.1 → 7.0.0-beta.3
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/README.md +11 -3
- package/README.short.md +11 -3
- package/build/cli/commands/manage/clean.d.ts +2 -0
- package/build/cli/commands/manage/clean.d.ts.map +1 -0
- package/build/cli/commands/manage/clean.js +277 -0
- package/build/cli/commands/manage/collections/delete.d.ts +2 -0
- package/build/cli/commands/manage/collections/delete.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/delete.js +180 -0
- package/build/cli/commands/manage/collections/index.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/index.js +63 -0
- package/build/cli/commands/manage/collections/list.d.ts +2 -0
- package/build/cli/commands/manage/collections/list.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/list.js +191 -0
- package/build/cli/commands/manage/collections/promote.d.ts +2 -0
- package/build/cli/commands/manage/collections/promote.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/promote.js +247 -0
- package/build/cli/commands/manage/collections/update-expiration.d.ts +2 -0
- package/build/cli/commands/manage/collections/update-expiration.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/update-expiration.js +215 -0
- package/build/cli/commands/manage/index.d.ts.map +1 -0
- package/build/cli/commands/{index.js → manage/index.js} +36 -34
- package/build/cli/commands/manage/publish-content.d.ts +2 -0
- package/build/cli/commands/manage/publish-content.d.ts.map +1 -0
- package/build/cli/commands/{publish-content.js → manage/publish-content.js} +186 -85
- package/build/cli/commands/{init-app.d.ts → scaffold/index.d.ts} +2 -2
- package/build/cli/commands/scaffold/index.d.ts.map +1 -0
- package/build/cli/commands/{init-app.js → scaffold/index.js} +80 -31
- package/build/cli/index.js +11 -3
- package/build/cli/util/api-token.d.ts.map +1 -0
- package/build/cli/{fastly-api → util}/api-token.js +8 -2
- package/build/cli/util/args.d.ts +16 -2
- package/build/cli/util/args.d.ts.map +1 -1
- package/build/cli/util/args.js +32 -6
- package/build/cli/util/config.d.ts.map +1 -1
- package/build/cli/util/config.js +19 -19
- package/build/cli/util/fastly-toml.d.ts +2 -0
- package/build/cli/util/fastly-toml.d.ts.map +1 -0
- package/build/cli/util/fastly-toml.js +15 -0
- package/build/cli/util/kv-store-items.d.ts +3 -2
- package/build/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/util/kv-store-items.js +7 -13
- package/build/cli/util/kv-store-local-server.d.ts +8 -0
- package/build/cli/util/kv-store-local-server.d.ts.map +1 -1
- package/build/cli/util/kv-store-local-server.js +76 -0
- package/build/cli/{fastly-api → util}/kv-store.d.ts +6 -6
- package/build/cli/util/kv-store.d.ts.map +1 -0
- package/build/cli/{fastly-api → util}/kv-store.js +4 -4
- package/build/cli/util/node.d.ts +2 -0
- package/build/cli/util/node.d.ts.map +1 -0
- package/build/cli/util/node.js +10 -0
- package/build/models/config/publish-content-config.d.ts +0 -2
- package/build/models/config/publish-content-config.d.ts.map +1 -1
- package/build/models/config/static-publish-rc.d.ts +1 -0
- package/build/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/models/server/index.d.ts +5 -0
- package/build/models/server/index.d.ts.map +1 -0
- package/build/models/server/index.js +1 -0
- package/build/models/time/index.d.ts +8 -0
- package/build/models/time/index.d.ts.map +1 -0
- package/build/models/time/index.js +54 -0
- package/build/server/publisher-server/index.d.ts +2 -0
- package/build/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/publisher-server/index.js +34 -3
- package/package.json +3 -2
- package/build/cli/commands/clean.d.ts +0 -2
- package/build/cli/commands/clean.d.ts.map +0 -1
- package/build/cli/commands/clean.js +0 -121
- package/build/cli/commands/collections/delete.d.ts +0 -2
- package/build/cli/commands/collections/delete.d.ts.map +0 -1
- package/build/cli/commands/collections/delete.js +0 -88
- package/build/cli/commands/collections/index.d.ts.map +0 -1
- package/build/cli/commands/collections/index.js +0 -52
- package/build/cli/commands/collections/list.d.ts +0 -2
- package/build/cli/commands/collections/list.d.ts.map +0 -1
- package/build/cli/commands/collections/list.js +0 -62
- package/build/cli/commands/index.d.ts.map +0 -1
- package/build/cli/commands/init-app.d.ts.map +0 -1
- package/build/cli/commands/publish-content.d.ts +0 -2
- package/build/cli/commands/publish-content.d.ts.map +0 -1
- package/build/cli/fastly-api/api-token.d.ts.map +0 -1
- package/build/cli/fastly-api/kv-store.d.ts.map +0 -1
- /package/build/cli/commands/{collections → manage/collections}/index.d.ts +0 -0
- /package/build/cli/commands/{index.d.ts → manage/index.d.ts} +0 -0
- /package/build/cli/{fastly-api → util}/api-token.d.ts +0 -0
|
@@ -2,34 +2,10 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
9
|
-
import * as collections from './collections/index.js';
|
|
10
|
-
export async function action(actionArgs) {
|
|
11
|
-
if (!fs.existsSync('./static-publish.rc.js')) {
|
|
12
|
-
await initApp.action(actionArgs);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const modes = {
|
|
16
|
-
'publish-content': publishContent,
|
|
17
|
-
'collections': collections,
|
|
18
|
-
};
|
|
19
|
-
const commandAndArgs = getCommandAndArgs(actionArgs, Object.keys(modes));
|
|
20
|
-
if (commandAndArgs.needHelp) {
|
|
21
|
-
if (commandAndArgs.command != null) {
|
|
22
|
-
console.error(`Unknown command: ${commandAndArgs.command}`);
|
|
23
|
-
console.error(`Specify one of: ${Object.keys(modes).join(', ')}`);
|
|
24
|
-
console.error();
|
|
25
|
-
process.exitCode = 1;
|
|
26
|
-
}
|
|
27
|
-
help();
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const { command, argv, } = commandAndArgs;
|
|
31
|
-
await modes[command].action(argv);
|
|
32
|
-
}
|
|
5
|
+
import { getCommandAndArgs } from '../../util/args.js';
|
|
6
|
+
import * as cleanCommand from './clean.js';
|
|
7
|
+
import * as publishContentCommand from './publish-content.js';
|
|
8
|
+
import * as collectionsCommands from './collections/index.js';
|
|
33
9
|
function help() {
|
|
34
10
|
console.log(`\
|
|
35
11
|
|
|
@@ -38,7 +14,8 @@ Usage:
|
|
|
38
14
|
|
|
39
15
|
Description:
|
|
40
16
|
Manage and publish static content to Fastly Compute using KV Store-backed collections.
|
|
41
|
-
|
|
17
|
+
|
|
18
|
+
Note: If run outside a scaffolded project, this tool will automatically enter scaffolding mode.
|
|
42
19
|
|
|
43
20
|
Available Commands:
|
|
44
21
|
publish-content Publish static files to the KV Store under a named collection
|
|
@@ -49,19 +26,44 @@ Available Commands:
|
|
|
49
26
|
collections update-expiration Modify expiration time for an existing collection
|
|
50
27
|
|
|
51
28
|
Global Options:
|
|
52
|
-
--
|
|
53
|
-
|
|
29
|
+
--local Instead of working with the Fastly KV Store, operate on
|
|
30
|
+
local files that will be used to simulate the KV Store
|
|
31
|
+
with the local development environment.
|
|
32
|
+
|
|
33
|
+
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
34
|
+
If not set, the tool will check:
|
|
54
35
|
1. FASTLY_API_TOKEN environment variable
|
|
55
|
-
2.
|
|
56
|
-
|
|
36
|
+
2. Logged-in Fastly CLI profile
|
|
37
|
+
|
|
38
|
+
-h, --help Show this help message and exit.
|
|
57
39
|
|
|
58
40
|
Automatic Project Initialization:
|
|
59
41
|
If run in a directory that does not contain a \`static-publish.rc.js\` file, this tool will scaffold a new
|
|
60
42
|
Compute application for you, including Fastly configuration, default routes, and publishing setup.
|
|
61
43
|
|
|
62
44
|
Examples:
|
|
63
|
-
npx @fastly/compute-js-static-publish publish-content --collection-name
|
|
45
|
+
npx @fastly/compute-js-static-publish publish-content --collection-name=live
|
|
64
46
|
npx @fastly/compute-js-static-publish collections list
|
|
65
47
|
npx @fastly/compute-js-static-publish clean --dry-run
|
|
66
48
|
`);
|
|
67
49
|
}
|
|
50
|
+
export async function action(actionArgs) {
|
|
51
|
+
const modes = {
|
|
52
|
+
'clean': cleanCommand,
|
|
53
|
+
'publish-content': publishContentCommand,
|
|
54
|
+
'collections': collectionsCommands,
|
|
55
|
+
};
|
|
56
|
+
const commandAndArgs = getCommandAndArgs(actionArgs, modes);
|
|
57
|
+
if (commandAndArgs.needHelp) {
|
|
58
|
+
if (commandAndArgs.command != null) {
|
|
59
|
+
console.error(`Unknown command: ${commandAndArgs.command}`);
|
|
60
|
+
console.error(`Specify one of: ${Object.keys(modes).join(', ')}`);
|
|
61
|
+
console.error();
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
}
|
|
64
|
+
help();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const { command, argv, } = commandAndArgs;
|
|
68
|
+
await modes[command].action(argv);
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AAsGA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA+kBhD"}
|
|
@@ -4,63 +4,141 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import * as fs from 'node:fs';
|
|
6
6
|
import * as path from 'node:path';
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { getKvStoreEntryInfo } from '
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
7
|
+
import { isKVAssetVariantMetadata } from '../../../models/assets/kvstore-assets.js';
|
|
8
|
+
import { calcExpirationTime } from '../../../models/time/index.js';
|
|
9
|
+
import { loadApiToken } from '../../util/api-token.js';
|
|
10
|
+
import { getKvStoreEntryInfo, kvStoreSubmitEntry } from '../../util/kv-store.js';
|
|
11
|
+
import { parseCommandLine } from '../../util/args.js';
|
|
12
|
+
import { mergeContentTypes, testFileContentType } from '../../util/content-types.js';
|
|
13
|
+
import { LoadConfigError, loadPublishContentConfigFile, loadStaticPublisherRcFile } from '../../util/config.js';
|
|
14
|
+
import { applyDefaults } from '../../util/data.js';
|
|
15
|
+
import { readServiceId } from '../../util/fastly-toml.js';
|
|
16
|
+
import { calculateFileSizeAndHash, enumerateFiles, getFileSize, rootRelative } from '../../util/files.js';
|
|
17
|
+
import { applyKVStoreEntriesChunks, doKvStoreItemsOperation, } from '../../util/kv-store-items.js';
|
|
18
|
+
import { writeKVStoreEntriesForLocal } from '../../util/kv-store-local-server.js';
|
|
19
|
+
import { isNodeError } from '../../util/node.js';
|
|
20
|
+
import { ensureVariantFileExists } from '../../util/variants.js';
|
|
19
21
|
// KV Store key format:
|
|
20
22
|
// <publishId>_index_<preview_id>.json
|
|
21
23
|
// <publishId>_settings_<preview_id>.json
|
|
22
24
|
// <publishId>_files_sha256_<hash>_<variant>
|
|
23
25
|
// split large files into 20MiB chunks
|
|
24
26
|
const KV_STORE_CHUNK_SIZE = 1024 * 1024 * 20;
|
|
25
|
-
|
|
27
|
+
function help() {
|
|
28
|
+
console.log(`\
|
|
29
|
+
|
|
30
|
+
Usage:
|
|
31
|
+
npx @fastly/compute-js-static-publish publish-content [--collection-name=<name>] [options]
|
|
32
|
+
|
|
33
|
+
Description:
|
|
34
|
+
Publishes static files from your local root directory into a named collection,
|
|
35
|
+
either in the Fastly KV Store (default) or to a local dev directory (--local).
|
|
36
|
+
Files that already exist with the same hash are skipped automatically.
|
|
37
|
+
|
|
38
|
+
After this process is complete, the PublisherServer object in the Compute application
|
|
39
|
+
will see the updated index of files and updated server settings from the
|
|
40
|
+
publish-content.config.js file.
|
|
41
|
+
|
|
42
|
+
Optional:
|
|
43
|
+
--collection-name=<name> Name of the collection to publish into.
|
|
44
|
+
Default: value from static-publisher.rc.js (defaultCollectionName)
|
|
45
|
+
|
|
46
|
+
--config=<file> Path to a publish-content.config.js file.
|
|
47
|
+
Default: ./publish-content.config.js
|
|
48
|
+
|
|
49
|
+
--root-dir=<dir> Directory to publish from. Overrides the config file setting.
|
|
50
|
+
Default: rootDir from publish-content.config.js
|
|
51
|
+
|
|
52
|
+
--kv-overwrite Cannot be used with --local.
|
|
53
|
+
When using Fastly KV Store, always overwrite
|
|
54
|
+
existing entries, even if unchanged.
|
|
55
|
+
|
|
56
|
+
Expiration:
|
|
57
|
+
--expires-in=<duration> Expiration duration from now.
|
|
58
|
+
Examples: 3d, 12h, 15m, 1w
|
|
59
|
+
|
|
60
|
+
--expires-at=<timestamp> Absolute expiration in ISO 8601 format.
|
|
61
|
+
Example: 2025-05-01T00:00:00Z
|
|
62
|
+
|
|
63
|
+
--expires-never Prevent this collection from expiring.
|
|
64
|
+
|
|
65
|
+
⚠ These three options are mutually exclusive.
|
|
66
|
+
Specify only one.
|
|
67
|
+
|
|
68
|
+
Global Options:
|
|
69
|
+
--local Instead of working with the Fastly KV Store, operate on
|
|
70
|
+
local files that will be used to simulate the KV Store
|
|
71
|
+
with the local development environment.
|
|
72
|
+
|
|
73
|
+
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
74
|
+
If not set, the tool will check:
|
|
75
|
+
1. FASTLY_API_TOKEN environment variable
|
|
76
|
+
2. Logged-in Fastly CLI profile
|
|
77
|
+
|
|
78
|
+
-h, --help Show this help message and exit.
|
|
79
|
+
|
|
80
|
+
Examples:
|
|
81
|
+
npx @fastly/compute-js-static-publish publish-content --collection-name=preview-456
|
|
82
|
+
npx @fastly/compute-js-static-publish publish-content --expires-in=7d --kv-overwrite
|
|
83
|
+
npx @fastly/compute-js-static-publish publish-content --expires-never --local
|
|
84
|
+
|
|
85
|
+
`);
|
|
86
|
+
}
|
|
87
|
+
export async function action(actionArgs) {
|
|
26
88
|
const optionDefinitions = [
|
|
27
|
-
{ name: 'verbose', type: Boolean
|
|
28
|
-
|
|
29
|
-
{ name: 'fastly-api-token', type: String, },
|
|
30
|
-
// Collection name to be used for this publishing.
|
|
89
|
+
{ name: 'verbose', type: Boolean },
|
|
90
|
+
{ name: 'config', type: String },
|
|
31
91
|
{ name: 'collection-name', type: String, },
|
|
32
|
-
// The 'root' directory for the publishing.
|
|
33
|
-
// All assets are expected to exist under this root. Required.
|
|
34
|
-
// For backwards compatibility, if this value is not provided,
|
|
35
|
-
// then the value of 'public-dir' is used.
|
|
36
92
|
{ name: 'root-dir', type: String, },
|
|
37
|
-
{ name: '
|
|
38
|
-
{ name: '
|
|
39
|
-
{ name: '
|
|
40
|
-
{ name: '
|
|
93
|
+
{ name: 'kv-overwrite', type: Boolean },
|
|
94
|
+
{ name: 'expires-in', type: String },
|
|
95
|
+
{ name: 'expires-at', type: String },
|
|
96
|
+
{ name: 'expires-never', type: Boolean },
|
|
97
|
+
{ name: 'local', type: Boolean },
|
|
98
|
+
{ name: 'fastly-api-token', type: String, },
|
|
41
99
|
];
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
100
|
+
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
101
|
+
if (parsed.needHelp) {
|
|
102
|
+
if (parsed.error != null) {
|
|
103
|
+
console.error(String(parsed.error));
|
|
104
|
+
console.error();
|
|
105
|
+
process.exitCode = 1;
|
|
106
|
+
}
|
|
107
|
+
help();
|
|
48
108
|
return;
|
|
49
109
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
//
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
110
|
+
const { verbose, config: configFilePathValue, ['collection-name']: collectionNameValue, ['root-dir']: rootDir, ['kv-overwrite']: overwriteKvStoreItems, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
111
|
+
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
112
|
+
// in other words, the directory that contains `fastly.toml`.
|
|
113
|
+
const computeAppDir = path.resolve();
|
|
114
|
+
// Check to see if we have a service ID listed in `fastly.toml`.
|
|
115
|
+
// If we do NOT, then we do not use the KV Store.
|
|
116
|
+
let serviceId;
|
|
117
|
+
try {
|
|
118
|
+
serviceId = readServiceId(path.resolve(computeAppDir, './fastly.toml'));
|
|
57
119
|
}
|
|
58
|
-
|
|
59
|
-
|
|
120
|
+
catch (err) {
|
|
121
|
+
if (isNodeError(err) && err.code === 'ENOENT') {
|
|
122
|
+
console.warn(`❌ ERROR: can't find 'fastly.toml'.`);
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
console.warn(`❌ ERROR: can't read or parse 'fastly.toml'.`);
|
|
127
|
+
process.exitCode = 1;
|
|
128
|
+
return;
|
|
60
129
|
}
|
|
61
|
-
console.log(`🚀 Publishing content
|
|
130
|
+
console.log(`🚀 Publishing content...`);
|
|
131
|
+
// Verify targets
|
|
62
132
|
let fastlyApiContext = undefined;
|
|
63
|
-
if (
|
|
133
|
+
if (localMode) {
|
|
134
|
+
console.log(` Working on local simulated KV Store...`);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
if (serviceId === null) {
|
|
138
|
+
console.log(`❌️ 'service_id' not set in 'fastly.toml' - Deploy your Compute app to Fastly before publishing.`);
|
|
139
|
+
process.exitCode = 1;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
64
142
|
const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
|
|
65
143
|
if (apiTokenResult == null) {
|
|
66
144
|
console.error("❌ Fastly API Token not provided.");
|
|
@@ -70,10 +148,8 @@ export async function action(argv) {
|
|
|
70
148
|
}
|
|
71
149
|
fastlyApiContext = { apiToken: apiTokenResult.apiToken };
|
|
72
150
|
console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
151
|
+
console.log(` Working on the Fastly KV Store...`);
|
|
73
152
|
}
|
|
74
|
-
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
75
|
-
// in other words, the directory that contains `fastly.toml`.
|
|
76
|
-
const computeAppDir = path.resolve();
|
|
77
153
|
// #### load config
|
|
78
154
|
let staticPublisherRc;
|
|
79
155
|
try {
|
|
@@ -113,15 +189,26 @@ export async function action(argv) {
|
|
|
113
189
|
console.log(`files to be included in your published output.`);
|
|
114
190
|
}
|
|
115
191
|
}
|
|
192
|
+
let expirationTime;
|
|
193
|
+
try {
|
|
194
|
+
expirationTime = calcExpirationTime({ expiresIn, expiresAt, expiresNever });
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
console.error(`❌ Cannot process expiration time`);
|
|
198
|
+
console.error(String(err));
|
|
199
|
+
process.exitCode = 1;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
116
202
|
console.log(`✔️ Public directory '${rootRelative(publicDirRoot)}'.`);
|
|
117
203
|
const publishId = staticPublisherRc.publishId;
|
|
118
|
-
console.log(
|
|
204
|
+
console.log(` | Publish ID: ${publishId}`);
|
|
119
205
|
const kvStoreName = staticPublisherRc.kvStoreName;
|
|
120
|
-
console.log(
|
|
206
|
+
console.log(` | Using KV Store: ${kvStoreName}`);
|
|
121
207
|
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
122
|
-
console.log(
|
|
123
|
-
|
|
124
|
-
|
|
208
|
+
console.log(` | Default Collection Name: ${defaultCollectionName}`);
|
|
209
|
+
const staticPublisherWorkingDir = staticPublisherRc.staticPublisherWorkingDir;
|
|
210
|
+
console.log(` | Static publisher working directory: ${staticPublisherWorkingDir}`);
|
|
211
|
+
const storeFile = path.resolve(staticPublisherWorkingDir, `./kvstore.json`);
|
|
125
212
|
// Load content types
|
|
126
213
|
const contentTypes = mergeContentTypes(publishContentConfig.contentTypes);
|
|
127
214
|
// #### Collect all file paths
|
|
@@ -143,6 +230,26 @@ export async function action(argv) {
|
|
|
143
230
|
if (includeWellKnown) {
|
|
144
231
|
console.log(`✔️ (.well-known is exempt from exclusion.)`);
|
|
145
232
|
}
|
|
233
|
+
// ### Collection name that we're currently publishing
|
|
234
|
+
// for example, live, staging
|
|
235
|
+
const collectionName = collectionNameValue ?? process.env.PUBLISHER_COLLECTION_NAME ?? defaultCollectionName;
|
|
236
|
+
console.log(`✔️ Collection Name: ${collectionName}`);
|
|
237
|
+
if (expirationTime != null) {
|
|
238
|
+
console.log(`✔️ Publishing with expiration timestamp: ${new Date(expirationTime * 1000).toISOString()}`);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
console.log(`✔️ Publishing with no expiration timestamp.`);
|
|
242
|
+
}
|
|
243
|
+
if (expirationTime == null) {
|
|
244
|
+
// includes null and undefined
|
|
245
|
+
console.log(`✔️ Publishing with no expiration timestamp.`);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
console.log(`✔️ Updating expiration timestamp: ${new Date(expirationTime * 1000).toISOString()}`);
|
|
249
|
+
}
|
|
250
|
+
if (collectionName === defaultCollectionName && expirationTime !== undefined) {
|
|
251
|
+
console.log(` ⚠️ NOTE: Expiration time not enforced for default collection.`);
|
|
252
|
+
}
|
|
146
253
|
// files to be included in the build/publish
|
|
147
254
|
const files = enumerateFiles({
|
|
148
255
|
publicDirRoot,
|
|
@@ -150,9 +257,6 @@ export async function action(argv) {
|
|
|
150
257
|
excludeDotFiles,
|
|
151
258
|
includeWellKnown,
|
|
152
259
|
});
|
|
153
|
-
// ### Collection name that we're currently publishing
|
|
154
|
-
// for example, live, staging
|
|
155
|
-
const collectionName = collectionNameValue ?? process.env.PUBLISHER_COLLECTION_NAME ?? defaultCollectionName;
|
|
156
260
|
const stats = {
|
|
157
261
|
kvStore: 0,
|
|
158
262
|
};
|
|
@@ -230,8 +334,11 @@ export async function action(argv) {
|
|
|
230
334
|
}
|
|
231
335
|
else {
|
|
232
336
|
let kvStoreItemMetadata = null;
|
|
233
|
-
if (
|
|
234
|
-
|
|
337
|
+
if (!localMode && !overwriteKvStoreItems) {
|
|
338
|
+
const items = [{
|
|
339
|
+
key: variantKey,
|
|
340
|
+
}];
|
|
341
|
+
await doKvStoreItemsOperation(items, async (_, variantKey) => {
|
|
235
342
|
// fastlyApiContext is non-null if useKvStore is true
|
|
236
343
|
const kvStoreEntryInfo = await getKvStoreEntryInfo(fastlyApiContext, kvStoreName, variantKey);
|
|
237
344
|
if (!kvStoreEntryInfo) {
|
|
@@ -275,22 +382,6 @@ export async function action(argv) {
|
|
|
275
382
|
};
|
|
276
383
|
}
|
|
277
384
|
}
|
|
278
|
-
}, {
|
|
279
|
-
onAttempt(attempt) {
|
|
280
|
-
if (attempt > 0) {
|
|
281
|
-
console.log(`Attempt ${attempt + 1} for: ${variantKey}`);
|
|
282
|
-
}
|
|
283
|
-
},
|
|
284
|
-
onRetry(attempt, err, delay) {
|
|
285
|
-
let statusMessage = 'unknown';
|
|
286
|
-
if (err instanceof FetchError) {
|
|
287
|
-
statusMessage = `HTTP ${err.status}`;
|
|
288
|
-
}
|
|
289
|
-
else if (err instanceof TypeError) {
|
|
290
|
-
statusMessage = 'transport';
|
|
291
|
-
}
|
|
292
|
-
console.log(`Attempt ${attempt + 1} for ${variantKey} gave retryable error (${statusMessage}), delaying ${delay} ms`);
|
|
293
|
-
},
|
|
294
385
|
});
|
|
295
386
|
}
|
|
296
387
|
if (kvStoreItemMetadata != null) {
|
|
@@ -306,7 +397,7 @@ export async function action(argv) {
|
|
|
306
397
|
}
|
|
307
398
|
else {
|
|
308
399
|
await ensureVariantFileExists(variantFilePath, variant, file);
|
|
309
|
-
if (
|
|
400
|
+
if (!localMode) {
|
|
310
401
|
console.log(` ・ Flagging asset for upload to KV Store with key "${variantKey}".`);
|
|
311
402
|
}
|
|
312
403
|
let contentEncoding, hash, size;
|
|
@@ -341,8 +432,8 @@ export async function action(argv) {
|
|
|
341
432
|
numChunks: variantMetadata.numChunks,
|
|
342
433
|
},
|
|
343
434
|
});
|
|
344
|
-
if (
|
|
345
|
-
// Although we already know the size and hash of the
|
|
435
|
+
if (localMode) {
|
|
436
|
+
// Although we already know the size and hash of the variant, the local server
|
|
346
437
|
// needs a copy of the file so we create it if it doesn't exist.
|
|
347
438
|
// This may happen for example if files were uploaded to the KV Store in a previous
|
|
348
439
|
// publishing, but local static content files have been removed since.
|
|
@@ -365,21 +456,28 @@ export async function action(argv) {
|
|
|
365
456
|
};
|
|
366
457
|
}
|
|
367
458
|
console.log(`✅ Scan complete.`);
|
|
459
|
+
// TODO: fix this bug:
|
|
460
|
+
// Technically it's a bug to WRITE the index and settings json files to the
|
|
461
|
+
// staticPublisherKvStoreContent dir when target === 'fastly'.
|
|
462
|
+
// For these files we should not be creating the files using
|
|
463
|
+
// kvStoreItemDescriptions, but rather creating them directly.
|
|
368
464
|
// #### INDEX FILE
|
|
369
465
|
console.log(`🗂️ Creating Index...`);
|
|
370
466
|
const indexFileName = `index_${collectionName}.json`;
|
|
371
467
|
const indexFileKey = `${publishId}_index_${collectionName}`;
|
|
372
|
-
// Metadata can have build time, expiration date, build name
|
|
373
|
-
// const indexMetadata = {};
|
|
374
468
|
const indexFilePath = path.resolve(staticPublisherKvStoreContent, indexFileName);
|
|
375
469
|
fs.writeFileSync(indexFilePath, JSON.stringify(kvAssetsIndex));
|
|
376
470
|
const indexFileSize = getFileSize(indexFilePath);
|
|
471
|
+
const indexMetadata = {
|
|
472
|
+
publishedTime: Math.floor(Date.now() / 1000),
|
|
473
|
+
expirationTime: expirationTime ?? undefined,
|
|
474
|
+
};
|
|
377
475
|
kvStoreItemDescriptions.push({
|
|
378
476
|
write: true,
|
|
379
477
|
size: indexFileSize,
|
|
380
478
|
key: indexFileKey,
|
|
381
479
|
filePath: indexFilePath,
|
|
382
|
-
|
|
480
|
+
metadataJson: indexMetadata,
|
|
383
481
|
});
|
|
384
482
|
console.log(`✅ Index has been saved.`);
|
|
385
483
|
// #### SERVER SETTINGS
|
|
@@ -456,17 +554,20 @@ export async function action(argv) {
|
|
|
456
554
|
console.log(`🍪 Chunking large files...`);
|
|
457
555
|
await applyKVStoreEntriesChunks(kvStoreItemDescriptions, KV_STORE_CHUNK_SIZE);
|
|
458
556
|
console.log(`✅ Large files have been chunked.`);
|
|
459
|
-
if (
|
|
460
|
-
console.log(`📤 Uploading entries to KV Store.`);
|
|
461
|
-
// fastlyApiContext is non-null if useKvStore is true
|
|
462
|
-
await uploadFilesToKVStore(fastlyApiContext, kvStoreName, kvStoreItemDescriptions);
|
|
463
|
-
console.log(`✅ Uploaded entries to KV Store.`);
|
|
464
|
-
}
|
|
465
|
-
if (createLocalFiles) {
|
|
557
|
+
if (localMode) {
|
|
466
558
|
console.log(`📝 Writing local server KV Store entries.`);
|
|
467
|
-
const storeFile = path.resolve(staticPublisherWorkingDir, `./kvstore.json`);
|
|
468
559
|
writeKVStoreEntriesForLocal(storeFile, computeAppDir, kvStoreItemDescriptions);
|
|
469
560
|
console.log(`✅ Wrote KV Store entries for local server.`);
|
|
470
561
|
}
|
|
562
|
+
else {
|
|
563
|
+
console.log(`📤 Uploading entries to KV Store.`);
|
|
564
|
+
// fastlyApiContext is non-null if useKvStore is true
|
|
565
|
+
await doKvStoreItemsOperation(kvStoreItemDescriptions.filter(x => x.write), async ({ filePath, metadataJson }, key) => {
|
|
566
|
+
const fileBytes = fs.readFileSync(filePath);
|
|
567
|
+
await kvStoreSubmitEntry(fastlyApiContext, kvStoreName, key, fileBytes, metadataJson != null ? JSON.stringify(metadataJson) : undefined);
|
|
568
|
+
console.log(` 🌐 Submitted asset "${rootRelative(filePath)}" to KV Store with key "${key}".`);
|
|
569
|
+
});
|
|
570
|
+
console.log(`✅ Uploaded entries to KV Store.`);
|
|
571
|
+
}
|
|
471
572
|
console.log(`🎉 Completed.`);
|
|
472
573
|
}
|
|
@@ -15,5 +15,5 @@ export type InitAppOptions = {
|
|
|
15
15
|
publishId: string | undefined;
|
|
16
16
|
kvStoreName: string | undefined;
|
|
17
17
|
};
|
|
18
|
-
export declare function action(
|
|
19
|
-
//# sourceMappingURL=
|
|
18
|
+
export declare function action(actionArgs: string[]): Promise<void>;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AA2DA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC,CAAC;AA0QF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAwehD"}
|