-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Different loading of user configuration in subdirectories #2544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I would have a working but dirty solution ready: diff --git a/lib/hooks/moduleloader/index.js b/lib/hooks/moduleloader/index.js
index e0ed0c6..9edc846 100644
--- a/lib/hooks/moduleloader/index.js
+++ b/lib/hooks/moduleloader/index.js
@@ -166,7 +166,8 @@ module.exports = function(sails) {
exclude : ['locales', 'local.js', 'local.json', 'local.coffee', 'local.litcoffee'],
excludeDirs: /(locales|env)$/,
filter : /(.+)\.(js|json|coffee|litcoffee)$/,
- identity : false
+ identity : false,
+ markDirectories: true
}, cb);
}, sails-build-dictionary: diff --git a/index.js b/index.js
index 97f66fb..1e96b9c 100644
--- a/index.js
+++ b/index.js
@@ -83,10 +83,14 @@ function buildDictionary (options, cb) {
return cb(new Error('Invalid module:' + module));
}
- // Merge module into dictionary
- _.merge(dictionary, module);
+ if(!module.isDirectory) {
+ // Merge module into dictionary
+ _.merge(dictionary, module);
- return;
+ return;
+ } else {
+ module = _.omit(module, 'isDirectory');
+ }
} Like I said, it's dirty and I feel like the changes made to build-dictionary are too case specific. |
With the exception of the
The extra few keystrokes are a lot better than the headache you'd have if we automatically determined the config keypath based on the file structure, and then you moved one of those files. |
As far as I have tested, using the content of So as far as I can see, I have to put everything into one file or use a place that is not getting auto-loaded and load it manually? |
Did you revert your changes to moduleLoader before you tried? |
Yes, I did a clean npm install |
My apologies--I should have actually tried this myself before I suggested it 😳. It looks to me like the |
Should I change the description of the main issue to depict the new context? |
Sails does indeed load the files in the subfolder already, however, it does this improperly. See balderdashy/sails#2544 for more info.
Added a fix and tests for this, and added a note to the migration guide. Thanks for pointing this out! |
Alright, thank you! |
I have a small issue with the way user configurations are loaded into
sails.config
when it comes to configuration files in subdirectories.Lets suppose we have this directory tree:
When I now load my app, wouldn't the most intuitive way of accessing the values of
banana
besails.config.fruits.banana
? Because right now, all config files of subdirectories get merged into the main config value, without sub-directives which depict the directory they're in, thus resulting insails.config.banana
. Sincelocals
andenv
have their own loading process, this shouldn't be much of an issue right?This would not only tidy up the config variable (because you can put similar configuration files into a subdirectory instead of polluting the main namespace), but also allows you to separate sails specific configuration and user made configuration. For example, when I want to have a config for some policies of my internal logic, I could then put them under
config/app/policies.js
and it would not add to the policies for sails.TL:DR: A configuration file under
config/sub/file.js
should be accessible viasails.config.sub.file
and not viasails.config.file
.The text was updated successfully, but these errors were encountered: