From 6f36a7c8b42fccd438f4175c7dd2ebcac44d76e3 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 24 Jul 2024 01:48:59 -0400 Subject: [PATCH] Automatically detect .entry.ts files as Vite entry points --- .../js/{dashboard.ts => dashboard.entry.ts} | 0 .../templates/dashboard/dashboard.dj.html | 2 +- js/{base.ts => base.entry.ts} | 0 package.json | 1 + ....ts => department_certifications.entry.ts} | 0 .../department_certifications.dj.html | 2 +- pnpm-lock.yaml | 122 ++++++++++++++++++ templates/base.dj.html | 2 +- vite.config.js | 26 ++-- 9 files changed, 142 insertions(+), 13 deletions(-) rename dashboard/js/{dashboard.ts => dashboard.entry.ts} (100%) rename js/{base.ts => base.entry.ts} (100%) rename paperwork/js/{department_certifications.ts => department_certifications.entry.ts} (100%) diff --git a/dashboard/js/dashboard.ts b/dashboard/js/dashboard.entry.ts similarity index 100% rename from dashboard/js/dashboard.ts rename to dashboard/js/dashboard.entry.ts diff --git a/dashboard/templates/dashboard/dashboard.dj.html b/dashboard/templates/dashboard/dashboard.dj.html index 9f2f088..4dd3093 100644 --- a/dashboard/templates/dashboard/dashboard.dj.html +++ b/dashboard/templates/dashboard/dashboard.dj.html @@ -3,7 +3,7 @@ {% load django_vite %} {% block vite_extra_assets %} - {% vite_asset 'dashboard/js/dashboard.ts' %} + {% vite_asset 'dashboard/js/dashboard.entry.ts' %} {% endblock %} {% block title %}Claremont MakerSpace Management{% endblock %} diff --git a/js/base.ts b/js/base.entry.ts similarity index 100% rename from js/base.ts rename to js/base.entry.ts diff --git a/package.json b/package.json index 1746534..2f7db87 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "devDependencies": { "@types/bootstrap": "^5.2.10", "@types/tabulator-tables": "^6.2.3", + "globby": "^14.0.2", "prettier": "^3.3.3", "sass": "^1.77.8", "typescript": "^5.5.4", diff --git a/paperwork/js/department_certifications.ts b/paperwork/js/department_certifications.entry.ts similarity index 100% rename from paperwork/js/department_certifications.ts rename to paperwork/js/department_certifications.entry.ts diff --git a/paperwork/templates/paperwork/department_certifications.dj.html b/paperwork/templates/paperwork/department_certifications.dj.html index 289370b..01273f0 100644 --- a/paperwork/templates/paperwork/department_certifications.dj.html +++ b/paperwork/templates/paperwork/department_certifications.dj.html @@ -3,7 +3,7 @@ {% load django_vite %} {% block vite_extra_assets %} - {% vite_asset 'paperwork/js/department_certifications.ts' %} + {% vite_asset 'paperwork/js/department_certifications.entry.ts' %} {% endblock %} {% block content %} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cd0dbf0..dbf5565 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,6 +27,9 @@ importers: '@types/tabulator-tables': specifier: ^6.2.3 version: 6.2.3 + globby: + specifier: ^14.0.2 + version: 14.0.2 prettier: specifier: ^3.3.3 version: 3.3.3 @@ -180,6 +183,18 @@ packages: cpu: [x64] os: [win32] + '@nodelib/fs.scandir@2.1.5': + resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} + engines: {node: '>= 8'} + + '@nodelib/fs.stat@2.0.5': + resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==} + engines: {node: '>= 8'} + + '@nodelib/fs.walk@1.2.8': + resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} + engines: {node: '>= 8'} + '@popperjs/core@2.11.8': resolution: {integrity: sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==} @@ -263,6 +278,10 @@ packages: cpu: [x64] os: [win32] + '@sindresorhus/merge-streams@2.3.0': + resolution: {integrity: sha512-LtoMMhxAlorcGhmFYI+LhPgbPZCkgP6ra1YL604EeF6U98pLlQ3iWIGMdWSC+vWmPBWBNgmDBAhnAobLROJmwg==} + engines: {node: '>=18'} + '@types/bootstrap@5.2.10': resolution: {integrity: sha512-F2X+cd6551tep0MvVZ6nM8v7XgGN/twpdNDjqS1TUM7YFNEtQYWk+dKAnH+T1gr6QgCoGMPl487xw/9hXooa2g==} @@ -301,6 +320,13 @@ packages: engines: {node: '>=12'} hasBin: true + fast-glob@3.3.2: + resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} + engines: {node: '>=8.6.0'} + + fastq@1.17.1: + resolution: {integrity: sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==} + fill-range@7.1.1: resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==} engines: {node: '>=8'} @@ -314,6 +340,14 @@ packages: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} + globby@14.0.2: + resolution: {integrity: sha512-s3Fq41ZVh7vbbe2PN3nrW7yC7U7MFVc5c98/iTl9c2GawNMKx/J648KQRW6WKkuU8GIbbh2IXfIRQjOZnXcTnw==} + engines: {node: '>=18'} + + ignore@5.3.1: + resolution: {integrity: sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==} + engines: {node: '>= 4'} + immutable@4.3.7: resolution: {integrity: sha512-1hqclzwYwjRDFLjcFxOM5AYkkG0rpFPpr1RLPMEuGczoS7YA8gLhy8SWXYRAA/XwfEHpfo3cw5JGioS32fnMRw==} @@ -333,6 +367,14 @@ packages: resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==} engines: {node: '>=0.12.0'} + merge2@1.4.1: + resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} + engines: {node: '>= 8'} + + micromatch@4.0.7: + resolution: {integrity: sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==} + engines: {node: '>=8.6'} + nanoid@3.3.7: resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} @@ -342,6 +384,10 @@ packages: resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} engines: {node: '>=0.10.0'} + path-type@5.0.0: + resolution: {integrity: sha512-5HviZNaZcfqP95rwpv+1HDgUamezbqdSYTyzjTvwtJSnIH+3vnbmWsItli8OFEndS984VT55M3jduxZbX351gg==} + engines: {node: '>=12'} + picocolors@1.0.1: resolution: {integrity: sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==} @@ -358,20 +404,34 @@ packages: engines: {node: '>=14'} hasBin: true + queue-microtask@1.2.3: + resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} + readdirp@3.6.0: resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} engines: {node: '>=8.10.0'} + reusify@1.0.4: + resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} + engines: {iojs: '>=1.0.0', node: '>=0.10.0'} + rollup@4.19.0: resolution: {integrity: sha512-5r7EYSQIowHsK4eTZ0Y81qpZuJz+MUuYeqmmYmRMl1nwhdmbiYqt5jwzf6u7wyOzJgYqtCRMtVRKOtHANBz7rA==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true + run-parallel@1.2.0: + resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} + sass@1.77.8: resolution: {integrity: sha512-4UHg6prsrycW20fqLGPShtEvo/WyHRVRHwOP4DzkUrObWoWI05QBSfzU71TVB7PFaL104TwNaHpjlWXAZbQiNQ==} engines: {node: '>=14.0.0'} hasBin: true + slash@5.1.0: + resolution: {integrity: sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==} + engines: {node: '>=14.16'} + source-map-js@1.2.0: resolution: {integrity: sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==} engines: {node: '>=0.10.0'} @@ -388,6 +448,10 @@ packages: engines: {node: '>=14.17'} hasBin: true + unicorn-magic@0.1.0: + resolution: {integrity: sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==} + engines: {node: '>=18'} + vite@5.3.4: resolution: {integrity: sha512-Cw+7zL3ZG9/NZBB8C+8QbQZmR54GwqIz+WMI4b3JgdYJvX+ny9AjJXqkGQlDXSXRP9rP0B4tbciRMOVEKulVOA==} engines: {node: ^18.0.0 || >=20.0.0} @@ -487,6 +551,18 @@ snapshots: '@esbuild/win32-x64@0.21.5': optional: true + '@nodelib/fs.scandir@2.1.5': + dependencies: + '@nodelib/fs.stat': 2.0.5 + run-parallel: 1.2.0 + + '@nodelib/fs.stat@2.0.5': {} + + '@nodelib/fs.walk@1.2.8': + dependencies: + '@nodelib/fs.scandir': 2.1.5 + fastq: 1.17.1 + '@popperjs/core@2.11.8': {} '@rollup/rollup-android-arm-eabi@4.19.0': @@ -537,6 +613,8 @@ snapshots: '@rollup/rollup-win32-x64-msvc@4.19.0': optional: true + '@sindresorhus/merge-streams@2.3.0': {} + '@types/bootstrap@5.2.10': dependencies: '@popperjs/core': 2.11.8 @@ -600,6 +678,18 @@ snapshots: '@esbuild/win32-ia32': 0.21.5 '@esbuild/win32-x64': 0.21.5 + fast-glob@3.3.2: + dependencies: + '@nodelib/fs.stat': 2.0.5 + '@nodelib/fs.walk': 1.2.8 + glob-parent: 5.1.2 + merge2: 1.4.1 + micromatch: 4.0.7 + + fastq@1.17.1: + dependencies: + reusify: 1.0.4 + fill-range@7.1.1: dependencies: to-regex-range: 5.0.1 @@ -611,6 +701,17 @@ snapshots: dependencies: is-glob: 4.0.3 + globby@14.0.2: + dependencies: + '@sindresorhus/merge-streams': 2.3.0 + fast-glob: 3.3.2 + ignore: 5.3.1 + path-type: 5.0.0 + slash: 5.1.0 + unicorn-magic: 0.1.0 + + ignore@5.3.1: {} + immutable@4.3.7: {} is-binary-path@2.1.0: @@ -625,10 +726,19 @@ snapshots: is-number@7.0.0: {} + merge2@1.4.1: {} + + micromatch@4.0.7: + dependencies: + braces: 3.0.3 + picomatch: 2.3.1 + nanoid@3.3.7: {} normalize-path@3.0.0: {} + path-type@5.0.0: {} + picocolors@1.0.1: {} picomatch@2.3.1: {} @@ -641,10 +751,14 @@ snapshots: prettier@3.3.3: {} + queue-microtask@1.2.3: {} + readdirp@3.6.0: dependencies: picomatch: 2.3.1 + reusify@1.0.4: {} + rollup@4.19.0: dependencies: '@types/estree': 1.0.5 @@ -667,12 +781,18 @@ snapshots: '@rollup/rollup-win32-x64-msvc': 4.19.0 fsevents: 2.3.3 + run-parallel@1.2.0: + dependencies: + queue-microtask: 1.2.3 + sass@1.77.8: dependencies: chokidar: 3.6.0 immutable: 4.3.7 source-map-js: 1.2.0 + slash@5.1.0: {} + source-map-js@1.2.0: {} tabulator-tables@6.2.5: {} @@ -683,6 +803,8 @@ snapshots: typescript@5.5.4: {} + unicorn-magic@0.1.0: {} + vite@5.3.4(sass@1.77.8): dependencies: esbuild: 0.21.5 diff --git a/templates/base.dj.html b/templates/base.dj.html index 3a5a479..4fc83cb 100644 --- a/templates/base.dj.html +++ b/templates/base.dj.html @@ -10,7 +10,7 @@ {% block vite_assets %} - {% vite_asset 'js/base.ts' %} + {% vite_asset 'js/base.entry.ts' %} {% block vite_extra_assets %}{% endblock %} {% endblock %} diff --git a/vite.config.js b/vite.config.js index 2dd0e91..1f4511d 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,5 +1,18 @@ -import { resolve, join } from "node:path"; +import path from "node:path"; import { defineConfig } from "vite"; +import { globbySync } from "globby"; + +const entry_points = globbySync("*/js/*.entry.ts", { gitignore: true }); + +const inputs = { + base: "./js/base.entry.ts", +}; + +for (const entry of entry_points) { + inputs[ + path.dirname(path.dirname(entry)) + "/" + path.basename(entry, ".entry.ts") + ] = entry; +} export default defineConfig({ base: "/static/", @@ -9,14 +22,7 @@ export default defineConfig({ }, build: { manifest: "manifest.json", - outDir: resolve("./vite-dist"), - rollupOptions: { - input: { - base: "./js/base.ts", - "paperwork/department_certifications": - "./paperwork/js/department_certifications.ts", - "dashboard/dashboard": "./dashboard/js/dashboard.ts", - }, - }, + outDir: path.resolve("./vite-dist"), + rollupOptions: { input: inputs }, }, });