create-foliwake 0.0.0-stage → 0.4.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 (68) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/LICENSE +202 -0
  3. package/README.md +64 -2
  4. package/dist/bin.d.ts +2 -0
  5. package/dist/bin.js +16 -0
  6. package/dist/cli.d.ts +8 -0
  7. package/dist/cli.js +88 -0
  8. package/dist/create.d.ts +50 -0
  9. package/dist/create.js +250 -0
  10. package/dist/destination.d.ts +47 -0
  11. package/dist/destination.js +243 -0
  12. package/dist/editor-files.d.ts +6 -0
  13. package/dist/editor-files.js +39 -0
  14. package/dist/files.d.ts +26 -0
  15. package/dist/files.js +94 -0
  16. package/dist/git.d.ts +22 -0
  17. package/dist/git.js +64 -0
  18. package/dist/index.d.ts +5 -0
  19. package/dist/index.js +7 -0
  20. package/dist/install.d.ts +12 -0
  21. package/dist/install.js +18 -0
  22. package/dist/options.d.ts +48 -0
  23. package/dist/options.js +54 -0
  24. package/dist/prompts.d.ts +16 -0
  25. package/dist/prompts.js +67 -0
  26. package/dist/starters.d.ts +20 -0
  27. package/dist/starters.js +61 -0
  28. package/dist/validate.d.ts +3 -0
  29. package/dist/validate.js +12 -0
  30. package/package.json +64 -3
  31. package/starters/examples/components/quiz/quiz.css +33 -0
  32. package/starters/examples/components/quiz/quiz.example.md +29 -0
  33. package/starters/examples/components/quiz/quiz.js +36 -0
  34. package/starters/examples/components/quiz/quiz.json +14 -0
  35. package/starters/examples/components/steps/steps.css +38 -0
  36. package/starters/examples/components/steps/steps.example.md +25 -0
  37. package/starters/examples/components/steps/steps.json +8 -0
  38. package/starters/examples/content/blocks.md +49 -0
  39. package/starters/examples/content/index.md +44 -0
  40. package/starters/minimal/components/note/note.css +15 -0
  41. package/starters/minimal/components/note/note.example.md +23 -0
  42. package/starters/minimal/components/note/note.json +8 -0
  43. package/starters/minimal/content/images/foliwake-logo.png +0 -0
  44. package/starters/minimal/content/index.md +32 -0
  45. package/starters/react/components/poll/poll.css +32 -0
  46. package/starters/react/components/poll/poll.example.md +26 -0
  47. package/starters/react/components/poll/poll.js +35 -0
  48. package/starters/react/components/poll/poll.json +13 -0
  49. package/starters/react/scripts/react-view.js +22 -0
  50. package/starters/shared/README.md +104 -0
  51. package/starters/shared/_github/actions/foliwake-request/action.yml +45 -0
  52. package/starters/shared/_github/scripts/foliwake-report.py +68 -0
  53. package/starters/shared/_github/workflows/branch-preview.yml +104 -0
  54. package/starters/shared/_github/workflows/frontend-checks.yml +28 -0
  55. package/starters/shared/_github/workflows/production.yml +134 -0
  56. package/starters/shared/_gitignore +8 -0
  57. package/starters/shared/jsconfig.json +15 -0
  58. package/starters/shared/scripts/components.js +284 -0
  59. package/starters/shared/site.yaml +2 -0
  60. package/starters/shared/styles/styles.css +106 -0
  61. package/starters/shared/tests/site.test.mjs +21 -0
  62. package/starters/shared/tests/workflows.test.mjs +84 -0
  63. package/starters/storybook/_storybook/main.js +49 -0
  64. package/starters/storybook/_storybook/preview.js +7 -0
  65. package/starters/storybook/_storybook/run.mjs +25 -0
  66. package/starters/storybook/pnpm-workspace.yaml +8 -0
  67. package/vendor/react.LICENSE.txt +21 -0
  68. package/vendor/react.js +32 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,85 @@
