Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Feat/config path from package.json #405

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion generators/app/configs/package.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const semver = require('semver');

module.exports = function(generator) {
const major = semver.major(process.version);
const envConfigDir = process.env['NODE_CONFIG_DIR'];
const configDirectory = envConfigDir ? p.join(envConfigDir) : 'config/';
const { props } = generator;
const lib = props.src;
const [ packager, version ] = props.packager.split('@');
Expand All @@ -22,7 +24,8 @@ module.exports = function(generator) {
bugs: {},
directories: {
lib,
test: 'test/'
test: 'test/',
config: configDirectory
},
engines: {
node: `^${major}.0.0`,
Expand Down
4 changes: 2 additions & 2 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ module.exports = class AppGenerator extends Generator {
);

this.fs.writeJSON(
this.destinationPath('config', 'default.json'),
this.destinationPath(this.configDirectory, 'default.json'),
makeConfig.configDefault(this)
);

this.fs.writeJSON(
this.destinationPath('config', 'production.json'),
this.destinationPath(this.configDirectory, 'production.json'),
makeConfig.configProduction(this)
);
}
Expand Down
4 changes: 2 additions & 2 deletions generators/authentication/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ module.exports = class AuthGenerator extends Generator {

this.conflicter.force = true;
this.fs.writeJSON(
this.destinationPath('config', 'default.json'),
this.destinationPath(this.configDirectory, 'default.json'),
config
);
}
Expand Down Expand Up @@ -167,7 +167,7 @@ module.exports = class AuthGenerator extends Generator {
dependencies.push(`@feathersjs/authentication-${strategy}`);
}
});

if(!this.fs.exists(this.destinationPath(this.libDirectory, 'services', context.kebabEntity, `${context.kebabEntity}.service.js`))) {
// Create the users service
this.composeWith(require.resolve('../service'), {
Expand Down
2 changes: 1 addition & 1 deletion generators/connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = class ConnectionGenerator extends Generator {

this.conflicter.force = true;
this.fs.writeJSON(
this.destinationPath('config', 'default.json'),
this.destinationPath(this.configDirectory, 'default.json'),
config
);
}
Expand Down
10 changes: 6 additions & 4 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ module.exports = class BaseGenerator extends Generator {
constructor(args, opts) {
super(args, opts);

const defaultConfig = this.destinationPath('config', 'default.json');

this.generatorPkg = this.fs.readJSON(path.join(__dirname, '..', 'package.json'));
this.pkg = this.fs.readJSON(this.destinationPath('package.json'), {});
this.defaultConfig = this.fs.readJSON(defaultConfig, {});
this.defaultConfig = this.fs.readJSON(this.destinationPath(this.configDirectory, 'default.json'), {});
this.props = opts.props || {};

if (!semver.satisfies(process.version, '>= 6.0.0')) {
Expand Down Expand Up @@ -52,9 +50,13 @@ module.exports = class BaseGenerator extends Generator {
get testDirectory() {
return (this.pkg.directories && this.pkg.directories.test) || 'test';
}

get configDirectory () {
return (this.pkg.directories && this.pkg.directories.config) || 'config';
}

_packagerInstall(deps, options) {
const packager = this.pkg.engines && this.pkg.engines.yarn ?
const packager = this.pkg.engines && this.pkg.engines.yarn ?
'yarn' : 'npm';
const method = `${packager}Install`;
const isDev = options.saveDev;
Expand Down