@fastly/compute-js-static-publish 8.0.1 → 8.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DOCUMENTATION.md +792 -35
- package/README.md +13 -3
- package/README.short.md +13 -3
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +14 -8
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +32 -15
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +10 -4
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +49 -8
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +69 -21
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +12 -12
- package/build/cli/cli/commands/manage/deploy.d.ts +2 -0
- package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/deploy.js +194 -0
- package/build/cli/cli/commands/manage/dev.d.ts +2 -0
- package/build/cli/cli/commands/manage/dev.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/dev.js +78 -0
- package/build/cli/cli/commands/manage/eject.d.ts +2 -0
- package/build/cli/cli/commands/manage/eject.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/eject.js +155 -0
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +42 -5
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +83 -37
- package/build/cli/cli/commands/manage/status.d.ts +2 -0
- package/build/cli/cli/commands/manage/status.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/status.js +162 -0
- package/build/cli/cli/commands/manage/template/index.d.ts +2 -0
- package/build/cli/cli/commands/manage/template/index.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/template/index.js +43 -0
- package/build/cli/cli/commands/manage/template/init.d.ts +13 -0
- package/build/cli/cli/commands/manage/template/init.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/template/init.js +172 -0
- package/build/cli/cli/commands/manage/upgrade.d.ts +2 -0
- package/build/cli/cli/commands/manage/upgrade.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/upgrade.js +59 -0
- package/build/cli/cli/commands/run-dev-watch.d.ts +8 -0
- package/build/cli/cli/commands/run-dev-watch.d.ts.map +1 -0
- package/build/cli/cli/commands/run-dev-watch.js +41 -0
- package/build/cli/cli/commands/run-template-hook.d.ts +2 -0
- package/build/cli/cli/commands/run-template-hook.d.ts.map +1 -0
- package/build/cli/cli/commands/run-template-hook.js +28 -0
- package/build/cli/cli/commands/scaffold/app-template.d.ts +17 -0
- package/build/cli/cli/commands/scaffold/app-template.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/app-template.js +54 -0
- package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts +5 -0
- package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/fastly-toml-sections.js +154 -0
- package/build/cli/cli/commands/scaffold/generate-app.d.ts +47 -0
- package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/generate-app.js +164 -0
- package/build/cli/cli/commands/scaffold/index.d.ts +6 -0
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +208 -290
- package/build/cli/cli/commands/scaffold/render.d.ts +7 -0
- package/build/cli/cli/commands/scaffold/render.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/render.js +72 -0
- package/build/cli/cli/hono/build.d.ts +43 -0
- package/build/cli/cli/hono/build.d.ts.map +1 -0
- package/build/cli/cli/hono/build.js +298 -0
- package/build/cli/cli/index.js +98 -5
- package/build/cli/cli/managed/app.d.ts +21 -0
- package/build/cli/cli/managed/app.d.ts.map +1 -0
- package/build/cli/cli/managed/app.js +162 -0
- package/build/cli/cli/managed/command-helpers.d.ts +6 -0
- package/build/cli/cli/managed/command-helpers.d.ts.map +1 -0
- package/build/cli/cli/managed/command-helpers.js +81 -0
- package/build/cli/cli/managed/eject.d.ts +6 -0
- package/build/cli/cli/managed/eject.d.ts.map +1 -0
- package/build/cli/cli/managed/eject.js +68 -0
- package/build/cli/cli/managed/fastly-service.d.ts +8 -0
- package/build/cli/cli/managed/fastly-service.d.ts.map +1 -0
- package/build/cli/cli/managed/fastly-service.js +21 -0
- package/build/cli/cli/managed/fingerprint.d.ts +13 -0
- package/build/cli/cli/managed/fingerprint.d.ts.map +1 -0
- package/build/cli/cli/managed/fingerprint.js +60 -0
- package/build/cli/cli/managed/lockfile.d.ts +31 -0
- package/build/cli/cli/managed/lockfile.d.ts.map +1 -0
- package/build/cli/cli/managed/lockfile.js +62 -0
- package/build/cli/cli/managed/project-edit.d.ts +3 -0
- package/build/cli/cli/managed/project-edit.d.ts.map +1 -0
- package/build/cli/cli/managed/project-edit.js +35 -0
- package/build/cli/cli/managed/project-file.d.ts +16 -0
- package/build/cli/cli/managed/project-file.d.ts.map +1 -0
- package/build/cli/cli/managed/project-file.js +119 -0
- package/build/cli/cli/managed/template-init.d.ts +12 -0
- package/build/cli/cli/managed/template-init.d.ts.map +1 -0
- package/build/cli/cli/managed/template-init.js +120 -0
- package/build/cli/cli/managed/version-check.d.ts +25 -0
- package/build/cli/cli/managed/version-check.d.ts.map +1 -0
- package/build/cli/cli/managed/version-check.js +84 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +1 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-local-provider.js +6 -3
- package/build/cli/cli/storage/kv-store-provider.d.ts +1 -0
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +9 -1
- package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +4 -0
- package/build/cli/cli/storage/storage-provider.d.ts +3 -0
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/storage-provider.js +32 -0
- package/build/cli/cli/util/api-token.d.ts.map +1 -1
- package/build/cli/cli/util/collection-name.d.ts +3 -0
- package/build/cli/cli/util/collection-name.d.ts.map +1 -0
- package/build/cli/cli/util/collection-name.js +24 -0
- package/build/cli/cli/util/collection-selection-flags.d.ts +13 -0
- package/build/cli/cli/util/collection-selection-flags.d.ts.map +1 -0
- package/build/cli/cli/util/collection-selection-flags.js +131 -0
- package/build/cli/cli/util/config.d.ts +13 -0
- package/build/cli/cli/util/config.d.ts.map +1 -1
- package/build/cli/cli/util/config.js +172 -38
- package/build/cli/cli/util/data.d.ts.map +1 -1
- package/build/cli/cli/util/global-options.d.ts +13 -0
- package/build/cli/cli/util/global-options.d.ts.map +1 -0
- package/build/cli/cli/util/global-options.js +53 -0
- package/build/cli/cli/util/kv-store-items.d.ts +1 -0
- package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-items.js +16 -40
- package/build/cli/cli/util/kv-store-local-server.d.ts +1 -1
- package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-local-server.js +4 -2
- package/build/cli/cli/util/output.d.ts +31 -0
- package/build/cli/cli/util/output.d.ts.map +1 -0
- package/build/cli/cli/util/output.js +139 -0
- package/build/cli/cli/util/package.d.ts +6 -0
- package/build/cli/cli/util/package.d.ts.map +1 -1
- package/build/cli/cli/util/package.js +23 -0
- package/build/cli/cli/util/progress.d.ts.map +1 -1
- package/build/cli/cli/util/purge.d.ts +6 -2
- package/build/cli/cli/util/purge.d.ts.map +1 -1
- package/build/cli/cli/util/purge.js +7 -2
- package/build/cli/cli/util/resources.d.ts +2 -0
- package/build/cli/cli/util/resources.d.ts.map +1 -0
- package/build/cli/cli/util/resources.js +8 -0
- package/build/cli/cli/util/service-id.d.ts +1 -0
- package/build/cli/cli/util/service-id.d.ts.map +1 -1
- package/build/cli/cli/util/service-id.js +5 -1
- package/build/cli/cli/util/variants.d.ts.map +1 -1
- package/build/cli/models/assets/index.d.ts +6 -0
- package/build/cli/models/assets/index.d.ts.map +1 -1
- package/build/cli/models/assets/index.js +24 -0
- package/build/cli/models/collections/index.d.ts +3 -0
- package/build/cli/models/collections/index.d.ts.map +1 -0
- package/build/cli/models/collections/index.js +15 -0
- package/build/cli/models/compression/index.d.ts +1 -1
- package/build/cli/models/compression/index.d.ts.map +1 -1
- package/build/cli/models/config/collection-selection.d.ts +55 -0
- package/build/cli/models/config/collection-selection.d.ts.map +1 -0
- package/build/cli/models/config/collection-selection.js +238 -0
- package/build/cli/models/config/item-patterns.d.ts +4 -0
- package/build/cli/models/config/item-patterns.d.ts.map +1 -0
- package/build/cli/models/config/item-patterns.js +43 -0
- package/build/cli/models/config/publish-content-config.d.ts +6 -1
- package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-project.d.ts +23 -0
- package/build/cli/models/config/static-publish-project.d.ts.map +1 -0
- package/build/cli/models/config/static-publish-project.js +11 -0
- package/build/cli/models/config/static-publish-rc.d.ts +25 -0
- package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-rc.js +31 -0
- package/build/cli/models/config/template-settings.d.ts +10 -0
- package/build/cli/models/config/template-settings.d.ts.map +1 -0
- package/build/cli/models/config/template-settings.js +72 -0
- package/build/cli/models/server/index.d.ts.map +1 -1
- package/build/cli/models/server/index.js +6 -2
- package/build/server/hono/extensions.d.ts +48 -0
- package/build/server/hono/extensions.d.ts.map +1 -0
- package/build/server/hono/extensions.js +65 -0
- package/build/server/hono/index.d.ts +30 -0
- package/build/server/hono/index.d.ts.map +1 -0
- package/build/server/hono/index.js +72 -0
- package/build/server/hono/path.d.ts +7 -0
- package/build/server/hono/path.d.ts.map +1 -0
- package/build/server/hono/path.js +32 -0
- package/build/server/models/assets/index.d.ts +6 -0
- package/build/server/models/assets/index.d.ts.map +1 -1
- package/build/server/models/assets/index.js +24 -0
- package/build/server/models/collections/index.d.ts +3 -0
- package/build/server/models/collections/index.d.ts.map +1 -0
- package/build/server/models/collections/index.js +15 -0
- package/build/server/models/compression/index.d.ts +1 -1
- package/build/server/models/compression/index.d.ts.map +1 -1
- package/build/server/models/config/collection-selection.d.ts +55 -0
- package/build/server/models/config/collection-selection.d.ts.map +1 -0
- package/build/server/models/config/collection-selection.js +238 -0
- package/build/server/models/config/item-patterns.d.ts +4 -0
- package/build/server/models/config/item-patterns.d.ts.map +1 -0
- package/build/server/models/config/item-patterns.js +43 -0
- package/build/server/models/config/publish-content-config.d.ts +6 -1
- package/build/server/models/config/publish-content-config.d.ts.map +1 -1
- package/build/server/models/config/static-publish-project.d.ts +23 -0
- package/build/server/models/config/static-publish-project.d.ts.map +1 -0
- package/build/server/models/config/static-publish-project.js +11 -0
- package/build/server/models/config/static-publish-rc.d.ts +25 -0
- package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/server/models/config/static-publish-rc.js +31 -0
- package/build/server/models/server/index.d.ts.map +1 -1
- package/build/server/models/server/index.js +6 -2
- package/build/server/server/collection-selection/index.d.ts +11 -0
- package/build/server/server/collection-selection/index.d.ts.map +1 -0
- package/build/server/server/collection-selection/index.js +192 -0
- package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -1
- package/build/server/server/collection-selector/from-cookie.js +6 -8
- package/build/server/server/collection-selector/from-request.d.ts.map +1 -1
- package/build/server/server/index.d.ts +4 -1
- package/build/server/server/index.d.ts.map +1 -1
- package/build/server/server/index.js +3 -1
- package/build/server/server/publisher-server/accept-html.d.ts +2 -0
- package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
- package/build/server/server/publisher-server/accept-html.js +50 -0
- package/build/server/server/publisher-server/index.d.ts +59 -7
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +362 -145
- package/build/server/server/publisher-server/response-cache.d.ts +3 -0
- package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
- package/build/server/server/publisher-server/response-cache.js +24 -1
- package/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/storage-provider.d.ts.map +1 -1
- package/build/server/server/util/body-length.d.ts.map +1 -1
- package/build/server/server/util/server-timing.d.ts.map +1 -1
- package/package.json +21 -3
- package/resources/app/fastly.toml.njk +58 -0
- package/resources/app/gitignore.njk +9 -0
- package/resources/app/publish-content.config.from-project.js.njk +9 -0
- package/resources/app/publish-content.config.js.njk +35 -0
- package/resources/app/static-publish.project.js.njk +83 -0
- package/resources/app/static-publish.rc.js.njk +43 -0
- package/resources/template-init/hono/_example.ts +22 -0
- package/resources/template-init/hono/tsconfig.json +17 -0
- package/resources/templates/hono/package-lock.json +4123 -0
- package/resources/templates/hono/package.json +15 -0
- package/resources/templates/hono/scripts/template_postinstall.js +10 -0
- package/resources/templates/hono/scripts/template_prebuild.js +8 -0
- package/resources/templates/hono/scripts/template_watch.js +15 -0
- package/resources/templates/hono/src/hono-extensions.generated.d.ts +5 -0
- package/resources/templates/hono/src/index.ts +53 -0
- package/resources/templates/hono/tsconfig.json +17 -0
- package/resources/templates/plain/package-lock.json +4088 -0
- package/resources/templates/plain/package.json +10 -0
- package/resources/templates/plain/src/index.js +34 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import child_process from 'node:child_process';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { generateApp } from '../scaffold/generate-app.js';
|
|
9
|
+
import { managedAppConfig, writeManagedAppFiles } from '../../managed/app.js';
|
|
10
|
+
import { loadManagedProject } from '../../managed/command-helpers.js';
|
|
11
|
+
import { findNonDataPaths, isScaffoldedPublishContent, renderPublishContentConfig } from '../../managed/eject.js';
|
|
12
|
+
import { THIS_PACKAGE, readTemplateLockfile } from '../../managed/lockfile.js';
|
|
13
|
+
import { parseCommandLine } from '../../util/args.js';
|
|
14
|
+
import { detectProjectMode } from '../../util/config.js';
|
|
15
|
+
import { rootRelative } from '../../util/files.js';
|
|
16
|
+
import { fail, recordFailure } from '../../util/output.js';
|
|
17
|
+
import { cliCommand, getOwnVersion } from '../../util/package.js';
|
|
18
|
+
import { MANAGED_APP_DIR, PROJECT_FILE_NAME, RC_FILE_NAME } from '../../../models/config/static-publish-project.js';
|
|
19
|
+
// An environment variable for the tests of this package only. The tests run a
|
|
20
|
+
// version that is not on npm, so they give here the spec of this package for
|
|
21
|
+
// the ejected app.
|
|
22
|
+
const PACKAGE_SPEC_ENV = 'CJSP_TEST_EJECT_PACKAGE_SPEC';
|
|
23
|
+
function help() {
|
|
24
|
+
console.log(`\
|
|
25
|
+
|
|
26
|
+
Usage:
|
|
27
|
+
${cliCommand()} eject [options]
|
|
28
|
+
|
|
29
|
+
Description:
|
|
30
|
+
Converts a managed project into an ejected app, which you own and change:
|
|
31
|
+
- Writes the app that deploy would deploy into ./compute-js (or --dir).
|
|
32
|
+
- Splits ${PROJECT_FILE_NAME} into ${RC_FILE_NAME} and
|
|
33
|
+
publish-content.config.js in that directory, with the paths written again
|
|
34
|
+
so that they point at the same directories. Then deletes ${PROJECT_FILE_NAME}.
|
|
35
|
+
- Pins this package to the version that runs: "^<version>" in package.json,
|
|
36
|
+
exactly <version> in package-lock.json (one 'npm install', which needs the
|
|
37
|
+
npm registry). The version must be published on npm.
|
|
38
|
+
|
|
39
|
+
Eject can copy publishContent only if it is data. If it has functions or
|
|
40
|
+
regular expressions (for example assetInclusionTest), eject stops.
|
|
41
|
+
|
|
42
|
+
Options:
|
|
43
|
+
--dir=<dir> The directory of the ejected app. Default: ./compute-js
|
|
44
|
+
--force Write into the directory also if it exists.
|
|
45
|
+
--fastly-service-id=<id> Written as service_id into fastly.toml. Default:
|
|
46
|
+
FASTLY_SERVICE_ID, then managed.serviceId.
|
|
47
|
+
|
|
48
|
+
Global Options:
|
|
49
|
+
-h, --help Show this help message and exit.
|
|
50
|
+
`);
|
|
51
|
+
}
|
|
52
|
+
function isPublished(version) {
|
|
53
|
+
const result = child_process.spawnSync('npm', ['view', `${THIS_PACKAGE}@${version}`, 'version'], { encoding: 'utf-8' });
|
|
54
|
+
return result.status === 0 && result.stdout.trim() === version;
|
|
55
|
+
}
|
|
56
|
+
export async function action(actionArgs) {
|
|
57
|
+
const optionDefinitions = [
|
|
58
|
+
{ name: 'dir', type: String },
|
|
59
|
+
{ name: 'force', type: Boolean },
|
|
60
|
+
{ name: 'fastly-service-id', type: String },
|
|
61
|
+
];
|
|
62
|
+
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
63
|
+
if (parsed.needHelp) {
|
|
64
|
+
if (parsed.error != null) {
|
|
65
|
+
console.error(String(parsed.error));
|
|
66
|
+
console.error();
|
|
67
|
+
recordFailure('usage', String(parsed.error));
|
|
68
|
+
}
|
|
69
|
+
help();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const { dir: dirValue, force, ['fastly-service-id']: fastlyServiceId, } = parsed.commandLineOptions;
|
|
73
|
+
if (detectProjectMode() === 'ejected') {
|
|
74
|
+
fail('usage', 'This app is already ejected.');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const project = await loadManagedProject('eject', '');
|
|
78
|
+
if (project == null) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const projectDir = path.resolve();
|
|
82
|
+
const appDir = path.resolve(dirValue ?? './compute-js');
|
|
83
|
+
if (appDir === projectDir || !appDir.startsWith(projectDir + path.sep) || appDir.startsWith(path.resolve(MANAGED_APP_DIR))) {
|
|
84
|
+
fail('usage', `--dir must be a directory in the project dir, and not in ${MANAGED_APP_DIR}.`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (fs.existsSync(appDir) && !force) {
|
|
88
|
+
fail('usage', `${rootRelative(appDir)} exists. Use --force to write into it.`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const nonData = findNonDataPaths(project.publishContent);
|
|
92
|
+
if (nonData.length > 0) {
|
|
93
|
+
fail('usage', `Eject cannot copy functions or regular expressions from publishContent: ${nonData.join(', ')}. ` +
|
|
94
|
+
`Remove them from ${PROJECT_FILE_NAME}, eject, and then add them to publish-content.config.js of the ejected app by hand.`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const version = getOwnVersion();
|
|
98
|
+
const testSpec = process.env[PACKAGE_SPEC_ENV];
|
|
99
|
+
if (testSpec == null && !isPublished(version)) {
|
|
100
|
+
fail('version-not-published', `Eject needs a version of ${THIS_PACKAGE} that is published on npm. ${version} is not.`);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const packageSpec = testSpec ?? `^${version}`;
|
|
104
|
+
const serviceId = (typeof fastlyServiceId === 'string' && fastlyServiceId !== '' ? fastlyServiceId : undefined) ??
|
|
105
|
+
(process.env.FASTLY_SERVICE_ID || undefined) ??
|
|
106
|
+
project.managed.serviceId;
|
|
107
|
+
const managedConfig = await managedAppConfig(projectDir, project, appDir);
|
|
108
|
+
const appConfig = {
|
|
109
|
+
...managedConfig,
|
|
110
|
+
serviceId,
|
|
111
|
+
staticPublishVersionSpec: packageSpec,
|
|
112
|
+
packageLock: undefined,
|
|
113
|
+
generatedFrom: {
|
|
114
|
+
template: managedConfig.template.name,
|
|
115
|
+
staticPublishVersion: version,
|
|
116
|
+
generatedAt: new Date().toISOString().slice(0, 10),
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
const files = generateApp(appConfig);
|
|
120
|
+
// The publish settings: the same file as an ejected scaffold, if the section
|
|
121
|
+
// is what scaffold --managed wrote; else the data of the section.
|
|
122
|
+
if (!isScaffoldedPublishContent(project.publishContent, appConfig, projectDir)) {
|
|
123
|
+
files['publish-content.config.js'] = renderPublishContentConfig(project.publishContent, projectDir, appDir);
|
|
124
|
+
}
|
|
125
|
+
// The template's lockfile, without this package. npm install adds it.
|
|
126
|
+
const lock = readTemplateLockfile(managedConfig.template.name);
|
|
127
|
+
if (appConfig.name != null) {
|
|
128
|
+
lock.name = appConfig.name;
|
|
129
|
+
lock.packages[''] = { ...lock.packages[''], name: appConfig.name };
|
|
130
|
+
}
|
|
131
|
+
files['package-lock.json'] = JSON.stringify(lock, undefined, 2) + '\n';
|
|
132
|
+
console.log(`📦 Writing the app into ${rootRelative(appDir)}...`);
|
|
133
|
+
writeManagedAppFiles(appDir, files);
|
|
134
|
+
// Pin this package: "^<version>" stays in package.json, and the lockfile gets exactly <version>.
|
|
135
|
+
const installArgs = testSpec != null ?
|
|
136
|
+
['install', '--no-audit', '--no-fund'] :
|
|
137
|
+
['install', '--save-dev', `${THIS_PACKAGE}@${version}`, '--no-audit', '--no-fund'];
|
|
138
|
+
console.log(`npm ${installArgs.join(' ')}`);
|
|
139
|
+
const install = child_process.spawnSync('npm', installArgs, { cwd: appDir, stdio: ['ignore', process.stderr, 'inherit'] });
|
|
140
|
+
if (install.error != null || install.status !== 0) {
|
|
141
|
+
fail('failed', `npm install failed in ${rootRelative(appDir)}. ${PROJECT_FILE_NAME} was not changed. Fix the problem, and run eject again with --force.`);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
fs.rmSync(path.resolve(projectDir, PROJECT_FILE_NAME));
|
|
145
|
+
console.log(`
|
|
146
|
+
🎉 Ejected into ${rootRelative(appDir)}. You now own the app and its upgrades (see MIGRATING.md).
|
|
147
|
+
|
|
148
|
+
- ${PROJECT_FILE_NAME} is deleted. ${rootRelative(appDir)}/${RC_FILE_NAME} and publish-content.config.js have its settings.
|
|
149
|
+
Commit ${rootRelative(appDir)}.
|
|
150
|
+
- Run the commands of this CLI in ${rootRelative(appDir)} now.
|
|
151
|
+
- You can delete ${MANAGED_APP_DIR}/. The line '/.static-publish/' in .gitignore is not needed any more.
|
|
152
|
+
- The working directory stays where it was. Run 'publish-content --local' again before 'npm run dev:start',
|
|
153
|
+
because the local KV Store has paths relative to the app.
|
|
154
|
+
`);
|
|
155
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"AAsFA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAmChD"}
|
|
@@ -3,14 +3,22 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import { getCommandAndArgs } from '../../util/args.js';
|
|
6
|
+
import { fail, isJsonMode, recordFailure } from '../../util/output.js';
|
|
6
7
|
import * as cleanCommand from './clean.js';
|
|
8
|
+
import * as deployCommand from './deploy.js';
|
|
9
|
+
import * as devCommand from './dev.js';
|
|
10
|
+
import * as ejectCommand from './eject.js';
|
|
11
|
+
import * as statusCommand from './status.js';
|
|
12
|
+
import * as templateCommands from './template/index.js';
|
|
13
|
+
import * as upgradeCommand from './upgrade.js';
|
|
7
14
|
import * as publishContentCommand from './publish-content.js';
|
|
8
15
|
import * as collectionsCommands from './collections/index.js';
|
|
16
|
+
import { cliCommand } from '../../util/package.js';
|
|
9
17
|
function help() {
|
|
10
18
|
console.log(`\
|
|
11
19
|
|
|
12
20
|
Usage:
|
|
13
|
-
|
|
21
|
+
${cliCommand()} <command> [options]
|
|
14
22
|
|
|
15
23
|
Description:
|
|
16
24
|
Manage and publish static content to Fastly Compute using KV Store-backed collections.
|
|
@@ -24,6 +32,13 @@ Available Commands:
|
|
|
24
32
|
collections delete Delete a specific collection index
|
|
25
33
|
collections promote Copy a collection to another name
|
|
26
34
|
collections update-expiration Modify expiration time for an existing collection
|
|
35
|
+
dev Run the app of a managed project locally
|
|
36
|
+
status Show the state of the app, and if a deploy is necessary
|
|
37
|
+
deploy Deploy the app of a managed project, if it changed
|
|
38
|
+
upgrade Move a managed project to the version of this CLI
|
|
39
|
+
eject Convert a managed project into an ejected app
|
|
40
|
+
template init Make or update the folder of the app's template
|
|
41
|
+
(for the hono template: hono-extensions/)
|
|
27
42
|
|
|
28
43
|
KV Store Options:
|
|
29
44
|
--local Instead of working with the Fastly KV Store, operate on
|
|
@@ -42,6 +57,17 @@ S3 Storage Options (BETA):
|
|
|
42
57
|
and S3_SECRET_ACCESS_KEY environment variables.
|
|
43
58
|
|
|
44
59
|
Global Options:
|
|
60
|
+
--project-dir=<dir> Run the command for the app in <dir>, the directory
|
|
61
|
+
that has static-publish.rc.js or static-publish.project.js.
|
|
62
|
+
Relative paths, also in other options, are then
|
|
63
|
+
relative to <dir>.
|
|
64
|
+
--version Print the version of this package and exit.
|
|
65
|
+
--non-interactive Never ask a question. Missing input is an error.
|
|
66
|
+
This is also on when the CI environment variable is set.
|
|
67
|
+
--json Write the result as one JSON object to stdout, and
|
|
68
|
+
the log to stderr. For publish-content,
|
|
69
|
+
collections list/delete/promote, status, deploy,
|
|
70
|
+
and --version.
|
|
45
71
|
-h, --help Show this help message and exit.
|
|
46
72
|
|
|
47
73
|
Automatic Project Initialization:
|
|
@@ -49,16 +75,23 @@ Automatic Project Initialization:
|
|
|
49
75
|
Compute application for you, including Fastly configuration, default routes, and publishing setup.
|
|
50
76
|
|
|
51
77
|
Examples:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
78
|
+
${cliCommand()} publish-content --collection-name=live
|
|
79
|
+
${cliCommand()} collections list
|
|
80
|
+
${cliCommand()} clean --dry-run
|
|
81
|
+
${cliCommand()} publish-content --project-dir=./compute-js
|
|
55
82
|
`);
|
|
56
83
|
}
|
|
57
84
|
export async function action(actionArgs) {
|
|
58
85
|
const modes = {
|
|
59
86
|
'clean': cleanCommand,
|
|
87
|
+
'deploy': deployCommand,
|
|
88
|
+
'dev': devCommand,
|
|
89
|
+
'eject': ejectCommand,
|
|
90
|
+
'status': statusCommand,
|
|
91
|
+
'upgrade': upgradeCommand,
|
|
60
92
|
'publish-content': publishContentCommand,
|
|
61
93
|
'collections': collectionsCommands,
|
|
94
|
+
'template': templateCommands,
|
|
62
95
|
};
|
|
63
96
|
const commandAndArgs = getCommandAndArgs(actionArgs, modes);
|
|
64
97
|
if (commandAndArgs.needHelp) {
|
|
@@ -66,11 +99,15 @@ export async function action(actionArgs) {
|
|
|
66
99
|
console.error(commandAndArgs.error);
|
|
67
100
|
console.error(`Specify one of the following commands: ${Object.keys(modes).join(', ')}`);
|
|
68
101
|
console.error();
|
|
69
|
-
|
|
102
|
+
recordFailure('usage', commandAndArgs.error);
|
|
70
103
|
}
|
|
71
104
|
help();
|
|
72
105
|
return;
|
|
73
106
|
}
|
|
74
107
|
const { command, argv, } = commandAndArgs;
|
|
108
|
+
if (isJsonMode() && !['publish-content', 'collections', 'status', 'deploy'].includes(command)) {
|
|
109
|
+
fail('json-not-supported', `--json is not supported for '${command}'.`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
75
112
|
await modes[command].action(argv);
|
|
76
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AAiJA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAqmBhD"}
|
|
@@ -4,18 +4,24 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import * as fs from 'node:fs';
|
|
6
6
|
import * as path from 'node:path';
|
|
7
|
+
import { HIDDEN_INDEX_FEATURE, findAssetEntry, hiddenIndexKey, } from '../../../models/assets/index.js';
|
|
8
|
+
import { parseItemPatterns, testItemPatterns } from '../../../models/config/item-patterns.js';
|
|
7
9
|
import { encodeIndexMetadata } from '../../../models/server/index.js';
|
|
8
10
|
import { calcExpirationTime } from '../../../models/time/index.js';
|
|
9
11
|
import { parseCommandLine } from '../../util/args.js';
|
|
12
|
+
import { errorCodeOf, fail, recordFailure, setJsonResult } from '../../util/output.js';
|
|
13
|
+
import { checkCollectionNameForWrite } from '../../util/collection-name.js';
|
|
10
14
|
import { mergeContentTypes, testFileContentType } from '../../util/content-types.js';
|
|
11
|
-
import { LoadConfigError,
|
|
15
|
+
import { LoadConfigError, configFileName, detectProjectMode, getComputeAppDir, loadProjectFile, loadPublishContentConfig, loadStaticPublisherRcFile, } from '../../util/config.js';
|
|
16
|
+
import { PROJECT_FILE_NAME } from '../../../models/config/static-publish-project.js';
|
|
12
17
|
import { applyDefaults } from '../../util/data.js';
|
|
13
18
|
import { calculateFileSizeAndHash, enumerateFiles, rootRelative } from '../../util/files.js';
|
|
14
19
|
import { ensureVariantFileExists, OncePerKey } from '../../util/variants.js';
|
|
15
20
|
import { concurrentMap } from '../../util/retryable.js';
|
|
16
21
|
import { ProgressLog } from '../../util/progress.js';
|
|
17
22
|
import { loadPurgeTarget, purgeCollection } from '../../util/purge.js';
|
|
18
|
-
import { getStorageKeysByHexPrefix, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
|
|
23
|
+
import { getStorageKeysByHexPrefix, isVariantInStorage, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
|
|
24
|
+
import { cliCommand } from '../../util/package.js';
|
|
19
25
|
// Storage key format:
|
|
20
26
|
// <publishId>_index_<preview_id>.json
|
|
21
27
|
// <publishId>_settings_<preview_id>.json
|
|
@@ -24,7 +30,7 @@ function help() {
|
|
|
24
30
|
console.log(`\
|
|
25
31
|
|
|
26
32
|
Usage:
|
|
27
|
-
|
|
33
|
+
${cliCommand()} publish-content [--collection-name=<name>] [options]
|
|
28
34
|
|
|
29
35
|
Description:
|
|
30
36
|
Publishes static files from your local root directory into a named collection,
|
|
@@ -101,9 +107,9 @@ Global Options:
|
|
|
101
107
|
-h, --help Show this help message and exit.
|
|
102
108
|
|
|
103
109
|
Examples:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
110
|
+
${cliCommand()} publish-content --collection-name=preview-456
|
|
111
|
+
${cliCommand()} publish-content --expires-in=7d --kv-overwrite
|
|
112
|
+
${cliCommand()} publish-content --expires-never --local
|
|
107
113
|
|
|
108
114
|
`);
|
|
109
115
|
}
|
|
@@ -132,7 +138,7 @@ export async function action(actionArgs) {
|
|
|
132
138
|
if (parsed.error != null) {
|
|
133
139
|
console.error(String(parsed.error));
|
|
134
140
|
console.error();
|
|
135
|
-
|
|
141
|
+
recordFailure('usage', String(parsed.error));
|
|
136
142
|
}
|
|
137
143
|
help();
|
|
138
144
|
return;
|
|
@@ -142,8 +148,7 @@ export async function action(actionArgs) {
|
|
|
142
148
|
if (s3UploadConcurrencyValue !== undefined) {
|
|
143
149
|
if (typeof s3UploadConcurrencyValue !== 'string' || !/^\d+$/.test(s3UploadConcurrencyValue) ||
|
|
144
150
|
Number(s3UploadConcurrencyValue) < 1 || Number(s3UploadConcurrencyValue) > 256) {
|
|
145
|
-
|
|
146
|
-
process.exitCode = 1;
|
|
151
|
+
fail('usage', `--s3-upload-concurrency must be an integer from 1 to 256.`);
|
|
147
152
|
return;
|
|
148
153
|
}
|
|
149
154
|
s3UploadConcurrency = Number(s3UploadConcurrencyValue);
|
|
@@ -151,7 +156,7 @@ export async function action(actionArgs) {
|
|
|
151
156
|
const overwriteExisting = _overwriteExisting ?? _kvOverwrite;
|
|
152
157
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
153
158
|
// in other words, the directory that contains `fastly.toml`.
|
|
154
|
-
const computeAppDir =
|
|
159
|
+
const computeAppDir = getComputeAppDir();
|
|
155
160
|
console.log(`🚀 Publishing content...`);
|
|
156
161
|
// #### load config
|
|
157
162
|
let staticPublisherRc;
|
|
@@ -159,20 +164,22 @@ export async function action(actionArgs) {
|
|
|
159
164
|
staticPublisherRc = await loadStaticPublisherRcFile();
|
|
160
165
|
}
|
|
161
166
|
catch (err) {
|
|
162
|
-
console.error(
|
|
167
|
+
console.error(`❌ Can't load ${configFileName()}`);
|
|
163
168
|
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
164
169
|
if (err instanceof LoadConfigError) {
|
|
165
170
|
for (const error of err.errors) {
|
|
166
171
|
console.error(error);
|
|
167
172
|
}
|
|
168
173
|
}
|
|
169
|
-
|
|
174
|
+
recordFailure('config-invalid', `Can't load ${configFileName()}.`);
|
|
170
175
|
return;
|
|
171
176
|
}
|
|
172
|
-
|
|
177
|
+
// In a managed project, the default is the publishContent section of the project file.
|
|
178
|
+
const managedProject = detectProjectMode() === 'managed' ? await loadProjectFile() : null;
|
|
179
|
+
const configFilePath = configFilePathValue ?? (managedProject != null ? `${PROJECT_FILE_NAME} (publishContent)` : './publish-content.config.js');
|
|
173
180
|
let publishContentConfig;
|
|
174
181
|
try {
|
|
175
|
-
publishContentConfig = await
|
|
182
|
+
publishContentConfig = await loadPublishContentConfig(configFilePathValue);
|
|
176
183
|
}
|
|
177
184
|
catch (err) {
|
|
178
185
|
console.error(`❌ Can't load ${configFilePath}`);
|
|
@@ -181,15 +188,14 @@ export async function action(actionArgs) {
|
|
|
181
188
|
console.error(error);
|
|
182
189
|
}
|
|
183
190
|
}
|
|
184
|
-
|
|
191
|
+
recordFailure('config-invalid', `Can't load ${configFilePath}.`);
|
|
185
192
|
return;
|
|
186
193
|
}
|
|
187
194
|
// --brotli-quality overrides brotliQuality in the config file.
|
|
188
195
|
let brotliQualitySource = 'config';
|
|
189
196
|
if (brotliQualityValue !== undefined) {
|
|
190
197
|
if (typeof brotliQualityValue !== 'string' || !/^\d+$/.test(brotliQualityValue) || Number(brotliQualityValue) > 11) {
|
|
191
|
-
|
|
192
|
-
process.exitCode = 1;
|
|
198
|
+
fail('usage', `--brotli-quality must be an integer from 0 to 11.`);
|
|
193
199
|
return;
|
|
194
200
|
}
|
|
195
201
|
publishContentConfig.brotliQuality = Number(brotliQualityValue);
|
|
@@ -210,7 +216,7 @@ export async function action(actionArgs) {
|
|
|
210
216
|
catch (err) {
|
|
211
217
|
console.error(`❌ Cannot process expiration time`);
|
|
212
218
|
console.error(String(err));
|
|
213
|
-
process
|
|
219
|
+
recordFailure('usage', `Cannot process expiration time: ${String(err)}`);
|
|
214
220
|
return;
|
|
215
221
|
}
|
|
216
222
|
console.log(`✔️ Public directory '${rootRelative(publicDirRoot)}'.`);
|
|
@@ -238,7 +244,7 @@ export async function action(actionArgs) {
|
|
|
238
244
|
catch (err) {
|
|
239
245
|
console.error(`❌ Could not instantiate store provider`);
|
|
240
246
|
console.error(String(err));
|
|
241
|
-
|
|
247
|
+
recordFailure(errorCodeOf(err), String(err));
|
|
242
248
|
return;
|
|
243
249
|
}
|
|
244
250
|
// Purge target: checked now, so that a missing API token fails before anything is uploaded.
|
|
@@ -248,13 +254,14 @@ export async function action(actionArgs) {
|
|
|
248
254
|
localMode: localMode ?? false,
|
|
249
255
|
computeAppDir,
|
|
250
256
|
fastlyServiceId,
|
|
257
|
+
projectServiceId: managedProject?.managed.serviceId,
|
|
251
258
|
fastlyApiToken,
|
|
252
259
|
purgeEnvironments: purgeEnvironmentValues,
|
|
253
260
|
});
|
|
254
261
|
}
|
|
255
262
|
catch (err) {
|
|
256
263
|
console.error(String(err));
|
|
257
|
-
|
|
264
|
+
recordFailure(errorCodeOf(err), String(err));
|
|
258
265
|
return;
|
|
259
266
|
}
|
|
260
267
|
// Load content types
|
|
@@ -278,10 +285,20 @@ export async function action(actionArgs) {
|
|
|
278
285
|
if (includeWellKnown) {
|
|
279
286
|
console.log(`✔️ (.well-known is exempt from exclusion.)`);
|
|
280
287
|
}
|
|
288
|
+
// The files to publish as hidden files (see also assetInclusionTest).
|
|
289
|
+
const hiddenItems = parseItemPatterns(publishContentConfig.hiddenItems, (i, x) => {
|
|
290
|
+
console.warn(`⚠️ Cannot parse hiddenItems item index ${i}: '${x}', skipping...`);
|
|
291
|
+
});
|
|
292
|
+
if (hiddenItems.length > 0) {
|
|
293
|
+
console.log(`✔️ Hidden items: ${publishContentConfig.hiddenItems.join(', ')}`);
|
|
294
|
+
}
|
|
281
295
|
// ### Collection name that we're currently publishing
|
|
282
296
|
// for example, live, staging
|
|
283
297
|
const collectionName = collectionNameValue ?? process.env.PUBLISHER_COLLECTION_NAME ?? defaultCollectionName;
|
|
284
298
|
console.log(`✔️ Collection Name: ${collectionName}`);
|
|
299
|
+
if (!await checkCollectionNameForWrite(storageProvider, publishId, collectionName)) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
285
302
|
if (expirationTime == null) {
|
|
286
303
|
// includes null and undefined
|
|
287
304
|
console.log(`✔️ Publishing with no expiration timestamp.`);
|
|
@@ -319,6 +336,8 @@ export async function action(actionArgs) {
|
|
|
319
336
|
// #### Keys that are already in storage
|
|
320
337
|
// The key of a file is the hash of its content. If the key exists, storage
|
|
321
338
|
// already has the same content. Thus we do not compress, hash, or upload it again.
|
|
339
|
+
// For a file in more than one chunk, isVariantInStorage() also compares the
|
|
340
|
+
// stored size of each chunk.
|
|
322
341
|
// In local mode, a key can refer to a working file that was deleted, so we do not list.
|
|
323
342
|
// All the keys that the scan looks for start with `<publishId>_files_sha256_` and a hex
|
|
324
343
|
// hash, so we list them in 16 parts at the same time.
|
|
@@ -330,17 +349,6 @@ export async function action(actionArgs) {
|
|
|
330
349
|
console.log(`✅ Found ${existingKeys.size} key(s) in ${((Date.now() - listStart) / 1000).toFixed(1)} s.`);
|
|
331
350
|
}
|
|
332
351
|
let existingVariantCount = 0;
|
|
333
|
-
function isVariantInStorage(variantKey, numChunks) {
|
|
334
|
-
if (existingKeys == null || !existingKeys.has(variantKey)) {
|
|
335
|
-
return false;
|
|
336
|
-
}
|
|
337
|
-
for (let chunkIndex = 1; chunkIndex < numChunks; chunkIndex++) {
|
|
338
|
-
if (!existingKeys.has(`${variantKey}_${chunkIndex}`)) {
|
|
339
|
-
return false;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
352
|
// #### Iterate files
|
|
345
353
|
const scanProgress = new ProgressLog('Files scanned', verbose);
|
|
346
354
|
const fileResults = await concurrentMap(files, async (file) => {
|
|
@@ -374,9 +382,12 @@ export async function action(actionArgs) {
|
|
|
374
382
|
if (!includeAsset) {
|
|
375
383
|
return;
|
|
376
384
|
}
|
|
385
|
+
// A hidden file is published, but PublisherServer does not serve it for a request.
|
|
386
|
+
const hidden = (typeof includeAsset === 'object' && includeAsset.hidden === true) ||
|
|
387
|
+
testItemPatterns(hiddenItems, assetKey);
|
|
377
388
|
// #### Base file size, hash, last modified time
|
|
378
389
|
const { size: baseSize, hash: baseHash } = await calculateFileSizeAndHash(file);
|
|
379
|
-
scanProgress.add(1, () => `📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}`);
|
|
390
|
+
scanProgress.add(1, () => `📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}${hidden ? ' (hidden)' : ''}`);
|
|
380
391
|
const stats = fs.statSync(file);
|
|
381
392
|
const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
|
|
382
393
|
// We know the number of chunks of the original before we read it. For a
|
|
@@ -392,7 +403,8 @@ export async function action(actionArgs) {
|
|
|
392
403
|
// Returns true if the index keeps the variant.
|
|
393
404
|
async function prepareVariant(variant, variantKey, variantFilePath) {
|
|
394
405
|
if ((variant === 'original' || baseNumChunks === 1) &&
|
|
395
|
-
|
|
406
|
+
existingKeys != null &&
|
|
407
|
+
await isVariantInStorage(storageProvider, existingKeys, variantKey, baseSize, variant === 'original' ? baseNumChunks : 1)) {
|
|
396
408
|
if (verbose) {
|
|
397
409
|
console.log(` ・ Asset found in storage with key "${variantKey}".`);
|
|
398
410
|
}
|
|
@@ -458,6 +470,7 @@ export async function action(actionArgs) {
|
|
|
458
470
|
}
|
|
459
471
|
return {
|
|
460
472
|
assetKey,
|
|
473
|
+
hidden,
|
|
461
474
|
asset: {
|
|
462
475
|
key: `sha256:${baseHash}`,
|
|
463
476
|
size: baseSize,
|
|
@@ -468,16 +481,24 @@ export async function action(actionArgs) {
|
|
|
468
481
|
batchItems,
|
|
469
482
|
};
|
|
470
483
|
});
|
|
484
|
+
let hiddenCount = 0;
|
|
471
485
|
for (const result of fileResults) {
|
|
472
486
|
if (result == null) {
|
|
473
487
|
continue;
|
|
474
488
|
}
|
|
475
|
-
|
|
489
|
+
if (result.hidden) {
|
|
490
|
+
assetsIndex[hiddenIndexKey(result.assetKey)] = result.asset;
|
|
491
|
+
hiddenCount++;
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
assetsIndex[result.assetKey] = result.asset;
|
|
495
|
+
}
|
|
476
496
|
for (const batchItem of result.batchItems) {
|
|
477
497
|
batch.add(batchItem);
|
|
478
498
|
}
|
|
479
499
|
}
|
|
480
500
|
console.log(`✅ Scan complete.`);
|
|
501
|
+
console.log(` | ${Object.keys(assetsIndex).length} file(s) in the index, ${hiddenCount} of them hidden.`);
|
|
481
502
|
if (existingKeys != null) {
|
|
482
503
|
console.log(` | ${existingVariantCount} variant(s) already in storage, ${batch.storageProviderBatchEntries.length} to upload.`);
|
|
483
504
|
}
|
|
@@ -491,6 +512,8 @@ export async function action(actionArgs) {
|
|
|
491
512
|
const indexMetadata = {
|
|
492
513
|
publishedTime: Math.floor(Date.now() / 1000),
|
|
493
514
|
expirationTime: expirationTime ?? undefined,
|
|
515
|
+
// A server that does not support hidden files must not serve this collection.
|
|
516
|
+
requires: hiddenCount > 0 ? [HIDDEN_INDEX_FEATURE] : undefined,
|
|
494
517
|
};
|
|
495
518
|
const indexFileName = `index_${collectionName}.json`;
|
|
496
519
|
const indexFilePath = path.resolve(storageContentDir, indexFileName);
|
|
@@ -519,7 +542,7 @@ export async function action(actionArgs) {
|
|
|
519
542
|
let spaFile = server.spaFile;
|
|
520
543
|
if (spaFile != null) {
|
|
521
544
|
console.log(` ✔️ Application SPA file '${spaFile}'.`);
|
|
522
|
-
const spaAsset = assetsIndex
|
|
545
|
+
const spaAsset = findAssetEntry(assetsIndex, spaFile, true);
|
|
523
546
|
if (spaAsset == null || spaAsset.contentType !== 'text/html') {
|
|
524
547
|
if (verbose) {
|
|
525
548
|
console.log(` ⚠️ Notice: '${spaFile}' does not exist or is not of type 'text/html'. Ignoring.`);
|
|
@@ -535,7 +558,7 @@ export async function action(actionArgs) {
|
|
|
535
558
|
let notFoundPageFile = server.notFoundPageFile;
|
|
536
559
|
if (notFoundPageFile != null) {
|
|
537
560
|
console.log(` ✔️ Application 'not found (404)' file '${notFoundPageFile}'.`);
|
|
538
|
-
const notFoundPageAsset = assetsIndex
|
|
561
|
+
const notFoundPageAsset = findAssetEntry(assetsIndex, notFoundPageFile, true);
|
|
539
562
|
if (notFoundPageAsset == null || notFoundPageAsset.contentType !== 'text/html') {
|
|
540
563
|
if (verbose) {
|
|
541
564
|
console.log(` ⚠️ Notice: '${notFoundPageFile}' does not exist or is not of type 'text/html'. Ignoring.`);
|
|
@@ -564,8 +587,31 @@ export async function action(actionArgs) {
|
|
|
564
587
|
const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
|
|
565
588
|
await storageProvider.submitStorageEntry(settingsFileKey, settingsFilePath, JSON.stringify(serverSettings));
|
|
566
589
|
console.log(`✅ Settings have been saved.`);
|
|
590
|
+
// A failed purge is only a warning (exit 0), because the content is published.
|
|
591
|
+
const purgeResults = [];
|
|
567
592
|
if (purgeTarget != null) {
|
|
568
|
-
await purgeCollection(purgeTarget, publishId, collectionName);
|
|
593
|
+
purgeResults.push(...await purgeCollection(purgeTarget, publishId, collectionName));
|
|
569
594
|
}
|
|
570
595
|
console.log(`🎉 Completed.`);
|
|
596
|
+
setJsonResult({
|
|
597
|
+
collection: collectionName,
|
|
598
|
+
publishId,
|
|
599
|
+
// The files in the index.
|
|
600
|
+
files: {
|
|
601
|
+
total: Object.keys(assetsIndex).length,
|
|
602
|
+
hidden: hiddenCount,
|
|
603
|
+
},
|
|
604
|
+
// Each file, and each compressed variant that is kept.
|
|
605
|
+
storageItems: {
|
|
606
|
+
uploaded: batch.storageProviderBatchEntries.length,
|
|
607
|
+
reused: existingVariantCount,
|
|
608
|
+
},
|
|
609
|
+
expiresAt: expirationTime != null ? new Date(expirationTime * 1000).toISOString() : null,
|
|
610
|
+
// null: no purge (--local, or no Service ID).
|
|
611
|
+
purge: purgeTarget != null ? {
|
|
612
|
+
ok: purgeResults.every(x => x.result !== 'failed'),
|
|
613
|
+
serviceId: purgeTarget.serviceId,
|
|
614
|
+
environments: purgeResults,
|
|
615
|
+
} : null,
|
|
616
|
+
});
|
|
571
617
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/status.ts"],"names":[],"mappings":"AAgDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAiIhD"}
|