@clafoutis/cli 1.1.1 → 1.1.2

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
@@ -1,12 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  import * as p2 from '@clack/prompts';
3
3
  import { Command } from 'commander';
4
+ import { generate } from '@clafoutis/generators/figma';
5
+ import { generate as generate$1 } from '@clafoutis/generators/tailwind';
4
6
  import { logger } from '@clafoutis/shared';
5
- import path2 from 'path';
7
+ import path from 'path';
6
8
  import StyleDictionary from 'style-dictionary';
7
- import { pathToFileURL } from 'url';
9
+ import { register } from 'tsx/esm/api';
10
+ import { fileURLToPath, pathToFileURL } from 'url';
8
11
  import { Ajv } from 'ajv';
9
12
  import fs from 'fs/promises';
13
+ import fs2 from 'fs';
10
14
  import { spawn } from 'child_process';
11
15
 
12
16
  // src/utils/errors.ts
@@ -159,8 +163,8 @@ function findUnknownFields(config, schemaProperties, prefix = "") {
159
163
  }
160
164
  return unknown;
161
165
  }
162
- function hasField(config, path4) {
163
- const parts = path4.split(".");
166
+ function hasField(config, path5) {
167
+ const parts = path5.split(".");
164
168
  let current = config;
165
169
  for (const part of parts) {
166
170
  if (current && typeof current === "object" && part in current) {
@@ -488,232 +492,38 @@ function getConsumerGitignore() {
488
492
  .clafoutis/cache
489
493
  `;
490
494
  }
491
-
492
- // src/templates/tokens.ts
493
- var colorPrimitives = {
494
- color: {
495
- gray: {
496
- 50: { $value: "#fafafa" },
497
- 100: { $value: "#f5f5f5" },
498
- 200: { $value: "#e5e5e5" },
499
- 300: { $value: "#d4d4d4" },
500
- 400: { $value: "#a3a3a3" },
501
- 500: { $value: "#737373" },
502
- 600: { $value: "#525252" },
503
- 700: { $value: "#404040" },
504
- 800: { $value: "#262626" },
505
- 900: { $value: "#171717" }
506
- },
507
- blue: {
508
- 50: { $value: "#eff6ff" },
509
- 100: { $value: "#dbeafe" },
510
- 200: { $value: "#bfdbfe" },
511
- 300: { $value: "#93c5fd" },
512
- 400: { $value: "#60a5fa" },
513
- 500: { $value: "#3b82f6" },
514
- 600: { $value: "#2563eb" },
515
- 700: { $value: "#1d4ed8" },
516
- 800: { $value: "#1e40af" },
517
- 900: { $value: "#1e3a8a" }
518
- },
519
- green: {
520
- 50: { $value: "#f0fdf4" },
521
- 100: { $value: "#dcfce7" },
522
- 200: { $value: "#bbf7d0" },
523
- 300: { $value: "#86efac" },
524
- 400: { $value: "#4ade80" },
525
- 500: { $value: "#22c55e" },
526
- 600: { $value: "#16a34a" },
527
- 700: { $value: "#15803d" },
528
- 800: { $value: "#166534" },
529
- 900: { $value: "#14532d" }
530
- },
531
- red: {
532
- 50: { $value: "#fef2f2" },
533
- 100: { $value: "#fee2e2" },
534
- 200: { $value: "#fecaca" },
535
- 300: { $value: "#fca5a5" },
536
- 400: { $value: "#f87171" },
537
- 500: { $value: "#ef4444" },
538
- 600: { $value: "#dc2626" },
539
- 700: { $value: "#b91c1c" },
540
- 800: { $value: "#991b1b" },
541
- 900: { $value: "#7f1d1d" }
542
- },
543
- amber: {
544
- 50: { $value: "#fffbeb" },
545
- 100: { $value: "#fef3c7" },
546
- 200: { $value: "#fde68a" },
547
- 300: { $value: "#fcd34d" },
548
- 400: { $value: "#fbbf24" },
549
- 500: { $value: "#f59e0b" },
550
- 600: { $value: "#d97706" },
551
- 700: { $value: "#b45309" },
552
- 800: { $value: "#92400e" },
553
- 900: { $value: "#78350f" }
554
- }
555
- }
556
- };
557
- var colorSemantics = {
558
- color: {
559
- primary: {
560
- 50: { $value: "{color.blue.50}" },
561
- 100: { $value: "{color.blue.100}" },
562
- 200: { $value: "{color.blue.200}" },
563
- 300: { $value: "{color.blue.300}" },
564
- 400: { $value: "{color.blue.400}" },
565
- 500: { $value: "{color.blue.500}" },
566
- 600: { $value: "{color.blue.600}" },
567
- 700: { $value: "{color.blue.700}" },
568
- 800: { $value: "{color.blue.800}" },
569
- 900: { $value: "{color.blue.900}" }
570
- },
571
- neutral: {
572
- 50: { $value: "{color.gray.50}" },
573
- 100: { $value: "{color.gray.100}" },
574
- 200: { $value: "{color.gray.200}" },
575
- 300: { $value: "{color.gray.300}" },
576
- 400: { $value: "{color.gray.400}" },
577
- 500: { $value: "{color.gray.500}" },
578
- 600: { $value: "{color.gray.600}" },
579
- 700: { $value: "{color.gray.700}" },
580
- 800: { $value: "{color.gray.800}" },
581
- 900: { $value: "{color.gray.900}" }
582
- },
583
- success: {
584
- 50: { $value: "{color.green.50}" },
585
- 100: { $value: "{color.green.100}" },
586
- 200: { $value: "{color.green.200}" },
587
- 300: { $value: "{color.green.300}" },
588
- 400: { $value: "{color.green.400}" },
589
- 500: { $value: "{color.green.500}" },
590
- 600: { $value: "{color.green.600}" },
591
- 700: { $value: "{color.green.700}" },
592
- 800: { $value: "{color.green.800}" },
593
- 900: { $value: "{color.green.900}" }
594
- },
595
- warning: {
596
- 50: { $value: "{color.amber.50}" },
597
- 100: { $value: "{color.amber.100}" },
598
- 200: { $value: "{color.amber.200}" },
599
- 300: { $value: "{color.amber.300}" },
600
- 400: { $value: "{color.amber.400}" },
601
- 500: { $value: "{color.amber.500}" },
602
- 600: { $value: "{color.amber.600}" },
603
- 700: { $value: "{color.amber.700}" },
604
- 800: { $value: "{color.amber.800}" },
605
- 900: { $value: "{color.amber.900}" }
606
- },
607
- error: {
608
- 50: { $value: "{color.red.50}" },
609
- 100: { $value: "{color.red.100}" },
610
- 200: { $value: "{color.red.200}" },
611
- 300: { $value: "{color.red.300}" },
612
- 400: { $value: "{color.red.400}" },
613
- 500: { $value: "{color.red.500}" },
614
- 600: { $value: "{color.red.600}" },
615
- 700: { $value: "{color.red.700}" },
616
- 800: { $value: "{color.red.800}" },
617
- 900: { $value: "{color.red.900}" }
618
- },
619
- background: {
620
- default: { $value: "{color.gray.50}" },
621
- subtle: { $value: "{color.gray.100}" },
622
- muted: { $value: "{color.gray.200}" }
623
- },
624
- foreground: {
625
- default: { $value: "{color.gray.900}" },
626
- muted: { $value: "{color.gray.600}" },
627
- subtle: { $value: "{color.gray.500}" }
628
- },
629
- border: {
630
- default: { $value: "{color.gray.200}" },
631
- muted: { $value: "{color.gray.100}" }
632
- }
633
- }
634
- };
635
- var colorSemanticsDark = {
636
- color: {
637
- background: {
638
- default: { $value: "{color.gray.900}" },
639
- subtle: { $value: "{color.gray.800}" },
640
- muted: { $value: "{color.gray.700}" }
641
- },
642
- foreground: {
643
- default: { $value: "{color.gray.50}" },
644
- muted: { $value: "{color.gray.400}" },
645
- subtle: { $value: "{color.gray.500}" }
646
- },
647
- border: {
648
- default: { $value: "{color.gray.700}" },
649
- muted: { $value: "{color.gray.800}" }
495
+ var __filename$1 = fileURLToPath(import.meta.url);
496
+ var __dirname$1 = path.dirname(__filename$1);
497
+ function getTokensDir() {
498
+ const devPath = path.resolve(__dirname$1, "tokens");
499
+ if (fs2.existsSync(devPath)) return devPath;
500
+ const distPath = path.resolve(__dirname$1, "templates", "tokens");
501
+ if (fs2.existsSync(distPath)) return distPath;
502
+ throw new Error(
503
+ `Starter token templates not found. Searched:
504
+ ${devPath}
505
+ ${distPath}`
506
+ );
507
+ }
508
+ function walkTokensDir(dir, base = "") {
509
+ const result = [];
510
+ for (const entry of fs2.readdirSync(dir, { withFileTypes: true })) {
511
+ const relPath = base ? path.join(base, entry.name) : entry.name;
512
+ const fullPath = path.join(dir, entry.name);
513
+ if (entry.isDirectory()) {
514
+ result.push(...walkTokensDir(fullPath, relPath));
515
+ } else if (entry.name.endsWith(".json")) {
516
+ result.push({
517
+ path: relPath,
518
+ content: fs2.readFileSync(fullPath, "utf-8")
519
+ });
650
520
  }
651
521
  }
652
- };
653
- var spacingPrimitives = {
654
- spacing: {
655
- 0: { $value: "0" },
656
- 1: { $value: "0.25rem" },
657
- 2: { $value: "0.5rem" },
658
- 3: { $value: "0.75rem" },
659
- 4: { $value: "1rem" },
660
- 5: { $value: "1.25rem" },
661
- 6: { $value: "1.5rem" },
662
- 8: { $value: "2rem" },
663
- 10: { $value: "2.5rem" },
664
- 12: { $value: "3rem" },
665
- 16: { $value: "4rem" },
666
- 20: { $value: "5rem" },
667
- 24: { $value: "6rem" }
668
- }
669
- };
670
- var typographyPrimitives = {
671
- fontFamily: {
672
- sans: { $value: "ui-sans-serif, system-ui, sans-serif" },
673
- serif: { $value: "ui-serif, Georgia, serif" },
674
- mono: { $value: "ui-monospace, monospace" }
675
- },
676
- fontSize: {
677
- xs: { $value: "0.75rem" },
678
- sm: { $value: "0.875rem" },
679
- base: { $value: "1rem" },
680
- lg: { $value: "1.125rem" },
681
- xl: { $value: "1.25rem" },
682
- "2xl": { $value: "1.5rem" },
683
- "3xl": { $value: "1.875rem" },
684
- "4xl": { $value: "2.25rem" }
685
- },
686
- fontWeight: {
687
- normal: { $value: "400" },
688
- medium: { $value: "500" },
689
- semibold: { $value: "600" },
690
- bold: { $value: "700" }
691
- },
692
- lineHeight: {
693
- tight: { $value: "1.25" },
694
- normal: { $value: "1.5" },
695
- relaxed: { $value: "1.75" }
696
- }
697
- };
698
- var starterTokens = {
699
- "colors/primitives.json": colorPrimitives,
700
- "colors/semantic.json": colorSemantics,
701
- "colors/semantic.dark.json": colorSemanticsDark,
702
- "spacing/primitives.json": spacingPrimitives,
703
- "typography/primitives.json": typographyPrimitives
704
- };
705
- function getStarterTokenContent(fileName) {
706
- const tokens = starterTokens[fileName];
707
- if (!tokens) {
708
- throw new Error(`Unknown starter token file: ${fileName}`);
709
- }
710
- return JSON.stringify(tokens, null, 2) + "\n";
522
+ return result;
711
523
  }
712
524
  function getAllStarterTokens() {
713
- return Object.keys(starterTokens).map((fileName) => ({
714
- path: fileName,
715
- content: getStarterTokenContent(fileName)
716
- }));
525
+ const tokensDir = getTokensDir();
526
+ return walkTokensDir(tokensDir);
717
527
  }
718
528
 
719
529
  // src/templates/workflow.ts
@@ -984,9 +794,9 @@ async function createProducerConfig(answers, force, dryRun) {
984
794
  description: `tokens: "${answers.tokens}", output: "${answers.output}"`
985
795
  }
986
796
  ];
987
- const starterTokens2 = getAllStarterTokens();
988
- for (const token of starterTokens2) {
989
- const tokenPath = path2.join(answers.tokens, token.path);
797
+ const starterTokens = getAllStarterTokens();
798
+ for (const token of starterTokens) {
799
+ const tokenPath = path.join(answers.tokens, token.path);
990
800
  if (!force && await fileExists(tokenPath)) {
991
801
  continue;
992
802
  }
@@ -1080,7 +890,7 @@ function showDryRunOutput(files) {
1080
890
  }
1081
891
  async function writeFiles(files) {
1082
892
  for (const file of files) {
1083
- const dir = path2.dirname(file.path);
893
+ const dir = path.dirname(file.path);
1084
894
  await fs.mkdir(dir, { recursive: true });
1085
895
  await fs.writeFile(file.path, file.content);
1086
896
  log3.success(`Created ${file.path}`);
@@ -1103,9 +913,8 @@ function showNextSteps(mode, answers) {
1103
913
 
1104
914
  // src/commands/generate.ts
1105
915
  async function loadPlugin(pluginPath) {
1106
- const absolutePath = path2.resolve(process.cwd(), pluginPath);
916
+ const absolutePath = path.resolve(process.cwd(), pluginPath);
1107
917
  if (pluginPath.endsWith(".ts")) {
1108
- const { register } = await import('tsx/esm/api');
1109
918
  register();
1110
919
  }
1111
920
  return import(pathToFileURL(absolutePath).href);
@@ -1150,8 +959,8 @@ async function generateCommand(options) {
1150
959
  if (options.output) {
1151
960
  config.output = options.output;
1152
961
  }
1153
- const tokensDir = path2.resolve(process.cwd(), config.tokens || "./tokens");
1154
- const outputDir = path2.resolve(process.cwd(), config.output || "./build");
962
+ const tokensDir = path.resolve(process.cwd(), config.tokens || "./tokens");
963
+ const outputDir = path.resolve(process.cwd(), config.output || "./build");
1155
964
  if (!await fileExists(tokensDir)) {
1156
965
  throw tokensDirNotFoundError(tokensDir);
1157
966
  }
@@ -1190,22 +999,17 @@ async function generateCommand(options) {
1190
999
  }
1191
1000
  } else {
1192
1001
  const builtInGenerators = {
1193
- tailwind: async () => import('@clafoutis/generators/tailwind'),
1194
- figma: async () => import('@clafoutis/generators/figma')
1002
+ tailwind: { generate: () => generate$1() },
1003
+ figma: { generate: () => generate() }
1195
1004
  };
1196
1005
  if (!builtInGenerators[name]) {
1197
1006
  throw generatorNotFoundError(name);
1198
1007
  }
1199
- try {
1200
- generatorModule = await builtInGenerators[name]();
1201
- } catch (err) {
1202
- const errorMessage = err instanceof Error ? err.message : String(err);
1203
- throw pluginLoadError(`@clafoutis/generators/${name}`, errorMessage);
1204
- }
1008
+ generatorModule = builtInGenerators[name];
1205
1009
  }
1206
1010
  const context = {
1207
1011
  tokensDir,
1208
- outputDir: path2.join(outputDir, name),
1012
+ outputDir: path.join(outputDir, name),
1209
1013
  config,
1210
1014
  StyleDictionary
1211
1015
  };
@@ -1312,8 +1116,8 @@ async function writeOutput(config, files) {
1312
1116
  for (const [assetName, content] of files) {
1313
1117
  const configPath = config.files[assetName];
1314
1118
  if (!configPath) continue;
1315
- const outputPath = path2.resolve(process.cwd(), configPath);
1316
- await fs.mkdir(path2.dirname(outputPath), { recursive: true });
1119
+ const outputPath = path.resolve(process.cwd(), configPath);
1120
+ await fs.mkdir(path.dirname(outputPath), { recursive: true });
1317
1121
  await fs.writeFile(outputPath, content);
1318
1122
  logger.success(`Written: ${outputPath}`);
1319
1123
  }
@@ -1359,7 +1163,7 @@ async function syncCommand(options) {
1359
1163
  }
1360
1164
  return;
1361
1165
  }
1362
- const resolveOutputPaths = () => Object.values(config.files).map((p5) => path2.resolve(process.cwd(), p5));
1166
+ const resolveOutputPaths = () => Object.values(config.files).map((p5) => path.resolve(process.cwd(), p5));
1363
1167
  if (!isLatest && !options.force && config.version === cachedVersion) {
1364
1168
  const outputPaths = resolveOutputPaths();
1365
1169
  const existsResults = await Promise.all(