Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Package using nix
Browse files Browse the repository at this point in the history
  • Loading branch information
prescientmoon committed Nov 15, 2023
1 parent 8db9f46 commit a545495
Show file tree
Hide file tree
Showing 36 changed files with 1,616 additions and 1,017 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build and deploy

on:
push:
pull_request:

permissions:
contents: read
pages: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main

- name: Build project
run: nix build .#doffycup-github-pages

- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: ./result/www

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/master'

steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
34 changes: 0 additions & 34 deletions .github/workflows/ghpages.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ node_modules
dist
dist-ssr
*.local
.direnv
result
.envrc
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# doffycup
# Doffycup

To see how the project looks like and how it works see the presentation here: https://youtu.be/h536BEVIe1U?t=296

49 changes: 49 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as esbuild from "esbuild";
import { htmlPlugin } from "@craftamap/esbuild-plugin-html";
import * as fs from "fs";

const serve = process.env.ESBUILD_SERVE === "1";
const baseurl = process.env.ESBUILD_BASEURL || "";

console.log(`Building with baseurl ${baseurl}`);

const entryPoints = ["src/main.tsx"];

const ctx = await esbuild.context({
entryPoints,
minify: !serve,
bundle: true,
metafile: true,
sourcemap: true,
outdir: "dist",
format: "esm",
target: ["es2020"],
assetNames: "assets/[name]",
loader: { ".png": "file" },
define: {
"process.env.BASEURL": JSON.stringify(baseurl),
},
plugins: [
htmlPlugin({
files: [
{
entryPoints,
filename: "index.html",
favicon: "src/favicon.ico",
htmlTemplate: "src/index.html",
scriptLoading: "module",
},
],
}),
],
publicPath: baseurl,
});

if (serve) {
const { port, host } = await ctx.serve({ servedir: "dist" });
console.log(`Serving on ${host}:${port}`);
} else {
await ctx.rebuild();
await ctx.dispose();
console.log(`Project bundled successfully`);
}
58 changes: 58 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
description = "Doffycup";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
nodejs = pkgs.nodejs_18;
in
rec {
packages.doffycup = pkgs.buildNpmPackage {
name = "doffycup";

buildInputs = [ nodejs pkgs.gzip ];

src = pkgs.lib.cleanSource ./.;
npmDepsHash = builtins.readFile ./npm-deps-hash;

ESBUILD_BASEURL = "";

postBuild = ''
# Github pages requires an additional 404.html file
cp dist/{index,404}.html
# -k = keeps the original files in place
# -r = recursive
# -9 = best compression
gzip -kr9 dist
'';

installPhase = ''
mkdir $out
cp -r dist $out/www
'';
};

# Github pages deploys to a subfolder
packages.doffycup-github-pages = packages.doffycup.overrideAttrs {
ESBUILD_BASEURL = "/doffycup";
};

packages.default = packages.doffycup;

devShells.default = pkgs.mkShell {
packages = [ nodejs ];
};

apps.compute-npm-dep-hash = {
type = "app";
program = pkgs.lib.getExe (pkgs.writeShellApplication {
name = "generate-layout-previes";
runtimeInputs = [ pkgs.prefetch-npm-deps ];
text = "prefetch-npm-deps ./package-lock.json > ./npm-deps-hash";
});
};
}
);
}

13 changes: 0 additions & 13 deletions index.html

This file was deleted.

1 change: 1 addition & 0 deletions npm-deps-hash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sha256-KuC12heZGyrrba49L4PUnoWwnZpEpOEx8q+wDpDaFr4=
Loading

0 comments on commit a545495

Please sign in to comment.