Skip to content

Commit

Permalink
Refactor handling configurations
Browse files Browse the repository at this point in the history
Switch to jest in the generated application
  • Loading branch information
Ugo committed Jan 2, 2021
1 parent 62cabfc commit 6c7b06d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
21 changes: 15 additions & 6 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = class extends Generator {
type: 'checkbox',
name: 'api',
message: 'Which API adapter should I prime? (press Enter to skip)',
choices: ['bla', 'blu', 'bli'],
choices: [{ name: 'Open Weather', value: 'openWeather' }],
default: []
}
]);
Expand All @@ -61,8 +61,7 @@ module.exports = class extends Generator {
// Dependencies injection
this.dependencies = ['axios', 'body-parser', 'cors', 'express'];
this.devDependencies = [
'chai',
'mocha',
'jest',
'dependency-cruiser',
'eslint',
'lint-staged',
Expand All @@ -83,19 +82,29 @@ module.exports = class extends Generator {
copyTpl(src('lib/index.js'), dest('lib/index.js'), {
mongoose: answers.database == 'MongoDB'
});
copyTpl(src('lib/config.js'), dest('lib/config.js'), {

// lib/config
copyTpl(src('lib/config/index.js'), dest('lib/config/index.js'), {
...answers,
api: answers.api.length > 0,
mongoose: answers.database == 'MongoDB'
});
copy(dest('lib/config.js'), dest('lib/config.js.template'));
copyTpl(dest('lib/config/index.js'), dest('lib/config/index.js.template'));

copy(src('lib/helpers'), dest('lib/helpers'));
copy(src('lib/routes'), dest('lib/routes'));

// lib/api
if (answers.api.length > 0) {
console.log(answers.api);
copy(src('lib/api'), dest('lib/api'));
copyTpl(src('api-lib/api.config.js'), dest('lib/config/api.config.js'), {
openWeather: answers.api.includes('openWeather')
});

// copy single modules
if (answers.api.includes('openWeather')) {
copy(src('api-lib/open-weather'), dest('lib/api/open-weather'));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<% if (api) { %>
const api = require('./api.config.js')
<% } %>

const env = {};

env.production = {
Expand All @@ -17,6 +21,8 @@ env.stage = {
local: "mongodb://localhost:27017/<%= name %>",
remote: "YOUR_REMOTE_DB"
}
<% } %><% if (api) { %>,
api
<% } %>
};

Expand All @@ -27,6 +33,8 @@ env.test = {
local: "mongodb://localhost:27017/<%= name %>",
remote: "YOUR_REMOTE_DB"
}
<% } %><% if (api) { %>,
api
<% } %>
};

Expand Down
2 changes: 1 addition & 1 deletion generators/app/templates/lib/helpers/get-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const config = require('../config.js');
const config = require('../config');

const DEFAULT_ENV = 'stage';

Expand Down
46 changes: 23 additions & 23 deletions generators/app/templates/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "<%= name %>",
"version": "<%= version %>",
"description": "<%= description %>",
"main": "index.js",
"scripts": {
"start": "node .",
"precommit": "lint-staged",
"dev": "nodemon .",
"test": "mocha lib/**/*/**/__test/*.spec.js --recursive",
"deploy": "bash ./.deployment/deploy.sh",
"build:deptree": "depcruise --exclude '^node_modules' --output-type dot lib | dot -T svg > dependencygraph.svg"
},
"author": "",
"email": "",
"license": "",
"devDependencies": {},
"lint-staged": {
"*.js": [
"prettier --write",
"git add"
]
},
"dependencies": {}
"name": "<%= name %>",
"version": "<%= version %>",
"description": "<%= description %>",
"main": "index.js",
"scripts": {
"start": "node .",
"precommit": "lint-staged",
"dev": "nodemon .",
"test": "jest --coverage",
"deploy": "bash ./.deployment/deploy.sh",
"build:deptree": "depcruise --exclude '^node_modules' --output-type dot lib | dot -T svg > dependencygraph.svg"
},
"author": "",
"email": "",
"license": "",
"devDependencies": {},
"lint-staged": {
"*.js": [
"prettier --write",
"git add"
]
},
"dependencies": {}
}

0 comments on commit 6c7b06d

Please sign in to comment.