@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,162 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { managedAppState } from '../../managed/app.js';
|
|
7
|
+
import { loadManagedProject } from '../../managed/command-helpers.js';
|
|
8
|
+
import { getActiveVersion, getVersionDomains } from '../../managed/fastly-service.js';
|
|
9
|
+
import { parseVersionComment } from '../../managed/fingerprint.js';
|
|
10
|
+
import { checkProjectVersion } from '../../managed/version-check.js';
|
|
11
|
+
import { loadApiToken } from '../../util/api-token.js';
|
|
12
|
+
import { parseCommandLine } from '../../util/args.js';
|
|
13
|
+
import { recordFailure, setJsonResult } from '../../util/output.js';
|
|
14
|
+
import { detectProjectMode } from '../../util/config.js';
|
|
15
|
+
import { cliCommand, getOwnVersion } from '../../util/package.js';
|
|
16
|
+
import { loadServiceId } from '../../util/service-id.js';
|
|
17
|
+
import { previewUrlTemplates } from '../../../models/config/collection-selection.js';
|
|
18
|
+
import { MANAGED_APP_DIR } from '../../../models/config/static-publish-project.js';
|
|
19
|
+
import { DEFAULT_APP_TEMPLATE_NAME } from '../scaffold/app-template.js';
|
|
20
|
+
import { providedVersions } from '../../managed/template-init.js';
|
|
21
|
+
function help() {
|
|
22
|
+
console.log(`\
|
|
23
|
+
|
|
24
|
+
Usage:
|
|
25
|
+
${cliCommand()} status [options]
|
|
26
|
+
|
|
27
|
+
Description:
|
|
28
|
+
Shows the state of the app. In a managed project: the fingerprint of the app
|
|
29
|
+
that the project generates, the fingerprint of the active version of the
|
|
30
|
+
service, and if a deploy is necessary. In an ejected app: the Service ID.
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
--fastly-service-id=<id> The service. Default: FASTLY_SERVICE_ID, then
|
|
34
|
+
managed.serviceId (or service_id in fastly.toml).
|
|
35
|
+
--fastly-api-token=<token> Reads the active version of the service. Default:
|
|
36
|
+
FASTLY_API_TOKEN. Without a token, the deployed
|
|
37
|
+
fingerprint is unknown.
|
|
38
|
+
|
|
39
|
+
Global Options:
|
|
40
|
+
-h, --help Show this help message and exit.
|
|
41
|
+
`);
|
|
42
|
+
}
|
|
43
|
+
export async function action(actionArgs) {
|
|
44
|
+
const optionDefinitions = [
|
|
45
|
+
{ name: 'fastly-service-id', type: String },
|
|
46
|
+
{ name: 'fastly-api-token', type: String },
|
|
47
|
+
];
|
|
48
|
+
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
49
|
+
if (parsed.needHelp) {
|
|
50
|
+
if (parsed.error != null) {
|
|
51
|
+
console.error(String(parsed.error));
|
|
52
|
+
console.error();
|
|
53
|
+
recordFailure('usage', String(parsed.error));
|
|
54
|
+
}
|
|
55
|
+
help();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const { ['fastly-service-id']: fastlyServiceId, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
59
|
+
if (detectProjectMode() === 'ejected') {
|
|
60
|
+
const serviceIdResult = loadServiceId({ commandLine: fastlyServiceId, fastlyTomlPath: path.resolve('fastly.toml') });
|
|
61
|
+
console.log(`Mode : ejected`);
|
|
62
|
+
console.log(`Service ID : ${serviceIdResult?.serviceId ?? '(none)'}`);
|
|
63
|
+
setJsonResult({ mode: 'ejected', serviceId: serviceIdResult?.serviceId ?? null });
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const project = await loadManagedProject('status', '');
|
|
67
|
+
if (project == null) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const running = getOwnVersion();
|
|
71
|
+
const versionCheck = checkProjectVersion(project.managed.staticPublishVersion, running);
|
|
72
|
+
const { fingerprint } = await managedAppState(path.resolve(), project);
|
|
73
|
+
const serviceIdResult = loadServiceId({
|
|
74
|
+
commandLine: fastlyServiceId,
|
|
75
|
+
// After the first deploy, the Fastly CLI writes service_id here.
|
|
76
|
+
fastlyTomlPath: path.resolve(MANAGED_APP_DIR, 'fastly.toml'),
|
|
77
|
+
projectServiceId: project.managed.serviceId,
|
|
78
|
+
});
|
|
79
|
+
const serviceId = serviceIdResult?.serviceId ?? null;
|
|
80
|
+
const apiToken = loadApiToken({ commandLine: fastlyApiToken });
|
|
81
|
+
let deployedFingerprint = null;
|
|
82
|
+
let deployedStaticPublishVersion = null;
|
|
83
|
+
let activeVersion = null;
|
|
84
|
+
let domain = null;
|
|
85
|
+
let needsDeploy;
|
|
86
|
+
const reasons = [];
|
|
87
|
+
if (serviceId == null) {
|
|
88
|
+
needsDeploy = true;
|
|
89
|
+
reasons.push('The project has no service yet (no Service ID).');
|
|
90
|
+
}
|
|
91
|
+
else if (apiToken == null) {
|
|
92
|
+
needsDeploy = null;
|
|
93
|
+
reasons.push('Unknown: no API token, so the active version of the service cannot be read.');
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const context = { apiToken: apiToken.apiToken };
|
|
97
|
+
const active = await getActiveVersion(context, serviceId);
|
|
98
|
+
if (active == null) {
|
|
99
|
+
needsDeploy = true;
|
|
100
|
+
reasons.push('The service has no active version.');
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
activeVersion = active.number;
|
|
104
|
+
domain = (await getVersionDomains(context, serviceId, active.number))[0] ?? null;
|
|
105
|
+
const deployed = parseVersionComment(active.comment);
|
|
106
|
+
if (deployed == null) {
|
|
107
|
+
needsDeploy = true;
|
|
108
|
+
reasons.push(`The active version (${active.number}) was not deployed by 'deploy' (its comment has no fingerprint).`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
deployedFingerprint = deployed.fingerprint;
|
|
112
|
+
deployedStaticPublishVersion = deployed.staticPublishVersion;
|
|
113
|
+
needsDeploy = deployed.fingerprint !== fingerprint;
|
|
114
|
+
if (needsDeploy) {
|
|
115
|
+
reasons.push(deployed.staticPublishVersion !== running ?
|
|
116
|
+
`The version of this package changed: ${deployed.staticPublishVersion} → ${running}.` :
|
|
117
|
+
'The generated app changed.');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const baseUrl = domain != null ? `https://${domain}` : 'https://<service domain>';
|
|
123
|
+
const previewUrls = project.rc.collectionSelection != null ? previewUrlTemplates(baseUrl, project.rc.collectionSelection) : [];
|
|
124
|
+
// The packages that the template provides to its folder (for example to the
|
|
125
|
+
// Hono extensions), with the versions of the generated app.
|
|
126
|
+
const templateName = project.managed.template ?? DEFAULT_APP_TEMPLATE_NAME;
|
|
127
|
+
const providedPackages = providedVersions(templateName, path.resolve(MANAGED_APP_DIR, 'node_modules'), running);
|
|
128
|
+
console.log(`Mode : managed`);
|
|
129
|
+
console.log(`Template : ${templateName}`);
|
|
130
|
+
console.log(`Service ID : ${serviceId ?? '(none)'}${serviceIdResult != null ? ` (from ${serviceIdResult.source})` : ''}`);
|
|
131
|
+
console.log(`Version of the project : ${versionCheck.recorded ?? '(missing)'}`);
|
|
132
|
+
console.log(`Version that runs : ${running}${versionCheck.result !== 'same' ? ` ⚠️ ${versionCheck.result}` : ''}`);
|
|
133
|
+
console.log(`Fingerprint : ${fingerprint}`);
|
|
134
|
+
console.log(`Deployed fingerprint : ${deployedFingerprint ?? '(unknown)'}${activeVersion != null ? ` (version ${activeVersion})` : ''}`);
|
|
135
|
+
console.log(`Deploy necessary : ${needsDeploy == null ? 'unknown' : needsDeploy ? 'yes' : 'no'}`);
|
|
136
|
+
for (const reason of reasons) {
|
|
137
|
+
console.log(` * ${reason}`);
|
|
138
|
+
}
|
|
139
|
+
for (const { type, url } of previewUrls) {
|
|
140
|
+
console.log(`Preview URL (${type})${' '.repeat(Math.max(0, 9 - type.length))}: ${url}`);
|
|
141
|
+
}
|
|
142
|
+
setJsonResult({
|
|
143
|
+
mode: 'managed',
|
|
144
|
+
template: { name: templateName, provides: providedPackages },
|
|
145
|
+
serviceId,
|
|
146
|
+
staticPublishVersion: {
|
|
147
|
+
recorded: versionCheck.recorded ?? null,
|
|
148
|
+
running,
|
|
149
|
+
check: versionCheck.result,
|
|
150
|
+
},
|
|
151
|
+
fingerprint: {
|
|
152
|
+
current: fingerprint,
|
|
153
|
+
deployed: deployedFingerprint,
|
|
154
|
+
deployedStaticPublishVersion,
|
|
155
|
+
},
|
|
156
|
+
activeVersion,
|
|
157
|
+
domain,
|
|
158
|
+
needsDeploy,
|
|
159
|
+
reasons,
|
|
160
|
+
previewUrls,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/template/index.ts"],"names":[],"mappings":"AA4BA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAuBhD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import { getCommandAndArgs } from '../../../util/args.js';
|
|
6
|
+
import { recordFailure } from '../../../util/output.js';
|
|
7
|
+
import * as initCommand from './init.js';
|
|
8
|
+
import { cliCommand } from '../../../util/package.js';
|
|
9
|
+
function help() {
|
|
10
|
+
console.log(`\
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
${cliCommand()} template <sub-command> [options]
|
|
14
|
+
|
|
15
|
+
Description:
|
|
16
|
+
Commands for the template of the app.
|
|
17
|
+
|
|
18
|
+
Available Subcommands:
|
|
19
|
+
init Make or update the folder of the template
|
|
20
|
+
(for the hono template: hono-extensions/)
|
|
21
|
+
|
|
22
|
+
Global Options:
|
|
23
|
+
-h, --help Show this help message and exit.
|
|
24
|
+
`);
|
|
25
|
+
}
|
|
26
|
+
export async function action(actionArgs) {
|
|
27
|
+
const modes = {
|
|
28
|
+
'init': initCommand,
|
|
29
|
+
};
|
|
30
|
+
const commandAndArgs = getCommandAndArgs(actionArgs, modes);
|
|
31
|
+
if (commandAndArgs.needHelp) {
|
|
32
|
+
if (commandAndArgs.error != null) {
|
|
33
|
+
console.error(commandAndArgs.error);
|
|
34
|
+
console.error(`Specify one of the following sub-commands: ${Object.keys(modes).join(', ')}`);
|
|
35
|
+
console.error();
|
|
36
|
+
recordFailure('usage', commandAndArgs.error);
|
|
37
|
+
}
|
|
38
|
+
help();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const { command, argv, } = commandAndArgs;
|
|
42
|
+
await modes[command].action(argv);
|
|
43
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type StaticPublishRc } from '../../../../models/config/static-publish-rc.js';
|
|
2
|
+
export type RunTemplateInitParams = {
|
|
3
|
+
templateName: string;
|
|
4
|
+
rc: Pick<StaticPublishRc, 'build'>;
|
|
5
|
+
baseDir: string;
|
|
6
|
+
appNodeModulesDir: string | undefined;
|
|
7
|
+
reset?: boolean;
|
|
8
|
+
force?: boolean;
|
|
9
|
+
check?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function runTemplateInit(params: RunTemplateInitParams): Promise<void>;
|
|
12
|
+
export declare function action(actionArgs: string[]): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/template/init.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gDAAgD,CAAC;AAyCtF,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAGnC,OAAO,EAAE,MAAM,CAAC;IAEhB,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AASF,wBAAsB,eAAe,CAAC,MAAM,EAAE,qBAAqB,iBAqDlE;AAED,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAsEhD"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import readline from 'node:readline/promises';
|
|
8
|
+
import { MANAGED_APP_DIR, PROJECT_FILE_NAME, RC_FILE_NAME } from '../../../../models/config/static-publish-project.js';
|
|
9
|
+
import { DEFAULT_APP_TEMPLATE_NAME } from '../../scaffold/app-template.js';
|
|
10
|
+
import { DEFAULT_HONO_EXTENSIONS_DIR } from '../../../hono/build.js';
|
|
11
|
+
import { loadManagedProject } from '../../../managed/command-helpers.js';
|
|
12
|
+
import { applyTemplateInit, planTemplateInit, providedVersions, templateHasInit } from '../../../managed/template-init.js';
|
|
13
|
+
import { parseCommandLine } from '../../../util/args.js';
|
|
14
|
+
import { LoadConfigError, detectProjectMode, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
15
|
+
import { rootRelative } from '../../../util/files.js';
|
|
16
|
+
import { fail, isNonInteractive, recordFailure } from '../../../util/output.js';
|
|
17
|
+
import { cliCommand, getOwnVersion } from '../../../util/package.js';
|
|
18
|
+
function help() {
|
|
19
|
+
console.log(`\
|
|
20
|
+
|
|
21
|
+
Usage:
|
|
22
|
+
${cliCommand()} template init [options]
|
|
23
|
+
|
|
24
|
+
Description:
|
|
25
|
+
Makes or updates the folder of the app's template: for the hono template,
|
|
26
|
+
the extensions folder (build.hono.extensionsDir, default ./hono-extensions).
|
|
27
|
+
The template is managed.template in ${PROJECT_FILE_NAME}, or
|
|
28
|
+
generatedFrom.template in ${RC_FILE_NAME}.
|
|
29
|
+
|
|
30
|
+
A new folder gets package.json, tsconfig.json, and inactive examples. In a
|
|
31
|
+
folder that exists, it updates only the peer dependencies on the packages
|
|
32
|
+
that the app provides, and adds the starter files that are missing. It never
|
|
33
|
+
changes your modules. Then run npm install in the folder.
|
|
34
|
+
|
|
35
|
+
Options:
|
|
36
|
+
--reset Also write the starter files again (tsconfig.json
|
|
37
|
+
and the examples). Asks before it replaces a file,
|
|
38
|
+
or needs --force in non-interactive mode.
|
|
39
|
+
--force With --reset: replace without a question.
|
|
40
|
+
--check Change nothing. Fail (template-init-needed) if
|
|
41
|
+
the folder is out of date. For CI.
|
|
42
|
+
|
|
43
|
+
Global Options:
|
|
44
|
+
-h, --help Show this help message and exit.
|
|
45
|
+
`);
|
|
46
|
+
}
|
|
47
|
+
// The folder of a template.
|
|
48
|
+
function templateFolderDir(templateName, rc, baseDir) {
|
|
49
|
+
// Only the hono template has a folder.
|
|
50
|
+
return path.resolve(baseDir, rc.build?.hono?.extensionsDir ?? DEFAULT_HONO_EXTENSIONS_DIR);
|
|
51
|
+
}
|
|
52
|
+
// template init for a template and a folder. scaffold also runs it.
|
|
53
|
+
export async function runTemplateInit(params) {
|
|
54
|
+
const { templateName, rc, baseDir, appNodeModulesDir, reset = false, force = false, check = false } = params;
|
|
55
|
+
if (!templateHasInit(templateName)) {
|
|
56
|
+
console.log(`✔️ The template '${templateName}' has no folder to initialize.`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const folderDir = templateFolderDir(templateName, rc, baseDir);
|
|
60
|
+
const folderName = rootRelative(folderDir);
|
|
61
|
+
const provided = providedVersions(templateName, appNodeModulesDir, getOwnVersion());
|
|
62
|
+
const plan = planTemplateInit(templateName, folderDir, provided, { reset });
|
|
63
|
+
if (check) {
|
|
64
|
+
if (plan.outOfDate.length > 0) {
|
|
65
|
+
fail('template-init-needed', `${folderName} is out of date. Run: ${cliCommand()} template init`);
|
|
66
|
+
for (const reason of plan.outOfDate) {
|
|
67
|
+
console.error(` * ${reason}`);
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
console.log(`✅ ${folderName} is up to date.`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (plan.replace.length > 0 && !force) {
|
|
75
|
+
console.log(`template init --reset replaces these files in ${folderName}:`);
|
|
76
|
+
for (const file of plan.replace) {
|
|
77
|
+
console.log(` * ${file}`);
|
|
78
|
+
}
|
|
79
|
+
if (isNonInteractive()) {
|
|
80
|
+
fail('usage', 'In non-interactive mode, template init --reset needs --force to replace files.');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
84
|
+
const answer = await rl.question('Replace them? (y/N) ');
|
|
85
|
+
rl.close();
|
|
86
|
+
if (!/^y(es)?$/i.test(answer.trim())) {
|
|
87
|
+
console.log('Nothing changed.');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const isNew = !fs.existsSync(folderDir);
|
|
92
|
+
const files = Object.keys(plan.write);
|
|
93
|
+
if (files.length === 0) {
|
|
94
|
+
console.log(`✅ ${folderName} is up to date. Nothing changed.`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
applyTemplateInit(folderDir, plan);
|
|
98
|
+
console.log(`✅ ${isNew ? 'Made' : 'Updated'} ${folderName}: ${files.join(', ')}`);
|
|
99
|
+
if (isNew || 'package.json' in plan.write) {
|
|
100
|
+
console.log(` * Run npm install in ${folderName}.`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export async function action(actionArgs) {
|
|
104
|
+
const optionDefinitions = [
|
|
105
|
+
{ name: 'reset', type: Boolean },
|
|
106
|
+
{ name: 'force', type: Boolean },
|
|
107
|
+
{ name: 'check', type: Boolean },
|
|
108
|
+
];
|
|
109
|
+
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
110
|
+
if (parsed.needHelp) {
|
|
111
|
+
if (parsed.error != null) {
|
|
112
|
+
console.error(String(parsed.error));
|
|
113
|
+
console.error();
|
|
114
|
+
recordFailure('usage', String(parsed.error));
|
|
115
|
+
}
|
|
116
|
+
help();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const { reset, force, check } = parsed.commandLineOptions;
|
|
120
|
+
if (check && (reset || force)) {
|
|
121
|
+
fail('usage', '--check cannot be used with --reset or --force.');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (force && !reset) {
|
|
125
|
+
fail('usage', '--force is only for --reset.');
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
let templateName;
|
|
129
|
+
let rc;
|
|
130
|
+
let appNodeModulesDir;
|
|
131
|
+
if (detectProjectMode() === 'managed') {
|
|
132
|
+
const project = await loadManagedProject('template init', '');
|
|
133
|
+
if (project == null) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
templateName = project.managed.template ?? DEFAULT_APP_TEMPLATE_NAME;
|
|
137
|
+
rc = project.rc;
|
|
138
|
+
appNodeModulesDir = path.resolve(MANAGED_APP_DIR, 'node_modules');
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
try {
|
|
142
|
+
rc = await loadStaticPublisherRcFile();
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
console.error(`❌ Can't load ${RC_FILE_NAME}`);
|
|
146
|
+
if (err instanceof LoadConfigError) {
|
|
147
|
+
for (const error of err.errors) {
|
|
148
|
+
console.error(error);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
recordFailure('config-invalid', `Can't load ${RC_FILE_NAME}.`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
templateName = rc.generatedFrom?.template;
|
|
155
|
+
if (templateName == null) {
|
|
156
|
+
fail('config-invalid', `${RC_FILE_NAME} has no generatedFrom, so the template of the app is not known.`);
|
|
157
|
+
console.error(` * Add it by hand, for example:`);
|
|
158
|
+
console.error(` generatedFrom: { template: 'hono', staticPublishVersion: '${getOwnVersion()}', generatedAt: 'YYYY-MM-DD' },`);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
appNodeModulesDir = path.resolve('node_modules');
|
|
162
|
+
}
|
|
163
|
+
await runTemplateInit({
|
|
164
|
+
templateName,
|
|
165
|
+
rc,
|
|
166
|
+
baseDir: path.resolve(),
|
|
167
|
+
appNodeModulesDir,
|
|
168
|
+
reset,
|
|
169
|
+
force,
|
|
170
|
+
check,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/upgrade.ts"],"names":[],"mappings":"AAiCA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAiChD"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import { loadManagedProject, writeProjectVersion } from '../../managed/command-helpers.js';
|
|
6
|
+
import { checkProjectVersion } from '../../managed/version-check.js';
|
|
7
|
+
import { parseCommandLine } from '../../util/args.js';
|
|
8
|
+
import { cliCommand, getOwnVersion } from '../../util/package.js';
|
|
9
|
+
import { PROJECT_FILE_NAME } from '../../../models/config/static-publish-project.js';
|
|
10
|
+
import { fail, recordFailure } from '../../util/output.js';
|
|
11
|
+
function help() {
|
|
12
|
+
console.log(`\
|
|
13
|
+
|
|
14
|
+
Usage:
|
|
15
|
+
${cliCommand()} upgrade
|
|
16
|
+
|
|
17
|
+
Description:
|
|
18
|
+
Moves a managed project to the version of @fastly/compute-js-static-publish
|
|
19
|
+
that runs: sets managed.staticPublishVersion in ${PROJECT_FILE_NAME}.
|
|
20
|
+
dev and deploy stop when this version is not the version that runs.
|
|
21
|
+
The next deploy then deploys the app of the new version.
|
|
22
|
+
|
|
23
|
+
Commit the change of ${PROJECT_FILE_NAME}.
|
|
24
|
+
|
|
25
|
+
Global Options:
|
|
26
|
+
-h, --help Show this help message and exit.
|
|
27
|
+
`);
|
|
28
|
+
}
|
|
29
|
+
export async function action(actionArgs) {
|
|
30
|
+
const optionDefinitions = [];
|
|
31
|
+
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
32
|
+
if (parsed.needHelp) {
|
|
33
|
+
if (parsed.error != null) {
|
|
34
|
+
console.error(String(parsed.error));
|
|
35
|
+
console.error();
|
|
36
|
+
recordFailure('usage', String(parsed.error));
|
|
37
|
+
}
|
|
38
|
+
help();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const project = await loadManagedProject('upgrade', 'An ejected app has no recorded version.');
|
|
42
|
+
if (project == null) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const running = getOwnVersion();
|
|
46
|
+
const check = checkProjectVersion(project.managed.staticPublishVersion, running);
|
|
47
|
+
if (check.result === 'same') {
|
|
48
|
+
console.log(`✅ The project already uses ${running}.`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (check.result === 'older-cli') {
|
|
52
|
+
fail('version-mismatch', `The project uses ${check.recorded}, which is newer than the version that runs (${running}). 'upgrade' does not move a project to an older version.`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!writeProjectVersion(running)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
console.log(`✅ The project now uses ${running}${check.recorded != null ? ` (was ${check.recorded})` : ''}. Commit ${PROJECT_FILE_NAME}.`);
|
|
59
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type ServeResult = {
|
|
2
|
+
status: number | null;
|
|
3
|
+
signal: NodeJS.Signals | null;
|
|
4
|
+
error?: Error;
|
|
5
|
+
};
|
|
6
|
+
export declare function serveApp(appDir: string, serveArgs: string[]): Promise<ServeResult>;
|
|
7
|
+
export declare function runDevWatch(args: string[]): Promise<number>;
|
|
8
|
+
//# sourceMappingURL=run-dev-watch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-dev-watch.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/run-dev-watch.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;IAC9B,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAOF,wBAAsB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAiBxF;AAKD,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAQjE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import * as child_process from 'node:child_process';
|
|
6
|
+
import * as fs from 'node:fs';
|
|
7
|
+
import * as path from 'node:path';
|
|
8
|
+
import { TEMPLATE_WATCH_SCRIPT } from './scaffold/generate-app.js';
|
|
9
|
+
// Runs `fastly compute serve` in the app dir. With --watch, the watch script
|
|
10
|
+
// (if the app has one) runs next to it, until the Fastly CLI stops. The script
|
|
11
|
+
// can watch files outside the app dir: when they change, it writes a file in
|
|
12
|
+
// the app dir, and then the Fastly CLI builds the app again. The Fastly CLI of
|
|
13
|
+
// the app is used, if it has one.
|
|
14
|
+
export async function serveApp(appDir, serveArgs) {
|
|
15
|
+
const appFastly = path.resolve(appDir, 'node_modules/.bin/fastly');
|
|
16
|
+
const fastly = fs.existsSync(appFastly) ? appFastly : 'fastly';
|
|
17
|
+
const watchScript = path.resolve(appDir, TEMPLATE_WATCH_SCRIPT);
|
|
18
|
+
const watcher = serveArgs.includes('--watch') && fs.existsSync(watchScript) ?
|
|
19
|
+
child_process.spawn(process.execPath, [watchScript], { cwd: appDir, stdio: 'inherit' }) :
|
|
20
|
+
undefined;
|
|
21
|
+
console.log(`▶️ fastly compute serve ${serveArgs.join(' ')}`);
|
|
22
|
+
const result = await new Promise(resolve => {
|
|
23
|
+
const child = child_process.spawn(fastly, ['compute', 'serve', ...serveArgs], { cwd: appDir, stdio: 'inherit' });
|
|
24
|
+
child.on('error', error => resolve({ status: null, signal: null, error }));
|
|
25
|
+
child.on('exit', (status, signal) => resolve({ status, signal }));
|
|
26
|
+
});
|
|
27
|
+
watcher?.kill();
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
// The dev:watch script of every app calls this: `fastly compute serve --watch`
|
|
31
|
+
// in the current directory, with the watch script of the app. The arguments
|
|
32
|
+
// go to `fastly compute serve`. Returns the exit code.
|
|
33
|
+
export async function runDevWatch(args) {
|
|
34
|
+
const serveArgs = args.includes('--watch') ? args : ['--watch', ...args];
|
|
35
|
+
const result = await serveApp(path.resolve(), serveArgs);
|
|
36
|
+
if (result.error != null) {
|
|
37
|
+
console.error(`❌ Could not run 'fastly compute serve': ${String(result.error)}`);
|
|
38
|
+
return 1;
|
|
39
|
+
}
|
|
40
|
+
return result.status ?? (result.signal != null ? 0 : 1);
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-template-hook.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/run-template-hook.ts"],"names":[],"mappings":"AAeA,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAiBhE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import * as child_process from 'node:child_process';
|
|
6
|
+
import * as fs from 'node:fs';
|
|
7
|
+
import * as path from 'node:path';
|
|
8
|
+
import { TEMPLATE_HOOKS } from './scaffold/generate-app.js';
|
|
9
|
+
// Runs scripts/template_<name>.js of the app in the current directory, if it
|
|
10
|
+
// exists. The npm scripts prebuild, postbuild, and postinstall of every
|
|
11
|
+
// scaffolded app call this, so a template, or the customer, can add a hook by
|
|
12
|
+
// adding the file. Returns the exit code.
|
|
13
|
+
export function runTemplateHook(name) {
|
|
14
|
+
if (name == null || !TEMPLATE_HOOKS.includes(name)) {
|
|
15
|
+
console.error(`❌ run-template-hook: the hook must be one of: ${TEMPLATE_HOOKS.join(', ')}.`);
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
18
|
+
const hookFile = path.resolve(`scripts/template_${name}.js`);
|
|
19
|
+
if (!fs.existsSync(hookFile)) {
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
const result = child_process.spawnSync(process.execPath, [hookFile], { stdio: 'inherit' });
|
|
23
|
+
if (result.error != null) {
|
|
24
|
+
console.error(`❌ run-template-hook: could not run ${hookFile}: ${String(result.error)}`);
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
return result.status ?? 1;
|
|
28
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type AppTemplate = {
|
|
2
|
+
name: string;
|
|
3
|
+
files: Record<string, string>;
|
|
4
|
+
entry: string;
|
|
5
|
+
dependencies: Record<string, string>;
|
|
6
|
+
devDependencies: Record<string, string>;
|
|
7
|
+
supports: AppTemplateSupports;
|
|
8
|
+
gitignore: string[];
|
|
9
|
+
};
|
|
10
|
+
export type AppTemplateSupports = {
|
|
11
|
+
collectionSelection?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare const APP_TEMPLATE_NAMES: string[];
|
|
14
|
+
export declare const DEFAULT_APP_TEMPLATE_NAME = "plain";
|
|
15
|
+
export declare function isAppTemplateName(name: string): boolean;
|
|
16
|
+
export declare function loadAppTemplate(name: string): AppTemplate;
|
|
17
|
+
//# sourceMappingURL=app-template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-template.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/app-template.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IAGb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAG9B,KAAK,EAAE,MAAM,CAAC;IAEd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,QAAQ,EAAE,mBAAmB,CAAC;IAG9B,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAGF,MAAM,MAAM,mBAAmB,GAAG;IAGhC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AASF,eAAO,MAAM,kBAAkB,UAA6B,CAAC;AAE7D,eAAO,MAAM,yBAAyB,UAAU,CAAC;AAKjD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,WAE7C;AAGD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAmCzD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { resourcesDir } from '../../util/resources.js';
|
|
8
|
+
// The templates in resources/templates/: what each one supports, and the lines
|
|
9
|
+
// that it adds to the .gitignore of the app.
|
|
10
|
+
const APP_TEMPLATES = {
|
|
11
|
+
plain: { supports: { collectionSelection: true }, gitignore: [] },
|
|
12
|
+
hono: { supports: { collectionSelection: true }, gitignore: ['/src/hono-extensions.generated.js'] },
|
|
13
|
+
};
|
|
14
|
+
export const APP_TEMPLATE_NAMES = Object.keys(APP_TEMPLATES);
|
|
15
|
+
export const DEFAULT_APP_TEMPLATE_NAME = 'plain';
|
|
16
|
+
// The files in a template directory that are not files of the app.
|
|
17
|
+
const TEMPLATE_PACKAGE_FILES = ['package.json', 'package-lock.json'];
|
|
18
|
+
export function isAppTemplateName(name) {
|
|
19
|
+
return APP_TEMPLATE_NAMES.includes(name);
|
|
20
|
+
}
|
|
21
|
+
// Reads resources/templates/<name>/.
|
|
22
|
+
export function loadAppTemplate(name) {
|
|
23
|
+
if (!isAppTemplateName(name)) {
|
|
24
|
+
throw new Error(`Unknown template '${name}'. Valid templates: ${APP_TEMPLATE_NAMES.join(', ')}.`);
|
|
25
|
+
}
|
|
26
|
+
const templateDir = path.resolve(resourcesDir, 'templates', name);
|
|
27
|
+
const files = {};
|
|
28
|
+
const walk = (sub) => {
|
|
29
|
+
for (const entry of fs.readdirSync(path.resolve(templateDir, sub), { withFileTypes: true })) {
|
|
30
|
+
const rel = path.posix.join(sub, entry.name);
|
|
31
|
+
if (entry.isDirectory()) {
|
|
32
|
+
if (entry.name !== 'node_modules') {
|
|
33
|
+
walk(rel);
|
|
34
|
+
}
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (sub === '' && TEMPLATE_PACKAGE_FILES.includes(entry.name)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
files[rel] = fs.readFileSync(path.resolve(templateDir, rel), 'utf-8');
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
walk('');
|
|
44
|
+
const packageJson = JSON.parse(fs.readFileSync(path.resolve(templateDir, 'package.json'), 'utf-8'));
|
|
45
|
+
return {
|
|
46
|
+
name,
|
|
47
|
+
files,
|
|
48
|
+
entry: packageJson.main ?? 'src/index.js',
|
|
49
|
+
dependencies: packageJson.dependencies ?? {},
|
|
50
|
+
devDependencies: packageJson.devDependencies ?? {},
|
|
51
|
+
supports: APP_TEMPLATES[name].supports,
|
|
52
|
+
gitignore: APP_TEMPLATES[name].gitignore,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type FastlyTomlSections } from '../../../models/config/static-publish-project.js';
|
|
2
|
+
export declare const FASTLY_TOML_SECTIONS: readonly ['local_server', 'setup'];
|
|
3
|
+
export declare function checkFastlyTomlSections(value: unknown, errors: string[]): value is FastlyTomlSections;
|
|
4
|
+
export declare function addFastlyTomlSections(fastlyToml: string, sections: FastlyTomlSections | undefined): string;
|
|
5
|
+
//# sourceMappingURL=fastly-toml-sections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastly-toml-sections.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/fastly-toml-sections.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,kDAAkD,CAAC;AAI3F,eAAO,MAAM,oBAAoB,YAAK,cAAc,EAAE,OAAO,CAAW,CAAC;AAWzE,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI,kBAAkB,CAkDrG;AAmDD,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,SAAS,GAAG,MAAM,CAsC1G"}
|