-
Notifications
You must be signed in to change notification settings - Fork 63
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
next take on updated rc system #132
Conversation
Codecov Report
@@ Coverage Diff @@
## master #132 +/- ##
==========================================
+ Coverage 82.17% 83.05% +0.88%
==========================================
Files 27 30 +3
Lines 387 413 +26
==========================================
+ Hits 318 343 +25
- Misses 69 70 +1
Continue to review full report at Codecov.
|
Looks great. I've been pondering the integration of I think it makes sense to ditch the environment singleton and simply call getEnvironment(cliConfig). The singleton was introduced (by me) to ensure that each of the CLI commands didn't cause config/blueprints to be loaded multiple times whilst building out the CLI. E.g. // cil/cmds/init.js
import getEnvironment from '../environment';
import Init from '../../sub-commands/init';
const subCommand = new Init(getEnvironment());
const usage = 'Usage:\n $0 init';
module.exports = {
command: 'init',
describe: 'Initialize .blueprintrc for the current project',
builder: yargs => yargs.usage(usage),
handler: () => subCommand.run()
}; If we move the instantiation of the environment inside the handler we have access to the cli config argument and we're guaranteed to only create a single environment in the context of any command. This is already the case for the // cli/cmds/init.js
import getEnvironment from '../environment';
import Init from '../../sub-commands/init';
const usage = 'Usage:\n $0 init';
module.exports = {
command: 'init',
describe: 'Initialize .blueprintrc for the current project',
builder: yargs => yargs.usage(usage),
handler: argv => {
const environment = getEnvironment(argv.config);
const subCommand = new Init(environment);
subCommand.run();
}
}; We could choose to pass I'm happy to provide a PR that would make those changes to the CLI commands (leaving that actual changes to getEnvironment to this PR). |
I've been accounting for taking the argv, but have purposely not spelled anything out about how and when. I think the only real 'danger' of not using a singleton requires using it twice within the same invocation. The IO cycles slow it down, but not noticably. So where ever in the process we decide to read it, we just need to make sure it's not read a second time. We could add tests to ensure that, but i'm not sure it's worth even that small amount of effort. The CLI pattern you laid out looks good to me. I'm working on the rest of the rc process today. Stay tuned to this space for all the latest |
More thoughts. I want to maintain a good separation of concerns between the classes. I'm thinking about this
|
Using the CLI pattern as described means there will only ever be a single call to instantiate the CLI environment using argv. It will then be passed into the SubCommand which can in turn pass it into any Tasks it needs to run. I'll submit a PR with those changes. |
I'm much happier with this take. I reduced the ridiculous amount of DI I was doing and scaled it back to a few targeted places where an override for the ENV or fs made testing much easier. Next step is the hand off of blueprint paths and then instantiating the Blueprint Collection. |
Victory is Mine! 🏆
|
I broke a ton of tests, and I'll fix those this weekend. But it's reading rc files and finding and instantiating blueprints. The big areas that need addressed are.
|
I'm still happy with the way this came together, and I handled the test coverage too. @jamesr73 can you give it a review when you have the time? Thanks. |
FileCollection
rcFiles.all
returns every file path checked for an rc filercFiles.present
returns paths to all files that existRcRaw
rcRaw.collection
an object with keys of the filename and values of the contents of that filercRaw.order
an array of rcFile names in the order of priorityrcRaw.data
an array of rcFile contents in order of of priorityRcData
rc.settings
object created by deep merge of all file contentsrc.get('key.path.parts[4]', default)
returns that value from the settings or defaultrc.with(opts)
returns a new rc object created from itself and optsrc.withBp(name,opts)
returns a new rc object for that Blueprint, merged with common settingsDirCollection
bpDirs.all
returns every directory that might be checked for blueprintsbpDirs.present
returns paths to all directoryies that exist