This commit is contained in:
Leandro Facchinetti 2021-03-18 11:20:46 +00:00
parent 00d7c596e5
commit e1cd5b5920
3 changed files with 17 additions and 21 deletions

View File

@ -1,15 +0,0 @@
module.exports = (require) => {
const path = require("path");
const killTheNewsletter = require(".").default;
const { webApplication, emailApplication } = killTheNewsletter(
path.join(__dirname, "data")
);
webApplication.listen(new URL(webApplication.get("url")).port, () => {
console.log(`Web server started at ${webApplication.get("url")}`);
});
emailApplication.listen(new URL(webApplication.get("email")).port, () => {
console.log(`Email server started at ${webApplication.get("email")}`);
});
};

View File

@ -18,7 +18,7 @@
"bugs": "https://github.com/leafac/kill-the-newsletter/issues", "bugs": "https://github.com/leafac/kill-the-newsletter/issues",
"homepage": "https://github.com/leafac/kill-the-newsletter#readme", "homepage": "https://github.com/leafac/kill-the-newsletter#readme",
"scripts": { "scripts": {
"start": "ts-node-dev --poll src/index.ts configuration.development.js", "start": "ts-node-dev --poll src/index.ts",
"test": "prettier --check \"src/**/*\" --end-of-line auto && jest", "test": "prettier --check \"src/**/*\" --end-of-line auto && jest",
"prepare": "tsc" "prepare": "tsc"
}, },

View File

@ -520,9 +520,20 @@ export default function killTheNewsletter(
if (require.main === module) { if (require.main === module) {
console.log(`Kill the Newsletter!/${VERSION}`); console.log(`Kill the Newsletter!/${VERSION}`);
const configurationFile = path.resolve( const configurationFile = process.argv[2];
process.argv[2] ?? path.join(process.cwd(), "configuration.js") if (configurationFile === undefined) {
const { webApplication, emailApplication } = killTheNewsletter(
path.join(process.cwd(), "data")
); );
require(configurationFile)(require); webApplication.listen(new URL(webApplication.get("url")).port, () => {
console.log(`Configuration loaded from ${configurationFile}.`); console.log(`Web server started at ${webApplication.get("url")}`);
});
emailApplication.listen(new URL(webApplication.get("email")).port, () => {
console.log(`Email server started at ${webApplication.get("email")}`);
});
} else {
const configurationFileAbsolute = path.resolve(configurationFile);
require(configurationFileAbsolute)(require);
console.log(`Configuration loaded from ${configurationFileAbsolute}.`);
}
} }