@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.
Files changed (247) hide show
  1. package/DOCUMENTATION.md +792 -35
  2. package/README.md +13 -3
  3. package/README.short.md +13 -3
  4. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
  5. package/build/cli/cli/commands/manage/clean.js +14 -8
  6. package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
  7. package/build/cli/cli/commands/manage/collections/delete.js +32 -15
  8. package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
  9. package/build/cli/cli/commands/manage/collections/index.js +10 -4
  10. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
  11. package/build/cli/cli/commands/manage/collections/list.js +49 -8
  12. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  13. package/build/cli/cli/commands/manage/collections/promote.js +69 -21
  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 +12 -12
  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 +78 -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 +42 -5
  27. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  28. package/build/cli/cli/commands/manage/publish-content.js +83 -37
  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 +43 -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 +298 -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 +6 -0
  132. package/build/cli/cli/util/package.d.ts.map +1 -1
  133. package/build/cli/cli/util/package.js +23 -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
package/README.md CHANGED
@@ -18,18 +18,18 @@ This CLI tool helps you:
18
18
  Create a directory for your project, place your static files in `./public`, then type:
19
19
 
20
20
  ```sh
21
- npx @fastly/compute-js-static-publish@latest --root-dir=./public --kv-store-name=site-content
21
+ npx @fastly/compute-js-static-publish@beta --root-dir=./public --kv-store-name=site-content
22
22
  ```
23
23
 
24
24
  **New in v8:** S3-compatible storage (such as Fastly Object Storage) is also supported (Beta). To use this mode, type:
25
25
 
26
26
  ```sh
27
- npx @fastly/compute-js-static-publish@latest --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
27
+ npx @fastly/compute-js-static-publish@beta --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
28
28
  ```
29
29
 
30
30
  If the storage needs a custom endpoint, as Fastly Object Storage does, add `--s3-endpoint=<endpoint>` (for example, `--s3-endpoint=https://us-east-1.object.fastlystorage.app`).
31
31
 
32
- For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/main/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
32
+ For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
33
33
 
34
34
  ### 🔧 Local Preview
35
35
 
@@ -69,6 +69,16 @@ npm run fastly:publish # upload your static files
69
69
 
70
70
  If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates. After the deploy, `fastly.toml` has the service ID, so `s3:publish` also purges the service's cache. For this purge, set `FASTLY_API_TOKEN` too. Without it, `s3:publish` stops with an error before it uploads files.
71
71
 
