@fastly/compute-js-static-publish 8.0.1 → 8.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/DOCUMENTATION.md +779 -22
  2. package/README.md +2 -2
  3. package/README.short.md +2 -2
  4. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
  5. package/build/cli/cli/commands/manage/clean.js +12 -7
  6. package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
  7. package/build/cli/cli/commands/manage/collections/delete.js +29 -13
  8. package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
  9. package/build/cli/cli/commands/manage/collections/index.js +6 -1
  10. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
  11. package/build/cli/cli/commands/manage/collections/list.js +47 -7
  12. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  13. package/build/cli/cli/commands/manage/collections/promote.js +67 -20
  14. package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
  15. package/build/cli/cli/commands/manage/collections/update-expiration.js +10 -11
  16. package/build/cli/cli/commands/manage/deploy.d.ts +2 -0
  17. package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -0
  18. package/build/cli/cli/commands/manage/deploy.js +194 -0
  19. package/build/cli/cli/commands/manage/dev.d.ts +2 -0
  20. package/build/cli/cli/commands/manage/dev.d.ts.map +1 -0
  21. package/build/cli/cli/commands/manage/dev.js +77 -0
  22. package/build/cli/cli/commands/manage/eject.d.ts +2 -0
  23. package/build/cli/cli/commands/manage/eject.d.ts.map +1 -0
  24. package/build/cli/cli/commands/manage/eject.js +155 -0
  25. package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
  26. package/build/cli/cli/commands/manage/index.js +37 -1
  27. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  28. package/build/cli/cli/commands/manage/publish-content.js +78 -33
  29. package/build/cli/cli/commands/manage/status.d.ts +2 -0
  30. package/build/cli/cli/commands/manage/status.d.ts.map +1 -0
  31. package/build/cli/cli/commands/manage/status.js +162 -0
  32. package/build/cli/cli/commands/manage/template/index.d.ts +2 -0
  33. package/build/cli/cli/commands/manage/template/index.d.ts.map +1 -0
  34. package/build/cli/cli/commands/manage/template/index.js +42 -0
  35. package/build/cli/cli/commands/manage/template/init.d.ts +13 -0
  36. package/build/cli/cli/commands/manage/template/init.d.ts.map +1 -0
  37. package/build/cli/cli/commands/manage/template/init.js +172 -0
  38. package/build/cli/cli/commands/manage/upgrade.d.ts +2 -0
  39. package/build/cli/cli/commands/manage/upgrade.d.ts.map +1 -0
  40. package/build/cli/cli/commands/manage/upgrade.js +59 -0
  41. package/build/cli/cli/commands/run-dev-watch.d.ts +8 -0
  42. package/build/cli/cli/commands/run-dev-watch.d.ts.map +1 -0
  43. package/build/cli/cli/commands/run-dev-watch.js +41 -0
  44. package/build/cli/cli/commands/run-template-hook.d.ts +2 -0
  45. package/build/cli/cli/commands/run-template-hook.d.ts.map +1 -0
  46. package/build/cli/cli/commands/run-template-hook.js +28 -0
  47. package/build/cli/cli/commands/scaffold/app-template.d.ts +17 -0
  48. package/build/cli/cli/commands/scaffold/app-template.d.ts.map +1 -0
  49. package/build/cli/cli/commands/scaffold/app-template.js +54 -0
  50. package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts +5 -0
  51. package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts.map +1 -0
  52. package/build/cli/cli/commands/scaffold/fastly-toml-sections.js +154 -0
  53. package/build/cli/cli/commands/scaffold/generate-app.d.ts +47 -0
  54. package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -0
  55. package/build/cli/cli/commands/scaffold/generate-app.js +164 -0
  56. package/build/cli/cli/commands/scaffold/index.d.ts +6 -0
  57. package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
  58. package/build/cli/cli/commands/scaffold/index.js +208 -290
  59. package/build/cli/cli/commands/scaffold/render.d.ts +7 -0
  60. package/build/cli/cli/commands/scaffold/render.d.ts.map +1 -0
  61. package/build/cli/cli/commands/scaffold/render.js +72 -0
  62. package/build/cli/cli/hono/build.d.ts +43 -0
  63. package/build/cli/cli/hono/build.d.ts.map +1 -0
  64. package/build/cli/cli/hono/build.js +297 -0
  65. package/build/cli/cli/index.js +98 -5
  66. package/build/cli/cli/managed/app.d.ts +21 -0
  67. package/build/cli/cli/managed/app.d.ts.map +1 -0
  68. package/build/cli/cli/managed/app.js +162 -0
  69. package/build/cli/cli/managed/command-helpers.d.ts +6 -0
  70. package/build/cli/cli/managed/command-helpers.d.ts.map +1 -0
  71. package/build/cli/cli/managed/command-helpers.js +81 -0
  72. package/build/cli/cli/managed/eject.d.ts +6 -0
  73. package/build/cli/cli/managed/eject.d.ts.map +1 -0
  74. package/build/cli/cli/managed/eject.js +68 -0
  75. package/build/cli/cli/managed/fastly-service.d.ts +8 -0
  76. package/build/cli/cli/managed/fastly-service.d.ts.map +1 -0
  77. package/build/cli/cli/managed/fastly-service.js +21 -0
  78. package/build/cli/cli/managed/fingerprint.d.ts +13 -0
  79. package/build/cli/cli/managed/fingerprint.d.ts.map +1 -0
  80. package/build/cli/cli/managed/fingerprint.js +60 -0
  81. package/build/cli/cli/managed/lockfile.d.ts +31 -0
  82. package/build/cli/cli/managed/lockfile.d.ts.map +1 -0
  83. package/build/cli/cli/managed/lockfile.js +62 -0
  84. package/build/cli/cli/managed/project-edit.d.ts +3 -0
  85. package/build/cli/cli/managed/project-edit.d.ts.map +1 -0
  86. package/build/cli/cli/managed/project-edit.js +35 -0
  87. package/build/cli/cli/managed/project-file.d.ts +16 -0
  88. package/build/cli/cli/managed/project-file.d.ts.map +1 -0
  89. package/build/cli/cli/managed/project-file.js +119 -0
  90. package/build/cli/cli/managed/template-init.d.ts +12 -0
  91. package/build/cli/cli/managed/template-init.d.ts.map +1 -0
  92. package/build/cli/cli/managed/template-init.js +120 -0
  93. package/build/cli/cli/managed/version-check.d.ts +25 -0
  94. package/build/cli/cli/managed/version-check.d.ts.map +1 -0
  95. package/build/cli/cli/managed/version-check.js +84 -0
  96. package/build/cli/cli/storage/kv-store-local-provider.d.ts +1 -0
  97. package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
  98. package/build/cli/cli/storage/kv-store-local-provider.js +6 -3
  99. package/build/cli/cli/storage/kv-store-provider.d.ts +1 -0
  100. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
  101. package/build/cli/cli/storage/kv-store-provider.js +9 -1
  102. package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
  103. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
  104. package/build/cli/cli/storage/s3-storage-provider.js +4 -0
  105. package/build/cli/cli/storage/storage-provider.d.ts +3 -0
  106. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
  107. package/build/cli/cli/storage/storage-provider.js +32 -0
  108. package/build/cli/cli/util/api-token.d.ts.map +1 -1
  109. package/build/cli/cli/util/collection-name.d.ts +3 -0
  110. package/build/cli/cli/util/collection-name.d.ts.map +1 -0
  111. package/build/cli/cli/util/collection-name.js +24 -0
  112. package/build/cli/cli/util/collection-selection-flags.d.ts +13 -0
  113. package/build/cli/cli/util/collection-selection-flags.d.ts.map +1 -0
  114. package/build/cli/cli/util/collection-selection-flags.js +131 -0
  115. package/build/cli/cli/util/config.d.ts +13 -0
  116. package/build/cli/cli/util/config.d.ts.map +1 -1
  117. package/build/cli/cli/util/config.js +172 -38
  118. package/build/cli/cli/util/data.d.ts.map +1 -1
  119. package/build/cli/cli/util/global-options.d.ts +13 -0
  120. package/build/cli/cli/util/global-options.d.ts.map +1 -0
  121. package/build/cli/cli/util/global-options.js +53 -0
  122. package/build/cli/cli/util/kv-store-items.d.ts +1 -0
  123. package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
  124. package/build/cli/cli/util/kv-store-items.js +16 -40
  125. package/build/cli/cli/util/kv-store-local-server.d.ts +1 -1
  126. package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -1
  127. package/build/cli/cli/util/kv-store-local-server.js +4 -2
  128. package/build/cli/cli/util/output.d.ts +31 -0
  129. package/build/cli/cli/util/output.d.ts.map +1 -0
  130. package/build/cli/cli/util/output.js +139 -0
  131. package/build/cli/cli/util/package.d.ts +3 -0
  132. package/build/cli/cli/util/package.d.ts.map +1 -1
  133. package/build/cli/cli/util/package.js +12 -0
  134. package/build/cli/cli/util/progress.d.ts.map +1 -1
  135. package/build/cli/cli/util/purge.d.ts +6 -2
  136. package/build/cli/cli/util/purge.d.ts.map +1 -1
  137. package/build/cli/cli/util/purge.js +7 -2
  138. package/build/cli/cli/util/resources.d.ts +2 -0
  139. package/build/cli/cli/util/resources.d.ts.map +1 -0
  140. package/build/cli/cli/util/resources.js +8 -0
  141. package/build/cli/cli/util/service-id.d.ts +1 -0
  142. package/build/cli/cli/util/service-id.d.ts.map +1 -1
  143. package/build/cli/cli/util/service-id.js +5 -1
  144. package/build/cli/cli/util/variants.d.ts.map +1 -1
  145. package/build/cli/models/assets/index.d.ts +6 -0
  146. package/build/cli/models/assets/index.d.ts.map +1 -1
  147. package/build/cli/models/assets/index.js +24 -0
  148. package/build/cli/models/collections/index.d.ts +3 -0
  149. package/build/cli/models/collections/index.d.ts.map +1 -0
  150. package/build/cli/models/collections/index.js +15 -0
  151. package/build/cli/models/compression/index.d.ts +1 -1
  152. package/build/cli/models/compression/index.d.ts.map +1 -1
  153. package/build/cli/models/config/collection-selection.d.ts +55 -0
  154. package/build/cli/models/config/collection-selection.d.ts.map +1 -0
  155. package/build/cli/models/config/collection-selection.js +238 -0
  156. package/build/cli/models/config/item-patterns.d.ts +4 -0
  157. package/build/cli/models/config/item-patterns.d.ts.map +1 -0
  158. package/build/cli/models/config/item-patterns.js +43 -0
  159. package/build/cli/models/config/publish-content-config.d.ts +6 -1
  160. package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
  161. package/build/cli/models/config/static-publish-project.d.ts +23 -0
  162. package/build/cli/models/config/static-publish-project.d.ts.map +1 -0
  163. package/build/cli/models/config/static-publish-project.js +11 -0
  164. package/build/cli/models/config/static-publish-rc.d.ts +25 -0
  165. package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
  166. package/build/cli/models/config/static-publish-rc.js +31 -0
  167. package/build/cli/models/config/template-settings.d.ts +10 -0
  168. package/build/cli/models/config/template-settings.d.ts.map +1 -0
  169. package/build/cli/models/config/template-settings.js +72 -0
  170. package/build/cli/models/server/index.d.ts.map +1 -1
  171. package/build/cli/models/server/index.js +6 -2
  172. package/build/server/hono/extensions.d.ts +48 -0
  173. package/build/server/hono/extensions.d.ts.map +1 -0
  174. package/build/server/hono/extensions.js +65 -0
  175. package/build/server/hono/index.d.ts +30 -0
  176. package/build/server/hono/index.d.ts.map +1 -0
  177. package/build/server/hono/index.js +72 -0
  178. package/build/server/hono/path.d.ts +7 -0
  179. package/build/server/hono/path.d.ts.map +1 -0
  180. package/build/server/hono/path.js +32 -0
  181. package/build/server/models/assets/index.d.ts +6 -0
  182. package/build/server/models/assets/index.d.ts.map +1 -1
  183. package/build/server/models/assets/index.js +24 -0
  184. package/build/server/models/collections/index.d.ts +3 -0
  185. package/build/server/models/collections/index.d.ts.map +1 -0
  186. package/build/server/models/collections/index.js +15 -0
  187. package/build/server/models/compression/index.d.ts +1 -1
  188. package/build/server/models/compression/index.d.ts.map +1 -1
  189. package/build/server/models/config/collection-selection.d.ts +55 -0
  190. package/build/server/models/config/collection-selection.d.ts.map +1 -0
  191. package/build/server/models/config/collection-selection.js +238 -0
  192. package/build/server/models/config/item-patterns.d.ts +4 -0
  193. package/build/server/models/config/item-patterns.d.ts.map +1 -0
  194. package/build/server/models/config/item-patterns.js +43 -0
  195. package/build/server/models/config/publish-content-config.d.ts +6 -1
  196. package/build/server/models/config/publish-content-config.d.ts.map +1 -1
  197. package/build/server/models/config/static-publish-project.d.ts +23 -0
  198. package/build/server/models/config/static-publish-project.d.ts.map +1 -0
  199. package/build/server/models/config/static-publish-project.js +11 -0
  200. package/build/server/models/config/static-publish-rc.d.ts +25 -0
  201. package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
  202. package/build/server/models/config/static-publish-rc.js +31 -0
  203. package/build/server/models/server/index.d.ts.map +1 -1
  204. package/build/server/models/server/index.js +6 -2
  205. package/build/server/server/collection-selection/index.d.ts +11 -0
  206. package/build/server/server/collection-selection/index.d.ts.map +1 -0
  207. package/build/server/server/collection-selection/index.js +192 -0
  208. package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -1
  209. package/build/server/server/collection-selector/from-cookie.js +6 -8
  210. package/build/server/server/collection-selector/from-request.d.ts.map +1 -1
  211. package/build/server/server/index.d.ts +4 -1
  212. package/build/server/server/index.d.ts.map +1 -1
  213. package/build/server/server/index.js +3 -1
  214. package/build/server/server/publisher-server/accept-html.d.ts +2 -0
  215. package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
  216. package/build/server/server/publisher-server/accept-html.js +50 -0
  217. package/build/server/server/publisher-server/index.d.ts +59 -7
  218. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  219. package/build/server/server/publisher-server/index.js +362 -145
  220. package/build/server/server/publisher-server/response-cache.d.ts +3 -0
  221. package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
  222. package/build/server/server/publisher-server/response-cache.js +24 -1
  223. package/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
  224. package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
  225. package/build/server/server/storage/storage-provider.d.ts.map +1 -1
  226. package/build/server/server/util/body-length.d.ts.map +1 -1
  227. package/build/server/server/util/server-timing.d.ts.map +1 -1
  228. package/package.json +21 -3
  229. package/resources/app/fastly.toml.njk +58 -0
  230. package/resources/app/gitignore.njk +9 -0
  231. package/resources/app/publish-content.config.from-project.js.njk +9 -0
  232. package/resources/app/publish-content.config.js.njk +35 -0
  233. package/resources/app/static-publish.project.js.njk +83 -0
  234. package/resources/app/static-publish.rc.js.njk +43 -0
  235. package/resources/template-init/hono/_example.ts +22 -0
  236. package/resources/template-init/hono/tsconfig.json +17 -0
  237. package/resources/templates/hono/package-lock.json +4123 -0
  238. package/resources/templates/hono/package.json +15 -0
  239. package/resources/templates/hono/scripts/template_postinstall.js +10 -0
  240. package/resources/templates/hono/scripts/template_prebuild.js +8 -0
  241. package/resources/templates/hono/scripts/template_watch.js +15 -0
  242. package/resources/templates/hono/src/hono-extensions.generated.d.ts +5 -0
  243. package/resources/templates/hono/src/index.ts +53 -0
  244. package/resources/templates/hono/tsconfig.json +17 -0
  245. package/resources/templates/plain/package-lock.json +4088 -0
  246. package/resources/templates/plain/package.json +10 -0
  247. package/resources/templates/plain/src/index.js +34 -0
