@drupal-canvas/cli 0.5.1 → 0.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/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { Command } from 'commander';
4
4
  import * as p from '@clack/prompts';
5
5
  import * as fs from 'fs';
6
6
  import fs__default, { realpathSync as realpathSync$1, readlinkSync, readdirSync, readdir as readdir$1, lstatSync, promises } from 'fs';
7
- import path3, { win32, posix } from 'path';
7
+ import path11, { win32, posix } from 'path';
8
8
  import dotenv from 'dotenv';
9
9
  import { transform, Features } from 'lightningcss';
10
10
  import axios from 'axios';
@@ -25,16 +25,16 @@ import { parse } from '@babel/parser';
25
25
 
26
26
  // package.json
27
27
  var package_default = {
28
- version: "0.5.1"};
28
+ version: "0.6.0"};
29
29
  function loadEnvFiles() {
30
30
  const homeDir = process.env.HOME || process.env.USERPROFILE || "";
31
31
  if (homeDir) {
32
- const homeEnvPath = path3.resolve(homeDir, ".canvasrc");
32
+ const homeEnvPath = path11.resolve(homeDir, ".canvasrc");
33
33
  if (fs__default.existsSync(homeEnvPath)) {
34
34
  dotenv.config({ path: homeEnvPath });
35
35
  }
36
36
  }
37
- const localEnvPath = path3.resolve(process.cwd(), ".env");
37
+ const localEnvPath = path11.resolve(process.cwd(), ".env");
38
38
  if (fs__default.existsSync(localEnvPath)) {
39
39
  dotenv.config({ path: localEnvPath });
40
40
  }
@@ -10805,17 +10805,17 @@ function createApiService() {
10805
10805
  userAgent: config2.userAgent
10806
10806
  });
10807
10807
  }
