@drupal-canvas/create 1.3.0 → 1.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 (3) hide show
  1. package/README.md +21 -0
  2. package/dist/index.js +102 -71
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -57,6 +57,27 @@ npx @drupal-canvas/create@latest my-app --template acquia-nebula --agents claude
57
57
  If `--agents` is omitted, the CLI keeps the current interactive prompt on TTY
58
58
  runs. On non-interactive runs, it skips compatibility setup silently.
59
59
 
60
+ ### `agents` command
61
+
62
+ Set up compatibility symlinks for additional agent skills directories in an
63
+ existing project:
64
+
65
+ ```bash
66
+ npx @drupal-canvas/create@latest agents
67
+ ```
68
+
69
+ You can also provide the agents as an argument:
70
+
71
+ ```bash
72
+ npx @drupal-canvas/create@latest agents claude-code,roo
73
+ ```
74
+
75
+ Skip compatibility symlinks:
76
+
77
+ ```bash
78
+ npx @drupal-canvas/create@latest agents none
79
+ ```
80
+
60
81
  ## Development
61
82
 
62
83
  Drupal Canvas Create is designed to be easily extendable with new templates.
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env node
2
- import chalk from 'chalk';
2
+ import chalk2 from 'chalk';
3
3
  import { Command } from 'commander';
4
- import * as p3 from '@clack/prompts';
4
+ import * as p4 from '@clack/prompts';
5
5
  import { readFile, writeFile, access, readdir, mkdir, symlink } from 'fs/promises';
6
- import { join, dirname, relative } from 'path';
7
- import spawn from 'cross-spawn';
8
- import { rimraf } from 'rimraf';
9
6
  import { platform } from 'os';
7
+ import { join, dirname, relative } from 'path';
10
8
  import * as readline from 'readline';
11
9
  import { Writable } from 'stream';
12
10
  import pc from 'picocolors';
11
+ import spawn from 'cross-spawn';
12
+ import { rimraf } from 'rimraf';
13
13
  import { simpleGit } from 'simple-git';
14
14
  import validate from 'validate-npm-package-name';
15
15
 