@@ -0,0 +1,2 @@
1
+ export declare function action(actionArgs: string[]): Promise<void>;
2
+ //# sourceMappingURL=deploy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/deploy.ts"],"names":[],"mappings":"AAuEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAqJhD"}
@@ -0,0 +1,194 @@
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 { managedAppState, prepareManagedApp } from '../../managed/app.js';
9
+ import { checkVersionForCommand, loadManagedProject, showTemplateFolderHint } from '../../managed/command-helpers.js';
10
+ import { getActiveVersion, getVersionDomains } from '../../managed/fastly-service.js';
11
+ import { formatVersionComment, parseVersionComment } from '../../managed/fingerprint.js';
12
+ import { writeBackServiceId } from '../../managed/project-edit.js';
13
+ import { loadApiToken } from '../../util/api-token.js';
14
+ import { parseCommandLine } from '../../util/args.js';
15
+ import { detectProjectMode } from '../../util/config.js';
16
+ import { readServiceId } from '../../util/fastly-toml.js';
17
+ import { getOwnPackageDir, getOwnVersion } from '../../util/package.js';
18
+ import { fail, isJsonMode, isNonInteractive, recordFailure, setJsonResult } from '../../util/output.js';
19
+ import { loadServiceId } from '../../util/service-id.js';
20
+ import { isS3StorageConfigRc } from '../../../models/config/static-publish-rc.js';
21
+ import { PROJECT_FILE_NAME } from '../../../models/config/static-publish-project.js';
22
+ function help() {
23
+ console.log(`\
24
+
25
+ Usage:
26
+ npx @fastly/compute-js-static-publish deploy [options]
27
+
28
+ Description:
29
+ Deploys the app of a managed project, only if it changed: generates the app,
30
+ installs its dependencies if necessary, and runs 'fastly compute build' and
31
+ 'fastly compute deploy'. The comment of the new service version has the
32
+ fingerprint of the app, so that 'status' and the next deploy can compare it.
33
+
34
+ After the first deploy, the Service ID is written into managed.serviceId in
35
+ ${PROJECT_FILE_NAME}.
36
+
37
+ In an ejected app, this runs 'fastly compute publish'.
38
+
39
+ Options:
40
+ --force Deploy also when the fingerprint did not change.
41
+ --auto-upgrade If the CLI is newer than managed.staticPublishVersion,
42
+ set it to the version that runs, and continue.
43
+ --comment=<text> Added to the comment of the service version,
44
+ for example a commit SHA.
45
+ --fastly-service-id=<id> The service. Default: FASTLY_SERVICE_ID, then
46
+ managed.serviceId. Without one, the Fastly CLI
47
+ makes a new service.
48
+ --fastly-api-token=<token> Default: FASTLY_API_TOKEN.
49
+
50
+ Global Options:
51
+ -h, --help Show this help message and exit.
52
+ `);
53
+ }
54
+ function runFastly(appDir, args, apiToken) {
55
+ const appFastly = path.resolve(appDir, 'node_modules/.bin/fastly');
56
+ const fastly = fs.existsSync(appFastly) ? appFastly : 'fastly';
57
+ console.log(`▶️ fastly ${args.join(' ')}`);
58
+ return child_process.spawnSync(fastly, args, {
59
+ cwd: appDir,
60
+ env: { ...process.env, FASTLY_API_TOKEN: apiToken },
61
+ // With --json, stdout is for the JSON object only.
62
+ stdio: [isNonInteractive() ? 'ignore' : 'inherit', isJsonMode() ? process.stderr : 'inherit', 'inherit'],
63
+ });
64
+ }
65
+ export async function action(actionArgs) {
66
+ const optionDefinitions = [
67
+ { name: 'force', type: Boolean },
68
+ { name: 'auto-upgrade', type: Boolean },
69
+ { name: 'comment', type: String },
70
+ { name: 'fastly-service-id', type: String },
71
+ { name: 'fastly-api-token', type: String },
72
+ ];
73
+ const parsed = parseCommandLine(actionArgs, optionDefinitions);
74
+ if (parsed.needHelp) {
75
+ if (parsed.error != null) {
76
+ console.error(String(parsed.error));
77
+ console.error();
78
+ recordFailure('usage', String(parsed.error));
79
+ }
80
+ help();
81
+ return;
82
+ }
83
+ const { force, ['auto-upgrade']: autoUpgrade, comment, ['fastly-service-id']: fastlyServiceId, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
84
+ if (detectProjectMode() === 'ejected') {
85
+ if (isJsonMode()) {
86
+ fail('json-not-supported', `--json is not supported for 'deploy' in an ejected app.`);
87
+ return;
88
+ }
89
+ const result = child_process.spawnSync('fastly', ['compute', 'publish'], { stdio: 'inherit' });
90
+ if (result.error != null || result.status !== 0) {
91
+ fail('deploy-failed', `'fastly compute publish' failed.`);
92
+ }
93
+ return;
94
+ }
95
+ const project = await loadManagedProject('deploy', '');
96
+ if (project == null) {
97
+ return;
98
+ }
99
+ showTemplateFolderHint(project);
100
+ if (!checkVersionForCommand(project, autoUpgrade === true)) {
101
+ return;
102
+ }
103
+ const apiToken = loadApiToken({ commandLine: fastlyApiToken });
104
+ if (apiToken == null) {
105
+ fail('credentials-missing', 'Fastly API Token not provided. Set the FASTLY_API_TOKEN environment variable to an API token that can deploy the service.');
106
+ return;
107
+ }
108
+ const context = { apiToken: apiToken.apiToken };
109
+ const serviceIdResult = loadServiceId({
110
+ commandLine: fastlyServiceId,
111
+ fastlyTomlPath: path.resolve('.static-publish/app/fastly.toml'),
112
+ projectServiceId: project.managed.serviceId,
113
+ });
114
+ let serviceId = serviceIdResult?.serviceId ?? null;
115
+ if (serviceId != null) {
116
+ console.log(`✔️ Service ID from ${serviceIdResult.source}: ${serviceId}`);
117
+ }
118
+ // The Fastly CLI cannot make the Secret Store of an S3 app without prompts.
119
+ if (serviceId == null && isS3StorageConfigRc(project.rc) && isNonInteractive()) {
120
+ fail('first-deploy-manual', 'The first deploy of an app with S3 storage must be done by hand: run deploy on your computer (the Fastly CLI asks for the S3 credentials), ' +
121
+ 'or give the ID of a service that is already set up (--fastly-service-id, FASTLY_SERVICE_ID, or managed.serviceId).');
122
+ return;
123
+ }
124
+ // A CLI run from the npx cache puts paths of the home directory into the Wasm binary.
125
+ if (getOwnPackageDir().includes(`${path.sep}_npx${path.sep}`)) {
126
+ console.warn(`⚠️ This CLI runs from the npx cache. The paths of the cache (in your home directory) go into the deployed Wasm binary.`);
127
+ console.warn(` * Add @fastly/compute-js-static-publish as a dev dependency of the project, and run it from there.`);
128
+ }
129
+ const { fingerprint } = await managedAppState(path.resolve(), project);
130
+ const staticPublishVersion = getOwnVersion();
131
+ if (serviceId != null && !force) {
132
+ const active = await getActiveVersion(context, serviceId);
133
+ const deployed = parseVersionComment(active?.comment);
134
+ if (active != null && deployed?.fingerprint === fingerprint) {
135
+ console.log(`✅ The active version ${active.number} already has this app (fingerprint ${fingerprint}). Nothing to deploy. Use --force to deploy anyway.`);
136
+ setJsonResult({
137
+ deployed: false,
138
+ reason: 'up-to-date',
139
+ serviceId,
140
+ version: active.number,
141
+ domain: (await getVersionDomains(context, serviceId, active.number))[0] ?? null,
142
+ fingerprint,
143
+ staticPublishVersion,
144
+ });
145
+ return;
146
+ }
147
+ }
148
+ const { appDir } = await prepareManagedApp(path.resolve(), project);
149
+ const build = runFastly(appDir, ['compute', 'build'], apiToken.apiToken);
150
+ if (build.error != null || build.status !== 0) {
151
+ fail('deploy-failed', `'fastly compute build' failed.`);
152
+ return;
153
+ }
154
+ const deployArgs = ['compute', 'deploy', '--comment', formatVersionComment(staticPublishVersion, fingerprint, comment)];
155
+ if (serviceId != null) {
156
+ deployArgs.push('--service-id', serviceId);
157
+ }
158
+ if (isNonInteractive()) {
159
+ deployArgs.push('--non-interactive');
160
+ }
161
+ const deploy = runFastly(appDir, deployArgs, apiToken.apiToken);
162
+ if (deploy.error != null || deploy.status !== 0) {
163
+ fail('deploy-failed', `'fastly compute deploy' failed.`);
164
+ return;
165
+ }
166
+ // After the first deploy, the Fastly CLI has written service_id into fastly.toml.
167
+ serviceId ??= readServiceId(path.resolve(appDir, 'fastly.toml')) ?? null;
168
+ if (serviceId == null) {
169
+ fail('deploy-failed', 'The deploy finished, but the Service ID is not known.');
170
+ return;
171
+ }
172
+ if (project.managed.serviceId == null) {
173
+ const projectFilePath = path.resolve(PROJECT_FILE_NAME);
174
+ const updated = writeBackServiceId(fs.readFileSync(projectFilePath, 'utf-8'), serviceId);
175
+ if (updated != null) {
176
+ fs.writeFileSync(projectFilePath, updated, 'utf-8');
177
+ console.log(`✔️ Wrote managed.serviceId "${serviceId}" into ${PROJECT_FILE_NAME}. Commit it.`);
178
+ }
179
+ else {
180
+ console.log(`⚠️ Set managed.serviceId to "${serviceId}" in ${PROJECT_FILE_NAME}. (The line 'serviceId: undefined,' was not found, so the CLI did not change the file.)`);
181
+ }
182
+ }
183
+ const active = await getActiveVersion(context, serviceId);
184
+ const domain = active != null ? (await getVersionDomains(context, serviceId, active.number))[0] ?? null : null;
185
+ console.log(`🎉 Deployed ${serviceId}${active != null ? ` version ${active.number}` : ''}${domain != null ? ` (https://${domain}/)` : ''}.`);
186
+ setJsonResult({
187
+ deployed: true,
188
+ serviceId,
189
+ version: active?.number ?? null,
190
+ domain,
191
+ fingerprint,
192
+ staticPublishVersion,
193
+ });
194
+ }
@@ -0,0 +1,2 @@
1
+ export declare function action(actionArgs: string[]): Promise<void>;
2
+ //# sourceMappingURL=dev.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/dev.ts"],"names":[],"mappings":"AA+CA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAwChD"}
@@ -0,0 +1,77 @@
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 { prepareManagedApp } from '../../managed/app.js';
7
+ import { parseCommandLine } from '../../util/args.js';
8
+ import { fail, recordFailure } from '../../util/output.js';
9
+ import { checkVersionForCommand, loadManagedProject, showTemplateFolderHint } from '../../managed/command-helpers.js';
10
+ import { PROJECT_FILE_NAME } from '../../../models/config/static-publish-project.js';
11
+ import { serveApp } from '../run-dev-watch.js';
12
+ function help() {
13
+ console.log(`\
14
+
15
+ Usage:
16
+ npx @fastly/compute-js-static-publish dev [-- <options of fastly compute serve>]
17
+
18
+ Description:
19
+ Runs the app of a managed project on your computer. Generates the app in
20
+ .static-publish/app from ${PROJECT_FILE_NAME}, installs its dependencies
21
+ if they changed, and runs 'fastly compute serve' in it.
22
+
23
+ The app serves the content of the local KV Store. To publish content to it,
24
+ run 'publish-content --local' first.
25
+
26
+ Only in a managed project. In an ejected app, run 'npm run dev:start', or
27
+ 'npm run dev:watch' (fastly compute serve --watch).
28
+
29
+ Options:
30
+ --auto-upgrade If the CLI is newer than managed.staticPublishVersion,
31
+ set it to the version that runs, and continue.
32
+ -- <options> Options after -- go to 'fastly compute serve',
33
+ for example: dev -- --addr=127.0.0.1:8080
34
+ With -- --watch, a change in the app builds and
35
+ restarts it. If the template has a watch script,
36
+ it runs next to 'fastly compute serve'.
37
+
38
+ Global Options:
39
+ -h, --help Show this help message and exit.
40
+ `);
41
+ }
42
+ export async function action(actionArgs) {
43
+ // Options after -- go to fastly compute serve.
44
+ const separator = actionArgs.indexOf('--');
45
+ const serveArgs = separator === -1 ? [] : actionArgs.slice(separator + 1);
46
+ const ownArgs = separator === -1 ? actionArgs : actionArgs.slice(0, separator);
47
+ const optionDefinitions = [
48
+ { name: 'auto-upgrade', type: Boolean },
49
+ ];
50
+ const parsed = parseCommandLine(ownArgs, optionDefinitions);
51
+ if (parsed.needHelp) {
52
+ if (parsed.error != null) {
53
+ console.error(String(parsed.error));
54
+ console.error();
55
+ recordFailure('usage', String(parsed.error));
56
+ }
57
+ help();
58
+ return;
59
+ }
60
+ const project = await loadManagedProject('dev', `In an ejected app, run 'npm run dev:start'.`);
61
+ if (project == null) {
62
+ return;
63
+ }
64
+ showTemplateFolderHint(project);
65
+ if (!checkVersionForCommand(project, parsed.commandLineOptions['auto-upgrade'] === true)) {
66
+ return;
67
+ }
68
+ const { appDir } = await prepareManagedApp(path.resolve(), project);
69
+ const result = await serveApp(appDir, serveArgs);
70
+ if (result.error != null) {
71
+ fail('failed', `Could not run 'fastly compute serve': ${String(result.error)}`);
72
+ return;
73
+ }
74
+ if (result.status !== 0 && result.signal == null) {
75
+ fail('failed', `'fastly compute serve' exited with ${result.status}.`);
76
+ }
77
+ }
@@ -0,0 +1,2 @@
1
+ export declare function action(actionArgs: string[]): Promise<void>;
2
+ //# sourceMappingURL=eject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eject.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/eject.ts"],"names":[],"mappings":"AA+DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAoHhD"}
@@ -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 { 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
+ npx @fastly/compute-js-static-publish 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":"AA2DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyBhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"AAqFA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAmChD"}
@@ -3,7 +3,14 @@
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';
9
16
  function help() {
@@ -24,6 +31,13 @@ Available Commands:
24
31
  collections delete Delete a specific collection index
25
32
  collections promote Copy a collection to another name
26
33
  collections update-expiration Modify expiration time for an existing collection
34
+ dev Run the app of a managed project locally
35
+ status Show the state of the app, and if a deploy is necessary
36
+ deploy Deploy the app of a managed project, if it changed
37
+ upgrade Move a managed project to the version of this CLI
38
+ eject Convert a managed project into an ejected app
39
+ template init Make or update the folder of the app's template
40
+ (for the hono template: hono-extensions/)
27
41
 
28
42
  KV Store Options:
29
43
  --local Instead of working with the Fastly KV Store, operate on
@@ -42,6 +56,17 @@ S3 Storage Options (BETA):
42
56
  and S3_SECRET_ACCESS_KEY environment variables.
43
57
 
44
58
  Global Options:
59
+ --project-dir=<dir> Run the command for the app in <dir>, the directory
60
+ that has static-publish.rc.js or static-publish.project.js.
61
+ Relative paths, also in other options, are then
62
+ relative to <dir>.
63
+ --version Print the version of this package and exit.
64
+ --non-interactive Never ask a question. Missing input is an error.
65
+ This is also on when the CI environment variable is set.
66
+ --json Write the result as one JSON object to stdout, and
67
+ the log to stderr. For publish-content,
68
+ collections list/delete/promote, status, deploy,
69
+ and --version.
45
70
  -h, --help Show this help message and exit.
46
71
 
47
72
  Automatic Project Initialization:
@@ -52,13 +77,20 @@ Examples:
52
77
  npx @fastly/compute-js-static-publish publish-content --collection-name=live
53
78
  npx @fastly/compute-js-static-publish collections list
54
79
  npx @fastly/compute-js-static-publish clean --dry-run
80
+ npx @fastly/compute-js-static-publish publish-content --project-dir=./compute-js
55
81
  `);
56
82
  }
57
83
  export async function action(actionArgs) {
58
84
  const modes = {
59
85
  'clean': cleanCommand,
86
+ 'deploy': deployCommand,
87
+ 'dev': devCommand,
88
+ 'eject': ejectCommand,
89
+ 'status': statusCommand,
90
+ 'upgrade': upgradeCommand,
60
91
  'publish-content': publishContentCommand,
61
92
  'collections': collectionsCommands,
93
+ 'template': templateCommands,
62
94
  };
63
95
  const commandAndArgs = getCommandAndArgs(actionArgs, modes);
64
96
  if (commandAndArgs.needHelp) {
@@ -66,11 +98,15 @@ export async function action(actionArgs) {
66
98
  console.error(commandAndArgs.error);
67
99
  console.error(`Specify one of the following commands: ${Object.keys(modes).join(', ')}`);
68
100
  console.error();
69
- process.exitCode = 1;
101
+ recordFailure('usage', commandAndArgs.error);
70
102
  }
71
103
  help();
72
104
  return;
73
105
  }
74
106
  const { command, argv, } = commandAndArgs;
107
+ if (isJsonMode() && !['publish-content', 'collections', 'status', 'deploy'].includes(command)) {
108
+ fail('json-not-supported', `--json is not supported for '${command}'.`);
109
+ return;
110
+ }
75
111
  await modes[command].action(argv);
76
112
  }
@@ -1 +1 @@
1
- {"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AA8HA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA4jBhD"}
1
+ {"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AAgJA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAqmBhD"}