@fastly/compute-js-static-publish 3.5.0 → 4.0.0-alpha.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/README.md +440 -103
- package/build/assets/asset-manager.d.ts +7 -0
- package/build/assets/asset-manager.d.ts.map +1 -0
- package/build/assets/asset-manager.js +11 -0
- package/build/assets/content-assets.d.ts +29 -0
- package/build/assets/content-assets.d.ts.map +1 -0
- package/build/assets/content-assets.js +88 -0
- package/build/assets/module-assets.d.ts +23 -0
- package/build/assets/module-assets.d.ts.map +1 -0
- package/build/assets/module-assets.js +45 -0
- package/build/cli/build-static.d.ts.map +1 -0
- package/build/cli/build-static.js +524 -0
- package/build/cli/clean-object-store.d.ts +2 -0
- package/build/cli/clean-object-store.d.ts.map +1 -0
- package/build/cli/cli.d.ts.map +1 -0
- package/build/{cli.js → cli/cli.js} +0 -0
- package/build/cli/commands/build-static.d.ts +3 -0
- package/build/cli/commands/build-static.d.ts.map +1 -0
- package/build/cli/commands/build-static.js +501 -0
- package/build/cli/commands/clean-object-store.d.ts +3 -0
- package/build/cli/commands/clean-object-store.d.ts.map +1 -0
- package/build/cli/commands/clean-object-store.js +54 -0
- package/build/cli/commands/init-app.d.ts.map +1 -0
- package/build/cli/commands/init-app.js +559 -0
- package/build/cli/compression/brotli.d.ts +3 -0
- package/build/cli/compression/brotli.d.ts.map +1 -0
- package/build/cli/compression/brotli.js +15 -0
- package/build/cli/compression/gzip.d.ts +3 -0
- package/build/cli/compression/gzip.d.ts.map +1 -0
- package/build/cli/compression/gzip.js +15 -0
- package/build/cli/compression/index.d.ts +8 -0
- package/build/cli/compression/index.d.ts.map +1 -0
- package/build/cli/compression/index.js +12 -0
- package/build/cli/index.d.ts +3 -0
- package/build/cli/index.d.ts.map +1 -0
- package/build/cli/index.js +86 -0
- package/build/cli/init-app.d.ts +3 -0
- package/build/cli/init-app.d.ts.map +1 -0
- package/build/{init-app.js → cli/init-app.js} +16 -16
- package/build/cli/load-config.d.ts +3 -0
- package/build/cli/load-config.d.ts.map +1 -0
- package/build/cli/load-config.js +357 -0
- package/build/cli/presets/implementations/create-react-app.d.ts +11 -0
- package/build/cli/presets/implementations/create-react-app.d.ts.map +1 -0
- package/build/cli/presets/implementations/create-react-app.js +34 -0
- package/build/cli/presets/implementations/docusaurus.d.ts +7 -0
- package/build/cli/presets/implementations/docusaurus.d.ts.map +1 -0
- package/build/cli/presets/implementations/docusaurus.js +13 -0
- package/build/cli/presets/implementations/gatsby.d.ts +7 -0
- package/build/cli/presets/implementations/gatsby.d.ts.map +1 -0
- package/build/cli/presets/implementations/gatsby.js +13 -0
- package/build/cli/presets/implementations/next.d.ts +7 -0
- package/build/cli/presets/implementations/next.d.ts.map +1 -0
- package/build/cli/presets/implementations/next.js +13 -0
- package/build/cli/presets/implementations/sveltekit.d.ts +7 -0
- package/build/cli/presets/implementations/sveltekit.d.ts.map +1 -0
- package/build/cli/presets/implementations/sveltekit.js +13 -0
- package/build/cli/presets/implementations/vite.d.ts +7 -0
- package/build/cli/presets/implementations/vite.d.ts.map +1 -0
- package/build/cli/presets/implementations/vite.js +13 -0
- package/build/cli/presets/index.d.ts +3 -0
- package/build/cli/presets/index.d.ts.map +1 -0
- package/build/cli/presets/index.js +16 -0
- package/build/cli/presets/preset-base.d.ts +19 -0
- package/build/cli/presets/preset-base.d.ts.map +1 -0
- package/build/cli/util/data.d.ts +7 -0
- package/build/cli/util/data.d.ts.map +1 -0
- package/build/cli/util/data.js +58 -0
- package/build/cli/util/fastly-api.d.ts +10 -0
- package/build/cli/util/fastly-api.d.ts.map +1 -0
- package/build/cli/util/fastly-api.js +47 -0
- package/build/cli/util/files.d.ts +11 -0
- package/build/cli/util/files.d.ts.map +1 -0
- package/build/cli/util/files.js +33 -0
- package/build/cli/util/hash.d.ts +2 -0
- package/build/cli/util/hash.d.ts.map +1 -0
- package/build/cli/util/hash.js +8 -0
- package/build/cli/util/id.d.ts +3 -0
- package/build/cli/util/id.d.ts.map +1 -0
- package/build/cli/util/id.js +17 -0
- package/build/cli/util/object-store.d.ts +16 -0
- package/build/cli/util/object-store.d.ts.map +1 -0
- package/build/cli/util/object-store.js +108 -0
- package/build/cli/util/publish-id.d.ts +5 -0
- package/build/cli/util/publish-id.d.ts.map +1 -0
- package/build/cli/util/publish-id.js +26 -0
- package/build/constants/compression.d.ts +3 -0
- package/build/constants/compression.d.ts.map +1 -0
- package/build/constants/compression.js +4 -0
- package/build/index.d.ts +5 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -1
- package/build/presets/implementations/create-react-app.js +1 -2
- package/build/presets/preset-base.d.ts +1 -1
- package/build/presets/preset-base.d.ts.map +1 -1
- package/build/server/assets/asset-manager.d.ts +7 -0
- package/build/server/assets/asset-manager.d.ts.map +1 -0
- package/build/server/assets/asset-manager.js +11 -0
- package/build/server/assets/content-assets.d.ts +33 -0
- package/build/server/assets/content-assets.d.ts.map +1 -0
- package/build/server/assets/content-assets.js +135 -0
- package/build/server/assets/module-assets.d.ts +23 -0
- package/build/server/assets/module-assets.d.ts.map +1 -0
- package/build/server/assets/module-assets.js +45 -0
- package/build/server/object-store/include-bytes-store-entry.d.ts +19 -0
- package/build/server/object-store/include-bytes-store-entry.d.ts.map +1 -0
- package/build/server/object-store/include-bytes-store-entry.js +87 -0
- package/build/server/object-store/inline-store-entry.d.ts +23 -0
- package/build/server/object-store/inline-store-entry.d.ts.map +1 -0
- package/build/server/object-store/inline-store-entry.js +95 -0
- package/build/server/publisher-server.d.ts +23 -0
- package/build/server/publisher-server.d.ts.map +1 -0
- package/build/server/publisher-server.js +224 -0
- package/build/server/serve-preconditions/if-modified-since.d.ts +4 -0
- package/build/server/serve-preconditions/if-modified-since.d.ts.map +1 -0
- package/build/server/serve-preconditions/if-modified-since.js +26 -0
- package/build/server/serve-preconditions/if-none-match.d.ts +3 -0
- package/build/server/serve-preconditions/if-none-match.d.ts.map +1 -0
- package/build/server/serve-preconditions/if-none-match.js +24 -0
- package/build/server/util/http.d.ts +2 -0
- package/build/server/util/http.d.ts.map +1 -0
- package/build/server/util/http.js +9 -0
- package/build/types/compute.d.ts +10 -0
- package/build/types/compute.d.ts.map +1 -0
- package/build/types/compute.js +1 -0
- package/build/types/config-normalized.d.ts +33 -0
- package/build/types/config-normalized.d.ts.map +1 -0
- package/build/types/config-normalized.js +1 -0
- package/build/types/config.d.ts +36 -0
- package/build/types/config.d.ts.map +1 -0
- package/build/types/config.js +1 -0
- package/build/types/content-assets.d.ts +37 -0
- package/build/types/content-assets.d.ts.map +1 -0
- package/build/types/content-assets.js +1 -0
- package/build/types/content-types.d.ts +11 -0
- package/build/types/content-types.d.ts.map +1 -0
- package/build/types/content-types.js +1 -0
- package/build/types/index.d.ts +7 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +1 -0
- package/build/types/module-assets.d.ts +15 -0
- package/build/types/module-assets.d.ts.map +1 -0
- package/build/types/module-assets.js +1 -0
- package/build/types/util.d.ts +7 -0
- package/build/types/util.d.ts.map +1 -0
- package/build/types/util.js +1 -0
- package/build/util/content-types.d.ts +5 -0
- package/build/util/content-types.d.ts.map +1 -0
- package/build/util/content-types.js +92 -0
- package/build/util/data.d.ts +7 -0
- package/build/util/data.d.ts.map +1 -0
- package/build/util/data.js +58 -0
- package/build/util/fastly-api.d.ts +10 -0
- package/build/util/fastly-api.d.ts.map +1 -0
- package/build/util/fastly-api.js +47 -0
- package/build/util/files.d.ts +10 -0
- package/build/util/files.d.ts.map +1 -0
- package/build/util/files.js +32 -0
- package/build/util/hash.d.ts +2 -0
- package/build/util/hash.d.ts.map +1 -0
- package/build/util/hash.js +8 -0
- package/build/util/id.d.ts +3 -0
- package/build/util/id.d.ts.map +1 -0
- package/build/util/id.js +17 -0
- package/build/util/index.d.ts +3 -0
- package/build/util/index.d.ts.map +1 -0
- package/build/util/index.js +2 -0
- package/build/util/metadata.d.ts +3 -0
- package/build/util/metadata.d.ts.map +1 -0
- package/build/util/metadata.js +12 -0
- package/build/util/object-store.d.ts +12 -0
- package/build/util/object-store.d.ts.map +1 -0
- package/build/util/object-store.js +80 -0
- package/package.json +11 -6
- package/resources/index.js +9 -114
- package/resources/statics-metadata.d.ts +10 -0
- package/resources/statics.d.ts +15 -7
- package/resources/webpack.config.js +4 -10
- package/build/assets.d.ts +0 -8
- package/build/assets.d.ts.map +0 -1
- package/build/assets.js +0 -24
- package/build/build-static.d.ts.map +0 -1
- package/build/build-static.js +0 -249
- package/build/cli.d.ts.map +0 -1
- package/build/init-app.d.ts.map +0 -1
- package/build/static-assets.d.ts +0 -11
- package/build/static-assets.d.ts.map +0 -1
- package/build/static-assets.js +0 -33
- package/build/types.d.ts +0 -50
- package/build/types.d.ts.map +0 -1
- package/resources/default-content-types.cjs +0 -105
- /package/build/{build-static.d.ts → cli/build-static.d.ts} +0 -0
- /package/build/{content-types.js → cli/clean-object-store.js} +0 -0
- /package/build/{cli.d.ts → cli/cli.d.ts} +0 -0
- /package/build/{init-app.d.ts → cli/commands/init-app.d.ts} +0 -0
- /package/build/{types.js → cli/presets/preset-base.js} +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import commandLineArgs from "command-line-args";
|
|
3
|
+
import { initApp } from "./commands/init-app.js";
|
|
4
|
+
import { buildStaticLoader } from "./commands/build-static.js";
|
|
5
|
+
import { cleanObjectStore } from "./commands/clean-object-store.js";
|
|
6
|
+
const optionDefinitions = [
|
|
7
|
+
// (optional) Should be one of:
|
|
8
|
+
// - cra (or create-react-app)
|
|
9
|
+
// - vite
|
|
10
|
+
// - sveltekit
|
|
11
|
+
// - next
|
|
12
|
+
// - gatsby
|
|
13
|
+
// - docusaurus
|
|
14
|
+
{ name: 'preset', type: String, },
|
|
15
|
+
{ name: 'build-static', type: Boolean },
|
|
16
|
+
{ name: 'suppress-framework-warnings', type: Boolean },
|
|
17
|
+
{ name: 'output', alias: 'o', type: String, defaultValue: './compute-js', },
|
|
18
|
+
// Whether the scaffolded project should use Webpack to bundle assets.
|
|
19
|
+
{ name: 'webpack', type: Boolean, defaultValue: false },
|
|
20
|
+
// The 'root' directory for the publishing.
|
|
21
|
+
// All assets are expected to exist under this root. Required.
|
|
22
|
+
// For backwards compatibility, if this value is not provided,
|
|
23
|
+
// then the value of 'public-dir' is used.
|
|
24
|
+
{ name: 'root-dir', type: String, },
|
|
25
|
+
// The 'public' directory. The Publisher Server will
|
|
26
|
+
// resolve requests relative to this directory. Specify this as
|
|
27
|
+
// a relative path from 'root-dir'. Defaults to './'.
|
|
28
|
+
{ name: 'public-dir', type: String, },
|
|
29
|
+
// Directories to specify as containing 'static' files. The
|
|
30
|
+
// Publisher Server will serve files from these directories
|
|
31
|
+
// with a long TTL. Each entry should be a relative path
|
|
32
|
+
// from 'public-dir'.
|
|
33
|
+
{ name: 'static-dir', type: String, multiple: true, },
|
|
34
|
+
// Path to a file to be used to serve in a SPA application.
|
|
35
|
+
// The Publisher Server will serve this file with a 200 status code
|
|
36
|
+
// when the request doesn't match a known file, and the accept
|
|
37
|
+
// header includes text/html. Specify this as a relative path
|
|
38
|
+
// from 'root-dir'. You may use the '[public-dir]' token if you wish
|
|
39
|
+
// to specify this as a relative path from the 'public-dir'.
|
|
40
|
+
{ name: 'spa', type: String, },
|
|
41
|
+
// Path to a file to be used to serve as a 404 not found page.
|
|
42
|
+
// The Publisher Server will serve this file with a 404 status code
|
|
43
|
+
// when the request doesn't match a known file, and the accept
|
|
44
|
+
// header includes text/html. Specify this as a relative path
|
|
45
|
+
// from 'root-dir'. You may use the '[public-dir]' token if you wish
|
|
46
|
+
// to specify this as a relative path from the 'public-dir'.
|
|
47
|
+
{ name: 'not-found-page', type: String, },
|
|
48
|
+
// List of files to automatically use as index, for example, index.html,index.htm
|
|
49
|
+
// If a request comes in but the route does not exist, we check the route
|
|
50
|
+
// plus a slash plus the items in this array.
|
|
51
|
+
{ name: 'auto-index', type: String, multiple: true, },
|
|
52
|
+
// List of extensions to apply to a path name, for example, if
|
|
53
|
+
// http://example.com/about is requested, we can respond with http://example.com/about.html
|
|
54
|
+
{ name: 'auto-ext', type: String, multiple: true, },
|
|
55
|
+
// Components from fastly.toml
|
|
56
|
+
// Name of the application, to be inserted into fastly.toml
|
|
57
|
+
{ name: 'name', type: String, },
|
|
58
|
+
// Name of the author, to be inserted into fastly.toml
|
|
59
|
+
{ name: 'author', type: String, },
|
|
60
|
+
// Description of the application, to be inserted into fastly.toml
|
|
61
|
+
{ name: 'description', type: String, },
|
|
62
|
+
// Fastly Service ID to be added to the fastly.toml that is generated.
|
|
63
|
+
{ name: 'service-id', type: String },
|
|
64
|
+
// Clean object store mode
|
|
65
|
+
{ name: 'clean-object-store', type: Boolean, },
|
|
66
|
+
];
|
|
67
|
+
const commandLineValues = commandLineArgs(optionDefinitions);
|
|
68
|
+
console.log("Fastly Compute@Edge JavaScript Static Publisher");
|
|
69
|
+
let mode = 'init-app';
|
|
70
|
+
if (commandLineValues['build-static']) {
|
|
71
|
+
mode = 'build-static';
|
|
72
|
+
}
|
|
73
|
+
else if (commandLineValues['clean-object-store']) {
|
|
74
|
+
mode = 'clean-object-store';
|
|
75
|
+
}
|
|
76
|
+
switch (mode) {
|
|
77
|
+
case 'build-static':
|
|
78
|
+
await buildStaticLoader(commandLineValues);
|
|
79
|
+
break;
|
|
80
|
+
case 'init-app':
|
|
81
|
+
initApp(commandLineValues);
|
|
82
|
+
break;
|
|
83
|
+
case 'clean-object-store':
|
|
84
|
+
await cleanObjectStore(commandLineValues);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../../src/cli/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAiDvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QAgS5D"}
|
|
@@ -35,10 +35,9 @@ function applyPublicDir(optionValue, publicDir) {
|
|
|
35
35
|
return optionValue.replace('[public-dir]', publicDir);
|
|
36
36
|
}
|
|
37
37
|
export function initApp(commandLineValues) {
|
|
38
|
-
var _a;
|
|
39
38
|
let options = defaultOptions;
|
|
40
39
|
let preset = null;
|
|
41
|
-
const presetName =
|
|
40
|
+
const presetName = commandLineValues['preset'] ?? 'none';
|
|
42
41
|
if (presetName !== 'none') {
|
|
43
42
|
const presetClass = presets[presetName];
|
|
44
43
|
if (presetClass == null) {
|
|
@@ -54,14 +53,14 @@ export function initApp(commandLineValues) {
|
|
|
54
53
|
const packageJsonText = fs.readFileSync("./package.json", "utf-8");
|
|
55
54
|
packageJson = JSON.parse(packageJsonText);
|
|
56
55
|
}
|
|
57
|
-
catch
|
|
56
|
+
catch {
|
|
58
57
|
console.log("Can't read/parse package.json in current directory, making no assumptions!");
|
|
59
58
|
packageJson = null;
|
|
60
59
|
}
|
|
61
60
|
options = {
|
|
62
61
|
...options,
|
|
63
62
|
...(preset != null ? preset.defaultOptions : {}),
|
|
64
|
-
...pickKeys(['author', 'name', 'description'], packageJson
|
|
63
|
+
...pickKeys(['author', 'name', 'description'], packageJson ?? {}),
|
|
65
64
|
...pickKeys(['public-dir', 'static-dir', 'spa', 'not-found-page', 'auto-index', 'auto-ext', 'author', 'name', 'description', 'service-id'], commandLineValues)
|
|
66
65
|
};
|
|
67
66
|
if (preset != null) {
|
|
@@ -142,15 +141,15 @@ export function initApp(commandLineValues) {
|
|
|
142
141
|
}
|
|
143
142
|
console.log('');
|
|
144
143
|
console.log('Public Dir :', PUBLIC_DIR);
|
|
145
|
-
console.log('Static Dir :', BUILD_STATIC_DIR
|
|
146
|
-
console.log('SPA :', spaRel
|
|
147
|
-
console.log('404 Page :', notFoundRel
|
|
148
|
-
console.log('Auto-Index :', autoIndex
|
|
149
|
-
console.log('Auto-Ext :', autoExt
|
|
144
|
+
console.log('Static Dir :', BUILD_STATIC_DIR ?? '(None)');
|
|
145
|
+
console.log('SPA :', spaRel ?? '(None)');
|
|
146
|
+
console.log('404 Page :', notFoundRel ?? '(None)');
|
|
147
|
+
console.log('Auto-Index :', autoIndex ?? '(None)');
|
|
148
|
+
console.log('Auto-Ext :', autoExt ?? '(None)');
|
|
150
149
|
console.log('name :', name);
|
|
151
150
|
console.log('author :', author);
|
|
152
151
|
console.log('description :', description);
|
|
153
|
-
console.log('Service ID :', fastlyServiceId
|
|
152
|
+
console.log('Service ID :', fastlyServiceId ?? '(None)');
|
|
154
153
|
console.log('');
|
|
155
154
|
console.log("Initializing Compute@Edge Application in " + computeJsDir + "...");
|
|
156
155
|
fs.mkdirSync(computeJsDir);
|
|
@@ -162,6 +161,8 @@ export function initApp(commandLineValues) {
|
|
|
162
161
|
/pkg
|
|
163
162
|
/src/statics.js
|
|
164
163
|
/src/statics.d.ts
|
|
164
|
+
/src/statics-metadata.js
|
|
165
|
+
/src/statics-metadata.d.ts
|
|
165
166
|
/src/static-content
|
|
166
167
|
`;
|
|
167
168
|
const gitIgnorePath = path.resolve(computeJsDir, '.gitignore');
|
|
@@ -174,13 +175,12 @@ export function initApp(commandLineValues) {
|
|
|
174
175
|
"description": ${JSON.stringify(description)},
|
|
175
176
|
"author": ${JSON.stringify(author)},
|
|
176
177
|
"devDependencies": {
|
|
177
|
-
"@fastly/compute-js-static-publish": "^
|
|
178
|
-
"@fastly/expressly": "^1.0.0-beta.2",
|
|
178
|
+
"@fastly/compute-js-static-publish": "^4.0.0-alpha.0",
|
|
179
179
|
"webpack": "^5.75.0",
|
|
180
180
|
"webpack-cli": "^5.0.0"
|
|
181
181
|
},
|
|
182
182
|
"dependencies": {
|
|
183
|
-
"@fastly/js-compute": "^1.
|
|
183
|
+
"@fastly/js-compute": "^1.4.0"
|
|
184
184
|
},
|
|
185
185
|
"engines": {
|
|
186
186
|
"node": ">=16.0.0"
|
|
@@ -241,7 +241,7 @@ ${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
|
|
|
241
241
|
notFoundFileRel = '/' + path.relative(publicDir, notFoundPageFilename);
|
|
242
242
|
}
|
|
243
243
|
const staticPublishJsContent = `\
|
|
244
|
-
/** @type {import('@fastly/compute-js-static-publish').
|
|
244
|
+
/** @type {import('@fastly/compute-js-static-publish').StaticPublisherConfig} */
|
|
245
245
|
module.exports = {
|
|
246
246
|
publicDir: ${JSON.stringify(publicDirRel)},
|
|
247
247
|
excludeDirs: [ './node_modules' ],
|
|
@@ -257,11 +257,11 @@ module.exports = {
|
|
|
257
257
|
// Copy resource files
|
|
258
258
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
259
259
|
// webpack.config.js
|
|
260
|
-
const webpackConfigJsSrcPath = path.resolve(__dirname, '
|
|
260
|
+
const webpackConfigJsSrcPath = path.resolve(__dirname, '../../resources/webpack.config.js');
|
|
261
261
|
const webpackConfigJsPath = path.resolve(computeJsDir, 'webpack.config.js');
|
|
262
262
|
fs.copyFileSync(webpackConfigJsSrcPath, webpackConfigJsPath);
|
|
263
263
|
// src/index.js
|
|
264
|
-
const indexJsSrcPath = path.resolve(__dirname, '
|
|
264
|
+
const indexJsSrcPath = path.resolve(__dirname, '../../resources/index.js');
|
|
265
265
|
const indexJsPath = path.resolve(computeJsDir, './src/index.js');
|
|
266
266
|
fs.copyFileSync(indexJsSrcPath, indexJsPath);
|
|
267
267
|
console.log("🚀 Compute@Edge application created!");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../src/cli/load-config.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,+BAA+B,EAEhC,MAAM,+BAA+B,CAAC;AAqVvC,wBAAsB,cAAc,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,+BAA+B,GAAG,IAAI,CAAC,CAgB3G"}
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import globToRegExp from 'glob-to-regexp';
|
|
3
|
+
import { buildNormalizeFunctionForArray, buildNormalizeFunctionForObject, isSpecified, isStringAndNotEmpty, } from "./util/data.js";
|
|
4
|
+
const normalizeContentTypeDef = buildNormalizeFunctionForObject((config, errors) => {
|
|
5
|
+
let { test, type, binary } = config;
|
|
6
|
+
if (typeof test === 'function' || test instanceof RegExp) {
|
|
7
|
+
// ok
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
errors.push('test cannot be null.');
|
|
11
|
+
}
|
|
12
|
+
if (isStringAndNotEmpty(type)) {
|
|
13
|
+
// ok
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
errors.push('type must be a non-empty string.');
|
|
17
|
+
}
|
|
18
|
+
if (!isSpecified(config, 'binary')) {
|
|
19
|
+
binary = false;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
if (typeof binary === 'boolean') {
|
|
23
|
+
// ok
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
errors.push('binary, if specified, must be a boolean value.');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (errors.length > 0) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
test,
|
|
34
|
+
contentType: type,
|
|
35
|
+
binary,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
const normalizeContentTypeDefs = buildNormalizeFunctionForArray((config, errors) => {
|
|
39
|
+
return normalizeContentTypeDef(config, errors);
|
|
40
|
+
});
|
|
41
|
+
const normalizePublisherServerConfig = buildNormalizeFunctionForObject((config, errors) => {
|
|
42
|
+
let { publicDirPrefix, staticItems, compression, spaFile, notFoundPageFile, autoExt, autoIndex } = config;
|
|
43
|
+
if (!isSpecified(config, 'publicDirPrefix')) {
|
|
44
|
+
publicDirPrefix = '';
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
if (typeof publicDirPrefix === 'string') {
|
|
48
|
+
// ok
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
errors.push('publicDirPrefix, if specified, must be a string value.');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!isSpecified(config, 'staticItems')) {
|
|
55
|
+
staticItems = [];
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (staticItems === null || staticItems === false) {
|
|
59
|
+
staticItems = [];
|
|
60
|
+
}
|
|
61
|
+
if (!Array.isArray(staticItems)) {
|
|
62
|
+
staticItems = [staticItems];
|
|
63
|
+
}
|
|
64
|
+
if (staticItems.every((x) => typeof x === 'string')) {
|
|
65
|
+
staticItems = staticItems.map((x, index) => {
|
|
66
|
+
if (x.includes('*')) {
|
|
67
|
+
let re;
|
|
68
|
+
try {
|
|
69
|
+
const regexp = globToRegExp(x, { globstar: true });
|
|
70
|
+
re = 're:' + String(regexp);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
errors.push(`staticItems item at index ${index}, '${x}', cannot be parsed as glob pattern.`);
|
|
74
|
+
re = null;
|
|
75
|
+
}
|
|
76
|
+
return re;
|
|
77
|
+
}
|
|
78
|
+
return x;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
errors.push('staticItems, if specified, must be a string value, an array of string values, false, or null');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!isSpecified(config, 'compression')) {
|
|
86
|
+
compression = ['br', 'gzip'];
|
|
87
|
+
}
|
|
88
|
+
else if (compression === null) {
|
|
89
|
+
compression = [];
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (!Array.isArray(compression)) {
|
|
93
|
+
compression = [compression];
|
|
94
|
+
}
|
|
95
|
+
if (compression.some((x) => x !== 'br' && x !== 'gzip')) {
|
|
96
|
+
errors.push(`compression, if specified, must be null or an array and can only contain 'br' and 'gzip'.`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!isSpecified(config, 'spaFile')) {
|
|
100
|
+
spaFile = null;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
if (typeof spaFile === 'string' || spaFile === null) {
|
|
104
|
+
// ok
|
|
105
|
+
}
|
|
106
|
+
else if (spaFile === false) {
|
|
107
|
+
spaFile = null;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
errors.push('spaFile, if specified, must be a string value, false, or null');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!isSpecified(config, 'notFoundPageFile')) {
|
|
114
|
+
notFoundPageFile = null;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
if (typeof notFoundPageFile === 'string' || notFoundPageFile === null) {
|
|
118
|
+
// ok
|
|
119
|
+
}
|
|
120
|
+
else if (notFoundPageFile === false) {
|
|
121
|
+
notFoundPageFile = null;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
errors.push('notFoundPageFile, if specified, must be a string value, false, or null');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!isSpecified(config, 'autoExt')) {
|
|
128
|
+
autoExt = [];
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
if (Array.isArray(autoExt) && autoExt.every(e => typeof e === 'string')) {
|
|
132
|
+
// ok
|
|
133
|
+
}
|
|
134
|
+
else if (autoExt === false || autoExt === null) {
|
|
135
|
+
autoExt = [];
|
|
136
|
+
}
|
|
137
|
+
else if (typeof autoExt === 'string') {
|
|
138
|
+
autoExt = [autoExt];
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
errors.push('autoExt, if specified, must be an array of string values, a string value, false, or null');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!isSpecified(config, 'autoIndex')) {
|
|
145
|
+
autoIndex = [];
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
if (Array.isArray(autoIndex) && autoIndex.every(e => typeof e === 'string')) {
|
|
149
|
+
// ok
|
|
150
|
+
}
|
|
151
|
+
else if (autoIndex === false || autoIndex === null) {
|
|
152
|
+
autoIndex = [];
|
|
153
|
+
}
|
|
154
|
+
else if (typeof autoIndex === 'string') {
|
|
155
|
+
autoIndex = [autoIndex];
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
errors.push('autoIndex, if specified, must be an array of string values, a string value, false, or null');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (errors.length > 0) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
publicDirPrefix,
|
|
166
|
+
staticItems,
|
|
167
|
+
compression,
|
|
168
|
+
spaFile,
|
|
169
|
+
notFoundPageFile,
|
|
170
|
+
autoExt,
|
|
171
|
+
autoIndex,
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
const normalizeConfig = buildNormalizeFunctionForObject((config, errors) => {
|
|
175
|
+
let { rootDir, objectStore, excludeDirs, excludeDotFiles, includeWellKnown, contentAssetInclusionTest, contentCompression, moduleAssetInclusionTest, contentTypes, server, } = config;
|
|
176
|
+
if (!isSpecified(config, 'rootDir')) {
|
|
177
|
+
errors.push('rootDir must be specified.');
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
if (isStringAndNotEmpty(rootDir)) {
|
|
181
|
+
// ok
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
errors.push('rootDir must be a non-empty string.');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (!isSpecified(config, 'objectStore')) {
|
|
188
|
+
objectStore = null;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
if (isStringAndNotEmpty(objectStore) || objectStore === null) {
|
|
192
|
+
// ok
|
|
193
|
+
}
|
|
194
|
+
else if (objectStore === false) {
|
|
195
|
+
objectStore = null;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
errors.push('objectStore, if specified, must be a non-empty string, false, or null.');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (!isSpecified(config, 'excludeDotFiles')) {
|
|
202
|
+
excludeDotFiles = true;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
if (typeof excludeDotFiles === 'boolean') {
|
|
206
|
+
// ok
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
errors.push('excludeDotFiles, if specified, must be a boolean value.');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (!isSpecified(config, 'includeWellKnown')) {
|
|
213
|
+
includeWellKnown = true;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
if (typeof includeWellKnown === 'boolean') {
|
|
217
|
+
// ok
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
errors.push('includeWellKnown, if specified, must be a boolean value.');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (!isSpecified(config, 'excludeDirs')) {
|
|
224
|
+
excludeDirs = ['./node_modules'];
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
if (excludeDirs === null) {
|
|
228
|
+
excludeDirs = [];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (!Array.isArray(excludeDirs)) {
|
|
232
|
+
excludeDirs = [excludeDirs];
|
|
233
|
+
}
|
|
234
|
+
excludeDirs = excludeDirs.map((x) => {
|
|
235
|
+
if (typeof x === 'string') {
|
|
236
|
+
let testString = x;
|
|
237
|
+
if (!testString.startsWith('/')) {
|
|
238
|
+
if (testString.startsWith('./')) {
|
|
239
|
+
testString = testString.slice(1);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
testString = '/' + testString;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (testString.endsWith('/')) {
|
|
246
|
+
testString = testString.slice(0, testString.length - 1);
|
|
247
|
+
}
|
|
248
|
+
return { test: (name) => name === testString, toString: () => testString };
|
|
249
|
+
}
|
|
250
|
+
if ((typeof x === 'object' || typeof x === 'function') && x != null) {
|
|
251
|
+
if ('test' in x && typeof x.test === 'function') {
|
|
252
|
+
return x;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return null;
|
|
256
|
+
});
|
|
257
|
+
if (excludeDirs.some((x) => x == null)) {
|
|
258
|
+
errors.push('excludeDirs, if specified, must be null, a string value, a RegExp, or an array of strings and RegExp values.');
|
|
259
|
+
}
|
|
260
|
+
if (!isSpecified(config, 'contentAssetInclusionTest')) {
|
|
261
|
+
contentAssetInclusionTest = null;
|
|
262
|
+
}
|
|
263
|
+
else if (contentAssetInclusionTest === null || typeof contentAssetInclusionTest === 'function') {
|
|
264
|
+
// ok
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
errors.push('contentAssetInclusionTest, if specified, must be null or a function.');
|
|
268
|
+
}
|
|
269
|
+
if (!isSpecified(config, 'contentCompression')) {
|
|
270
|
+
contentCompression = ['br', 'gzip'];
|
|
271
|
+
}
|
|
272
|
+
else if (contentCompression === null) {
|
|
273
|
+
contentCompression = [];
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
if (!Array.isArray(contentCompression)) {
|
|
277
|
+
contentCompression = [contentCompression];
|
|
278
|
+
}
|
|
279
|
+
if (contentCompression.some((x) => x !== 'br' && x !== 'gzip')) {
|
|
280
|
+
errors.push(`contentCompression, if specified, must be null or an array and can only contain 'br' and 'gzip'.`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (!isSpecified(config, 'moduleAssetInclusionTest')) {
|
|
284
|
+
moduleAssetInclusionTest = null;
|
|
285
|
+
}
|
|
286
|
+
else if (moduleAssetInclusionTest === null || typeof moduleAssetInclusionTest === 'function') {
|
|
287
|
+
// ok
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
errors.push('moduleAssetInclusionTest, if specified, must be null or a function.');
|
|
291
|
+
}
|
|
292
|
+
if (!isSpecified(config, 'contentTypes')) {
|
|
293
|
+
contentTypes = [];
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
const innerErrors = [];
|
|
297
|
+
let normalized;
|
|
298
|
+
if (Array.isArray(contentTypes) && (normalized = normalizeContentTypeDefs(contentTypes, innerErrors))) {
|
|
299
|
+
// ok
|
|
300
|
+
contentTypes = normalized;
|
|
301
|
+
}
|
|
302
|
+
else if (contentTypes === null) {
|
|
303
|
+
contentTypes = [];
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
errors.push('contentTypes, if specified, must be null or an array of content type definitions.');
|
|
307
|
+
errors.push(...innerErrors);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (!isSpecified(config, 'server')) {
|
|
311
|
+
server = null;
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
const innerErrors = [];
|
|
315
|
+
let normalized;
|
|
316
|
+
if ((normalized = normalizePublisherServerConfig(server, innerErrors))) {
|
|
317
|
+
// ok
|
|
318
|
+
server = normalized;
|
|
319
|
+
}
|
|
320
|
+
else if (server === null) {
|
|
321
|
+
// ok
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
errors.push('server, if specified, must be fit for server config.');
|
|
325
|
+
errors.push(...innerErrors);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (errors.length > 0) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
rootDir,
|
|
333
|
+
objectStore,
|
|
334
|
+
excludeDotFiles,
|
|
335
|
+
includeWellKnown,
|
|
336
|
+
excludeDirs,
|
|
337
|
+
contentAssetInclusionTest,
|
|
338
|
+
contentCompression,
|
|
339
|
+
moduleAssetInclusionTest,
|
|
340
|
+
contentTypes,
|
|
341
|
+
server,
|
|
342
|
+
};
|
|
343
|
+
});
|
|
344
|
+
export async function loadConfigFile(errors = []) {
|
|
345
|
+
let config = undefined;
|
|
346
|
+
const staticPublishRcPath = path.resolve('./static-publish.rc.js');
|
|
347
|
+
try {
|
|
348
|
+
config = (await import(staticPublishRcPath)).default;
|
|
349
|
+
}
|
|
350
|
+
catch {
|
|
351
|
+
errors.push('Unable to load ' + staticPublishRcPath);
|
|
352
|
+
}
|
|
353
|
+
if (config != null) {
|
|
354
|
+
config = normalizeConfig(config, errors);
|
|
355
|
+
}
|
|
356
|
+
return config ?? null;
|
|
357
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export class CreateReactAppPreset {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.name = 'Create React App';
|
|
4
|
+
this.defaultOptions = {
|
|
5
|
+
rootDir: './build',
|
|
6
|
+
staticDirs: ['[public-dir]/static'],
|
|
7
|
+
name: 'my-create-react-app',
|
|
8
|
+
description: 'Compute@Edge static site from create-react-app',
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
check(packageJson) {
|
|
12
|
+
if (packageJson == null) {
|
|
13
|
+
console.error("❌ Can't read/parse package.json");
|
|
14
|
+
console.error("Run this from a create-react-app project directory.");
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (packageJson?.dependencies?.['react-scripts'] == null) {
|
|
18
|
+
console.error("❌ Can't find react-scripts in dependencies");
|
|
19
|
+
console.error("Run this from a create-react-app project directory.");
|
|
20
|
+
console.log("If this is a project created with create-react-app and has since been ejected, specify preset cra-eject to skip this check.");
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class CreateReactAppEjectedPreset extends CreateReactAppPreset {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
29
|
+
this.name = 'Create React App (Ejected)';
|
|
30
|
+
}
|
|
31
|
+
check() {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docusaurus.d.ts","sourceRoot":"","sources":["../../../../src/cli/presets/implementations/docusaurus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,gBAAiB,YAAW,WAAW;IAClD,IAAI,SAAgB;IACpB,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAIjC;IACF,KAAK;CAGN"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class DocusaurusPreset {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.name = 'Docusaurus';
|
|
4
|
+
this.defaultOptions = {
|
|
5
|
+
rootDir: './build',
|
|
6
|
+
name: 'my-docusaurus-app',
|
|
7
|
+
description: 'Compute@Edge static site from docusaurus',
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
check() {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gatsby.d.ts","sourceRoot":"","sources":["../../../../src/cli/presets/implementations/gatsby.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,YAAa,YAAW,WAAW;IAC9C,IAAI,SAAY;IAChB,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAIjC;IACF,KAAK;CAGN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../../../src/cli/presets/implementations/next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,YAAa,YAAW,WAAW;IAC9C,IAAI,SAAa;IACjB,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAIjC;IACF,KAAK;CAGN"}
|