@@ -226,6 +226,44 @@ function isUniversalAgent(type) {
226
226
  function isAgentType(value) {
227
227
  return Object.prototype.hasOwnProperty.call(agents, value);
228
228
  }
229
+
230
+ // src/lib/agent-selection.ts
231
+ var NONE_VALUE = "none";
232
+ function parseAgentSelection(value, label = "--agents") {
233
+ if (value === void 0) {
234
+ return void 0;
235
+ }
236
+ const selectedAgents = Array.from(
237
+ new Set(
238
+ value.split(",").map((agent) => agent.trim()).filter(Boolean)
239
+ )
240
+ );
241
+ if (selectedAgents.length === 0) {
242
+ throw new Error(
243
+ `Invalid ${label} value. Provide a comma-separated list or "none".`
244
+ );
245
+ }
246
+ if (selectedAgents.includes(NONE_VALUE)) {
247
+ if (selectedAgents.length > 1) {
248
+ throw new Error(
249
+ `Invalid ${label} value. "none" cannot be combined with other agents.`
250
+ );
251
+ }
252
+ return [];
253
+ }
254
+ const nonUniversalAgents = new Set(getNonUniversalAgents());
255
+ return selectedAgents.map((agent) => {
256
+ if (!isAgentType(agent)) {
257
+ throw new Error(`Invalid ${label} value. Unknown agent "${agent}".`);
258
+ }
259
+ if (isUniversalAgent(agent) || !nonUniversalAgents.has(agent)) {
260
+ throw new Error(
261
+ `Invalid ${label} value. Agent "${agent}" already uses .agents/skills.`
262
+ );
263
+ }
264
+ return agent;
265
+ });
266
+ }
229
267
  var silentOutput = new Writable({
230
268
  write(_chunk, _encoding, callback) {
231
269
  callback();
@@ -443,8 +481,8 @@ function pluralize(word, count) {
443
481
  // src/lib/agent-skills-setup.ts
444
482
  var DEFAULT_SKILLS_DIR = ".agents/skills";
445
483
  async function setupAgentSkills(projectDir, options = {}) {
446
- const info = options.onInfo ?? p3.log.info;
447
- const warning = options.onWarning ?? p3.log.warn;
484
+ const info = options.onInfo ?? p4.log.info;
485
+ const warning = options.onWarning ?? p4.log.warn;
448
486
  const interactive = options.interactive ?? true;
449
487
  const hasExplicitSelection = options.selectedAgents !== void 0;
450
488
  try {
@@ -454,6 +492,7 @@ async function setupAgentSkills(projectDir, options = {}) {
454
492
  const canonicalSkillsDir = join(projectDir, DEFAULT_SKILLS_DIR);
455
493
  const hasSkillsDir = await pathExists(canonicalSkillsDir);
456
494
  if (!hasSkillsDir) {
495
+ info("No .agents/skills directory found. Skipping compatibility setup.");
457
496
  return;
458
497
  }
459
498
  const skillNames = await discoverSkillNames(canonicalSkillsDir);
@@ -466,7 +505,7 @@ async function setupAgentSkills(projectDir, options = {}) {
466
505
  const promptForAgents = options.promptForAgents ?? defaultPromptForAgents;
467
506
  selected = await promptForAgents();
468
507
  }
469
- if (p3.isCancel(selected) || typeof selected === "symbol") {
508
+ if (p4.isCancel(selected) || typeof selected === "symbol") {
470
509
  info("Skipped compatibility setup.");
471
510
  return;
472
511
  }
@@ -507,7 +546,7 @@ async function setupAgentSkills(projectDir, options = {}) {
507
546
  );
508
547
  }
509
548
  } catch (error) {
510
- const warning2 = options.onWarning ?? p3.log.warn;
549
+ const warning2 = options.onWarning ?? p4.log.warn;
511
550
  const message = error instanceof Error ? error.message : "Unknown error during compatibility setup";
512
551
  warning2(`Compatibility setup skipped: ${message}`);
513
552
  }
@@ -515,6 +554,7 @@ async function setupAgentSkills(projectDir, options = {}) {
515
554
  async function defaultPromptForAgents() {
516
555
  const universalAgents = getUniversalAgents();
517
556
  const additionalAgents = getNonUniversalAgents();
557
+ p4.log.message("");
518
558
  const selected = await searchMultiselect({
519
559
  message: "Which additional agents should this codebase support?",
520
560
  items: additionalAgents.map((agent) => ({
@@ -579,6 +619,34 @@ async function pathExists(path) {
579
619
  }
580
620
  }
581
621
 
622
+ // src/agents.ts
623
+ function agentsCommand(program2) {
624
+ program2.command("agents").description(
625
+ "set up compatibility symlinks for additional agent skills directories"
626
+ ).argument(
627
+ "[agents]",
628
+ 'comma-separated list of additional agents to support, or "none" to skip compatibility symlinks'
629
+ ).action(async (agentsArg) => {
630
+ p4.intro(chalk2.bold("Drupal Canvas Create - agents setup"));
631
+ try {
632
+ const selectedAgents = parseAgentSelection(agentsArg, "agents");
633
+ const projectDir = process.cwd();
634
+ await setupAgentSkills(projectDir, {
635
+ selectedAgents,
636
+ interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY)
637
+ });
638
+ p4.outro("\u{1F916} Done.");
639
+ } catch (error) {
640
+ if (error instanceof Error) {
641
+ p4.log.error(`Error: ${error.message}`);
642
+ } else {
643
+ p4.log.error(`Unknown error: ${String(error)}`);
644
+ }
645
+ process.exit(1);
646
+ }
647
+ });
648
+ }
649
+
582
650
  // src/lib/detect-package-manager.ts
583
651
  function detectPackageManager() {
584
652
  const userAgent = process.env.npm_config_user_agent || "";
@@ -597,7 +665,7 @@ function detectPackageManager() {
597
665
  // package.json
598
666
  var package_default = {
599
667
  name: "@drupal-canvas/create",
600
- version: "1.3.0",
668
+ version: "1.4.0",
601
669
  description: "CLI to scaffold a codebase for working with Drupal Canvas Code Components"};
602
670
 
603
671
  // src/lib/meta-info.ts
@@ -612,7 +680,7 @@ async function createApp(ctx) {
612
680
  const { template, appName, selectedAgents } = ctx;
613
681
  const projectDir = `${process.cwd()}/${appName}`;
614
682
  try {
615
- const s1 = p3.spinner();
683
+ const s1 = p4.spinner();
616
684
  s1.start("Fetching initial codebase");
617
685
  const hasCommitSHARef = /^[a-f0-9]{40}$/i.test(template.repository.ref);
618
686
  const git = use_git_default();
@@ -637,12 +705,12 @@ async function createApp(ctx) {
637
705
  packageJsonPath,
638
706
  JSON.stringify(packageJson, null, 2) + "\n"
639
707
  );
640
- s1.stop(chalk.green("Fetched initial codebase"));
708
+ s1.stop(chalk2.green("Fetched initial codebase"));
641
709
  await setupAgentSkills(projectDir, {
642
710
  selectedAgents,
643
711
  interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY)
644
712
  });
645
- const s2 = p3.spinner();
713
+ const s2 = p4.spinner();
646
714
  const packageManager = detectPackageManager();
647
715
  s2.start(`Installing dependencies using ${packageManager}`);
648
716
  await new Promise((resolve, reject) => {
@@ -675,8 +743,8 @@ ${stderrOutput}` : ""}`
675
743
  }
676
744
  });
677
745
  });
678
- s2.stop(chalk.green("Installed dependencies"));
679
- const s3 = p3.spinner();
746
+ s2.stop(chalk2.green("Installed dependencies"));
747
+ const s3 = p4.spinner();
680
748
  s3.start("Preparing your repository");
681
749
  await git.init(["--initial-branch=main", appName]);
682
750
  await gitAppDir.add(["--all"]);
@@ -686,57 +754,19 @@ ${stderrOutput}` : ""}`
686
754
  Template repository: ${template.repository.url}
687
755
  Ref: ${template.repository.ref}`
688
756
  );
689
- s3.stop(chalk.green("Prepared repository"));
690
- p3.note(`$ cd ${appName}
757
+ s3.stop(chalk2.green("Prepared repository"));
758
+ p4.note(`$ cd ${appName}
691
759
  $ ${packageManager} run dev`, "Get started");
692
- p3.outro("\u{1F680} App created successfully");
760
+ p4.outro("\u{1F680} App created successfully");
693
761
  } catch (error) {
694
762
  if (error instanceof Error) {
695
- p3.log.error(`Error: ${error.message}`);
763
+ p4.log.error(`Error: ${error.message}`);
696
764
  } else {
697
- p3.log.error(`Unknown error: ${String(error)}`);
765
+ p4.log.error(`Unknown error: ${String(error)}`);
698
766
  }
699
767
  process.exit(1);
700
768
  }
701
769
  }
702
-
703
- // src/lib/agent-selection.ts
704
- var NONE_VALUE = "none";
705
- function parseAgentSelection(value) {
706
- if (value === void 0) {
707
- return void 0;
708
- }
709
- const selectedAgents = Array.from(
710
- new Set(
711
- value.split(",").map((agent) => agent.trim()).filter(Boolean)
712
- )
713
- );
714
- if (selectedAgents.length === 0) {
715
- throw new Error(
716
- 'Invalid --agents value. Provide a comma-separated list or "none".'
717
- );
718
- }
719
- if (selectedAgents.includes(NONE_VALUE)) {
720
- if (selectedAgents.length > 1) {
721
- throw new Error(
722
- 'Invalid --agents value. "none" cannot be combined with other agents.'
723
- );
724
- }
725
- return [];
726
- }
727
- const nonUniversalAgents = new Set(getNonUniversalAgents());
728
- return selectedAgents.map((agent) => {
729
- if (!isAgentType(agent)) {
730
- throw new Error(`Invalid --agents value. Unknown agent "${agent}".`);
731
- }
732
- if (isUniversalAgent(agent) || !nonUniversalAgents.has(agent)) {
733
- throw new Error(
734
- `Invalid --agents value. Agent "${agent}" already uses .agents/skills.`
735
- );
736
- }
737
- return agent;
738
- });
739
- }
740
770
  function validateName(name) {
741
771
  const nameValidation = validate(name);
742
772
  if (nameValidation.validForNewPackages) {
@@ -765,7 +795,7 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
765
795
  "-a, --agents <agents>",
766
796
  'comma-separated list of additional agents to support, or "none" to skip compatibility symlinks'
767
797
  ).action(async (appNameArg, options) => {
768
- p3.intro(chalk.bold("Drupal Canvas Create"));
798
+ p4.intro(chalk2.bold("Drupal Canvas Create"));
769
799
  try {
770
800
  const selectedAgents = parseAgentSelection(options.agents);
771
801
  if (options.template) {
@@ -792,13 +822,13 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
792
822
  }
793
823
  });
794
824
  } else if (!template2) {
795
- p3.log.error(`Template "${options.template}" not found`);
825
+ p4.log.error(`Template "${options.template}" not found`);
796
826
  process.exit(1);
797
827
  }
798
828
  }
799
829
  let appName = appNameArg;
800
830
  if (!appName) {
801
- const name = await p3.text({
831
+ const name = await p4.text({
802
832
  message: "Enter the app name",
803
833
  initialValue: "my-canvas-app",
804
834
  validate: (value) => {
@@ -810,15 +840,15 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
810
840
  return;
811
841
  }
812
842
  });
813
- if (p3.isCancel(name)) {
814
- p3.cancel("Operation cancelled");
843
+ if (p4.isCancel(name)) {
844
+ p4.cancel("Operation cancelled");
815
845
  process.exit(0);
816
846
  }
817
847
  appName = name;
818
848
  } else {
819
849
  const { valid, problems } = validateName(appName);
820
850
  if (!valid) {
821
- p3.log.error(`Invalid app name: ${problems.join(", ")}`);
851
+ p4.log.error(`Invalid app name: ${problems.join(", ")}`);
822
852
  process.exit(1);
823
853
  }
824
854
  }
@@ -827,15 +857,15 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
827
857
  if (templates_default.length === 1) {
828
858
  templateId = templates_default[0].id;
829
859
  } else {
830
- const selected = await p3.select({
860
+ const selected = await p4.select({
831
861
  message: "Select a template",
832
862
  options: templates_default.map((t, index) => ({
833
863
  value: t.id,
834
864
  label: index === 0 ? `${t.label} (Recommended)` : t.label
835
865
  }))
836
866
  });
837
- if (p3.isCancel(selected)) {
838
- p3.cancel("Operation cancelled");
867
+ if (p4.isCancel(selected)) {
868
+ p4.cancel("Operation cancelled");
839
869
  process.exit(0);
840
870
  }
841
871
  templateId = selected;
@@ -847,25 +877,26 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
847
877
  if (options.ref) {
848
878
  template.repository.ref = options.ref;
849
879
  }
850
- p3.note(`Template: ${template.label}
880
+ p4.note(`Template: ${template.label}
851
881
  App name: ${appName}`);
852
882
  await createApp({ template, appName, selectedAgents });
853
883
  } catch (error) {
854
884
  if (error instanceof Error) {
855
- p3.log.error(`Error: ${error.message}`);
885
+ p4.log.error(`Error: ${error.message}`);
856
886
  } else {
857
- p3.log.error(`Unknown error: ${String(error)}`);
887
+ p4.log.error(`Unknown error: ${String(error)}`);
858
888
  }
859
889
  process.exit(1);
860
890
  }
861
891
  });
892
+ agentsCommand(program);
862
893
  program.showHelpAfterError();
863
894
  program.showSuggestionAfterError(true);
864
895
  try {
865
896
  await program.parseAsync(process.argv);
866
897
  } catch (error) {
867
898
  if (error instanceof Error) {
868
- console.error(chalk.red(`Error: ${error.message}`));
899
+ console.error(chalk2.red(`Error: ${error.message}`));
869
900
  process.exit(1);
870
901
  }
871
902
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drupal-canvas/create",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "CLI to scaffold a codebase for working with Drupal Canvas Code Components",
5
5
  "license": "MIT",
6
6
  "repository": {