Skip to content

Commit

Permalink
Modernise several aspects, update dependencies, tighten core constriant.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lattyware committed May 19, 2024
1 parent 968c503 commit 3d49167
Show file tree
Hide file tree
Showing 15 changed files with 533 additions and 540 deletions.
38 changes: 19 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
ARG NODE_VERSION=21
ARG NODE_VERSION=22
ARG ELM_FONTAWESOME_VERSION


FROM node:${NODE_VERSION}-alpine AS base

WORKDIR "/fa"

COPY --link ["./package.json", "./package-lock.json", "elm-tooling.json", "./"]


# Build the generator.
FROM base AS build

COPY ["./package.json", "./package-lock.json", "elm-tooling.json", "./"]
RUN ["npm", "ci", "--include=dev"]

COPY ["./tsconfig.json", "./"]
COPY ["./src", "./src"]
RUN ["npm", "run", "build"]

RUN \
--mount=type=cache,target=/usr/src/app/.npm \
npm set cache /usr/src/app/.npm && \
npm ci --include=dev

# Install only prod dependencies.
FROM base AS install

COPY ["./package.json", "./package-lock.json", "elm-tooling.json", "./"]
RUN ["npm", "ci"]
COPY --link ["./tsconfig.json", "./"]
COPY --link ["./src", "./src"]
RUN npm run build


# Image for the generator.
# `--target generator` to stop here and get an image to generate with repeatedly.
FROM base AS generator

COPY ["./package.json", "./"]
COPY --from=install ["/fa/node_modules", "./node_modules"]
COPY ["./config.json", "./"]
COPY ["./base", "./base"]
COPY --from=build ["/fa/dist/generator", "./"]
COPY --link ["./config.json", "./"]
RUN \
--mount=type=cache,target=/usr/src/app/.npm \
npm set cache /usr/src/app/.npm && \
npm ci

COPY --link ["./base", "./base"]
COPY --link --from=build ["/fa/dist/generator", "./"]

CMD ["node", "--enable-source-maps", "./cli.js"]

Expand All @@ -50,4 +50,4 @@ RUN ["node", "--enable-source-maps", "./cli.js"]
# Just keep the generated files.
FROM scratch AS generated

COPY --from=generate ["/fa/dist/lib/.", "/."]
COPY --link --from=generate ["/fa/dist/lib/.", "/."]
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ itself][elm-fontawesome].
## How it works.

This package works by generating Elm source code using [the FontAwesome SVG
JavaScript Core][fa-core].
JavaScript Core library][fa-core].

We load icon packs, then generate Elm functions for each icon. When run, these
generate the desired SVG icons. This means no need to rely on any external
Expand Down Expand Up @@ -55,20 +55,15 @@ Note our build process requires [Buildx/BuildKit][buildx] enabled Docker.
You can then run `npm run docker:generate` to generate the Elm library into
the `build` directory.

If you would like to build without Docker, you will need Node 18 installed.
You can install dependencies with `npm install`. Note that [the FontAwesome
packages are currently broken][font-awesome-bug] and require manual fixing to
work in node as modules. E.g:

```sh
for f in node_modules/@fortawesome/_/_.es.js; do mv "$f" "$(echo "$f" | sed s/\.es\.js/\.mjs/)"; done
for f in node_modules/@fortawesome/*/package.json; do sed -i s/\.es\.js/\.mjs/ "$f"; done
```
If you would like to build without Docker, you will need Node 22 installed.
You can install dependencies with `npm install`.