10808
- var CANVAS_CACHE_DIR = path3.join(os.homedir(), ".canvas");
10808
+ var CANVAS_CACHE_DIR = path11.join(os.homedir(), ".canvas");
10809
10809
  async function downloadJsSourceFromCanvas(componentsToDownload) {
10810
10810
  for (const key in componentsToDownload) {
10811
10811
  const component = componentsToDownload[key];
10812
10812
  try {
10813
- const componentDir = path3.join(CANVAS_CACHE_DIR, component.machineName);
10813
+ const componentDir = path11.join(CANVAS_CACHE_DIR, component.machineName);
10814
10814
  await fs2.rm(componentDir, { recursive: true, force: true });
10815
10815
  await fs2.mkdir(componentDir, { recursive: true });
10816
10816
  if (component.sourceCodeJs) {
10817
10817
  await fs2.writeFile(
10818
- path3.join(componentDir, `index.jsx`),
10818
+ path11.join(componentDir, `index.jsx`),
10819
10819
  component.sourceCodeJs,
10820
10820
  "utf-8"
10821
10821
  );
@@ -10833,14 +10833,14 @@ async function copyLocalJsSource(componentsToCopy) {
10833
10833
  try {
10834
10834
  await fs2.mkdir(CANVAS_CACHE_DIR, { recursive: true });
10835
10835
  for (const componentPath of componentsToCopy) {
10836
- const baseName = path3.basename(componentPath);
10836
+ const baseName = path11.basename(componentPath);
10837
10837
  const sourcePath = componentPath;
10838
- const targetPath = path3.join(CANVAS_CACHE_DIR, baseName);
10838
+ const targetPath = path11.join(CANVAS_CACHE_DIR, baseName);
10839
10839
  const stats = await fs2.stat(sourcePath);
10840
10840
  if (stats.isDirectory()) {
10841
10841
  await fs2.mkdir(targetPath, { recursive: true });
10842
- const sourceFile = path3.join(sourcePath, "index.jsx");
10843
- const targetFile = path3.join(targetPath, "index.jsx");
10842
+ const sourceFile = path11.join(sourcePath, "index.jsx");
10843
+ const targetFile = path11.join(targetPath, "index.jsx");
10844
10844
  await fs2.copyFile(sourceFile, targetFile);
10845
10845
  }
10846
10846
  }
@@ -10858,7 +10858,7 @@ async function cleanUpCacheDirectory() {
10858
10858
  withFileTypes: true
10859
10859
  });
10860
10860
  for (const entry of cacheEntries) {
10861
- const entryPath = path3.join(CANVAS_CACHE_DIR, entry.name);
10861
+ const entryPath = path11.join(CANVAS_CACHE_DIR, entry.name);
10862
10862
  if (entry.isDirectory()) {
10863
10863
  await fs2.rm(entryPath, { recursive: true, force: true });
10864
10864
  } else {
@@ -10873,32 +10873,8 @@ async function cleanUpCacheDirectory() {
10873
10873
  );
10874
10874
  }
10875
10875
  }
10876
- async function fileExists(filePath) {
10877
- try {
10878
- await fs2.access(filePath);
10879
- return true;
10880
- } catch {
10881
- return false;
10882
- }
10883
- }
10884
- async function directoryExists(dirPath) {
10885
- return await fs2.stat(dirPath).then(() => true).catch(() => false);
10886
- }
10887
10876
 
10888
10877
  // src/utils/build-tailwind.ts
10889
- async function downloadGlobalCssInBackground() {
10890
- const apiService = await createApiService();
10891
- const globalAssetLibrary = await apiService.getGlobalAssetLibrary();
10892
- return globalAssetLibrary.css.original;
10893
- }
10894
- async function getGlobalCss(useLocal = true) {
10895
- const config2 = getConfig();
10896
- const localGlobalCssPath = path3.join(config2.componentDir, "global.css");
10897
- if (useLocal && await fileExists(localGlobalCssPath)) {
10898
- return await promises.readFile(localGlobalCssPath, "utf-8");
10899
- }
10900
- return await downloadGlobalCssInBackground();
10901
- }
10902
10878
  async function getAllClassNameCandidatesFromCacheDir(componentsToDownload, localComponentsToCopy) {
10903
10879
  if (Object.keys(componentsToDownload).length > 0) {
10904
10880
  await downloadJsSourceFromCanvas(componentsToDownload);
@@ -10907,7 +10883,7 @@ async function getAllClassNameCandidatesFromCacheDir(componentsToDownload, local
10907
10883
  const cacheEntries = await promises.readdir(CANVAS_CACHE_DIR, {
10908
10884
  withFileTypes: true
10909
10885
  });
10910
- const cacheDirs = cacheEntries.filter((entry) => entry.isDirectory()).map((dir) => path3.join(CANVAS_CACHE_DIR, dir.name));
10886
+ const cacheDirs = cacheEntries.filter((entry) => entry.isDirectory()).map((dir) => path11.join(CANVAS_CACHE_DIR, dir.name));
10911
10887
  let allClassNameCandidates = [];
10912
10888
  for (const cacheDir of cacheDirs) {
10913
10889
  const componentClassNameCandidates = await getClassNameCandidatesForComponent(cacheDir);
@@ -10925,16 +10901,16 @@ async function buildTailwindCss(classNameCandidates, globalSourceCodeCss, distDi
10925
10901
  globalSourceCodeCss
10926
10902
  );
10927
10903
  const transformedTwCss = await transformCss(compiledTwCss);
10928
- await promises.writeFile(path3.join(distDir, "index.css"), transformedTwCss);
10904
+ await promises.writeFile(path11.join(distDir, "index.css"), transformedTwCss);
10929
10905
  }
10930
10906
  async function getClassNameCandidatesForComponent(dir) {
10931
- const componentName = path3.basename(dir);
10907
+ const componentName = path11.basename(dir);
10932
10908
  const config2 = getConfig();
10933
10909
  const componentsDir = config2.componentDir;
10934
- const distDir = path3.join(componentsDir, "dist");
10935
- const jsSource = await promises.readFile(path3.join(dir, "index.jsx"), "utf-8");
10910
+ const distDir = path11.join(componentsDir, "dist");
10911
+ const jsSource = await promises.readFile(path11.join(dir, "index.jsx"), "utf-8");
10936
10912
  const currentGlobalSourceCodeJs = await promises.readFile(
10937
- path3.join(distDir, "index.js"),
10913
+ path11.join(distDir, "index.js"),
10938
10914
  "utf-8"
10939
10915
  );
10940
10916
  const classNameCandidates = OE(jsSource);
@@ -10943,20 +10919,20 @@ async function getClassNameCandidatesForComponent(dir) {
10943
10919
  componentName,
10944
10920
  classNameCandidates
10945
10921
  );
10946
- await promises.writeFile(path3.join(distDir, "index.js"), globalJSClassNameIndex);
10922
+ await promises.writeFile(path11.join(distDir, "index.js"), globalJSClassNameIndex);
10947
10923
  return nextClassNameCandidates;
10948
10924
  }
10949
- async function buildTailwindForComponents(selectedComponents, useLocalGlobalCss = true) {
10925
+ async function buildTailwindForComponents(selectedComponents) {
10950
10926
  try {
10951
10927
  const config2 = getConfig();
10952
10928
  const apiService = await createApiService();
10953
10929
  const onlineComponents = await apiService.listComponents();
10954
- const globalSourceCodeCss = await getGlobalCss(useLocalGlobalCss);
10955
10930
  const globalAssetLibrary = await apiService.getGlobalAssetLibrary();
10956
10931
  const globalSourceCodeJs = globalAssetLibrary.js.original;
10957
- const distDir = path3.join(config2.componentDir, "dist");
10932
+ const globalSourceCodeCss = globalAssetLibrary.css.original;
10933
+ const distDir = path11.join(config2.componentDir, "dist");
10958
10934
  await promises.mkdir(distDir, { recursive: true });
10959
- const targetFile = path3.join(distDir, "index.js");
10935
+ const targetFile = path11.join(distDir, "index.js");
10960
10936
  await promises.writeFile(targetFile, globalSourceCodeJs, "utf-8");
10961
10937
  const allClassNameCandidates = await getAllClassNameCandidatesFromCacheDir(
10962
10938
  onlineComponents,
@@ -11008,6 +10984,17 @@ function compileJS(source) {
11008
10984
  const { code } = transformSync(source, SWC_OPTIONS);
11009
10985
  return code;
11010
10986
  }
10987
+ async function fileExists(filePath) {
10988
+ try {
10989
+ await fs2.access(filePath);
10990
+ return true;
10991
+ } catch {
10992
+ return false;
10993
+ }
10994
+ }
10995
+ async function directoryExists(dirPath) {
10996
+ return await fs2.stat(dirPath).then(() => true).catch(() => false);
10997
+ }
11011
10998
  async function validateComponent(componentDir, fix = false) {
11012
10999
  const eslint = new ESLint({
11013
11000
  overrideConfigFile: true,
@@ -11025,7 +11012,7 @@ async function validateComponent(componentDir, fix = false) {
11025
11012
  (msg) => `Line ${msg.line}, Column ${msg.column}: ` + msg.message + (msg.ruleId ? ` (${msg.ruleId})` : "")
11026
11013
  );
11027
11014
  details.push({
11028
- heading: path3.relative(process.cwd(), result.filePath),
11015
+ heading: path11.relative(process.cwd(), result.filePath),
11029
11016
  content: messages.join("\n\n")
11030
11017
  });
11031
11018
  });
@@ -11037,8 +11024,8 @@ async function validateComponent(componentDir, fix = false) {
11037
11024
  }
11038
11025
 
11039
11026
  // src/utils/build.ts
11040
- async function buildComponent(componentDir, useLocalGlobalCss = true) {
11041
- const componentName = path3.basename(componentDir);
11027
+ async function buildComponent(componentDir) {
11028
+ const componentName = path11.basename(componentDir);
11042
11029
  const result = {
11043
11030
  itemName: componentName,
11044
11031
  success: true,
@@ -11050,7 +11037,7 @@ async function buildComponent(componentDir, useLocalGlobalCss = true) {
11050
11037
  result.details = validationResult.details;
11051
11038
  return result;
11052
11039
  }
11053
- const distDir = path3.join(componentDir, "dist");
11040
+ const distDir = path11.join(componentDir, "dist");
11054
11041
  try {
11055
11042
  await promises.mkdir(distDir, { recursive: true });
11056
11043
  } catch (error) {
@@ -11063,11 +11050,11 @@ async function buildComponent(componentDir, useLocalGlobalCss = true) {
11063
11050
  }
11064
11051
  try {
11065
11052
  const jsSource = await promises.readFile(
11066
- path3.join(componentDir, "index.jsx"),
11053
+ path11.join(componentDir, "index.jsx"),
11067
11054
  "utf-8"
11068
11055
  );
11069
11056
  const jsCompiled = compileJS(jsSource);
11070
- await promises.writeFile(path3.join(distDir, "index.js"), jsCompiled);
11057
+ await promises.writeFile(path11.join(distDir, "index.js"), jsCompiled);
11071
11058
  } catch (error) {
11072
11059
  result.success = false;
11073
11060
  result.details?.push({
@@ -11075,9 +11062,11 @@ async function buildComponent(componentDir, useLocalGlobalCss = true) {
11075
11062
  content: String(error)
11076
11063
  });
11077
11064
  }
11078
- const globalSourceCodeCss = await getGlobalCss(useLocalGlobalCss);
11065
+ const apiService = await createApiService();
11066
+ const globalAssetLibrary = await apiService.getGlobalAssetLibrary();
11067
+ const globalSourceCodeCss = globalAssetLibrary.css.original;
11079
11068
  try {
11080
- const cssPath = path3.join(componentDir, "index.css");
11069
+ const cssPath = path11.join(componentDir, "index.css");
11081
11070
  const cssFileExists = await fileExists(cssPath);
11082
11071
  if (cssFileExists) {
11083
11072
  const cssSource = await promises.readFile(cssPath, "utf-8");
@@ -11086,7 +11075,7 @@ async function buildComponent(componentDir, useLocalGlobalCss = true) {
11086
11075
  globalSourceCodeCss
11087
11076
  );
11088
11077
  const cssTranspiled = await transformCss(cssCompiled);
11089
- await promises.writeFile(path3.join(distDir, "index.css"), cssTranspiled);
11078
+ await promises.writeFile(path11.join(distDir, "index.css"), cssTranspiled);
11090
11079
  }
11091
11080
  } catch (error) {
11092
11081
  result.success = false;
@@ -17739,11 +17728,11 @@ async function findComponentDirectories(baseDir) {
17739
17728
  const namedYmls = await glob(`${baseDir}/**/*.component.yml`);
17740
17729
  const allComponentPaths = [...standardYmls, ...namedYmls];
17741
17730
  const uniqueDirs = new Set(
17742
- allComponentPaths.map((filePath) => path3.dirname(filePath))
17731
+ allComponentPaths.map((filePath) => path11.dirname(filePath))
17743
17732
  );
17744
17733
  let componentDirs = Array.from(uniqueDirs).sort();
17745
17734
  let sdcs = await glob(`${baseDir}/**/*.twig`);
17746
- sdcs = sdcs.map((sdc) => path3.dirname(sdc));
17735
+ sdcs = sdcs.map((sdc) => path11.dirname(sdc));
17747
17736
  componentDirs = componentDirs.filter(
17748
17737
  (componentDir) => !sdcs.includes(componentDir)
17749
17738
  );
@@ -17755,29 +17744,9 @@ async function findComponentDirectories(baseDir) {
17755
17744
  }
17756
17745
 
17757
17746
  // src/utils/component-selector.ts
17758
- var GLOBAL_CSS_SELECTOR = "__GLOBAL_CSS__";
17759
- function determineGlobalCssSelection(options) {
17760
- if (options.cssOnly) {
17761
- return true;
17762
- }
17763
- if (options.skipCss) {
17764
- return false;
17765
- }
17766
- if (!options.includeGlobalCss) {
17767
- return void 0;
17768
- }
17769
- return options.globalCssDefault !== false;
17770
- }
17771
17747
  async function selectLocalComponents(options) {
17772
17748
  const config2 = getConfig();
17773
17749
  const componentDir = options.componentDir || config2.componentDir;
17774
- const globalCssSelection = determineGlobalCssSelection(options);
17775
- if (options.cssOnly) {
17776
- return {
17777
- directories: [],
17778
- includeGlobalCss: true
17779
- };
17780
- }
17781
17750
  const allLocalDirs = await findComponentDirectories(componentDir);
17782
17751
  if (allLocalDirs.length === 0) {
17783
17752
  throw new Error(`No local components were found in ${componentDir}`);
@@ -17786,8 +17755,7 @@ async function selectLocalComponents(options) {
17786
17755
  return selectSpecificLocalComponents(
17787
17756
  options.components,
17788
17757
  allLocalDirs,
17789
- options,
17790
- globalCssSelection
17758
+ options
17791
17759
  );
17792
17760
  }
17793
17761
  if (options.all) {
@@ -17801,23 +17769,16 @@ async function selectLocalComponents(options) {
17801
17769
  }
17802
17770
  }
17803
17771
  p.log.info(`Selected all components`);
17804
- return {
17805
- directories: allLocalDirs,
17806
- includeGlobalCss: globalCssSelection
17807
- };
17772
+ return { directories: allLocalDirs };
17808
17773
  }
17809
- return selectLocalComponentsInteractive(
17810
- allLocalDirs,
17811
- options,
17812
- globalCssSelection
17813
- );
17774
+ return selectLocalComponentsInteractive(allLocalDirs, options);
17814
17775
  }
17815
- async function selectSpecificLocalComponents(componentsInput, allLocalDirs, options, globalCssSelection) {
17776
+ async function selectSpecificLocalComponents(componentsInput, allLocalDirs, options) {
17816
17777
  const requestedNames = componentsInput.split(",").map((name) => name.trim()).filter((name) => name.length > 0);
17817
17778
  const notFound = [];
17818
17779
  const foundDirs = [];
17819
17780
  for (const requestedName of requestedNames) {
17820
- const dir = allLocalDirs.find((d2) => path3.basename(d2) === requestedName);
17781
+ const dir = allLocalDirs.find((d2) => path11.basename(d2) === requestedName);
17821
17782
  if (dir) {
17822
17783
  foundDirs.push(dir);
17823
17784
  } else {
@@ -17837,48 +17798,27 @@ async function selectSpecificLocalComponents(componentsInput, allLocalDirs, opti
17837
17798
  throw new Error("Operation cancelled by user");
17838
17799
  }
17839
17800
  }
17840
- return {
17841
- directories: foundDirs,
17842
- includeGlobalCss: globalCssSelection
17843
- };
17801
+ return { directories: foundDirs };
17844
17802
  }
17845
- async function selectLocalComponentsInteractive(allLocalDirs, options, globalCssSelection) {
17846
- const multiSelectOptions = [
17847
- {
17848
- value: ALL_COMPONENTS_SELECTOR,
17849
- label: "All components"
17850
- }
17851
- ];
17852
- if (options.includeGlobalCss) {
17853
- multiSelectOptions.push({
17854
- value: GLOBAL_CSS_SELECTOR,
17855
- label: "Global CSS"
17856
- });
17857
- }
17858
- multiSelectOptions.push(
17859
- ...allLocalDirs.map((dir) => ({
17860
- value: dir,
17861
- label: path3.basename(dir)
17862
- }))
17863
- );
17864
- const selectedItems = await p.multiselect({
17865
- message: options.selectMessage || "Select items",
17866
- options: multiSelectOptions,
17867
- initialValues: options.includeGlobalCss && options.globalCssDefault !== false ? [GLOBAL_CSS_SELECTOR] : [],
17803
+ async function selectLocalComponentsInteractive(allLocalDirs, options) {
17804
+ const selectedDirs = await p.multiselect({
17805
+ message: options.selectMessage || "Select components",
17806
+ options: [
17807
+ {
17808
+ value: ALL_COMPONENTS_SELECTOR,
17809
+ label: "All components"
17810
+ },
17811
+ ...allLocalDirs.map((dir) => ({
17812
+ value: dir,
17813
+ label: path11.basename(dir)
17814
+ }))
17815
+ ],
17868
17816
  required: true
17869
17817
  });
17870
- if (p.isCancel(selectedItems)) {
17818
+ if (p.isCancel(selectedDirs)) {
17871
17819
  throw new Error("Operation cancelled by user");
17872
17820
  }
17873
- const includesAllComponents = selectedItems.includes(
17874
- ALL_COMPONENTS_SELECTOR
17875
- );
17876
- const includesGlobalCss = selectedItems.includes(
17877
- GLOBAL_CSS_SELECTOR
17878
- );
17879
- const finalDirs = includesAllComponents ? allLocalDirs : selectedItems.filter(
17880
- (item) => item !== ALL_COMPONENTS_SELECTOR && item !== GLOBAL_CSS_SELECTOR
17881
- );
17821
+ const finalDirs = selectedDirs.includes(ALL_COMPONENTS_SELECTOR) ? allLocalDirs : selectedDirs;
17882
17822
  if (!options.skipConfirmation) {
17883
17823
  const confirmed = await confirmSelection(
17884
17824
  finalDirs.length,
@@ -17888,21 +17828,10 @@ async function selectLocalComponentsInteractive(allLocalDirs, options, globalCss
17888
17828
  throw new Error("Operation cancelled by user");
17889
17829
  }
17890
17830
  }
17891
- const finalGlobalCss = options.includeGlobalCss ? includesGlobalCss : globalCssSelection;
17892
- return {
17893
- directories: finalDirs,
17894
- includeGlobalCss: finalGlobalCss
17895
- };
17831
+ return { directories: finalDirs };
17896
17832
  }
17897
17833
  async function selectRemoteComponents(allComponents, options) {
17898
17834
  const componentCount = Object.keys(allComponents).length;
17899
- const globalCssSelection = determineGlobalCssSelection(options);
17900
- if (options.cssOnly) {
17901
- return {
17902
- components: {},
17903
- includeGlobalCss: true
17904
- };
17905
- }
17906
17835
  if (componentCount === 0) {
17907
17836
  throw new Error("No components found");
17908
17837
  }
@@ -17916,26 +17845,18 @@ async function selectRemoteComponents(allComponents, options) {
17916
17845
  throw new Error("Operation cancelled by user");
17917
17846
  }
17918
17847
  }
17919
- return {
17920
- components: allComponents,
17921
- includeGlobalCss: globalCssSelection
17922
- };
17848
+ return { components: allComponents };
17923
17849
  }
17924
17850
  if (options.components) {
17925
17851
  return selectSpecificRemoteComponents(
17926
17852
  options.components,
17927
17853
  allComponents,
17928
- options,
17929
- globalCssSelection
17854
+ options
17930
17855
  );
17931
17856
  }
17932
- return selectRemoteComponentsInteractive(
17933
- allComponents,
17934
- options,
17935
- globalCssSelection
17936
- );
17857
+ return selectRemoteComponentsInteractive(allComponents, options);
17937
17858
  }
17938
- async function selectSpecificRemoteComponents(componentsInput, allComponents, options, globalCssSelection) {
17859
+ async function selectSpecificRemoteComponents(componentsInput, allComponents, options) {
17939
17860
  const requestedNames = componentsInput.split(",").map((name) => name.trim()).filter((name) => name.length > 0);
17940
17861
  const notFound = [];
17941
17862
  const selected = {};
@@ -17960,48 +17881,31 @@ async function selectSpecificRemoteComponents(componentsInput, allComponents, op
17960
17881
  throw new Error("Operation cancelled by user");
17961
17882
  }
17962
17883
  }
17963
- return {
17964
- components: selected,
17965
- includeGlobalCss: globalCssSelection
17966
- };
17884
+ return { components: selected };
17967
17885
  }
17968
- async function selectRemoteComponentsInteractive(allComponents, options, globalCssSelection) {
17969
- const multiSelectOptions = [
17970
- {
17971
- value: ALL_COMPONENTS_SELECTOR,
17972
- label: "All components"
17973
- }
17974
- ];
17975
- if (options.includeGlobalCss) {
17976
- multiSelectOptions.push({
17977
- value: GLOBAL_CSS_SELECTOR,
17978
- label: "Global CSS"
17979
- });
17980
- }
17981
- multiSelectOptions.push(
17982
- ...Object.keys(allComponents).map((key) => ({
17983
- value: allComponents[key].machineName,
17984
- label: `${allComponents[key].name} (${allComponents[key].machineName})`
17985
- }))
17986
- );
17987
- const selectedItems = await p.multiselect({
17988
- message: options.selectMessage || "Select items to download",
17989
- options: multiSelectOptions,
17990
- initialValues: options.includeGlobalCss && options.globalCssDefault !== false ? [GLOBAL_CSS_SELECTOR] : [],
17886
+ async function selectRemoteComponentsInteractive(allComponents, options) {
17887
+ const selectedMachineNames = await p.multiselect({
17888
+ message: options.selectMessage || "Select components to download",
17889
+ options: [
17890
+ {
17891
+ value: ALL_COMPONENTS_SELECTOR,
17892
+ label: "All components"
17893
+ },
17894
+ ...Object.keys(allComponents).map((key) => ({
17895
+ value: allComponents[key].machineName,
17896
+ label: `${allComponents[key].name} (${allComponents[key].machineName})`
17897
+ }))
17898
+ ],
17991
17899
  required: true
17992
17900
  });
17993
- if (p.isCancel(selectedItems)) {
17901
+ if (p.isCancel(selectedMachineNames)) {
17994
17902
  throw new Error("Operation cancelled by user");
17995
17903
  }
17996
- const includesAllComponents = selectedItems.includes(
17904
+ const selected = selectedMachineNames.includes(
17997
17905
  ALL_COMPONENTS_SELECTOR
17998
- );
17999
- const includesGlobalCss = selectedItems.includes(
18000
- GLOBAL_CSS_SELECTOR
18001
- );
18002
- const selected = includesAllComponents ? allComponents : Object.fromEntries(
17906
+ ) ? allComponents : Object.fromEntries(
18003
17907
  Object.entries(allComponents).filter(
18004
- ([, component]) => selectedItems.includes(component.machineName)
17908
+ ([, component]) => selectedMachineNames.includes(component.machineName)
18005
17909
  )
18006
17910
  );
18007
17911
  if (!options.skipConfirmation) {
@@ -18013,11 +17917,7 @@ async function selectRemoteComponentsInteractive(allComponents, options, globalC
18013
17917
  throw new Error("Operation cancelled by user");
18014
17918
  }
18015
17919
  }
18016
- const finalGlobalCss = options.includeGlobalCss ? includesGlobalCss : globalCssSelection;
18017
- return {
18018
- components: selected,
18019
- includeGlobalCss: finalGlobalCss
18020
- };
17920
+ return { components: selected };
18021
17921
  }
18022
17922
  async function confirmSelection(count, customMessage) {
18023
17923
  const componentLabel = count === 1 ? "component" : "components";
@@ -18161,15 +18061,10 @@ function downloadCommand(program2) {
18161
18061
  ).option("--all", "Download all components").option("-y, --yes", "Skip all confirmation prompts").option(
18162
18062
  "--skip-overwrite",
18163
18063
  "Skip downloading components that already exist locally"
18164
- ).option("--skip-css", "Skip downloading global CSS").option("--css-only", "Download only global CSS (skip components)").option("--verbose", "Enable verbose output").action(async (options) => {
18064
+ ).option("--verbose", "Enable verbose output").action(async (options) => {
18165
18065
  p.intro(chalk2.bold("Drupal Canvas CLI: download"));
18166
18066
  try {
18167
18067
  validateComponentOptions(options);
18168
- if (options.skipCss && options.cssOnly) {
18169
- throw new Error(
18170
- "Cannot use both --skip-css and --css-only flags together"
18171
- );
18172
- }
18173
18068
  updateConfigFromOptions(options);
18174
18069
  await ensureConfig([
18175
18070
  "siteUrl",
@@ -18180,52 +18075,35 @@ function downloadCommand(program2) {
18180
18075
  ]);
18181
18076
  const config2 = getConfig();
18182
18077
  const apiService = await createApiService();
18183
- let components = {};
18184
- let globalCss;
18185
18078
  const s = p.spinner();
18186
- if (options.cssOnly) {
18187
- s.start("Fetching global CSS");
18188
- const {
18189
- css: { original }
18190
- } = await apiService.getGlobalAssetLibrary();
18191
- globalCss = original;
18192
- s.stop("Global CSS fetched");
18193
- } else {
18194
- s.start("Fetching components and global CSS");
18195
- const [fetchedComponents, globalAssetLibrary] = await Promise.all([
18196
- apiService.listComponents(),
18197
- apiService.getGlobalAssetLibrary()
18198
- ]);
18199
- components = fetchedComponents;
18200
- globalCss = globalAssetLibrary.css.original;
18201
- if (Object.keys(components).length === 0) {
18202
- s.stop("No components found");
18203
- p.outro("Download cancelled - no components were found");
18204
- return;
18205
- }
18206
- s.stop(`Found ${Object.keys(components).length} components`);
18079
+ s.start("Fetching components");
18080
+ const components = await apiService.listComponents();
18081
+ const {
18082
+ css: { original: globalCss }
18083
+ } = await apiService.getGlobalAssetLibrary();
18084
+ if (Object.keys(components).length === 0) {
18085
+ s.stop("No components found");
18086
+ p.outro("Download cancelled - no components were found");
18087
+ return;
18207
18088
  }
18089
+ s.stop(`Found ${Object.keys(components).length} components`);
18208
18090
  const allFlag = options.all || options.yes && !options.components || false;
18209
- const { components: componentsToDownload, includeGlobalCss } = await selectRemoteComponents(components, {
18091
+ const { components: componentsToDownload } = await selectRemoteComponents(components, {
18210
18092
  all: allFlag,
18211
18093
  components: options.components,
18212
18094
  skipConfirmation: options.yes,
18213
- skipCss: options.skipCss,
18214
- cssOnly: options.cssOnly,
18215
- includeGlobalCss: !options.skipCss,
18216
- globalCssDefault: true,
18217
- selectMessage: "Select items to download",
18095
+ selectMessage: "Select components to download",
18218
18096
  confirmMessage: `Download to ${config2.componentDir}?`
18219
18097
  });
18220
- const componentCount = Object.keys(componentsToDownload).length;
18221
- const componentPluralized = pluralizeComponent(componentCount);
18098
+ const componentPluralized = pluralizeComponent(
18099
+ Object.keys(componentsToDownload).length
18100
+ );
18222
18101
  const results = [];
18223
- const downloadMessage = options.cssOnly ? "Downloading global CSS" : componentCount > 0 ? `Downloading ${componentPluralized}` : "Processing request";
18224
- s.start(downloadMessage);
18102
+ s.start(`Downloading ${componentPluralized}`);
18225
18103
  for (const key in componentsToDownload) {
18226
18104
  const component = componentsToDownload[key];
18227
18105
  try {
18228
- const componentDir = path3.join(
18106
+ const componentDir = path11.join(
18229
18107
  config2.componentDir,
18230
18108
  component.machineName
18231
18109
  );
@@ -18270,20 +18148,20 @@ function downloadCommand(program2) {
18270
18148
  slots: component.slots || {}
18271
18149
  };
18272
18150
  await fs2.writeFile(
18273
- path3.join(componentDir, `component.yml`),
18151
+ path11.join(componentDir, `component.yml`),
18274
18152
  yaml__default.dump(metadata),
18275
18153
  "utf-8"
18276
18154
  );
18277
18155
  if (component.sourceCodeJs) {
18278
18156
  await fs2.writeFile(
18279
- path3.join(componentDir, `index.jsx`),
18157
+ path11.join(componentDir, `index.jsx`),
18280
18158
  component.sourceCodeJs,
18281
18159
  "utf-8"
18282
18160
  );
18283
18161
  }
18284
18162
  if (component.sourceCodeCss) {
18285
18163
  await fs2.writeFile(
18286
- path3.join(componentDir, `index.css`),
18164
+ path11.join(componentDir, `index.css`),
18287
18165
  component.sourceCodeCss,
18288
18166
  "utf-8"
18289
18167
  );
@@ -18304,15 +18182,16 @@ function downloadCommand(program2) {
18304
18182
  });
18305
18183
  }
18306
18184
  }
18307
- const successMessage = options.cssOnly && componentCount === 0 ? "Global CSS download completed" : `Processed ${componentCount} ${componentPluralized}`;
18308
- s.stop(chalk2.green(successMessage));
18309
- if (componentCount > 0) {
18310
- reportResults(results, "Downloaded components", "Component");
18311
- }
18312
- if (includeGlobalCss && typeof globalCss === "string") {
18185
+ s.stop(
18186
+ chalk2.green(
18187
+ `Processed ${Object.keys(componentsToDownload).length} ${componentPluralized}`
18188
+ )
18189
+ );
18190
+ reportResults(results, "Downloaded components", "Component");
18191
+ if (globalCss) {
18313
18192
  let globalCssResult;
18314
18193
  try {
18315
- const globalCssPath = path3.join(config2.componentDir, "global.css");
18194
+ const globalCssPath = path11.join(config2.componentDir, "global.css");
18316
18195
  await fs2.writeFile(globalCssPath, globalCss, "utf-8");
18317
18196
  globalCssResult = {
18318
18197
  itemName: "global.css",
@@ -18332,8 +18211,7 @@ function downloadCommand(program2) {
18332
18211
  }
18333
18212
  reportResults([globalCssResult], "Downloaded assets", "Asset");
18334
18213
  }
18335
- const outroMessage = options.cssOnly && componentCount === 0 ? "\u2B07\uFE0F Global CSS downloaded successfully" : includeGlobalCss && componentCount > 0 ? "\u2B07\uFE0F Components and global CSS downloaded successfully" : componentCount > 0 ? "\u2B07\uFE0F Components downloaded successfully" : "\u2B07\uFE0F Download command completed";
18336
- p.outro(outroMessage);
18214
+ p.outro(`\u2B07\uFE0F Download command completed`);
18337
18215
  } catch (error) {
18338
18216
  if (error instanceof Error) {
18339
18217
  p.note(chalk2.red(`Error: ${error.message}`));
@@ -18376,13 +18254,13 @@ function scaffoldCommand(program2) {
18376
18254
  }
18377
18255
  componentName = name;
18378
18256
  }
18379
- const componentDir = path3.join(baseDir, componentName);
18257
+ const componentDir = path11.join(baseDir, componentName);
18380
18258
  const s = p.spinner();
18381
18259
  s.start(`Creating component "${componentName}"`);
18382
18260
  try {
18383
18261
  await fs2.mkdir(componentDir, { recursive: true });
18384
- const templateDir = path3.join(
18385
- path3.dirname(new URL(import.meta.url).pathname),
18262
+ const templateDir = path11.join(
18263
+ path11.dirname(new URL(import.meta.url).pathname),
18386
18264
  "templates/hello-world"
18387
18265
  );
18388
18266
  const files = await fs2.readdir(templateDir);
@@ -18398,8 +18276,8 @@ function scaffoldCommand(program2) {
18398
18276
  }
18399
18277
  }
18400
18278
  for (const file of files) {
18401
- const srcPath = path3.join(templateDir, file);
18402
- const destPath = path3.join(componentDir, file);
18279
+ const srcPath = path11.join(templateDir, file);
18280
+ const destPath = path11.join(componentDir, file);
18403
18281
  let content = await fs2.readFile(srcPath, "utf-8");
18404
18282
  const { pascalCaseName, className, displayName, machineName } = generateComponentNameFormats(componentName);
18405
18283
  content = content.replace(/HelloWorld/g, pascalCaseName).replace(/hello-world-component/g, className).replace(/Hello World/g, displayName).replace(/hello_world/g, machineName);
@@ -18408,9 +18286,9 @@ function scaffoldCommand(program2) {
18408
18286
  s.stop(chalk2.green(`Created component "${componentName}"`));
18409
18287
  p.note(`Component "${componentName}" has been created:
18410
18288
  - Directory: ${componentDir}
18411
- - Component metadata: ${path3.join(componentDir, `component.yml`)}
18412
- - Source file: ${path3.join(componentDir, `index.jsx`)}
18413
- - CSS file: ${path3.join(componentDir, `index.css`)}`);
18289
+ - Component metadata: ${path11.join(componentDir, `component.yml`)}
18290
+ - Source file: ${path11.join(componentDir, `index.jsx`)}
18291
+ - CSS file: ${path11.join(componentDir, `index.css`)}`);
18414
18292
  p.outro("\u{1F3D7}\uFE0F Scaffold command completed");
18415
18293
  } catch (error) {
18416
18294
  s.stop(chalk2.red(`Failed to create component "${componentName}"`));
@@ -18450,7 +18328,7 @@ var getDataDependenciesFromAst = (ast) => ast.program.body.filter((d2) => d2.typ
18450
18328
  const source = d2.source.value;
18451
18329
  if (
18452
18330
  // Only consider imports from these two modules.
18453
- source !== "@/lib/drupal-utils" && source !== "@drupal-api-client/json-api-client"
18331
+ source !== "@/lib/drupal-utils" && source !== "@drupal-api-client/json-api-client" && source !== "drupal-canvas"
18454
18332
  ) {
18455
18333
  return carry;
18456
18334
  }
@@ -18488,20 +18366,20 @@ var getDataDependenciesFromAst = (ast) => ast.program.body.filter((d2) => d2.typ
18488
18366
  async function processComponentFiles(componentDir) {
18489
18367
  const metadataPath = await findMetadataPath(componentDir);
18490
18368
  const metadata = await readComponentMetadata(metadataPath);
18491
- const distDir = path3.join(componentDir, "dist");
18369
+ const distDir = path11.join(componentDir, "dist");
18492
18370
  const sourceCodeJs = await promises.readFile(
18493
- path3.join(componentDir, "index.jsx"),
18371
+ path11.join(componentDir, "index.jsx"),
18494
18372
  "utf-8"
18495
18373
  );
18496
- const compiledJs = await promises.readFile(path3.join(distDir, "index.js"), "utf-8");
18374
+ const compiledJs = await promises.readFile(path11.join(distDir, "index.js"), "utf-8");
18497
18375
  let sourceCodeCss = "";
18498
18376
  let compiledCss = "";
18499
18377
  try {
18500
18378
  sourceCodeCss = await promises.readFile(
18501
- path3.join(componentDir, "index.css"),
18379
+ path11.join(componentDir, "index.css"),
18502
18380
  "utf-8"
18503
18381
  );
18504
- compiledCss = await promises.readFile(path3.join(distDir, "index.css"), "utf-8");
18382
+ compiledCss = await promises.readFile(path11.join(distDir, "index.css"), "utf-8");
18505
18383
  } catch {
18506
18384
  }
18507
18385
  return {
@@ -18513,7 +18391,7 @@ async function processComponentFiles(componentDir) {
18513
18391
  };
18514
18392
  }
18515
18393
  async function findMetadataPath(componentDir) {
18516
- const metadataPath = path3.join(componentDir, "component.yml");
18394
+ const metadataPath = path11.join(componentDir, "component.yml");
18517
18395
  try {
18518
18396
  await promises.access(metadataPath);
18519
18397
  return metadataPath;
@@ -18534,10 +18412,10 @@ async function readComponentMetadata(filePath) {
18534
18412
  }
18535
18413
  const metadata = rawMetadata;
18536
18414
  if (!metadata.name) {
18537
- metadata.name = path3.basename(path3.dirname(filePath));
18415
+ metadata.name = path11.basename(path11.dirname(filePath));
18538
18416
  }
18539
18417
  if (!metadata.machineName) {
18540
- metadata.machineName = path3.basename(path3.dirname(filePath));
18418
+ metadata.machineName = path11.basename(path11.dirname(filePath));
18541
18419
  }
18542
18420
  if (!metadata.slots || typeof metadata.slots !== "object") {
18543
18421
  metadata.slots = {};
@@ -18707,17 +18585,12 @@ function uploadCommand(program2) {
18707
18585
  program2.command("upload").description("build and upload local components and global CSS assets").option("--client-id <id>", "Client ID").option("--client-secret <secret>", "Client Secret").option("--site-url <url>", "Site URL").option("--scope <scope>", "Scope").option("-d, --dir <directory>", "Component directory").option(
18708
18586
  "-c, --components <names>",
18709
18587
  "Specific component(s) to upload (comma-separated)"
18710
- ).option("--all", "Upload all components").option("-y, --yes", "Skip confirmation prompts").option("--verbose", "Verbose output").option("--no-tailwind", "Skip Tailwind CSS building").option("--skip-css", "Skip global CSS upload").option("--css-only", "Upload only global CSS (skip components)").action(async (options) => {
18588
+ ).option("--all", "Upload all components").option("-y, --yes", "Skip confirmation prompts").option("--verbose", "Verbose output").option("--no-tailwind", "Skip Tailwind CSS building").action(async (options) => {
18711
18589
  const allFlag = options.all || options.yes && !options.components || false;
18712
18590
  const skipTailwind = !options.tailwind;
18713
18591
  try {
18714
18592
  p.intro(chalk2.bold("Drupal Canvas CLI: upload"));
18715
18593
  validateComponentOptions(options);
18716
- if (options.skipCss && options.cssOnly) {
18717
- throw new Error(
18718
- "Cannot use both --skip-css and --css-only flags together"
18719
- );
18720
- }
18721
18594
  updateConfigFromOptions(options);
18722
18595
  await ensureConfig([
18723
18596
  "siteUrl",
@@ -18727,28 +18600,22 @@ function uploadCommand(program2) {
18727
18600
  "componentDir"
18728
18601
  ]);
18729
18602
  const config2 = getConfig();
18730
- const { directories: componentsToUpload, includeGlobalCss } = await selectLocalComponents({
18731
- all: allFlag,
18732
- components: options.components,
18733
- skipConfirmation: options.yes,
18734
- skipCss: options.skipCss,
18735
- cssOnly: options.cssOnly,
18736
- includeGlobalCss: !options.skipCss,
18737
- globalCssDefault: true,
18738
- selectMessage: "Select items to upload"
18739
- });
18740
- const apiService = await createApiService();
18741
- let componentResults = [];
18742
- if (!options.cssOnly && componentsToUpload.length > 0) {
18743
- componentResults = await getBuildAndUploadResults(
18744
- componentsToUpload,
18745
- apiService,
18746
- includeGlobalCss ?? false
18747
- );
18748
- reportResults(componentResults, "Uploaded components", "Component");
18749
- if (componentResults.some((result) => !result.success)) {
18750
- process.exit(1);
18603
+ const { directories: componentsToUpload } = await selectLocalComponents(
18604
+ {
18605
+ all: allFlag,
18606
+ components: options.components,
18607
+ skipConfirmation: options.yes,
18608
+ selectMessage: "Select components to upload"
18751
18609
  }
18610
+ );
18611
+ const apiService = await createApiService();
18612
+ const componentResults = await getBuildAndUploadResults(
18613
+ componentsToUpload,
18614
+ apiService
18615
+ );
18616
+ reportResults(componentResults, "Uploaded components", "Component");
18617
+ if (componentResults.some((result) => !result.success)) {
18618
+ process.exit(1);
18752
18619
  }
18753
18620
  if (skipTailwind) {
18754
18621
  p.log.info("Skipping Tailwind CSS build");
@@ -18756,9 +18623,7 @@ function uploadCommand(program2) {
18756
18623
  const s2 = p.spinner();
18757
18624
  s2.start("Building Tailwind CSS");
18758
18625
  const tailwindResult = await buildTailwindForComponents(
18759
- componentsToUpload,
18760
- includeGlobalCss
18761
- // Use local CSS if includeGlobalCss is true
18626
+ componentsToUpload
18762
18627
  );
18763
18628
  const componentLabelPluralized = pluralizeComponent(
18764
18629
  componentsToUpload.length
@@ -18774,20 +18639,14 @@ function uploadCommand(program2) {
18774
18639
  chalk2.red(`Tailwind build failed, global assets upload aborted.`)
18775
18640
  );
18776
18641
  } else {
18777
- if (includeGlobalCss) {
18778
- const globalCssResult = await uploadGlobalAssetLibrary(
18779
- apiService,
18780
- config2.componentDir
18781
- );
18782
- reportResults([globalCssResult], "Uploaded assets", "Asset");
18783
- } else {
18784
- p.log.info("Skipping global CSS upload");
18785
- }
18642
+ const globalCssResult = await uploadGlobalAssetLibrary(
18643
+ apiService,
18644
+ config2.componentDir
18645
+ );
18646
+ reportResults([globalCssResult], "Uploaded assets", "Asset");
18786
18647
  }
18787
18648
  }
18788
- const componentCount = componentsToUpload.length;
18789
- const outroMessage = options.cssOnly && componentCount === 0 ? "\u2B06\uFE0F Global CSS uploaded successfully" : includeGlobalCss && componentCount > 0 ? "\u2B06\uFE0F Components and global CSS uploaded successfully" : componentCount > 0 ? "\u2B06\uFE0F Components uploaded successfully" : "\u2B06\uFE0F Upload command completed";
18790
- p.outro(outroMessage);
18649
+ p.outro("\u2B06\uFE0F Upload command completed");
18791
18650
  } catch (error) {
18792
18651
  if (error instanceof Error) {
18793
18652
  p.note(chalk2.red(`Error: ${error.message}`));
@@ -18803,11 +18662,11 @@ async function prepareComponentsForUpload(successfulBuilds, componentsToUpload)
18803
18662
  const failed = [];
18804
18663
  for (const buildResult of successfulBuilds) {
18805
18664
  const dir = buildResult.itemName ? componentsToUpload.find(
18806
- (d2) => path3.basename(d2) === buildResult.itemName
18665
+ (d2) => path11.basename(d2) === buildResult.itemName
18807
18666
  ) : void 0;
18808
18667
  if (!dir) continue;
18809
18668
  try {
18810
- const componentName = path3.basename(dir);
18669
+ const componentName = path11.basename(dir);
18811
18670
  const { sourceCodeJs, compiledJs, sourceCodeCss, compiledCss, metadata } = await processComponentFiles(dir);
18812
18671
  if (!metadata) {
18813
18672
  throw new Error("Invalid metadata file");
@@ -18860,14 +18719,11 @@ async function prepareComponentsForUpload(successfulBuilds, componentsToUpload)
18860
18719
  }
18861
18720
  return { prepared, failed };
18862
18721
  }
18863
- async function getBuildAndUploadResults(componentsToUpload, apiService, includeGlobalCss) {
18722
+ async function getBuildAndUploadResults(componentsToUpload, apiService) {
18864
18723
  const results = [];
18865
18724
  const spinner6 = p.spinner();
18866
18725
  spinner6.start("Building components");
18867
- const buildResults = await buildSelectedComponents(
18868
- componentsToUpload,
18869
- includeGlobalCss
18870
- );
18726
+ const buildResults = await buildSelectedComponents(componentsToUpload);
18871
18727
  const successfulBuilds = buildResults.filter((build) => build.success);
18872
18728
  const failedBuilds = buildResults.filter((build) => !build.success);
18873
18729
  if (successfulBuilds.length === 0) {
@@ -18942,28 +18798,29 @@ async function getBuildAndUploadResults(componentsToUpload, apiService, includeG
18942
18798
  );
18943
18799
  return results;
18944
18800
  }
18945
- async function buildSelectedComponents(componentDirs, useLocalGlobalCss = true) {
18801
+ async function buildSelectedComponents(componentDirs) {
18946
18802
  const buildResults = [];
18947
18803
  for (const dir of componentDirs) {
18948
- buildResults.push(await buildComponent(dir, useLocalGlobalCss));
18804
+ buildResults.push(await buildComponent(dir));
18949
18805
  }
18950
18806
  return buildResults;
18951
18807
  }
18952
18808
  async function uploadGlobalAssetLibrary(apiService, componentDir) {
18953
18809
  try {
18954
- const distDir = path3.join(componentDir, "dist");
18955
- const globalCompiledCssPath = path3.join(distDir, "index.css");
18810
+ const distDir = path11.join(componentDir, "dist");
18811
+ const globalCompiledCssPath = path11.join(distDir, "index.css");
18956
18812
  const globalCompiledCssExists = await fileExists(globalCompiledCssPath);
18957
18813
  if (globalCompiledCssExists) {
18958
18814
  const globalCompiledCss = await fs2.readFile(
18959
- path3.join(distDir, "index.css"),
18815
+ path11.join(distDir, "index.css"),
18960
18816
  "utf-8"
18961
18817
  );
18962
18818
  const classNameCandidateIndexFile = await fs2.readFile(
18963
- path3.join(distDir, "index.js"),
18819
+ path11.join(distDir, "index.js"),
18964
18820
  "utf-8"
18965
18821
  );
18966
- const originalCss = await getGlobalCss();
18822
+ const current = await apiService.getGlobalAssetLibrary();
18823
+ const originalCss = current.css.original;
18967
18824
  await apiService.updateGlobalAssetLibrary({
18968
18825
  css: {
18969
18826
  original: originalCss,
@@ -19076,5 +18933,3 @@ try {
19076
18933
  process.exit(1);
19077
18934
  }
19078
18935
  }
19079
- //# sourceMappingURL=index.js.map
19080
- //# sourceMappingURL=index.js.map