foldcn 0.0.17 → 0.0.19
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/bin.js +68 -17
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -17,7 +17,7 @@ var __export = (target, all) => {
|
|
|
17
17
|
// src/bin.ts
|
|
18
18
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
19
19
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
20
|
-
import { Effect as Effect12 } from "effect";
|
|
20
|
+
import { Console as Console4, Effect as Effect12 } from "effect";
|
|
21
21
|
|
|
22
22
|
// src/cli.ts
|
|
23
23
|
import { Effect as Effect11 } from "effect";
|
|
@@ -600,6 +600,18 @@ class RegistryNotConfiguredError extends Schema4.TaggedErrorClass()("RegistryNot
|
|
|
600
600
|
}) {
|
|
601
601
|
}
|
|
602
602
|
|
|
603
|
+
class RegistryTemplateError extends Schema4.TaggedErrorClass()("RegistryTemplateError", {
|
|
604
|
+
namespace: Schema4.String,
|
|
605
|
+
template: Schema4.String
|
|
606
|
+
}) {
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
class PackageManagerNotFoundError extends Schema4.TaggedErrorClass()("PackageManagerNotFoundError", {
|
|
610
|
+
packageManager: Schema4.String,
|
|
611
|
+
cause: Schema4.String
|
|
612
|
+
}) {
|
|
613
|
+
}
|
|
614
|
+
|
|
603
615
|
class UnsafeTargetError extends Schema4.TaggedErrorClass()("UnsafeTargetError", {
|
|
604
616
|
target: Schema4.String
|
|
605
617
|
}) {
|
|
@@ -686,7 +698,7 @@ var install = (plan) => Effect4.gen(function* () {
|
|
|
686
698
|
stderr: "inherit"
|
|
687
699
|
});
|
|
688
700
|
return yield* handle.exitCode;
|
|
689
|
-
}));
|
|
701
|
+
})).pipe(Effect4.catchTag("PlatformError", (error2) => Effect4.fail(new PackageManagerNotFoundError({ packageManager: plan.packageManager, cause: String(error2) }))));
|
|
690
702
|
if (exitCode !== 0) {
|
|
691
703
|
return yield* new InstallFailedError({
|
|
692
704
|
packageManager: plan.packageManager,
|
|
@@ -757,6 +769,9 @@ var makeGetItem = (options) => Effect6.gen(function* () {
|
|
|
757
769
|
if (template2 === undefined) {
|
|
758
770
|
return yield* new RegistryNotConfiguredError({ namespace });
|
|
759
771
|
}
|
|
772
|
+
if (!template2.includes(namePlaceholder)) {
|
|
773
|
+
return yield* new RegistryTemplateError({ namespace, template: template2 });
|
|
774
|
+
}
|
|
760
775
|
return { location: template2.replace(namePlaceholder, name), template: template2 };
|
|
761
776
|
}
|
|
762
777
|
const originTemplate = Option2.flatMap(maybeOrigin, (origin) => Option2.fromNullishOr(keyTemplates.get(origin)));
|
|
@@ -850,7 +865,11 @@ var planFiles = (context, files) => Effect8.gen(function* () {
|
|
|
850
865
|
const relativeToKind = stripRegistrySourcePrefix(file.path);
|
|
851
866
|
const baseDir = file.type === "registry:lib" ? context.libDir : context.uiDir;
|
|
852
867
|
const absolutePath = path.resolve(baseDir, relativeToKind);
|
|
853
|
-
|
|
868
|
+
const relativeFromCwd = path.relative(context.cwd, absolutePath);
|
|
869
|
+
if (relativeFromCwd.startsWith("..") || path.isAbsolute(relativeFromCwd)) {
|
|
870
|
+
return yield* new UnsafeTargetError({ target: relativeFromCwd });
|
|
871
|
+
}
|
|
872
|
+
planned.push({ absolutePath, relativePath: relativeFromCwd, content });
|
|
854
873
|
}
|
|
855
874
|
return planned;
|
|
856
875
|
});
|
|
@@ -874,6 +893,22 @@ var runAdd = ({ components, cwd, dryRun, overwrite, registry: registry2 }) => Ef
|
|
|
874
893
|
}
|
|
875
894
|
const writableFiles = tree.files.filter((file) => file.type !== "registry:example");
|
|
876
895
|
const allPlanned = yield* planFiles(context, writableFiles);
|
|
896
|
+
if (dryRun) {
|
|
897
|
+
yield* Console.log(`Would write ${allPlanned.length} ${allPlanned.length === 1 ? "file" : "files"}:`);
|
|
898
|
+
for (const file of allPlanned) {
|
|
899
|
+
const exists = yield* fileSystem.exists(file.absolutePath);
|
|
900
|
+
const existing = exists ? yield* fileSystem.readFileString(file.absolutePath) : undefined;
|
|
901
|
+
const note = exists && existing !== file.content ? " (exists — needs --overwrite)" : exists ? " (unchanged)" : "";
|
|
902
|
+
yield* Console.log(` ${file.relativePath}${note}`);
|
|
903
|
+
}
|
|
904
|
+
if (tree.dependencies.length > 0) {
|
|
905
|
+
yield* Console.log(`Would install: ${tree.dependencies.join(" ")}`);
|
|
906
|
+
}
|
|
907
|
+
if (tree.devDependencies.length > 0) {
|
|
908
|
+
yield* Console.log(`Would install (dev): ${tree.devDependencies.join(" ")}`);
|
|
909
|
+
}
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
877
912
|
const planned = [];
|
|
878
913
|
const conflicts = [];
|
|
879
914
|
for (const file of allPlanned) {
|
|
@@ -895,19 +930,6 @@ var runAdd = ({ components, cwd, dryRun, overwrite, registry: registry2 }) => Ef
|
|
|
895
930
|
if (conflicts.length > 0) {
|
|
896
931
|
return yield* new FileConflictError({ paths: conflicts });
|
|
897
932
|
}
|
|
898
|
-
if (dryRun) {
|
|
899
|
-
yield* Console.log(`Would write ${planned.length} files:`);
|
|
900
|
-
for (const file of planned) {
|
|
901
|
-
yield* Console.log(` ${file.relativePath}`);
|
|
902
|
-
}
|
|
903
|
-
if (tree.dependencies.length > 0) {
|
|
904
|
-
yield* Console.log(`Would install: ${tree.dependencies.join(" ")}`);
|
|
905
|
-
}
|
|
906
|
-
if (tree.devDependencies.length > 0) {
|
|
907
|
-
yield* Console.log(`Would install (dev): ${tree.devDependencies.join(" ")}`);
|
|
908
|
-
}
|
|
909
|
-
return;
|
|
910
|
-
}
|
|
911
933
|
for (const file of planned) {
|
|
912
934
|
yield* fileSystem.makeDirectory(path.dirname(file.absolutePath), { recursive: true });
|
|
913
935
|
yield* fileSystem.writeFileString(file.absolutePath, file.content);
|
|
@@ -1123,4 +1145,33 @@ var run = Effect11.fn("FoldcnCli.run")(function* (argv) {
|
|
|
1123
1145
|
var main = Command4.run(command, { version });
|
|
1124
1146
|
|
|
1125
1147
|
// src/bin.ts
|
|
1126
|
-
|
|
1148
|
+
var fail = (message) => Console4.error(message).pipe(Effect12.andThen(Effect12.sync(() => globalThis.process.exitCode = 1)));
|
|
1149
|
+
var handled = main.pipe(Effect12.catchTags({
|
|
1150
|
+
ConfigNotFoundError: (error2) => fail(`No components.json found in ${error2.cwd}.
|
|
1151
|
+
Run \`foldcn init\` to create one, then try again.`),
|
|
1152
|
+
JsonParseError: (error2) => fail(`Could not parse ${error2.path}:
|
|
1153
|
+
${error2.message}`),
|
|
1154
|
+
RegistryFetchError: (error2) => fail(`Could not fetch registry item "${error2.spec}".
|
|
1155
|
+
${error2.message}
|
|
1156
|
+
Check the component name and your registry configuration.`),
|
|
1157
|
+
RegistryNotConfiguredError: (error2) => fail(`No registry configured for "${error2.namespace}".
|
|
1158
|
+
Add it to the "registries" map in components.json.`),
|
|
1159
|
+
RegistryTemplateError: (error2) => fail(`The registry template for "${error2.namespace}" is missing the {name} placeholder:
|
|
1160
|
+
${error2.template}
|
|
1161
|
+
Add {name} so each component resolves to its own file.`),
|
|
1162
|
+
UnsafeTargetError: (error2) => fail(`Refusing to write outside the project: ${error2.target}
|
|
1163
|
+
Check the "aliases" in components.json and the item's target.`),
|
|
1164
|
+
FileConflictError: (error2) => fail(`These files already exist and differ from the registry:
|
|
1165
|
+
${error2.paths.map((path) => ` ${path}`).join(`
|
|
1166
|
+
`)}
|
|
1167
|
+
Pass --overwrite to replace them.`),
|
|
1168
|
+
InstallFailedError: (error2) => fail(`\`${error2.packageManager} ${error2.invocation}\` failed (exit ${error2.exitCode}).
|
|
1169
|
+
The component files were written; install the dependencies manually.`),
|
|
1170
|
+
PackageManagerNotFoundError: (error2) => fail(`Could not run the package manager "${error2.packageManager}".
|
|
1171
|
+
${error2.cause}
|
|
1172
|
+
Install it (or use a project with a lockfile for another manager), then re-run.`),
|
|
1173
|
+
StylesheetNotFoundError: (error2) => fail(`Stylesheet not found: ${error2.path}
|
|
1174
|
+
Check the "css" path in components.json.`),
|
|
1175
|
+
UnknownRegistryDependencyError: (error2) => fail(`"${error2.itemName}" depends on "${error2.dependency}", which is not in the registry.`)
|
|
1176
|
+
}));
|
|
1177
|
+
NodeRuntime.runMain(handled.pipe(Effect12.provide(NodeServices.layer)));
|
package/package.json
CHANGED