@drupal-canvas/create 1.3.0 → 1.4.1

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 +111 -72
  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.1",
601
669
  description: "CLI to scaffold a codebase for working with Drupal Canvas Code Components"};
602
670
 
603
671
  // src/lib/meta-info.ts
@@ -605,14 +673,22 @@ var getName = () => package_default.name;
605
673
  var getDescription = () => package_default.description;
606
674
  var getVersion = () => package_default.version;
607
675
  var GIT_TERMINAL_PROMPT = 0;
608
- var use_git_default = (baseDir) => simpleGit(baseDir).env({ ...process.env, GIT_TERMINAL_PROMPT });
676
+ var unsafe = {
677
+ allowUnsafeEditor: true,
678
+ allowUnsafePager: true
679
+ };
680
+ var use_git_default = (baseDir) => {
681
+ const options = { unsafe };
682
+ const git = baseDir === void 0 ? simpleGit(options) : simpleGit(baseDir, options);
683
+ return git.env({ ...process.env, GIT_TERMINAL_PROMPT });
684
+ };
609
685
 
610
686
  // src/create.ts
611
687
  async function createApp(ctx) {
612
688
  const { template, appName, selectedAgents } = ctx;
613
689
  const projectDir = `${process.cwd()}/${appName}`;
614
690
  try {
615
- const s1 = p3.spinner();
691
+ const s1 = p4.spinner();
616
692
  s1.start("Fetching initial codebase");
617
693
  const hasCommitSHARef = /^[a-f0-9]{40}$/i.test(template.repository.ref);
618
694
  const git = use_git_default();
@@ -637,12 +713,12 @@ async function createApp(ctx) {
637
713
  packageJsonPath,
638
714
  JSON.stringify(packageJson, null, 2) + "\n"
639
715
  );
640
- s1.stop(chalk.green("Fetched initial codebase"));
716
+ s1.stop(chalk2.green("Fetched initial codebase"));
641
717
  await setupAgentSkills(projectDir, {
642
718
  selectedAgents,
643
719
  interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY)
644
720
  });
645
- const s2 = p3.spinner();
721
+ const s2 = p4.spinner();
646
722
  const packageManager = detectPackageManager();
647
723
  s2.start(`Installing dependencies using ${packageManager}`);
648
724
  await new Promise((resolve, reject) => {
@@ -675,8 +751,8 @@ ${stderrOutput}` : ""}`
675
751
  }
676
752
  });
677
753
  });
678
- s2.stop(chalk.green("Installed dependencies"));
679
- const s3 = p3.spinner();
754
+ s2.stop(chalk2.green("Installed dependencies"));
755
+ const s3 = p4.spinner();
680
756
  s3.start("Preparing your repository");
681
757
  await git.init(["--initial-branch=main", appName]);
682
758
  await gitAppDir.add(["--all"]);
@@ -686,57 +762,19 @@ ${stderrOutput}` : ""}`
686
762
  Template repository: ${template.repository.url}
687
763
  Ref: ${template.repository.ref}`
688
764
  );
689
- s3.stop(chalk.green("Prepared repository"));
690
- p3.note(`$ cd ${appName}
765
+ s3.stop(chalk2.green("Prepared repository"));
766
+ p4.note(`$ cd ${appName}
691
767
  $ ${packageManager} run dev`, "Get started");
692
- p3.outro("\u{1F680} App created successfully");
768
+ p4.outro("\u{1F680} App created successfully");
693
769
  } catch (error) {
694
770
  if (error instanceof Error) {
695
- p3.log.error(`Error: ${error.message}`);
771
+ p4.log.error(`Error: ${error.message}`);
696
772
  } else {
697
- p3.log.error(`Unknown error: ${String(error)}`);
773
+ p4.log.error(`Unknown error: ${String(error)}`);
698
774
  }
699
775
  process.exit(1);
700
776
  }
