From 3e8421d8b7b1c54ff1f21871d20187121a174a0c Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 22 Jul 2022 21:39:49 +0100 Subject: [PATCH] refactor: group asset-related files Fixes #15 --- website/Dockerfile | 11 +++--- website/{ => assets}/.yarnrc | 0 website/assets/esbuild.config.js | 29 ++++++++++++++++ website/assets/js/app.js | 35 ++++++++++---------- website/{ => assets}/package.json | 0 website/{ => assets}/postcss.config.js | 0 website/{ => assets}/tailwind.config.js | 0 website/{ => assets}/yarn.lock | 0 website/docker-compose.override.yaml.example | 4 +-- website/esbuild.config.js | 28 ---------------- website/run | 2 +- 11 files changed, 55 insertions(+), 54 deletions(-) rename website/{ => assets}/.yarnrc (100%) create mode 100644 website/assets/esbuild.config.js rename website/{ => assets}/package.json (100%) rename website/{ => assets}/postcss.config.js (100%) rename website/{ => assets}/tailwind.config.js (100%) rename website/{ => assets}/yarn.lock (100%) delete mode 100644 website/esbuild.config.js diff --git a/website/Dockerfile b/website/Dockerfile index 15cd8a03..5f3a133b 100644 --- a/website/Dockerfile +++ b/website/Dockerfile @@ -4,25 +4,26 @@ ARG NODE_ENV="production" ARG SCULPIN_ENV="prod" ENV NODE_ENV="${NODE_ENV}" \ PATH="${PATH}:/node_modules/.bin" \ - SCULPIN_ENV="${SCULPIN_ENV}" + SCULPIN_ENV="${SCULPIN_ENV}" \ + USER="node" RUN apk add --no-cache bash -WORKDIR /app +WORKDIR /app/assets RUN mkdir -p /node_modules \ && chown node:node -R /app /node_modules USER node -COPY --chown=node:node *yarn* package.json ./ +COPY --chown=node:node assets/*yarn* assets/package.json ./ RUN yarn install && yarn cache clean -COPY --chown=node:node . . +COPY --chown=node:node . .. RUN if [ "${NODE_ENV}" != "development" ]; then \ - ./run yarn:build:css && ./run yarn:build:js; \ + ../run yarn:build:css && ../run yarn:build:js; \ else mkdir -p /app/build; fi CMD ["bash"] diff --git a/website/.yarnrc b/website/assets/.yarnrc similarity index 100% rename from website/.yarnrc rename to website/assets/.yarnrc diff --git a/website/assets/esbuild.config.js b/website/assets/esbuild.config.js new file mode 100644 index 00000000..5afa1bd9 --- /dev/null +++ b/website/assets/esbuild.config.js @@ -0,0 +1,29 @@ +const esbuild = require("esbuild"); + +let minify = false; +let sourcemap = true; +let watch_fs = true; + +if (process.env.NODE_ENV === "production") { + minify = true; + sourcemap = false; + watch_fs = false; +} + +const watch = watch_fs && { + onRebuild(error) { + if (error) console.error("[watch] build failed", error); + else console.log("[watch] build finished"); + }, +}; +console.log(watch); + +esbuild.build({ + entryPoints: ["./js/app.js"], + outfile: "../source/build/app.js", + bundle: true, + minify: minify, + sourcemap: sourcemap, + watch: watch, + plugins: [], +}); diff --git a/website/assets/js/app.js b/website/assets/js/app.js index 511b02d1..ee2ef8ae 100644 --- a/website/assets/js/app.js +++ b/website/assets/js/app.js @@ -1,20 +1,19 @@ -import 'alpinejs' -import 'focus-visible' -import bash from 'highlight.js/lib/languages/bash' -import hljs from 'highlight.js/lib/core' -import ini from 'highlight.js/lib/languages/ini' -import javascript from 'highlight.js/lib/languages/javascript' -import php from 'highlight.js/lib/languages/php' -import yaml from 'highlight.js/lib/languages/yaml' +import "focus-visible"; +import bash from "highlight.js/lib/languages/bash"; +import hljs from "highlight.js/lib/core"; +import ini from "highlight.js/lib/languages/ini"; +import javascript from "highlight.js/lib/languages/javascript"; +import php from "highlight.js/lib/languages/php"; +import yaml from "highlight.js/lib/languages/yaml"; -hljs.registerLanguage('bash', bash); -hljs.registerLanguage('ini', ini); -hljs.registerLanguage('javascript', javascript); -hljs.registerLanguage('php', php); -hljs.registerLanguage('yaml', yaml); +hljs.registerLanguage("bash", bash); +hljs.registerLanguage("ini", ini); +hljs.registerLanguage("javascript", javascript); +hljs.registerLanguage("php", php); +hljs.registerLanguage("yaml", yaml); -document.addEventListener('DOMContentLoaded', event => { - document.querySelectorAll('pre code').forEach(block => { - hljs.highlightBlock(block) - }) -}) +document.addEventListener("DOMContentLoaded", (event) => { + document.querySelectorAll("pre code").forEach((element) => { + hljs.highlightElement(element); + }); +}); diff --git a/website/package.json b/website/assets/package.json similarity index 100% rename from website/package.json rename to website/assets/package.json diff --git a/website/postcss.config.js b/website/assets/postcss.config.js similarity index 100% rename from website/postcss.config.js rename to website/assets/postcss.config.js diff --git a/website/tailwind.config.js b/website/assets/tailwind.config.js similarity index 100% rename from website/tailwind.config.js rename to website/assets/tailwind.config.js diff --git a/website/yarn.lock b/website/assets/yarn.lock similarity index 100% rename from website/yarn.lock rename to website/assets/yarn.lock diff --git a/website/docker-compose.override.yaml.example b/website/docker-compose.override.yaml.example index d2a05700..af5b2919 100644 --- a/website/docker-compose.override.yaml.example +++ b/website/docker-compose.override.yaml.example @@ -13,8 +13,8 @@ x-assets: &default-assets services: css: <<: *default-assets - command: "./run yarn:build:css" + command: "../run yarn:build:css" js: <<: *default-assets - command: "./run yarn:build:js" + command: "../run yarn:build:js" diff --git a/website/esbuild.config.js b/website/esbuild.config.js deleted file mode 100644 index 21bd2078..00000000 --- a/website/esbuild.config.js +++ /dev/null @@ -1,28 +0,0 @@ -const esbuild = require('esbuild') - -let minify = false -let sourcemap = true -let watch_fs = true - -if (process.env.NODE_ENV === 'production') { - minify = true - sourcemap = false - watch_fs = false -} - -const watch = watch_fs && { - onRebuild(error) { - if (error) console.error('[watch] build failed', error) - else console.log('[watch] build finished') - }, -} - -esbuild.build({ - entryPoints: ['./assets/js/app.js'], - outfile: './build/app.js', - bundle: true, - minify: minify, - sourcemap: sourcemap, - watch: watch, - plugins: [], -}) diff --git a/website/run b/website/run index 6bbfa899..6a6eebf6 100755 --- a/website/run +++ b/website/run @@ -87,7 +87,7 @@ function yarn:build:css { fi tailwindcss --postcss \ - -i assets/css/tailwind.pcss \ + -i css/tailwind.pcss \ -o source/build/app.css "${args[@]}" }