diff --git a/package.json b/package.json index efa01af..ed2c1b5 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "build": "NODE_ENV=prod run-s clear build:web build:prepare build:prod", "build:prepare": "node tasks/prepare.prod.mjs build", "build:web": "vite build", - "build:dev": "tsup src/scripts/background.js src/scripts/contentscript.js --target=node20 --format iife --out-dir extension/dev/dist --no-splitting --onSuccess 'node --no-warnings=ExperimentalWarning tasks/mvsw.dev.mjs'", - "build:prod": "tsup src/scripts/background.js src/scripts/contentscript.js --target=node20 --minify --format iife --out-dir extension/prod/dist --no-splitting --onSuccess 'node --no-warnings=ExperimentalWarning tasks/mvsw.prod.mjs'", + "build:dev": "tsup --onSuccess 'node --no-warnings=ExperimentalWarning tasks/mvsw.dev.mjs'", + "build:prod": "tsup --onSuccess 'node --no-warnings=ExperimentalWarning tasks/mvsw.prod.mjs'", "clear": "rimraf extension/prod" }, "standard": { diff --git a/src/pages/iframe.html b/src/pages/iframe.html index 230e258..fede243 100644 --- a/src/pages/iframe.html +++ b/src/pages/iframe.html @@ -4,6 +4,6 @@ - UFABC Next Storage + Next Storage diff --git a/src/scripts/contentScriptPortal.js b/src/scripts/contentScriptPortal.js index 853a439..e4337fe 100644 --- a/src/scripts/contentScriptPortal.js +++ b/src/scripts/contentScriptPortal.js @@ -5,17 +5,17 @@ import Utils from "../utils/extensionUtils"; import { NextAPI } from "../services/NextAPI"; import Axios from "axios"; import Toastify from "toastify-js"; -import "toastify-js/src/toastify.css"; -const loading = require("../assets/loading.svg"); -const errorSVG = require("../assets/error.svg"); -const logoWhite = require("../assets/logo-white.svg"); + +const getURL = chrome.runtime.getURL ?? ((path) => path); const nextApi = NextAPI(); const toast = new Toastify({ text: `
- +

Atualizando suas informações...

\n\n NÃO SAIA DESSA PÁGINA,

apenas aguarde, no máx. 5 min 🙏

@@ -26,51 +26,38 @@ const toast = new Toastify({ position: "right", className: "toast-loading", escapeMarkup: false, - avatar: loading, + avatar: getURL("/assets/loading.svg"), style: { background: "linear-gradient(to right, #2E7EED, rgba(46, 126, 237, 0.5));", }, }); -if (isIndexPortalAluno()) { +const basePortalAlunoURL = new URL(document.location.href); +const isPortalAluno = basePortalAlunoURL.pathname === "/dados_pessoais"; +const isFichasIndividuais = + basePortalAlunoURL.pathname === "/fichas_individuais"; +const isStudentFicha = basePortalAlunoURL.pathname === "/ficha_individual"; + +if (isPortalAluno) { const anchor = document.createElement("div"); anchor.setAttribute("id", "app"); document.body.append(anchor); - Utils.injectScript("studentPortal.js"); Utils.injectStyle("styles/portal.css"); + toastr.info( "Clique em Ficha Individual para atualizar suas informações!" ); -} else if (isFichasIndividuaisPath()) { +} else if (isFichasIndividuais) { Utils.injectStyle("styles/portal.css"); toast.showToast(); iterateTabelaCursosAndSaveToLocalStorage(); -} else if (isFichaIndividualPath()) { +} else if (isStudentFicha) { Utils.injectStyle("styles/portal.css"); } -function isIndexPortalAluno() { - return ( - document.location.href.indexOf("aluno.ufabc.edu.br/dados_pessoais") !== -1 - ); -} - -function isFichasIndividuaisPath() { - return ( - document.location.href.indexOf("aluno.ufabc.edu.br/fichas_individuais") !== - -1 - ); -} - -function isFichaIndividualPath() { - return ( - document.location.href.indexOf("aluno.ufabc.edu.br/ficha_individual") !== -1 - ); -} - function iterateTabelaCursosAndSaveToLocalStorage() { var tabelaCursos = $("tbody").children().slice(1); let count = 0; @@ -182,7 +169,9 @@ async function getFichaAluno(fichaAlunoUrl, nomeDoCurso, anoDaGrade) { Toastify({ text: `
- + Não foi possível salvar seus dados, recarregue a página e aguarde.
`, duration: -1, @@ -190,6 +179,7 @@ async function getFichaAluno(fichaAlunoUrl, nomeDoCurso, anoDaGrade) { gravity: "top", position: "right", className: "toast-error-container", + escapeMarkup: false, style: { background: "#E74C3C;", }, diff --git a/src/services/NextAPI.js b/src/services/NextAPI.js index 8647b06..c9fafa9 100644 --- a/src/services/NextAPI.js +++ b/src/services/NextAPI.js @@ -5,7 +5,7 @@ function resolveEndpoint(env) { { development: "http://localhost:8011/v1", staging: "https://ufabc-matricula-test.cdd.naoseiprogramar.com.br/v1", - production: "https://api.ufabcnext.com/v1", + prod: "https://api.ufabcnext.com/v1", }[env] || "http://localhost:8011/v1" ); } diff --git a/src/styles/main.css b/src/styles/main.css index f11eaea..1c8991a 100644 --- a/src/styles/main.css +++ b/src/styles/main.css @@ -1,6 +1,6 @@ /* Keep in mind that when you inject main.css you inject all this files to the website */ -@import "../../node_modules/toastr/build/toastr.min.css"; -/*@import "../../node_modules/element-ui/lib/theme-chalk/index.css";*/ +@import "./toastr.css"; +@import "../../node_modules/element-ui/lib/theme-chalk/index.css"; @import "../../node_modules/vuetify/dist/vuetify.min.css"; @import url("https://fonts.googleapis.com/css?family=Ubuntu"); diff --git a/src/styles/portal.css b/src/styles/portal.css index da426f2..be004af 100644 --- a/src/styles/portal.css +++ b/src/styles/portal.css @@ -1,8 +1,7 @@ -@import "../../node_modules/toastr/build/toastr.min.css"; - -@import url('https://fonts.googleapis.com/css?family=Ubuntu'); -@import url('https://fonts.googleapis.com/css?family=Lato'); - +@import url("https://fonts.googleapis.com/css?family=Ubuntu"); +@import url("https://fonts.googleapis.com/css?family=Lato"); +@import url("./toastr.css"); +@import url("./toastify.css"); .toast-loading { display: flex; @@ -58,7 +57,7 @@ font-stretch: normal; line-height: 1.38; letter-spacing: normal; - color: rgba(0, 0, 0, 0.75); + color: rgba(0, 0, 0, 0.75); } #conteudo #page > p:nth-child(3) { diff --git a/src/styles/toastify.css b/src/styles/toastify.css new file mode 100644 index 0000000..fb50a17 --- /dev/null +++ b/src/styles/toastify.css @@ -0,0 +1,87 @@ +/*! + * Toastify js 1.12.0 + * https://github.com/apvarun/toastify-js + * @license MIT licensed + * + * Copyright (C) 2018 Varun A P + */ + +.toastify { + padding: 12px 20px; + color: #ffffff; + display: inline-block; + box-shadow: 0 3px 6px -1px rgba(0, 0, 0, 0.12), + 0 10px 36px -4px rgba(77, 96, 232, 0.3); + background: -webkit-linear-gradient(315deg, #73a5ff, #5477f5); + background: linear-gradient(135deg, #73a5ff, #5477f5); + position: fixed; + opacity: 0; + transition: all 0.4s cubic-bezier(0.215, 0.61, 0.355, 1); + border-radius: 2px; + cursor: pointer; + text-decoration: none; + max-width: calc(50% - 20px); + z-index: 2147483647; +} + +.toastify.on { + opacity: 1; +} + +.toast-close { + background: transparent; + border: 0; + color: white; + cursor: pointer; + font-family: inherit; + font-size: 1em; + opacity: 0.4; + padding: 0 5px; +} + +.toastify-right { + right: 15px; +} + +.toastify-left { + left: 15px; +} + +.toastify-top { + top: -150px; +} + +.toastify-bottom { + bottom: -150px; +} + +.toastify-rounded { + border-radius: 25px; +} + +.toastify-avatar { + width: 1.5em; + height: 1.5em; + margin: -7px 5px; + border-radius: 2px; +} + +.toastify-center { + margin-left: auto; + margin-right: auto; + left: 0; + right: 0; + max-width: fit-content; + max-width: -moz-fit-content; +} + +@media only screen and (max-width: 360px) { + .toastify-right, + .toastify-left { + margin-left: auto; + margin-right: auto; + left: 0; + right: 0; + max-width: fit-content; + } +} diff --git a/src/styles/toastr.css b/src/styles/toastr.css new file mode 100644 index 0000000..aebf0f5 --- /dev/null +++ b/src/styles/toastr.css @@ -0,0 +1,228 @@ +.toast-title { + font-weight: bold; +} +.toast-message { + -ms-word-wrap: break-word; + word-wrap: break-word; +} +.toast-message a, +.toast-message label { + color: #ffffff; +} +.toast-message a:hover { + color: #cccccc; + text-decoration: none; +} +.toast-close-button { + position: relative; + right: -0.3em; + top: -0.3em; + float: right; + font-size: 20px; + font-weight: bold; + color: #ffffff; + -webkit-text-shadow: 0 1px 0 #ffffff; + text-shadow: 0 1px 0 #ffffff; + opacity: 0.8; + -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=80); + filter: alpha(opacity=80); + line-height: 1; +} +.toast-close-button:hover, +.toast-close-button:focus { + color: #000000; + text-decoration: none; + cursor: pointer; + opacity: 0.4; + -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=40); + filter: alpha(opacity=40); +} +.rtl .toast-close-button { + left: -0.3em; + float: left; + right: 0.3em; +} +/*Additional properties for button version + iOS requires the button element instead of an anchor tag. + If you want the anchor version, it requires `href="#"`.*/ +button.toast-close-button { + padding: 0; + cursor: pointer; + background: transparent; + border: 0; + -webkit-appearance: none; +} +.toast-top-center { + top: 0; + right: 0; + width: 100%; +} +.toast-bottom-center { + bottom: 0; + right: 0; + width: 100%; +} +.toast-top-full-width { + top: 0; + right: 0; + width: 100%; +} +.toast-bottom-full-width { + bottom: 0; + right: 0; + width: 100%; +} +.toast-top-left { + top: 12px; + left: 12px; +} +.toast-top-right { + top: 12px; + right: 12px; +} +.toast-bottom-right { + right: 12px; + bottom: 12px; +} +.toast-bottom-left { + bottom: 12px; + left: 12px; +} +#toast-container { + position: fixed; + z-index: 999999; + pointer-events: none; + /*overrides*/ +} +#toast-container * { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} +#toast-container > div { + position: relative; + pointer-events: auto; + overflow: hidden; + margin: 0 0 6px; + padding: 15px 15px 15px 50px; + width: 300px; + -moz-border-radius: 3px 3px 3px 3px; + -webkit-border-radius: 3px 3px 3px 3px; + border-radius: 3px 3px 3px 3px; + background-position: 15px center; + background-repeat: no-repeat; + -moz-box-shadow: 0 0 12px #999999; + -webkit-box-shadow: 0 0 12px #999999; + box-shadow: 0 0 12px #999999; + color: #ffffff; + opacity: 0.8; + -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=80); + filter: alpha(opacity=80); +} +#toast-container > div.rtl { + direction: rtl; + padding: 15px 50px 15px 15px; + background-position: right 15px center; +} +#toast-container > div:hover { + -moz-box-shadow: 0 0 12px #000000; + -webkit-box-shadow: 0 0 12px #000000; + box-shadow: 0 0 12px #000000; + opacity: 1; + -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100); + filter: alpha(opacity=100); + cursor: pointer; +} +#toast-container > .toast-info { + background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGwSURBVEhLtZa9SgNBEMc9sUxxRcoUKSzSWIhXpFMhhYWFhaBg4yPYiWCXZxBLERsLRS3EQkEfwCKdjWJAwSKCgoKCcudv4O5YLrt7EzgXhiU3/4+b2ckmwVjJSpKkQ6wAi4gwhT+z3wRBcEz0yjSseUTrcRyfsHsXmD0AmbHOC9Ii8VImnuXBPglHpQ5wwSVM7sNnTG7Za4JwDdCjxyAiH3nyA2mtaTJufiDZ5dCaqlItILh1NHatfN5skvjx9Z38m69CgzuXmZgVrPIGE763Jx9qKsRozWYw6xOHdER+nn2KkO+Bb+UV5CBN6WC6QtBgbRVozrahAbmm6HtUsgtPC19tFdxXZYBOfkbmFJ1VaHA1VAHjd0pp70oTZzvR+EVrx2Ygfdsq6eu55BHYR8hlcki+n+kERUFG8BrA0BwjeAv2M8WLQBtcy+SD6fNsmnB3AlBLrgTtVW1c2QN4bVWLATaIS60J2Du5y1TiJgjSBvFVZgTmwCU+dAZFoPxGEEs8nyHC9Bwe2GvEJv2WXZb0vjdyFT4Cxk3e/kIqlOGoVLwwPevpYHT+00T+hWwXDf4AJAOUqWcDhbwAAAAASUVORK5CYII=") !important; +} +#toast-container > .toast-error { + background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHOSURBVEhLrZa/SgNBEMZzh0WKCClSCKaIYOED+AAKeQQLG8HWztLCImBrYadgIdY+gIKNYkBFSwu7CAoqCgkkoGBI/E28PdbLZmeDLgzZzcx83/zZ2SSXC1j9fr+I1Hq93g2yxH4iwM1vkoBWAdxCmpzTxfkN2RcyZNaHFIkSo10+8kgxkXIURV5HGxTmFuc75B2RfQkpxHG8aAgaAFa0tAHqYFfQ7Iwe2yhODk8+J4C7yAoRTWI3w/4klGRgR4lO7Rpn9+gvMyWp+uxFh8+H+ARlgN1nJuJuQAYvNkEnwGFck18Er4q3egEc/oO+mhLdKgRyhdNFiacC0rlOCbhNVz4H9FnAYgDBvU3QIioZlJFLJtsoHYRDfiZoUyIxqCtRpVlANq0EU4dApjrtgezPFad5S19Wgjkc0hNVnuF4HjVA6C7QrSIbylB+oZe3aHgBsqlNqKYH48jXyJKMuAbiyVJ8KzaB3eRc0pg9VwQ4niFryI68qiOi3AbjwdsfnAtk0bCjTLJKr6mrD9g8iq/S/B81hguOMlQTnVyG40wAcjnmgsCNESDrjme7wfftP4P7SP4N3CJZdvzoNyGq2c/HWOXJGsvVg+RA/k2MC/wN6I2YA2Pt8GkAAAAASUVORK5CYII=") !important; +} +#toast-container > .toast-success { + background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADsSURBVEhLY2AYBfQMgf///3P8+/evAIgvA/FsIF+BavYDDWMBGroaSMMBiE8VC7AZDrIFaMFnii3AZTjUgsUUWUDA8OdAH6iQbQEhw4HyGsPEcKBXBIC4ARhex4G4BsjmweU1soIFaGg/WtoFZRIZdEvIMhxkCCjXIVsATV6gFGACs4Rsw0EGgIIH3QJYJgHSARQZDrWAB+jawzgs+Q2UO49D7jnRSRGoEFRILcdmEMWGI0cm0JJ2QpYA1RDvcmzJEWhABhD/pqrL0S0CWuABKgnRki9lLseS7g2AlqwHWQSKH4oKLrILpRGhEQCw2LiRUIa4lwAAAABJRU5ErkJggg==") !important; +} +#toast-container > .toast-warning { + background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGYSURBVEhL5ZSvTsNQFMbXZGICMYGYmJhAQIJAICYQPAACiSDB8AiICQQJT4CqQEwgJvYASAQCiZiYmJhAIBATCARJy+9rTsldd8sKu1M0+dLb057v6/lbq/2rK0mS/TRNj9cWNAKPYIJII7gIxCcQ51cvqID+GIEX8ASG4B1bK5gIZFeQfoJdEXOfgX4QAQg7kH2A65yQ87lyxb27sggkAzAuFhbbg1K2kgCkB1bVwyIR9m2L7PRPIhDUIXgGtyKw575yz3lTNs6X4JXnjV+LKM/m3MydnTbtOKIjtz6VhCBq4vSm3ncdrD2lk0VgUXSVKjVDJXJzijW1RQdsU7F77He8u68koNZTz8Oz5yGa6J3H3lZ0xYgXBK2QymlWWA+RWnYhskLBv2vmE+hBMCtbA7KX5drWyRT/2JsqZ2IvfB9Y4bWDNMFbJRFmC9E74SoS0CqulwjkC0+5bpcV1CZ8NMej4pjy0U+doDQsGyo1hzVJttIjhQ7GnBtRFN1UarUlH8F3xict+HY07rEzoUGPlWcjRFRr4/gChZgc3ZL2d8oAAAAASUVORK5CYII=") !important; +} +#toast-container.toast-top-center > div, +#toast-container.toast-bottom-center > div { + width: 300px; + margin-left: auto; + margin-right: auto; +} +#toast-container.toast-top-full-width > div, +#toast-container.toast-bottom-full-width > div { + width: 96%; + margin-left: auto; + margin-right: auto; +} +.toast { + background-color: #030303; +} +.toast-success { + background-color: #51a351; +} +.toast-error { + background-color: #bd362f; +} +.toast-info { + background-color: #2f96b4; +} +.toast-warning { + background-color: #f89406; +} +.toast-progress { + position: absolute; + left: 0; + bottom: 0; + height: 4px; + background-color: #000000; + opacity: 0.4; + -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=40); + filter: alpha(opacity=40); +} +/*Responsive Design*/ +@media all and (max-width: 240px) { + #toast-container > div { + padding: 8px 8px 8px 50px; + width: 11em; + } + #toast-container > div.rtl { + padding: 8px 50px 8px 8px; + } + #toast-container .toast-close-button { + right: -0.2em; + top: -0.2em; + } + #toast-container .rtl .toast-close-button { + left: -0.2em; + right: 0.2em; + } +} +@media all and (min-width: 241px) and (max-width: 480px) { + #toast-container > div { + padding: 8px 8px 8px 50px; + width: 18em; + } + #toast-container > div.rtl { + padding: 8px 50px 8px 8px; + } + #toast-container .toast-close-button { + right: -0.2em; + top: -0.2em; + } + #toast-container .rtl .toast-close-button { + left: -0.2em; + right: 0.2em; + } +} +@media all and (min-width: 481px) and (max-width: 768px) { + #toast-container > div { + padding: 15px 15px 15px 50px; + width: 25em; + } + #toast-container > div.rtl { + padding: 15px 50px 15px 15px; + } +} diff --git a/tasks/manifest.prod.mjs b/tasks/manifest.prod.mjs new file mode 100644 index 0000000..b837b2a --- /dev/null +++ b/tasks/manifest.prod.mjs @@ -0,0 +1,23 @@ +import { ensureFile } from "fs-extra"; +import { writeFile } from "node:fs/promises"; +import { resolve } from "node:path"; +import { getManifest } from "../src/manifest.mjs"; +import { EsmDirname, logger } from "./utils.mjs"; + +const resolvePath = (...args) => resolve(EsmDirname, "..", ...args); + +export async function writeManifest() { + const manifest = await getManifest(); + + const normalizedPath = resolvePath("extension/prod/manifest.json"); + + // TODO: remove fs-extra + await ensureFile(normalizedPath); + await writeFile( + resolvePath("extension/prod/manifest.json"), + JSON.stringify(manifest, null, 2) + ); + logger("PRE", "write manifest.json"); +} + +writeManifest(); diff --git a/tasks/mvsw.dev.mjs b/tasks/mvsw.dev.mjs index eb7f2b6..1e97269 100644 --- a/tasks/mvsw.dev.mjs +++ b/tasks/mvsw.dev.mjs @@ -7,16 +7,43 @@ import { logger } from "./utils.mjs"; await cp(resolve("src/assets"), resolve("extension/dev/assets"), { recursive: true, }); + await cp(resolve("src/styles"), resolve("extension/dev/styles"), { + recursive: true, + }); + await cp(resolve("src/pages"), resolve("extension/dev/pages"), { + recursive: true, + }); + await cp(resolve("src/lib"), resolve("extension/dev/lib"), { + recursive: true, + }); + await rename( + resolve("extension/dev/dist/lib/init.global.js"), + resolve("extension/dev/lib/init.js") + ); + await rename( + resolve("extension/dev/dist/lib/xdLocalStorage.min.global.js"), + resolve("extension/dev/lib/xdLocalStorage.min.js") + ); await rename( - resolve("extension/dev/dist/background.global.js"), + resolve( + "extension/dev/dist/lib/xdLocalStoragePostMessageApi.min.global.js" + ), + resolve("extension/dev/lib/xdLocalStoragePostMessageApi.min.js") + ); + await rename( + resolve("extension/dev/dist/scripts/background.global.js"), resolve("extension/dev/background.js") ); await rename( - resolve("extension/dev/dist/contentscript.global.js"), + resolve("extension/dev/dist/scripts/contentscript.global.js"), resolve("extension/dev/contentscript.js") ); + await rename( + resolve("extension/dev/dist/scripts/contentScriptPortal.global.js"), + resolve("extension/dev/contentScriptPortal.js") + ); await rm(resolve("extension/dev/dist"), { recursive: true }); - logger("BUILD:SW", "Moved service-worker success!"); + logger("BUILD:DEV", "Builded extension successfully!"); } catch (error) { console.error("error moving files", error); } diff --git a/tasks/mvsw.prod.mjs b/tasks/mvsw.prod.mjs index 56a4588..f13e047 100644 --- a/tasks/mvsw.prod.mjs +++ b/tasks/mvsw.prod.mjs @@ -1,21 +1,49 @@ import { resolve } from "node:path"; import { cp, rename, rm } from "node:fs/promises"; +import { logger } from "./utils.mjs"; (async () => { try { await cp(resolve("src/assets"), resolve("extension/prod/assets"), { recursive: true, }); + await cp(resolve("src/styles"), resolve("extension/prod/styles"), { + recursive: true, + }); + await cp(resolve("src/pages"), resolve("extension/prod/pages"), { + recursive: true, + }); + await cp(resolve("src/lib"), resolve("extension/prod/lib"), { + recursive: true, + }); + await rename( + resolve("extension/prod/dist/lib/init.global.js"), + resolve("extension/prod/lib/init.js") + ); + await rename( + resolve("extension/prod/dist/lib/xdLocalStorage.min.global.js"), + resolve("extension/prod/lib/xdLocalStorage.min.js") + ); await rename( - resolve("extension/prod/dist/background.global.js"), + resolve( + "extension/prod/dist/lib/xdLocalStoragePostMessageApi.min.global.js" + ), + resolve("extension/prod/lib/xdLocalStoragePostMessageApi.min.js") + ); + await rename( + resolve("extension/prod/dist/scripts/background.global.js"), resolve("extension/prod/background.js") ); await rename( - resolve("extension/prod/dist/contentscript.global.js"), + resolve("extension/prod/dist/scripts/contentscript.global.js"), resolve("extension/prod/contentscript.js") ); + await rename( + resolve("extension/prod/dist/scripts/contentScriptPortal.global.js"), + resolve("extension/prod/contentScriptPortal.js") + ); await rm(resolve("extension/prod/dist"), { recursive: true }); - console.log("sucessfuly built worker [PROD]"); + logger("BUILD:PROD", "Builded extension successfully!"); } catch (error) { console.error("error moving files [PROD]", error); } diff --git a/tasks/prepare.prod.mjs b/tasks/prepare.prod.mjs index b5ee526..12d7a92 100644 --- a/tasks/prepare.prod.mjs +++ b/tasks/prepare.prod.mjs @@ -1,5 +1,5 @@ import { execSync } from "node:child_process"; (function writeManifest() { - execSync("node ./tasks/manifest.dev.mjs", { stdio: "inherit" }); + execSync("node ./tasks/manifest.prod.mjs", { stdio: "inherit" }); })(); diff --git a/tsup.config.mjs b/tsup.config.mjs new file mode 100644 index 0000000..01bcc54 --- /dev/null +++ b/tsup.config.mjs @@ -0,0 +1,20 @@ +import { defineConfig } from "tsup"; + +const isDev = process.env.NODE_ENV !== "prod"; + +export default defineConfig({ + entry: [ + "src/scripts/background.js", + "src/scripts/contentscript.js", + "src/scripts/contentScriptPortal.js", + "src/lib/*.js", + ], + target: "node20", + format: "iife", + outDir: isDev ? "extension/dev/dist" : "extension/prod/dist", + splitting: false, + minify: isDev ? false : true, + env: { + NODE_ENV: isDev ? "dev" : "prod", + }, +});