adonis-mailbuilder
Version:
AdonisJS 5 mailbuilder
70 lines (69 loc) • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.indexPageRender = exports.livereloadScript = exports.listFiles = exports.getMailBuilderTmpPath = exports.dirIsExists = exports.getMailBuilderAppClassesPath = exports.getMailBuilderCompiledClassesPath = void 0;
const path_1 = require("path");
const fs_1 = require("fs");
function getMailBuilderCompiledClassesPath(app) {
const path = (0, path_1.join)(app.appRoot, 'app', 'MailBuilder');
return path;
// return join(process.cwd(), '/build/', )
}
exports.getMailBuilderCompiledClassesPath = getMailBuilderCompiledClassesPath;
function getMailBuilderAppClassesPath(app) {
return getMailBuilderCompiledClassesPath(app);
}
exports.getMailBuilderAppClassesPath = getMailBuilderAppClassesPath;
async function dirIsExists(path) {
try {
return !!(await fs_1.promises.readdir(path));
}
catch (e) {
return false;
}
}
exports.dirIsExists = dirIsExists;
async function getMailBuilderTmpPath() {
const path = (0, path_1.join)(process.cwd(), 'tmp');
try {
if (!(await dirIsExists(path))) {
await fs_1.promises.mkdir(path);
}
}
catch (e) {
console.error(e.message);
}
return path;
}
exports.getMailBuilderTmpPath = getMailBuilderTmpPath;
const listFiles = (path) => {
return fs_1.promises.readdir(path);
};
exports.listFiles = listFiles;
const livereloadScript = (url, filePath) => `<script>
window.bodyTextForLiveReload = ''
setInterval(function() {
fetch(new Request('${url}/${filePath}'))
.then(function (response){
response.text().then(function (text) {
if(window.bodyTextForLiveReload !== text){
window.bodyTextForLiveReload = text
document.body.innerHTML = text
console.log('Set new body')
}
});
})
}, 1000)
</script>`;
exports.livereloadScript = livereloadScript;
const indexPageRender = (files) => `
<h1>Please select your mailbuilder:</h1>
${files}
<style>
body{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
</style>`;
exports.indexPageRender = indexPageRender;