removido bun
This commit is contained in:
parent
3cf79e06e4
commit
30f581db65
13 changed files with 2317 additions and 1706 deletions
59
dist-front/mapear_pasta.js
Normal file
59
dist-front/mapear_pasta.js
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { globSync } from "glob";
|
||||
const mapearPasta = ({
|
||||
prefixos,
|
||||
pasta,
|
||||
arquivoDestino,
|
||||
variavel
|
||||
}) => {
|
||||
const pasta_estaticos = pasta.endsWith("/") ? pasta : `${pasta}/`;
|
||||
if (!fs.existsSync(pasta_estaticos))
|
||||
throw new Error(`Pasta ${pasta_estaticos} n\xE3o existe`);
|
||||
const _gerar = (async () => {
|
||||
const files = globSync(`${pasta_estaticos}**/*`, { nodir: true });
|
||||
const arquivo_ts = `
|
||||
|
||||
|
||||
const Prefixos = {
|
||||
${Object.entries(prefixos).map(([k, v]) => `"${k}": "${v.replace(/"/g, '\\"')}"`).join(",\n")}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param caminho
|
||||
* @returns String
|
||||
*/
|
||||
export const ${variavel || "estaticos"} = (caminho: keyof typeof Prefixos) => {
|
||||
const prefixo = Prefixos[caminho];
|
||||
|
||||
return ${(() => {
|
||||
const arquivos = {};
|
||||
for (const arquivo of files) {
|
||||
const partes = arquivo.slice(pasta_estaticos.length).split("/");
|
||||
let pasta2 = arquivos;
|
||||
for (const [i, parte] of partes.entries()) {
|
||||
if (i === partes.length - 1) {
|
||||
pasta2[parte] = `~~~\${prefixo}${encodeURI(
|
||||
arquivo.slice(pasta_estaticos.length - 1)
|
||||
)}~~~`;
|
||||
} else {
|
||||
pasta2[parte] = pasta2[parte] || {};
|
||||
pasta2 = pasta2[parte];
|
||||
}
|
||||
}
|
||||
}
|
||||
return JSON.stringify(arquivos, null, 2).replace(/"~~~/g, "`").replace(/~~~"/g, "`");
|
||||
})()};
|
||||
};
|
||||
`;
|
||||
const pastaDestino = path.dirname(arquivoDestino);
|
||||
if (!fs.existsSync(pastaDestino)) {
|
||||
fs.mkdirSync(pastaDestino, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(arquivoDestino, arquivo_ts);
|
||||
})();
|
||||
};
|
||||
export {
|
||||
mapearPasta
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue