@emulsify/cli 2.1.1 → 2.2.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 (80) hide show
  1. package/README.md +43 -264
  2. package/dist/handlers/init.js +13 -5
  3. package/dist/handlers/systemInstall.js +77 -4
  4. package/dist/index.js +99 -21
  5. package/dist/node_modules/.package-lock.json +11 -11
  6. package/dist/node_modules/@types/node/README.md +1 -1
  7. package/dist/node_modules/@types/node/assert/strict.d.ts +10 -1
  8. package/dist/node_modules/@types/node/assert.d.ts +144 -17
  9. package/dist/node_modules/@types/node/async_hooks.d.ts +9 -9
  10. package/dist/node_modules/@types/node/buffer.d.ts +0 -5
  11. package/dist/node_modules/@types/node/child_process.d.ts +17 -21
  12. package/dist/node_modules/@types/node/cluster.d.ts +13 -13
  13. package/dist/node_modules/@types/node/console.d.ts +1 -1
  14. package/dist/node_modules/@types/node/crypto.d.ts +454 -571
  15. package/dist/node_modules/@types/node/diagnostics_channel.d.ts +20 -9
  16. package/dist/node_modules/@types/node/dns.d.ts +14 -14
  17. package/dist/node_modules/@types/node/events.d.ts +3 -3
  18. package/dist/node_modules/@types/node/fs/promises.d.ts +4 -4
  19. package/dist/node_modules/@types/node/fs.d.ts +3 -12
  20. package/dist/node_modules/@types/node/globals.d.ts +4 -4
  21. package/dist/node_modules/@types/node/http.d.ts +5 -5
  22. package/dist/node_modules/@types/node/http2.d.ts +1 -1
  23. package/dist/node_modules/@types/node/index.d.ts +0 -3
  24. package/dist/node_modules/@types/node/inspector.d.ts +1 -1
  25. package/dist/node_modules/@types/node/module.d.ts +16 -45
  26. package/dist/node_modules/@types/node/net.d.ts +1 -1
  27. package/dist/node_modules/@types/node/os.d.ts +2 -2
  28. package/dist/node_modules/@types/node/package.json +4 -4
  29. package/dist/node_modules/@types/node/perf_hooks.d.ts +1 -9
  30. package/dist/node_modules/@types/node/process.d.ts +11 -11
  31. package/dist/node_modules/@types/node/readline.d.ts +12 -11
  32. package/dist/node_modules/@types/node/repl.d.ts +10 -10
  33. package/dist/node_modules/@types/node/sqlite.d.ts +1 -1
  34. package/dist/node_modules/@types/node/stream/promises.d.ts +2 -2
  35. package/dist/node_modules/@types/node/stream/web.d.ts +1 -1
  36. package/dist/node_modules/@types/node/stream.d.ts +5 -5
  37. package/dist/node_modules/@types/node/test/reporters.d.ts +1 -1
  38. package/dist/node_modules/@types/node/test.d.ts +8 -8
  39. package/dist/node_modules/@types/node/tls.d.ts +1 -1
  40. package/dist/node_modules/@types/node/ts5.6/index.d.ts +1 -4
  41. package/dist/node_modules/@types/node/ts5.7/index.d.ts +0 -3
  42. package/dist/node_modules/@types/node/url.d.ts +3 -3
  43. package/dist/node_modules/@types/node/util/types.d.ts +1 -1
  44. package/dist/node_modules/@types/node/util.d.ts +3 -20
  45. package/dist/node_modules/@types/node/v8.d.ts +1 -1
  46. package/dist/node_modules/@types/node/vm.d.ts +9 -9
  47. package/dist/node_modules/@types/node/web-globals/domexception.d.ts +15 -0
  48. package/dist/node_modules/@types/node/worker_threads.d.ts +2 -5
  49. package/dist/node_modules/@types/node/zlib.d.ts +3 -3
  50. package/dist/node_modules/chardet/README.md +15 -1
  51. package/dist/node_modules/chardet/lib/encoding/sbcs.d.ts +19 -0
  52. package/dist/node_modules/chardet/lib/encoding/sbcs.js +172 -1
  53. package/dist/node_modules/chardet/lib/encoding/sbcs.js.map +1 -1
  54. package/dist/node_modules/chardet/lib/index.js +3 -0
  55. package/dist/node_modules/chardet/lib/index.js.map +1 -1
  56. package/dist/node_modules/chardet/lib/match.d.ts +1 -1
  57. package/dist/node_modules/chardet/lib/match.js.map +1 -1
  58. package/dist/node_modules/chardet/package.json +14 -10
  59. package/dist/node_modules/undici-types/agent.d.ts +0 -2
  60. package/dist/node_modules/undici-types/client.d.ts +25 -19
  61. package/dist/node_modules/undici-types/dispatcher.d.ts +7 -33
  62. package/dist/node_modules/undici-types/dispatcher1-wrapper.d.ts +7 -0
  63. package/dist/node_modules/undici-types/fetch.d.ts +24 -4
  64. package/dist/node_modules/undici-types/h2c-client.d.ts +6 -6
  65. package/dist/node_modules/undici-types/handlers.d.ts +1 -2
  66. package/dist/node_modules/undici-types/header.d.ts +5 -0
  67. package/dist/node_modules/undici-types/index.d.ts +3 -1
  68. package/dist/node_modules/undici-types/interceptors.d.ts +1 -1
  69. package/dist/node_modules/undici-types/package.json +1 -1
  70. package/dist/node_modules/undici-types/pool.d.ts +0 -2
  71. package/dist/node_modules/undici-types/proxy-agent.d.ts +2 -2
  72. package/dist/node_modules/undici-types/round-robin-pool.d.ts +0 -2
  73. package/dist/node_modules/undici-types/snapshot-agent.d.ts +4 -0
  74. package/dist/node_modules/undici-types/socks5-proxy-agent.d.ts +2 -2
  75. package/dist/node_modules/undici-types/webidl.d.ts +0 -1
  76. package/dist/package-lock.json +37 -37
  77. package/dist/package.json +2 -2
  78. package/dist/util/platform/getInitSuccessMessageForPlatform.js +30 -25
  79. package/package.json +2 -2
  80. package/dist/node_modules/@types/node/compatibility/iterators.d.ts +0 -21
