@fastly/compute-js-static-publish 6.3.0 → 7.0.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/LICENSE +1 -1
- package/README.md +31 -586
- package/README.short.md +53 -0
- package/build/cli/commands/clean.d.ts +2 -0
- package/build/cli/commands/clean.d.ts.map +1 -0
- package/build/cli/commands/clean.js +121 -0
- package/build/cli/commands/collections/delete.d.ts +2 -0
- package/build/cli/commands/collections/delete.d.ts.map +1 -0
- package/build/cli/commands/collections/delete.js +88 -0
- package/build/cli/commands/collections/index.d.ts +2 -0
- package/build/cli/commands/collections/index.d.ts.map +1 -0
- package/build/cli/commands/collections/index.js +52 -0
- package/build/cli/commands/collections/list.d.ts +2 -0
- package/build/cli/commands/collections/list.d.ts.map +1 -0
- package/build/cli/commands/collections/list.js +62 -0
- package/build/cli/commands/index.d.ts +2 -0
- package/build/cli/commands/index.d.ts.map +1 -0
- package/build/cli/commands/index.js +67 -0
- package/build/cli/commands/init-app.d.ts +18 -2
- package/build/cli/commands/init-app.d.ts.map +1 -1
- package/build/cli/commands/init-app.js +299 -266
- package/build/cli/commands/publish-content.d.ts +2 -0
- package/build/cli/commands/publish-content.d.ts.map +1 -0
- package/build/cli/commands/publish-content.js +472 -0
- package/build/cli/compression/brotli.d.ts +1 -1
- package/build/cli/compression/brotli.d.ts.map +1 -1
- package/build/cli/compression/brotli.js +8 -11
- package/build/cli/compression/gzip.d.ts +1 -1
- package/build/cli/compression/gzip.d.ts.map +1 -1
- package/build/cli/compression/gzip.js +8 -11
- package/build/cli/compression/index.d.ts +3 -6
- package/build/cli/compression/index.d.ts.map +1 -1
- package/build/cli/compression/index.js +8 -9
- package/build/cli/fastly-api/api-token.d.ts +17 -0
- package/build/cli/fastly-api/api-token.d.ts.map +1 -0
- package/build/cli/fastly-api/api-token.js +94 -0
- package/build/cli/fastly-api/kv-store.d.ts +24 -0
- package/build/cli/fastly-api/kv-store.d.ts.map +1 -0
- package/build/cli/{util → fastly-api}/kv-store.js +42 -22
- package/build/cli/index.js +7 -91
- package/build/cli/util/args.d.ts +16 -0
- package/build/cli/util/args.d.ts.map +1 -0
- package/build/cli/util/args.js +55 -0
- package/build/cli/util/config.d.ts +13 -0
- package/build/cli/util/config.d.ts.map +1 -0
- package/build/cli/{load-config.js → util/config.js} +234 -187
- package/build/{util → cli/util}/content-types.d.ts +1 -2
- package/build/cli/util/content-types.d.ts.map +1 -0
- package/build/{util → cli/util}/content-types.js +11 -6
- package/build/cli/util/data.d.ts +3 -3
- package/build/cli/util/data.d.ts.map +1 -1
- package/build/cli/util/data.js +6 -2
- package/build/cli/util/files.d.ts +10 -2
- package/build/cli/util/files.d.ts.map +1 -1
- package/build/cli/util/files.js +53 -6
- package/build/cli/util/kv-store-items.d.ts +12 -0
- package/build/cli/util/kv-store-items.d.ts.map +1 -0
- package/build/cli/util/kv-store-items.js +161 -0
- package/build/cli/util/kv-store-local-server.d.ts +3 -0
- package/build/cli/util/kv-store-local-server.d.ts.map +1 -0
- package/build/cli/util/kv-store-local-server.js +35 -0
- package/build/cli/util/package.d.ts +9 -0
- package/build/cli/util/package.d.ts.map +1 -0
- package/build/cli/util/package.js +44 -0
- package/build/cli/util/retryable.d.ts +12 -0
- package/build/cli/util/retryable.d.ts.map +1 -0
- package/build/cli/util/retryable.js +43 -0
- package/build/cli/util/variants.d.ts +4 -0
- package/build/cli/util/variants.d.ts.map +1 -0
- package/build/cli/util/variants.js +27 -0
- package/build/index.d.ts +5 -5
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -6
- package/build/models/assets/kvstore-assets.d.ts +17 -0
- package/build/models/assets/kvstore-assets.d.ts.map +1 -0
- package/build/models/assets/kvstore-assets.js +28 -0
- package/build/{constants/compression.d.ts → models/compression/index.d.ts} +2 -1
- package/build/models/compression/index.d.ts.map +1 -0
- package/build/models/compression/index.js +11 -0
- package/build/models/config/publish-content-config.d.ts +41 -0
- package/build/models/config/publish-content-config.d.ts.map +1 -0
- package/build/models/config/publish-content-config.js +5 -0
- package/build/models/config/publisher-server-config.d.ts +20 -0
- package/build/models/config/publisher-server-config.d.ts.map +1 -0
- package/build/models/config/publisher-server-config.js +5 -0
- package/build/models/config/static-publish-rc.d.ts +6 -0
- package/build/models/config/static-publish-rc.d.ts.map +1 -0
- package/build/models/config/static-publish-rc.js +5 -0
- package/build/server/collection-selector/from-config-store.d.ts +2 -0
- package/build/server/collection-selector/from-config-store.d.ts.map +1 -0
- package/build/server/collection-selector/from-config-store.js +15 -0
- package/build/server/collection-selector/from-cookie.d.ts +23 -0
- package/build/server/collection-selector/from-cookie.d.ts.map +1 -0
- package/build/server/collection-selector/from-cookie.js +98 -0
- package/build/server/collection-selector/from-request.d.ts +13 -0
- package/build/server/collection-selector/from-request.d.ts.map +1 -0
- package/build/server/collection-selector/from-request.js +22 -0
- package/build/server/collection-selector/index.d.ts +5 -0
- package/build/server/collection-selector/index.d.ts.map +1 -0
- package/build/server/collection-selector/index.js +7 -0
- package/build/server/collection-selector/request-collection-selector.d.ts +5 -0
- package/build/server/collection-selector/request-collection-selector.d.ts.map +1 -0
- package/build/server/collection-selector/request-collection-selector.js +5 -0
- package/build/server/publisher-server/index.d.ts +38 -0
- package/build/server/publisher-server/index.d.ts.map +1 -0
- package/build/server/publisher-server/index.js +418 -0
- package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts +3 -0
- package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +1 -0
- package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-modified-since.js +6 -2
- package/build/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +1 -0
- package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-none-match.js +4 -0
- package/build/server/util/cookies.d.ts +2 -0
- package/build/server/util/cookies.d.ts.map +1 -0
- package/build/server/util/cookies.js +14 -0
- package/build/server/util/kv-store.d.ts +3 -0
- package/build/server/util/kv-store.d.ts.map +1 -0
- package/build/server/util/kv-store.js +95 -0
- package/package.json +18 -10
- package/build/cli/commands/build-static.d.ts +0 -3
- package/build/cli/commands/build-static.d.ts.map +0 -1
- package/build/cli/commands/build-static.js +0 -541
- package/build/cli/commands/clean-kv-store.d.ts +0 -3
- package/build/cli/commands/clean-kv-store.d.ts.map +0 -1
- package/build/cli/commands/clean-kv-store.js +0 -55
- package/build/cli/load-config.d.ts +0 -6
- package/build/cli/load-config.d.ts.map +0 -1
- package/build/cli/presets/implementations/astro.d.ts +0 -7
- package/build/cli/presets/implementations/astro.d.ts.map +0 -1
- package/build/cli/presets/implementations/astro.js +0 -23
- package/build/cli/presets/implementations/create-react-app.d.ts +0 -11
- package/build/cli/presets/implementations/create-react-app.d.ts.map +0 -1
- package/build/cli/presets/implementations/create-react-app.js +0 -34
- package/build/cli/presets/implementations/docusaurus.d.ts +0 -7
- package/build/cli/presets/implementations/docusaurus.d.ts.map +0 -1
- package/build/cli/presets/implementations/docusaurus.js +0 -13
- package/build/cli/presets/implementations/gatsby.d.ts +0 -7
- package/build/cli/presets/implementations/gatsby.d.ts.map +0 -1
- package/build/cli/presets/implementations/gatsby.js +0 -13
- package/build/cli/presets/implementations/next.d.ts +0 -7
- package/build/cli/presets/implementations/next.d.ts.map +0 -1
- package/build/cli/presets/implementations/next.js +0 -13
- package/build/cli/presets/implementations/sveltekit.d.ts +0 -7
- package/build/cli/presets/implementations/sveltekit.d.ts.map +0 -1
- package/build/cli/presets/implementations/sveltekit.js +0 -13
- package/build/cli/presets/implementations/vite.d.ts +0 -7
- package/build/cli/presets/implementations/vite.d.ts.map +0 -1
- package/build/cli/presets/implementations/vite.js +0 -13
- package/build/cli/presets/implementations/vue.d.ts +0 -7
- package/build/cli/presets/implementations/vue.d.ts.map +0 -1
- package/build/cli/presets/implementations/vue.js +0 -24
- package/build/cli/presets/index.d.ts +0 -3
- package/build/cli/presets/index.d.ts.map +0 -1
- package/build/cli/presets/index.js +0 -20
- package/build/cli/presets/preset-base.d.ts +0 -21
- package/build/cli/presets/preset-base.d.ts.map +0 -1
- package/build/cli/presets/preset-base.js +0 -1
- package/build/cli/util/fastly-api.d.ts +0 -10
- package/build/cli/util/fastly-api.d.ts.map +0 -1
- package/build/cli/util/fastly-api.js +0 -47
- package/build/cli/util/hash.d.ts +0 -5
- package/build/cli/util/hash.d.ts.map +0 -1
- package/build/cli/util/hash.js +0 -9
- package/build/cli/util/id.d.ts +0 -3
- package/build/cli/util/id.d.ts.map +0 -1
- package/build/cli/util/id.js +0 -17
- package/build/cli/util/kv-store.d.ts +0 -16
- package/build/cli/util/kv-store.d.ts.map +0 -1
- package/build/cli/util/publish-id.d.ts +0 -5
- package/build/cli/util/publish-id.d.ts.map +0 -1
- package/build/cli/util/publish-id.js +0 -26
- package/build/compute-js.d.ts +0 -3
- package/build/compute-js.d.ts.map +0 -1
- package/build/compute-js.js +0 -2
- package/build/constants/compression.d.ts.map +0 -1
- package/build/constants/compression.js +0 -4
- package/build/server/assets/asset-manager.d.ts +0 -8
- package/build/server/assets/asset-manager.d.ts.map +0 -1
- package/build/server/assets/asset-manager.js +0 -14
- package/build/server/assets/content-asset-kv-store.d.ts +0 -19
- package/build/server/assets/content-asset-kv-store.d.ts.map +0 -1
- package/build/server/assets/content-asset-kv-store.js +0 -70
- package/build/server/assets/content-asset-wasm-inline.d.ts +0 -18
- package/build/server/assets/content-asset-wasm-inline.d.ts.map +0 -1
- package/build/server/assets/content-asset-wasm-inline.js +0 -52
- package/build/server/assets/content-assets.d.ts +0 -46
- package/build/server/assets/content-assets.d.ts.map +0 -1
- package/build/server/assets/content-assets.js +0 -100
- package/build/server/assets/module-assets.d.ts +0 -23
- package/build/server/assets/module-assets.d.ts.map +0 -1
- package/build/server/assets/module-assets.js +0 -45
- package/build/server/kv-store/inline-store-entry.d.ts +0 -25
- package/build/server/kv-store/inline-store-entry.d.ts.map +0 -1
- package/build/server/kv-store/inline-store-entry.js +0 -100
- package/build/server/publisher-server.d.ts +0 -23
- package/build/server/publisher-server.d.ts.map +0 -1
- package/build/server/publisher-server.js +0 -257
- package/build/server/serve-preconditions/if-modified-since.d.ts +0 -4
- package/build/server/serve-preconditions/if-modified-since.d.ts.map +0 -1
- package/build/server/serve-preconditions/if-none-match.d.ts.map +0 -1
- package/build/server/util/http.d.ts +0 -2
- package/build/server/util/http.d.ts.map +0 -1
- package/build/server/util/http.js +0 -9
- package/build/types/compute.d.ts +0 -11
- package/build/types/compute.d.ts.map +0 -1
- package/build/types/compute.js +0 -1
- package/build/types/config-normalized.d.ts +0 -34
- package/build/types/config-normalized.d.ts.map +0 -1
- package/build/types/config-normalized.js +0 -1
- package/build/types/config.d.ts +0 -37
- package/build/types/config.d.ts.map +0 -1
- package/build/types/config.js +0 -1
- package/build/types/content-assets.d.ts +0 -55
- package/build/types/content-assets.d.ts.map +0 -1
- package/build/types/content-assets.js +0 -1
- package/build/types/content-types.d.ts +0 -11
- package/build/types/content-types.d.ts.map +0 -1
- package/build/types/content-types.js +0 -1
- package/build/types/index.d.ts +0 -7
- package/build/types/index.d.ts.map +0 -1
- package/build/types/index.js +0 -1
- package/build/types/module-assets.d.ts +0 -15
- package/build/types/module-assets.d.ts.map +0 -1
- package/build/types/module-assets.js +0 -1
- package/build/types/util.d.ts +0 -7
- package/build/types/util.d.ts.map +0 -1
- package/build/types/util.js +0 -1
- package/build/util/content-types.d.ts.map +0 -1
- package/build/util/index.d.ts +0 -3
- package/build/util/index.d.ts.map +0 -1
- package/build/util/index.js +0 -2
- package/build/util/metadata.d.ts +0 -3
- package/build/util/metadata.d.ts.map +0 -1
- package/build/util/metadata.js +0 -12
- package/resources/README.md +0 -3
- package/resources/statics-metadata.d.ts +0 -10
- package/resources/statics.d.ts +0 -19
- package/resources/webpack.config.js +0 -41
- /package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-none-match.d.ts +0 -0
|
@@ -1,541 +0,0 @@
|
|
|
1
|
-
// This program builds static resources out of the files in the
|
|
2
|
-
// public folder to be served.
|
|
3
|
-
// e.g., with create-react-app, this would be the ./build directory.
|
|
4
|
-
// Outputs:
|
|
5
|
-
//
|
|
6
|
-
// statics-metadata.js
|
|
7
|
-
//
|
|
8
|
-
// kvStoreName: string - Name of KV Store, or null if not used.
|
|
9
|
-
// contentAssetMetadataMap: Map<string, ContentAssetMetadataMapEntry> - mapping of asset keys to their metadata
|
|
10
|
-
// - key: string - assetKey, the filename relative to root dir (e.g., /public/foo/index.html)
|
|
11
|
-
// - value: ContentAssetMetadataMapEntry - metadata for asset
|
|
12
|
-
//
|
|
13
|
-
// ContentAssetMetadataMapEntry structure
|
|
14
|
-
// - assetKey: string - filename relative to root dir
|
|
15
|
-
// - contentType: string - MIME type
|
|
16
|
-
// - text: boolean - whether this is a text file
|
|
17
|
-
// - lastModifiedTime: number - last modified time as unix time (seconds)
|
|
18
|
-
// - fileInfo: FileInfo - information about the file
|
|
19
|
-
// - compressedFileInfos: Map<string, FileInfo> - information about any compressed versions
|
|
20
|
-
// - key: string - compression algorithm name (e.g., "gzip", "br", etc.)
|
|
21
|
-
// - value: FileInfo - information about the compressed version of the file
|
|
22
|
-
// - type: string - where the data is available. Usually 'wasm-inline' or 'kv-store'.
|
|
23
|
-
// FileInfo structure
|
|
24
|
-
// - hash: string - SHA-256 hash of file
|
|
25
|
-
// - size: number - file size in bytes
|
|
26
|
-
// - staticFilePath: string - path to file in local filesystem, relative to root dir
|
|
27
|
-
// - kvStoreKey: string - KV Store key, present only for items in KV Store
|
|
28
|
-
//
|
|
29
|
-
// statics.js
|
|
30
|
-
// imports statics-metadata.js and adds utilities for working with the content assets, as well as
|
|
31
|
-
// for loading module assets. Also gives access to StaticPublisher and its config.
|
|
32
|
-
// See README.md for details
|
|
33
|
-
//
|
|
34
|
-
// moduleAssetMap: Map<string, ModuleAssetMapEntry>
|
|
35
|
-
// - key: string - assetKey, the filename relative to root dir (e.g., /module/hello.js)
|
|
36
|
-
// - value: ModuleAssetMapEntry - information about the module
|
|
37
|
-
//
|
|
38
|
-
// ModuleAssetMapEntry structure
|
|
39
|
-
// - isStaticImport: boolean - if true, then uses a static import statement to load the module
|
|
40
|
-
// - if false, then module is loaded when getModule is called
|
|
41
|
-
// - module: any - the statically loaded module if isStaticImport is true, or null
|
|
42
|
-
// - loadModule: function - a function that dynamically loads the module and returns it, if isStaticImport is false, or null
|
|
43
|
-
//
|
|
44
|
-
// contentAssets: ContentAssets instance
|
|
45
|
-
// moduleAssets: ModuleAssets instance
|
|
46
|
-
//
|
|
47
|
-
// getServer(): function - instantiates PublisherServer singleton and returns it
|
|
48
|
-
// serverConfig: PublisherServerConfigNormalized - publisher server config settings
|
|
49
|
-
//
|
|
50
|
-
// PublisherServerConfigNormalized structure
|
|
51
|
-
// - publicDirPrefix: string
|
|
52
|
-
// - staticItems: string[]
|
|
53
|
-
// - compression: string[]
|
|
54
|
-
// - spaFile: string or null
|
|
55
|
-
// - notFoundPageFile: string or null
|
|
56
|
-
// - autoExt: string[]
|
|
57
|
-
// - autoIndex: string[]
|
|
58
|
-
//
|
|
59
|
-
import * as fs from "fs";
|
|
60
|
-
import * as path from "path";
|
|
61
|
-
import * as url from "url";
|
|
62
|
-
import { loadConfigFile } from "../load-config.js";
|
|
63
|
-
import { applyDefaults } from "../util/data.js";
|
|
64
|
-
import { calculateFileSizeAndHash } from "../util/hash.js";
|
|
65
|
-
import { getFiles } from "../util/files.js";
|
|
66
|
-
import { generateOrLoadPublishId } from "../util/publish-id.js";
|
|
67
|
-
import { loadApiKey } from "../util/fastly-api.js";
|
|
68
|
-
import { kvStoreEntryExists, kvStoreSubmitFile } from "../util/kv-store.js";
|
|
69
|
-
import { mergeContentTypes, testFileContentType } from "../../util/content-types.js";
|
|
70
|
-
import { algs } from "../compression/index.js";
|
|
71
|
-
async function uploadFilesToKVStore(fastlyApiContext, kvStoreName, kvStoreItems) {
|
|
72
|
-
for (const { kvStoreKey, staticFilePath, text } of kvStoreItems) {
|
|
73
|
-
if (await kvStoreEntryExists(fastlyApiContext, kvStoreName, kvStoreKey)) {
|
|
74
|
-
// Already exists in KV Store
|
|
75
|
-
console.log(`✔️ Asset already exists in KV Store with key "${kvStoreKey}".`);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
// Upload to KV Store
|
|
79
|
-
const fileData = fs.readFileSync(staticFilePath);
|
|
80
|
-
await kvStoreSubmitFile(fastlyApiContext, kvStoreName, kvStoreKey, fileData);
|
|
81
|
-
console.log(`✔️ Submitted ${text ? 'text' : 'binary'} asset "${staticFilePath}" to KV Store with key "${kvStoreKey}".`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
function writeKVStoreEntriesToFastlyToml(kvStoreName, kvStoreItems) {
|
|
86
|
-
let fastlyToml = fs.readFileSync('./fastly.toml', 'utf-8');
|
|
87
|
-
let before = '';
|
|
88
|
-
let after = '';
|
|
89
|
-
kvStoreName = kvStoreName.includes(".") ? `"${kvStoreName}"` : kvStoreName;
|
|
90
|
-
const tableMarker = `[[local_server.kv_stores.${kvStoreName}]]`;
|
|
91
|
-
const startPos = fastlyToml.indexOf(tableMarker);
|
|
92
|
-
if (startPos === -1) {
|
|
93
|
-
// KV Store decl not in fastly.toml yet
|
|
94
|
-
if (fastlyToml.indexOf(kvStoreName) !== -1) {
|
|
95
|
-
// don't do this!
|
|
96
|
-
console.error("improperly configured entry for '${kvStoreName}' in fastly.toml");
|
|
97
|
-
// TODO: handle thrown exception from callers
|
|
98
|
-
throw "No";
|
|
99
|
-
}
|
|
100
|
-
let newLines;
|
|
101
|
-
if (fastlyToml.endsWith('\n\n')) {
|
|
102
|
-
newLines = '';
|
|
103
|
-
}
|
|
104
|
-
else if (fastlyToml.endsWith('\n')) {
|
|
105
|
-
newLines = '\n';
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
newLines = '\n\n';
|
|
109
|
-
}
|
|
110
|
-
before = fastlyToml + newLines;
|
|
111
|
-
after = '';
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
const lastObjStoreTablePos = fastlyToml.lastIndexOf(tableMarker);
|
|
115
|
-
const nextTablePos = fastlyToml.indexOf('[', lastObjStoreTablePos + tableMarker.length);
|
|
116
|
-
before = fastlyToml.slice(0, startPos);
|
|
117
|
-
if (nextTablePos === -1) {
|
|
118
|
-
after = '';
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
after = fastlyToml.slice(nextTablePos);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
let tablesToml = '';
|
|
125
|
-
for (const { kvStoreKey, staticFilePath } of kvStoreItems) {
|
|
126
|
-
// Probably, JSON.stringify is wrong, but it should do its job
|
|
127
|
-
tablesToml += tableMarker + '\n';
|
|
128
|
-
tablesToml += 'key = ' + JSON.stringify(kvStoreKey) + '\n';
|
|
129
|
-
tablesToml += 'path = ' + JSON.stringify(path.relative('./', staticFilePath)) + '\n';
|
|
130
|
-
tablesToml += '\n';
|
|
131
|
-
}
|
|
132
|
-
fastlyToml = before + tablesToml + after;
|
|
133
|
-
fs.writeFileSync('./fastly.toml', fastlyToml, 'utf-8');
|
|
134
|
-
}
|
|
135
|
-
export async function buildStaticLoader(commandLineValues) {
|
|
136
|
-
const { 'suppress-framework-warnings': suppressFrameworkWarnings } = commandLineValues;
|
|
137
|
-
const displayFrameworkWarnings = !suppressFrameworkWarnings;
|
|
138
|
-
const { publishId, created } = generateOrLoadPublishId();
|
|
139
|
-
if (created) {
|
|
140
|
-
console.log("✅ Created publish ID");
|
|
141
|
-
}
|
|
142
|
-
console.log(`Publish ID: ${publishId}`);
|
|
143
|
-
console.log("🚀 Building loader...");
|
|
144
|
-
const errors = [];
|
|
145
|
-
const { normalized: config, raw: configRaw } = await loadConfigFile(errors);
|
|
146
|
-
if (config == null) {
|
|
147
|
-
console.error("❌ Can't load static-publish.rc.js");
|
|
148
|
-
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
149
|
-
for (const error of errors) {
|
|
150
|
-
console.error(error);
|
|
151
|
-
}
|
|
152
|
-
process.exitCode = 1;
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const outputDir = path.resolve();
|
|
156
|
-
const publicDirRoot = path.resolve(config.rootDir);
|
|
157
|
-
console.log(`✔️ Public directory '${publicDirRoot}'.`);
|
|
158
|
-
const kvStoreName = config.kvStoreName;
|
|
159
|
-
let fastlyApiContext = null;
|
|
160
|
-
if (kvStoreName != null) {
|
|
161
|
-
// TODO: load api key from command line
|
|
162
|
-
const apiKeyResult = loadApiKey();
|
|
163
|
-
if (apiKeyResult == null) {
|
|
164
|
-
console.error("❌ Fastly API Token not provided.");
|
|
165
|
-
console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
166
|
-
process.exitCode = 1;
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
fastlyApiContext = { apiToken: apiKeyResult.apiToken };
|
|
170
|
-
console.log(`✔️ Using KV Store mode, with KV Store: ${kvStoreName}`);
|
|
171
|
-
console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiKeyResult.source}'`);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
if (displayFrameworkWarnings) {
|
|
175
|
-
console.log(`✔️ Not using KV Store mode.`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
const excludeDirs = config.excludeDirs;
|
|
179
|
-
if (excludeDirs.length > 0) {
|
|
180
|
-
console.log(`✔️ Using exclude directories: ${excludeDirs.join(', ')}`);
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
if (displayFrameworkWarnings) {
|
|
184
|
-
console.log(`✔️ No exclude directories defined.`);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
const excludeDotFiles = config.excludeDotFiles;
|
|
188
|
-
if (excludeDotFiles) {
|
|
189
|
-
console.log(`✔️ Files/Directories starting with . are excluded.`);
|
|
190
|
-
}
|
|
191
|
-
const includeWellKnown = config.includeWellKnown;
|
|
192
|
-
if (includeWellKnown) {
|
|
193
|
-
console.log(`✔️ (.well-known is exempt from exclusion.)`);
|
|
194
|
-
}
|
|
195
|
-
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
196
|
-
// Load content types
|
|
197
|
-
const finalContentTypes = mergeContentTypes(config.contentTypes);
|
|
198
|
-
// getFiles() applies excludeDirs, excludeDotFiles, and includeWellKnown.
|
|
199
|
-
let files = getFiles(publicDirRoot, { ...config, publicDirRoot });
|
|
200
|
-
// If public dir is not inside the c@e dir, then
|
|
201
|
-
// exclude files that come from C@E app dir
|
|
202
|
-
if (!publicDirRoot.startsWith(outputDir)) {
|
|
203
|
-
files = files.filter(file => !file.startsWith(outputDir));
|
|
204
|
-
}
|
|
205
|
-
// And then we apply assetInclusionTest.
|
|
206
|
-
const assetInfos = files.map(file => {
|
|
207
|
-
const assetKey = file.slice(publicDirRoot.length)
|
|
208
|
-
// in Windows, assetKey will otherwise end up as \path\file.html
|
|
209
|
-
.replace(/\\/g, '/');
|
|
210
|
-
let contentTypeTestResult = testFileContentType(finalContentTypes, assetKey);
|
|
211
|
-
if (contentTypeTestResult == null) {
|
|
212
|
-
contentTypeTestResult = {
|
|
213
|
-
text: false,
|
|
214
|
-
contentType: 'application/octet-stream',
|
|
215
|
-
};
|
|
216
|
-
if (displayFrameworkWarnings) {
|
|
217
|
-
console.log('⚠️ Notice: Unknown file type ' + assetKey + '. Treating as binary file.');
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
let contentAssetInclusionResultValue = config.contentAssetInclusionTest?.(assetKey, contentTypeTestResult.contentType);
|
|
221
|
-
if (typeof contentAssetInclusionResultValue === 'boolean') {
|
|
222
|
-
contentAssetInclusionResultValue = {
|
|
223
|
-
includeContent: contentAssetInclusionResultValue,
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
else if (contentAssetInclusionResultValue === 'inline') {
|
|
227
|
-
contentAssetInclusionResultValue = {
|
|
228
|
-
includeContent: true,
|
|
229
|
-
inline: true,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
const contentAssetInclusionResult = applyDefaults(contentAssetInclusionResultValue ?? null, {
|
|
233
|
-
includeContent: true,
|
|
234
|
-
inline: false,
|
|
235
|
-
});
|
|
236
|
-
let moduleAssetInclusionResultValue = config.moduleAssetInclusionTest?.(assetKey, contentTypeTestResult.contentType);
|
|
237
|
-
if (typeof moduleAssetInclusionResultValue === 'boolean') {
|
|
238
|
-
moduleAssetInclusionResultValue = {
|
|
239
|
-
includeModule: moduleAssetInclusionResultValue,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
else if (moduleAssetInclusionResultValue === 'static-import') {
|
|
243
|
-
moduleAssetInclusionResultValue = {
|
|
244
|
-
includeModule: true,
|
|
245
|
-
useStaticImport: true,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
const moduleAssetInclusionResult = applyDefaults(moduleAssetInclusionResultValue ?? null, {
|
|
249
|
-
includeModule: false,
|
|
250
|
-
useStaticImport: false,
|
|
251
|
-
});
|
|
252
|
-
const stats = fs.statSync(file);
|
|
253
|
-
const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
|
|
254
|
-
const { size, hash } = calculateFileSizeAndHash(file);
|
|
255
|
-
return {
|
|
256
|
-
file,
|
|
257
|
-
assetKey,
|
|
258
|
-
lastModifiedTime,
|
|
259
|
-
hash,
|
|
260
|
-
size,
|
|
261
|
-
...contentAssetInclusionResult,
|
|
262
|
-
...moduleAssetInclusionResult,
|
|
263
|
-
...contentTypeTestResult,
|
|
264
|
-
};
|
|
265
|
-
});
|
|
266
|
-
console.log("🚀 Preparing content assets ...");
|
|
267
|
-
if (kvStoreName == null && configRaw != null && !("contentCompression" in configRaw)) {
|
|
268
|
-
console.log(`⚠️ Notice: By default, pre-compressed content assets are not generated when KV Store is not used.`);
|
|
269
|
-
console.log(" If you want to pre-compress assets, add a value for 'contentCompression' to your static-publish.rc.js.");
|
|
270
|
-
}
|
|
271
|
-
// The Static Content Root Dir, which will hold the loaders and a copy of static files.
|
|
272
|
-
const staticContentRootDir = config.staticContentRootDir;
|
|
273
|
-
// Create "static content" dir that will be used to hold a copy of static files.
|
|
274
|
-
// NOTE: This copy is created so that they can be loaded with includeBytes(), which requires
|
|
275
|
-
// all files to be under the Compute project dir.
|
|
276
|
-
const staticContentDir = `${staticContentRootDir}/static-content`;
|
|
277
|
-
fs.rmSync(staticContentDir, { recursive: true, force: true });
|
|
278
|
-
fs.mkdirSync(staticContentDir, { recursive: true });
|
|
279
|
-
// Build content assets metadata
|
|
280
|
-
const contentAssetMetadataMap = {};
|
|
281
|
-
// KV Store items to upload
|
|
282
|
-
const kvStoreItems = [];
|
|
283
|
-
let contentItems = 0;
|
|
284
|
-
const counts = {
|
|
285
|
-
inline: 0,
|
|
286
|
-
kvStore: 0,
|
|
287
|
-
excluded: 0,
|
|
288
|
-
};
|
|
289
|
-
for (const assetInfo of assetInfos) {
|
|
290
|
-
if (!assetInfo.includeContent) {
|
|
291
|
-
// Non-content asset
|
|
292
|
-
counts.excluded++;
|
|
293
|
-
continue;
|
|
294
|
-
}
|
|
295
|
-
contentItems++;
|
|
296
|
-
console.log(`✔️ [${contentItems}] ${assetInfo.assetKey}: ${JSON.stringify(assetInfo.contentType)}`);
|
|
297
|
-
const { file, assetKey, contentType, text, hash, size, lastModifiedTime, } = assetInfo;
|
|
298
|
-
const entryBase = {
|
|
299
|
-
assetKey,
|
|
300
|
-
contentType,
|
|
301
|
-
lastModifiedTime,
|
|
302
|
-
text,
|
|
303
|
-
fileInfo: {
|
|
304
|
-
hash,
|
|
305
|
-
size,
|
|
306
|
-
},
|
|
307
|
-
};
|
|
308
|
-
let metadata;
|
|
309
|
-
const isInline = kvStoreName == null || assetInfo.inline;
|
|
310
|
-
const staticContentFilePath = `${staticContentDir}/file${contentItems}.${assetInfo.text ? 'txt' : 'bin'}`;
|
|
311
|
-
async function prepareCompressedVersions(contentCompressions, func) {
|
|
312
|
-
for (const alg of contentCompression) {
|
|
313
|
-
const compressTo = algs[alg];
|
|
314
|
-
if (compressTo != null) {
|
|
315
|
-
// Even for items that are not inlined, compressed copies of the file are
|
|
316
|
-
// always created in the static content directory.
|
|
317
|
-
const staticFilePath = `${staticContentFilePath}_${alg}`;
|
|
318
|
-
if (await compressTo(file, staticFilePath, text)) {
|
|
319
|
-
console.log(`✔️ Compressed ${text ? 'text' : 'binary'} asset "${file}" to "${staticFilePath}" [${alg}].`);
|
|
320
|
-
const { size, hash } = calculateFileSizeAndHash(staticFilePath);
|
|
321
|
-
func(alg, staticFilePath, hash, size);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
const contentCompression = config.contentCompression;
|
|
327
|
-
if (isInline) {
|
|
328
|
-
// We will inline this file using includeBytes()
|
|
329
|
-
// so we copy it to the static-content directory.
|
|
330
|
-
const staticFilePath = staticContentFilePath;
|
|
331
|
-
fs.cpSync(file, staticFilePath);
|
|
332
|
-
console.log(`✔️ Copied ${text ? 'text' : 'binary'} asset "${file}" to "${staticFilePath}".`);
|
|
333
|
-
const compressedFileInfos = {};
|
|
334
|
-
await prepareCompressedVersions(contentCompression, (alg, staticFilePath, hash, size) => {
|
|
335
|
-
compressedFileInfos[alg] = { staticFilePath, hash, size };
|
|
336
|
-
});
|
|
337
|
-
metadata = {
|
|
338
|
-
...entryBase,
|
|
339
|
-
type: 'wasm-inline',
|
|
340
|
-
fileInfo: {
|
|
341
|
-
...entryBase.fileInfo,
|
|
342
|
-
staticFilePath,
|
|
343
|
-
},
|
|
344
|
-
compressedFileInfos,
|
|
345
|
-
};
|
|
346
|
-
counts.inline++;
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
// For KV Store mode, we don't need to make a copy of the original file
|
|
350
|
-
const staticFilePath = file;
|
|
351
|
-
// Use the hash as part of the key name. This avoids having to
|
|
352
|
-
// re-upload a file if it already exists.
|
|
353
|
-
const kvStoreKey = `${publishId}:${assetKey}_${hash}`;
|
|
354
|
-
kvStoreItems.push({
|
|
355
|
-
kvStoreKey,
|
|
356
|
-
staticFilePath,
|
|
357
|
-
text,
|
|
358
|
-
});
|
|
359
|
-
const compressedFileInfos = {};
|
|
360
|
-
await prepareCompressedVersions(contentCompression, (alg, staticFilePath, hash, size) => {
|
|
361
|
-
const kvStoreKey = `${publishId}:${assetKey}_${alg}_${hash}`;
|
|
362
|
-
compressedFileInfos[alg] = { staticFilePath, kvStoreKey, hash, size };
|
|
363
|
-
kvStoreItems.push({
|
|
364
|
-
kvStoreKey,
|
|
365
|
-
staticFilePath,
|
|
366
|
-
text,
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
metadata = {
|
|
370
|
-
...entryBase,
|
|
371
|
-
type: 'kv-store',
|
|
372
|
-
fileInfo: {
|
|
373
|
-
...entryBase.fileInfo,
|
|
374
|
-
staticFilePath,
|
|
375
|
-
kvStoreKey,
|
|
376
|
-
},
|
|
377
|
-
compressedFileInfos,
|
|
378
|
-
};
|
|
379
|
-
counts.kvStore++;
|
|
380
|
-
}
|
|
381
|
-
contentAssetMetadataMap[assetKey] = metadata;
|
|
382
|
-
}
|
|
383
|
-
if (kvStoreName != null) {
|
|
384
|
-
await uploadFilesToKVStore(fastlyApiContext, kvStoreName, kvStoreItems);
|
|
385
|
-
writeKVStoreEntriesToFastlyToml(kvStoreName, kvStoreItems);
|
|
386
|
-
}
|
|
387
|
-
console.log("✅ Prepared " + (counts.inline + counts.kvStore) + " content asset(s):");
|
|
388
|
-
if (counts.inline > 0) {
|
|
389
|
-
console.log(" " + counts.inline + " inline");
|
|
390
|
-
}
|
|
391
|
-
if (counts.kvStore > 0) {
|
|
392
|
-
console.log(" " + counts.kvStore + " KV Store");
|
|
393
|
-
}
|
|
394
|
-
// Build statics-metadata.js
|
|
395
|
-
let metadataFileContents = `/*
|
|
396
|
-
* Generated by @fastly/compute-js-static-publish.
|
|
397
|
-
*/
|
|
398
|
-
|
|
399
|
-
`;
|
|
400
|
-
metadataFileContents += `\nexport const kvStoreName = ${JSON.stringify(kvStoreName)};\n`;
|
|
401
|
-
metadataFileContents += `\nexport const contentAssetMetadataMap = {\n`;
|
|
402
|
-
for (const [key, value] of Object.entries(contentAssetMetadataMap)) {
|
|
403
|
-
metadataFileContents += ` ${JSON.stringify(key)}: ${JSON.stringify(value)},\n`;
|
|
404
|
-
}
|
|
405
|
-
metadataFileContents += '};\n';
|
|
406
|
-
fs.writeFileSync(`${staticContentRootDir}/statics-metadata.js`, metadataFileContents);
|
|
407
|
-
console.log(`✅ Wrote static file metadata for ${contentItems} file(s).`);
|
|
408
|
-
// Copy Types file for static file loader
|
|
409
|
-
try {
|
|
410
|
-
const typesFile = path.resolve(__dirname, '../../../resources/statics-metadata.d.ts');
|
|
411
|
-
fs.copyFileSync(typesFile, `${staticContentRootDir}/statics-metadata.d.ts`);
|
|
412
|
-
console.log("✅ Wrote content assets metadata types file statics-metadata.d.ts.");
|
|
413
|
-
}
|
|
414
|
-
catch {
|
|
415
|
-
console.log("⚠️ Notice: could not write content assets metadata types file statics-metadata.d.ts.");
|
|
416
|
-
}
|
|
417
|
-
// Build statics.js
|
|
418
|
-
let fileContents = `/*
|
|
419
|
-
* Generated by @fastly/compute-js-static-publish.
|
|
420
|
-
*/
|
|
421
|
-
|
|
422
|
-
`;
|
|
423
|
-
fileContents += 'import { ContentAssets, ModuleAssets, PublisherServer } from "@fastly/compute-js-static-publish";\n\n';
|
|
424
|
-
fileContents += 'import "@fastly/compute-js-static-publish/build/compute-js.js";\n\n';
|
|
425
|
-
fileContents += 'import { kvStoreName, contentAssetMetadataMap } from "./statics-metadata.js";\n';
|
|
426
|
-
// Add import statements for assets that are modules and that need to be statically imported.
|
|
427
|
-
const staticImportModuleNumbers = {};
|
|
428
|
-
let staticImportModuleNumber = 0;
|
|
429
|
-
for (const assetInfo of assetInfos) {
|
|
430
|
-
if (assetInfo.includeModule && assetInfo.useStaticImport) {
|
|
431
|
-
staticImportModuleNumber++;
|
|
432
|
-
staticImportModuleNumbers[assetInfo.assetKey] = staticImportModuleNumber;
|
|
433
|
-
// static-content lives in the staticContentRootDir dir, so the import must be declared as
|
|
434
|
-
// relative to that file.
|
|
435
|
-
const relativeFilePath = path.relative(staticContentRootDir, assetInfo.file);
|
|
436
|
-
fileContents += `import * as fileModule${staticImportModuleNumber} from "${relativeFilePath}";\n`;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
fileContents += `\nexport const moduleAssetsMap = {\n`;
|
|
440
|
-
for (const assetInfo of assetInfos) {
|
|
441
|
-
if (!assetInfo.includeModule) {
|
|
442
|
-
continue;
|
|
443
|
-
}
|
|
444
|
-
let module;
|
|
445
|
-
let loadModuleFunction;
|
|
446
|
-
if (assetInfo.useStaticImport) {
|
|
447
|
-
const moduleNumber = staticImportModuleNumbers[assetInfo.assetKey];
|
|
448
|
-
if (moduleNumber == null) {
|
|
449
|
-
throw new Error(`Unexpected! module asset number for "${assetInfo.assetKey}" was not found!`);
|
|
450
|
-
}
|
|
451
|
-
loadModuleFunction = `() => Promise.resolve(fileModule${moduleNumber})`;
|
|
452
|
-
module = `fileModule${moduleNumber}`;
|
|
453
|
-
}
|
|
454
|
-
else {
|
|
455
|
-
// static-content lives in the staticContentRootDir dir, so the import must be declared as
|
|
456
|
-
// relative to that file.
|
|
457
|
-
const relativeFilePath = path.relative(staticContentRootDir, assetInfo.file);
|
|
458
|
-
loadModuleFunction = `() => import("${relativeFilePath}")`;
|
|
459
|
-
module = 'null';
|
|
460
|
-
}
|
|
461
|
-
fileContents += ` ${JSON.stringify(assetInfo.assetKey)}: { isStaticImport: ${JSON.stringify(assetInfo.useStaticImport)}, module: ${module}, loadModule: ${loadModuleFunction} },\n`;
|
|
462
|
-
}
|
|
463
|
-
fileContents += '};\n';
|
|
464
|
-
const server = applyDefaults(config.server, {
|
|
465
|
-
publicDirPrefix: '',
|
|
466
|
-
staticItems: [],
|
|
467
|
-
compression: ['br', 'gzip'],
|
|
468
|
-
spaFile: null,
|
|
469
|
-
notFoundPageFile: null,
|
|
470
|
-
autoExt: [],
|
|
471
|
-
autoIndex: [],
|
|
472
|
-
});
|
|
473
|
-
let publicDirPrefix = server.publicDirPrefix;
|
|
474
|
-
console.log(`✔️ Server public dir prefix '${publicDirPrefix}'.`);
|
|
475
|
-
let staticItems = server.staticItems;
|
|
476
|
-
let compression = server.compression;
|
|
477
|
-
let spaFile = server.spaFile;
|
|
478
|
-
if (spaFile != null) {
|
|
479
|
-
console.log(`✔️ Application SPA file '${spaFile}'.`);
|
|
480
|
-
const spaAsset = assetInfos.find(assetInfo => assetInfo.assetKey === spaFile);
|
|
481
|
-
if (spaAsset == null || spaAsset.contentType !== 'text/html') {
|
|
482
|
-
if (displayFrameworkWarnings) {
|
|
483
|
-
console.log(`⚠️ Notice: '${spaFile}' does not exist or is not of type 'text/html'. Ignoring.`);
|
|
484
|
-
}
|
|
485
|
-
spaFile = null;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
if (displayFrameworkWarnings) {
|
|
490
|
-
console.log(`✔️ Application is not a SPA.`);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
let notFoundPageFile = server.notFoundPageFile;
|
|
494
|
-
if (notFoundPageFile != null) {
|
|
495
|
-
console.log(`✔️ Application 'not found (404)' file '${notFoundPageFile}'.`);
|
|
496
|
-
const notFoundPageAsset = assetInfos.find(assetInfo => assetInfo.assetKey === notFoundPageFile);
|
|
497
|
-
if (notFoundPageAsset == null || notFoundPageAsset.contentType !== 'text/html') {
|
|
498
|
-
if (displayFrameworkWarnings) {
|
|
499
|
-
console.log(`⚠️ Notice: '${notFoundPageFile}' does not exist or is not of type 'text/html'. Ignoring.`);
|
|
500
|
-
}
|
|
501
|
-
notFoundPageFile = null;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
else {
|
|
505
|
-
if (displayFrameworkWarnings) {
|
|
506
|
-
console.log(`✔️ Application specifies no 'not found (404)' page.`);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
let autoIndex = server.autoIndex;
|
|
510
|
-
let autoExt = server.autoExt;
|
|
511
|
-
const serverConfig = {
|
|
512
|
-
publicDirPrefix,
|
|
513
|
-
staticItems,
|
|
514
|
-
compression,
|
|
515
|
-
spaFile,
|
|
516
|
-
notFoundPageFile,
|
|
517
|
-
autoExt,
|
|
518
|
-
autoIndex,
|
|
519
|
-
};
|
|
520
|
-
fileContents += `\nexport const serverConfig = ${JSON.stringify(serverConfig, null, 2)};\n`;
|
|
521
|
-
fileContents += '\nexport const contentAssets = new ContentAssets(contentAssetMetadataMap, {kvStoreName});';
|
|
522
|
-
fileContents += '\nexport const moduleAssets = new ModuleAssets(moduleAssetsMap);\n';
|
|
523
|
-
fileContents += '\nlet server = null;';
|
|
524
|
-
fileContents += '\nexport function getServer() {' +
|
|
525
|
-
'\n if (server == null) {' +
|
|
526
|
-
'\n server = new PublisherServer(serverConfig, contentAssets);' +
|
|
527
|
-
'\n }' +
|
|
528
|
-
'\n return server;' +
|
|
529
|
-
'\n}\n';
|
|
530
|
-
fs.writeFileSync(`${staticContentRootDir}/statics.js`, fileContents);
|
|
531
|
-
console.log("✅ Wrote static file loader for " + files.length + " file(s).");
|
|
532
|
-
// Copy Types file for static file loader
|
|
533
|
-
try {
|
|
534
|
-
const staticsTypeFile = path.resolve(__dirname, '../../../resources/statics.d.ts');
|
|
535
|
-
fs.copyFileSync(staticsTypeFile, `${staticContentRootDir}/statics.d.ts`);
|
|
536
|
-
console.log(`✅ Wrote static file loader types file ${staticContentRootDir}/statics.d.ts.`);
|
|
537
|
-
}
|
|
538
|
-
catch {
|
|
539
|
-
console.log(`⚠️ Notice: could not write static file loader types file ${staticContentRootDir}/statics.d.ts.`);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clean-kv-store.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/clean-kv-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAc5D,wBAAsB,YAAY,CAAC,iBAAiB,EAAE,kBAAkB,iBAkEvE"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { generateOrLoadPublishId } from "../util/publish-id.js";
|
|
3
|
-
import { loadConfigFile } from "../load-config.js";
|
|
4
|
-
import { getKVStoreKeys, kvStoreDeleteFile } from "../util/kv-store.js";
|
|
5
|
-
import { loadApiKey } from "../util/fastly-api.js";
|
|
6
|
-
import { getKVStoreKeysFromMetadata } from "../../util/metadata.js";
|
|
7
|
-
export async function cleanKVStore(commandLineValues) {
|
|
8
|
-
const { publishId } = generateOrLoadPublishId();
|
|
9
|
-
const errors = [];
|
|
10
|
-
const { normalized: config } = await loadConfigFile(errors);
|
|
11
|
-
if (config == null) {
|
|
12
|
-
console.error("❌ Can't load static-publish.rc.js");
|
|
13
|
-
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
14
|
-
for (const error of errors) {
|
|
15
|
-
console.error(error);
|
|
16
|
-
}
|
|
17
|
-
process.exitCode = 1;
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
let fastlyApiContext = null;
|
|
21
|
-
const apiKeyResult = loadApiKey();
|
|
22
|
-
if (apiKeyResult == null) {
|
|
23
|
-
console.error("❌ Fastly API Token not provided.");
|
|
24
|
-
console.error("Specify one on the command line, or use the FASTLY_API_TOKEN environment variable.");
|
|
25
|
-
process.exitCode = 1;
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
fastlyApiContext = { apiToken: apiKeyResult.apiToken };
|
|
29
|
-
const staticContentRootDir = config.staticContentRootDir;
|
|
30
|
-
const staticsMetadata = await import(path.resolve(`${staticContentRootDir}/statics-metadata.js`));
|
|
31
|
-
const { kvStoreName, contentAssetMetadataMap } = staticsMetadata;
|
|
32
|
-
if (kvStoreName == null) {
|
|
33
|
-
console.error("❌ KV Store not specified.");
|
|
34
|
-
console.error("This only has meaning in KV Store mode.");
|
|
35
|
-
process.exitCode = 1;
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
// TODO: Enable getting kvStoreName and publishId from command line
|
|
39
|
-
// These are the items that are currently in the KV Store and that belong to this publish ID.
|
|
40
|
-
const items = ((await getKVStoreKeys(fastlyApiContext, kvStoreName)) ?? [])
|
|
41
|
-
.filter(x => x.startsWith(`${publishId}:`));
|
|
42
|
-
// These are the items that are currently are being used.
|
|
43
|
-
const keys = getKVStoreKeysFromMetadata(contentAssetMetadataMap);
|
|
44
|
-
// So these are the items that we should be deleting.
|
|
45
|
-
const itemsToDelete = items.filter(x => !keys.has(x));
|
|
46
|
-
console.log("Publish ID: " + publishId);
|
|
47
|
-
console.log("KV Store contains " + items.length + " item(s) for this publish ID.");
|
|
48
|
-
console.log("Current site metadata contains " + keys.size + " item(s) (including compressed alternates).");
|
|
49
|
-
console.log("Number of items to delete: " + itemsToDelete.length);
|
|
50
|
-
for (const [index, item] of itemsToDelete.entries()) {
|
|
51
|
-
console.log("Deleting item [" + (index + 1) + "]: " + item);
|
|
52
|
-
await kvStoreDeleteFile(fastlyApiContext, kvStoreName, item);
|
|
53
|
-
}
|
|
54
|
-
console.log("✅ Completed.");
|
|
55
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { StaticPublisherConfigNormalized } from "../types/config-normalized.js";
|
|
2
|
-
export declare function loadConfigFile(errors?: string[]): Promise<{
|
|
3
|
-
normalized: StaticPublisherConfigNormalized | null;
|
|
4
|
-
raw: any;
|
|
5
|
-
}>;
|
|
6
|
-
//# sourceMappingURL=load-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../src/cli/load-config.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,+BAA+B,EAEhC,MAAM,+BAA+B,CAAC;AA6WvC,wBAAsB,cAAc,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC;IAAC,UAAU,EAAE,+BAA+B,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAC,CAAC,CAkBnI"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"astro.d.ts","sourceRoot":"","sources":["../../../../src/cli/presets/implementations/astro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,WAAY,YAAW,WAAW;IAC7C,IAAI,SAAW;IACf,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAIjC;IACF,KAAK,CAAC,WAAW,EAAE,GAAG;CAavB"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export class AstroPreset {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.name = 'Astro';
|
|
4
|
-
this.defaultOptions = {
|
|
5
|
-
rootDir: './dist',
|
|
6
|
-
name: 'my-astro-app',
|
|
7
|
-
description: 'Fastly Compute static site from Astro',
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
check(packageJson) {
|
|
11
|
-
if (packageJson == null) {
|
|
12
|
-
console.error("❌ Can't read/parse package.json");
|
|
13
|
-
console.error("Run this from a Astro project directory.");
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
if (packageJson?.dependencies?.['astro'] == null) {
|
|
17
|
-
console.error("❌ Can't find astro in dependencies");
|
|
18
|
-
console.error("Run this from a Astro project directory.");
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AppOptions, IPresetBase } from '../preset-base.js';
|
|
2
|
-
export declare class CreateReactAppPreset implements IPresetBase {
|
|
3
|
-
name: string;
|
|
4
|
-
defaultOptions: Partial<AppOptions>;
|
|
5
|
-
check(packageJson: any): boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare class CreateReactAppEjectedPreset extends CreateReactAppPreset {
|
|
8
|
-
name: string;
|
|
9
|
-
check(): boolean;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=create-react-app.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-react-app.d.ts","sourceRoot":"","sources":["../../../../src/cli/presets/implementations/create-react-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,oBAAqB,YAAW,WAAW;IACtD,IAAI,SAAsB;IAC1B,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAKjC;IAEF,KAAK,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO;CAejC;AAED,qBAAa,2BAA4B,SAAQ,oBAAoB;IACnE,IAAI,SAAgC;IACpC,KAAK;CAGN"}
|