1
+ # Changelog: create-foliwake
2
+
3
+ `create-foliwake` shares one version with the `@foliwake/*` packages of this repository and is released together
4
+ with them. While the version is 0.x, a minor release may break; breaking changes are marked **BREAKING**.
5
+
6
+ Entries are written from the changesets of each pull request (`.changeset/`, CONTRIBUTING.md), newest first.
7
+
8
+ ## 0.4.0
9
+
10
+ ### Minor Changes
11
+
12
+ - 70af3e5: **BREAKING**: the old forms are removed; only the current ones remain.
13
+
14
+ - The kit's only specifier is `@foliwake/block-kit`. The import map of a code release no longer maps
15
+ `foliwake`; `LEGACY_KIT_SPECIFIER` and `KIT_SPECIFIERS` are removed from `@foliwake/blocks-contract/import-map`
16
+ (use `KIT_SPECIFIER`). `@foliwake/site-check` refuses a bare `foliwake` import, preload hints follow only
17
+ `@foliwake/block-kit`, and new projects map only `@foliwake/block-kit` (jsconfig, Storybook).
18
+ - `@foliwake/block-kit/block-kit-1.js` (the kit of blocks contract 1) is removed, with its `exports` entry;
19
+ `@foliwake/site-check` no longer treats `_foliwake/block-kit-1.js` as an engine file, and the Storybook
20
+ starter no longer aliases relative `_foliwake/` imports.
21
+ - An origin answer without `X-Code-Release` is an error (`FoliwakePageError` `invalid`), not a body shown
22
+ without blocks. `codeRelease` of `PageEnvelope` and `FoliwakePageData` is `CodeReleaseId` (never null),
23
+ and the client error code `NO_CODE_RELEASE` is removed.
24
+ - A `foliwake.remote.json` with any `version` other than 2 is refused with one "unsupported version" error.
25
+
26
+ Added (not breaking): `defineBlock(name, setup, { autoReady: false })` in `@foliwake/block-kit`. The kit then
27
+ sends `ready` only when the block sends it (`ctx.emit('ready', …)`), so a setup that cannot run leaves the root
28
+ without `ready`. The default (`autoReady: true`) is unchanged: after a setup that did not send `ready`, the kit
29
+ sends it.
30
+
31
+ ### Patch Changes
32
+
33
+ - 1cc3743: Documentation: the READMEs name the kit's specifier `@foliwake/block-kit` everywhere, link to sibling
34
+ packages instead of guides that are not public, and say which features need the Foliwake CLI, which is not
35
+ public yet. The `@foliwake/next` README shows how to write the cached read yourself. The starters' loader comment names HTML contract 2. No API change.
36
+ - Updated dependencies [2b0bb9f]
37
+ - Updated dependencies [1cc3743]
38
+ - Updated dependencies [70af3e5]
39
+ - @foliwake/block-kit@0.4.0
40
+ - @foliwake/site-check@0.4.0
41
+
42
+ ## 0.3.0
43
+
44
+ ### Minor Changes
45
+
46
+ - The kit's specifier is `@foliwake/block-kit`, the npm name of the kit (`KIT_SPECIFIER`); the import map of a code
47
+ release maps it and, for one more minor version, the previous `foliwake` (`LEGACY_KIT_SPECIFIER`, deprecated) to
48
+ the release's kit. `@foliwake/client` adds that map, `@foliwake/server` follows both specifiers in preload hints,
49
+ `@foliwake/site-check` accepts both in the reference scan, and the starters of `create-foliwake` import
50
+ `@foliwake/block-kit`.
51
+
52
+ A block may declare the major of the blocks contract it speaks: `BlockInit` has an optional `contract`, the block
53
+ kit's `defineBlock` sets `init.contract = 2`, and the starters' loader refuses another major
54
+ (`LOADER_BLOCK_CONTRACT`); a block that declares none is accepted. The loader always passes `host` (required in
55
+ the contract's `BlockInit`); the kit's init takes `host?` with the browser's fallbacks.
56
+
57
+ The kit's types of `ctx.mount` are `ViewAdapter`, `ViewHandle` and `ViewOptions`, so the contract's `MountHandle`
58
+ is re-exported under its own name. Reserved (not implemented): `shell: 'web-component'` (`KnownShell`), the
59
+ context key `'foliwake:host'`, and the loader's attributes as values (`@foliwake/blocks-contract/reserved`:
60
+ `BLOCK_ATTRIBUTES`, `KNOWN_SHELLS`, `HOST_CONTEXT_KEY`).
61
+ - b0c16ac: New package `create-foliwake`: `npm create foliwake@latest` (also `npx`, `pnpm`, `yarn` and `bun create`). The
62
+ create command of the Foliwake CLI without its server step: the starters (inside the package), questions, flags
63
+ and write guarantees, plus `--install` for Storybook's packages (the only network step). The planned project is
64
+ checked with `@foliwake/site-check` before anything is written; its "Frontend checks" workflow runs
65
+ `npx -y @foliwake/site-check@<version> . --format github`. React for the starters is vendored when the package is
66
+ built. The project gets the types of `foliwake` for editors (`.foliwake/types/foliwake.d.ts`, from
67
+ `@foliwake/block-kit`) and the JSON Schema of block definitions, both git-ignored. `createProject()` and
68
+ `create-foliwake/starters` for the Foliwake CLI's `foliwake create`.
69
+ `@foliwake/site-check`: license and notice files next to code (`scripts/vendor/react.LICENSE.txt`) are neither
70
+ captured nor noted.
71
+
72
+ ### Patch Changes
73
+
74
+ - Updated dependencies [b0c16ac]
75
+ - Updated dependencies
76
+ - Updated dependencies [b0c16ac]
77
+ - Updated dependencies [b0c16ac]
78
+ - Updated dependencies [b0c16ac]
79
+ - Updated dependencies [b0c16ac]
80
+ - @foliwake/block-kit@0.3.0
81
+ - @foliwake/site-check@0.3.0
82
+
83
+ ## 0.2.0 and earlier (never published on npm)
84
+
85
+ The package did not exist yet; it is first released with the shared version after 0.2.0.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,65 @@
1
- # Temporary Holding Version
1
+ # create-foliwake
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <!-- usage -->
4
+
5
+ Creates the code repository of a Foliwake site: blocks, styles, a few local sample pages, quick tests and the
6
+ GitHub workflows that connect it to the platform.
7
+
8
+ ```sh
9
+ npm create foliwake@latest my-site
10
+ npx create-foliwake@latest my-site
11
+ pnpm create foliwake my-site
12
+ yarn create foliwake my-site
13
+ bun create foliwake my-site
14
+ ```
15
+
16
+ In a terminal it asks for what the options leave open (folder, template, React, Storybook, whether to install
17
+ Storybook's packages, Git). Without a terminal, or with `--no-interactive`, it uses the defaults: folder
18
+ `foliwake-site`, template `minimal`, no React, no Storybook, a Git repository with a first commit.
19
+
20
+ | Option | What |
21
+ | --- | --- |
22
+ | `[folder]` | the new project's folder (default `foliwake-site`; `.` for the current folder) |
23
+ | `--template minimal\|examples` | `minimal`: one page, one block; `examples`: two pages, three blocks, one with JavaScript |
24
+ | `--site <id>` | the site id on your Foliwake server, if you know it (used in the README and local configuration) |
25
+ | `--react` / `--no-react` | React and ReactDOM vendored in `scripts/vendor/` (shipped with this package; nothing is downloaded) and a React example block |
26
+ | `--storybook` / `--no-storybook` | Storybook for the blocks; `npm run stories` needs the Foliwake CLI, which is not public yet |
27
+ | `--install` / `--no-install` | install the npm packages (only Storybook has any) with the package manager that ran create |
28
+ | `--git` / `--no-git` | a Git repository (branch `main`) and a first commit with your own Git identity |
29
+ | `--overwrite` \| `--keep-existing` | the folder is not empty: remove its files (`.git` is kept), or add the project next to them |
30
+ | `--interactive` / `--no-interactive` | ask for missing values (default: only in a terminal) |
31
+
32
+ Exit status: `0` created; `1` a step failed (the project stays; what to do is printed); `2` refused input
33
+ (nothing written); `130` cancelled (nothing written).
34
+
35
+ ## What it guarantees
36
+
37
+ - Nothing is written before every check passed: the planned files are checked with
38
+ [`@foliwake/site-check`](https://www.npmjs.com/package/@foliwake/site-check), the checks the platform runs, and
39
+ must be clean (no errors, warnings or notes).
40
+ - The files are written as one transaction: on a failure nothing of the run stays, and `--overwrite` puts the
41
+ original files back. Nothing is written through a symbolic link, Git metadata is never a destination, and a
42
+ folder holding other repositories is never cleared.
43
+ - No network: the starters, React and the checker come with the package. The only download is installing
44
+ Storybook's packages, and only when you ask for it.
45
+ - The first commit stages only the project's files and uses your Git identity; inside an existing repository
46
+ no repository is created.
47
+
48
+ ## The project
49
+
50
+ Without anything installed: `npx @foliwake/site-check` checks the code (the "Frontend checks" workflow runs it,
51
+ pinned to the version this package was released with), and `node --test "tests/*.test.mjs"` runs the quick
52
+ tests. Push the repository to GitHub and connect it to your site in the Foliwake admin: every branch gets a
53
+ preview. For editors, create writes the types of `@foliwake/block-kit` and the JSON Schema of block definitions
54
+ into `.foliwake/` (git-ignored). The project's `README.md` has the details.
55
+
56
+ The Foliwake CLI is not public yet. Without it you do not get a local preview (`foliwake dev`), the local block
57
+ catalog (`/_dev/blocks`), `npm run stories` (Storybook renders the block examples with the CLI), the page checks
58
+ (`foliwake page check`) or the types of each block's own fields (`.foliwake/types/blocks/`). The branch preview
59
+ on the platform shows pages and block examples instead.
60
+
61
+ ## API
62
+
63
+ `createProject(request, io)` is the same run without printing, for a wrapper that adds its own steps (the
64
+ Foliwake CLI's `foliwake create`); `printResult` and `nextSteps` print its result. `create-foliwake/starters`
65
+ gives the starter files (`starterFile(layer, path)`, `layerFiles`, `vendoredReact`).
package/dist/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/bin.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ // The `create-foliwake` command: runCli (cli.ts) on the process's arguments, streams and environment.
3
+ import { runCli } from './cli.js';
4
+ const io = {
5
+ cwd: process.cwd(),
6
+ stdin: process.stdin,
7
+ stdout: process.stdout,
8
+ stderr: process.stderr,
9
+ env: process.env,
10
+ };
11
+ runCli(process.argv.slice(2), io).then((status) => {
12
+ process.exitCode = status;
13
+ }, (error) => {
14
+ process.stderr.write(`create-foliwake: ${error instanceof Error ? (error.stack ?? error.message) : error}\n`);
15
+ process.exitCode = 1;
16
+ });
package/dist/cli.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { type CreateIO } from './create.js';
2
+ import { type CreateRequest } from './options.js';
3
+ export declare const EXIT_USAGE = 2;
4
+ export declare const USAGE = "Usage: create-foliwake [folder] [options]\n\nCreates a Foliwake site frontend: blocks, styles, local sample pages, checks and GitHub workflows.\nIn a terminal it asks for what the options leave open; otherwise (or with --no-interactive) it uses the\ndefaults: folder foliwake-site, template minimal, no React, no Storybook, a Git repository with a first commit.\n\n --template minimal|examples minimal: one page and one block; examples: two pages and three blocks\n --site <id> the site id on your Foliwake server, if you know it\n --react / --no-react React and ReactDOM vendored in scripts/vendor/ and a React example block\n --storybook / --no-storybook Storybook for the blocks (`npm run stories` needs the Foliwake CLI)\n --install / --no-install install Storybook's npm packages with the package manager that ran create\n --git / --no-git a Git repository (branch main) and the first commit with your Git identity\n --overwrite | --keep-existing a non-empty folder: remove its files (.git is kept) | add the project next to them\n --interactive / --no-interactive ask for missing values (default: only in a terminal)\n -h, --help, --version";
5
+ /** The request the command line makes (undefined: not given). */
6
+ export declare function requestOf(args: readonly string[]): CreateRequest | 'help' | 'version';
7
+ /** Runs the command; resolves to the exit status. */
8
+ export declare function runCli(args: readonly string[], io: CreateIO): Promise<number>;
package/dist/cli.js ADDED
@@ -0,0 +1,88 @@
1
+ // The command line of create-foliwake: `npm create foliwake@latest [folder] [flags]` (also npx create-foliwake,
2
+ // pnpm create foliwake, yarn create foliwake, bun create foliwake). Exit status: 0 created; 1 a failed step;
3
+ // 2 refused input; 130 cancelled.
4
+ import { parseArgs } from 'node:util';
5
+ import { runCreate } from './create.js';
6
+ import { CreateUsageError, TEMPLATES } from './options.js';
7
+ import { packageVersion } from './starters.js';
8
+ export const EXIT_USAGE = 2;
9
+ export const USAGE = `Usage: create-foliwake [folder] [options]
10
+
11
+ Creates a Foliwake site frontend: blocks, styles, local sample pages, checks and GitHub workflows.
12
+ In a terminal it asks for what the options leave open; otherwise (or with --no-interactive) it uses the
13
+ defaults: folder foliwake-site, template minimal, no React, no Storybook, a Git repository with a first commit.
14
+
15
+ --template minimal|examples minimal: one page and one block; examples: two pages and three blocks
16
+ --site <id> the site id on your Foliwake server, if you know it
17
+ --react / --no-react React and ReactDOM vendored in scripts/vendor/ and a React example block
18
+ --storybook / --no-storybook Storybook for the blocks (\`npm run stories\` needs the Foliwake CLI)
19
+ --install / --no-install install Storybook's npm packages with the package manager that ran create
20
+ --git / --no-git a Git repository (branch main) and the first commit with your Git identity
21
+ --overwrite | --keep-existing a non-empty folder: remove its files (.git is kept) | add the project next to them
22
+ --interactive / --no-interactive ask for missing values (default: only in a terminal)
23
+ -h, --help, --version`;
24
+ const OPTIONS = {
25
+ template: { type: 'string' },
26
+ site: { type: 'string' },
27
+ react: { type: 'boolean' },
28
+ storybook: { type: 'boolean' },
29
+ install: { type: 'boolean' },
30
+ git: { type: 'boolean' },
31
+ overwrite: { type: 'boolean' },
32
+ 'keep-existing': { type: 'boolean' },
33
+ interactive: { type: 'boolean' },
34
+ help: { type: 'boolean', short: 'h' },
35
+ version: { type: 'boolean' },
36
+ };
37
+ function parse(args) {
38
+ try {
39
+ return parseArgs({ args: [...args], options: OPTIONS, allowPositionals: true, allowNegative: true, strict: true });
40
+ }
41
+ catch (error) {
42
+ throw new CreateUsageError(error.message);
43
+ }
44
+ }
45
+ /** The request the command line makes (undefined: not given). */
46
+ export function requestOf(args) {
47
+ const { values, positionals } = parse(args);
48
+ if (values.help)
49
+ return 'help';
50
+ if (values.version)
51
+ return 'version';
52
+ if (positionals.length > 1)
53
+ throw new CreateUsageError(`one folder only, got ${positionals.join(', ')}`);
54
+ if (values.overwrite && values['keep-existing'])
55
+ throw new CreateUsageError('--overwrite and --keep-existing: choose one.');
56
+ const template = values.template;
57
+ if (template !== undefined && !TEMPLATES.includes(template)) {
58
+ throw new CreateUsageError(`Unknown template "${template}": use ${TEMPLATES.join(' or ')}.`);
59
+ }
60
+ return {
61
+ folder: positionals[0],
62
+ template: template,
63
+ site: values.site,
64
+ react: values.react,
65
+ storybook: values.storybook,
66
+ install: values.install,
67
+ git: values.git,
68
+ existing: values.overwrite ? 'clear' : values['keep-existing'] ? 'keep' : undefined,
69
+ interactive: values.interactive,
70
+ };
71
+ }
72
+ /** Runs the command; resolves to the exit status. */
73
+ export async function runCli(args, io) {
74
+ try {
75
+ const request = requestOf(args);
76
+ if (request === 'help' || request === 'version') {
77
+ io.stdout.write(`${request === 'help' ? USAGE : await packageVersion()}\n`);
78
+ return 0;
79
+ }
80
+ return await runCreate(request, io);
81
+ }
82
+ catch (error) {
83
+ if (!(error instanceof CreateUsageError))
84
+ throw error;
85
+ io.stderr.write(`create-foliwake: ${error.message}\n`);
86
+ return EXIT_USAGE;
87
+ }
88
+ }
@@ -0,0 +1,50 @@
1
+ import type { Readable, Writable } from 'node:stream';
2
+ import { type CreateAnswers, type CreateRequest } from './options.js';
3
+ import { type PromptStreams } from './prompts.js';
4
+ export declare const EXIT_CANCELLED = 130;
5
+ export interface CreateIO {
6
+ cwd: string;
7
+ stdin: Readable & {
8
+ isTTY?: boolean;
9
+ };
10
+ stdout: Writable & {
11
+ isTTY?: boolean;
12
+ };
13
+ stderr: Writable;
14
+ env: NodeJS.ProcessEnv;
15
+ /** Prompt streams (default stdin/stdout); tests supply their own. */
16
+ prompts?: PromptStreams;
17
+ }
18
+ /** What a run did: enough for the report, and for a wrapper (the Foliwake CLI) to add its own steps. */
19
+ export interface CreateResult {
20
+ /** 0 created; 1 created with a failed step, or refused by its own check (nothing written); 130 cancelled */
21
+ status: number;
22
+ /** false when nothing was written (cancelled, or the starters failed their check) */
23
+ created: boolean;
24
+ answers: (CreateAnswers & {
25
+ target: string;
26
+ }) | null;
27
+ /** the folder as the user should type it (`cd …`) */
28
+ shown: string;
29
+ /** the project's files (project paths) */
30
+ files: string[];
31
+ /** true when this run made the repository and its first commit */
32
+ committed: boolean;
33
+ /** the report: what was checked and created, the Git result, notes */
34
+ report: string[];
35
+ /** what to do by hand after a failed or skipped Git step (stderr) */
36
+ help: string | null;
37
+ }
38
+ /** A path as a shell word (quoted only when needed). */
39
+ export declare function shellWord(value: string): string;
40
+ /**
41
+ * Creates the project; resolves to what it did (create-foliwake prints it with printResult, a wrapper may add
42
+ * its own steps first). Throws CreateUsageError for refused input (nothing was written).
43
+ */
44
+ export declare function createProject(request: CreateRequest, io: CreateIO): Promise<CreateResult>;
45
+ /** The «Next» steps after a project is created. */
46
+ export declare function nextSteps(result: CreateResult): string[];
47
+ /** Prints the report (and the Next steps of a created project). */
48
+ export declare function printResult(result: CreateResult, io: Pick<CreateIO, 'stdout' | 'stderr'>): void;
49
+ /** Runs create-foliwake; resolves to the exit status. Throws CreateUsageError for refused input. */
50
+ export declare function runCreate(request: CreateRequest, io: CreateIO): Promise<number>;