Skip to content

Commit

Permalink
chore: final cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Anut-py committed Jan 17, 2024
1 parent 06a94cf commit 854f1d1
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 23 deletions.
75 changes: 63 additions & 12 deletions devtools.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
const { rmSync, readFileSync, existsSync, writeFileSync } = require("fs");
const {
rmSync,
readFileSync,
existsSync,
writeFileSync,
copyFileSync,
} = require("fs");
const { execSync, spawnSync } = require("child_process");
const path = require("path");

const exec = (c) => execSync(c).toString();
const exec = (...c) => execSync(...c).toString();

const silent = process.argv.includes("-s") || process.argv.includes("--silent"); // No logs
const quiet = process.argv.includes("-q") || process.argv.includes("--quiet"); // Errors only
const verbose =
process.argv.includes("-v") || process.argv.includes("--verbose"); // All logs
const normal = !silent && !quiet && !verbose; // Non-verbose logs

const hraylibVersion = readFileSync(path.join(__dirname, "h-raylib.cabal"))
.toString()
.split("\n")
.find((line) => line.startsWith("version:"))
.split(/\s+/)[1];

const logLevel = { VERB: 0, INFO: 1, WARN: 2, ERR: 3 };
const log = (level, ...strs) => {
// Level 0 = verbose, level 1 = info, level 2 = warning, level 3 = error
Expand Down Expand Up @@ -86,13 +98,6 @@ if (process.argv.includes("-u") || process.argv.includes("--nix-update")) {

log(logLevel.VERB, "Found revision: " + revision);
log(logLevel.VERB, "Fetching h-raylib version");

const hraylibVersion = readFileSync(path.join(__dirname, "h-raylib.cabal"))
.toString()
.split("\n")
.find((line) => line.startsWith("version:"))
.split(/\s+/)[1];

log(logLevel.INFO, "h-raylib version " + hraylibVersion);

const flakeUpdated = readFileSync(
Expand Down Expand Up @@ -201,6 +206,46 @@ if (process.argv.includes("-u") || process.argv.includes("--nix-update")) {
shell: true,
});
}
} else if (process.argv.includes("-p") || process.argv.includes("--package")) {
const cabalPath = findCommandPath("cabal", "--cabal-path", "-c");

log(logLevel.INFO, "Using cabal path: " + cabalPath);
log(logLevel.VERB, "Cleaning and packaging");

exec(`${cabalPath} clean`);
exec(`${cabalPath} sdist`);

log(logLevel.INFO, "Successfully packaged the project");
log(logLevel.INFO, "Extracting dist files");
log(logLevel.VERB, "h-raylib version " + hraylibVersion);

exec(
`cd ${path.join(
__dirname,
"dist-newstyle",
"sdist"
)} && tar -xzf h-raylib-${hraylibVersion}.tar.gz`
);

log(logLevel.VERB, "Dist files extracted");
log(logLevel.VERB, "Copying files");

const extractPath = path.join(
__dirname,
"dist-newstyle",
"sdist",
`h-raylib-${hraylibVersion}`
);

copyFileSync(path.join(__dirname, "cabal.project"), path.join(extractPath, "cabal.project"));
copyFileSync(path.join(__dirname, "run-all-examples.sh"), path.join(extractPath, "run-all-examples.sh"));

log(logLevel.INFO, `Building and running project in ${extractPath}`);

spawnSync(`cd ${extractPath} && sh ${path.join(extractPath, "run-all-examples.sh")}`, {
shell: true,
stdio: "inherit",
});
} else {
const helpText = `
This script contains useful tools for h-raylib development
Expand All @@ -224,13 +269,19 @@ This script contains useful tools for h-raylib development
-d Diff the local raylib source with the latest remote code
--raylib-diff
-p Package the cabal project and run the examples
--package
Additional options
-n <NIX-PATH> Manually provide the path to nix; if not provided, the PATH environment variable will be searched
-n <NIX-PATH> Manually provide the path to nix; if not provided, the PATH environment variable will be searched
--nix-path=<NIX-PATH>
-g <NIX-PATH> Manually provide the path to git; if not provided, the PATH environment variable will be searched
--git-path=<NIX-PATH>
-g <GIT-PATH> Manually provide the path to git; if not provided, the PATH environment variable will be searched
--git-path=<GIT-PATH>
-c <CABAL-PATH> Manually provide the path to cabal; if not provided, the PATH environment variable will be searched
--cabal-path=<CABAL-PATH>
`;
console.log(helpText);
}
24 changes: 13 additions & 11 deletions h-raylib.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ extra-source-files:
examples/**/*.mtl
examples/**/*.obj
examples/**/*.png
examples/**/*.ttf
examples/**/*.vert
examples/**/*.xm
lib/**/*.c
lib/**/*.h
lib/**/*.m
Expand Down Expand Up @@ -201,7 +203,8 @@ library
winmm
shell32
gcc
if impl(ghc < 9.4.1)

if impl(ghc <9.4.1)
extra-libraries: gcc_eh

else
Expand All @@ -210,7 +213,8 @@ library
gdi32
winmm
shell32
if impl(ghc < 9.4.1)

if impl(ghc <9.4.1)
extra-libraries: gcc_eh

elif (flag(platform-linux) || (flag(detect-platform) && os(linux)))
Expand Down Expand Up @@ -238,9 +242,8 @@ library
GL
pthread

elif (flag(platform-nixos))
pkgconfig-depends:
raylib
elif flag(platform-nixos)
pkgconfig-depends: raylib

else

Expand All @@ -250,8 +253,8 @@ library
lib/rl_bindings.c
lib/rl_internal.c
lib/rlgl_bindings.c
if (!flag(platform-nixos))

if !flag(platform-nixos)
c-sources:
raylib/src/raudio.c
raylib/src/rcore.c
Expand All @@ -268,16 +271,15 @@ library
elif (flag(ghci) && (flag(platform-windows) || (flag(detect-platform) && os(windows))))
c-sources: lib/glfw_patch/rglfw_patch.c

elif (!flag(platform-nixos))
elif !flag(platform-nixos)
c-sources: raylib/src/rglfw.c

if flag(ghci)
cpp-options: -DGHCI

include-dirs:
lib
include-dirs: lib

if (!flag(platform-nixos))
if !flag(platform-nixos)
include-dirs:
raylib/src raylib/src/external/glfw/src
raylib/src/external/glfw/include

0 comments on commit 854f1d1

Please sign in to comment.