72
+ ## New in 8.1
73
+
74
+ - **Managed projects:** keep only `static-publish.project.js` in your repo. The CLI generates the app, and `dev`, `deploy`, `status`, `upgrade`, and `eject` work with it. ([Managed and ejected apps](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#managed-and-ejected-apps))
75
+ - **Previews:** serve another collection for a request, selected by host, path, query, cookie, or header. ([Previews](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-previews-collection-selection))
76
+ - **Hidden files:** publish files that the server does not serve for a request, for your own code to read. ([Hidden files](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#hidden-files))
77
+ - **Hono:** the `hono` template, with your own middleware and routes in `hono-extensions/`, and examples for GRIP streaming and OAuth login. For your own Hono app, `@fastly/compute-js-static-publish/hono` replaces `@fastly/hono-compute-js-static-publish`. ([Using Hono](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-hono))
78
+ - **CI:** `--json` output, exit codes, error codes, `--project-dir`, and `--non-interactive`. ([Using the CLI in CI](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-the-cli-in-ci))
79
+
80
+ Before you upgrade, read [CHANGELOG.md](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/CHANGELOG.md): collection names now must be DNS labels (lowercase letters, digits, and `-`), and a usage or config error now exits with `2`.
81
+
72
82
  ## Features
73
83
 
74
84
  - Named collections for previews, staging, production
package/README.short.md CHANGED
@@ -18,18 +18,18 @@ This CLI tool helps you:
18
18
  Create a directory for your project, place your static files in `./public`, then type:
19
19
 
20
20
  ```sh
21
- npx @fastly/compute-js-static-publish@latest --root-dir=./public --kv-store-name=site-content
21
+ npx @fastly/compute-js-static-publish@beta --root-dir=./public --kv-store-name=site-content
22
22
  ```
23
23
 
24
24
  **New in v8:** S3-compatible storage (such as Fastly Object Storage) is also supported (Beta). To use this mode, type:
25
25
 
26
26
  ```sh
27
- npx @fastly/compute-js-static-publish@latest --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
27
+ npx @fastly/compute-js-static-publish@beta --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
28
28
  ```
29
29
 
30
30
  If the storage needs a custom endpoint, as Fastly Object Storage does, add `--s3-endpoint=<endpoint>` (for example, `--s3-endpoint=https://us-east-1.object.fastlystorage.app`).
31
31
 
32
- For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/main/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
32
+ For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
33
33
 
34
34
  ### 🔧 Local Preview
35
35
 
@@ -69,6 +69,16 @@ npm run fastly:publish # upload your static files
69
69
 
70
70
  If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates. After the deploy, `fastly.toml` has the service ID, so `s3:publish` also purges the service's cache. For this purge, set `FASTLY_API_TOKEN` too. Without it, `s3:publish` stops with an error before it uploads files.
71
71
 
72
+ ## New in 8.1
73
+
74
+ - **Managed projects:** keep only `static-publish.project.js` in your repo. The CLI generates the app, and `dev`, `deploy`, `status`, `upgrade`, and `eject` work with it. ([Managed and ejected apps](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#managed-and-ejected-apps))
75
+ - **Previews:** serve another collection for a request, selected by host, path, query, cookie, or header. ([Previews](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-previews-collection-selection))
76
+ - **Hidden files:** publish files that the server does not serve for a request, for your own code to read. ([Hidden files](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#hidden-files))
77
+ - **Hono:** the `hono` template, with your own middleware and routes in `hono-extensions/`, and examples for GRIP streaming and OAuth login. For your own Hono app, `@fastly/compute-js-static-publish/hono` replaces `@fastly/hono-compute-js-static-publish`. ([Using Hono](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-hono))
78
+ - **CI:** `--json` output, exit codes, error codes, `--project-dir`, and `--non-interactive`. ([Using the CLI in CI](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-the-cli-in-ci))
79
+
80
+ Before you upgrade, read [CHANGELOG.md](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/CHANGELOG.md): collection names now must be DNS labels (lowercase letters, digits, and `-`), and a usage or config error now exits with `2`.
81
+
72
82
  ## Features
73
83
 
74
84
  - Named collections for previews, staging, production
@@ -1 +1 @@
1
- {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0NhD"}
1
+ {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"AAgEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0NhD"}
@@ -2,22 +2,28 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
- import path from 'node:path';
6
5
  import { decodeIndexMetadata } from '../../../models/server/index.js';
7
6
  import { isExpired } from '../../../models/time/index.js';
8
7
  import { parseCommandLine } from '../../util/args.js';
9
- import { LoadConfigError, loadStaticPublisherRcFile } from '../../util/config.js';
8
+ import { errorCodeOf, recordFailure } from '../../util/output.js';
9
+ import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../util/config.js';
10
10
  import { loadStorageProviderFromStaticPublishRc } from '../../storage/storage-provider.js';
11
+ import { cliCommand } from '../../util/package.js';
11
12
  function help() {
12
13
  console.log(`\
13
14
 
14
15
  Usage:
15
- npx @fastly/compute-js-static-publish clean [options]
16
+ ${cliCommand()} clean [options]
16
17
 
17
18
  Description:
18
19
  Cleans up expired or unreferenced items in storage.
19
20
  This can include expired collection indexes and orphaned content assets.
20
21
 
22
+ Do not run clean while publish-content can run for the same storage.
23
+ clean can delete files that a publish uses before the publish writes its
24
+ index. In CI, put the jobs that publish and the job that cleans in the same
25
+ concurrency group.
26
+
21
27
  Options:
22
28
  --delete-expired-collections If set, expired collection index files will be deleted.
23
29
 
@@ -58,7 +64,7 @@ export async function action(actionArgs) {
58
64
  if (parsed.error != null) {
59
65
  console.error(String(parsed.error));
60
66
  console.error();
61
- process.exitCode = 1;
67
+ recordFailure('usage', String(parsed.error));
62
68
  }
63
69
  help();
64
70
  return;
@@ -66,7 +72,7 @@ export async function action(actionArgs) {
66
72
  const { verbose, ['delete-expired-collections']: deleteExpiredCollections, ['dry-run']: dryRun, local: localMode, ['fastly-api-token']: fastlyApiToken, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
67
73
  // compute-js-static-publisher cli is always run from the Compute application directory
68
74
  // in other words, the directory that contains `fastly.toml`.
69
- const computeAppDir = path.resolve();
75
+ const computeAppDir = getComputeAppDir();
70
76
  console.log(`🧹 Cleaning storage entries...`);
71
77
  // #### load config
72
78
  let staticPublisherRc;
@@ -74,14 +80,14 @@ export async function action(actionArgs) {
74
80
  staticPublisherRc = await loadStaticPublisherRcFile();
75
81
  }
76
82
  catch (err) {
77
- console.error("❌ Can't load static-publish.rc.js");
83
+ console.error(`❌ Can't load ${configFileName()}`);
78
84
  console.error("Run this from a compute-js-static-publish compute-js directory.");
79
85
  if (err instanceof LoadConfigError) {
80
86
  for (const error of err.errors) {
81
87
  console.error(error);
82
88
  }
83
89
  }
84
- process.exitCode = 1;
90
+ recordFailure('config-invalid', `Can't load ${configFileName()}.`);
85
91
  return;
86
92
  }
87
93
  const publishId = staticPublisherRc.publishId;
@@ -104,7 +110,7 @@ export async function action(actionArgs) {
104
110
  catch (err) {
105
111
  console.error(`❌ Could not instantiate store provider`);
106
112
  console.error(String(err));
107
- process.exitCode = 1;
113
+ recordFailure(errorCodeOf(err), String(err));
108
114
  return;
109
115
  }
110
116
  // ### Asset keys to delete
@@ -1 +1 @@
1
- {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"AAiEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA+JhD"}
1
+ {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"AAwEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAiLhD"}
@@ -2,22 +2,23 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
- import path from 'node:path';
6
5
  import { parseCommandLine } from '../../../util/args.js';
7
- import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
6
+ import { errorCodeOf, fail, recordFailure, setJsonResult } from '../../../util/output.js';
7
+ import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../../util/config.js';
8
8
  import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
9
9
  import { loadPurgeTarget, purgeCollection } from '../../../util/purge.js';
10
+ import { cliCommand } from '../../../util/package.js';
10
11
  function help() {
11
12
  console.log(`\
12
13
 
13
14
  Usage:
14
- npx @fastly/compute-js-static-publish collections delete --collection-name=<name> [options]
15
+ ${cliCommand()} collections delete --collection-name=<name> [options]
15
16
 
16
17
  Description:
17
18
  Deletes a collection index from storage. The content files will remain as they may still
18
19
  be referenced by other collection indexes.
19
20
 
20
- Use the 'npx @fastly/compute-js-static-publish clean' command afterward to remove content
21
+ Use the '${cliCommand()} clean' command afterward to remove content
21
22
  files that are no longer referenced by any collection.
22
23
 
23
24
  If a Service ID is found, the tool then purges the cached responses of the collection
@@ -73,7 +74,7 @@ export async function action(actionArgs) {
73
74
  if (parsed.error != null) {
74
75
  console.error(String(parsed.error));
75
76
  console.error();
76
- process.exitCode = 1;
77
+ recordFailure('usage', String(parsed.error));
77
78
  }
78
79
  help();
79
80
  return;
@@ -81,10 +82,9 @@ export async function action(actionArgs) {
81
82
  const { verbose, ['collection-name']: collectionNameValue, ['fastly-api-token']: fastlyApiToken, ['fastly-service-id']: fastlyServiceId, ['purge-environment']: purgeEnvironmentValues, local: localMode, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
82
83
  // compute-js-static-publisher cli is always run from the Compute application directory
83
84
  // in other words, the directory that contains `fastly.toml`.
84
- const computeAppDir = path.resolve();
85
+ const computeAppDir = getComputeAppDir();
85
86
  if (collectionNameValue == null) {
86
- console.error("❌ Required argument '--collection-name' not specified.");
87
- process.exitCode = 1;
87
+ fail('usage', "Required argument '--collection-name' not specified.");
88
88
  return;
89
89
  }
90
90
  console.log(`🧹 Deleting storage collection...`);
@@ -94,14 +94,14 @@ export async function action(actionArgs) {
94
94
  staticPublisherRc = await loadStaticPublisherRcFile();
95
95
  }
96
96
  catch (err) {
97
- console.error("❌ Can't load static-publish.rc.js");
97
+ console.error(`❌ Can't load ${configFileName()}`);
98
98
  console.error("Run this from a compute-js-static-publish compute-js directory.");
99
99
  if (err instanceof LoadConfigError) {
100
100
  for (const error of err.errors) {
101
101
  console.error(error);
102
102
  }
103
103
  }
104
- process.exitCode = 1;
104
+ recordFailure('config-invalid', `Can't load ${configFileName()}.`);
105
105
  return;
106
106
  }
107
107
  const publishId = staticPublisherRc.publishId;
@@ -124,13 +124,12 @@ export async function action(actionArgs) {
124
124
  catch (err) {
125
125
  console.error(`❌ Could not instantiate store provider`);
126
126
  console.error(String(err));
127
- process.exitCode = 1;
127
+ recordFailure(errorCodeOf(err), String(err));
128
128
  return;
129
129
  }
130
130
  const collectionName = collectionNameValue;
131
131
  if (collectionName === defaultCollectionName) {
132
- console.error(`❌ Cannot delete default collection: ${collectionName}`);
133
- process.exitCode = 1;
132
+ fail('usage', `Cannot delete default collection: ${collectionName}`);
134
133
  return;
135
134
  }
136
135
  console.log(`✔️ Collection to delete: ${collectionName}`);
@@ -147,7 +146,7 @@ export async function action(actionArgs) {
147
146
  }
148
147
  catch (err) {
149
148
  console.error(String(err));
150
- process.exitCode = 1;
149
+ recordFailure(errorCodeOf(err), String(err));
151
150
  return;
152
151
  }
153
152
  // ### Asset Keys to delete
@@ -172,14 +171,32 @@ export async function action(actionArgs) {
172
171
  }
173
172
  }
174
173
  }
174
+ // A collection that does not exist is not an error: there is nothing to
175
+ // delete. The purge still runs, in case an earlier delete did not purge.
176
+ if (assetKeysToDelete.size === 0) {
177
+ console.log(`✔️ Collection '${collectionName}' does not exist. Nothing to delete.`);
178
+ }
175
179
  // ### Delete items that have been flagged
176
180
  const items = [...assetKeysToDelete].map(key => ({ key }));
177
181
  await storageProvider.doConcurrentParallel(items, async (_, key) => {
178
182
  console.log(`Deleting key from storage: ${key}`);
179
183
  await storageProvider.deleteStorageEntry(key);
180
184
  }, undefined, true);
185
+ const purgeResults = [];
181
186
  if (purgeTarget != null) {
182
- await purgeCollection(purgeTarget, publishId, collectionName);
187
+ purgeResults.push(...await purgeCollection(purgeTarget, publishId, collectionName));
183
188
  }
184
189
  console.log("✅ Completed.");
190
+ setJsonResult({
191
+ collection: collectionName,
192
+ publishId,
193
+ deleted: assetKeysToDelete.size > 0,
194
+ ...(assetKeysToDelete.size === 0 ? { reason: 'not-found' } : {}),
195
+ // null: no purge (--local, or no Service ID).
196
+ purge: purgeTarget != null ? {
197
+ ok: purgeResults.every(x => x.result !== 'failed'),
198
+ serviceId: purgeTarget.serviceId,
199
+ environments: purgeResults,
200
+ } : null,
201
+ });
185
202
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0BhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"AAsDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA8BhD"}
@@ -3,15 +3,17 @@
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 deleteCommand from './delete.js';
7
8
  import * as listCommand from './list.js';
8
9
  import * as promoteCommand from './promote.js';
9
10
  import * as updateExpirationCommand from './update-expiration.js';
11
+ import { cliCommand } from '../../../util/package.js';
10
12
  function help() {
11
13
  console.log(`\
12
14
 
13
15
  Usage:
14
- npx @fastly/compute-js-static-publish collections <sub-command> [options]
16
+ ${cliCommand()} collections <sub-command> [options]
15
17
 
16
18
  Description:
17
19
  Manage named collections within a Compute application built with @fastly/compute-js-static-publish.
@@ -43,8 +45,8 @@ Global Options:
43
45
  -h, --help Show this help message and exit.
44
46
 
45
47
  Examples:
46
- npx @fastly/compute-js-static-publish collections list
47
- npx @fastly/compute-js-static-publish collections delete --collection-name=preview-42
48
+ ${cliCommand()} collections list
49
+ ${cliCommand()} collections delete --collection-name=preview-42
48
50
  `);
49
51
  }
50
52
  export async function action(actionArgs) {
@@ -60,11 +62,15 @@ export async function action(actionArgs) {
60
62
  console.error(commandAndArgs.error);
61
63
  console.error(`Specify one of the following sub-commands: ${Object.keys(modes).join(', ')}`);
62
64
  console.error();
63
- process.exitCode = 1;
65
+ recordFailure('usage', commandAndArgs.error);
64
66
  }
65
67
  help();
66
68
  return;
67
69
  }
68
70
  const { command, argv, } = commandAndArgs;
71
+ if (isJsonMode() && !['list', 'delete', 'promote'].includes(command)) {
72
+ fail('json-not-supported', `--json is not supported for 'collections ${command}'.`);
73
+ return;
74
+ }
69
75
  await modes[command].action(argv);
70
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"AA6CA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA4IhD"}
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"AAqDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAoLhD"}
@@ -2,17 +2,19 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
- import path from 'node:path';
5
+ import { countHiddenEntries } from '../../../../models/assets/index.js';
6
6
  import { decodeIndexMetadata, getUnsupportedIndexFeatures } from '../../../../models/server/index.js';
7
7
  import { isExpired } from '../../../../models/time/index.js';
8
8
  import { parseCommandLine } from '../../../util/args.js';
9
- import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
9
+ import { errorCodeOf, recordFailure, setJsonResult } from '../../../util/output.js';
10
+ import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../../util/config.js';
10
11
  import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
12
+ import { cliCommand } from '../../../util/package.js';
11
13
  function help() {
12
14
  console.log(`\
13
15
 
14
16
  Usage:
15
- npx @fastly/compute-js-static-publish collections list [options]
17
+ ${cliCommand()} collections list [options]
16
18
 
17
19
  Description:
18
20
  Lists all collections currently published in the KV Store.
@@ -50,7 +52,7 @@ export async function action(actionArgs) {
50
52
  if (parsed.error != null) {
51
53
  console.error(String(parsed.error));
52
54
  console.error();
53
- process.exitCode = 1;
55
+ recordFailure('usage', String(parsed.error));
54
56
  }
55
57
  help();
56
58
  return;
@@ -58,7 +60,7 @@ export async function action(actionArgs) {
58
60
  const { verbose, local: localMode, ['fastly-api-token']: fastlyApiToken, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
59
61
  // compute-js-static-publisher cli is always run from the Compute application directory
60
62
  // in other words, the directory that contains `fastly.toml`.
61
- const computeAppDir = path.resolve();
63
+ const computeAppDir = getComputeAppDir();
62
64
  console.log(`📃 Listing collections...`);
63
65
  // #### load config
64
66
  let staticPublisherRc;
@@ -66,14 +68,14 @@ export async function action(actionArgs) {
66
68
  staticPublisherRc = await loadStaticPublisherRcFile();
67
69
  }
68
70
  catch (err) {
69
- console.error("❌ Can't load static-publish.rc.js");
71
+ console.error(`❌ Can't load ${configFileName()}`);
70
72
  console.error("Run this from a compute-js-static-publish compute-js directory.");
71
73
  if (err instanceof LoadConfigError) {
72
74
  for (const error of err.errors) {
73
75
  console.error(error);
74
76
  }
75
77
  }
76
- process.exitCode = 1;
78
+ recordFailure('config-invalid', `Can't load ${configFileName()}.`);
77
79
  return;
78
80
  }
79
81
  const publishId = staticPublisherRc.publishId;
@@ -96,7 +98,7 @@ export async function action(actionArgs) {
96
98
  catch (err) {
97
99
  console.error(`❌ Could not instantiate store provider`);
98
100
  console.error(String(err));
99
- process.exitCode = 1;
101
+ recordFailure(errorCodeOf(err), String(err));
100
102
  return;
101
103
  }
102
104
  // ### List all indexes ###
@@ -107,6 +109,8 @@ export async function action(actionArgs) {
107
109
  }
108
110
  // ### Found collections ###
109
111
  const foundCollections = indexKeys.map(x => x.slice(indexesPrefix.length));
112
+ // For --json.
113
+ const collectionInfos = [];
110
114
  if (foundCollections.length === 0) {
111
115
  console.log('No collections found.');
112
116
  }
@@ -125,16 +129,48 @@ export async function action(actionArgs) {
125
129
  throw new Error(`❌ Can't load storage entry ${indexesPrefix + collection}`);
126
130
  }
127
131
  let indexMetadata = decodeIndexMetadata(indexEntryInfo.metadata);
132
+ const info = {
133
+ name: collection,
134
+ isDefault: collection === defaultCollectionName,
135
+ publishedAt: null,
136
+ expiresAt: null,
137
+ expired: false,
138
+ requires: [],
139
+ unsupported: [],
140
+ files: null,
141
+ hidden: null,
142
+ };
143
+ collectionInfos.push(info);
128
144
  if (indexMetadata == null) {
129
145
  console.log(` No metadata found.`);
130
146
  continue;
131
147
  }
148
+ if (indexMetadata.publishedTime != null) {
149
+ info.publishedAt = new Date(indexMetadata.publishedTime * 1000).toISOString();
150
+ }
151
+ if (indexMetadata.expirationTime != null) {
152
+ info.expiresAt = new Date(indexMetadata.expirationTime * 1000).toISOString();
153
+ // The expiration time is not enforced for the default collection.
154
+ info.expired = collection !== defaultCollectionName && isExpired(indexMetadata.expirationTime);
155
+ }
156
+ info.requires = indexMetadata.requires ?? [];
157
+ info.unsupported = getUnsupportedIndexFeatures(indexMetadata);
132
158
  if (indexMetadata.publishedTime == null) {
133
159
  console.log(' Published : unknown');
134
160
  }
135
161
  else {
136
162
  console.log(` Published : ${new Date(indexMetadata.publishedTime * 1000)}`);
137
163
  }
164
+ try {
165
+ const assetEntryMap = (await new Response(indexEntryInfo.data).json());
166
+ const fileCount = Object.keys(assetEntryMap).length;
167
+ info.files = fileCount;
168
+ info.hidden = countHiddenEntries(assetEntryMap);
169
+ console.log(` Files : ${fileCount} (${countHiddenEntries(assetEntryMap)} hidden)`);
170
+ }
171
+ catch {
172
+ console.log(' Files : unknown (cannot read the index)');
173
+ }
138
174
  if (indexMetadata.requires != null) {
139
175
  console.log(` Requires : ${indexMetadata.requires.join(', ')}`);
140
176
  const unsupportedFeatures = getUnsupportedIndexFeatures(indexMetadata);
@@ -159,4 +195,9 @@ export async function action(actionArgs) {
159
195
  }
160
196
  }
161
197
  console.log("✅ Completed.");
198
+ setJsonResult({
199
+ publishId,
200
+ defaultCollection: defaultCollectionName,
201
+ collections: collectionInfos,
202
+ });
162
203
  }
@@ -1 +1 @@
1
- {"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"AAmEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAuLhD"}
1
+ {"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"AA0FA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0NhD"}