@drupal-canvas/create 1.4.1 → 1.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.
- package/README.md +89 -15
- package/dist/index.js +572 -143
- package/docs/experimental.md +61 -0
- package/package.json +5 -3
- package/templates.json +39 -6
package/README.md
CHANGED
|
@@ -22,40 +22,96 @@ pnpm dlx @drupal-canvas/create@latest
|
|
|
22
22
|
bunx @drupal-canvas/create@latest
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
You can also provide the
|
|
25
|
+
You can also provide the project name as an argument:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
npx @drupal-canvas/create@latest my-
|
|
28
|
+
npx @drupal-canvas/create@latest my-project
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
Experimental features are documented in
|
|
32
|
+
[`docs/experimental.md`](docs/experimental.md).
|
|
33
|
+
|
|
31
34
|
### Options
|
|
32
35
|
|
|
33
|
-
| Option
|
|
34
|
-
|
|
|
35
|
-
| `--template -t`
|
|
36
|
-
| `--ref <ref>`
|
|
37
|
-
| `--agents -a`
|
|
36
|
+
| Option | Description |
|
|
37
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
38
|
+
| `--template -t` | Template to use when scaffolding the project. One of the predefined templates in `templates.json` or a URL to a custom template's Git repository. |
|
|
39
|
+
| `--ref <ref>` | Custom Git ref to use when cloning the template repository. For example, a branch name or a tag. |
|
|
40
|
+
| `--agents -a` | Comma-separated list of additional agents to support, or `none` to skip compatibility symlink creation. |
|
|
41
|
+
| `--site-name <name>` | Site name to slugify and suggest as the interactive project name. |
|
|
42
|
+
| `--site-url <url>` | Canvas site URL to write to the generated `.env`. Takes precedence over `CANVAS_SITE_URL`. |
|
|
43
|
+
|
|
44
|
+
### Interactive and non-interactive input
|
|
45
|
+
|
|
46
|
+
A run is interactive when both standard input and output are attached to a
|
|
47
|
+
terminal. Non-interactive runs never prompt.
|
|
48
|
+
|
|
49
|
+
| Input | CLI input | Interactive when omitted | Non-interactive when omitted |
|
|
50
|
+
| ------------ | --------------------------------- | ------------------------------------------------ | --------------------------------------- |
|
|
51
|
+
| Project name | Positional `[project-name]` | Prompted | Error |
|
|
52
|
+
| Template | `--template`, `-t` | Default frontend selected automatically | Default frontend selected automatically |
|
|
53
|
+
| Site name | `--site-name` | Used to suggest the project name | Ignored |
|
|
54
|
+
| Site URL | `--site-url` or `CANVAS_SITE_URL` | Prompted | Optional; no `.env` when omitted |
|
|
55
|
+
| Git ref | `--ref`, `-r` | Template default applies | Template default applies |
|
|
56
|
+
| Agents | `--agents`, `-a` | Prompted when the template includes agent skills | Optional; compatibility is skipped |
|
|
38
57
|
|
|
39
58
|
### Example
|
|
40
59
|
|
|
41
60
|
```bash
|
|
42
|
-
npx @drupal-canvas/create@latest my-
|
|
61
|
+
npx @drupal-canvas/create@latest my-project --template default
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The previous `acquia-nebula` template ID remains supported as an alias.
|
|
65
|
+
|
|
66
|
+
Use a site name to suggest an editable project name when the positional project
|
|
67
|
+
name is omitted:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npx @drupal-canvas/create@latest --site-name 'My Drupal Site'
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Provide the Canvas site URL with a flag:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npx @drupal-canvas/create@latest my-project \
|
|
77
|
+
--site-url https://canvas.example.com
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The `CANVAS_SITE_URL` environment variable can be used instead. The flag takes
|
|
81
|
+
precedence when both are provided:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
CANVAS_SITE_URL='https://canvas.example.com' \
|
|
85
|
+
npx @drupal-canvas/create@latest my-project
|
|
43
86
|
```
|
|
44
87
|
|
|
88
|
+
When neither value is provided, interactive runs prompt for the site URL.
|
|
89
|
+
Non-interactive runs continue without creating `.env`. When a URL is provided
|
|
90
|
+
and the template includes `.env.example`, the CLI copies it to `.env` and
|
|
91
|
+
updates or appends `CANVAS_SITE_URL`. Otherwise, it creates a new `.env`. If
|
|
92
|
+
`.env` already exists, the CLI adds or fills `CANVAS_SITE_URL`; when a non-empty
|
|
93
|
+
value is already configured, it keeps that value. The CLI prints a message for
|
|
94
|
+
each outcome and ensures `.env` is listed in `.gitignore`.
|
|
95
|
+
|
|
96
|
+
Non-interactive runs require a positional project name. When multiple templates
|
|
97
|
+
are enabled, `--template` is also required. The `--site-name` option does not
|
|
98
|
+
replace the positional project name in this mode. Missing site URLs and agent
|
|
99
|
+
selections remain optional and do not prompt.
|
|
100
|
+
|
|
45
101
|
Explicitly skip additional agent compatibility symlinks:
|
|
46
102
|
|
|
47
103
|
```bash
|
|
48
|
-
npx @drupal-canvas/create@latest my-
|
|
104
|
+
npx @drupal-canvas/create@latest my-project --template default --agents none
|
|
49
105
|
```
|
|
50
106
|
|
|
51
107
|
Provide additional agent compatibility symlinks without prompting:
|
|
52
108
|
|
|
53
109
|
```bash
|
|
54
|
-
npx @drupal-canvas/create@latest my-
|
|
110
|
+
npx @drupal-canvas/create@latest my-project --template default --agents claude-code,roo
|
|
55
111
|
```
|
|
56
112
|
|
|
57
113
|
If `--agents` is omitted, the CLI keeps the current interactive prompt on TTY
|
|
58
|
-
runs. On non-interactive runs, it skips compatibility setup
|
|
114
|
+
runs. On non-interactive runs, it skips compatibility setup and prints a note.
|
|
59
115
|
|
|
60
116
|
### `agents` command
|
|
61
117
|
|
|
@@ -82,10 +138,28 @@ npx @drupal-canvas/create@latest agents none
|
|
|
82
138
|
|
|
83
139
|
Drupal Canvas Create is designed to be easily extendable with new templates.
|
|
84
140
|
|
|
85
|
-
**Templates** are predefined
|
|
141
|
+
**Templates** are predefined Canvas project starter codebases. Each template
|
|
86
142
|
references a Git repository that will be cloned to provide the initial codebase.
|
|
87
143
|
To add a template, edit `templates.json` in the package root.
|
|
88
144
|
|
|
145
|
+
A repository can contain multiple templates. Set the optional repository `path`
|
|
146
|
+
to use a directory within the cloned repository as the project root:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"id": "company-starter",
|
|
151
|
+
"label": "company/canvas-starter",
|
|
152
|
+
"repository": {
|
|
153
|
+
"url": "https://github.com/company/canvas-templates.git",
|
|
154
|
+
"ref": "main",
|
|
155
|
+
"path": "templates/starter"
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The path must identify a directory within the repository. Files outside that
|
|
161
|
+
directory are not included in the created project.
|
|
162
|
+
|
|
89
163
|
### Working with the codebase
|
|
90
164
|
|
|
91
165
|
First, build the project:
|
|
@@ -103,9 +177,9 @@ npm start
|
|
|
103
177
|
Alternatively, use `npm run dev` to compile and watch for changes during
|
|
104
178
|
development.
|
|
105
179
|
|
|
106
|
-
⚠️ You must use `my-canvas-
|
|
107
|
-
when running the script from a local directory. (Reasons are explained in
|
|
108
|
-
`.gitignore` file where we had to ignore this directory.)
|
|
180
|
+
⚠️ You must use `my-canvas-project` (provided as default value) as your project
|
|
181
|
+
name when running the script from a local directory. (Reasons are explained in
|
|
182
|
+
the `.gitignore` file where we had to ignore this directory.)
|
|
109
183
|
|
|
110
184
|
### Scripts
|
|
111
185
|
|
package/dist/index.js
CHANGED
|
@@ -1,40 +1,78 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import chalk2 from 'chalk';
|
|
3
3
|
import { Command } from 'commander';
|
|
4
|
-
import * as
|
|
5
|
-
import { readFile, writeFile, access, readdir, mkdir, symlink } from 'fs/promises';
|
|
4
|
+
import * as p5 from '@clack/prompts';
|
|
5
|
+
import { mkdtemp, readFile, writeFile, lstat, rename, access, readdir, mkdir, symlink } from 'fs/promises';
|
|
6
6
|
import { platform } from 'os';
|
|
7
|
-
import { join,
|
|
7
|
+
import { join, resolve, relative, sep, isAbsolute, dirname } from 'path';
|
|
8
8
|
import * as readline from 'readline';
|
|
9
9
|
import { Writable } from 'stream';
|
|
10
10
|
import pc from 'picocolors';
|
|
11
11
|
import spawn from 'cross-spawn';
|
|
12
12
|
import { rimraf } from 'rimraf';
|
|
13
13
|
import { simpleGit } from 'simple-git';
|
|
14
|
+
import slugify from '@sindresorhus/slugify';
|
|
14
15
|
import validate from 'validate-npm-package-name';
|
|
15
16
|
|
|
16
17
|
// templates.json
|
|
17
18
|
var templates_default = [
|
|
18
19
|
{
|
|
19
|
-
id: "
|
|
20
|
-
|
|
20
|
+
id: "default",
|
|
21
|
+
aliases: ["acquia-nebula"],
|
|
22
|
+
label: "Default (Canvas-rendered React)",
|
|
21
23
|
repository: {
|
|
22
24
|
url: "https://github.com/acquia/nebula.git",
|
|
23
25
|
ref: "main"
|
|
24
26
|
}
|
|
25
27
|
},
|
|
26
28
|
{
|
|
27
|
-
id: "
|
|
28
|
-
label: "
|
|
29
|
+
id: "nextjs",
|
|
30
|
+
label: "Next.js",
|
|
31
|
+
experimental: true,
|
|
29
32
|
repository: {
|
|
30
|
-
url: "https://github.com/
|
|
31
|
-
ref: "main"
|
|
33
|
+
url: "https://github.com/drupal-canvas/headless-templates.git",
|
|
34
|
+
ref: "main",
|
|
35
|
+
path: "nextjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "astro",
|
|
40
|
+
label: "Astro",
|
|
41
|
+
experimental: true,
|
|
42
|
+
repository: {
|
|
43
|
+
url: "https://github.com/drupal-canvas/headless-templates.git",
|
|
44
|
+
ref: "main",
|
|
45
|
+
path: "astro"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: "nuxt",
|
|
50
|
+
label: "Nuxt",
|
|
51
|
+
experimental: true,
|
|
52
|
+
repository: {
|
|
53
|
+
url: "https://github.com/drupal-canvas/headless-templates.git",
|
|
54
|
+
ref: "main",
|
|
55
|
+
path: "nuxt"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: "tanstack-start",
|
|
60
|
+
label: "TanStack Start",
|
|
61
|
+
experimental: true,
|
|
62
|
+
repository: {
|
|
63
|
+
url: "https://github.com/drupal-canvas/headless-templates.git",
|
|
64
|
+
ref: "main",
|
|
65
|
+
path: "tanstack-start"
|
|
32
66
|
}
|
|
33
67
|
}
|
|
34
68
|
];
|
|
35
69
|
|
|
36
70
|
// src/lib/agents.ts
|
|
37
71
|
var agents = {
|
|
72
|
+
"aider-desk": {
|
|
73
|
+
displayName: "AiderDesk",
|
|
74
|
+
skillsDir: ".aider-desk/skills"
|
|
75
|
+
},
|
|
38
76
|
amp: {
|
|
39
77
|
displayName: "Amp",
|
|
40
78
|
skillsDir: ".agents/skills"
|
|
@@ -47,6 +85,10 @@ var agents = {
|
|
|
47
85
|
displayName: "Augment",
|
|
48
86
|
skillsDir: ".augment/skills"
|
|
49
87
|
},
|
|
88
|
+
bob: {
|
|
89
|
+
displayName: "IBM Bob",
|
|
90
|
+
skillsDir: ".bob/skills"
|
|
91
|
+
},
|
|
50
92
|
"claude-code": {
|
|
51
93
|
displayName: "Claude Code",
|
|
52
94
|
skillsDir: ".claude/skills"
|
|
@@ -59,10 +101,22 @@ var agents = {
|
|
|
59
101
|
displayName: "Cline",
|
|
60
102
|
skillsDir: ".agents/skills"
|
|
61
103
|
},
|
|
104
|
+
"codearts-agent": {
|
|
105
|
+
displayName: "CodeArts Agent",
|
|
106
|
+
skillsDir: ".codeartsdoer/skills"
|
|
107
|
+
},
|
|
62
108
|
codebuddy: {
|
|
63
109
|
displayName: "CodeBuddy",
|
|
64
110
|
skillsDir: ".codebuddy/skills"
|
|
65
111
|
},
|
|
112
|
+
codemaker: {
|
|
113
|
+
displayName: "Codemaker",
|
|
114
|
+
skillsDir: ".codemaker/skills"
|
|
115
|
+
},
|
|
116
|
+
codestudio: {
|
|
117
|
+
displayName: "Code Studio",
|
|
118
|
+
skillsDir: ".codestudio/skills"
|
|
119
|
+
},
|
|
66
120
|
codex: {
|
|
67
121
|
displayName: "Codex",
|
|
68
122
|
skillsDir: ".agents/skills"
|
|
@@ -91,10 +145,26 @@ var agents = {
|
|
|
91
145
|
displayName: "Deep Agents",
|
|
92
146
|
skillsDir: ".agents/skills"
|
|
93
147
|
},
|
|
148
|
+
devin: {
|
|
149
|
+
displayName: "Devin for Terminal",
|
|
150
|
+
skillsDir: ".devin/skills"
|
|
151
|
+
},
|
|
152
|
+
dexto: {
|
|
153
|
+
displayName: "Dexto",
|
|
154
|
+
skillsDir: ".agents/skills"
|
|
155
|
+
},
|
|
94
156
|
droid: {
|
|
95
157
|
displayName: "Droid",
|
|
96
158
|
skillsDir: ".factory/skills"
|
|
97
159
|
},
|
|
160
|
+
firebender: {
|
|
161
|
+
displayName: "Firebender",
|
|
162
|
+
skillsDir: ".agents/skills"
|
|
163
|
+
},
|
|
164
|
+
forgecode: {
|
|
165
|
+
displayName: "ForgeCode",
|
|
166
|
+
skillsDir: ".forge/skills"
|
|
167
|
+
},
|
|
98
168
|
"gemini-cli": {
|
|
99
169
|
displayName: "Gemini CLI",
|
|
100
170
|
skillsDir: ".agents/skills"
|
|
@@ -107,6 +177,10 @@ var agents = {
|
|
|
107
177
|
displayName: "Goose",
|
|
108
178
|
skillsDir: ".goose/skills"
|
|
109
179
|
},
|
|
180
|
+
"hermes-agent": {
|
|
181
|
+
displayName: "Hermes Agent",
|
|
182
|
+
skillsDir: ".hermes/skills"
|
|
183
|
+
},
|
|
110
184
|
junie: {
|
|
111
185
|
displayName: "Junie",
|
|
112
186
|
skillsDir: ".junie/skills"
|
|
@@ -168,10 +242,18 @@ var agents = {
|
|
|
168
242
|
skillsDir: ".agents/skills",
|
|
169
243
|
showInUniversalList: false
|
|
170
244
|
},
|
|
245
|
+
rovodev: {
|
|
246
|
+
displayName: "Rovo Dev",
|
|
247
|
+
skillsDir: ".rovodev/skills"
|
|
248
|
+
},
|
|
171
249
|
roo: {
|
|
172
250
|
displayName: "Roo Code",
|
|
173
251
|
skillsDir: ".roo/skills"
|
|
174
252
|
},
|
|
253
|
+
"tabnine-cli": {
|
|
254
|
+
displayName: "Tabnine CLI",
|
|
255
|
+
skillsDir: ".tabnine/agent/skills"
|
|
256
|
+
},
|
|
175
257
|
trae: {
|
|
176
258
|
displayName: "Trae",
|
|
177
259
|
skillsDir: ".trae/skills"
|
|
@@ -180,6 +262,11 @@ var agents = {
|
|
|
180
262
|
displayName: "Trae CN",
|
|
181
263
|
skillsDir: ".trae/skills"
|
|
182
264
|
},
|
|
265
|
+
universal: {
|
|
266
|
+
displayName: "Universal",
|
|
267
|
+
skillsDir: ".agents/skills",
|
|
268
|
+
showInUniversalList: false
|
|
269
|
+
},
|
|
183
270
|
warp: {
|
|
184
271
|
displayName: "Warp",
|
|
185
272
|
skillsDir: ".agents/skills"
|
|
@@ -188,6 +275,10 @@ var agents = {
|
|
|
188
275
|
displayName: "Windsurf",
|
|
189
276
|
skillsDir: ".windsurf/skills"
|
|
190
277
|
},
|
|
278
|
+
zed: {
|
|
279
|
+
displayName: "Zed",
|
|
280
|
+
skillsDir: ".agents/skills"
|
|
281
|
+
},
|
|
191
282
|
zencoder: {
|
|
192
283
|
displayName: "Zencoder",
|
|
193
284
|
skillsDir: ".zencoder/skills"
|
|
@@ -287,7 +378,7 @@ async function searchMultiselect(options) {
|
|
|
287
378
|
required = false,
|
|
288
379
|
lockedSection
|
|
289
380
|
} = options;
|
|
290
|
-
return new Promise((
|
|
381
|
+
return new Promise((resolve2) => {
|
|
291
382
|
const rl = readline.createInterface({
|
|
292
383
|
input: process.stdin,
|
|
293
384
|
output: silentOutput,
|
|
@@ -415,12 +506,12 @@ async function searchMultiselect(options) {
|
|
|
415
506
|
}
|
|
416
507
|
render("submit");
|
|
417
508
|
cleanup();
|
|
418
|
-
|
|
509
|
+
resolve2([...lockedValues, ...Array.from(selected)]);
|
|
419
510
|
};
|
|
420
511
|
const cancel2 = () => {
|
|
421
512
|
render("cancel");
|
|
422
513
|
cleanup();
|
|
423
|
-
|
|
514
|
+
resolve2(cancelSymbol);
|
|
424
515
|
};
|
|
425
516
|
const keypressHandler = (_str, key) => {
|
|
426
517
|
if (!key) return;
|
|
@@ -481,12 +572,15 @@ function pluralize(word, count) {
|
|
|
481
572
|
// src/lib/agent-skills-setup.ts
|
|
482
573
|
var DEFAULT_SKILLS_DIR = ".agents/skills";
|
|
483
574
|
async function setupAgentSkills(projectDir, options = {}) {
|
|
484
|
-
const info = options.onInfo ??
|
|
485
|
-
const warning = options.onWarning ??
|
|
575
|
+
const info = options.onInfo ?? p5.log.info;
|
|
576
|
+
const warning = options.onWarning ?? p5.log.warn;
|
|
486
577
|
const interactive = options.interactive ?? true;
|
|
487
578
|
const hasExplicitSelection = options.selectedAgents !== void 0;
|
|
488
579
|
try {
|
|
489
580
|
if (!hasExplicitSelection && !interactive) {
|
|
581
|
+
info(
|
|
582
|
+
"Agent compatibility skipped because the command is non-interactive. Use --agents to enable it."
|
|
583
|
+
);
|
|
490
584
|
return;
|
|
491
585
|
}
|
|
492
586
|
const canonicalSkillsDir = join(projectDir, DEFAULT_SKILLS_DIR);
|
|
@@ -505,7 +599,7 @@ async function setupAgentSkills(projectDir, options = {}) {
|
|
|
505
599
|
const promptForAgents = options.promptForAgents ?? defaultPromptForAgents;
|
|
506
600
|
selected = await promptForAgents();
|
|
507
601
|
}
|
|
508
|
-
if (
|
|
602
|
+
if (p5.isCancel(selected) || typeof selected === "symbol") {
|
|
509
603
|
info("Skipped compatibility setup.");
|
|
510
604
|
return;
|
|
511
605
|
}
|
|
@@ -528,8 +622,12 @@ async function setupAgentSkills(projectDir, options = {}) {
|
|
|
528
622
|
skillNames,
|
|
529
623
|
selectedAgents: nonUniversalAgents
|
|
530
624
|
});
|
|
531
|
-
|
|
532
|
-
|
|
625
|
+
info(
|
|
626
|
+
`Agent compatibility:
|
|
627
|
+
${nonUniversalAgents.map(
|
|
628
|
+
(agent) => `- ${agents[agent].displayName}: ${agents[agent].skillsDir}`
|
|
629
|
+
).join("\n")}`
|
|
630
|
+
);
|
|
533
631
|
if (results.created.length > 0) {
|
|
534
632
|
info(
|
|
535
633
|
`Created compatibility ${pluralize("symlink", results.created.length)} (${skillNames.length} ${pluralize("skill", skillNames.length)} \xD7 ${nonUniversalAgents.length} ${pluralize("agent", nonUniversalAgents.length)}).`
|
|
@@ -546,7 +644,7 @@ async function setupAgentSkills(projectDir, options = {}) {
|
|
|
546
644
|
);
|
|
547
645
|
}
|
|
548
646
|
} catch (error) {
|
|
549
|
-
const warning2 = options.onWarning ??
|
|
647
|
+
const warning2 = options.onWarning ?? p5.log.warn;
|
|
550
648
|
const message = error instanceof Error ? error.message : "Unknown error during compatibility setup";
|
|
551
649
|
warning2(`Compatibility setup skipped: ${message}`);
|
|
552
650
|
}
|
|
@@ -554,9 +652,9 @@ async function setupAgentSkills(projectDir, options = {}) {
|
|
|
554
652
|
async function defaultPromptForAgents() {
|
|
555
653
|
const universalAgents = getUniversalAgents();
|
|
556
654
|
const additionalAgents = getNonUniversalAgents();
|
|
557
|
-
|
|
655
|
+
p5.log.message("");
|
|
558
656
|
const selected = await searchMultiselect({
|
|
559
|
-
message: "Which
|
|
657
|
+
message: "Which AI coding agents should this codebase support?",
|
|
560
658
|
items: additionalAgents.map((agent) => ({
|
|
561
659
|
value: agent,
|
|
562
660
|
label: agents[agent].displayName,
|
|
@@ -618,6 +716,16 @@ async function pathExists(path) {
|
|
|
618
716
|
return false;
|
|
619
717
|
}
|
|
620
718
|
}
|
|
719
|
+
var DRUPAL_BLUE = "#009CDE";
|
|
720
|
+
var DRUPAL_NAVY = "#12285F";
|
|
721
|
+
var DRUPAL_PURPLE = "#CCBAF4";
|
|
722
|
+
function commandIntro(commandName) {
|
|
723
|
+
return `${chalk2.bgHex(DRUPAL_BLUE).hex(DRUPAL_NAVY)(" Drupal Canvas ")}${chalk2.bgHex(DRUPAL_PURPLE).hex(DRUPAL_NAVY)(` ${commandName} `)}`;
|
|
724
|
+
}
|
|
725
|
+
function printCommandIntro(commandName) {
|
|
726
|
+
console.log();
|
|
727
|
+
p5.intro(commandIntro(commandName));
|
|
728
|
+
}
|
|
621
729
|
|
|
622
730
|
// src/agents.ts
|
|
623
731
|
function agentsCommand(program2) {
|
|
@@ -627,7 +735,7 @@ function agentsCommand(program2) {
|
|
|
627
735
|
"[agents]",
|
|
628
736
|
'comma-separated list of additional agents to support, or "none" to skip compatibility symlinks'
|
|
629
737
|
).action(async (agentsArg) => {
|
|
630
|
-
|
|
738
|
+
printCommandIntro("create agents");
|
|
631
739
|
try {
|
|
632
740
|
const selectedAgents = parseAgentSelection(agentsArg, "agents");
|
|
633
741
|
const projectDir = process.cwd();
|
|
@@ -635,12 +743,12 @@ function agentsCommand(program2) {
|
|
|
635
743
|
selectedAgents,
|
|
636
744
|
interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY)
|
|
637
745
|
});
|
|
638
|
-
|
|
746
|
+
p5.outro("Agent compatibility setup complete.");
|
|
639
747
|
} catch (error) {
|
|
640
748
|
if (error instanceof Error) {
|
|
641
|
-
|
|
749
|
+
p5.log.error(`Error: ${error.message}`);
|
|
642
750
|
} else {
|
|
643
|
-
|
|
751
|
+
p5.log.error(`Unknown error: ${String(error)}`);
|
|
644
752
|
}
|
|
645
753
|
process.exit(1);
|
|
646
754
|
}
|
|
@@ -665,13 +773,185 @@ function detectPackageManager() {
|
|
|
665
773
|
// package.json
|
|
666
774
|
var package_default = {
|
|
667
775
|
name: "@drupal-canvas/create",
|
|
668
|
-
version: "1.
|
|
776
|
+
version: "1.6.0",
|
|
669
777
|
description: "CLI to scaffold a codebase for working with Drupal Canvas Code Components"};
|
|
670
778
|
|
|
671
779
|
// src/lib/meta-info.ts
|
|
672
780
|
var getName = () => package_default.name;
|
|
673
781
|
var getDescription = () => package_default.description;
|
|
674
782
|
var getVersion = () => package_default.version;
|
|
783
|
+
async function moveTemplateDirectory(repositoryDir, projectDir, repositoryPath) {
|
|
784
|
+
const templateDir = resolve(repositoryDir, repositoryPath);
|
|
785
|
+
const relativeTemplateDir = relative(repositoryDir, templateDir);
|
|
786
|
+
if (!relativeTemplateDir || relativeTemplateDir === ".." || relativeTemplateDir.startsWith(`..${sep}`) || isAbsolute(relativeTemplateDir)) {
|
|
787
|
+
throw new Error(
|
|
788
|
+
`Template repository path "${repositoryPath}" must be a relative path within the repository`
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
let templateStats;
|
|
792
|
+
try {
|
|
793
|
+
templateStats = await lstat(templateDir);
|
|
794
|
+
} catch (error) {
|
|
795
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
796
|
+
throw new Error(
|
|
797
|
+
`Template repository path "${repositoryPath}" does not exist`
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
throw error;
|
|
801
|
+
}
|
|
802
|
+
if (!templateStats.isDirectory()) {
|
|
803
|
+
throw new Error(
|
|
804
|
+
`Template repository path "${repositoryPath}" must point to a directory`
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
try {
|
|
808
|
+
await lstat(projectDir);
|
|
809
|
+
throw new Error(`Project directory "${projectDir}" already exists`);
|
|
810
|
+
} catch (error) {
|
|
811
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") ; else {
|
|
812
|
+
throw error;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
await rename(templateDir, projectDir);
|
|
816
|
+
}
|
|
817
|
+
var ENV_FILENAME = ".env";
|
|
818
|
+
var ENV_EXAMPLE_FILENAME = ".env.example";
|
|
819
|
+
var ENV_VARIABLE = "CANVAS_SITE_URL";
|
|
820
|
+
function isNodeError(error) {
|
|
821
|
+
return error instanceof Error && "code" in error;
|
|
822
|
+
}
|
|
823
|
+
function validateSiteUrl(value) {
|
|
824
|
+
if (!value) return "Canvas site URL is required";
|
|
825
|
+
try {
|
|
826
|
+
const url = new URL(value);
|
|
827
|
+
if ((url.protocol === "http:" || url.protocol === "https:") && url.hostname) {
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
} catch {
|
|
831
|
+
}
|
|
832
|
+
return "Canvas site URL must be an http:// or https:// URL";
|
|
833
|
+
}
|
|
834
|
+
async function ensureEnvIsIgnored(projectDir) {
|
|
835
|
+
const gitignorePath = join(projectDir, ".gitignore");
|
|
836
|
+
let gitignore = "";
|
|
837
|
+
try {
|
|
838
|
+
gitignore = await readFile(gitignorePath, "utf-8");
|
|
839
|
+
} catch (error) {
|
|
840
|
+
if (!isNodeError(error) || error.code !== "ENOENT") {
|
|
841
|
+
throw error;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
const ignoresEnv = gitignore.split(/\r?\n/).some((line) => line.trim() === ENV_FILENAME);
|
|
845
|
+
if (ignoresEnv) return;
|
|
846
|
+
const separator = gitignore.length > 0 && !gitignore.endsWith("\n") ? "\n" : "";
|
|
847
|
+
await writeFile(
|
|
848
|
+
gitignorePath,
|
|
849
|
+
`${gitignore}${separator}${ENV_FILENAME}
|
|
850
|
+
`,
|
|
851
|
+
"utf-8"
|
|
852
|
+
);
|
|
853
|
+
}
|
|
854
|
+
async function readOptionalFile(path) {
|
|
855
|
+
try {
|
|
856
|
+
return await readFile(path, "utf-8");
|
|
857
|
+
} catch (error) {
|
|
858
|
+
if (isNodeError(error) && error.code === "ENOENT") {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
throw error;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
function splitEnv(content) {
|
|
865
|
+
const eol = content.includes("\r\n") ? "\r\n" : "\n";
|
|
866
|
+
const hasFinalEol = content.endsWith("\n");
|
|
867
|
+
const lines = content.split(/\r?\n/);
|
|
868
|
+
if (hasFinalEol) lines.pop();
|
|
869
|
+
return { lines, eol, hasFinalEol };
|
|
870
|
+
}
|
|
871
|
+
function joinEnv({ lines, eol, hasFinalEol }) {
|
|
872
|
+
return `${lines.join(eol)}${hasFinalEol ? eol : ""}`;
|
|
873
|
+
}
|
|
874
|
+
function findAssignments(lines) {
|
|
875
|
+
const assignmentPattern = new RegExp(
|
|
876
|
+
`^(\\s*(?:export\\s+)?${ENV_VARIABLE}\\s*=\\s*)(.*)$`
|
|
877
|
+
);
|
|
878
|
+
return lines.flatMap((line, index) => {
|
|
879
|
+
const match = line.match(assignmentPattern);
|
|
880
|
+
return match ? [{ index, prefix: match[1], value: match[2] }] : [];
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
function setAssignment(env, siteUrl, assignment) {
|
|
884
|
+
const value = `${ENV_VARIABLE}=${JSON.stringify(siteUrl)}`;
|
|
885
|
+
if (assignment) {
|
|
886
|
+
env.lines[assignment.index] = `${assignment.prefix}${JSON.stringify(siteUrl)}`;
|
|
887
|
+
} else if (env.lines.length === 1 && env.lines[0] === "") {
|
|
888
|
+
env.lines[0] = value;
|
|
889
|
+
} else {
|
|
890
|
+
env.lines.push(value);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
function createEnvFromExample(example, siteUrl) {
|
|
894
|
+
const env = splitEnv(example);
|
|
895
|
+
const assignments = findAssignments(env.lines);
|
|
896
|
+
if (assignments.length > 1) {
|
|
897
|
+
throw new Error(
|
|
898
|
+
`${ENV_EXAMPLE_FILENAME} contains more than one ${ENV_VARIABLE} assignment`
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
setAssignment(env, siteUrl, assignments[0]);
|
|
902
|
+
return joinEnv(env);
|
|
903
|
+
}
|
|
904
|
+
function hasConfiguredValue(assignment) {
|
|
905
|
+
const value = assignment.value.trim();
|
|
906
|
+
return value !== "" && value !== '""' && value !== "''" && !value.startsWith("#");
|
|
907
|
+
}
|
|
908
|
+
function updateExistingEnv(content, siteUrl) {
|
|
909
|
+
const env = splitEnv(content);
|
|
910
|
+
const assignments = findAssignments(env.lines);
|
|
911
|
+
const effectiveAssignment = assignments.at(-1);
|
|
912
|
+
if (effectiveAssignment && hasConfiguredValue(effectiveAssignment)) {
|
|
913
|
+
return { content, result: "existing-site-url" };
|
|
914
|
+
}
|
|
915
|
+
setAssignment(env, siteUrl, effectiveAssignment);
|
|
916
|
+
return { content: joinEnv(env), result: "configured-existing" };
|
|
917
|
+
}
|
|
918
|
+
function normalizeSiteUrl(siteUrl) {
|
|
919
|
+
const { protocol, hostname } = new URL(siteUrl);
|
|
920
|
+
if (protocol === "https:" && (hostname === "ddev.site" || hostname.endsWith(".ddev.site"))) {
|
|
921
|
+
return siteUrl.replace(/^https:\/\//i, "http://");
|
|
922
|
+
}
|
|
923
|
+
return siteUrl;
|
|
924
|
+
}
|
|
925
|
+
async function writeSiteUrlEnv(projectDir, siteUrl) {
|
|
926
|
+
const validationError = validateSiteUrl(siteUrl);
|
|
927
|
+
if (validationError) throw new Error(validationError);
|
|
928
|
+
siteUrl = normalizeSiteUrl(siteUrl);
|
|
929
|
+
const envPath = join(projectDir, ENV_FILENAME);
|
|
930
|
+
const existingEnv = await readOptionalFile(envPath);
|
|
931
|
+
if (existingEnv !== void 0) {
|
|
932
|
+
const updated = updateExistingEnv(existingEnv, siteUrl);
|
|
933
|
+
await ensureEnvIsIgnored(projectDir);
|
|
934
|
+
if (updated.content !== existingEnv) {
|
|
935
|
+
await writeFile(envPath, updated.content, "utf-8");
|
|
936
|
+
}
|
|
937
|
+
return updated.result;
|
|
938
|
+
}
|
|
939
|
+
const example = await readOptionalFile(
|
|
940
|
+
join(projectDir, ENV_EXAMPLE_FILENAME)
|
|
941
|
+
);
|
|
942
|
+
const envContent = example === void 0 ? `${ENV_VARIABLE}=${JSON.stringify(siteUrl)}
|
|
943
|
+
` : createEnvFromExample(example, siteUrl);
|
|
944
|
+
await ensureEnvIsIgnored(projectDir);
|
|
945
|
+
try {
|
|
946
|
+
await writeFile(envPath, envContent, { encoding: "utf-8", flag: "wx" });
|
|
947
|
+
} catch (error) {
|
|
948
|
+
if (isNodeError(error) && error.code === "EEXIST") {
|
|
949
|
+
return writeSiteUrlEnv(projectDir, siteUrl);
|
|
950
|
+
}
|
|
951
|
+
throw error;
|
|
952
|
+
}
|
|
953
|
+
return example === void 0 ? "created" : "copied-example";
|
|
954
|
+
}
|
|
675
955
|
var GIT_TERMINAL_PROMPT = 0;
|
|
676
956
|
var unsafe = {
|
|
677
957
|
allowUnsafeEditor: true,
|
|
@@ -684,12 +964,12 @@ var use_git_default = (baseDir) => {
|
|
|
684
964
|
};
|
|
685
965
|
|
|
686
966
|
// src/create.ts
|
|
687
|
-
async function
|
|
688
|
-
const { template,
|
|
689
|
-
const projectDir = `${process.cwd()}/${
|
|
967
|
+
async function createProject(ctx) {
|
|
968
|
+
const { template, projectName, siteUrl, selectedAgents, interactive } = ctx;
|
|
969
|
+
const projectDir = `${process.cwd()}/${projectName}`;
|
|
690
970
|
try {
|
|
691
|
-
const s1 =
|
|
692
|
-
s1.start("Fetching
|
|
971
|
+
const s1 = p5.spinner();
|
|
972
|
+
s1.start("Fetching template");
|
|
693
973
|
const hasCommitSHARef = /^[a-f0-9]{40}$/i.test(template.repository.ref);
|
|
694
974
|
const git = use_git_default();
|
|
695
975
|
const options = {
|
|
@@ -698,32 +978,74 @@ async function createApp(ctx) {
|
|
|
698
978
|
if (template.repository.ref !== "HEAD" && !hasCommitSHARef) {
|
|
699
979
|
options["--branch"] = template.repository.ref;
|
|
700
980
|
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
await
|
|
981
|
+
const repositoryPath = template.repository.path;
|
|
982
|
+
let temporaryCloneDir;
|
|
983
|
+
let cloneDir = projectDir;
|
|
984
|
+
if (repositoryPath) {
|
|
985
|
+
temporaryCloneDir = await mkdtemp(
|
|
986
|
+
join(process.cwd(), ".canvas-template-")
|
|
987
|
+
);
|
|
988
|
+
cloneDir = temporaryCloneDir;
|
|
989
|
+
}
|
|
990
|
+
try {
|
|
991
|
+
await git.clone(template.repository.url, cloneDir, options);
|
|
992
|
+
const gitCloneDir = use_git_default(cloneDir);
|
|
993
|
+
if (hasCommitSHARef) {
|
|
994
|
+
await gitCloneDir.fetch("origin", template.repository.ref);
|
|
995
|
+
await gitCloneDir.checkout(template.repository.ref);
|
|
996
|
+
}
|
|
997
|
+
if (repositoryPath) {
|
|
998
|
+
await moveTemplateDirectory(cloneDir, projectDir, repositoryPath);
|
|
999
|
+
await rimraf(cloneDir);
|
|
1000
|
+
temporaryCloneDir = void 0;
|
|
1001
|
+
}
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
if (temporaryCloneDir) {
|
|
1004
|
+
await rimraf(temporaryCloneDir);
|
|
1005
|
+
}
|
|
1006
|
+
throw error;
|
|
706
1007
|
}
|
|
707
|
-
|
|
1008
|
+
const gitProjectDir = use_git_default(projectDir);
|
|
1009
|
+
await rimraf(join(projectDir, ".git"));
|
|
708
1010
|
const packageJsonPath = join(projectDir, "package.json");
|
|
709
1011
|
const packageJsonContent = await readFile(packageJsonPath, "utf-8");
|
|
710
1012
|
const packageJson = JSON.parse(packageJsonContent);
|
|
711
|
-
packageJson.name =
|
|
1013
|
+
packageJson.name = projectName;
|
|
712
1014
|
await writeFile(
|
|
713
1015
|
packageJsonPath,
|
|
714
1016
|
JSON.stringify(packageJson, null, 2) + "\n"
|
|
715
1017
|
);
|
|
716
|
-
|
|
1018
|
+
const siteUrlEnvResult = siteUrl ? await writeSiteUrlEnv(projectDir, siteUrl) : void 0;
|
|
1019
|
+
s1.stop(chalk2.green("Fetched template"));
|
|
1020
|
+
switch (siteUrlEnvResult) {
|
|
1021
|
+
case "created":
|
|
1022
|
+
p5.log.info("Created .env.");
|
|
1023
|
+
break;
|
|
1024
|
+
case "copied-example":
|
|
1025
|
+
p5.log.info("Created .env from .env.example.");
|
|
1026
|
+
break;
|
|
1027
|
+
case "configured-existing":
|
|
1028
|
+
p5.log.info("Updated .env with CANVAS_SITE_URL.");
|
|
1029
|
+
break;
|
|
1030
|
+
case "existing-site-url":
|
|
1031
|
+
p5.log.info("Kept existing CANVAS_SITE_URL in .env.");
|
|
1032
|
+
break;
|
|
1033
|
+
case void 0:
|
|
1034
|
+
p5.log.warn(
|
|
1035
|
+
"No site URL provided. Set CANVAS_SITE_URL in .env to connect the project to your Drupal site."
|
|
1036
|
+
);
|
|
1037
|
+
break;
|
|
1038
|
+
}
|
|
717
1039
|
await setupAgentSkills(projectDir, {
|
|
718
1040
|
selectedAgents,
|
|
719
|
-
interactive
|
|
1041
|
+
interactive
|
|
720
1042
|
});
|
|
721
|
-
const s2 =
|
|
1043
|
+
const s2 = p5.spinner();
|
|
722
1044
|
const packageManager = detectPackageManager();
|
|
723
|
-
s2.start(`Installing dependencies
|
|
724
|
-
await new Promise((
|
|
1045
|
+
s2.start(`Installing dependencies with ${packageManager}`);
|
|
1046
|
+
await new Promise((resolve2, reject) => {
|
|
725
1047
|
const child = spawn(packageManager, ["install"], {
|
|
726
|
-
cwd: `./${
|
|
1048
|
+
cwd: `./${projectName}`,
|
|
727
1049
|
stdio: ["ignore", "ignore", "pipe"],
|
|
728
1050
|
env: {
|
|
729
1051
|
...process.env,
|
|
@@ -742,35 +1064,48 @@ async function createApp(ctx) {
|
|
|
742
1064
|
if (code !== 0) {
|
|
743
1065
|
reject(
|
|
744
1066
|
new Error(
|
|
745
|
-
`Package installation failed with code ${code}
|
|
1067
|
+
`Package installation failed with code ${code}.
|
|
1068
|
+
Failed command: ${packageManager} install
|
|
1069
|
+
Working directory: ./${projectName}${stderrOutput ? `
|
|
1070
|
+
|
|
746
1071
|
${stderrOutput}` : ""}`
|
|
747
1072
|
)
|
|
748
1073
|
);
|
|
749
1074
|
} else {
|
|
750
|
-
|
|
1075
|
+
resolve2();
|
|
751
1076
|
}
|
|
752
1077
|
});
|
|
753
1078
|
});
|
|
754
|
-
s2.stop(chalk2.green(
|
|
755
|
-
const s3 =
|
|
756
|
-
s3.start("
|
|
757
|
-
await git.init(["--initial-branch=main",
|
|
758
|
-
await
|
|
759
|
-
|
|
760
|
-
|
|
1079
|
+
s2.stop(chalk2.green(`Installed dependencies with ${packageManager}`));
|
|
1080
|
+
const s3 = p5.spinner();
|
|
1081
|
+
s3.start("Initializing Git repository");
|
|
1082
|
+
await git.init(["--initial-branch=main", projectName]);
|
|
1083
|
+
await gitProjectDir.add(["--all"]);
|
|
1084
|
+
const repositoryPathMessage = template.repository.path ? `
|
|
1085
|
+
Path: ${template.repository.path}` : "";
|
|
1086
|
+
await gitProjectDir.commit(
|
|
1087
|
+
`Init project using ${getName()}@${getVersion()}
|
|
761
1088
|
|
|
762
1089
|
Template repository: ${template.repository.url}
|
|
763
|
-
Ref: ${template.repository.ref}`
|
|
1090
|
+
Ref: ${template.repository.ref}${repositoryPathMessage}`
|
|
1091
|
+
);
|
|
1092
|
+
s3.stop(
|
|
1093
|
+
chalk2.green("Initialized Git repository on main with initial commit")
|
|
1094
|
+
);
|
|
1095
|
+
p5.note(
|
|
1096
|
+
`Created project in ./${projectName}
|
|
1097
|
+
|
|
1098
|
+
Next steps:
|
|
1099
|
+
cd ${projectName}
|
|
1100
|
+
${packageManager} run dev`,
|
|
1101
|
+
"Get started"
|
|
764
1102
|
);
|
|
765
|
-
|
|
766
|
-
p4.note(`$ cd ${appName}
|
|
767
|
-
$ ${packageManager} run dev`, "Get started");
|
|
768
|
-
p4.outro("\u{1F680} App created successfully");
|
|
1103
|
+
p5.outro("Canvas project created successfully.");
|
|
769
1104
|
} catch (error) {
|
|
770
1105
|
if (error instanceof Error) {
|
|
771
|
-
|
|
1106
|
+
p5.log.error(`Error: ${error.message}`);
|
|
772
1107
|
} else {
|
|
773
|
-
|
|
1108
|
+
p5.log.error(`Unknown error: ${String(error)}`);
|
|
774
1109
|
}
|
|
775
1110
|
process.exit(1);
|
|
776
1111
|
}
|
|
@@ -789,11 +1124,43 @@ function validateName(name) {
|
|
|
789
1124
|
};
|
|
790
1125
|
}
|
|
791
1126
|
|
|
1127
|
+
// src/lib/slugify-project-name.ts
|
|
1128
|
+
var DEFAULT_PROJECT_NAME = "my-canvas-project";
|
|
1129
|
+
var MAX_PACKAGE_NAME_LENGTH = 214;
|
|
1130
|
+
function slugifyProjectName(siteName) {
|
|
1131
|
+
const slug = slugify(siteName).slice(0, MAX_PACKAGE_NAME_LENGTH).replace(/-+$/g, "");
|
|
1132
|
+
if (!slug || !validateName(slug).valid) {
|
|
1133
|
+
return DEFAULT_PROJECT_NAME;
|
|
1134
|
+
}
|
|
1135
|
+
return slug;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// src/lib/template-resolution.ts
|
|
1139
|
+
function resolveTemplate(templates, identifier) {
|
|
1140
|
+
return templates.find(
|
|
1141
|
+
(template) => template.id === identifier || template.aliases?.includes(identifier)
|
|
1142
|
+
);
|
|
1143
|
+
}
|
|
1144
|
+
function assertUniqueTemplateIdentifiers(templates) {
|
|
1145
|
+
const identifiers = /* @__PURE__ */ new Map();
|
|
1146
|
+
for (const template of templates) {
|
|
1147
|
+
for (const identifier of [template.id, ...template.aliases ?? []]) {
|
|
1148
|
+
const existingTemplateId = identifiers.get(identifier);
|
|
1149
|
+
if (existingTemplateId) {
|
|
1150
|
+
throw new Error(
|
|
1151
|
+
`Template identifier "${identifier}" is used by both "${existingTemplateId}" and "${template.id}"`
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
identifiers.set(identifier, template.id);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
|
|
792
1159
|
// src/index.ts
|
|
793
1160
|
process.on("SIGINT", () => process.exit(0));
|
|
794
1161
|
process.on("SIGTERM", () => process.exit(0));
|
|
795
1162
|
var program = new Command();
|
|
796
|
-
program.name(getName()).description(getDescription()).version(getVersion()).argument("[
|
|
1163
|
+
program.name(getName()).description(getDescription()).version(getVersion()).argument("[project-name]", "name of the project to create").option(
|
|
797
1164
|
"-t, --template <template>",
|
|
798
1165
|
"use template when scaffolding (predefined name or custom Git repository URL)"
|
|
799
1166
|
).option(
|
|
@@ -802,101 +1169,163 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
|
|
|
802
1169
|
).option(
|
|
803
1170
|
"-a, --agents <agents>",
|
|
804
1171
|
'comma-separated list of additional agents to support, or "none" to skip compatibility symlinks'
|
|
805
|
-
).
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
1172
|
+
).option(
|
|
1173
|
+
"--experimental-headless",
|
|
1174
|
+
"enable experimental headless frontend templates"
|
|
1175
|
+
).option(
|
|
1176
|
+
"--site-name <name>",
|
|
1177
|
+
"use slugified site name as the suggested project name"
|
|
1178
|
+
).option(
|
|
1179
|
+
"--site-url <url>",
|
|
1180
|
+
"use Canvas site URL when configuring the project"
|
|
1181
|
+
).action(
|
|
1182
|
+
async (projectNameArg, options) => {
|
|
1183
|
+
printCommandIntro("create");
|
|
1184
|
+
try {
|
|
1185
|
+
const interactive = Boolean(
|
|
1186
|
+
process.stdin.isTTY && process.stdout.isTTY
|
|
812
1187
|
);
|
|
813
|
-
const
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
1188
|
+
const selectedAgents = parseAgentSelection(options.agents);
|
|
1189
|
+
const predefinedTemplates = templates_default;
|
|
1190
|
+
assertUniqueTemplateIdentifiers(predefinedTemplates);
|
|
1191
|
+
const availableTemplates = options.experimentalHeadless ? predefinedTemplates : predefinedTemplates.filter((template2) => !template2.experimental);
|
|
1192
|
+
if (options.template) {
|
|
1193
|
+
const template2 = resolveTemplate(
|
|
1194
|
+
predefinedTemplates,
|
|
1195
|
+
options.template
|
|
1196
|
+
);
|
|
1197
|
+
const isCustomRepositoryUrl = [
|
|
1198
|
+
// Remote repositories.
|
|
1199
|
+
"https://",
|
|
1200
|
+
"http://",
|
|
1201
|
+
"git@",
|
|
1202
|
+
// Local repositories.
|
|
1203
|
+
"../",
|
|
1204
|
+
"./",
|
|
1205
|
+
"/"
|
|
1206
|
+
].some((prefix) => options.template?.startsWith(prefix));
|
|
1207
|
+
if (!template2 && isCustomRepositoryUrl) {
|
|
1208
|
+
predefinedTemplates.push({
|
|
1209
|
+
id: options.template,
|
|
1210
|
+
label: options.template,
|
|
1211
|
+
repository: {
|
|
1212
|
+
url: options.template,
|
|
1213
|
+
ref: "HEAD"
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
} else if (!template2) {
|
|
1217
|
+
p5.log.error(
|
|
1218
|
+
`Template "${options.template}" not found.
|
|
1219
|
+
|
|
1220
|
+
Available templates:
|
|
1221
|
+
${availableTemplates.map((availableTemplate) => `- ${availableTemplate.id}`).join("\n")}`
|
|
1222
|
+
);
|
|
1223
|
+
process.exit(1);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
let projectName = projectNameArg;
|
|
1227
|
+
if (!projectName) {
|
|
1228
|
+
if (!interactive) {
|
|
1229
|
+
p5.log.error("Project name is required in a non-interactive run.");
|
|
1230
|
+
process.exit(1);
|
|
1231
|
+
}
|
|
1232
|
+
const name = await p5.text({
|
|
1233
|
+
message: "Enter the project name",
|
|
1234
|
+
initialValue: options.siteName === void 0 ? DEFAULT_PROJECT_NAME : slugifyProjectName(options.siteName),
|
|
1235
|
+
validate: (value) => {
|
|
1236
|
+
if (!value) return "Project name is required";
|
|
1237
|
+
const { valid, problems } = validateName(value);
|
|
1238
|
+
if (!valid) {
|
|
1239
|
+
return problems.join(", ");
|
|
1240
|
+
}
|
|
1241
|
+
return;
|
|
830
1242
|
}
|
|
831
1243
|
});
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
1244
|
+
if (p5.isCancel(name)) {
|
|
1245
|
+
p5.cancel("Operation cancelled");
|
|
1246
|
+
process.exit(0);
|
|
1247
|
+
}
|
|
1248
|
+
projectName = name;
|
|
1249
|
+
} else {
|
|
1250
|
+
const { valid, problems } = validateName(projectName);
|
|
1251
|
+
if (!valid) {
|
|
1252
|
+
p5.log.error(`Invalid project name: ${problems.join(", ")}`);
|
|
1253
|
+
process.exit(1);
|
|
1254
|
+
}
|
|
835
1255
|
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
if (
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
return problems.join(", ");
|
|
1256
|
+
let siteUrl = options.siteUrl ?? process.env.CANVAS_SITE_URL;
|
|
1257
|
+
if (!siteUrl?.trim()) {
|
|
1258
|
+
if (interactive) {
|
|
1259
|
+
const enteredSiteUrl = await p5.text({
|
|
1260
|
+
message: "Enter the Drupal site URL",
|
|
1261
|
+
validate: (value) => validateSiteUrl(value.trim())
|
|
1262
|
+
});
|
|
1263
|
+
if (p5.isCancel(enteredSiteUrl)) {
|
|
1264
|
+
p5.cancel("Operation cancelled");
|
|
1265
|
+
process.exit(0);
|
|
847
1266
|
}
|
|
848
|
-
|
|
1267
|
+
siteUrl = enteredSiteUrl;
|
|
1268
|
+
} else {
|
|
1269
|
+
siteUrl = void 0;
|
|
849
1270
|
}
|
|
850
|
-
});
|
|
851
|
-
if (p4.isCancel(name)) {
|
|
852
|
-
p4.cancel("Operation cancelled");
|
|
853
|
-
process.exit(0);
|
|
854
1271
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
1272
|
+
if (siteUrl !== void 0) {
|
|
1273
|
+
siteUrl = siteUrl.trim();
|
|
1274
|
+
const siteUrlValidationError = validateSiteUrl(siteUrl);
|
|
1275
|
+
if (siteUrlValidationError) {
|
|
1276
|
+
p5.log.error(siteUrlValidationError);
|
|
1277
|
+
process.exit(1);
|
|
1278
|
+
}
|
|
861
1279
|
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
1280
|
+
let templateId = options.template;
|
|
1281
|
+
if (!templateId) {
|
|
1282
|
+
if (availableTemplates.length === 1) {
|
|
1283
|
+
templateId = availableTemplates[0].id;
|
|
1284
|
+
} else {
|
|
1285
|
+
if (!interactive) {
|
|
1286
|
+
p5.log.error(
|
|
1287
|
+
"Template is required in a non-interactive run. Use --template."
|
|
1288
|
+
);
|
|
1289
|
+
process.exit(1);
|
|
1290
|
+
}
|
|
1291
|
+
const selected = await p5.select({
|
|
1292
|
+
message: "Select a template",
|
|
1293
|
+
options: availableTemplates.map((template2) => ({
|
|
1294
|
+
value: template2.id,
|
|
1295
|
+
label: template2.label
|
|
1296
|
+
}))
|
|
1297
|
+
});
|
|
1298
|
+
if (p5.isCancel(selected)) {
|
|
1299
|
+
p5.cancel("Operation cancelled");
|
|
1300
|
+
process.exit(0);
|
|
1301
|
+
}
|
|
1302
|
+
templateId = selected;
|
|
878
1303
|
}
|
|
879
|
-
templateId = selected;
|
|
880
1304
|
}
|
|
1305
|
+
const template = resolveTemplate(
|
|
1306
|
+
predefinedTemplates,
|
|
1307
|
+
templateId
|
|
1308
|
+
);
|
|
1309
|
+
if (options.ref) {
|
|
1310
|
+
template.repository.ref = options.ref;
|
|
1311
|
+
}
|
|
1312
|
+
await createProject({
|
|
1313
|
+
template,
|
|
1314
|
+
projectName,
|
|
1315
|
+
siteUrl,
|
|
1316
|
+
selectedAgents,
|
|
1317
|
+
interactive
|
|
1318
|
+
});
|
|
1319
|
+
} catch (error) {
|
|
1320
|
+
if (error instanceof Error) {
|
|
1321
|
+
p5.log.error(`Error: ${error.message}`);
|
|
1322
|
+
} else {
|
|
1323
|
+
p5.log.error(`Unknown error: ${String(error)}`);
|
|
1324
|
+
}
|
|
1325
|
+
process.exit(1);
|
|
881
1326
|
}
|
|
882
|
-
const template = templates_default.find(
|
|
883
|
-
(t) => t.id === templateId
|
|
884
|
-
);
|
|
885
|
-
if (options.ref) {
|
|
886
|
-
template.repository.ref = options.ref;
|
|
887
|
-
}
|
|
888
|
-
p4.note(`Template: ${template.label}
|
|
889
|
-
App name: ${appName}`);
|
|
890
|
-
await createApp({ template, appName, selectedAgents });
|
|
891
|
-
} catch (error) {
|
|
892
|
-
if (error instanceof Error) {
|
|
893
|
-
p4.log.error(`Error: ${error.message}`);
|
|
894
|
-
} else {
|
|
895
|
-
p4.log.error(`Unknown error: ${String(error)}`);
|
|
896
|
-
}
|
|
897
|
-
process.exit(1);
|
|
898
1327
|
}
|
|
899
|
-
|
|
1328
|
+
);
|
|
900
1329
|
agentsCommand(program);
|
|
901
1330
|
program.showHelpAfterError();
|
|
902
1331
|
program.showSuggestionAfterError(true);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Experimental features
|
|
2
|
+
|
|
3
|
+
Experimental features may change or be removed without notice.
|
|
4
|
+
|
|
5
|
+
## Headless frontend templates
|
|
6
|
+
|
|
7
|
+
Without `--experimental-headless`, the CLI automatically uses the default
|
|
8
|
+
frontend template when `--template` is omitted.
|
|
9
|
+
|
|
10
|
+
Pass `--experimental-headless` to show all frontend templates in one interactive
|
|
11
|
+
list:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx @drupal-canvas/create@latest --experimental-headless
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```text
|
|
18
|
+
Select a template
|
|
19
|
+
Default frontend
|
|
20
|
+
Next.js
|
|
21
|
+
Astro
|
|
22
|
+
Nuxt
|
|
23
|
+
TanStack Start
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The available experimental template IDs are:
|
|
27
|
+
|
|
28
|
+
| Template ID | Label |
|
|
29
|
+
| ---------------- | -------------- |
|
|
30
|
+
| `nextjs` | Next.js |
|
|
31
|
+
| `astro` | Astro |
|
|
32
|
+
| `nuxt` | Nuxt |
|
|
33
|
+
| `tanstack-start` | TanStack Start |
|
|
34
|
+
|
|
35
|
+
The experimental flag is only needed for interactive discovery. An experimental
|
|
36
|
+
template ID can be provided directly without it:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npx @drupal-canvas/create@latest my-project \
|
|
40
|
+
--template nextjs
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Non-interactive runs using `--experimental-headless` require both the positional
|
|
44
|
+
project name and `--template`, so they do not use the template prompt. Without
|
|
45
|
+
the flag, the default frontend is selected automatically.
|
|
46
|
+
|
|
47
|
+
Experimental templates set `experimental` in `templates.json`. They can share a
|
|
48
|
+
repository by setting a repository-relative `path`:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"id": "nextjs",
|
|
53
|
+
"label": "Next.js",
|
|
54
|
+
"experimental": true,
|
|
55
|
+
"repository": {
|
|
56
|
+
"url": "https://github.com/drupal-canvas/headless-templates.git",
|
|
57
|
+
"ref": "main",
|
|
58
|
+
"path": "nextjs"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drupal-canvas/create",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "CLI to scaffold a codebase for working with Drupal Canvas Code Components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"files": [
|
|
15
15
|
"dist",
|
|
16
|
+
"docs",
|
|
16
17
|
"templates.json",
|
|
17
18
|
"README.md"
|
|
18
19
|
],
|
|
@@ -23,16 +24,17 @@
|
|
|
23
24
|
"create"
|
|
24
25
|
],
|
|
25
26
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
27
|
+
"node": ">=20.0.0"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
30
|
"@clack/prompts": "^0.11.0",
|
|
31
|
+
"@sindresorhus/slugify": "^3.0.0",
|
|
30
32
|
"chalk": "^5.6.2",
|
|
31
33
|
"commander": "^14.0.2",
|
|
32
34
|
"cross-spawn": "^7.0.6",
|
|
33
35
|
"picocolors": "^1.1.1",
|
|
34
36
|
"rimraf": "^6.1.2",
|
|
35
|
-
"simple-git": "^3.
|
|
37
|
+
"simple-git": "^3.36.0",
|
|
36
38
|
"string-width": "^7.2.0",
|
|
37
39
|
"validate-npm-package-name": "^7.0.0"
|
|
38
40
|
},
|
package/templates.json
CHANGED
|
@@ -1,18 +1,51 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
|
-
"id": "
|
|
4
|
-
"
|
|
3
|
+
"id": "default",
|
|
4
|
+
"aliases": ["acquia-nebula"],
|
|
5
|
+
"label": "Default (Canvas-rendered React)",
|
|
5
6
|
"repository": {
|
|
6
7
|
"url": "https://github.com/acquia/nebula.git",
|
|
7
8
|
"ref": "main"
|
|
8
9
|
}
|
|
9
10
|
},
|
|
10
11
|
{
|
|
11
|
-
"id": "
|
|
12
|
-
"label": "
|
|
12
|
+
"id": "nextjs",
|
|
13
|
+
"label": "Next.js",
|
|
14
|
+
"experimental": true,
|
|
13
15
|
"repository": {
|
|
14
|
-
"url": "https://github.com/
|
|
15
|
-
"ref": "main"
|
|
16
|
+
"url": "https://github.com/drupal-canvas/headless-templates.git",
|
|
17
|
+
"ref": "main",
|
|
18
|
+
"path": "nextjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"id": "astro",
|
|
23
|
+
"label": "Astro",
|
|
24
|
+
"experimental": true,
|
|
25
|
+
"repository": {
|
|
26
|
+
"url": "https://github.com/drupal-canvas/headless-templates.git",
|
|
27
|
+
"ref": "main",
|
|
28
|
+
"path": "astro"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"id": "nuxt",
|
|
33
|
+
"label": "Nuxt",
|
|
34
|
+
"experimental": true,
|
|
35
|
+
"repository": {
|
|
36
|
+
"url": "https://github.com/drupal-canvas/headless-templates.git",
|
|
37
|
+
"ref": "main",
|
|
38
|
+
"path": "nuxt"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "tanstack-start",
|
|
43
|
+
"label": "TanStack Start",
|
|
44
|
+
"experimental": true,
|
|
45
|
+
"repository": {
|
|
46
|
+
"url": "https://github.com/drupal-canvas/headless-templates.git",
|
|
47
|
+
"ref": "main",
|
|
48
|
+
"path": "tanstack-start"
|
|
16
49
|
}
|
|
17
50
|
}
|
|
18
51
|
]
|