tolustar/express-api-cli

fails silently when `src/config/database.js` is missing

Opened this issue · 0 comments

Any command, including exp-api -v, exits with 0 status without printing anything when it can't open src/config/database.js.

There are 4 issues:

  • exp-api -v shouldn't be looking for any files to begin with

  • utils.checkLangAndDB doesn't handle error from missing ./src:

    let files = fs.readdirSync('./src/');

  • utils.checkLangAndDB attempts to print error from missing ./src/config/database.js without importing chalk:

    try {
    if (config.lang === 'js') {
    db = await fs.readFile('./src/config/database.js');
    } else {
    db = await fs.readFile('./src/config/database.ts');
    }
    db = db.toString();
    } catch (error) {
    console.log(
    chalk.yellow(`
    Database config not detected in src/config.
    express-api-cli shall assume project default database config uses mongoose. Thank you.
    `)
    );
    }

  • all unhandled errors are swallowed:

    } catch (error) {}