@scalar/cli 2.15.0 → 2.18.0

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 (112) hide show
  1. package/README.md +121 -25
  2. package/chunks/{action-3W4IC7QL.js → action-2WVJ2WEW.js} +26 -27
  3. package/chunks/{action-HOCCP353.js → action-4BDZ2CXP.js} +12 -13
  4. package/chunks/{action-3QQSKGM3.js → action-5AXDB5VN.js} +21 -23
  5. package/chunks/{action-LD5B5QQ4.js → action-6I3TJLRO.js} +34 -33
  6. package/chunks/{action-T7SD3ETN.js → action-6WZN63LT.js} +299 -75
  7. package/chunks/{action-IUAYC2SC.js → action-7GZGVTYI.js} +1071 -775
  8. package/chunks/{action-2BGAMGXU.js → action-7ZCJAWI2.js} +9 -9
  9. package/chunks/{action-6HFH7DAW.js → action-A6YOY24G.js} +14 -10
  10. package/chunks/{action-IU2AVNOW.js → action-AGGHY4N2.js} +26 -26
  11. package/chunks/{action-B2WWTOF6.js → action-BVZOA2G5.js} +15 -16
  12. package/chunks/{action-2UZWKMSJ.js → action-BYDJ4R4F.js} +18 -19
  13. package/chunks/{action-HDT7EO7W.js → action-CBAL5CYB.js} +19 -21
  14. package/chunks/action-COFGCCYS.js +89 -0
  15. package/chunks/action-CYU5Q5LT.js +254 -0
  16. package/chunks/{action-MJHLG7AE.js → action-DTQH6CKR.js} +33 -33
  17. package/chunks/{action-P2RPH5R2.js → action-ED5WLLIE.js} +11 -12
  18. package/chunks/action-F4CQ4DW3.js +654 -0
  19. package/chunks/{action-SRFBOLDL.js → action-GQDQU2WE.js} +1 -1
  20. package/chunks/{action-PDSSIW2A.js → action-GVW5PSPT.js} +26 -28
  21. package/chunks/{action-WOLNPEUQ.js → action-H5VRLFCY.js} +16 -12
  22. package/chunks/{action-G2WBTXOK.js → action-IWEAWDT3.js} +19 -19
  23. package/chunks/{action-NZJ4Z64U.js → action-JN6JVQUV.js} +16 -18
  24. package/chunks/{action-PNSWHIHC.js → action-KVM76ZKQ.js} +20 -20
  25. package/chunks/{action-JNH4DCZX.js → action-LLMFEBHH.js} +3 -4
  26. package/chunks/{action-QJMRAFOF.js → action-PEG7AUA6.js} +20 -19
  27. package/chunks/{action-2HPMP473.js → action-QC72LLYE.js} +13 -11
  28. package/chunks/{action-ZTLOQZTT.js → action-QP6MRSQW.js} +16 -15
  29. package/chunks/{action-4HXB3YQR.js → action-R53K22GE.js} +230 -52
  30. package/chunks/{action-U2RJ3ZAU.js → action-SJPWL723.js} +6 -5
  31. package/chunks/{action-57SV3ZBM.js → action-T3R4SDAI.js} +9 -9
  32. package/chunks/{action-777R7LOG.js → action-TT7ZJNST.js} +25 -25
  33. package/chunks/{action-TY4BZEMN.js → action-UPVVJE26.js} +18 -19
  34. package/chunks/{action-MBAAYXKK.js → action-V35W4MRK.js} +18 -19
  35. package/chunks/{action-TR2T2UYB.js → action-W4KGRBRV.js} +9 -9
  36. package/chunks/{action-ENDUKGWS.js → action-ZIVYJCC2.js} +16 -18
  37. package/chunks/{action-7LK4RUDP.js → action-ZU5X2KQX.js} +52 -49
  38. package/chunks/{actions-D5OHPBWC.js → actions-CERT7BL4.js} +25 -26
  39. package/chunks/{actions-RI42JY6H.js → actions-RCIS37Y6.js} +22 -24
  40. package/chunks/{agent-NA3QFKJX.js → agent-CT3RRYPJ.js} +7 -7
  41. package/chunks/{asyncapi-YBTWMTW6.js → asyncapi-DVBS23QW.js} +17 -18
  42. package/chunks/{build.action-4YDNDBXC.js → build.action-7MKMMV6V.js} +38 -32
  43. package/chunks/{chunk-MGGMCT77.js → chunk-36UI2W7I.js} +1 -1
  44. package/chunks/chunk-4BMOCIYO.js +536 -0
  45. package/chunks/{chunk-ADQ6B6QI.js → chunk-5DRLDTTU.js} +1 -1
  46. package/chunks/{chunk-G5WWW7VD.js → chunk-5EO2CVAR.js} +6 -6
  47. package/chunks/{chunk-Q26DFKTY.js → chunk-5GZAGHKL.js} +1 -1
  48. package/chunks/{chunk-DWJMPHLY.js → chunk-7LUXRNKV.js} +27 -2
  49. package/chunks/{chunk-BY4NGQ5D.js → chunk-A2MPF6GE.js} +7 -3
  50. package/chunks/{chunk-5D3T63G4.js → chunk-BIQFYZP6.js} +1 -1
  51. package/chunks/chunk-CNJ4TLU7.js +83 -0
  52. package/chunks/{chunk-UM3WZUGF.js → chunk-CWCRBWA6.js} +7 -3
  53. package/chunks/{chunk-Z6HOHGUJ.js → chunk-CYIGEQOJ.js} +2 -2
  54. package/chunks/{chunk-4S3DGMMZ.js → chunk-DUIMDHQQ.js} +1 -1
  55. package/chunks/{chunk-W7P6VTCG.js → chunk-DVA4NCCY.js} +6 -4
  56. package/chunks/chunk-DWWY3LPC.js +85 -0
  57. package/chunks/{chunk-USVU6AC2.js → chunk-F6E7FJEC.js} +18 -12
  58. package/chunks/{chunk-E24BNP6E.js → chunk-FDW4LC45.js} +1 -1
  59. package/chunks/{chunk-TW2UASEW.js → chunk-FMPJSW6A.js} +4 -4
  60. package/chunks/{chunk-IPWJEGPD.js → chunk-GCVB22TG.js} +2 -2
  61. package/chunks/{chunk-6BQHLHBE.js → chunk-GXKNYM54.js} +3 -3
  62. package/chunks/chunk-I25ZCHBJ.js +22 -0
  63. package/chunks/{chunk-I57ID5K7.js → chunk-JBMHCTZD.js} +8 -1
  64. package/chunks/{chunk-KOLEQNLG.js → chunk-JEOQ7LSA.js} +1 -1
  65. package/chunks/{chunk-QMERQSPM.js → chunk-KI2AVDKM.js} +8 -6
  66. package/chunks/{chunk-2KSOARE4.js → chunk-KSY2GH53.js} +3 -3
  67. package/chunks/{chunk-SHRUJFQI.js → chunk-KWQVA66H.js} +105 -18
  68. package/chunks/{chunk-DLYMDGFW.js → chunk-LPWRG2MS.js} +4 -4
  69. package/chunks/{chunk-Y6GKZ2FM.js → chunk-LVUMNGVA.js} +1 -1
  70. package/chunks/{chunk-PIDLENYN.js → chunk-M34HMQMV.js} +42 -83
  71. package/chunks/{chunk-7FS7BAUX.js → chunk-MRZ5A7LB.js} +133 -19
  72. package/chunks/chunk-O3I3LTTJ.js +24 -0
  73. package/chunks/{chunk-VBHPHAGS.js → chunk-O4DJIA6Y.js} +2 -18
  74. package/chunks/chunk-OKLL5422.js +263 -0
  75. package/chunks/{chunk-HIDIW2FN.js → chunk-OQE3WKI3.js} +1 -1
  76. package/chunks/{chunk-ERZ3HYB5.js → chunk-PMDHYIB4.js} +9 -21
  77. package/chunks/{chunk-IDGT5RAQ.js → chunk-RELSIFIL.js} +2 -2
  78. package/chunks/{chunk-BOCMOHQA.js → chunk-RGJPENX7.js} +1 -1
  79. package/chunks/{chunk-7FGJIUDN.js → chunk-RHAQ4XBA.js} +3 -3
  80. package/chunks/chunk-RQ7QBRJT.js +93 -0
  81. package/chunks/chunk-S3LY7RKP.js +54 -0
  82. package/chunks/{chunk-T76K7QNX.js → chunk-S5OGPH2P.js} +3 -3
  83. package/chunks/{chunk-ANP5XF26.js → chunk-U36HEOGO.js} +12625 -1369
  84. package/chunks/{chunk-IPUJEBMI.js → chunk-UWRJCJVG.js} +1 -1
  85. package/chunks/chunk-V7DBDXSJ.js +24 -0
  86. package/chunks/{chunk-RRYUCZYO.js → chunk-WGTZEX4Y.js} +7 -3
  87. package/chunks/{chunk-7PNOYE6B.js → chunk-Y3CXAIAG.js} +30 -3
  88. package/chunks/{chunk-GOKHFNB2.js → chunk-Z7EH7CJC.js} +3 -3
  89. package/chunks/{chunk-42MIV6WF.js → chunk-ZMJW5UWU.js} +6 -5
  90. package/chunks/chunk-ZQDAPKWX.js +111 -0
  91. package/chunks/{create.action-52K3XAYN.js → create.action-VA2ISPIM.js} +27 -29
  92. package/chunks/{delete.action-47LPLTOX.js → delete.action-AIWMDGXV.js} +26 -28
  93. package/chunks/{delete.action-3NMOQPIR.js → delete.action-GEN6OD7A.js} +26 -28
  94. package/chunks/{diff.action-5TLC2EHT.js → diff.action-LBK656RN.js} +32 -27
  95. package/chunks/{get.action-BCMLG7C7.js → get.action-5SWRNQ3D.js} +20 -19
  96. package/chunks/{get.action-TOZ474GO.js → get.action-UPPPGGI4.js} +29 -23
  97. package/chunks/{list.action-6ZWEENT6.js → list.action-YJZBC25S.js} +26 -28
  98. package/chunks/{list.action-CMAA5KTY.js → list.action-YOWWC4I4.js} +54 -25
  99. package/chunks/{publish.action-U3VIU5LZ.js → publish.action-QMVDHDJZ.js} +52 -49
  100. package/chunks/{update.action-UQHZYVTP.js → update.action-GFDZIGEP.js} +27 -29
  101. package/chunks/{update.action-QZOP25ME.js → update.action-SNGKPS7A.js} +26 -28
  102. package/index.js +688 -212
  103. package/package.json +11 -11
  104. package/skills/scalar-cli/SKILL.md +4 -3
  105. package/template.md +120 -24
  106. package/chunks/action-3KP3WVPZ.js +0 -112
  107. package/chunks/action-APBLB3IU.js +0 -235
  108. package/chunks/chunk-BLY2CF4S.js +0 -58
  109. package/chunks/chunk-BMQFEKHA.js +0 -3534
  110. package/chunks/chunk-EOTD7HAV.js +0 -318
  111. package/chunks/chunk-QXOUDBFK.js +0 -92
  112. package/chunks/chunk-TR5U7G7T.js +0 -32
