@foliwake/cli 0.0.0-stage → 0.6.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 (252) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE +202 -0
  3. package/README.md +643 -2
  4. package/dist/bin.d.ts +2 -0
  5. package/dist/bin.js +9 -0
  6. package/dist/command-words.d.ts +13 -0
  7. package/dist/command-words.js +53 -0
  8. package/dist/commands/account/keys/create.d.ts +12 -0
  9. package/dist/commands/account/keys/create.js +36 -0
  10. package/dist/commands/account/keys/list.d.ts +9 -0
  11. package/dist/commands/account/keys/list.js +23 -0
  12. package/dist/commands/account/keys/revoke.d.ts +12 -0
  13. package/dist/commands/account/keys/revoke.js +15 -0
  14. package/dist/commands/branch/bootstrap.d.ts +11 -0
  15. package/dist/commands/branch/bootstrap.js +23 -0
  16. package/dist/commands/branch/delete.d.ts +17 -0
  17. package/dist/commands/branch/delete.js +38 -0
  18. package/dist/commands/branch/history.d.ts +14 -0
  19. package/dist/commands/branch/history.js +24 -0
  20. package/dist/commands/branch/list.d.ts +11 -0
  21. package/dist/commands/branch/list.js +15 -0
  22. package/dist/commands/branch/update.d.ts +19 -0
  23. package/dist/commands/branch/update.js +49 -0
  24. package/dist/commands/code/deploy.d.ts +15 -0
  25. package/dist/commands/code/deploy.js +78 -0
  26. package/dist/commands/code/prepare.d.ts +13 -0
  27. package/dist/commands/code/prepare.js +54 -0
  28. package/dist/commands/code/release.d.ts +19 -0
  29. package/dist/commands/code/release.js +51 -0
  30. package/dist/commands/code/rollback.d.ts +17 -0
  31. package/dist/commands/code/rollback.js +38 -0
  32. package/dist/commands/connect.d.ts +19 -0
  33. package/dist/commands/connect.js +100 -0
  34. package/dist/commands/create.d.ts +30 -0
  35. package/dist/commands/create.js +163 -0
  36. package/dist/commands/credential/list.d.ts +10 -0
  37. package/dist/commands/credential/list.js +21 -0
  38. package/dist/commands/credential/rm.d.ts +12 -0
  39. package/dist/commands/credential/rm.js +18 -0
  40. package/dist/commands/credential/set.d.ts +15 -0
  41. package/dist/commands/credential/set.js +58 -0
  42. package/dist/commands/dev.d.ts +25 -0
  43. package/dist/commands/dev.js +89 -0
  44. package/dist/commands/login.d.ts +20 -0
  45. package/dist/commands/login.js +94 -0
  46. package/dist/commands/logout.d.ts +14 -0
  47. package/dist/commands/logout.js +61 -0
  48. package/dist/commands/migration/commit.d.ts +13 -0
  49. package/dist/commands/migration/commit.js +42 -0
  50. package/dist/commands/migration/prepare.d.ts +18 -0
  51. package/dist/commands/migration/prepare.js +53 -0
  52. package/dist/commands/operation/cancel.d.ts +14 -0
  53. package/dist/commands/operation/cancel.js +21 -0
  54. package/dist/commands/operation/get.d.ts +14 -0
  55. package/dist/commands/operation/get.js +26 -0
  56. package/dist/commands/operation/list.d.ts +12 -0
  57. package/dist/commands/operation/list.js +25 -0
  58. package/dist/commands/operation/recover.d.ts +20 -0
  59. package/dist/commands/operation/recover.js +49 -0
  60. package/dist/commands/page/changes.d.ts +13 -0
  61. package/dist/commands/page/changes.js +26 -0
  62. package/dist/commands/page/check.d.ts +12 -0
  63. package/dist/commands/page/check.js +25 -0
  64. package/dist/commands/page/replace.d.ts +13 -0
  65. package/dist/commands/page/replace.js +59 -0
  66. package/dist/commands/page/unpreview.d.ts +17 -0
  67. package/dist/commands/page/unpreview.js +54 -0
  68. package/dist/commands/page/unpublish.d.ts +18 -0
  69. package/dist/commands/page/unpublish.js +36 -0
  70. package/dist/commands/project/preview.d.ts +8 -0
  71. package/dist/commands/project/preview.js +20 -0
  72. package/dist/commands/project/publish.d.ts +16 -0
  73. package/dist/commands/project/publish.js +40 -0
  74. package/dist/commands/project/unpublish.d.ts +16 -0
  75. package/dist/commands/project/unpublish.js +33 -0
  76. package/dist/commands/release/rollback.d.ts +17 -0
  77. package/dist/commands/release/rollback.js +38 -0
  78. package/dist/commands/servers/index.d.ts +20 -0
  79. package/dist/commands/servers/index.js +36 -0
  80. package/dist/commands/servers/use.d.ts +11 -0
  81. package/dist/commands/servers/use.js +30 -0
  82. package/dist/commands/site/adopt.d.ts +11 -0
  83. package/dist/commands/site/adopt.js +21 -0
  84. package/dist/commands/site/create.d.ts +18 -0
  85. package/dist/commands/site/create.js +61 -0
  86. package/dist/commands/site/edit.d.ts +11 -0
  87. package/dist/commands/site/edit.js +56 -0
  88. package/dist/commands/site/history.d.ts +11 -0
  89. package/dist/commands/site/history.js +25 -0
  90. package/dist/commands/site/link.d.ts +15 -0
  91. package/dist/commands/site/link.js +35 -0
  92. package/dist/commands/site/list.d.ts +9 -0
  93. package/dist/commands/site/list.js +29 -0
  94. package/dist/commands/site/reset-storage.d.ts +15 -0
  95. package/dist/commands/site/reset-storage.js +61 -0
  96. package/dist/commands/site/set.d.ts +16 -0
  97. package/dist/commands/site/set.js +45 -0
  98. package/dist/commands/site/show.d.ts +10 -0
  99. package/dist/commands/site/show.js +19 -0
  100. package/dist/commands/site/status.d.ts +11 -0
  101. package/dist/commands/site/status.js +15 -0
  102. package/dist/commands/site/unlink.d.ts +11 -0
  103. package/dist/commands/site/unlink.js +28 -0
  104. package/dist/commands/source/add.d.ts +32 -0
  105. package/dist/commands/source/add.js +103 -0
  106. package/dist/commands/source/adopt-pages.d.ts +14 -0
  107. package/dist/commands/source/adopt-pages.js +30 -0
  108. package/dist/commands/source/check.d.ts +17 -0
  109. package/dist/commands/source/check.js +52 -0
  110. package/dist/commands/source/list.d.ts +11 -0
  111. package/dist/commands/source/list.js +15 -0
  112. package/dist/commands/source/mappings/check.d.ts +13 -0
  113. package/dist/commands/source/mappings/check.js +69 -0
  114. package/dist/commands/source/pending.d.ts +12 -0
  115. package/dist/commands/source/pending.js +25 -0
  116. package/dist/commands/source/plugins.d.ts +6 -0
  117. package/dist/commands/source/plugins.js +17 -0
  118. package/dist/commands/source/sync.d.ts +16 -0
  119. package/dist/commands/source/sync.js +58 -0
  120. package/dist/commands/whoami.d.ts +6 -0
  121. package/dist/commands/whoami.js +21 -0
  122. package/dist/connect-prompts.d.ts +16 -0
  123. package/dist/connect-prompts.js +24 -0
  124. package/dist/connect.d.ts +133 -0
  125. package/dist/connect.js +416 -0
  126. package/dist/core-command.d.ts +91 -0
  127. package/dist/core-command.js +262 -0
  128. package/dist/core-types.d.ts +21 -0
  129. package/dist/core-types.js +1 -0
  130. package/dist/create-connect.d.ts +26 -0
  131. package/dist/create-connect.js +93 -0
  132. package/dist/dev/code-watcher.d.ts +66 -0
  133. package/dist/dev/code-watcher.js +254 -0
  134. package/dist/dev/dev-checks.d.ts +14 -0
  135. package/dist/dev/dev-checks.js +138 -0
  136. package/dist/dev/dev-reload.d.ts +51 -0
  137. package/dist/dev/dev-reload.js +345 -0
  138. package/dist/dev/flags.d.ts +15 -0
  139. package/dist/dev/flags.js +43 -0
  140. package/dist/dev/html.d.ts +30 -0
  141. package/dist/dev/html.js +106 -0
  142. package/dist/dev/kit-files.d.ts +7 -0
  143. package/dist/dev/kit-files.js +33 -0
  144. package/dist/dev/local-code.d.ts +22 -0
  145. package/dist/dev/local-code.js +101 -0
  146. package/dist/dev/remote-config.d.ts +57 -0
  147. package/dist/dev/remote-config.js +100 -0
  148. package/dist/dev/remote-dev.d.ts +41 -0
  149. package/dist/dev/remote-dev.js +527 -0
  150. package/dist/dev/remote-fetch.d.ts +5 -0
  151. package/dist/dev/remote-fetch.js +36 -0
  152. package/dist/dev/remote-html.d.ts +10 -0
  153. package/dist/dev/remote-html.js +60 -0
  154. package/dist/dev/remote-page.d.ts +34 -0
  155. package/dist/dev/remote-page.js +183 -0
  156. package/dist/dev/remote-routes.d.ts +63 -0
  157. package/dist/dev/remote-routes.js +114 -0
  158. package/dist/dev/signal-stop.d.ts +17 -0
  159. package/dist/dev/signal-stop.js +46 -0
  160. package/dist/dev/start.d.ts +18 -0
  161. package/dist/dev/start.js +80 -0
  162. package/dist/index.d.ts +5 -0
  163. package/dist/index.js +7 -0
  164. package/dist/lib/diagnostics.d.ts +15 -0
  165. package/dist/lib/diagnostics.js +12 -0
  166. package/dist/lib/front-matter.d.ts +6 -0
  167. package/dist/lib/front-matter.js +59 -0
  168. package/dist/lib/operation-result.d.ts +3 -0
  169. package/dist/lib/operation-result.js +16 -0
  170. package/dist/lib/problem-groups.d.ts +27 -0
  171. package/dist/lib/problem-groups.js +49 -0
  172. package/dist/lib/problems.d.ts +50 -0
  173. package/dist/lib/problems.js +94 -0
  174. package/dist/lib/prompts.d.ts +38 -0
  175. package/dist/lib/prompts.js +77 -0
  176. package/dist/lib/result-types.d.ts +198 -0
  177. package/dist/lib/result-types.js +3 -0
  178. package/dist/lib/rules.d.ts +15 -0
  179. package/dist/lib/rules.js +26 -0
  180. package/dist/lib/summaries.d.ts +19 -0
  181. package/dist/lib/summaries.js +22 -0
  182. package/dist/lib/sync-problems.d.ts +21 -0
  183. package/dist/lib/sync-problems.js +19 -0
  184. package/dist/main.d.ts +2 -0
  185. package/dist/main.js +40 -0
  186. package/dist/project-preview.d.ts +35 -0
  187. package/dist/project-preview.js +156 -0
  188. package/dist/project-publish.d.ts +28 -0
  189. package/dist/project-publish.js +173 -0
  190. package/dist/remote/connection.d.ts +8 -0
  191. package/dist/remote/connection.js +19 -0
  192. package/dist/remote/core-failure.d.ts +8 -0
  193. package/dist/remote/core-failure.js +15 -0
  194. package/dist/remote/credentials.d.ts +15 -0
  195. package/dist/remote/credentials.js +112 -0
  196. package/dist/remote/device-login.d.ts +33 -0
  197. package/dist/remote/device-login.js +161 -0
  198. package/dist/remote/remote-caller.d.ts +14 -0
  199. package/dist/remote/remote-caller.js +52 -0
  200. package/dist/remote/rpc-wire.d.ts +18 -0
  201. package/dist/remote/rpc-wire.js +57 -0
  202. package/dist/remote/servers.d.ts +80 -0
  203. package/dist/remote/servers.js +162 -0
  204. package/dist/remote/session.d.ts +53 -0
  205. package/dist/remote/session.js +132 -0
  206. package/dist/remote/sign-in-here.d.ts +5 -0
  207. package/dist/remote/sign-in-here.js +33 -0
  208. package/dist/remote/sign-in.d.ts +25 -0
  209. package/dist/remote/sign-in.js +55 -0
  210. package/dist/remote/wait-slices.d.ts +16 -0
  211. package/dist/remote/wait-slices.js +21 -0
  212. package/dist/render/add.d.ts +3 -0
  213. package/dist/render/add.js +9 -0
  214. package/dist/render/branch-write.d.ts +9 -0
  215. package/dist/render/branch-write.js +28 -0
  216. package/dist/render/branches.d.ts +5 -0
  217. package/dist/render/branches.js +28 -0
  218. package/dist/render/credentials.d.ts +5 -0
  219. package/dist/render/credentials.js +39 -0
  220. package/dist/render/operation-result.d.ts +16 -0
  221. package/dist/render/operation-result.js +65 -0
  222. package/dist/render/operation.d.ts +7 -0
  223. package/dist/render/operation.js +15 -0
  224. package/dist/render/page-changes.d.ts +3 -0
  225. package/dist/render/page-changes.js +36 -0
  226. package/dist/render/pending.d.ts +3 -0
  227. package/dist/render/pending.js +46 -0
  228. package/dist/render/plugin-list.d.ts +3 -0
  229. package/dist/render/plugin-list.js +30 -0
  230. package/dist/render/probe.d.ts +3 -0
  231. package/dist/render/probe.js +61 -0
  232. package/dist/render/problems.d.ts +35 -0
  233. package/dist/render/problems.js +64 -0
  234. package/dist/render/recovery.d.ts +2 -0
  235. package/dist/render/recovery.js +36 -0
  236. package/dist/render/reset-storage.d.ts +4 -0
  237. package/dist/render/reset-storage.js +70 -0
  238. package/dist/render/site-status.d.ts +2 -0
  239. package/dist/render/site-status.js +81 -0
  240. package/dist/render/source-list.d.ts +2 -0
  241. package/dist/render/source-list.js +37 -0
  242. package/dist/render/sync.d.ts +5 -0
  243. package/dist/render/sync.js +66 -0
  244. package/dist/settings.d.ts +10 -0
  245. package/dist/settings.js +45 -0
  246. package/dist/site-entry-edit.d.ts +5 -0
  247. package/dist/site-entry-edit.js +44 -0
  248. package/dist/source-entry.d.ts +32 -0
  249. package/dist/source-entry.js +89 -0
  250. package/dist/version.d.ts +3 -0
  251. package/dist/version.js +10 -0
  252. package/package.json +108 -3