package/README.md CHANGED
@@ -3,11 +3,13 @@
3
3
 
4
4
  # Emulsify CLI
5
5
 
6
- Command line interface for Emulsify projects.
6
+ Command line interface for creating Emulsify projects, installing component systems, installing system components, and generating local components.
7
7
 
8
- ## Installation
8
+ ## Requirements
9
+
10
+ Emulsify CLI requires Node.js 24 or newer.
9
11
 
10
- Emulsify CLI requires Node 24 or newer.
12
+ ## Installation
11
13
 
12
14
  Install Emulsify CLI globally from [npm](https://www.npmjs.com/package/@emulsify/cli):
13
15
 
@@ -15,284 +17,61 @@ Install Emulsify CLI globally from [npm](https://www.npmjs.com/package/@emulsify
15
17
  npm install -g @emulsify/cli
16
18
  ```
17
19
 
18
- ## Usage
19
-
20
- Run `emulsify --help` for the current command list.
21
-
22
- ### Commands
23
-
24
- | Command | Alias | Description |
25
- | ----------------------------------- | ----------------------------- | ----------------------------------------------------------------- |
26
- | `emulsify init [name] [path]` | | Initializes an Emulsify project from a starter. |
27
- | `emulsify system list` | `emulsify system ls` | Lists built-in systems available for installation. |
28
- | `emulsify system install [name]` | | Installs a system in the current Emulsify project. |
29
- | `emulsify component list` | `emulsify component ls` | Lists components available from the installed system and variant. |
30
- | `emulsify component install [name]` | `emulsify component i [name]` | Installs one component from the installed system and variant. |
31
- | `emulsify component create [name]` | `emulsify component c [name]` | Creates a local component in the current Emulsify project. |
32
-
33
- ### Initialize A Project
34
-
35
- `emulsify init [name] [path]` clones a starter, writes the project configuration, installs dependencies, runs the starter init hook when present, and removes the starter Git history.
36
-
37
- Options:
38
-
39
- - `--machineName <machineName>`: Sets the machine-friendly project name. When omitted, Emulsify CLI derives it from the project name.
40
- - `--starter <repository>`: Uses a specific starter repository.
41
- - `--checkout <commit/branch/tag>`: Checks out a specific starter commit, branch, or tag.
42
- - `--platform <platform>`: Sets the project platform when auto-detection is unavailable or should be overridden. For Drupal projects, pass `drupal`.
43
- - `--yes`: Accepts default init values for missing options without prompting.
44
-
45
- Current starter repositories:
46
-
47
- - `https://github.com/emulsify-ds/emulsify-starter`
48
- - `https://github.com/emulsify-ds/emulsify-drupal-starter`
49
-
50
- Examples:
51
-
52
- ```bash
53
- emulsify init "My Project" ./projects
54
- emulsify init "My Theme" ./web/themes/custom --platform drupal --yes
55
- emulsify init "My Project" ./projects --starter https://github.com/emulsify-ds/emulsify-starter --checkout main
56
- ```
57
-
58
- ### Systems
59
-
60
- `emulsify system list` lists the built-in systems that Emulsify CLI can install. `emulsify system ls` is the same command.
20
+ Run the current command help at any time:
61
21
 
62
22
  ```bash
63
- emulsify system list
64
- emulsify system ls
65
- ```
66
-
67
- `emulsify system install [name]` installs a system in the current Emulsify project. Use `compound` to install the built-in Compound system. The command installs required components by default.
68
-
69
- Options:
70
-
71
- - `--repository <repository>`: Installs a system from a specific Git repository.
72
- - `--checkout <commit/branch/tag>`: Checks out a specific system commit, branch, or tag. This is required when `--repository` is used.
73
- - `--all`: Installs all available components from the system instead of only required components.
74
-
75
- Examples:
76
-
77
- ```bash
78
- emulsify system install compound
79
- emulsify system install compound --all
80
- emulsify system install --repository https://github.com/example/example-system.git --checkout v1.0.0
23
+ emulsify
24
+ emulsify --help
81
25
  ```
82
26
 
83
- ### Components
27
+ ## Quick Start
84
28
 
85
- `emulsify component list` lists components available from the installed system and variant. `emulsify component ls` is the same command.
29
+ Create a Drupal starter project, install a system, and add components:
86
30
 
87
31
  ```bash
32
+ emulsify init "My Theme" ./web/themes/custom --platform drupal
33
+ cd ./web/themes/custom/my_theme
34
+ emulsify system install
88
35
  emulsify component list
89
- emulsify component ls
36
+ emulsify component install card
37
+ emulsify component create promo-card --directory molecules --format default
90
38
  ```
91
39
 
92
- `emulsify component install [name]` installs one component from the installed system and variant. `emulsify component i [name]` is the same command.
93
-
94
- Options:
95
-
96
- - `--force`: Replaces an installed component.
97
- - `--all`: Installs all available components instead of one named component.
98
- - `--dry-run`: Previews planned component installs, dependencies, destinations, and overwrite behavior without copying or removing files.
99
-
100
- Examples:
40
+ For non-interactive environments, pass the flags that normally prompt for input:
101
41
 
102
42
  ```bash
103
- emulsify component install button
104
- emulsify component install card --dry-run
105
- emulsify component i card --force
106
- emulsify component install --all
107
- ```
108
-
109
- `emulsify component create [name]` creates a local component in the current Emulsify project. `emulsify component c [name]` is the same command.
110
-
111
- Options:
112
-
113
- - `--directory <directory>`: Sets the variant structure directory where the component is created.
114
- - `--format <format>`: Sets the component format. Supported values are `default` and `sdc`.
115
- - `--yes`: Replaces an existing component without an overwrite confirmation prompt.
116
- - `--dry-run`: Previews the destination and generated files without writing, removing, or creating files.
117
-
118
- In non-interactive environments, pass both `--directory` and `--format`.
119
-
120
- Examples:
121
-
122
- ```bash
123
- emulsify component create card --directory base --format default
124
- emulsify component create card --directory base --format default --dry-run
125
- emulsify component create teaser --directory molecules --format sdc --yes
126
- emulsify component create teaser --directory molecules --format sdc --dry-run
43
+ emulsify init "My Theme" ./web/themes/custom --platform drupal --yes
44
+ emulsify system install compound
45
+ emulsify component create promo-card --directory molecules --format default --yes
127
46
  ```
128
47
 
129
- ### Component Template Overrides
130
-
131
- Projects can override the built-in `component create` templates by adding component template override files under `.cli/templates/` at the Emulsify project root. Overrides replace only the known artifacts that Emulsify CLI already generates; they do not add extra files or change which files are created.
132
-
133
- Default component overrides:
134
-
135
- - `.cli/templates/default/component.twig`
136
- - `.cli/templates/default/component.scss`
137
- - `.cli/templates/default/component.yml`
138
- - `.cli/templates/default/component.stories.js`
139
-
140
- SDC component overrides:
48
+ ## Documentation
141
49
 
142
- - `.cli/templates/sdc/component.twig`
143
- - `.cli/templates/sdc/component.scss`
144
- - `.cli/templates/sdc/component.component.yml`
145
- - `.cli/templates/sdc/component.js`
146
- - `.cli/templates/sdc/component.stories.js`
50
+ Detailed documentation lives in [docs](./docs/README.md).
147
51
 
148
- Override files can use double-brace tokens:
52
+ | Topic | Use This When |
53
+ | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
54
+ | [CLI Reference](./docs/cli-reference.md) | Looking up commands, aliases, options, and examples. |
55
+ | [Project Initialization](./docs/project-initialization.md) | Creating a new Emulsify project from a starter. |
56
+ | [Systems](./docs/systems.md) | Listing, installing, or authoring component systems. |
57
+ | [Components](./docs/components.md) | Listing, installing, dry-running, or creating components. |
58
+ | [Project Configuration](./docs/configuration.md) | Understanding `project.emulsify.json`, variants, and structure mappings. |
59
+ | [Component Template Overrides](./docs/component-template-overrides.md) | Customizing files generated by `emulsify component create`. |
60
+ | [Hooks And Cache](./docs/hooks-and-cache.md) | Understanding starter hooks, system hooks, and local repository cache behavior. |
61
+ | [Development](./docs/development.md) | Setting up this repository and running local checks. |
62
+ | [Release](./docs/release.md) | Understanding CI, semantic-release, and npm publishing. |
149
63
 
150
- - `{{ filename }}`
151
- - `{{ className }}`
152
- - `{{ camelName }}`
153
- - `{{ snakeName }}`
154
- - `{{ humanName }}`
155
- - `{{ directory }}`
156
- - `{{ format }}`
64
+ ## Command Overview
157
65
 
158
- For each generated artifact, Emulsify CLI first checks for the matching override file. If the override is missing, the built-in template is used. If the override exists but is empty, the built-in template is used and a warning is logged. Unknown tokens are left unchanged and logged as warnings. Partial override sets are supported, so a project can override only `component.twig` and keep the built-in SCSS, data, and story templates. Extra arbitrary files are not generated by component template overrides.
159
-
160
- For more documentation, see the [Emulsify CLI usage documentation](https://www.emulsify.info/docs/supporting-projects/emulsify-cli/emulsify-cli-usage).
161
-
162
- ## Development
163
-
164
- Emulsify CLI is developed using TypeScript. You can find all of the source files in the `src` directory, which is organized in the following manner:
165
-
166
- - `src/index.ts` - uses Commander to compose the CLI.
167
- - `src/handlers` - contains all functions that handle CLI commands, such as `emulsify init`.
168
- - `src/lib` - general definitions and logging tools.
169
- - `src/schemas` - contains JSON-Schema files that describe project, system, and variant configuration. These schema files are used to generate TypeScript types.
170
- - `src/scripts` - holds utility scripts for the project.
171
- - `src/types` - type modules live here, auto-generated ones are prefixed with an underscore (`_`).
172
- - `src/util` - contains utility functions that are used in handlers to do various things, such as caching systems and resolving component template overrides.
173
-
174
- ### Setup
175
-
176
- - Install the version of Node specified in this project's `.nvmrc` file. If you are using nvm, run `nvm use`.
177
- - Clone this repository into a directory of your choosing.
178
- - In the directory, run `npm install`.
179
- - Build the project: `npm run build`, or watch: `npm run watch`.
180
- - To test the CLI, run: `npm link`.
181
-
182
- ### Scripts
183
-
184
- - `npm run build`: builds the project based on the configuration in `tsconfig.dist.json`.
185
- - `npm run build-schema-types`: Compiles the JSON Schema definitions within this project into TypeScript types.
186
- - `npm run watch`: watches the codebase, and re-compiles every time a change is made.
187
- - `npm run format`: uses prettier to format all ts files within the codebase.
188
- - `npm run lint`: runs the Jest test suite via the `test` script.
189
- - `npm run test`: runs Jest on the codebase. You can specify a path to a single test, and add any flags supported by Jest's CLI.
190
- - `npm run type`: uses typescript to check all type signatures.
191
- - `npm run twatch`: runs Jest without coverage, in verbose and watch mode. This is useful for running a single test during active development.
192
- - `npm run semantic-release`: publishes a release using `release.config.cjs`.
193
-
194
- ## Deployment
195
-
196
- This project is automatically built and deployed to npm via the release GitHub Actions workflow. Pushes to `main` run `npm run build` and then `npm run semantic-release`.
66
+ | Command | Alias | Description |
67
+ | ----------------------------------- | ----------------------------- | ----------------------------------------------------------------- |
68
+ | `emulsify init [name] [path]` | | Initializes an Emulsify project from a starter. |
69
+ | `emulsify system list` | `emulsify system ls` | Lists built-in systems available for installation. |
70
+ | `emulsify system install [name]` | | Installs or scaffolds a system in the current Emulsify project. |
71
+ | `emulsify component list` | `emulsify component ls` | Lists components available from the installed system and variant. |
72
+ | `emulsify component install [name]` | `emulsify component i [name]` | Installs one component from the installed system and variant. |
73
+ | `emulsify component create [name]` | `emulsify component c [name]` | Creates a local component in the current Emulsify project. |
197
74
 
198
- ### Contributors
75
+ ## Contributors
199
76
 
200
- <table>
201
- <tr>
202
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
203
- <a href=https://github.com/patrickocoffeyo>
204
- <img src=https://avatars.githubusercontent.com/u/1107871?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Patrick Coffey/>
205
- <br />
206
- <sub style="font-size:14px"><b>Patrick Coffey</b></sub>
207
- </a>
208
- </td>
209
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
210
- <a href=https://github.com/ModulesUnraveled>
211
- <img src=https://avatars.githubusercontent.com/u/1663810?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Brian Lewis/>
212
- <br />
213
- <sub style="font-size:14px"><b>Brian Lewis</b></sub>
214
- </a>
215
- </td>
216
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
217
- <a href=https://github.com/amazingrando>
218
- <img src=https://avatars.githubusercontent.com/u/409903?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Randy Oest/>
219
- <br />
220
- <sub style="font-size:14px"><b>Randy Oest</b></sub>
221
- </a>
222
- </td>
223
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
224
- <a href=https://github.com/callinmullaney>
225
- <img src=https://avatars.githubusercontent.com/u/369018?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Callin Mullaney/>
226
- <br />
227
- <sub style="font-size:14px"><b>Callin Mullaney</b></sub>
228
- </a>
229
- </td>
230
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
231
- <a href=https://github.com/JeffTomlinson>
232
- <img src=https://avatars.githubusercontent.com/u/2602202?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Jeff Tomlinson/>
233
- <br />
234
- <sub style="font-size:14px"><b>Jeff Tomlinson</b></sub>
235
- </a>
236
- </td>
237
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
238
- <a href=https://github.com/mikeethedude>
239
- <img src=https://avatars.githubusercontent.com/u/15275301?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=mikeethedude/>
240
- <br />
241
- <sub style="font-size:14px"><b>mikeethedude</b></sub>
242
- </a>
243
- </td>
244
- </tr>
245
- <tr>
246
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
247
- <a href=https://github.com/robherba>
248
- <img src=https://avatars.githubusercontent.com/u/9342274?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Roberto Hernández Badilla/>
249
- <br />
250
- <sub style="font-size:14px"><b>Roberto Hernández Badilla</b></sub>
251
- </a>
252
- </td>
253
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
254
- <a href=https://github.com/fertant>
255
- <img src=https://avatars.githubusercontent.com/u/3853492?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Andrii Shutov/>
256
- <br />
257
- <sub style="font-size:14px"><b>Andrii Shutov</b></sub>
258
- </a>
259
- </td>
260
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
261
- <a href=https://github.com/nJim>
262
- <img src=https://avatars.githubusercontent.com/u/9594124?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Jim Vomero/>
263
- <br />
264
- <sub style="font-size:14px"><b>Jim Vomero</b></sub>
265
- </a>
266
- </td>
267
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
268
- <a href=https://github.com/calebtr-metro>
269
- <img src=https://avatars.githubusercontent.com/u/43386533?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Caleb Tucker-Raymond/>
270
- <br />
271
- <sub style="font-size:14px"><b>Caleb Tucker-Raymond</b></sub>
272
- </a>
273
- </td>
274
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
275
- <a href=https://github.com/karldivad>
276
- <img src=https://avatars.githubusercontent.com/u/13474855?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Carlos Valencia Rivero/>
277
- <br />
278
- <sub style="font-size:14px"><b>Carlos Valencia Rivero</b></sub>
279
- </a>
280
- </td>
281
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
282
- <a href=https://github.com/iryston>
283
- <img src=https://avatars.githubusercontent.com/u/1258460?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Igor R. Plity/>
284
- <br />
285
- <sub style="font-size:14px"><b>Igor R. Plity</b></sub>
286
- </a>
287
- </td>
288
- </tr>
289
- <tr>
290
- <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
291
- <a href=https://github.com/ryanhagerty>
292
- <img src=https://avatars.githubusercontent.com/u/8405274?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Ryan Hagerty/>
293
- <br />
294
- <sub style="font-size:14px"><b>Ryan Hagerty</b></sub>
295
- </a>
296
- </td>
297
- </tr>
298
- </table>
77
+ See [Contributors](./docs/contributors.md).
@@ -1,7 +1,7 @@
1
1
  import { join } from 'path';
2
2
  import { existsSync, promises as fs } from 'fs';
3
3
  import { simpleGit } from 'simple-git';
4
- import { input } from '@inquirer/prompts';
4
+ import { input, select } from '@inquirer/prompts';
5
5
  import { EMULSIFY_PROJECT_CONFIG_FILE, EMULSIFY_PROJECT_HOOK_INIT, EMULSIFY_PROJECT_HOOK_FOLDER, } from '../lib/constants.js';
6
6
  import getPlatformInfo from '../util/platform/getPlatformInfo.js';
7
7
  import getAvailableStarters from '../util/getAvailableStarters.js';
@@ -16,9 +16,14 @@ const git = simpleGit();
16
16
  export const DIRECTORY = 1;
17
17
  const DEFAULT_PROJECT_NAME = 'emulsifyTheme';
18
18
  const DEFAULT_PLATFORM = 'drupal';
19
+ const PLATFORM_CHOICES = [
20
+ 'drupal',
21
+ 'none',
22
+ ];
19
23
  export default function init(progress) {
20
24
  return async (name, targetDirectory, options) => {
21
25
  const { name: autoPlatformName, emulsifyParentDirectory } = (await getPlatformInfo()) || {};
26
+ const isDetectedDrupalProject = autoPlatformName === 'drupal';
22
27
  const canPrompt = process.stdin.isTTY === true;
23
28
  const acceptDefaults = options?.yes === true;
24
29
  let projectName = name || options?.machineName;
@@ -54,10 +59,11 @@ export default function init(progress) {
54
59
  platformName = DEFAULT_PLATFORM;
55
60
  }
56
61
  else if (canPrompt) {
57
- platformName = (await input({
62
+ platformName = await select({
58
63
  message: 'Platform:',
64
+ choices: PLATFORM_CHOICES,
59
65
  default: DEFAULT_PLATFORM,
60
- }));
66
+ });
61
67
  }
62
68
  }
63
69
  if (!platformName) {
@@ -71,7 +77,7 @@ export default function init(progress) {
71
77
  const starter = starters.find((s) => s.platform === platformName);
72
78
  const target = targetParent ? join(targetParent, machineName) : undefined;
73
79
  const repository = options?.starter || starter?.repository;
74
- const checkout = options?.checkout || starter?.checkout;
80
+ const checkout = options?.checkout || (options?.starter ? undefined : starter?.checkout);
75
81
  if (!target) {
76
82
  throw new CliError('Unable to find a directory to put Emulsify in. Please specify a directory using the "path" argument: emulsify init myTheme ./themes');
77
83
  }
@@ -112,7 +118,9 @@ export default function init(progress) {
112
118
  message: 'init script executed, initialization complete',
113
119
  });
114
120
  log('success', `Created an Emulsify project in ${target}.`);
115
- getInitSuccessMessageForPlatform(platformName, target).map(({ method, message }) => log(method, message));
121
+ getInitSuccessMessageForPlatform(platformName, target, {
122
+ includeDrupalInstallReminder: isDetectedDrupalProject && platformName === 'drupal',
123
+ }).map(({ method, message }) => log(method, message));
116
124
  }
117
125
  catch (e) {
118
126
  throw new CliError(`Unable to pull down ${repository}: ${String(e)}`);
@@ -1,8 +1,9 @@
1
1
  import { Ajv } from 'ajv';
2
2
  import addFormats from 'ajv-formats';
3
- import { join } from 'path';
3
+ import { dirname, join } from 'path';
4
4
  import { existsSync } from 'fs';
5
- import { EMULSIFY_SYSTEM_CONFIG_FILE, EMULSIFY_PROJECT_HOOK_FOLDER, EMULSIFY_PROJECT_HOOK_SYSTEM_INSTALL, } from '../lib/constants.js';
5
+ import { select } from '@inquirer/prompts';
6
+ import { EMULSIFY_PROJECT_CONFIG_FILE, EMULSIFY_SYSTEM_CONFIG_FILE, EMULSIFY_PROJECT_HOOK_FOLDER, EMULSIFY_PROJECT_HOOK_SYSTEM_INSTALL, } from '../lib/constants.js';
6
7
  import log from '../lib/log.js';
7
8
  import CliError from '../lib/CliError.js';
8
9
  import getAvailableSystems from '../util/system/getAvailableSystems.js';
@@ -17,6 +18,10 @@ import setEmulsifyConfig from '../util/project/setEmulsifyConfig.js';
17
18
  import getEmulsifyConfig from '../util/project/getEmulsifyConfig.js';
18
19
  import findFileInCurrentPath from '../util/fs/findFileInCurrentPath.js';
19
20
  import executeScript from '../util/fs/executeScript.js';
21
+ import writeToJsonFile from '../util/fs/writeToJsonFile.js';
22
+ const CREATE_NEW_SYSTEM_CHOICE = 'create a new system';
23
+ const CANCEL_SYSTEM_INSTALL_CHOICE = 'cancel';
24
+ const SYSTEM_INSTALL_ERROR = 'Unable to download specified system. You must either specify a valid name of an out-of-the-box system using the --name flag, or specify a valid repository and branch/tag/commit using the --repository and --checkout flags.';
20
25
  async function loadSchemas() {
21
26
  const [{ default: systemSchema }, { default: variantSchema }] = await Promise.all([
22
27
  import('../schemas/system.json', { with: { type: 'json' } }),
@@ -56,6 +61,63 @@ export async function getSystemRepoInfo(name, { repository, checkout }) {
56
61
  }
57
62
  }
58
63
  }
64
+ async function promptForSystemInstallChoice() {
65
+ const availableSystems = await getAvailableSystems();
66
+ const selectedSystem = await select({
67
+ message: 'Choose a component system:',
68
+ choices: [
69
+ ...availableSystems.map(({ name }) => name),
70
+ CREATE_NEW_SYSTEM_CHOICE,
71
+ CANCEL_SYSTEM_INSTALL_CHOICE,
72
+ ],
73
+ });
74
+ if (selectedSystem === CANCEL_SYSTEM_INSTALL_CHOICE) {
75
+ log('info', 'System install cancelled.');
76
+ return;
77
+ }
78
+ return selectedSystem;
79
+ }
80
+ function getCustomSystemPlatform(platform) {
81
+ return platform === 'drupal' || platform === 'none' ? platform : 'none';
82
+ }
83
+ function buildCustomSystemDefinition(platform) {
84
+ return {
85
+ name: 'custom-system',
86
+ homepage: 'https://example.com/custom-system',
87
+ repository: 'https://github.com/example/custom-system.git',
88
+ structure: [
89
+ {
90
+ name: 'components',
91
+ description: 'Project component library',
92
+ },
93
+ ],
94
+ variants: [
95
+ {
96
+ platform,
97
+ structureImplementations: [
98
+ {
99
+ name: 'components',
100
+ directory: './src/components',
101
+ },
102
+ ],
103
+ components: [],
104
+ },
105
+ ],
106
+ };
107
+ }
108
+ async function scaffoldCustomSystemDefinition(projectConfig) {
109
+ const projectConfigPath = findFileInCurrentPath(EMULSIFY_PROJECT_CONFIG_FILE);
110
+ if (!projectConfigPath) {
111
+ throw new CliError(`Unable to find ${EMULSIFY_PROJECT_CONFIG_FILE}. Run this command from within an Emulsify project.`);
112
+ }
113
+ const systemConfigPath = join(dirname(projectConfigPath), EMULSIFY_SYSTEM_CONFIG_FILE);
114
+ if (existsSync(systemConfigPath)) {
115
+ throw new CliError(`${EMULSIFY_SYSTEM_CONFIG_FILE} already exists. Remove or rename it before creating a new custom system definition.`);
116
+ }
117
+ await writeToJsonFile(systemConfigPath, buildCustomSystemDefinition(getCustomSystemPlatform(projectConfig.project.platform)));
118
+ log('success', `Created ${EMULSIFY_SYSTEM_CONFIG_FILE}.`);
119
+ log('info', 'Add your real system name, repository, structures, variants, and components before using this system to install or generate components.');
120
+ }
59
121
  export default async function systemInstall(name, options) {
60
122
  const projectConfig = await getEmulsifyConfig();
61
123
  if (!projectConfig) {
@@ -64,9 +126,20 @@ export default async function systemInstall(name, options) {
64
126
  if (projectConfig.system) {
65
127
  throw new CliError('You have already selected a system within this Emulsify project.');
66
128
  }
67
- const repo = await getSystemRepoInfo(name, options);
129
+ let selectedName = name;
130
+ if (!selectedName && !options.repository && process.stdin.isTTY === true) {
131
+ selectedName = await promptForSystemInstallChoice();
132
+ if (!selectedName) {
133
+ return;
134
+ }
135
+ if (selectedName === CREATE_NEW_SYSTEM_CHOICE) {
136
+ await scaffoldCustomSystemDefinition(projectConfig);
137
+ return;
138
+ }
139
+ }
140
+ const repo = await getSystemRepoInfo(selectedName, options);
68
141
  if (!repo) {
69
- throw new CliError('Unable to download specified system. You must either specify a valid name of an out-of-the-box system using the --name flag, or specify a valid repository and branch/tag/commit using the --repository and --checkout flags.');
142
+ throw new CliError(SYSTEM_INSTALL_ERROR);
70
143
  }
71
144
  if (repo.checkout === undefined) {
72
145
  repo.checkout = await getRepositoryLatestTag(repo.repository);