@@ -4,62 +4,64 @@ import {
4
4
  DEFAULT_MARKDOWN_FILE_NAME,
5
5
  DEFAULT_OPENAPI_FILE_NAME,
6
6
  findConfig,
7
- getCurrentFolderName,
7
+ getCurrentFolderName
8
+ } from "./chunk-S3LY7RKP.js";
9
+ import {
8
10
  scalarConfigSchema
9
- } from "./chunk-PIDLENYN.js";
11
+ } from "./chunk-M34HMQMV.js";
12
+ import {
13
+ canPrompt,
14
+ confirm,
15
+ requireInteractive,
16
+ text
17
+ } from "./chunk-XUX6JXU5.js";
18
+ import "./chunk-IRQJDPZE.js";
10
19
  import {
11
20
  writeJson
12
21
  } from "./chunk-SNQFFEYH.js";
13
22
  import {
14
23
  apiService
15
- } from "./chunk-BMQFEKHA.js";
16
- import "./chunk-ANP5XF26.js";
17
- import "./chunk-7FS7BAUX.js";
18
- import "./chunk-Z6HOHGUJ.js";
19
- import "./chunk-EOTD7HAV.js";
20
- import "./chunk-USVU6AC2.js";
21
- import "./chunk-W7P6VTCG.js";
22
- import "./chunk-5D3T63G4.js";
24
+ } from "./chunk-U36HEOGO.js";
25
+ import "./chunk-MRZ5A7LB.js";
26
+ import "./chunk-CYIGEQOJ.js";
27
+ import "./chunk-4BMOCIYO.js";
28
+ import "./chunk-F6E7FJEC.js";
29
+ import "./chunk-DVA4NCCY.js";
30
+ import "./chunk-BIQFYZP6.js";
31
+ import "./chunk-KSY2GH53.js";
23
32
  import {
24
33
  getMetadata
25
- } from "./chunk-42MIV6WF.js";
34
+ } from "./chunk-ZMJW5UWU.js";
26
35
  import {
27
36
  config
28
- } from "./chunk-TR5U7G7T.js";
29
- import "./chunk-DWJMPHLY.js";
30
- import "./chunk-6BQHLHBE.js";
31
- import "./chunk-BOCMOHQA.js";
32
- import {
33
- cancelOperation,
34
- confirm,
35
- requireInteractive,
36
- text
37
- } from "./chunk-XUX6JXU5.js";
38
- import "./chunk-IRQJDPZE.js";
39
- import "./chunk-2KSOARE4.js";
37
+ } from "./chunk-7LUXRNKV.js";
40
38
  import {
41
39
  output
42
40
  } from "./chunk-T5HJUAWB.js";
