@fastly/compute-js-static-publish 6.2.0 → 7.0.0-beta.0
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 -575
- 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 +291 -264
- 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 +38 -32
- 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 +415 -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 -33
- /package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-none-match.d.ts +0 -0
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
1
5
|
// This program creates a Fastly Compute JavaScript application
|
|
2
6
|
// in a subfolder named compute-js.
|
|
3
7
|
// This project can be served using fastly compute serve
|
|
4
8
|
// or deployed to a Compute service using fastly compute publish.
|
|
5
|
-
import * as child_process from
|
|
6
|
-
import * as path from
|
|
7
|
-
import * as fs from
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
9
|
+
import * as child_process from 'node:child_process';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import * as fs from 'node:fs';
|
|
12
|
+
import commandLineArgs from 'command-line-args';
|
|
13
|
+
import { dotRelative, rootRelative } from '../util/files.js';
|
|
14
|
+
import { findComputeJsStaticPublisherVersion } from '../util/package.js';
|
|
10
15
|
const defaultOptions = {
|
|
16
|
+
outputDir: undefined,
|
|
11
17
|
rootDir: undefined,
|
|
12
18
|
publicDir: undefined,
|
|
13
19
|
staticDirs: [],
|
|
14
|
-
|
|
20
|
+
staticPublisherWorkingDir: undefined,
|
|
15
21
|
spa: undefined,
|
|
16
22
|
notFoundPage: '[public-dir]/404.html',
|
|
17
23
|
autoIndex: ['index.html', 'index.htm'],
|
|
@@ -20,66 +26,77 @@ const defaultOptions = {
|
|
|
20
26
|
name: 'compute-js-static-site',
|
|
21
27
|
description: 'Fastly Compute static site',
|
|
22
28
|
serviceId: undefined,
|
|
29
|
+
publishId: undefined,
|
|
23
30
|
kvStoreName: undefined,
|
|
24
31
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
32
|
+
function buildOptions(packageJson, commandLineValues) {
|
|
33
|
+
// Applied in this order for proper overriding
|
|
34
|
+
// 1. defaults
|
|
35
|
+
// 2. package.json
|
|
36
|
+
// 3. command-line args
|
|
37
|
+
const options = structuredClone(defaultOptions);
|
|
38
|
+
if (packageJson?.name !== undefined) {
|
|
39
|
+
options.name = packageJson.name;
|
|
40
|
+
}
|
|
41
|
+
if (packageJson?.author !== undefined) {
|
|
42
|
+
options.author = packageJson.author;
|
|
43
|
+
}
|
|
44
|
+
if (packageJson?.description !== undefined) {
|
|
45
|
+
options.description = packageJson.description;
|
|
46
|
+
}
|
|
30
47
|
{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
48
|
+
let outputDir;
|
|
49
|
+
const outputDirValue = commandLineValues['output'];
|
|
50
|
+
if (outputDirValue == null || typeof outputDirValue === 'string') {
|
|
51
|
+
outputDir = outputDirValue;
|
|
52
|
+
}
|
|
53
|
+
if (outputDir !== undefined) {
|
|
54
|
+
options.outputDir = outputDir;
|
|
34
55
|
}
|
|
35
56
|
}
|
|
36
|
-
let rootDir;
|
|
37
|
-
let publicDir;
|
|
38
57
|
{
|
|
58
|
+
let rootDir;
|
|
39
59
|
const rootDirValue = commandLineValues['root-dir'];
|
|
40
60
|
if (rootDirValue == null || typeof rootDirValue === 'string') {
|
|
41
61
|
rootDir = rootDirValue;
|
|
42
62
|
}
|
|
43
|
-
if (rootDir
|
|
44
|
-
rootDir =
|
|
63
|
+
if (rootDir !== undefined) {
|
|
64
|
+
options.rootDir = rootDir;
|
|
45
65
|
}
|
|
66
|
+
}
|
|
67
|
+
{
|
|
68
|
+
let publicDir;
|
|
46
69
|
const publicDirValue = commandLineValues['public-dir'];
|
|
47
70
|
if (publicDirValue == null || typeof publicDirValue === 'string') {
|
|
48
71
|
publicDir = publicDirValue;
|
|
49
72
|
}
|
|
50
|
-
if (publicDir
|
|
51
|
-
publicDir =
|
|
52
|
-
}
|
|
53
|
-
// If we don't have a preset, then for backwards compatibility
|
|
54
|
-
// we check if we have public-dir but no root-dir. If that is
|
|
55
|
-
// the case then we use the value public-dir as root-dir.
|
|
56
|
-
if (preset == null && rootDir == null && publicDir != null) {
|
|
57
|
-
rootDir = publicDir;
|
|
58
|
-
publicDir = undefined;
|
|
73
|
+
if (publicDir !== undefined) {
|
|
74
|
+
options.publicDir = publicDir;
|
|
59
75
|
}
|
|
60
76
|
}
|
|
61
|
-
// Filepaths provided on the command line are always given relative to CWD,
|
|
62
|
-
// so we need to resolve them.
|
|
63
|
-
let staticDirs;
|
|
64
77
|
{
|
|
78
|
+
let staticDirs;
|
|
65
79
|
const staticDirsValue = commandLineValues['static-dir'];
|
|
66
80
|
const asArray = Array.isArray(staticDirsValue) ? staticDirsValue : [staticDirsValue];
|
|
67
81
|
if (asArray.every((x) => typeof x === 'string')) {
|
|
68
|
-
staticDirs = asArray
|
|
82
|
+
staticDirs = asArray;
|
|
83
|
+
}
|
|
84
|
+
if (staticDirs !== undefined) {
|
|
85
|
+
options.staticDirs = staticDirs;
|
|
69
86
|
}
|
|
70
87
|
}
|
|
71
|
-
let staticContentRootDir;
|
|
72
88
|
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
89
|
+
let staticPublisherWorkingDir;
|
|
90
|
+
const staticPublisherWorkingDirValue = commandLineValues['static-publisher-working-dir'];
|
|
91
|
+
if (staticPublisherWorkingDirValue == null || typeof staticPublisherWorkingDirValue === 'string') {
|
|
92
|
+
staticPublisherWorkingDir = staticPublisherWorkingDirValue;
|
|
76
93
|
}
|
|
77
|
-
if (
|
|
78
|
-
|
|
94
|
+
if (staticPublisherWorkingDir !== undefined) {
|
|
95
|
+
options.staticPublisherWorkingDir = staticPublisherWorkingDir;
|
|
79
96
|
}
|
|
80
97
|
}
|
|
81
|
-
let spa;
|
|
82
98
|
{
|
|
99
|
+
let spa;
|
|
83
100
|
const spaValue = commandLineValues['spa'];
|
|
84
101
|
if (spaValue === null) {
|
|
85
102
|
// If 'spa' is provided with a null value, then the flag was provided
|
|
@@ -90,9 +107,12 @@ function processCommandLineArgs(commandLineValues) {
|
|
|
90
107
|
else if (spaValue == null || typeof spaValue === 'string') {
|
|
91
108
|
spa = spaValue;
|
|
92
109
|
}
|
|
110
|
+
if (spa !== undefined) {
|
|
111
|
+
options.spa = spa;
|
|
112
|
+
}
|
|
93
113
|
}
|
|
94
|
-
let notFoundPage;
|
|
95
114
|
{
|
|
115
|
+
let notFoundPage;
|
|
96
116
|
const notFoundPageValue = commandLineValues['not-found-page'];
|
|
97
117
|
if (notFoundPageValue === null) {
|
|
98
118
|
// If 'spa' is provided with a null value, then the flag was provided
|
|
@@ -103,9 +123,12 @@ function processCommandLineArgs(commandLineValues) {
|
|
|
103
123
|
else if (notFoundPageValue == null || typeof notFoundPageValue === 'string') {
|
|
104
124
|
notFoundPage = notFoundPageValue;
|
|
105
125
|
}
|
|
126
|
+
if (notFoundPage !== undefined) {
|
|
127
|
+
options.notFoundPage = notFoundPage;
|
|
128
|
+
}
|
|
106
129
|
}
|
|
107
|
-
let autoIndex;
|
|
108
130
|
{
|
|
131
|
+
let autoIndex;
|
|
109
132
|
const autoIndexValue = commandLineValues['auto-index'];
|
|
110
133
|
const asArray = Array.isArray(autoIndexValue) ? autoIndexValue : [autoIndexValue];
|
|
111
134
|
if (asArray.every((x) => typeof x === 'string')) {
|
|
@@ -120,9 +143,12 @@ function processCommandLineArgs(commandLineValues) {
|
|
|
120
143
|
return acc;
|
|
121
144
|
}, []);
|
|
122
145
|
}
|
|
146
|
+
if (autoIndex !== undefined) {
|
|
147
|
+
options.autoIndex = autoIndex;
|
|
148
|
+
}
|
|
123
149
|
}
|
|
124
|
-
let autoExt = [];
|
|
125
150
|
{
|
|
151
|
+
let autoExt = [];
|
|
126
152
|
const autoExtValue = commandLineValues['auto-ext'];
|
|
127
153
|
const asArray = Array.isArray(autoExtValue) ? autoExtValue : [autoExtValue];
|
|
128
154
|
if (asArray.every((x) => typeof x === 'string')) {
|
|
@@ -138,90 +164,138 @@ function processCommandLineArgs(commandLineValues) {
|
|
|
138
164
|
return acc;
|
|
139
165
|
}, []);
|
|
140
166
|
}
|
|
167
|
+
if (autoExt !== undefined) {
|
|
168
|
+
options.autoExt = autoExt;
|
|
169
|
+
}
|
|
141
170
|
}
|
|
142
|
-
let name;
|
|
143
171
|
{
|
|
172
|
+
let name;
|
|
144
173
|
const nameValue = commandLineValues['name'];
|
|
145
174
|
if (nameValue == null || typeof nameValue === 'string') {
|
|
146
175
|
name = nameValue;
|
|
147
176
|
}
|
|
177
|
+
if (name !== undefined) {
|
|
178
|
+
options.name = name;
|
|
179
|
+
}
|
|
148
180
|
}
|
|
149
|
-
let author;
|
|
150
181
|
{
|
|
182
|
+
let author;
|
|
151
183
|
const authorValue = commandLineValues['author'];
|
|
152
184
|
if (authorValue == null || typeof authorValue === 'string') {
|
|
153
185
|
author = authorValue;
|
|
154
186
|
}
|
|
187
|
+
if (author !== undefined) {
|
|
188
|
+
options.author = author;
|
|
189
|
+
}
|
|
155
190
|
}
|
|
156
|
-
let description;
|
|
157
191
|
{
|
|
192
|
+
let description;
|
|
158
193
|
const descriptionValue = commandLineValues['description'];
|
|
159
194
|
if (descriptionValue == null || typeof descriptionValue === 'string') {
|
|
160
195
|
description = descriptionValue;
|
|
161
196
|
}
|
|
197
|
+
if (description !== undefined) {
|
|
198
|
+
options.description = description;
|
|
199
|
+
}
|
|
162
200
|
}
|
|
163
|
-
let serviceId;
|
|
164
201
|
{
|
|
202
|
+
let serviceId;
|
|
165
203
|
const serviceIdValue = commandLineValues['service-id'];
|
|
166
204
|
if (serviceIdValue == null || typeof serviceIdValue === 'string') {
|
|
167
205
|
serviceId = serviceIdValue;
|
|
168
206
|
}
|
|
207
|
+
if (serviceId !== undefined) {
|
|
208
|
+
options.serviceId = serviceId;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
{
|
|
212
|
+
let publishId;
|
|
213
|
+
const publishIdValue = commandLineValues['publish-id'];
|
|
214
|
+
if (publishIdValue == null || typeof publishIdValue === 'string') {
|
|
215
|
+
publishId = publishIdValue;
|
|
216
|
+
}
|
|
217
|
+
if (publishId !== undefined) {
|
|
218
|
+
options.publishId = publishId;
|
|
219
|
+
}
|
|
169
220
|
}
|
|
170
|
-
let kvStoreName;
|
|
171
221
|
{
|
|
222
|
+
let kvStoreName;
|
|
172
223
|
const kvStoreNameValue = commandLineValues['kv-store-name'];
|
|
173
224
|
if (kvStoreNameValue == null || typeof kvStoreNameValue === 'string') {
|
|
174
225
|
kvStoreName = kvStoreNameValue;
|
|
175
226
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
rootDir,
|
|
179
|
-
publicDir,
|
|
180
|
-
staticDirs,
|
|
181
|
-
staticContentRootDir,
|
|
182
|
-
spa,
|
|
183
|
-
notFoundPage,
|
|
184
|
-
autoIndex,
|
|
185
|
-
autoExt,
|
|
186
|
-
name,
|
|
187
|
-
author,
|
|
188
|
-
description,
|
|
189
|
-
serviceId,
|
|
190
|
-
kvStoreName,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
function pickKeys(keys, object) {
|
|
194
|
-
const result = {};
|
|
195
|
-
for (const key of keys) {
|
|
196
|
-
if (object[key] !== undefined) {
|
|
197
|
-
result[key] = object[key];
|
|
227
|
+
if (kvStoreName !== undefined) {
|
|
228
|
+
options.kvStoreName = kvStoreName;
|
|
198
229
|
}
|
|
199
230
|
}
|
|
200
|
-
return
|
|
231
|
+
return options;
|
|
201
232
|
}
|
|
202
233
|
const PUBLIC_DIR_TOKEN = '[public-dir]';
|
|
203
234
|
function processPublicDirToken(filepath, publicDir) {
|
|
204
235
|
if (!filepath.startsWith(PUBLIC_DIR_TOKEN)) {
|
|
205
|
-
return filepath;
|
|
236
|
+
return path.resolve(filepath);
|
|
206
237
|
}
|
|
207
238
|
const processedPath = '.' + filepath.slice(PUBLIC_DIR_TOKEN.length);
|
|
208
|
-
|
|
209
|
-
return path.relative(path.resolve(), resolvedPath);
|
|
239
|
+
return path.resolve(publicDir, processedPath);
|
|
210
240
|
}
|
|
211
|
-
export function
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
241
|
+
export async function action(argv) {
|
|
242
|
+
const optionDefinitions = [
|
|
243
|
+
{ name: 'verbose', type: Boolean },
|
|
244
|
+
// Required. The name of a Fastly KV Store to hold the content assets.
|
|
245
|
+
// It is also added to the fastly.toml that is generated.
|
|
246
|
+
{ name: 'kv-store-name', type: String, },
|
|
247
|
+
// Output directory. "Required" (if not specified, then defaultValue is used).
|
|
248
|
+
{ name: 'output', alias: 'o', type: String, defaultValue: './compute-js', },
|
|
249
|
+
// Name of the application, to be inserted into fastly.toml
|
|
250
|
+
{ name: 'name', type: String, },
|
|
251
|
+
// Description of the application, to be inserted into fastly.toml
|
|
252
|
+
{ name: 'description', type: String, },
|
|
253
|
+
// Name of the author, to be inserted into fastly.toml
|
|
254
|
+
{ name: 'author', type: String, },
|
|
255
|
+
// Fastly Service ID to be added to the fastly.toml that is generated.
|
|
256
|
+
{ name: 'service-id', type: String },
|
|
257
|
+
// Required. The 'root' directory for the publishing.
|
|
258
|
+
// All assets are expected to exist under this root. Required.
|
|
259
|
+
// For backwards compatibility, if this value is not provided,
|
|
260
|
+
// then the value of 'public-dir' is used.
|
|
261
|
+
{ name: 'root-dir', type: String, },
|
|
262
|
+
// Publish ID to be used as a prefix for all KV Store entries.
|
|
263
|
+
// If not provided, the default value of 'default' is used.
|
|
264
|
+
{ name: 'publish-id', type: String, },
|
|
265
|
+
// The 'static publisher working directory' is the directory under the Compute
|
|
266
|
+
// application where asset files are written in preparation for upload to the
|
|
267
|
+
// KV Store and for serving for local mode.
|
|
268
|
+
{ name: 'static-publisher-working-dir', type: String, },
|
|
269
|
+
// The 'public' directory. The Publisher Server will
|
|
270
|
+
// resolve requests relative to this directory. If not specified,
|
|
271
|
+
// defaults to the same value as 'root-dir'. See README for
|
|
272
|
+
// details.
|
|
273
|
+
{ name: 'public-dir', type: String, },
|
|
274
|
+
// Directories to specify as containing 'static' files. The
|
|
275
|
+
// Publisher Server will serve files from these directories
|
|
276
|
+
// with a long TTL.
|
|
277
|
+
{ name: 'static-dir', type: String, multiple: true, },
|
|
278
|
+
// Path to a file to be used to serve in a SPA application.
|
|
279
|
+
// The Publisher Server will serve this file with a 200 status code
|
|
280
|
+
// when the request doesn't match a known file, and the accept
|
|
281
|
+
// header includes text/html. You may use the '[public-dir]' token
|
|
282
|
+
// if you wish to specify this as a relative path from the 'public-dir'.
|
|
283
|
+
{ name: 'spa', type: String, },
|
|
284
|
+
// Path to a file to be used to serve as a 404 not found page.
|
|
285
|
+
// The Publisher Server will serve this file with a 404 status code
|
|
286
|
+
// when the request doesn't match a known file, and the accept
|
|
287
|
+
// header includes text/html. You may use the '[public-dir]' token
|
|
288
|
+
// if you wish to specify this as a relative path from the 'public-dir'.
|
|
289
|
+
{ name: 'not-found-page', type: String, },
|
|
290
|
+
// List of files to automatically use as index, for example, index.html,index.htm
|
|
291
|
+
// If a request comes in but the route does not exist, we check the route
|
|
292
|
+
// plus a slash plus the items in this array.
|
|
293
|
+
{ name: 'auto-index', type: String, multiple: true, },
|
|
294
|
+
// List of extensions to apply to a path name, for example, if
|
|
295
|
+
// http://example.com/about is requested, we can respond with http://example.com/about.html
|
|
296
|
+
{ name: 'auto-ext', type: String, multiple: true, },
|
|
297
|
+
];
|
|
298
|
+
const commandLineValues = commandLineArgs(optionDefinitions, { argv });
|
|
225
299
|
let packageJson;
|
|
226
300
|
try {
|
|
227
301
|
const packageJsonText = fs.readFileSync("./package.json", "utf-8");
|
|
@@ -231,53 +305,13 @@ export function initApp(commandLineValues) {
|
|
|
231
305
|
console.log("Can't read/parse package.json in current directory, making no assumptions!");
|
|
232
306
|
packageJson = null;
|
|
233
307
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
// This may be a file url if during development
|
|
242
|
-
if (computeJsStaticPublisherVersion != null) {
|
|
243
|
-
if (computeJsStaticPublisherVersion.startsWith('file:')) {
|
|
244
|
-
// this is a relative path from the current directory.
|
|
245
|
-
// we replace it with an absolute path
|
|
246
|
-
const relPath = computeJsStaticPublisherVersion.slice('file:'.length);
|
|
247
|
-
const absPath = path.resolve(relPath);
|
|
248
|
-
computeJsStaticPublisherVersion = 'file:' + absPath;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
if (computeJsStaticPublisherVersion == null) {
|
|
253
|
-
// Also try package.json of the package that contains the currently running program
|
|
254
|
-
// This is used when the program doesn't actually install the package (running via npx).
|
|
255
|
-
const computeJsStaticPublishPackageJsonPath = path.resolve(__dirname, '../../../package.json');
|
|
256
|
-
const computeJsStaticPublishPackageJsonText = fs.readFileSync(computeJsStaticPublishPackageJsonPath, 'utf-8');
|
|
257
|
-
const computeJsStaticPublishPackageJson = JSON.parse(computeJsStaticPublishPackageJsonText);
|
|
258
|
-
computeJsStaticPublisherVersion = computeJsStaticPublishPackageJson?.version;
|
|
259
|
-
}
|
|
260
|
-
if (computeJsStaticPublisherVersion == null) {
|
|
261
|
-
// Unexpected, but if it's still null then we go to a literal
|
|
262
|
-
computeJsStaticPublisherVersion = '^4.0.0';
|
|
263
|
-
}
|
|
264
|
-
const commandLineAppOptions = processCommandLineArgs(commandLineValues);
|
|
265
|
-
options = {
|
|
266
|
-
...options,
|
|
267
|
-
...(preset != null ? preset.defaultOptions : {}),
|
|
268
|
-
...pickKeys(['author', 'name', 'description'], (packageJson ?? {})),
|
|
269
|
-
...pickKeys(['rootDir', 'publicDir', 'staticDirs', 'staticContentRootDir', 'spa', 'notFoundPage', 'autoIndex', 'autoExt', 'author', 'name', 'description', 'serviceId', 'kvStoreName'], commandLineAppOptions),
|
|
270
|
-
};
|
|
271
|
-
if (preset != null) {
|
|
272
|
-
if (!preset.check(packageJson, options)) {
|
|
273
|
-
console.log("Failed preset check.");
|
|
274
|
-
process.exitCode = 1;
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
// Webpack now optional as of v4
|
|
279
|
-
const useWebpack = commandLineValues['webpack'];
|
|
280
|
-
const COMPUTE_JS_DIR = commandLineValues.output;
|
|
308
|
+
const options = buildOptions(packageJson, commandLineValues);
|
|
309
|
+
const COMPUTE_JS_DIR = options.outputDir;
|
|
310
|
+
if (COMPUTE_JS_DIR == null) {
|
|
311
|
+
console.error("❌ required parameter --output not provided.");
|
|
312
|
+
process.exitCode = 1;
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
281
315
|
const computeJsDir = path.resolve(COMPUTE_JS_DIR);
|
|
282
316
|
// Resolve the root dir, relative to current directory, and make sure it exists.
|
|
283
317
|
const ROOT_DIR = options.rootDir;
|
|
@@ -289,7 +323,7 @@ export function initApp(commandLineValues) {
|
|
|
289
323
|
const rootDir = path.resolve(ROOT_DIR);
|
|
290
324
|
if (!fs.existsSync(rootDir) || !fs.statSync(rootDir).isDirectory()) {
|
|
291
325
|
console.error(`❌ Specified root directory '${ROOT_DIR}' does not exist.`);
|
|
292
|
-
console.error(` * ${rootDir} must exist and be a directory.`);
|
|
326
|
+
console.error(` * ${rootRelative(rootDir)} must exist and be a directory.`);
|
|
293
327
|
process.exitCode = 1;
|
|
294
328
|
return;
|
|
295
329
|
}
|
|
@@ -298,14 +332,14 @@ export function initApp(commandLineValues) {
|
|
|
298
332
|
const publicDir = path.resolve(PUBLIC_DIR);
|
|
299
333
|
if (!fs.existsSync(publicDir) || !fs.statSync(publicDir).isDirectory()) {
|
|
300
334
|
console.error(`❌ Specified public directory '${PUBLIC_DIR}' does not exist.`);
|
|
301
|
-
console.error(` * ${publicDir} must exist and be a directory.`);
|
|
335
|
+
console.error(` * ${rootRelative(publicDir)} must exist and be a directory.`);
|
|
302
336
|
process.exitCode = 1;
|
|
303
337
|
return;
|
|
304
338
|
}
|
|
305
339
|
// Public dir must be inside the root dir.
|
|
306
340
|
if (!publicDir.startsWith(rootDir)) {
|
|
307
341
|
console.error(`❌ Specified public directory '${PUBLIC_DIR}' is not under the asset root directory.`);
|
|
308
|
-
console.error(` * ${publicDir} must be under ${rootDir}`);
|
|
342
|
+
console.error(` * ${rootRelative(publicDir)} must be under ${rootRelative(rootDir)}`);
|
|
309
343
|
process.exitCode = 1;
|
|
310
344
|
return;
|
|
311
345
|
}
|
|
@@ -314,68 +348,66 @@ export function initApp(commandLineValues) {
|
|
|
314
348
|
const staticDirs = [];
|
|
315
349
|
for (const STATIC_DIR of STATIC_DIRS) {
|
|
316
350
|
// For backwards compatibility, these values can start with [public-dir]
|
|
317
|
-
const staticDir =
|
|
351
|
+
const staticDir = processPublicDirToken(STATIC_DIR, publicDir);
|
|
318
352
|
if (!staticDir.startsWith(publicDir)) {
|
|
319
353
|
console.log(`⚠️ Ignoring static directory '${STATIC_DIR}'`);
|
|
320
|
-
console.log(` * ${staticDir} is not under ${publicDir}`);
|
|
354
|
+
console.log(` * ${rootRelative(staticDir)} is not under ${rootRelative(publicDir)}`);
|
|
321
355
|
continue;
|
|
322
356
|
}
|
|
323
357
|
if (!fs.existsSync(staticDir) || !fs.statSync(staticDir).isDirectory()) {
|
|
324
358
|
console.log(`⚠️ Ignoring static directory '${STATIC_DIR}'`);
|
|
325
|
-
console.log(` * ${staticDir} does not exist or is not a directory.`);
|
|
359
|
+
console.log(` * ${rootRelative(staticDir)} does not exist or is not a directory.`);
|
|
326
360
|
continue;
|
|
327
361
|
}
|
|
328
362
|
staticDirs.push(staticDir);
|
|
329
363
|
}
|
|
330
|
-
// Static
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (!
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
console.error(
|
|
364
|
+
// Static Publisher Working Root Dir must be under the current dir
|
|
365
|
+
// This comes in relative to cwd.
|
|
366
|
+
const STATIC_PUBLISHER_WORKING_DIR = options.staticPublisherWorkingDir ??
|
|
367
|
+
path.resolve(computeJsDir, './static-publisher');
|
|
368
|
+
const staticPublisherWorkingDir = path.resolve(STATIC_PUBLISHER_WORKING_DIR);
|
|
369
|
+
if (!staticPublisherWorkingDir.startsWith(computeJsDir) ||
|
|
370
|
+
staticPublisherWorkingDir === computeJsDir ||
|
|
371
|
+
staticPublisherWorkingDir === path.resolve(computeJsDir, './bin') ||
|
|
372
|
+
staticPublisherWorkingDir === path.resolve(computeJsDir, './pkg') ||
|
|
373
|
+
staticPublisherWorkingDir === path.resolve(computeJsDir, './src') ||
|
|
374
|
+
staticPublisherWorkingDir === path.resolve(computeJsDir, './node_modules')) {
|
|
375
|
+
console.error(`❌ Specified static publisher working directory '${rootRelative(staticPublisherWorkingDir)}' must be under ${rootRelative(computeJsDir)}.`);
|
|
376
|
+
console.error(` It also must not be bin, pkg, src, or node_modules.`);
|
|
342
377
|
process.exitCode = 1;
|
|
343
378
|
return;
|
|
344
379
|
}
|
|
345
|
-
staticContentRootDir = './' + path.relative(computeJsDir, staticContentRootDir);
|
|
346
380
|
// SPA and Not Found are relative to the asset root dir.
|
|
347
381
|
const SPA = options.spa;
|
|
348
382
|
let spaFilename;
|
|
349
383
|
if (SPA != null) {
|
|
350
384
|
// If it starts with [public-dir], then resolve it relative to public directory.
|
|
351
|
-
spaFilename =
|
|
385
|
+
spaFilename = processPublicDirToken(SPA, publicDir);
|
|
352
386
|
// At any rate it must exist under the root directory
|
|
353
387
|
if (!spaFilename.startsWith(rootDir)) {
|
|
354
388
|
console.log(`⚠️ Ignoring specified SPA file '${SPA}' as is not under the asset root directory.`);
|
|
355
|
-
console.log(` * ${spaFilename} is not under ${rootDir}`);
|
|
389
|
+
console.log(` * ${rootRelative(spaFilename)} is not under ${rootRelative(rootDir)}`);
|
|
356
390
|
spaFilename = undefined;
|
|
357
391
|
}
|
|
358
392
|
else if (!fs.existsSync(spaFilename)) {
|
|
359
|
-
console.log(`⚠️ Ignoring specified SPA file '${SPA}'
|
|
360
|
-
console.log(` * ${spaFilename} does not exist.`);
|
|
361
|
-
spaFilename = undefined;
|
|
393
|
+
console.log(`⚠️ Warning: Ignoring specified SPA file '${SPA}' does not exist.`);
|
|
394
|
+
console.log(` * ${rootRelative(spaFilename)} does not exist.`);
|
|
362
395
|
}
|
|
363
396
|
}
|
|
364
397
|
const NOT_FOUND_PAGE = options.notFoundPage;
|
|
365
398
|
let notFoundPageFilename;
|
|
366
399
|
if (NOT_FOUND_PAGE != null) {
|
|
367
400
|
// If it starts with [public-dir], then resolve it relative to public directory.
|
|
368
|
-
notFoundPageFilename =
|
|
401
|
+
notFoundPageFilename = processPublicDirToken(NOT_FOUND_PAGE, publicDir);
|
|
369
402
|
// At any rate it must exist under the root directory
|
|
370
403
|
if (!notFoundPageFilename.startsWith(rootDir)) {
|
|
371
404
|
console.log(`⚠️ Ignoring specified Not Found file '${NOT_FOUND_PAGE}' as is not under the asset root directory.`);
|
|
372
|
-
console.log(` * ${notFoundPageFilename} is not under ${rootDir}`);
|
|
405
|
+
console.log(` * ${rootRelative(notFoundPageFilename)} is not under ${rootRelative(rootDir)}`);
|
|
373
406
|
notFoundPageFilename = undefined;
|
|
374
407
|
}
|
|
375
408
|
else if (!fs.existsSync(notFoundPageFilename)) {
|
|
376
|
-
console.log(`⚠️ Ignoring specified Not Found file '${NOT_FOUND_PAGE}' as it does not exist.`);
|
|
377
|
-
console.log(` * ${notFoundPageFilename} does not exist.`);
|
|
378
|
-
notFoundPageFilename = undefined;
|
|
409
|
+
console.log(`⚠️ Warning: Ignoring specified Not Found file '${NOT_FOUND_PAGE}' as it does not exist.`);
|
|
410
|
+
console.log(` * ${rootRelative(notFoundPageFilename)} does not exist.`);
|
|
379
411
|
}
|
|
380
412
|
}
|
|
381
413
|
const autoIndex = options.autoIndex;
|
|
@@ -384,8 +416,9 @@ export function initApp(commandLineValues) {
|
|
|
384
416
|
if (exists) {
|
|
385
417
|
console.error(`❌ '${COMPUTE_JS_DIR}' directory already exists!`);
|
|
386
418
|
console.error(` You should not run this command if this directory exists.`);
|
|
387
|
-
console.error(` If you need to re-scaffold the static publisher
|
|
388
|
-
console.error(`
|
|
419
|
+
console.error(` If you need to re-scaffold the static publisher Compute App,`);
|
|
420
|
+
console.error(` delete the following directory and then try again:`);
|
|
421
|
+
console.error(` ${rootRelative(computeJsDir)}`);
|
|
389
422
|
process.exitCode = 1;
|
|
390
423
|
return;
|
|
391
424
|
}
|
|
@@ -394,116 +427,118 @@ export function initApp(commandLineValues) {
|
|
|
394
427
|
const description = options.description;
|
|
395
428
|
const fastlyServiceId = options.serviceId;
|
|
396
429
|
const kvStoreName = options.kvStoreName;
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
430
|
+
if (kvStoreName == null) {
|
|
431
|
+
console.error(`❌ required parameter --kv-store-name not provided.`);
|
|
432
|
+
process.exitCode = 1;
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
let publishId = options.publishId;
|
|
436
|
+
if (publishId == null) {
|
|
437
|
+
publishId = 'default';
|
|
403
438
|
}
|
|
439
|
+
const defaultCollectionName = 'live';
|
|
404
440
|
console.log('');
|
|
405
|
-
console.log('
|
|
406
|
-
console.log('
|
|
407
|
-
console.log('
|
|
408
|
-
console.log('
|
|
409
|
-
console.log('
|
|
410
|
-
console.log('
|
|
411
|
-
console.log('
|
|
412
|
-
console.log('
|
|
413
|
-
console.log('
|
|
414
|
-
console.log('
|
|
415
|
-
console.log('
|
|
416
|
-
console.log('
|
|
417
|
-
console.log('
|
|
441
|
+
console.log('Compute Application Settings');
|
|
442
|
+
console.log('----------------------------');
|
|
443
|
+
console.log('Compute Application Output Dir :', rootRelative(computeJsDir));
|
|
444
|
+
console.log('name :', name);
|
|
445
|
+
console.log('author :', author);
|
|
446
|
+
console.log('description :', description);
|
|
447
|
+
console.log('Service ID :', fastlyServiceId ?? '(None)');
|
|
448
|
+
console.log('KV Store Name :', kvStoreName);
|
|
449
|
+
console.log('Default Collection Name :', defaultCollectionName);
|
|
450
|
+
console.log('Publish ID :', publishId);
|
|
451
|
+
console.log('');
|
|
452
|
+
console.log('Publish Settings');
|
|
453
|
+
console.log('----------------');
|
|
454
|
+
console.log('Publish Root Dir :', rootRelative(rootDir));
|
|
455
|
+
console.log('Publisher Working Dir :', rootRelative(staticPublisherWorkingDir));
|
|
456
|
+
console.log('');
|
|
457
|
+
console.log('Publisher Server Settings');
|
|
458
|
+
console.log('-------------------------');
|
|
459
|
+
console.log('Server Public Dir :', rootRelative(publicDir));
|
|
460
|
+
console.log('SPA :', spaFilename != null ? rootRelative(spaFilename) : '(None)');
|
|
461
|
+
console.log('404 Page :', notFoundPageFilename != null ? rootRelative(notFoundPageFilename) : '(None)');
|
|
462
|
+
console.log('Auto-Index :', autoIndex.length > 0 ? autoIndex : '(None)');
|
|
463
|
+
console.log('Auto-Ext :', autoExt.length > 0 ? autoExt : '(None)');
|
|
464
|
+
console.log('Static Files Dir :', staticDirs.length > 0 ? staticDirs.map(rootRelative) : '(None)');
|
|
418
465
|
console.log('');
|
|
419
|
-
if (useWebpack) {
|
|
420
|
-
console.log('Creating project with Webpack.');
|
|
421
|
-
console.log('');
|
|
422
|
-
}
|
|
423
466
|
console.log("Initializing Compute Application in " + computeJsDir + "...");
|
|
424
467
|
fs.mkdirSync(computeJsDir);
|
|
425
468
|
fs.mkdirSync(path.resolve(computeJsDir, './src'));
|
|
426
|
-
const
|
|
427
|
-
let staticFiles = staticContentRootDirFromRoot;
|
|
428
|
-
if (staticContentRootDirFromRoot === '/src') {
|
|
429
|
-
staticFiles = `\
|
|
430
|
-
${staticContentRootDirFromRoot}/statics.js
|
|
431
|
-
${staticContentRootDirFromRoot}/statics.d.ts
|
|
432
|
-
${staticContentRootDirFromRoot}/statics-metadata.js
|
|
433
|
-
${staticContentRootDirFromRoot}/statics-metadata.d.ts
|
|
434
|
-
${staticContentRootDirFromRoot}/static-content`;
|
|
435
|
-
}
|
|
469
|
+
const resourceFiles = {};
|
|
436
470
|
// .gitignore
|
|
437
|
-
|
|
471
|
+
resourceFiles['.gitignore'] = `\
|
|
438
472
|
/node_modules
|
|
439
473
|
/bin
|
|
440
474
|
/pkg
|
|
441
|
-
|
|
475
|
+
/${path.relative(computeJsDir, staticPublisherWorkingDir)}
|
|
442
476
|
`;
|
|
443
|
-
const gitIgnorePath = path.resolve(computeJsDir, '.gitignore');
|
|
444
|
-
fs.writeFileSync(gitIgnorePath, gitIgnoreContent, "utf-8");
|
|
445
477
|
// package.json
|
|
446
|
-
const
|
|
478
|
+
const computeJsStaticPublisherVersion = findComputeJsStaticPublisherVersion(packageJson);
|
|
479
|
+
resourceFiles['package.json'] = JSON.stringify({
|
|
447
480
|
name,
|
|
448
481
|
version: '0.1.0',
|
|
449
482
|
description,
|
|
450
483
|
author,
|
|
451
484
|
type: 'module',
|
|
452
485
|
devDependencies: {
|
|
453
|
-
"@fastly/cli": "^
|
|
486
|
+
"@fastly/cli": "^11.2.0",
|
|
454
487
|
'@fastly/compute-js-static-publish': computeJsStaticPublisherVersion,
|
|
455
488
|
},
|
|
456
489
|
dependencies: {
|
|
457
|
-
'@fastly/js-compute': '^3.
|
|
490
|
+
'@fastly/js-compute': '^3.26.0',
|
|
458
491
|
},
|
|
459
492
|
engines: {
|
|
460
|
-
node: '>=
|
|
493
|
+
node: '>=20.11.0',
|
|
461
494
|
},
|
|
462
|
-
license: 'UNLICENSED',
|
|
463
495
|
private: true,
|
|
464
496
|
scripts: {
|
|
497
|
+
prestart: "npx @fastly/compute-js-static-publish publish-content --local-only",
|
|
465
498
|
start: "fastly compute serve",
|
|
466
499
|
deploy: "fastly compute publish",
|
|
467
|
-
|
|
500
|
+
"publish-content": 'npx @fastly/compute-js-static-publish publish-content',
|
|
468
501
|
build: 'js-compute-runtime ./src/index.js ./bin/main.wasm'
|
|
469
502
|
},
|
|
470
|
-
};
|
|
471
|
-
if (useWebpack) {
|
|
472
|
-
delete packageJsonContent.type;
|
|
473
|
-
packageJsonContent.devDependencies = {
|
|
474
|
-
...packageJsonContent.devDependencies,
|
|
475
|
-
'webpack': '^5.75.0',
|
|
476
|
-
'webpack-cli': '^5.0.0',
|
|
477
|
-
};
|
|
478
|
-
packageJsonContent.scripts = {
|
|
479
|
-
...packageJsonContent.scripts,
|
|
480
|
-
prebuild: 'npx @fastly/compute-js-static-publish --build-static && webpack',
|
|
481
|
-
build: 'js-compute-runtime ./bin/index.js ./bin/main.wasm'
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
const packageJsonContentJson = JSON.stringify(packageJsonContent, undefined, 2);
|
|
485
|
-
const packageJsonPath = path.resolve(computeJsDir, 'package.json');
|
|
486
|
-
fs.writeFileSync(packageJsonPath, packageJsonContentJson, "utf-8");
|
|
503
|
+
}, undefined, 2);
|
|
487
504
|
// fastly.toml
|
|
488
|
-
|
|
489
|
-
|
|
505
|
+
const localServerKvStorePath = dotRelative(computeJsDir, path.resolve(staticPublisherWorkingDir, 'kvstore.json'));
|
|
506
|
+
resourceFiles['fastly.toml'] = /* language=text */ `\
|
|
490
507
|
# This file describes a Fastly Compute package. To learn more visit:
|
|
491
508
|
# https://developer.fastly.com/reference/fastly-toml/
|
|
492
509
|
|
|
493
510
|
authors = [ "${author}" ]
|
|
494
511
|
description = "${description}"
|
|
495
512
|
language = "javascript"
|
|
496
|
-
manifest_version =
|
|
513
|
+
manifest_version = 3
|
|
497
514
|
name = "${name}"
|
|
498
|
-
${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
|
|
499
|
-
` : ''}
|
|
515
|
+
${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"\n` : ''}
|
|
500
516
|
[scripts]
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
517
|
+
build = "npm run build"
|
|
518
|
+
|
|
519
|
+
[local_server.kv_stores]
|
|
520
|
+
${kvStoreName} = { file = "${localServerKvStorePath}", format = "json" }
|
|
521
|
+
|
|
522
|
+
[setup.kv_stores.${kvStoreName}]
|
|
523
|
+
`;
|
|
524
|
+
// kvstore.json
|
|
525
|
+
resourceFiles[localServerKvStorePath] = '{}';
|
|
505
526
|
// static-publish.rc.js
|
|
506
|
-
|
|
527
|
+
resourceFiles['static-publish.rc.js'] = `\
|
|
528
|
+
/*
|
|
529
|
+
* Generated by @fastly/compute-js-static-publish.
|
|
530
|
+
*/
|
|
531
|
+
|
|
532
|
+
/** @type {import('@fastly/compute-js-static-publish').StaticPublishRc} */
|
|
533
|
+
const rc = {
|
|
534
|
+
kvStoreName: ${JSON.stringify(kvStoreName)},
|
|
535
|
+
publishId: ${JSON.stringify(publishId)},
|
|
536
|
+
defaultCollectionName: ${JSON.stringify(defaultCollectionName)},
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
export default rc;
|
|
540
|
+
`;
|
|
541
|
+
// publish-content.config.js
|
|
507
542
|
// publicDirPrefix -- if public dir is deeper than the root dir, then
|
|
508
543
|
// public dir is used as a prefix to drill into asset names.
|
|
509
544
|
// e.g.,
|
|
@@ -539,33 +574,32 @@ ${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
|
|
|
539
574
|
// and that it exists
|
|
540
575
|
notFoundPageFile = notFoundPageFilename.slice(rootDir.length);
|
|
541
576
|
}
|
|
542
|
-
|
|
577
|
+
resourceFiles['publish-content.config.js'] = `\
|
|
543
578
|
/*
|
|
544
|
-
*
|
|
545
|
-
* Licensed under the MIT license. See LICENSE file for details.
|
|
579
|
+
* Generated by @fastly/compute-js-static-publish.
|
|
546
580
|
*/
|
|
547
581
|
|
|
548
582
|
// Commented items are defaults, feel free to modify and experiment!
|
|
549
583
|
// See README for a detailed explanation of the configuration options.
|
|
550
584
|
|
|
551
|
-
/** @type {import('@fastly/compute-js-static-publish').
|
|
585
|
+
/** @type {import('@fastly/compute-js-static-publish').PublishContentConfig} */
|
|
552
586
|
const config = {
|
|
553
|
-
rootDir: ${JSON.stringify(
|
|
554
|
-
|
|
555
|
-
${(kvStoreName != null ? 'kvStoreName: ' + JSON.stringify(kvStoreName) : '// kvStoreName: false')},
|
|
587
|
+
rootDir: ${JSON.stringify(dotRelative(computeJsDir, rootDir))},
|
|
588
|
+
staticPublisherWorkingDir: ${JSON.stringify(dotRelative(computeJsDir, staticPublisherWorkingDir))},
|
|
556
589
|
// excludeDirs: [ './node_modules' ],
|
|
557
590
|
// excludeDotFiles: true,
|
|
558
591
|
// includeWellKnown: true,
|
|
559
|
-
//
|
|
560
|
-
// contentCompression: [ 'br', 'gzip' ],
|
|
561
|
-
// moduleAssetInclusionTest: (filename) => false,
|
|
592
|
+
// kvStoreAssetInclusionTest: (assetKey) => true,
|
|
593
|
+
// contentCompression: [ 'br', 'gzip' ],
|
|
562
594
|
// contentTypes: [
|
|
563
595
|
// { test: /.custom$/, contentType: 'application/x-custom', text: false },
|
|
564
596
|
// ],
|
|
597
|
+
|
|
598
|
+
// Server settings are saved to the KV Store per collection
|
|
565
599
|
server: {
|
|
566
600
|
publicDirPrefix: ${JSON.stringify(publicDirPrefix)},
|
|
567
601
|
staticItems: ${JSON.stringify(staticItems)},
|
|
568
|
-
|
|
602
|
+
allowedEncodings: [ 'br', 'gzip' ],
|
|
569
603
|
spaFile: ${JSON.stringify(spaFile)},
|
|
570
604
|
notFoundPageFile: ${JSON.stringify(notFoundPageFile)},
|
|
571
605
|
autoExt: ${JSON.stringify(autoExt)},
|
|
@@ -573,31 +607,20 @@ const config = {
|
|
|
573
607
|
},
|
|
574
608
|
};
|
|
575
609
|
|
|
576
|
-
|
|
610
|
+
export default config;
|
|
577
611
|
`;
|
|
578
|
-
const staticPublishJsonPath = path.resolve(computeJsDir, 'static-publish.rc.js');
|
|
579
|
-
fs.writeFileSync(staticPublishJsonPath, staticPublishJsContent, "utf-8");
|
|
580
|
-
// Copy resource files
|
|
581
|
-
if (useWebpack) {
|
|
582
|
-
// webpack.config.js
|
|
583
|
-
const webpackConfigJsSrcPath = path.resolve(__dirname, '../../../resources/webpack.config.js');
|
|
584
|
-
const webpackConfigJsPath = path.resolve(computeJsDir, 'webpack.config.js');
|
|
585
|
-
fs.copyFileSync(webpackConfigJsSrcPath, webpackConfigJsPath);
|
|
586
|
-
}
|
|
587
612
|
// src/index.js
|
|
588
|
-
|
|
589
|
-
path.relative('./src', staticContentRootDir) :
|
|
590
|
-
'.';
|
|
591
|
-
const indexJsContent = /* language=JavaScript */ `\
|
|
613
|
+
resourceFiles['./src/index.js'] = /* language=text */ `\
|
|
592
614
|
/// <reference types="@fastly/js-compute" />
|
|
593
|
-
import {
|
|
594
|
-
|
|
615
|
+
import { PublisherServer } from '@fastly/compute-js-static-publish';
|
|
616
|
+
import rc from '../static-publish.rc.js';
|
|
617
|
+
const publisherServer = PublisherServer.fromStaticPublishRc(rc);
|
|
595
618
|
|
|
596
619
|
// eslint-disable-next-line no-restricted-globals
|
|
597
620
|
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
|
|
598
621
|
async function handleRequest(event) {
|
|
599
622
|
|
|
600
|
-
const response = await
|
|
623
|
+
const response = await publisherServer.serveRequest(event.request);
|
|
601
624
|
if (response != null) {
|
|
602
625
|
return response;
|
|
603
626
|
}
|
|
@@ -608,8 +631,12 @@ async function handleRequest(event) {
|
|
|
608
631
|
return new Response('Not found', { status: 404 });
|
|
609
632
|
}
|
|
610
633
|
`;
|
|
611
|
-
|
|
612
|
-
|
|
634
|
+
// Write out the files
|
|
635
|
+
for (const [filename, content] of Object.entries(resourceFiles)) {
|
|
636
|
+
const filePath = path.resolve(computeJsDir, filename);
|
|
637
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
638
|
+
fs.writeFileSync(filePath, content, 'utf-8');
|
|
639
|
+
}
|
|
613
640
|
console.log("🚀 Compute application created!");
|
|
614
641
|
console.log('Installing dependencies...');
|
|
615
642
|
console.log(`npm --prefix ${COMPUTE_JS_DIR} install`);
|