58 lines
1.7 KiB
Nix
58 lines
1.7 KiB
Nix
{ pkgs ? import <nixpkgs> { }, proj ? pkgs.proj }:
|
|
pkgs.buildGoModule rec {
|
|
meta = {
|
|
description = "Nidus Sync";
|
|
homepage = "https://github.com/Gleipnir-Technology/nidus-sync";
|
|
};
|
|
pname = "nidus-sync";
|
|
src = ./.;
|
|
subPackages = [];
|
|
version = "0.0.11";
|
|
# Needs to be updated after every modification of go.mod/go.sum
|
|
vendorHash = "sha256-zXjryPAJYpc80cqYtrcp//i6OQi5V5QwhaKQYYfrlL8=";
|
|
|
|
buildInputs = [ pkgs.proj ];
|
|
nativeBuildInputs = [
|
|
pkgs.pkg-config
|
|
pkgs.dart-sass
|
|
pkgs.esbuild
|
|
];
|
|
|
|
preBuild = ''
|
|
# Compile SCSS
|
|
SASS_SRC_DIR="./scss"
|
|
CSS_OUTPUT_DIR="./static/gen/css"
|
|
|
|
mkdir -p "$CSS_OUTPUT_DIR"
|
|
|
|
echo "Compiling $SASS_SRC_DIR/style.scss to $CSS_OUTPUT_DIR/style.css..."
|
|
sass --style=compressed --trace "$SASS_SRC_DIR/style.scss":"$CSS_OUTPUT_DIR/style.css"
|
|
|
|
# Generate hash and rename style
|
|
STYLE_HASH=$(sha256sum "$CSS_OUTPUT_DIR/style.css" | cut -c1-12)
|
|
mv "$CSS_OUTPUT_DIR/style.css" "$CSS_OUTPUT_DIR/style.$STYLE_HASH.css"
|
|
echo "Generated CSS style with hash: $STYLE_HASH"
|
|
|
|
# Bundle TypeScript
|
|
JS_OUTPUT_DIR="./static/gen/js"
|
|
mkdir -p "$JS_OUTPUT_DIR"
|
|
|
|
echo "Bundling TypeScript..."
|
|
esbuild ts/main.ts --bundle --minify --outfile="$JS_OUTPUT_DIR/bundle.js"
|
|
|
|
# Generate hash and rename bundle
|
|
BUNDLE_HASH=$(sha256sum "$JS_OUTPUT_DIR/bundle.js" | cut -c1-12)
|
|
mv "$JS_OUTPUT_DIR/bundle.js" "$JS_OUTPUT_DIR/bundle.$BUNDLE_HASH.js"
|
|
echo "Generated JS bundle with hash: $BUNDLE_HASH"
|
|
|
|
# Generate gen.go with bundle path
|
|
cat > static/gen.go <<EOF
|
|
package static
|
|
|
|
// Generated by Nix build - do not edit manually
|
|
const BundlePathCSS = "/static/gen/css/style.$STYLE_HASH.css"
|
|
const BundlePathJS = "/static/gen/js/bundle.$BUNDLE_HASH.js"
|
|
EOF
|
|
echo "Generated static/gen.go"
|
|
'';
|
|
}
|