diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6cbaed3..67c9a0c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,6 +25,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + submodules: false + - name: Checkout excalidraw + run: git submodule update --init excalidraw - name: Install Nix uses: DeterminateSystems/nix-installer-action@main - name: Setup Nix Cache diff --git a/.gitmodules b/.gitmodules index d1e2071..a8dd3b8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "MAS/Projeto (site)"] path = MAS/Projeto (site) url = https://github.com/JCapucho/mas-projeto-final.git +[submodule "excalidraw"] + path = excalidraw + url = https://github.com/excalidraw/excalidraw.git diff --git a/bun.lockb b/bun.lockb index e7c46fb..32a2327 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/excalidraw b/excalidraw new file mode 160000 index 0000000..b7d7ccc --- /dev/null +++ b/excalidraw @@ -0,0 +1 @@ +Subproject commit b7d7ccc929696cc17b4cc34452e4afd846d59f4f diff --git a/excalidraw.patch b/excalidraw.patch new file mode 100644 index 0000000..c4bbfd4 --- /dev/null +++ b/excalidraw.patch @@ -0,0 +1,215 @@ +diff --git a/src/packages/utils/index.js b/src/packages/utils/index.js +index 4dc03e93..c739646d 100644 +--- a/src/packages/utils/index.js ++++ b/src/packages/utils/index.js +@@ -1 +1,6 @@ +-export { exportToBlob, exportToSvg, exportToCanvas } from "../utils.ts"; ++export { ++ loadFromBlob, ++ exportToBlob, ++ exportToSvg, ++ exportToCanvas, ++} from "../utils.ts"; +diff --git a/src/packages/utils/package.json b/src/packages/utils/package.json +index 7375e8b5..1dd8f3ad 100644 +--- a/src/packages/utils/package.json ++++ b/src/packages/utils/package.json +@@ -41,6 +41,7 @@ + "@babel/plugin-transform-typescript": "7.18.8", + "@babel/preset-env": "7.18.9", + "@babel/preset-typescript": "7.18.6", ++ "autoprefixer": "10.4.7", + "babel-loader": "8.2.5", + "babel-plugin-transform-class-properties": "6.24.1", + "cross-env": "7.0.3", +diff --git a/src/packages/utils/webpack.prod.config.js b/src/packages/utils/webpack.prod.config.js +index 7238ad02..18f38dfd 100644 +--- a/src/packages/utils/webpack.prod.config.js ++++ b/src/packages/utils/webpack.prod.config.js +@@ -1,4 +1,5 @@ + const webpack = require("webpack"); ++const autoprefixer = require("autoprefixer"); + const path = require("path"); + const BundleAnalyzerPlugin = + require("webpack-bundle-analyzer").BundleAnalyzerPlugin; +@@ -23,11 +24,38 @@ module.exports = { + { + test: /\.(sa|sc|c)ss$/, + exclude: /node_modules/, +- use: ["style-loader", { loader: "css-loader" }, "sass-loader"], ++ use: [ ++ "style-loader", ++ { ++ loader: "css-loader", ++ }, ++ { ++ loader: "postcss-loader", ++ options: { ++ postcssOptions: { ++ plugins: [autoprefixer()], ++ }, ++ }, ++ }, ++ "sass-loader", ++ ], + }, ++ // So that type module works with webpack ++ // https://github.com/webpack/webpack/issues/11467#issuecomment-691873586 + { +- test: /\.(ts|tsx|js)$/, ++ test: /\.m?js/, ++ resolve: { ++ fullySpecified: false, ++ }, ++ }, ++ { ++ test: /\.(ts|tsx|js|jsx|mjs)$/, ++ exclude: ++ /node_modules[\\/](?!(browser-fs-access|canvas-roundrect-polyfill))/, + use: [ ++ { ++ loader: "import-meta-loader", ++ }, + { + loader: "ts-loader", + options: { +@@ -37,18 +65,24 @@ module.exports = { + }, + { + loader: "babel-loader", +- + options: { + presets: [ + "@babel/preset-env", + ["@babel/preset-react", { runtime: "automatic" }], + "@babel/preset-typescript", + ], +- plugins: [["@babel/plugin-transform-runtime"]], ++ plugins: [ ++ "transform-class-properties", ++ "@babel/plugin-transform-runtime", ++ ], + }, + }, + ], + }, ++ { ++ test: /\.(woff|woff2|eot|ttf|otf)$/, ++ type: "asset/resource", ++ }, + ], + }, + plugins: [ +diff --git a/src/packages/utils/yarn.lock b/src/packages/utils/yarn.lock +index c10a5aed..c895e9ea 100644 +--- a/src/packages/utils/yarn.lock ++++ b/src/packages/utils/yarn.lock +@@ -1231,6 +1231,18 @@ ansi-styles@^4.1.0: + dependencies: + color-convert "^2.0.1" + ++autoprefixer@10.4.7: ++ version "10.4.7" ++ resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.4.7.tgz#1db8d195f41a52ca5069b7593be167618edbbedf" ++ integrity sha512-ypHju4Y2Oav95SipEcCcI5J7CGPuvz8oat7sUtYj3ClK44bldfvtvcxK6IEK++7rqB7YchDGzweZIBG+SD0ZAA== ++ dependencies: ++ browserslist "^4.20.3" ++ caniuse-lite "^1.0.30001335" ++ fraction.js "^4.2.0" ++ normalize-range "^0.1.2" ++ picocolors "^1.0.0" ++ postcss-value-parser "^4.2.0" ++ + babel-code-frame@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" +@@ -1393,6 +1405,16 @@ browserslist@^4.14.5, browserslist@^4.20.2, browserslist@^4.21.2: + node-releases "^2.0.6" + update-browserslist-db "^1.0.4" + ++browserslist@^4.20.3: ++ version "4.22.2" ++ resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.22.2.tgz#704c4943072bd81ea18997f3bd2180e89c77874b" ++ integrity sha512-0UgcrvQmBDvZHFGdYUehrCNIazki7/lUP3kkoi/r3YB2amZbFM9J43ZRkJTXBUZK4gmx56+Sqk9+Vs9mwZx9+A== ++ dependencies: ++ caniuse-lite "^1.0.30001565" ++ electron-to-chromium "^1.4.601" ++ node-releases "^2.0.14" ++ update-browserslist-db "^1.0.13" ++ + buffer-from@^1.0.0: + version "1.1.2" + resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" +@@ -1406,6 +1428,11 @@ call-bind@^1.0.0: + function-bind "^1.1.1" + get-intrinsic "^1.0.2" + ++caniuse-lite@^1.0.30001335, caniuse-lite@^1.0.30001565: ++ version "1.0.30001568" ++ resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001568.tgz#53fa9297273c9a977a560663f48cbea1767518b7" ++ integrity sha512-vSUkH84HontZJ88MiNrOau1EBrCqEQYgkC5gIySiDlpsm8sGVrhU7Kx4V6h0tnqaHzIHZv08HlJIwPbL4XL9+A== ++ + caniuse-lite@^1.0.30001366: + version "1.0.30001367" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001367.tgz#2b97fe472e8fa29c78c5970615d7cd2ee414108a" +@@ -1585,6 +1612,11 @@ electron-to-chromium@^1.4.188: + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.195.tgz#139b2d95a42a3f17df217589723a1deac71d1473" + integrity sha512-vefjEh0sk871xNmR5whJf9TEngX+KTKS3hOHpjoMpauKkwlGwtMz1H8IaIjAT/GNnX0TbGwAdmVoXCAzXf+PPg== + ++electron-to-chromium@^1.4.601: ++ version "1.4.610" ++ resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.610.tgz#e17b22203f4aa2e1ed77759c720546d95a51186f" ++ integrity sha512-mqi2oL1mfeHYtOdCxbPQYV/PL7YrQlxbvFEZ0Ee8GbDdShimqt2/S6z2RWqysuvlwdOrQdqvE0KZrBTipAeJzg== ++ + emojis-list@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-3.0.0.tgz#5570662046ad29e2e916e71aae260abdff4f6a78" +@@ -1700,6 +1732,11 @@ find-up@^4.0.0: + locate-path "^5.0.0" + path-exists "^4.0.0" + ++fraction.js@^4.2.0: ++ version "4.3.7" ++ resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.3.7.tgz#06ca0085157e42fda7f9e726e79fefc4068840f7" ++ integrity sha512-ZsDfxO51wGAXREY55a7la9LScWpwv9RxIrYABrlvOFBlH/ShPnrtsXeuUIfXKKOVicNxQ+o8JTbJvjS4M89yew== ++ + function-bind@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" +@@ -1990,11 +2027,21 @@ neo-async@^2.6.2: + resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" + integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== + ++node-releases@^2.0.14: ++ version "2.0.14" ++ resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.14.tgz#2ffb053bceb8b2be8495ece1ab6ce600c4461b0b" ++ integrity sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw== ++ + node-releases@^2.0.6: + version "2.0.6" + resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.6.tgz#8a7088c63a55e493845683ebf3c828d8c51c5503" + integrity sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg== + ++normalize-range@^0.1.2: ++ version "0.1.2" ++ resolved "https://registry.yarnpkg.com/normalize-range/-/normalize-range-0.1.2.tgz#2d10c06bdfd312ea9777695a4d28439456b75942" ++ integrity sha512-bdok/XvKII3nUpklnV6P2hxtMNrCboOjAcyBuQnWEhO665FwrSNRxU+AqpsyvO6LgGYPspN+lu5CLtw4jPRKNA== ++ + object-keys@^1.0.12, object-keys@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e" +@@ -2448,6 +2495,14 @@ uniq@^1.0.1: + resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff" + integrity sha1-sxxa6CVIRKOoKBVBzisEuGWnNP8= + ++update-browserslist-db@^1.0.13: ++ version "1.0.13" ++ resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz#3c5e4f5c083661bd38ef64b6328c26ed6c8248c4" ++ integrity sha512-xebP81SNcPuNpPP3uzeW1NYXxI3rxyJzF3pD6sH4jE7o/IX+WtSpwnVU+qIsDPyk0d3hmFQ7mjqc6AtV604hbg== ++ dependencies: ++ escalade "^3.1.1" ++ picocolors "^1.0.0" ++ + update-browserslist-db@^1.0.4: + version "1.0.5" + resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.5.tgz#be06a5eedd62f107b7c19eb5bcefb194411abf38" diff --git a/flake.nix b/flake.nix index 2185a1b..cbce3ac 100644 --- a/flake.nix +++ b/flake.nix @@ -58,6 +58,7 @@ base-pkgs = with pkgs; [ bun + yarn nodejs_latest pandoc pandoc-norg-rs.packages.${system}.default diff --git a/package.json b/package.json index 6ebe23f..8f1c2de 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,14 @@ "scripts": { "dev": "parcel index.eta", "build": "parcel build index.eta", - "index": "pagefind --site dist" + "index": "pagefind --site dist", + "postinstall": "bun ./scripts/build-excalidraw.js" }, "staticFiles": { "staticPath": "public" }, "devDependencies": { - "@excalidraw/excalidraw": "^0.17.2", + "@excalidraw/excalidraw": "file:./excalidraw/src/packages/utils", "@parcel/config-default": "^2.10.0", "@parcel/core": "^2.10.0", "@parcel/plugin": "^2.10.0", @@ -27,6 +28,7 @@ "posthtml": "^0.16.6", "posthtml-parser": "^0.11.0", "posthtml-toc": "posthtml/posthtml-toc#0c19ee4de97c5985fda86550d0590e29074191d4", + "rewire": "^7.0.0", "tailwindcss": "^3.3.3" }, "dependencies": { diff --git a/plugins/excalidrawSetupDom.js b/plugins/excalidrawSetupDom.js index 7e70f60..ccbedad 100644 --- a/plugins/excalidrawSetupDom.js +++ b/plugins/excalidrawSetupDom.js @@ -4,5 +4,8 @@ import "global-jsdom/register"; import excalidrawPkg from "@excalidraw/excalidraw/package.json" assert { type: "json" }; const excalidrawAssets = `https://unpkg.com/@excalidraw/excalidraw@${excalidrawPkg.version}`; +const localDistUrl = import.meta.resolve("@excalidraw/excalidraw/dist"); + global.Path2D = Path2D; global.window.EXCALIDRAW_ASSET_PATH = excalidrawAssets; +global.window.EXCALIDRAW_WEBPACK_ASSET_PATH = localDistUrl + "/"; diff --git a/scripts/build-excalidraw.js b/scripts/build-excalidraw.js new file mode 100644 index 0000000..d974682 --- /dev/null +++ b/scripts/build-excalidraw.js @@ -0,0 +1,68 @@ +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import { spawnSync } from "node:child_process"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +export const project_root = path.join(__dirname, ".."); + +const excalidrawDir = path.join(project_root, "excalidraw"); +const excalidrawPkgDir = path.join(excalidrawDir, "src/packages/utils"); + +const gitRevCheck = spawnSync( + "git", + [ + "apply", + "--reverse", + "--check", + path.join(project_root, "excalidraw.patch"), + ], + { + cwd: excalidrawDir, + }, +); + +if (gitRevCheck.status != 0) { + spawnSync("git", ["apply", path.join(project_root, "excalidraw.patch")], { + cwd: excalidrawDir, + stdio: "inherit", + }); +} else { + console.error("Excalidraw patch already applied"); +} + +let res = spawnSync("yarn", ["--frozen-lockfile"], { + stdio: "inherit", + cwd: excalidrawDir, +}); + +if (res.error) throw res.error; + +res = spawnSync("yarn", ["--frozen-lockfile"], { + stdio: "inherit", + cwd: excalidrawPkgDir, +}); + +if (res.error) throw res.error; + +res = spawnSync("rm", ["-rf", "dist"], { + stdio: "inherit", + cwd: excalidrawPkgDir, +}); + +if (res.error) throw res.error; + +res = spawnSync("yarn", ["webpack", "--config", "webpack.prod.config.js"], { + stdio: "inherit", + cwd: excalidrawPkgDir, + env: { + NODE_ENV: "production", + }, +}); + +if (res.error) throw res.error; + +res = spawnSync("bun", ["install", "--ignore-scripts", "--frozen-lockfile"], { + stdio: "inherit", +}); + +if (res.error) throw res.error;