43
- import "./chunk-4S3DGMMZ.js";
44
- import "./chunk-7PNOYE6B.js";
45
- import "./chunk-Q26DFKTY.js";
41
+ import {
42
+ err,
43
+ ok
44
+ } from "./chunk-DUIMDHQQ.js";
45
+ import "./chunk-Y3CXAIAG.js";
46
+ import "./chunk-GXKNYM54.js";
47
+ import "./chunk-RGJPENX7.js";
48
+ import "./chunk-5GZAGHKL.js";
46
49
  import {
47
50
  slugify
48
- } from "./chunk-I57ID5K7.js";
51
+ } from "./chunk-JBMHCTZD.js";
49
52
  import "./chunk-3MZYUBJ6.js";
50
53
 
51
54
  // src/domains/project/init/action.ts
52
- import fs from "node:fs/promises";
53
- import path from "node:path";
55
+ import path2 from "node:path";
54
56
  import as from "ansis";
55
57
 
56
- // ../../node_modules/.pnpm/@scalar+galaxy@0.7.2/node_modules/@scalar/galaxy/dist/3.1.json
58
+ // ../../node_modules/.pnpm/@scalar+galaxy@0.7.3/node_modules/@scalar/galaxy/dist/3.1.json
57
59
  var __default = {
58
60
  openapi: "3.1.1",
59
61
  info: {
60
62
  title: "Scalar Galaxy",
61
63
  description: "The Scalar Galaxy is an example OpenAPI document to test OpenAPI tools and libraries. It's a fictional universe with fictional planets and fictional data.\n\n## Resources\n\n* https://github.com/scalar/scalar\n* https://github.com/OAI/OpenAPI-Specification\n* https://scalar.com\n\n## Markdown Support\n\nAll descriptions *can* contain ~~tons of text~~ **Markdown**. [If GitHub supports the syntax](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax), chances are we're supporting it, too.\n\n<details>\n <summary>Examples</summary>\n\n **Blockquotes**\n\n > I love OpenAPI. <3\n\n **Tables**\n\n | Feature | Availability |\n | ---------------- | ------------ |\n | Markdown Support | \u2713 |\n\n **Accordion**\n\n ```html\n <details>\n <summary>Using Details Tags</summary>\n <p>HTML Example</p>\n </details>\n ```\n\n **Images**\n\n Yes, there's support for images, too!\n\n ![Empty placeholder image showing the width/height](https://images.placeholders.dev/?width=1280&height=720)\n\n **Alerts**\n\n > [!tip]\n > You can use Markdown alerts in your descriptions.\n\n</details>\n",
62
- version: "0.7.2",
64
+ version: "0.7.3",
63
65
  contact: {
64
66
  name: "Scalar Support",
65
67
  url: "https://scalar.com",
@@ -2056,21 +2058,264 @@ We're here to help:
2056
2058
  - [Schedule a call](https://scalar.cal.com/scalar/chat-with-scalar)
2057
2059
  `;
2058
2060
 
2059
- // src/domains/project/init/action.ts
2060
- async function fileExists(path2) {
2061
+ // src/domains/project/init/files.ts
2062
+ import fs from "node:fs/promises";
2063
+ import path from "node:path";
2064
+ var describeError = (error) => error instanceof Error ? error.message : String(error);
2065
+ function isMissing(error) {
2066
+ return Boolean(
2067
+ error && typeof error === "object" && "code" in error && error.code === "ENOENT"
2068
+ );
2069
+ }
2070
+ async function inspect(filePath) {
2061
2071
  try {
2062
- await fs.access(path2, fs.constants.F_OK);
2063
- return true;
2064
- } catch {
2065
- return false;
2072
+ return ok(await fs.lstat(filePath));
2073
+ } catch (error) {
2074
+ if (isMissing(error)) {
2075
+ return ok(void 0);
2076
+ }
2077
+ return err(`Could not inspect ${filePath}: ${describeError(error)}`);
2066
2078
  }
2067
2079
  }
2080
+ async function preflightInitFiles(paths, force = false) {
2081
+ const destinations = [];
2082
+ const conflicts = [];
2083
+ const errors = [];
2084
+ for (const filePath of paths) {
2085
+ const result = await inspect(filePath);
2086
+ if (!result.ok) {
2087
+ errors.push(result.error);
2088
+ continue;
2089
+ }
2090
+ if (result.data && !result.data.isFile()) {
2091
+ errors.push(
2092
+ `Cannot replace ${filePath}: destination is not a regular file.`
2093
+ );
2094
+ continue;
2095
+ }
2096
+ if (result.data && !force) conflicts.push(filePath);
2097
+ destinations.push({ path: filePath, original: result.data });
2098
+ }
2099
+ if (conflicts.length) {
2100
+ errors.push(
2101
+ `Existing init files:
2102
+ ${conflicts.join("\n")}
2103
+ Run scalar project init with --force to replace the configuration, docs-quickstart.md, and docs-openapi.json.`
2104
+ );
2105
+ }
2106
+ return errors.length ? err(errors.join("\n")) : ok(destinations);
2107
+ }
2108
+ function unchanged(actual, expected) {
2109
+ if (!actual || !expected) return actual === expected;
2110
+ return actual.isFile() && actual.dev === expected.dev && actual.ino === expected.ino && actual.size === expected.size && actual.mtimeMs === expected.mtimeMs && actual.mode === expected.mode;
2111
+ }
2112
+ async function preserveMode(mode, inspectMode, chmod) {
2113
+ try {
2114
+ const actual = await inspectMode();
2115
+ if ((actual.mode & 511) === mode) return ok(void 0);
2116
+ await chmod(mode).catch((error) => {
2117
+ if (error && typeof error === "object" && "code" in error && error.code === "EPERM" && typeof process.geteuid === "function" && actual.uid !== process.geteuid())
2118
+ return;
2119
+ throw error;
2120
+ });
2121
+ return ok(void 0);
2122
+ } catch (error) {
2123
+ return err(describeError(error));
2124
+ }
2125
+ }
2126
+ async function installExclusive(source, destination, trackIdentity) {
2127
+ try {
2128
+ const linked = await fs.link(source, destination).then(() => true).catch((error) => {
2129
+ if (error && typeof error === "object" && "code" in error && typeof error.code === "string" && error.code !== "EEXIST")
2130
+ return false;
2131
+ throw error;
2132
+ });
2133
+ if (linked) return ok(void 0);
2134
+ const content = await fs.readFile(source);
2135
+ const sourceIdentity = await fs.stat(source);
2136
+ const handle = await fs.open(destination, "wx", sourceIdentity.mode & 511);
2137
+ try {
2138
+ trackIdentity?.(await handle.stat());
2139
+ const permissions = await preserveMode(
2140
+ sourceIdentity.mode & 511,
2141
+ () => handle.stat(),
2142
+ (mode) => handle.chmod(mode)
2143
+ );
2144
+ if (!permissions.ok) throw new Error(permissions.error);
2145
+ await handle.writeFile(content);
2146
+ } finally {
2147
+ try {
2148
+ trackIdentity?.(await handle.stat());
2149
+ } finally {
2150
+ await handle.close();
2151
+ }
2152
+ }
2153
+ return ok(void 0);
2154
+ } catch (error) {
2155
+ return err(describeError(error));
2156
+ }
2157
+ }
2158
+ async function withdrawInstalledFile(file) {
2159
+ const displacedPath = `${file.stagedPath}.rollback`;
2160
+ const moved = await fs.rename(file.destination.path, displacedPath).then(() => ok(true)).catch(
2161
+ (error) => isMissing(error) ? ok(false) : err(describeError(error))
2162
+ );
2163
+ if (!moved.ok) return moved;
2164
+ if (!moved.data) return ok(void 0);
2165
+ const displaced = await inspect(displacedPath);
2166
+ if (displaced.ok && unchanged(displaced.data, file.stagedIdentity)) {
2167
+ return ok(void 0);
2168
+ }
2169
+ const restored = await installExclusive(displacedPath, file.destination.path);
2170
+ return err(
2171
+ `Destination changed during initialization: ${file.destination.path}
2172
+ Displaced file retained at ${displacedPath}.${displaced.ok ? "" : `
2173
+ ${displaced.error}`}${restored.ok ? "" : `
2174
+ Could not restore displaced file: ${restored.error}`}`
2175
+ );
2176
+ }
2177
+ async function restoreFiles(files) {
2178
+ const errors = [];
2179
+ for (const file of [...files].reverse()) {
2180
+ try {
2181
+ if (file.installed) {
2182
+ const withdrawn = await withdrawInstalledFile(file);
2183
+ if (!withdrawn.ok) throw new Error(withdrawn.error);
2184
+ }
2185
+ if (file.backedUp) {
2186
+ const restored = await installExclusive(
2187
+ file.backupPath,
2188
+ file.destination.path
2189
+ );
2190
+ if (!restored.ok) throw new Error(restored.error);
2191
+ }
2192
+ } catch (error) {
2193
+ errors.push(
2194
+ `${describeError(error)}${file.backedUp ? `
2195
+ Original file retained at ${file.backupPath}` : ""}`
2196
+ );
2197
+ }
2198
+ }
2199
+ return errors;
2200
+ }
2201
+ async function writeInitFiles(files) {
2202
+ const first = files[0];
2203
+ if (!first) return ok({ warnings: [] });
2204
+ const staging = await fs.mkdtemp(path.join(path.dirname(first.path), ".scalar-init-")).catch(
2205
+ (error) => err(`Could not stage init files: ${describeError(error)}`)
2206
+ );
2207
+ if (typeof staging !== "string") return staging;
2208
+ const staged = [];
2209
+ try {
2210
+ for (const [index, destination] of files.entries()) {
2211
+ const stagedPath = path.join(staging, `${index}.new`);
2212
+ await fs.writeFile(stagedPath, destination.content, {
2213
+ flag: "wx",
2214
+ mode: destination.original ? destination.original.mode & 511 : 438
2215
+ });
2216
+ if (destination.original) {
2217
+ const permissions = await preserveMode(
2218
+ destination.original.mode & 511,
2219
+ () => fs.stat(stagedPath),
2220
+ (mode) => fs.chmod(stagedPath, mode)
2221
+ );
2222
+ if (!permissions.ok) throw new Error(permissions.error);
2223
+ }
2224
+ staged.push({
2225
+ destination,
2226
+ stagedPath,
2227
+ backupPath: path.join(
2228
+ staging,
2229
+ `${path.basename(destination.path)}.original`
2230
+ ),
2231
+ stagedIdentity: await fs.lstat(stagedPath),
2232
+ backedUp: false,
2233
+ installed: false
2234
+ });
2235
+ }
2236
+ for (const file of staged) {
2237
+ const current = await inspect(file.destination.path);
2238
+ if (!current.ok) throw new Error(current.error);
2239
+ if (!unchanged(current.data, file.destination.original)) {
2240
+ throw new Error(
2241
+ `Destination changed after preflight: ${file.destination.path}`
2242
+ );
2243
+ }
2244
+ if (file.destination.original) {
2245
+ await fs.rename(file.destination.path, file.backupPath);
2246
+ file.backedUp = true;
2247
+ if (!unchanged(await fs.lstat(file.backupPath), file.destination.original)) {
2248
+ throw new Error(
2249
+ `Destination changed while backing up: ${file.destination.path}`
2250
+ );
2251
+ }
2252
+ }
2253
+ const installed = await installExclusive(
2254
+ file.stagedPath,
2255
+ file.destination.path,
2256
+ (identity) => {
2257
+ file.installed = true;
2258
+ file.stagedIdentity = identity;
2259
+ }
2260
+ );
2261
+ if (!installed.ok) throw new Error(installed.error);
2262
+ file.installed = true;
2263
+ }
2264
+ } catch (error) {
2265
+ const recoveryErrors = await restoreFiles(staged);
2266
+ if (recoveryErrors.length) {
2267
+ return err(
2268
+ `Could not initialize project: ${describeError(error)}
2269
+ ${recoveryErrors.join("\n")}
2270
+ Recovery files retained in ${staging}.`
2271
+ );
2272
+ }
2273
+ const cleanup2 = await fs.rm(staging, { recursive: true }).catch((error2) => describeError(error2));
2274
+ return err(
2275
+ `Could not initialize project: ${describeError(error)}
2276
+ Changes from this initialization rolled back.${cleanup2 ? `
2277
+ Could not remove staging directory ${staging}: ${cleanup2}` : ""}`
2278
+ );
2279
+ }
2280
+ const cleanup = await fs.rm(staging, { recursive: true }).catch((error) => describeError(error));
2281
+ return ok({
2282
+ warnings: cleanup ? [
2283
+ `Project files initialized, but could not remove staging directory ${staging}: ${cleanup}`
2284
+ ] : []
2285
+ });
2286
+ }
2287
+
2288
+ // src/domains/project/init/action.ts
2068
2289
  async function initAction({
2069
2290
  subdomain,
2070
2291
  force,
2071
2292
  json
2072
2293
  }) {
2073
- const configFile = findConfig() || CONFIG_FILE_DEFAULT;
2294
+ const configFile = path2.resolve(findConfig() || CONFIG_FILE_DEFAULT);
2295
+ const currentDir = path2.dirname(configFile);
2296
+ const markdownFile = path2.join(currentDir, DEFAULT_MARKDOWN_FILE_NAME);
2297
+ const openapiFile = path2.join(currentDir, DEFAULT_OPENAPI_FILE_NAME);
2298
+ const canConfirmOverwrite = !force && !json && canPrompt();
2299
+ const destinations = await preflightInitFiles(
2300
+ [markdownFile, openapiFile, configFile],
2301
+ force || canConfirmOverwrite
2302
+ );
2303
+ if (!destinations.ok) {
2304
+ return output.error().message(destinations.error).exit("error");
2305
+ }
2306
+ const conflicts = destinations.data.filter(
2307
+ (destination) => destination.original
2308
+ );
2309
+ if (canConfirmOverwrite && conflicts.length) {
2310
+ const overwrite = await confirm({
2311
+ message: `Replace these existing init files?
2312
+ ${conflicts.map((file) => file.path).join("\n")}`,
2313
+ initialValue: false
2314
+ });
2315
+ if (!overwrite) {
2316
+ return output.error().message("Operation cancelled.").exit("error");
2317
+ }
2318
+ }
2074
2319
  const nextSteps = () => {
2075
2320
  if (!json)
2076
2321
  output.info().line("Next steps:").line(
@@ -2085,30 +2330,6 @@ async function initAction({
2085
2330
  )
2086
2331
  ).print();
2087
2332
  };
2088
- if (await fileExists(configFile)) {
2089
- if (!json)
2090
- output.info().line(
2091
- `${as.green("\u26A0")} Found existing configuration: ${as.green.bold(`${configFile}`)}`
2092
- ).print();
2093
- if (force) {
2094
- if (!json)
2095
- output.info().line(`${as.green("\u2714")} Overwriting existing file\u2026`).print();
2096
- }
2097
- if (force === void 0 || json && !force) {
2098
- requireInteractive(
2099
- "Pass --force to overwrite an existing configuration non-interactively.",
2100
- json
2101
- );
2102
- }
2103
- const shouldOverwriteExisting = force ?? await confirm({
2104
- message: "Overwrite the existing configuration file?",
2105
- initialValue: false
2106
- });
2107
- if (!shouldOverwriteExisting) {
2108
- return cancelOperation();
2109
- }
2110
- }
2111
- const currentDir = path.resolve(path.dirname(configFile));
2112
2333
  const configuration = scalarConfigSchema.parse({
2113
2334
  info: {},
2114
2335
  navigation: {
@@ -2191,28 +2412,31 @@ async function initAction({
2191
2412
  break;
2192
2413
  }
2193
2414
  const content = JSON.stringify(configuration, null, 2);
2194
- await fs.writeFile(configFile, content);
2195
- await fs.writeFile(
2196
- path.join(currentDir, DEFAULT_MARKDOWN_FILE_NAME),
2197
- quickstartMarkdown
2198
- );
2199
- await fs.writeFile(
2200
- path.join(currentDir, DEFAULT_OPENAPI_FILE_NAME),
2201
- JSON.stringify(__default, null, 2)
2415
+ const written = await writeInitFiles(
2416
+ destinations.data.map((destination) => ({
2417
+ ...destination,
2418
+ content: destination.path === configFile ? content : destination.path === markdownFile ? quickstartMarkdown : JSON.stringify(__default, null, 2)
2419
+ }))
2202
2420
  );
2421
+ if (!written.ok) {
2422
+ return output.error().message(written.error).exit("error");
2423
+ }
2203
2424
  if (json) {
2204
2425
  writeJson({
2205
- configPath: path.resolve(configFile),
2426
+ configPath: path2.resolve(configFile),
2206
2427
  subdomain: configuration.siteConfig.subdomain,
2207
2428
  files: [
2208
2429
  configFile,
2209
- path.join(currentDir, DEFAULT_MARKDOWN_FILE_NAME),
2210
- path.join(currentDir, DEFAULT_OPENAPI_FILE_NAME)
2211
- ].map((file) => path.resolve(file)),
2212
- availabilityChecked: Boolean(apiClient)
2430
+ path2.join(currentDir, DEFAULT_MARKDOWN_FILE_NAME),
2431
+ path2.join(currentDir, DEFAULT_OPENAPI_FILE_NAME)
2432
+ ].map((file) => path2.resolve(file)),
2433
+ availabilityChecked: Boolean(apiClient),
2434
+ ...written.data.warnings.length ? { warnings: written.data.warnings } : {}
2213
2435
  });
2214
2436
  return;
2215
2437
  }
2438
+ for (const warning of written.data.warnings)
2439
+ output.warn().message(warning).print();
2216
2440
  output.info().line(`${as.green("\u2714")} Configuration stored.
2217
2441
  `).line(`${as.green.bold(`${configFile}`)}
2218
2442
  `).line(