-
Notifications
You must be signed in to change notification settings - Fork 20
Allow config file to be arbitrarily named #66
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
Allow config file to be arbitrarily named #66
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @casio !
@@ -65,7 +65,13 @@ program.parse(process.argv); | |||
|
|||
var input = program.args[0] ? resolve(program.args[0]) : null; | |||
var output = program.args[1] ? resolve(program.args[1]) : null; | |||
var config = program.config ? require(resolve(program.config)) : null; | |||
var config = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that this could just be declared var config;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, now this makes node run lint
bark:
suit-preprocessor/bin/suitcss
94:1 error Combine this with the previous 'var' statement with uninitialized variables one-var
I guess lint suggests to read sth like
var config, currentWatchedFiles;
...but since the vars are rather unrelated in their sections, should we really?!
if (configFile && configFile.endsWith('.js')) { | ||
config = require(resolve(configFile)); | ||
} else if (configFile) { | ||
config = fs.readJsonSync(configFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve(configFile)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ouch, absolutely! : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the eslint failure either by combining this declaration with the previous one or reverting the change and setting it to null
and then this is good to go!
config = require(resolve(configFile)); | ||
} else if (configFile) { | ||
config = fs.readJsonSync(resolve(configFile)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could put this into a function to reduce the duplication? Something like:
var config = resolveConfig(program.config);
function resolveConfig(configFile) {
if (!configFile) {return;}
var configPath = resolve(configFile);
var ext = path.extname(configPath);
if (/js|json/.test(ext)) {
return require(configPath);
}
return fs.readJsonSync(configPath);
}
Note I haven't tested the above, but it will allow us to leverage require
for JSON files too and fix the ESLint issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, functions would also cleanup the cli code a bit - would be helpful also in the importRoot fix, btw.
I wasnt sure, if you guys wanted this inside the cli code. should these be factored out to something like bin/utils.js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My vote would be just add small functions in the bin
file. I'd only split them out if we need them elsewhere. We can use rewire
to unit test them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I went too fast & pushed an factor out commit already, sry.
however, maybe once the importRoot stuff also gets more code in the cli, it might get a bit cluttered?
anyway, just ping me if you'd like this changed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thoughts are unless we expect that utils file to be large and used in multiple places it just adds more misdirection to reading the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simonsmith alright, I factored the fn into bin/suitcss
again.
also I left out unit tests for now, as the fns scope is covered by the integration tests already. good?
var configPath = resolve(configFile); | ||
var ext = path.extname(configPath); | ||
|
||
if (/js/.test(ext)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: we could avoid the regexp here with ext.indexOf('js') === 0
otherwise it should be ^js(?:on)?$
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, how about straight ext === '.js'
, then? : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can still require json
function requireOrParse(configFile) { | ||
var configPath = resolve(configFile); | ||
var ext = path.extname(configPath); | ||
var readFn = ext === '.js' ? require : fs.readJsonSync; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if @simonsmith thinks that it is not a big deal to require .json
files with readJsonSync
(it could be require
d) then we can merge this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should lean on require
where possible. It seems wasteful to send JSON files through this extra module which basically does what require
would already.
Could we reinstate the regex or check for json
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho it shows the purpose of the fn more clearly and since the dep on fs-extra
is used elsewhere I thought 'hey, exactly what we want here' : )
but anyway: your call, I'll push an update in a minute!
Just re-running the windows build |
I think we could squash this into one commit and just reference the issue in the description. Are you happy to do that @casio? |
a189d3d
to
69b73c1
Compare
@simonsmith yup, here you go |
cool thanks @casio! |
CLI forever. Thanks for this @casio 🎉 |
haha :D pleasure! |
this is a stab at #65 - if you guys should choose to change the behaviour