Skip to content

Commit

Permalink
add additional docs for config, change connection.sequelize to connec…
Browse files Browse the repository at this point in the history
…tion.instance, add quiet mode for console commands, version bump
  • Loading branch information
realtux committed Jul 1, 2024
1 parent 5fd3394 commit 75c979d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ let config = {

console: {
use: false,
quiet: false,
},

views: {
Expand Down
2 changes: 1 addition & 1 deletion lib/database/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Sequelize } from 'sequelize';
let connection = {};

export const init = async () => {
connection.sequelize = new Sequelize(
connection.instance = new Sequelize(
config.database.name,
config.database.username,
config.database.password,
Expand Down
2 changes: 1 addition & 1 deletion lib/database/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const init = async () => {
model.init(
model.fields,
{
sequelize: connection.sequelize,
sequelize: connection.instance,
modelName: model.table_name,
freezeTableName: true,
hooks: model.hooks || {},
Expand Down
31 changes: 18 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ export default new class {
async start(file) {
const is_console = process.argv[2] === 'console';

// console.time('startup took');


console.log();
console.log(`${chalk.yellow('exa.js')} by tux - v0.0.9`);
console.log('-----------------------------');
console.log(`${chalk.green(DateTime.now().toISO())}`);
console.log('-----------------------------');

try {
/**
* set up the project root directory, necessary to discover and
Expand All @@ -45,14 +36,30 @@ export default new class {

await init_config(root_dir);

console.log(`mode: ${config.environment.development ? 'development' : 'production'}`);
let quiet = false

if (is_console && config.console.quiet) {
quiet = true;
}

if (!quiet) {
console.log();
console.log(`${chalk.yellow('exa.js')} by tux - v0.0.10`);
console.log('-----------------------------');
console.log(`${chalk.green(DateTime.now().toISO())}`);
console.log('-----------------------------');
console.log(`mode: ${config.environment.development ? 'development' : 'production'}`);
}

/**
* initialize database connection and models
* by default this uses sequelize
*/
if (config.database.use) {
console.log('initializing database...');
if (!quiet) {
console.log('initializing database...');
}

await init_db();
await init_models();
}
Expand Down Expand Up @@ -89,8 +96,6 @@ export default new class {
console.log('failed to start');
console.log(e.stack);
}

// console.timeEnd('startup took');
}

}
3 changes: 3 additions & 0 deletions lib/system/sequelize.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import sequelize from 'sequelize';

export default sequelize;
export * from 'sequelize';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@exajs/core",
"type": "module",
"author": "Brian Seymour <@realtux>",
"version": "0.0.9",
"version": "0.0.10",
"description": "modern opinionated node.js framework",
"license": "MIT",
"homepage": "https://github.com/realtux/exa",
Expand Down
15 changes: 12 additions & 3 deletions var/template/config/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ export default {
* - creates http routes from http/*
*/
http: {
// whether or not to start an express http server
use: true,
// host to run on, 0.0.0.0 for all hosts
host: '0.0.0.0',
// port to run on
port: 8118,
},

/**
* database module configuration
* - uses sequelize.js
* - creates database connection
* - initializes models in models/*
*/
database: {
// whether or not to initialize db models in models/*
use: true,
// sequelize dialect to use, supports: mysql | postgres
dialect: 'mysql',
username: 'admin',
password: 'password',
Expand All @@ -37,16 +41,19 @@ export default {
* - allows console commands ran from console/*
*/
console: {
// whether or not to allow console commands
use: true,
// whether or not to show startup information
quiet: false,
},

/**
* views module configuration
* - available engines:
* - nunjucks
*/
views: {
// whether or not to enable views
use: true,
// which view engine to use, supports: nunjucks
engine: 'nunjucks',
},

Expand All @@ -55,7 +62,9 @@ export default {
* - uses express.static(path)
*/
public: {
// whether or not to serve static assets
use: true,
// base url to serve static assets on
base_url: '/public',
},

Expand Down
4 changes: 2 additions & 2 deletions var/template/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ case $* in
console* )
docker compose run --rm console node app console ${@:2}
;;
rmig* )
docker compose exec app rmig ${@:2}
jmig* )
docker compose exec app npx jmig ${@:2}
;;
npm* )
docker run -it --rm -v .:/opt/src -w /opt/src node:20 npm ${@:2}
Expand Down

0 comments on commit 75c979d

Please sign in to comment.