82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
var mapear_pasta_exports = {};
|
|
__export(mapear_pasta_exports, {
|
|
mapearPasta: () => mapearPasta
|
|
});
|
|
module.exports = __toCommonJS(mapear_pasta_exports);
|
|
const mapearPasta = ({
|
|
prefixos,
|
|
pasta,
|
|
arquivoDestino,
|
|
variavel,
|
|
globSync,
|
|
fs,
|
|
path
|
|
}) => {
|
|
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);
|
|
})();
|
|
};
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
mapearPasta
|
|
});
|