Skip to content

Commit

Permalink
Add dependency management functionality and update version to 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
timschwartz committed Feb 24, 2025
1 parent 9ebb3de commit 5c24a35
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metaverse-systems/the-seed",
"version": "1.0.3",
"version": "1.0.5",
"description": "The Seed",
"main": "dist/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/Build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Config from "./Config";
const { execSync } = require('child_process');

const targets: {
export const targets: {
[key:string]: string;
} = {
"native": "x86_64-linux-gnu",
Expand Down
95 changes: 95 additions & 0 deletions src/Dependencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import Config from "./Config";
const { execSync } = require("child_process");
import { targets } from "./Build";

const execOptions = { stdio: "pipe", shell: "/bin/bash", env: { ...process.env } };
const libEcsRepo = "https://github.com/metaverse-systems/libecs-cpp.git";
const libTheSeedRepo = "https://github.com/metaverse-systems/libthe-seed.git";

export const checkLib = (config: Config, library: string, target: string) => {
const targetPrefix = targets[target];
const prefix = config.config.prefix + "/" + targetPrefix;
const pkgConfigCommand =
"PKG_CONFIG_PATH=" +
prefix +
"/lib/pkgconfig/ " +
"pkg-config --cflags --libs " +
library;
try {
const result = execSync(pkgConfigCommand, execOptions).toString();
if (result.includes(library)) {
return true;
}
console.error("pkg-config did not find " + library);
} catch (e) {
return false;
}
return false;
};

export const checkLibEcs = (config: Config, target: string) => {
return checkLib(config, "ecs-cpp", target);
};

export const checkLibTheSeed = (config: Config, target: string) => {
return checkLib(config, "the-seed", target);
};

export const installLibEcs = (config: Config, target: string) => {
const targetDir = targets[target];
const prefix = config.config.prefix + "/" + targetDir;
const cloneCommand = "git clone " + libEcsRepo;
try {
const result = execSync(cloneCommand, execOptions).toString();
} catch (e) {
console.error("Failed to clone libecs-cpp");
}
const buildCommand =
"cd ecs-cpp && ./autogen.sh && ./configure --prefix=" +
prefix +
target != "native" ? " --host=" + targetDir : "" +
" && make && make install";
try {
const result = execSync(buildCommand, execOptions).toString();
} catch (e) {
console.error("Failed to build libecs-cpp");
console.error(e);
return false;
}
return true;
};

export const installLibTheSeed = (config: Config, target: string) => {
const targetDir = targets[target];
const prefix = config.config.prefix + "/" + targetDir;
const cloneCommand = "git clone " + libTheSeedRepo;
try {
const result = execSync(cloneCommand, execOptions).toString();
} catch (e) {
console.error("Failed to clone libthe-seed");
}
const env = {
...process.env,
PKG_CONFIG_PATH: `${prefix}/lib/pkgconfig/`
};

let buildCommand = "cd libthe-seed";
buildCommand += " && ./autogen.sh";
buildCommand += " && PKG_CONFIG_PATH=" + prefix + "/lib/pkgconfig/";
buildCommand += " ./configure --prefix=" + prefix;
if(target != "native") {
buildCommand += " --host=" + targetDir;
}
buildCommand += " && make && make install";
try {
const result = execSync(
buildCommand,
{ stdio: "inherit", env, shell: "/bin/bash" }
);
} catch (e) {
console.error("Failed to build libthe-seed");
console.error(e);
return false;
}
return true;
};
57 changes: 57 additions & 0 deletions src/scripts/DependenciesCLI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { checkLibEcs, checkLibTheSeed, installLibEcs, installLibTheSeed } from "../Dependencies";
import Config from "../Config";
import { ScriptArgsType } from "../types";

const DependenciesCLI = (scriptConfig: ScriptArgsType) => {
const config = new Config(scriptConfig.configDir);

const command = scriptConfig.args[3];
const target = scriptConfig.args[4] ? scriptConfig.args[4] : "native";

switch (command) {
case "help":
console.log("\nUsage: the-seed dependencies <command>");
console.log("\nAvailable commands:");
console.log(" help - Show this help message");
console.log(" check - Check if dependencies are installed");
break;
case "check":
if (checkLibEcs(config, target)) {
console.log("libecs-cpp is installed.");
} else {
console.log("libecs-cpp is not installed.");
}
if (checkLibTheSeed(config, target)) {
console.log("libthe-seed is installed.");
} else {
console.log("libthe-seed is not installed.");
}
break;
case "install":
if (!checkLibEcs(config, target)) {
console.log("Installing libecs-cpp...");
if (installLibEcs(config, target)) {
console.log("libecs-cpp installed successfully.");
} else {
console.error("Failed to install libecs-cpp.");
}
}
if (!checkLibTheSeed(config, target)) {
console.log("Installing libthe-seed...");
if (installLibTheSeed(config, target)) {
console.log("libthe-seed installed successfully.");
} else {
console.error("Failed to install libthe-seed.");
}
}
break;
default:
console.log(
"Invalid command. Use 'the-seed dependencies help' for usage information."
);
break;
}
return true;
};

export default DependenciesCLI;
8 changes: 8 additions & 0 deletions src/scripts/the-seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ScopesCLI from "./ScopesCLI";
import TemplateCLI from "./TemplateCLI";
import BuildCLI from "./BuildCLI";
import ResourcePakCLI from "./ResourcePakCLI";
import DependenciesCLI from "./DependenciesCLI";
import { ScriptArgsType } from "../types";

const homedir = os.homedir;
Expand All @@ -21,6 +22,7 @@ const section = scriptConfig.args[2] || "help";
switch(section)
{
case "help":
console.log(scriptConfig.binName + " dependencies");
console.log(scriptConfig.binName + " build");
console.log(scriptConfig.binName + " config");
console.log(scriptConfig.binName + " scopes");
Expand All @@ -42,4 +44,10 @@ switch(section)
case "resource-pak":
ResourcePakCLI(scriptConfig);
break;
case "dependencies":
DependenciesCLI(scriptConfig);
break;
default:
console.log("Invalid command. Use 'the-seed help' for usage information.");
break;
}

0 comments on commit 5c24a35

Please sign in to comment.