Skip to content

Commit

Permalink
load all ops in dir
Browse files Browse the repository at this point in the history
  • Loading branch information
steam0r committed Mar 7, 2024
1 parent dc3f419 commit 07f5387
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions src/electron/electron_endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,21 @@ class ElectronEndpoint
async getProjectOpsCode()
{
const project = this.getCurrentProject();
const opDocs = doc.getOpDocs(true, true);
let opDocs = doc.getOpDocs(true, true);
let code = "";
let missingOps = [];
if (project && project.ops)
{
let missingOps = project.ops.filter((op) => { return !opDocs.some((d) => { return d.id === op.opId; }); });
missingOps = project.ops.filter((op) => { return !opDocs.some((d) => { return d.id === op.opId; }); });
const ops = subPatchOpUtil.getOpsUsedInSubPatches(project);
const opsInProjectDir = this._getOpDocsInProjectDir();
missingOps = missingOps.concat(ops);
missingOps = missingOps.concat(opsInProjectDir);
missingOps = missingOps.filter((op) => { return !opDocs.some((d) => { return d.id === op.opId; }); });
missingOps = missingOps.filter((obj, index) => { return missingOps.findIndex((item) => { return item.opId === obj.opId; }) === index; });
code = opsUtil.buildFullCode(missingOps, opsUtil.PREFIX_OPS, opDocs);
return code;
}
else
{
return code;
}
code = opsUtil.buildFullCode(missingOps, opsUtil.PREFIX_OPS, true, true, opDocs);
return code;
}

savePatch(patch)
Expand Down Expand Up @@ -274,7 +273,8 @@ class ElectronEndpoint
"_id": randomId,
"shortId": shortId,
"name": "new project",
"ops": []
"ops": [],
"settings": {}
};
}
}
Expand Down Expand Up @@ -1126,17 +1126,47 @@ class ElectronEndpoint
{
const fileContents = packageFiles[packageFile];
const fileJson = JSON.parse(fileContents);
const deps = fileJson.packages[""].dependencies;
Object.keys(deps)
.forEach((lib) =>
const packages = fileJson.packages;
if (packages && packages[""])
{
const deps = packages[""].dependencies || [];
Object.keys(deps).forEach((lib) =>
{
const ver = deps[lib];
const semVer = lib + "@" + ver;
toInstall.push(addDependency(semVer, { "cwd": currentProjectDir }));
});
}
});
return Promise.all(toInstall);
}

_getOpDocsInProjectDir()
{
const dir = cables.getProjectOpsPath();
const opDocs = [];
if (fs.existsSync(dir))
{
const jsonFiles = helper.getFilesRecursive(dir, ".json");
Object.keys(jsonFiles).forEach((jsonFile) =>
{
const basename = path.basename(jsonFile, ".json");
if (opsUtil.isOpNameValid(basename))
{
try
{
const opJson = JSON.parse(jsonFiles[jsonFile].toString());
opJson.objName = basename;
opJson.opId = opJson.id;
opJson.name = basename;
opDocs.push(opJson);
}
catch (e) {}
}
});
}
return opDocs;
}
}

export default new ElectronEndpoint();

0 comments on commit 07f5387

Please sign in to comment.