@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
@@ -0,0 +1,154 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ // managed.fastlyToml of a managed project: the local_server and setup sections
6
+ // that the customer adds to the fastly.toml of the app, for example a local
7
+ // Secret Store for fastly compute serve.
8
+ import toml from 'toml';
9
+ import { ConfigError } from '../../util/output.js';
10
+ import { tomlFilter, tomlKeyFilter } from './render.js';
11
+ export const FASTLY_TOML_SECTIONS = ['local_server', 'setup'];
12
+ const isPlainObject = (value) => value != null && typeof value === 'object' && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
13
+ const isTableArray = (value) => Array.isArray(value) && value.length > 0 && value.every(isPlainObject);
14
+ // Checks managed.fastlyToml. Each section is an object of resource types (for
15
+ // example secret_stores), and each value can be written as TOML: a string, a
16
+ // finite number, a boolean, an array, or a plain object.
17
+ export function checkFastlyTomlSections(value, errors) {
18
+ const start = errors.length;
19
+ if (!isPlainObject(value)) {
20
+ errors.push('managed.fastlyToml, if specified, must be an object.');
21
+ return false;
22
+ }
23
+ const checkValue = (item, at) => {
24
+ if (typeof item === 'string' || typeof item === 'boolean' || (typeof item === 'number' && Number.isFinite(item))) {
25
+ return;
26
+ }
27
+ if (Array.isArray(item)) {
28
+ if (item.length > 0 && item.some(isPlainObject) && !item.every(isPlainObject)) {
29
+ errors.push(`${at}: an array must have only objects, or no objects.`);
30
+ return;
31
+ }
32
+ item.forEach((x, i) => checkValue(x, `${at}[${i}]`));
33
+ return;
34
+ }
35
+ if (isPlainObject(item)) {
36
+ for (const [key, x] of Object.entries(item)) {
37
+ if (x !== undefined) {
38
+ checkValue(x, `${at}.${key}`);
39
+ }
40
+ }
41
+ return;
42
+ }
43
+ errors.push(`${at}: the value cannot be written to fastly.toml. Use a string, a number, a boolean, an array, or an object.`);
44
+ };
45
+ for (const [section, content] of Object.entries(value)) {
46
+ const at = `managed.fastlyToml.${section}`;
47
+ if (!FASTLY_TOML_SECTIONS.includes(section)) {
48
+ errors.push(`${at}: only ${FASTLY_TOML_SECTIONS.join(' and ')} can be added to fastly.toml.`);
49
+ continue;
50
+ }
51
+ if (content === undefined) {
52
+ continue;
53
+ }
54
+ if (!isPlainObject(content)) {
55
+ errors.push(`${at} must be an object, for example { secret_stores: { … } }.`);
56
+ continue;
57
+ }
58
+ for (const [type, tables] of Object.entries(content)) {
59
+ if (tables !== undefined && !isPlainObject(tables)) {
60
+ errors.push(`${at}.${type} must be an object.`);
61
+ continue;
62
+ }
63
+ checkValue(tables, `${at}.${type}`);
64
+ }
65
+ }
66
+ return errors.length === start;
67
+ }
68
+ function tomlValue(value) {
69
+ if (typeof value === 'string') {
70
+ return tomlFilter(value);
71
+ }
72
+ if (typeof value === 'number' || typeof value === 'boolean') {
73
+ return String(value);
74
+ }
75
+ if (Array.isArray(value)) {
76
+ return `[ ${value.map(tomlValue).join(', ')} ]`;
77
+ }
78
+ if (isPlainObject(value)) {
79
+ const entries = Object.entries(value).filter(([, x]) => x !== undefined);
80
+ return `{ ${entries.map(([key, x]) => `${tomlKeyFilter(key)} = ${tomlValue(x)}`).join(', ')} }`;
81
+ }
82
+ throw new Error(`This value cannot be written to fastly.toml: ${String(value)}`);
83
+ }
84
+ // Writes the tables of an object with the full path in each header, so that the
85
+ // text can come after the sections that the CLI writes. A table gets a header
86
+ // only if it has values, or if it is a resource (for example
87
+ // [setup.kv_stores.name]) and has nothing else; the tables above it are made
88
+ // implicitly, and are never declared a second time.
89
+ function writeTables(lines, keys, table, header) {
90
+ const entries = Object.entries(table).filter(([, x]) => x !== undefined);
91
+ const values = entries.filter(([, x]) => !isPlainObject(x) && !isTableArray(x));
92
+ const tables = entries.filter(([, x]) => isPlainObject(x));
93
+ const tableArrays = entries.filter(([, x]) => isTableArray(x));
94
+ const name = keys.map(tomlKeyFilter).join('.');
95
+ const isResource = keys.length >= 3;
96
+ if (header === '[[' || values.length > 0 || (isResource && tables.length === 0 && tableArrays.length === 0)) {
97
+ lines.push(header === '[[' ? `[[${name}]]` : `[${name}]`);
98
+ for (const [key, x] of values) {
99
+ lines.push(`${tomlKeyFilter(key)} = ${tomlValue(x)}`);
100
+ }
101
+ }
102
+ for (const [key, x] of tables) {
103
+ writeTables(lines, [...keys, key], x, '[');
104
+ }
105
+ for (const [key, items] of tableArrays) {
106
+ for (const item of items) {
107
+ writeTables(lines, [...keys, key], item, '[[');
108
+ }
109
+ }
110
+ }
111
+ // Adds managed.fastlyToml to the text of a fastly.toml that the CLI made.
112
+ // Throws a ConfigError if a resource has the name of one that the CLI writes
113
+ // (for example the KV Store of the content), or if the result is not valid
114
+ // TOML.
115
+ export function addFastlyTomlSections(fastlyToml, sections) {
116
+ if (sections == null) {
117
+ return fastlyToml;
118
+ }
119
+ const base = toml.parse(fastlyToml);
120
+ const lines = [];
121
+ for (const section of FASTLY_TOML_SECTIONS) {
122
+ const content = sections[section];
123
+ if (content == null) {
124
+ continue;
125
+ }
126
+ for (const [type, tables] of Object.entries(content)) {
127
+ if (!isPlainObject(tables)) {
128
+ continue;
129
+ }
130
+ const baseType = base[section]?.[type];
131
+ for (const name of Object.keys(tables)) {
132
+ if (baseType?.[name] !== undefined) {
133
+ throw new ConfigError(`managed.fastlyToml.${section}.${type}.${name}: the CLI writes this entry. Use another name.`);
134
+ }
135
+ }
136
+ const hasValues = Object.values(tables).some(x => x !== undefined && !isPlainObject(x) && !isTableArray(x));
137
+ if (baseType != null && hasValues) {
138
+ throw new ConfigError(`managed.fastlyToml.${section}.${type}: the CLI writes this table. Add only new entries to it.`);
139
+ }
140
+ writeTables(lines, [section, type], tables, '[');
141
+ }
142
+ }
143
+ if (lines.length === 0) {
144
+ return fastlyToml;
145
+ }
146
+ const result = `${fastlyToml.trimEnd()}\n\n# From managed.fastlyToml in the project file.\n${lines.join('\n')}\n`;
147
+ try {
148
+ toml.parse(result);
149
+ }
150
+ catch (err) {
151
+ throw new ConfigError(`managed.fastlyToml does not give a valid fastly.toml: ${String(err instanceof Error ? err.message : err)}`);
152
+ }
153
+ return result;
154
+ }
@@ -0,0 +1,47 @@
1
+ import { type CollectionSelection } from '../../../models/config/collection-selection.js';
2
+ import { type FastlyTomlSections } from '../../../models/config/static-publish-project.js';
3
+ import { type GeneratedFrom, type StaticPublishTemplateOptions } from '../../../models/config/static-publish-rc.js';
4
+ import { type AppTemplate } from './app-template.js';
5
+ export type AppConfig = {
6
+ appDir: string;
7
+ name: string | undefined;
8
+ author: string | undefined;
9
+ description: string | undefined;
10
+ serviceId: string | undefined;
11
+ storage: {
12
+ mode: 'kv-store';
13
+ kvStoreName: string;
14
+ } | {
15
+ mode: 's3';
16
+ region: string;
17
+ bucket: string;
18
+ endpointUrl: string;
19
+ endpointGenerated: boolean;
20
+ };
21
+ publishId: string;
22
+ defaultCollectionName: string;
23
+ staticPublisherWorkingDir: string;
24
+ rootDir: string;
25
+ publicDir: string;
26
+ staticDirs: string[];
27
+ spaFilename: string | undefined;
28
+ notFoundPageFilename: string | undefined;
29
+ autoIndex: string[];
30
+ autoExt: string[];
31
+ staticPublishVersionSpec: string;
32
+ template: AppTemplate;
33
+ generatedFrom: GeneratedFrom | undefined;
34
+ collectionSelection?: CollectionSelection;
35
+ fastlyToml?: FastlyTomlSections;
36
+ build?: {
37
+ hono?: {
38
+ extensionsDir: string;
39
+ };
40
+ };
41
+ templateOptions?: StaticPublishTemplateOptions;
42
+ packageLock?: string;
43
+ };
44
+ export declare const TEMPLATE_HOOKS: readonly ['prebuild', 'postbuild', 'postinstall'];
45
+ export declare const TEMPLATE_WATCH_SCRIPT = "scripts/template_watch.js";
46
+ export declare function generateApp(config: AppConfig): Record<string, string>;
47
+ //# sourceMappingURL=generate-app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-app.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/generate-app.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAC1F,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAGpH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMrD,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EACH;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GACzC;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,iBAAiB,EAAE,OAAO,CAAA;KAAE,CAAC;IACpG,SAAS,EAAE,MAAM,CAAC;IAClB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,yBAAyB,EAAE,MAAM,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,wBAAwB,EAAE,MAAM,CAAC;IAEjC,QAAQ,EAAE,WAAW,CAAC;IAEtB,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAEzC,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAE1C,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAGhC,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE;YAAE,aAAa,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAG7C,eAAe,CAAC,EAAE,4BAA4B,CAAC;IAE/C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAIF,eAAO,MAAM,cAAc,YAAK,UAAU,EAAE,WAAW,EAAE,aAAa,CAAW,CAAC;AAKlF,eAAO,MAAM,qBAAqB,8BAA8B,CAAC;AAKjE,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAsLrE"}
@@ -0,0 +1,164 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import * as path from 'node:path';
6
+ import { dotRelative } from '../../util/files.js';
7
+ import { ConfigError } from '../../util/output.js';
8
+ import { addFastlyTomlSections } from './fastly-toml-sections.js';
9
+ import { renderAppResource } from './render.js';
10
+ // The names of the template hooks. Every app has them as npm scripts. Each one
11
+ // runs scripts/template_<name>.js if the app has that file.
12
+ export const TEMPLATE_HOOKS = ['prebuild', 'postbuild', 'postinstall'];
13
+ // The watch script of a template, if it has one. It runs next to
14
+ // `fastly compute serve --watch` (npm run dev:watch, or dev -- --watch), until
15
+ // it is stopped.
16
+ export const TEMPLATE_WATCH_SCRIPT = 'scripts/template_watch.js';
17
+ // Makes the files of the app, keyed by the path relative to the app dir.
18
+ // It does not write files or use the network, so that tests can compare its
19
+ // output. It reads only the resources/ directory of this package.
20
+ export function generateApp(config) {
21
+ const { appDir: computeJsDir, name, author, description, serviceId, storage, publishId, defaultCollectionName, staticPublisherWorkingDir, rootDir, publicDir, staticDirs, spaFilename, notFoundPageFilename, autoIndex, autoExt, staticPublishVersionSpec, template, generatedFrom, collectionSelection, fastlyToml, build, templateOptions, packageLock, } = config;
22
+ if (collectionSelection != null && !template.supports.collectionSelection) {
23
+ throw new ConfigError(`The template '${template.name}' does not support collectionSelection.`);
24
+ }
25
+ const resourceFiles = {};
26
+ // .gitignore. The working dir only if it is in the app dir.
27
+ const workingDirInApp = path.relative(computeJsDir, staticPublisherWorkingDir);
28
+ resourceFiles['.gitignore'] = renderAppResource('gitignore', {
29
+ workingDirInApp: !workingDirInApp.startsWith('..') ? workingDirInApp : undefined,
30
+ templateLines: template.gitignore,
31
+ });
32
+ // package.json: the dependencies come from the template's package.json.
33
+ const packageJsonScripts = {
34
+ 'dev:start': 'fastly compute serve',
35
+ 'dev:watch': 'compute-js-static-publish run-dev-watch',
36
+ 'fastly:deploy': 'fastly compute publish',
37
+ 'prebuild': 'compute-js-static-publish run-template-hook prebuild',
38
+ 'build': `js-compute-runtime ./${template.entry} ./bin/main.wasm`,
39
+ 'postbuild': 'compute-js-static-publish run-template-hook postbuild',
40
+ 'postinstall': 'compute-js-static-publish run-template-hook postinstall',
41
+ };
42
+ if (storage.mode === 'kv-store') {
43
+ packageJsonScripts['dev:publish'] = 'npx @fastly/compute-js-static-publish publish-content --local';
44
+ packageJsonScripts['fastly:publish'] = 'npx @fastly/compute-js-static-publish publish-content';
45
+ }
46
+ else if (storage.mode === 's3') {
47
+ packageJsonScripts['s3:publish'] = 'npx @fastly/compute-js-static-publish publish-content';
48
+ }
49
+ resourceFiles['package.json'] = JSON.stringify({
50
+ name,
51
+ version: '0.1.0',
52
+ description,
53
+ author,
54
+ type: 'module',
55
+ devDependencies: {
56
+ ...template.devDependencies,
57
+ '@fastly/compute-js-static-publish': staticPublishVersionSpec,
58
+ },
59
+ dependencies: {
60
+ ...template.dependencies,
61
+ },
62
+ engines: {
63
+ node: '>=20.11.0',
64
+ },
65
+ private: true,
66
+ scripts: packageJsonScripts,
67
+ }, undefined, 2);
68
+ if (packageLock != null) {
69
+ resourceFiles['package-lock.json'] = packageLock;
70
+ }
71
+ // fastly.toml
72
+ let localServerKvStorePath;
73
+ let s3EndpointUrl;
74
+ let s3EndpointHostname;
75
+ if (storage.mode === 'kv-store') {
76
+ localServerKvStorePath = dotRelative(computeJsDir, path.resolve(staticPublisherWorkingDir, 'kvstore.json'));
77
+ // kvstore.json
78
+ resourceFiles[localServerKvStorePath] = '{}';
79
+ }
80
+ else if (storage.mode === 's3') {
81
+ const url = new URL(storage.endpointUrl);
82
+ s3EndpointUrl = String(url);
83
+ s3EndpointHostname = url.hostname;
84
+ }
85
+ resourceFiles['fastly.toml'] = addFastlyTomlSections(renderAppResource('fastly.toml', {
86
+ author,
87
+ description,
88
+ name,
89
+ serviceId,
90
+ storage,
91
+ localServerKvStorePath,
92
+ s3EndpointUrl,
93
+ s3EndpointHostname,
94
+ }), fastlyToml);
95
+ // static-publish.rc.js
96
+ resourceFiles['static-publish.rc.js'] = renderAppResource('static-publish.rc.js', {
97
+ storage,
98
+ s3EndpointUrl,
99
+ publishId,
100
+ defaultCollectionName,
101
+ staticPublisherWorkingDir: dotRelative(computeJsDir, staticPublisherWorkingDir),
102
+ generatedFrom,
103
+ collectionSelection,
104
+ build: build?.hono != null ?
105
+ { hono: { extensionsDir: dotRelative(computeJsDir, build.hono.extensionsDir).split(path.sep).join('/') } } :
106
+ undefined,
107
+ templateOptions,
108
+ });
109
+ // publish-content.config.js
110
+ // publicDirPrefix -- if public dir is deeper than the root dir, then
111
+ // public dir is used as a prefix to drill into asset names.
112
+ // e.g.,
113
+ // root dir : /path/to/root
114
+ // public dir : /path/to/root/public
115
+ // then publicDirPrefix = /public
116
+ // The caller has already established publicDir.startsWith(rootDir)
117
+ let publicDirPrefix = '';
118
+ if (rootDir !== publicDir) {
119
+ publicDirPrefix = publicDir.slice(rootDir.length);
120
+ }
121
+ // staticItems - specified as prefixes, relative to publicDir
122
+ const staticItems = [];
123
+ for (const staticDir of staticDirs) {
124
+ // The caller has already established staticDir.startsWith(publicDir)
125
+ let staticItem = staticDir.slice(publicDir.length);
126
+ if (!staticItem.endsWith('/')) {
127
+ // Ending with a slash denotes that this is a directory.
128
+ staticItem = staticItem + '/';
129
+ }
130
+ staticItems.push(staticItem);
131
+ }
132
+ // spaFile - asset key of spa file
133
+ let spaFile = false;
134
+ if (spaFilename != null) {
135
+ // The caller has already established spaFilename.startsWith(rootDir)
136
+ // and that it exists
137
+ spaFile = spaFilename.slice(rootDir.length);
138
+ }
139
+ let notFoundPageFile = false;
140
+ if (notFoundPageFilename != null) {
141
+ // The caller has already established notFoundPageFilename.startsWith(rootDir)
142
+ // and that it exists
143
+ notFoundPageFile = notFoundPageFilename.slice(rootDir.length);
144
+ }
145
+ resourceFiles['publish-content.config.js'] = renderAppResource('publish-content.config.js', {
146
+ rootDir: dotRelative(computeJsDir, rootDir),
147
+ publicDirPrefix,
148
+ staticItems,
149
+ spaFile,
150
+ notFoundPageFile,
151
+ autoExt,
152
+ autoIndex,
153
+ });
154
+ // The files of the template, for example src/index.js. A template never
155
+ // replaces a file that generateApp() writes.
156
+ const written = new Set(Object.keys(resourceFiles).map(file => path.posix.normalize(file)));
157
+ for (const [file, content] of Object.entries(template.files)) {
158
+ if (written.has(path.posix.normalize(file))) {
159
+ throw new Error(`The template '${template.name}' has the file '${file}', which generateApp() writes.`);
160
+ }
161
+ resourceFiles[file] = content;
162
+ }
163
+ return resourceFiles;
164
+ }
@@ -13,11 +13,17 @@ export type InitAppOptions = {
13
13
  description: string | undefined;
14
14
  serviceId: string | undefined;
15
15
  publishId: string | undefined;
16
+ defaultCollectionName: string | undefined;
16
17
  storageMode: string | undefined;
17
18
  kvStoreName: string | undefined;
18
19
  s3Region: string | undefined;
19
20
  s3Bucket: string | undefined;
20
21
  s3Endpoint: string | undefined;
22
+ template: string;
21
23
  };
22
24
  export declare function action(actionArgs: string[]): Promise<void>;
25
+ export declare function addGitignoreLines(existing: string | null, lines: string[]): {
26
+ content: string;
27
+ added: string[];
28
+ };
23
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAwEA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AA0TF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAktBhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAoGA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA0UF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA8iBhD;AAKD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAehH"}