foldcn 0.0.19 → 0.0.20

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 (2) hide show
  1. package/dist/bin.js +42 -8
  2. package/package.json +1 -1
package/dist/bin.js CHANGED
@@ -62,7 +62,7 @@ var CssVars = Schema.Struct({
62
62
  var Css = Schema.Record(Schema.String, Schema.Union([Schema.String, Schema.suspend(() => Css)])).annotate({ identifier: "Foldcn.Registry.Css" });
63
63
  var Item = Schema.Struct({
64
64
  $schema: Schema.optionalKey(Schema.String),
65
- name: Schema.String,
65
+ name: Schema.NonEmptyString,
66
66
  type: ItemType,
67
67
  title: Schema.optionalKey(Schema.String),
68
68
  description: Schema.optionalKey(Schema.String),
@@ -633,6 +633,22 @@ class StylesheetNotFoundError extends Schema4.TaggedErrorClass()("StylesheetNotF
633
633
  path: Schema4.String
634
634
  }) {
635
635
  }
636
+
637
+ class FileReadError extends Schema4.TaggedErrorClass()("FileReadError", {
638
+ path: Schema4.String,
639
+ message: Schema4.String
640
+ }) {
641
+ }
642
+
643
+ class DuplicateItemError extends Schema4.TaggedErrorClass()("DuplicateItemError", {
644
+ name: Schema4.String
645
+ }) {
646
+ }
647
+
648
+ class NotAProjectError extends Schema4.TaggedErrorClass()("NotAProjectError", {
649
+ cwd: Schema4.String
650
+ }) {
651
+ }
636
652
  // src/installer/installer.ts
637
653
  import { Effect as Effect4, FileSystem as FileSystem2, Path } from "effect";
638
654
  import { ChildProcess } from "effect/unstable/process";
@@ -972,11 +988,17 @@ var registryArgument = Argument2.string("registry").pipe(Argument2.withDescripti
972
988
  var outputFlag = Flag2.string("output").pipe(Flag2.withAlias("o"), Flag2.withDescription("Destination directory for built registry JSON"), Flag2.withDefault("./public/r"));
973
989
  var cwdFlag2 = Flag2.string("cwd").pipe(Flag2.withAlias("c"), Flag2.withDescription("Working directory"), Flag2.withDefault("."));
974
990
  var isLocalName = (spec) => !spec.includes("://") && !spec.startsWith("@") && !spec.startsWith(".") && !spec.startsWith("/");
975
- var validateLocalDependencies = (manifest) => Effect9.gen(function* () {
976
- const names = new Set(manifest.items.map((item) => item.name));
991
+ var validateManifest = (manifest) => Effect9.gen(function* () {
992
+ const seen = new Set;
993
+ for (const item of manifest.items) {
994
+ if (seen.has(item.name)) {
995
+ return yield* new DuplicateItemError({ name: item.name });
996
+ }
997
+ seen.add(item.name);
998
+ }
977
999
  for (const item of manifest.items) {
978
1000
  for (const dependency of item.registryDependencies ?? []) {
979
- if (isLocalName(dependency) && !names.has(dependency)) {
1001
+ if (isLocalName(dependency) && !seen.has(dependency)) {
980
1002
  return yield* new UnknownRegistryDependencyError({ itemName: item.name, dependency });
981
1003
  }
982
1004
  }
@@ -987,14 +1009,21 @@ var buildCommand = Command2.make("build", { registry: registryArgument, output:
987
1009
  const path = yield* Path5.Path;
988
1010
  const cwdAbsolute = path.resolve(cwd);
989
1011
  const manifestPath = path.resolve(cwdAbsolute, registry2);
990
- const manifestJson = yield* readJsonFile(manifestPath);
1012
+ const manifestJson = yield* readJsonFile(manifestPath).pipe(Effect9.catchTag("PlatformError", (error2) => Effect9.fail(new FileReadError({ path: manifestPath, message: `registry manifest not readable: ${error2}` }))));
991
1013
  const manifest = yield* Schema7.decodeUnknownEffect(exports_registry.Manifest)(manifestJson);
992
- yield* validateLocalDependencies(manifest);
1014
+ yield* validateManifest(manifest);
993
1015
  const outputDir = path.resolve(cwdAbsolute, output);
994
1016
  yield* fileSystem.makeDirectory(outputDir, { recursive: true });
1017
+ const existingEntries = yield* fileSystem.readDirectory(outputDir).pipe(Effect9.orElseSucceed(() => []));
1018
+ yield* Effect9.forEach(existingEntries.filter((entry) => entry.endsWith(".json")), (entry) => fileSystem.remove(path.join(outputDir, entry)).pipe(Effect9.orElseSucceed(() => {
1019
+ return;
1020
+ })));
995
1021
  for (const item of manifest.items) {
996
1022
  const files = yield* Effect9.forEach(item.files ?? [], (file) => Effect9.gen(function* () {
997
- const content = yield* fileSystem.readFileString(path.resolve(cwdAbsolute, file.path));
1023
+ const content = yield* fileSystem.readFileString(path.resolve(cwdAbsolute, file.path)).pipe(Effect9.catchTag("PlatformError", (error2) => Effect9.fail(new FileReadError({
1024
+ path: file.path,
1025
+ message: `source file referenced by item "${item.name}" not readable: ${error2}`
1026
+ }))));
998
1027
  return { ...file, content };
999
1028
  }));
1000
1029
  const builtItem = {
@@ -1098,7 +1127,7 @@ var initCommand = Command3.make("init", {
1098
1127
  const cwdAbsolute = path.resolve(cwd);
1099
1128
  const hasPackageJson = yield* fileSystem.exists(path.join(cwdAbsolute, "package.json"));
1100
1129
  if (!hasPackageJson) {
1101
- return yield* new ConfigNotFoundError({ cwd: cwdAbsolute });
1130
+ return yield* new NotAProjectError({ cwd: cwdAbsolute });
1102
1131
  }
1103
1132
  const packageJson = yield* readJsonFile(path.join(cwdAbsolute, "package.json")).pipe(Effect10.orElseSucceed(() => ({})));
1104
1133
  const dependencies = packageJson.dependencies ?? {};
@@ -1149,8 +1178,13 @@ var fail = (message) => Console4.error(message).pipe(Effect12.andThen(Effect12.s
1149
1178
  var handled = main.pipe(Effect12.catchTags({
1150
1179
  ConfigNotFoundError: (error2) => fail(`No components.json found in ${error2.cwd}.
1151
1180
  Run \`foldcn init\` to create one, then try again.`),
1181
+ NotAProjectError: (error2) => fail(`No package.json found in ${error2.cwd}.
1182
+ Run \`foldcn init\` from your project root (a FoldKit app).`),
1152
1183
  JsonParseError: (error2) => fail(`Could not parse ${error2.path}:
1153
1184
  ${error2.message}`),
1185
+ FileReadError: (error2) => fail(`Could not read ${error2.path}:
1186
+ ${error2.message}`),
1187
+ DuplicateItemError: (error2) => fail(`The registry manifest declares two items named "${error2.name}". Item names must be unique.`),
1154
1188
  RegistryFetchError: (error2) => fail(`Could not fetch registry item "${error2.spec}".
1155
1189
  ${error2.message}
1156
1190
  Check the component name and your registry configuration.`),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "foldcn",
4
- "version": "0.0.19",
4
+ "version": "0.0.20",
5
5
  "description": "shadcn-style CLI for FoldKit: add copy-in components from a registry",
6
6
  "type": "module",
7
7
  "license": "MIT",