Skip to content

Commit

Permalink
fixup! fix: update config imports and scopes file error
Browse files Browse the repository at this point in the history
  • Loading branch information
danewalters committed Jul 2, 2024
1 parent dc2d691 commit 440c6cc
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 112 deletions.
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"jsonschema": "npm:[email protected]",
"jsonpatch": "npm:[email protected]",
"just-diff": "npm:[email protected]",
"just-diff-apply": "npm:[email protected]",
"ejs": "npm:[email protected]"
},
"tasks": {
Expand Down
141 changes: 71 additions & 70 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 20 additions & 42 deletions src/jcli/config/project-json-patch-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
ProjectPluginInstanceUpdatePatch,
} from "@/jcli/config/project-json.ts";

import { diffApply } from "just-diff-apply";

type PathNode = string | number;

type DiffPatchOp = "add" | "replace" | "remove";
Expand Down Expand Up @@ -377,23 +379,16 @@ function buildImportsPatch(
patch: ProjectPatch,
context: BuilderContext,
): void {
switch (op) {
case "replace": {
patch.imports = value as ProjectImports | undefined;
break;
}
case "add":
case "remove": {
const key = context.restPathNodes[0];
if (op === "add") {
context.dataWas.imports![key] = value as string;
} else if (op === "remove") {
delete context.dataWas.imports![key];
}
patch.imports = context.dataWas.imports;
break;
}
if (op === "replace") {
patch.imports = value as ProjectImports | undefined;
return;
}

diffApply(context.dataWas.imports!, [
{ op, path: context.restPathNodes as string[], value },
]);

patch.imports = context.dataWas.imports;
}

function buildScopesPatch(
Expand All @@ -402,33 +397,16 @@ function buildScopesPatch(
patch: ProjectPatch,
context: BuilderContext,
): void {
switch (op) {
case "replace": {
patch.scopes = value as ProjectScopes | undefined;
break;
}
case "add":
case "remove": {
const key = context.restPathNodes[0];

if (op === "add") {
if (context.restPathNodes.length === 2) {
context.dataWas.scopes![key][context.restPathNodes[1]] =
value as string;
} else {
context.dataWas.scopes![key] = value as Record<string, string>;
}
} else if (op === "remove") {
if (context.restPathNodes.length === 2) {
delete context.dataWas.scopes![key][context.restPathNodes[1]];
} else {
delete context.dataWas.scopes![key];
}
}

patch.scopes = context.dataWas.scopes;
}
if (op === "replace") {
patch.scopes = value as ProjectScopes | undefined;
return;
}

diffApply(context.dataWas.scopes!, [
{ op, path: context.restPathNodes as string[], value },
]);

patch.scopes = context.dataWas.scopes;
}

export const builder = new BuilderNode().children([
Expand Down

0 comments on commit 440c6cc

Please sign in to comment.