@@ -0,0 +1,51 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { CoreCommand } from '../../core-command.js';
3
+ import { longWriteReport } from '../../render/operation-result.js';
4
+ export default class CodeRelease extends CoreCommand {
5
+ static description = 'Make a prepared code release live code; pages stay as they are; refused when live is not the release you ' +
6
+ 'expected (core code.release)';
7
+ static examples = [
8
+ '<%= config.bin %> branch list # code ids per branch',
9
+ '<%= config.bin %> code release cd_… --expect sr_…',
10
+ '<%= config.bin %> code release cd_… --latest-live --rev <sha> --sequence <ci run id> --json',
11
+ ];
12
+ static args = { code: Args.string({ description: 'the prepared code release (cd_…)' }) };
13
+ static flags = {
14
+ ...CoreCommand.siteFlags,
15
+ ...CoreCommand.expectLiveFlags,
16
+ rev: Flags.string({
17
+ description: 'the commit the code was prepared from (full SHA), when it was prepared from several',
18
+ }),
19
+ sequence: Flags.integer({
20
+ min: 1,
21
+ description: 'deployment ordering, e.g. a CI run id: refused as superseded when live code was released with a higher one',
22
+ }),
23
+ ...CoreCommand.refreshWaitFlag,
24
+ ...CoreCommand.inputFlag,
25
+ };
26
+ async run() {
27
+ const { args, flags } = await this.parse(CodeRelease);
28
+ const input = await this.resolveInput(flags.input, async () => {
29
+ if (args.code == null)
30
+ this.error('Name the prepared code release (cd_…).', { exit: 2 });
31
+ const { site } = await this.siteInput(flags.site);
32
+ return {
33
+ site,
34
+ code: args.code,
35
+ expect: { live: await this.expectedLive(site, flags) },
36
+ ...(flags.rev === undefined ? {} : { sourceRevision: flags.rev }),
37
+ ...(flags.sequence === undefined ? {} : { sequence: flags.sequence }),
38
+ };
39
+ });
40
+ const operation = await this.follow(await this.core.code.release(input), {
41
+ wait: true,
42
+ waitTimeout: flags['wait-timeout'],
43
+ });
44
+ const report = longWriteReport(operation, `Released ${input.code} as live code`);
45
+ if (!this.jsonEnabled())
46
+ for (const line of report.lines)
47
+ this.log(line);
48
+ process.exitCode = report.exitCode;
49
+ return operation;
50
+ }
51
+ }
@@ -0,0 +1,17 @@
1
+ import { CoreCommand } from '../../core-command.js';
2
+ export default class CodeRollback extends CoreCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static args: {
6
+ to: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
7
+ };
8
+ static flags: {
9
+ input: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'wait-timeout': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ expect: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'latest-live': import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ site: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ };
16
+ run(): Promise<unknown>;
17
+ }
@@ -0,0 +1,38 @@
1
+ import { Args } from '@oclif/core';
2
+ import { CoreCommand } from '../../core-command.js';
3
+ import { longWriteReport } from '../../render/operation-result.js';
4
+ export default class CodeRollback extends CoreCommand {
5
+ static description = 'Make earlier live code live again; pages stay as they are; refused when live is not the release you expected ' +
6
+ '(core code.rollback)';
7
+ static examples = [
8
+ '<%= config.bin %> site status --json # earlier code ids are listed under history',
9
+ '<%= config.bin %> code rollback cd_… --expect sr_…',
10
+ '<%= config.bin %> code rollback cd_… --latest-live',
11
+ ];
12
+ static args = { to: Args.string({ description: 'the code release to go back to (cd_…)' }) };
13
+ static flags = {
14
+ ...CoreCommand.siteFlags,
15
+ ...CoreCommand.expectLiveFlags,
16
+ ...CoreCommand.refreshWaitFlag,
17
+ ...CoreCommand.inputFlag,
18
+ };
19
+ async run() {
20
+ const { args, flags } = await this.parse(CodeRollback);
21
+ const input = await this.resolveInput(flags.input, async () => {
22
+ if (args.to == null)
23
+ this.error('Name the code release to go back to (cd_…).', { exit: 2 });
24
+ const { site } = await this.siteInput(flags.site);
25
+ return { site, to: args.to, expect: { live: await this.expectedLive(site, flags) } };
26
+ });
27
+ const operation = await this.follow(await this.core.code.rollback(input), {
28
+ wait: true,
29
+ waitTimeout: flags['wait-timeout'],
30
+ });
31
+ const report = longWriteReport(operation, `Live code rolled back to ${input.to}`);
32
+ if (!this.jsonEnabled())
33
+ for (const line of report.lines)
34
+ this.log(line);
35
+ process.exitCode = report.exitCode;
36
+ return operation;
37
+ }
38
+ }
@@ -0,0 +1,19 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class Connect extends Command {
3
+ static summary: string;
4
+ static description: string;
5
+ static examples: string[];
6
+ static enableJsonFlag: boolean;
7
+ static flags: {
8
+ create: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ link: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ server: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ interactive: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ };
14
+ run(): Promise<unknown>;
15
+ private interactiveOf;
16
+ private refuseLinked;
17
+ private connect;
18
+ private originOf;
19
+ }
@@ -0,0 +1,100 @@
1
+ // `foliwake connect`: link this project folder to a site, new or existing, in one step. In a terminal it asks
2
+ // (server, sign-in when needed, then «create a new site or link an existing one?»); without one it takes
3
+ // --create <id> or --link <id>. It runs the same code as `site create` and `site link` (create-connect.ts).
4
+ import { execFileSync } from 'node:child_process';
5
+ import { Command, Flags } from '@oclif/core';
6
+ import { ServerAddressError, serverOrigin } from '../remote/servers.js';
7
+ import { COMMAND } from '../settings.js';
8
+ /** Whether the folder's Git repository has a commit (a new site gets its first code from it). */
9
+ function hasCommit(cwd) {
10
+ try {
11
+ execFileSync('git', ['rev-parse', '--verify', 'HEAD^{commit}'], { cwd, stdio: 'ignore' });
12
+ return true;
13
+ }
14
+ catch {
15
+ return false;
16
+ }
17
+ }
18
+ export default class Connect extends Command {
19
+ static summary = 'Link this project folder to a site on your Foliwake server: a new one or an existing one';
20
+ static description = `In a terminal: asks which server (signing in first when needed), then whether to create a new site ` +
21
+ `(as \`${COMMAND} site create\`, the folder name as its id) or link one you may develop (as ` +
22
+ `\`${COMMAND} site link\`). Without a terminal, or with --no-interactive: --create <id> or --link <id>. ` +
23
+ `A folder linked already is refused; --force replaces its link, \`${COMMAND} site unlink\` removes it.`;
24
+ static examples = [
25
+ '<%= config.bin %> connect',
26
+ '<%= config.bin %> connect --create mysite --server https://foliwake.example',
27
+ '<%= config.bin %> connect --link docs-en --json',
28
+ ];
29
+ static enableJsonFlag = true;
30
+ static flags = {
31
+ create: Flags.string({ exclusive: ['link'], description: 'create this new site and link the folder to it' }),
32
+ link: Flags.string({ exclusive: ['create'], description: 'link the folder to this existing site' }),
33
+ server: Flags.string({
34
+ description: 'the Foliwake server (origin or host; default: $FOLIWAKE_SERVER, else asked or the only one)',
35
+ }),
36
+ force: Flags.boolean({ description: 'replace the link of a folder that is linked already' }),
37
+ interactive: Flags.boolean({
38
+ allowNo: true,
39
+ description: 'ask for what the flags leave open (default: only when stdin and stdout are a terminal)',
40
+ }),
41
+ };
42
+ async run() {
43
+ const { flags } = await this.parse(Connect);
44
+ const cwd = process.cwd();
45
+ await this.refuseLinked(cwd, flags.force);
46
+ const interactive = this.interactiveOf(flags.interactive);
47
+ if (!interactive && flags.create === undefined && flags.link === undefined) {
48
+ this.error('Without a terminal, say what to do: --create <id> or --link <id>.', { exit: 2 });
49
+ }
50
+ const json = this.jsonEnabled();
51
+ let linked = null;
52
+ const exit = await this.connect(cwd, flags, interactive, json, (value) => (linked = value));
53
+ process.exitCode = exit ?? 1;
54
+ if (exit === null && !json)
55
+ this.log(`Not connected; run \`${COMMAND} connect\` again when you are ready.`);
56
+ return linked ?? { server: null, site: null, created: false };
57
+ }
58
+ interactiveOf(asked) {
59
+ const tty = process.stdin.isTTY === true && process.stdout.isTTY === true;
60
+ return (asked ?? tty) && !this.jsonEnabled() && tty;
61
+ }
62
+ async refuseLinked(cwd, force) {
63
+ const { describeLink, existingLink } = await import('../connect.js');
64
+ const link = await existingLink(cwd);
65
+ if (link === null || force)
66
+ return;
67
+ this.error(`This folder is linked to ${describeLink(link)} already (.foliwake/connection.json). Pass --force to ` +
68
+ `replace that link, or remove it first with \`${COMMAND} site unlink\`.`, { exit: 1 });
69
+ }
70
+ async connect(cwd, flags, interactive, json, onLinked) {
71
+ const { connectStep } = await import('../create-connect.js');
72
+ const { signInHere } = await import('../remote/sign-in-here.js');
73
+ const say = (text = '') => (json ? undefined : this.log(text));
74
+ const io = { out: say, err: (text = '') => this.logToStderr(text) };
75
+ const step = {
76
+ target: cwd,
77
+ siteId: flags.create ?? null,
78
+ committed: hasCommit(cwd),
79
+ interactive,
80
+ createSite: flags.create !== undefined,
81
+ linkSite: flags.link,
82
+ server: flags.server === undefined ? undefined : this.originOf(flags.server),
83
+ relink: flags.force,
84
+ prompts: { input: process.stdin, output: process.stdout },
85
+ signIn: signInHere,
86
+ onLinked,
87
+ };
88
+ return connectStep(step, io);
89
+ }
90
+ originOf(typed) {
91
+ try {
92
+ return serverOrigin(typed);
93
+ }
94
+ catch (error) {
95
+ if (error instanceof ServerAddressError)
96
+ this.error(error.message, { exit: 2 });
97
+ throw error;
98
+ }
99
+ }
100
+ }
@@ -0,0 +1,30 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class Create extends Command {
3
+ static summary: string;
4
+ static description: string;
5
+ static examples: string[];
6
+ static args: {
7
+ folder: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
8
+ };
9
+ static flags: {
10
+ template: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ site: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ react: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ storybook: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ install: import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
+ git: import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
+ overwrite: import("@oclif/core/interfaces").BooleanFlag<boolean>;
17
+ 'keep-existing': import("@oclif/core/interfaces").BooleanFlag<boolean>;
18
+ 'create-site': import("@oclif/core/interfaces").BooleanFlag<boolean>;
19
+ 'link-site': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
+ server: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
+ relink: import("@oclif/core/interfaces").BooleanFlag<boolean>;
22
+ connect: import("@oclif/core/interfaces").BooleanFlag<boolean>;
23
+ interactive: import("@oclif/core/interfaces").BooleanFlag<boolean>;
24
+ help: import("@oclif/core/interfaces").BooleanFlag<void>;
25
+ };
26
+ run(): Promise<void>;
27
+ private serverOf;
28
+ private createProject;
29
+ private connect;
30
+ }
@@ -0,0 +1,163 @@
1
+ // `foliwake create [<folder>]`: create-foliwake's new site frontend, then «Connect to a Foliwake server?»
2
+ // (`site create` or `site link` in the new folder). Reads no project configuration; only its last step reads
3
+ // this computer's sign-ins and may sign in, as `login` does.
4
+ import { Args, Command, Flags } from '@oclif/core';
5
+ export default class Create extends Command {
6
+ static summary = 'Create a new site frontend: blocks, styles, local pages, checks and workflows';
7
+ static description = `Runs create-foliwake (\`npm create foliwake\`): asks in a terminal only for what the flags ` +
8
+ `leave open; without a terminal (or with --no-interactive) it uses the defaults: folder foliwake-site, template ` +
9
+ `minimal, no site id, no React, no Storybook, Git repository with a first commit.
10
+ The project is checked with @foliwake/site-check before anything is written.
11
+ A non-empty folder is refused unless you choose --overwrite or --keep-existing; .git is never touched.
12
+ At the end it can create or link the site on your Foliwake server (--create-site, --link-site, or a question).`;
13
+ static examples = [
14
+ '<%= config.bin %> create',
15
+ '<%= config.bin %> create my-site',
16
+ '<%= config.bin %> create my-site --template examples --site my-site --no-interactive',
17
+ '<%= config.bin %> create my-site --react --storybook',
18
+ '<%= config.bin %> create . --overwrite --no-git',
19
+ '<%= config.bin %> create mytest --no-interactive --server http://localhost:8080 --create-site',
20
+ ];
21
+ static args = {
22
+ folder: Args.string({
23
+ description: 'folder of the new project (default: foliwake-site); "." for the current folder',
24
+ }),
25
+ };
26
+ static flags = {
27
+ template: Flags.string({
28
+ options: ['minimal', 'examples'],
29
+ description: 'minimal: one page and one block (default); examples: two pages and three blocks, one with JavaScript',
30
+ }),
31
+ site: Flags.string({
32
+ description: 'the site id on your Foliwake server, if you know it (the README uses it); empty: none',
33
+ }),
34
+ react: Flags.boolean({
35
+ allowNo: true,
36
+ description: 'add React support: React and ReactDOM vendored in scripts/vendor/ and the React example block poll; ' +
37
+ 'default: asked in a terminal, else no',
38
+ }),
39
+ storybook: Flags.boolean({
40
+ allowNo: true,
41
+ description: 'add Storybook for the blocks: .storybook/ and npm scripts; default: asked in a terminal, else no',
42
+ }),
43
+ install: Flags.boolean({
44
+ allowNo: true,
45
+ description: "install Storybook's npm packages; default: asked in a terminal after Storybook, else no",
46
+ }),
47
+ git: Flags.boolean({
48
+ allowNo: true,
49
+ description: 'create a Git repository (branch main) and commit the project with your Git identity (default: yes); ' +
50
+ 'skipped inside an existing repository',
51
+ }),
52
+ overwrite: Flags.boolean({
53
+ exclusive: ['keep-existing'],
54
+ description: 'the folder is not empty: remove its files first (.git is kept)',
55
+ }),
56
+ 'keep-existing': Flags.boolean({
57
+ exclusive: ['overwrite'],
58
+ description: 'the folder is not empty: add the project next to its files (refused if one would be replaced)',
59
+ }),
60
+ 'create-site': Flags.boolean({
61
+ exclusive: ['link-site'],
62
+ description: 'at the end, create the site (id: --site, else the folder name) on your server, as `site create`',
63
+ }),
64
+ 'link-site': Flags.string({
65
+ exclusive: ['create-site'],
66
+ description: 'at the end, link the project to this existing site on your Foliwake server, as `site link`',
67
+ }),
68
+ server: Flags.string({
69
+ description: 'the Foliwake server to connect to (origin, host, or `cloud`; default: $FOLIWAKE_SERVER, else asked ' +
70
+ 'in a terminal; without one, the only server you are signed in to — several are refused)',
71
+ }),
72
+ relink: Flags.boolean({
73
+ description: 'with --create-site or --link-site in a folder already linked elsewhere: replace that link',
74
+ }),
75
+ connect: Flags.boolean({
76
+ allowNo: true,
77
+ description: '--no-connect: never ask «Connect to a Foliwake server?» (default: asked at the end in a terminal)',
78
+ }),
79
+ interactive: Flags.boolean({
80
+ allowNo: true,
81
+ description: 'ask for missing values (default: only when stdin and stdout are a terminal)',
82
+ }),
83
+ help: Flags.help({ char: 'h' }),
84
+ };
85
+ async run() {
86
+ const { args, flags } = await this.parse(Create);
87
+ const server = await this.serverOf(flags.server);
88
+ const linking = flags['create-site'] || flags['link-site'] !== undefined || server !== undefined;
89
+ if (flags.connect === false && linking) {
90
+ this.error('--no-connect conflicts with --create-site, --link-site and --server: choose one.', { exit: 2 });
91
+ }
92
+ const request = {
93
+ folder: args.folder,
94
+ template: flags.template,
95
+ site: flags.site,
96
+ git: flags.git,
97
+ storybook: flags.storybook,
98
+ install: flags.install,
99
+ react: flags.react,
100
+ existing: flags.overwrite ? 'clear' : flags['keep-existing'] ? 'keep' : undefined,
101
+ interactive: flags.interactive,
102
+ };
103
+ const result = await this.createProject(request);
104
+ if (!result.created || result.answers === null) {
105
+ process.exitCode = result.status;
106
+ return;
107
+ }
108
+ process.exitCode = await this.connect(result, flags, server);
109
+ }
110
+ async serverOf(typed) {
111
+ if (typed === undefined)
112
+ return undefined;
113
+ const { ServerAddressError, serverOrigin } = await import('../remote/servers.js');
114
+ try {
115
+ return serverOrigin(typed);
116
+ }
117
+ catch (error) {
118
+ if (error instanceof ServerAddressError)
119
+ this.error(error.message, { exit: 2 });
120
+ throw error;
121
+ }
122
+ }
123
+ async createProject(request) {
124
+ const { CreateUsageError, createProject, printResult } = await import('create-foliwake');
125
+ const io = { cwd: process.cwd(), stdin: process.stdin, stdout: process.stdout, stderr: process.stderr };
126
+ try {
127
+ const result = await createProject(request, { ...io, env: process.env });
128
+ printResult(result, io);
129
+ return result;
130
+ }
131
+ catch (error) {
132
+ if (error instanceof CreateUsageError)
133
+ this.error(error.message, { exit: 2 });
134
+ throw error;
135
+ }
136
+ }
137
+ async connect(result, flags, server) {
138
+ const { COMMAND } = await import('../settings.js');
139
+ const answers = result.answers;
140
+ const interactive = flags.interactive ?? (process.stdin.isTTY === true && process.stdout.isTTY === true);
141
+ const out = (stream) => (text = '') => void stream.write(`${text}\n`);
142
+ const io = { out: out(process.stdout), err: out(process.stderr) };
143
+ const connected = flags.connect === false
144
+ ? null
145
+ : await (await import('../create-connect.js')).connectStep({
146
+ target: answers.target,
147
+ siteId: answers.siteId,
148
+ committed: result.committed,
149
+ interactive,
150
+ createSite: flags['create-site'],
151
+ linkSite: flags['link-site'],
152
+ server,
153
+ relink: flags.relink,
154
+ prompts: { input: process.stdin, output: process.stdout },
155
+ signIn: (await import('../remote/sign-in-here.js')).signInHere,
156
+ }, io);
157
+ if (connected === null) {
158
+ io.out(`To publish it: sign in with \`${COMMAND} login\`, then run \`${COMMAND} site create <id>\` ` +
159
+ `(or \`${COMMAND} site link <id>\` for an existing site) in the folder.`);
160
+ }
161
+ return connected === null || connected === 0 ? result.status : connected;
162
+ }
163
+ }
@@ -0,0 +1,10 @@
1
+ import { CoreCommand } from '../../core-command.js';
2
+ export default class CredentialList extends CoreCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ site: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ };
9
+ run(): Promise<unknown>;
10
+ }
@@ -0,0 +1,21 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { CoreCommand } from '../../core-command.js';
3
+ import { credentialListLines } from '../../render/credentials.js';
4
+ export default class CredentialList extends CoreCommand {
5
+ static description = 'Credentials the content sources use: set or not, from the environment or stored; ' +
6
+ 'never the value (core credentials.list)';
7
+ static examples = ['<%= config.bin %> credential list', '<%= config.bin %> credential list --site my-site --json'];
8
+ static flags = {
9
+ ...CoreCommand.configFlag,
10
+ site: Flags.string({
11
+ description: "only the credentials this site's sources use (default: every site you administer)",
12
+ }),
13
+ };
14
+ async run() {
15
+ const { flags } = await this.parse(CredentialList);
16
+ const answer = await this.core.credentials.list(flags.site === undefined ? {} : { site: flags.site });
17
+ for (const line of credentialListLines(answer))
18
+ this.log(line);
19
+ return answer;
20
+ }
21
+ }
@@ -0,0 +1,12 @@
1
+ import { CoreCommand } from '../../core-command.js';
2
+ export default class CredentialRm extends CoreCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static args: {
6
+ name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
7
+ };
8
+ static flags: {
9
+ config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ };
11
+ run(): Promise<unknown>;
12
+ }
@@ -0,0 +1,18 @@
1
+ import { Args } from '@oclif/core';
2
+ import { CoreCommand } from '../../core-command.js';
3
+ import { credentialRemoveLines } from '../../render/credentials.js';
4
+ export default class CredentialRm extends CoreCommand {
5
+ static description = "Removes a stored credential (the installation's owner); refused while a source uses it (core credentials.remove)";
6
+ static examples = ['<%= config.bin %> credential rm OLD_DRIVE_KEY'];
7
+ static args = {
8
+ name: Args.string({ description: 'the credential name, such as FOLIWAKE_GOOGLE_SA_KEY', required: true }),
9
+ };
10
+ static flags = { ...CoreCommand.configFlag };
11
+ async run() {
12
+ const { args } = await this.parse(CredentialRm);
13
+ const answer = await this.core.credentials.remove({ name: args.name });
14
+ for (const line of credentialRemoveLines(answer))
15
+ this.log(line);
16
+ return answer;
17
+ }
18
+ }
@@ -0,0 +1,15 @@
1
+ import { CoreCommand } from '../../core-command.js';
2
+ export default class CredentialSet extends CoreCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static args: {
6
+ name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
7
+ };
8
+ static flags: {
9
+ 'from-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'from-stdin': import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
+ config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ };
13
+ run(): Promise<unknown>;
14
+ private valueOf;
15
+ }
@@ -0,0 +1,58 @@
1
+ import { readFile, stat } from 'node:fs/promises';
2
+ import { Args, Errors, Flags } from '@oclif/core';
3
+ import { MAX_CREDENTIAL_BYTES } from '../../lib/rules.js';
4
+ import { CoreCommand } from '../../core-command.js';
5
+ import { credentialSetLines } from '../../render/credentials.js';
6
+ /** One trailing line break of a file or a pipe is not part of a token. */
7
+ const withoutFinalNewline = (text) => text.replace(/\r?\n$/, '');
8
+ async function readStdin() {
9
+ const chunks = [];
10
+ let size = 0;
11
+ for await (const chunk of process.stdin) {
12
+ size += chunk.length;
13
+ if (size > MAX_CREDENTIAL_BYTES)
14
+ throw new Errors.CLIError('The value is larger than 64 KiB.');
15
+ chunks.push(chunk);
16
+ }
17
+ return Buffer.concat(chunks).toString('utf8');
18
+ }
19
+ async function readValueFile(file) {
20
+ if ((await stat(file)).size > MAX_CREDENTIAL_BYTES)
21
+ throw new Errors.CLIError('The file is larger than 64 KiB.');
22
+ return readFile(file, 'utf8');
23
+ }
24
+ export default class CredentialSet extends CoreCommand {
25
+ static description = "Stores a credential value on the server (the installation's owner): a source names it in `credentials`; " +
26
+ 'the next sync uses it without a restart. The value is read from a file or stdin, never from the command line ' +
27
+ '(core credentials.set)';
28
+ static examples = [
29
+ '<%= config.bin %> credential set FOLIWAKE_GOOGLE_SA_KEY --from-file key.json',
30
+ 'printf %s "$TOKEN" | <%= config.bin %> credential set FOLIWAKE_GIT_TOKEN_DOCS --from-stdin',
31
+ ];
32
+ static args = {
33
+ name: Args.string({ description: 'the name a source refers to, such as FOLIWAKE_GOOGLE_SA_KEY', required: true }),
34
+ };
35
+ static flags = {
36
+ ...CoreCommand.configFlag,
37
+ 'from-file': Flags.string({
38
+ description: 'read the value from this file (a Google service-account JSON key is checked)',
39
+ exclusive: ['from-stdin'],
40
+ }),
41
+ 'from-stdin': Flags.boolean({ description: 'read the value from standard input', exclusive: ['from-file'] }),
42
+ };
43
+ async run() {
44
+ const { args, flags } = await this.parse(CredentialSet);
45
+ const value = await this.valueOf(flags);
46
+ const answer = await this.core.credentials.set({ name: args.name, value });
47
+ for (const line of credentialSetLines(answer))
48
+ this.log(line);
49
+ return answer;
50
+ }
51
+ async valueOf(flags) {
52
+ if (flags['from-file'] !== undefined)
53
+ return withoutFinalNewline(await readValueFile(flags['from-file']));
54
+ if (flags['from-stdin'])
55
+ return withoutFinalNewline(await readStdin());
56
+ throw new Errors.CLIError('Give the value with --from-file <file> or --from-stdin; it is never a command-line argument.', { exit: 2 });
57
+ }
58
+ }
@@ -0,0 +1,25 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class Dev extends Command {
3
+ static summary: string;
4
+ static description: string;
5
+ static examples: string[];
6
+ static flags: {
7
+ port: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ watch: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
+ 'watch-polling': import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
+ remote: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'remote-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'remote-auth-env': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ 'remote-auth-user': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ 'remote-config': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ };
16
+ run(): Promise<void>;
17
+ /** Set by stopOnSignal(): settles when a signal has stopped the server. */
18
+ private stopped;
19
+ /** On Ctrl+C or SIGTERM: closes the listeners, waits for the work that runs, exits. */
20
+ private stopOnSignal;
21
+ protected _run<T>(): Promise<T>;
22
+ protected catch(error: Error & {
23
+ exitCode?: number;
24
+ }): Promise<unknown>;
25
+ }