You can then run `npm run generate` to generate the Elm library into the
build` directory.

You can modify `config.json` to further customise the build.
You can modify `config.json` to further customise the build. You can also write a
`config.js` file instead to do something more fancy (export the generated config
as default).

- `version`: (Required) The version number to output in the generated elm.json
file.
Expand Down
1 change: 1 addition & 0 deletions base/.github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
if git diff --exit-code; then
echo "No changes to commit."
else
echo "Changes to commit."
git add -A
git commit -m "Generated by ${{ github.repository }}" -m "Commit: ${{ env.GIT_TAG_NAME || github.sha }}"
git tag -am "${GIT_TAG_NAME} Release" "${GIT_TAG_NAME}"
Expand Down
2 changes: 1 addition & 1 deletion base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ the powerful transformation, layering, text, counter, and masking features.

## How it works.

This package is generated using [the FontAwesome SVG JavaScript Core][fa-core].
This package is generated using [the FontAwesome SVG JavaScript Core library][fa-core].
If you are interested in how this is done, would like to manually subset the
icons (which shouldn't be necessary due to tree-shaking in most cases), or want
to update to a new version of FontAwesome (do also feel free to submit an issue
Expand Down
31 changes: 18 additions & 13 deletions base/example/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,35 @@ ARG ELM_VERSION=0.19.1
ARG ELM_FONTAWESOME_SOURCE=context
ARG ELM_FONTAWESOME_PACKAGE=lattyware/elm-fontawesome


FROM alpine AS base

ARG ELM_VERSION

WORKDIR "/elm"

RUN [ "apk", "add", "--no-cache", "jq", "moreutils" ]
RUN \
--mount=type=cache,sharing=locked,target=/etc/apk/cache \
apk add --no-cache jq moreutils

ADD https://github.com/elm/compiler/releases/download/${ELM_VERSION}/binary-for-linux-64-bit.gz /elm/elm.gz
ADD --link https://github.com/elm/compiler/releases/download/${ELM_VERSION}/binary-for-linux-64-bit.gz /elm/elm.gz

RUN gunzip elm.gz
RUN chmod +x elm
RUN mkdir -p "/elm/${ELM_VERSION}/bin"
RUN mv elm "/elm/${ELM_VERSION}/bin/elm"
RUN \
gunzip elm.gz && \
chmod +x elm && \
mkdir -p "/elm/${ELM_VERSION}/bin" && \
mv elm "/elm/${ELM_VERSION}/bin/elm"

ENV PATH=/elm/${ELM_VERSION}/bin:${PATH}

RUN [[ "$(elm --version)" == "${ELM_VERSION}" ]] && echo "Elm ${ELM_VERSION} installed." || exit 1
RUN [[ "$(elm --version)" == "${ELM_VERSION}" ]] && echo "Elm ${ELM_VERSION} installed." || exit 1

WORKDIR "/build"

COPY [ ".", "." ]
RUN jq '."source-directories" -= ["lib"]' elm.json | sponge elm.json
RUN jq 'del(.dependencies.direct."lattyware/elm-fontawesome")' elm.json | sponge elm.json
COPY --link [ ".", "." ]
RUN \
jq '."source-directories" -= ["lib"]' elm.json | sponge elm.json && \
jq 'del(.dependencies.direct."lattyware/elm-fontawesome")' elm.json | sponge elm.json


# This is replaced with a context when this is baked.
Expand All @@ -35,7 +40,7 @@ FROM scratch as fontawesome
# Use a copy of fontawesome supplied by the context.
FROM base as context

COPY --from=fontawesome [ "/src/.", "lib/." ]
COPY --link --from=fontawesome [ "/src/.", "lib/." ]
RUN jq '."source-directories" += ["lib"]' elm.json | sponge elm.json


Expand All @@ -55,5 +60,5 @@ RUN ["elm", "make", "src/Example.elm", "--optimize", "--output=dist/example.js"]
# Just keep the generated files.
FROM scratch AS generated

COPY [ "assets/.", "/." ]
COPY --from=build ["/build/dist/.", "/."]
COPY --link [ "assets/.", "/." ]
COPY --link --from=build ["/build/dist/.", "/."]
2 changes: 1 addition & 1 deletion base/example/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# FontAwesome 5 for Elm Example.
# FontAwesome for Elm Example.

[![Generator Build Status](https://img.shields.io/github/actions/workflow/status/lattyware/elm-fontawesome-generator/build.yml?logo=github&label=generator%20build)](https://github.com/Lattyware/elm-fontawesome-generator/actions/workflows/build.yml)
[![Package Publish Status](https://img.shields.io/github/actions/workflow/status/lattyware/elm-fontawesome/publish.yml?logo=github&label=package%20publish)](https://github.com/Lattyware/elm-fontawesome/actions/workflows/publish.yml)
Expand Down
27 changes: 0 additions & 27 deletions eslint.config.js

This file was deleted.

31 changes: 31 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import simpleImportSort from "eslint-plugin-simple-import-sort";
import js from "@eslint/js";
import ts from "typescript-eslint";
import prettierConfig from "eslint-config-prettier";

export default [
js.configs.recommended,
...ts.configs.strictTypeChecked,
...ts.configs.stylisticTypeChecked,
prettierConfig,
{
include: ["src/**/*"],
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
"simple-import-sort": simpleImportSort
},
rules: {
"simple-import-sort/imports": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", destructuredArrayIgnorePattern: "^_" },
],
},
},
];
Loading

0 comments on commit 3d49167

Please sign in to comment.