701
777
  }
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
778
  function validateName(name) {
741
779
  const nameValidation = validate(name);
742
780
  if (nameValidation.validForNewPackages) {
@@ -765,7 +803,7 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
765
803
  "-a, --agents <agents>",
766
804
  'comma-separated list of additional agents to support, or "none" to skip compatibility symlinks'
767
805
  ).action(async (appNameArg, options) => {
768
- p3.intro(chalk.bold("Drupal Canvas Create"));
806
+ p4.intro(chalk2.bold("Drupal Canvas Create"));
769
807
  try {
770
808
  const selectedAgents = parseAgentSelection(options.agents);
771
809
  if (options.template) {
@@ -792,13 +830,13 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
792
830
  }
793
831
  });
794
832
  } else if (!template2) {
795
- p3.log.error(`Template "${options.template}" not found`);
833
+ p4.log.error(`Template "${options.template}" not found`);
796
834
  process.exit(1);
797
835
  }
798
836
  }
799
837
  let appName = appNameArg;
800
838
  if (!appName) {
801
- const name = await p3.text({
839
+ const name = await p4.text({
802
840
  message: "Enter the app name",
803
841
  initialValue: "my-canvas-app",
804
842
  validate: (value) => {
@@ -810,15 +848,15 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
810
848
  return;
811
849
  }
812
850
  });
813
- if (p3.isCancel(name)) {
814
- p3.cancel("Operation cancelled");
851
+ if (p4.isCancel(name)) {
852
+ p4.cancel("Operation cancelled");
815
853
  process.exit(0);
816
854
  }
817
855
  appName = name;
818
856
  } else {
819
857
  const { valid, problems } = validateName(appName);
820
858
  if (!valid) {
821
- p3.log.error(`Invalid app name: ${problems.join(", ")}`);
859
+ p4.log.error(`Invalid app name: ${problems.join(", ")}`);
822
860
  process.exit(1);
823
861
  }
824
862
  }
@@ -827,15 +865,15 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
827
865
  if (templates_default.length === 1) {
828
866
  templateId = templates_default[0].id;
829
867
  } else {
830
- const selected = await p3.select({
868
+ const selected = await p4.select({
831
869
  message: "Select a template",
832
870
  options: templates_default.map((t, index) => ({
833
871
  value: t.id,
834
872
  label: index === 0 ? `${t.label} (Recommended)` : t.label
835
873
  }))
836
874
  });
837
- if (p3.isCancel(selected)) {
838
- p3.cancel("Operation cancelled");
875
+ if (p4.isCancel(selected)) {
876
+ p4.cancel("Operation cancelled");
839
877
  process.exit(0);
840
878
  }
841
879
  templateId = selected;
@@ -847,25 +885,26 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
847
885
  if (options.ref) {
848
886
  template.repository.ref = options.ref;
849
887
  }
850
- p3.note(`Template: ${template.label}
888
+ p4.note(`Template: ${template.label}
851
889
  App name: ${appName}`);
852
890
  await createApp({ template, appName, selectedAgents });
853
891
  } catch (error) {
854
892
  if (error instanceof Error) {
855
- p3.log.error(`Error: ${error.message}`);
893
+ p4.log.error(`Error: ${error.message}`);
856
894
  } else {
857
- p3.log.error(`Unknown error: ${String(error)}`);
895
+ p4.log.error(`Unknown error: ${String(error)}`);
858
896
  }
859
897
  process.exit(1);
860
898
  }
861
899
  });
900
+ agentsCommand(program);
862
901
  program.showHelpAfterError();
863
902
  program.showSuggestionAfterError(true);
864
903
  try {
865
904
  await program.parseAsync(process.argv);
866
905
  } catch (error) {
867
906
  if (error instanceof Error) {
868
- console.error(chalk.red(`Error: ${error.message}`));
907
+ console.error(chalk2.red(`Error: ${error.message}`));
869
908
  process.exit(1);
870
909
  }
871
910
  }
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.1",
4
4
  "description": "CLI to scaffold a codebase for working with Drupal Canvas Code Components",
5
5
  "license": "MIT",
6
6
  "repository": {