Skip to content

Commit

Permalink
move mods to data
Browse files Browse the repository at this point in the history
  • Loading branch information
Jomik committed Feb 15, 2024
1 parent 5df3270 commit c8c59d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ RUN mv /screeps/assets /data/assets && \
WORKDIR /screeps
COPY screeps-cli.js ./bin/cli
COPY screeps-start.js ./bin/start
ENV SERVER_DIR=/screeps NODE_ENV=production PATH="/screeps/bin:${PATH}"
ENV SERVER_DIR=/screeps DATA_DIR=/data NODE_ENV=production PATH="/screeps/bin:${PATH}"

VOLUME [ "/data" ]
EXPOSE 21025
Expand Down
17 changes: 8 additions & 9 deletions screeps-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ const RootDir = process.env["SERVER_DIR"];
if (!RootDir) {
throw new Error("Missing environment variable $SERVER_DIR");
}
const ConfigPath = process.env["CONFIG_FILE"] || "./config.yml";
const DataDir = process.env["DATA_DIR"];
if (!DataDir) {
throw new Error("Missing environment variable $DATA_DIR");
}
const ConfigPath =
process.env["CONFIG_FILE"] || path.join(RootDir, "config.yml");

process.chdir(RootDir);

Expand All @@ -17,7 +22,7 @@ const config = yaml.load(fs.readFileSync(ConfigPath, "utf8"));
const loadPackage = (dir) =>
JSON.parse(fs.readFileSync(path.resolve(dir, "package.json"), "utf8"));

const ModsDir = "./mods";
const ModsDir = path.join(DataDir, "mods");

const isDependency = (pkg, [name, version]) =>
pkg.includes(name) || version.includes(pkg);
Expand All @@ -30,9 +35,9 @@ const installPackages = () => {
const modsPackage = loadPackage(ModsDir);
const dependencies = modsPackage.dependencies || {};

// Calculate package diff
const packages = [...mods, ...Object.values(bots)];

// Calculate package diff
const newPackages = packages.filter(
(pkg) =>
!Object.entries(dependencies).some((dependency) =>
Expand Down Expand Up @@ -81,12 +86,6 @@ const installPackages = () => {
);
}

const newPackage = loadPackage(ModsDir);
fs.writeFileSync(
path.resolve(ModsDir, "package.json"),
JSON.stringify(newPackage, null, 2),
);

console.log("Done updating");
};

Expand Down

0 comments on commit c8c59d7

Please sign in to comment.