Skip to content

Commit

Permalink
Merge pull request #65 from ufabc-next/chore/migrate-stuff-to-esm
Browse files Browse the repository at this point in the history
ESM as default
  • Loading branch information
Joabesv authored Feb 14, 2024
2 parents 7605a65 + 8a27347 commit 0dd76d4
Show file tree
Hide file tree
Showing 28 changed files with 43 additions and 104 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
"name": "UFABC-Next-Extension",
"private": true,
"version": "1.1.7",
"type": "module",
"description": "Adiciona funcionalidades novas ao sistema de matricula da UFABC",
"scripts": {
"dev": "rimraf extension/dev && run-p dev:*",
"dev:prepare": "node --no-warnings=ExperimentalWarning tasks/prepare.dev.mjs dev",
"dev:prepare": "node --no-warnings=ExperimentalWarning tasks/prepare.dev.js dev",
"dev:web": "vite",
"dev:js": "yarn run build:dev --watch src",
"build": "NODE_ENV=prod run-s clear build:web build:prepare build:prod",
"build:prepare": "node tasks/prepare.prod.mjs build",
"build:prepare": "node tasks/prepare.prod.js build",
"build:web": "vite build",
"build:dev": "tsup --onSuccess 'node --no-warnings=ExperimentalWarning tasks/mvsw.dev.mjs'",
"build:prod": "tsup --onSuccess 'node --no-warnings=ExperimentalWarning tasks/mvsw.prod.mjs'",
"build:dev": "tsup --onSuccess 'node --no-warnings=ExperimentalWarning tasks/mvsw.dev.js'",
"build:prod": "tsup --onSuccess 'node --no-warnings=ExperimentalWarning tasks/mvsw.prod.js'",
"clear": "rimraf extension/prod"
},
"standard": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/scripts/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function load() {
Utils.injectScript("lib/init.js");

setupStorage();
require("./contentScriptPortal");
await import("./contentScriptPortal");

if (matricula_url.some((url) => currentUrl.indexOf(url) != -1)) {
// update teachers locally
Expand Down
6 changes: 1 addition & 5 deletions src/services/NextAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function resolveEndpoint(env) {
);
}

function NextAPI() {
export function NextAPI() {
const baseURL = resolveEndpoint(process.env.NODE_ENV);
const REQUEST_TIMEOUT = 5000;
const nextAPI = Axios.create({
Expand All @@ -24,7 +24,3 @@ function NextAPI() {

return nextAPI;
}

module.exports = {
NextAPI,
};
File renamed without changes.
6 changes: 3 additions & 3 deletions src/utils/Matricula.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Axios from "axios";
import { NextAPI } from "../services/NextAPI";
import toJSON from "./toJSON";
import { toJSON } from "./toJSON";
import _ from "lodash";
import $ from "jquery";
import Utils from "./extensionUtils";

const nextApi = NextAPI();

module.exports = new Matricula();

function Matricula() {
const MATRICULAS_URL =
{
Expand Down Expand Up @@ -154,3 +152,5 @@ function Matricula() {
sendAlunoData,
};
}

export default new Matricula();
10 changes: 3 additions & 7 deletions src/utils/convertUfabcDisciplina.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const _ = require("lodash");
const removeDiacritics = require("./removeDiacritics");
import _ from "lodash";
import removeDiacritics from "./removeDiacritics";

// This convert an disciplina from the .json from matriculas.ufabc
function convertDisciplina(d) {
export function convertDisciplina(d) {
const obj = _.defaults(_.clone(d));

// specific for .json
Expand Down Expand Up @@ -114,7 +114,3 @@ function extractCampus(d) {

return null;
}

module.exports = {
convertDisciplina,
};
11 changes: 5 additions & 6 deletions src/utils/disciplinaIdentifier.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { createHash } from "crypto";
import { createHash } from "node:crypto";
import _ from "lodash";

const DEFAULT_FIELDS_TO_ENCODE = ["disciplina", "turno", "campus", "turma"];

/**
* Generates a unique identifier for a given disciplina
* */
function generateIdentifier(disciplina, keys = DEFAULT_FIELDS_TO_ENCODE) {
export function generateIdentifier(
disciplina,
keys = DEFAULT_FIELDS_TO_ENCODE
) {
const unorderedDisciplinas = keys.map((key) => String(disciplina[key]));
const disciplinaToEncode = unorderedDisciplinas
.map((disciplina) => _.camelCase(disciplina))
.join("");

return createHash("md5").update(disciplinaToEncode).digest("hex");
}

module.exports = {
generateIdentifier,
};
4 changes: 2 additions & 2 deletions src/utils/extensionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import Axios from "axios";
import is from "is_js";
import _ from "lodash";

module.exports = new ExtensionUtils();

function ExtensionUtils() {
// force initialization of xdLocalStorage
// window.xdLocalStorage.init({
Expand Down Expand Up @@ -131,3 +129,5 @@ function ExtensionUtils() {
storage,
};
}

export default new ExtensionUtils();
8 changes: 4 additions & 4 deletions src/utils/removeDiacritics.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@
}

// "what?" version ... http://jsperf.com/diacritics/12
module.exports = function removeDiacritics (str) {
return str.replace(/[^\u0000-\u007E]/g, function(a){
return diacriticsMap[a] || a;
export default function removeDiacritics (str) {
return str.replace(/[^\u0000-\u007E]/g, function(a){
return diacriticsMap[a] || a;
});
}
}
12 changes: 3 additions & 9 deletions src/utils/season.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function findQuadFromDate(month) {
}
}

function findSeason(date = new Date()) {
export function findSeason(date = new Date()) {
const month = date.getMonth();
return {
1: {
Expand All @@ -28,12 +28,12 @@ function findSeason(date = new Date()) {
}[findQuadFromDate(date.getMonth() || month)];
}

function findSeasonKey(date) {
export function findSeasonKey(date) {
const { year, quad } = findSeason(date);
return `${year}:${quad}`;
}

function findIdeais(date) {
export function findIdeais(date) {
return {
1: [
"BCM0506-15", // COMUNICACAO E REDES
Expand Down Expand Up @@ -76,9 +76,3 @@ function findIdeais(date) {
],
}[findQuadFromDate(date || new Date().getMonth())];
}

module.exports = {
findSeason,
findSeasonKey,
findIdeais,
};
6 changes: 1 addition & 5 deletions src/utils/setupStorage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function setupStorage() {
export function setupStorage() {
document.addEventListener("requestStorage", (event) => {
const key = event.detail.key;
const date = event.detail.date;
Expand Down Expand Up @@ -63,7 +63,3 @@ function setupStorage() {
}
});
}

module.exports = {
setupStorage,
};
39 changes: 0 additions & 39 deletions src/utils/setupStorageESM.mjs

This file was deleted.

8 changes: 2 additions & 6 deletions src/utils/toJSON.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from "lodash";

const toJSON = (payload, max) => {
export function toJSON(payload, max) {
const json = JSON.parse(
_.get(new RegExp(/^\w*=(.*)/).exec(payload), "[1]", {})
);
Expand All @@ -10,8 +10,4 @@ const toJSON = (payload, max) => {
}

return json;
};

module.exports = {
toJSON,
};
}
4 changes: 2 additions & 2 deletions src/views/Popup/Popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
<script setup>
import { onMounted, ref } from "vue";
import { NextStorage } from "../../services/NextStorage";
import { setupStorageESM } from "../../utils/setupStorageESM";
import { setupStorage } from "../../utils/setupStorage";
setupStorageESM();
setupStorage();
const students = ref(null);
const loading = ref(false);
Expand Down
4 changes: 2 additions & 2 deletions tasks/manifest.dev.mjs → tasks/manifest.dev.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { writeFile } from "node:fs/promises";
import { ensureFile } from "fs-extra";
import { getManifest } from "../src/manifest.mjs";
import { getManifest } from "../src/manifest.js";
import { resolve } from "node:path";
import { EsmDirname, logger } from "./utils.mjs";
import { EsmDirname, logger } from "./utils.js";

const resolvePath = (...args) => resolve(EsmDirname, "..", ...args);

Expand Down
4 changes: 2 additions & 2 deletions tasks/manifest.prod.mjs → tasks/manifest.prod.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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";
import { getManifest } from "../src/manifest.js";
import { EsmDirname, logger } from "./utils.js";

const resolvePath = (...args) => resolve(EsmDirname, "..", ...args);

Expand Down
2 changes: 1 addition & 1 deletion tasks/mvsw.dev.mjs → tasks/mvsw.dev.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from "node:path";
import { cp, rename, rm } from "node:fs/promises";
import { logger } from "./utils.mjs";
import { logger } from "./utils.js";

(async () => {
try {
Expand Down
2 changes: 1 addition & 1 deletion tasks/mvsw.prod.mjs → tasks/mvsw.prod.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from "node:path";
import { cp, rename, rm } from "node:fs/promises";
import { logger } from "./utils.mjs";
import { logger } from "./utils.js";

(async () => {
try {
Expand Down
6 changes: 3 additions & 3 deletions tasks/prepare.dev.mjs → tasks/prepare.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { execSync } from "node:child_process";
import { resolve } from "node:path";
import { watch } from "chokidar";
import { existsSync } from "node:fs";
import { EsmDirname, logger, PORT } from "./utils.mjs";
import { EsmDirname, logger, PORT } from "./utils.js";

const resolvePath = (...args) => resolve(EsmDirname, "..", ...args);

Expand Down Expand Up @@ -46,7 +46,7 @@ async function stubHtml() {
}

function writeManifest() {
execSync("node ./tasks/manifest.dev.mjs", { stdio: "inherit" });
execSync("node ./tasks/manifest.dev.js", { stdio: "inherit" });
}

writeManifest();
Expand All @@ -56,7 +56,7 @@ if (isDev) {
watch(resolvePath("src/**/*.html")).on("change", () => {
stubHtml();
});
watch([resolvePath("src/manifest.mjs"), resolvePath("package.json")]).on(
watch([resolvePath("src/manifest.js"), resolvePath("package.json")]).on(
"change",
() => {
writeManifest();
Expand Down
2 changes: 1 addition & 1 deletion tasks/prepare.prod.mjs → tasks/prepare.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execSync } from "node:child_process";

(function writeManifest() {
execSync("node ./tasks/manifest.prod.mjs", { stdio: "inherit" });
execSync("node ./tasks/manifest.prod.js", { stdio: "inherit" });
})();
File renamed without changes.
2 changes: 1 addition & 1 deletion tsup.config.mjs → tsup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
"src/scripts/background.js",
"src/scripts/contentscript.js",
"src/scripts/contentScriptPortal.js",
"src/lib/*.js",
"src/lib/*.cjs",
],
target: "node20",
format: "iife",
Expand Down
File renamed without changes.

0 comments on commit 0dd76d4

Please sign in to comment.