Skip to content

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

Merged
merged 1 commit into from
Nov 30, 2016

Conversation

casio
Copy link
Contributor

@casio casio commented Nov 28, 2016

this is a stab at #65 - if you guys should choose to change the behaviour

Copy link
Member

@giuseppeg giuseppeg left a 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;
Copy link
Member

@giuseppeg giuseppeg Nov 28, 2016

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;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, fine

Copy link
Contributor Author

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve(configFile) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch, absolutely! : )

Copy link
Member

@giuseppeg giuseppeg left a 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));
}
Copy link
Member

@simonsmith simonsmith Nov 28, 2016

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.

Copy link
Contributor Author

@casio casio Nov 28, 2016

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?

Copy link
Member

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.

Copy link
Contributor Author

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!

Copy link
Member

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.

Copy link
Contributor Author

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)) {
Copy link
Member

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)?$

Copy link
Contributor Author

@casio casio Nov 28, 2016

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? : )

Copy link
Member

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;
Copy link
Member

@giuseppeg giuseppeg Nov 29, 2016

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 required) then we can merge this.

Copy link
Member

@simonsmith simonsmith Nov 29, 2016

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?

Copy link
Contributor Author

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!

@simonsmith
Copy link
Member

Just re-running the windows build

@simonsmith
Copy link
Member

I think we could squash this into one commit and just reference the issue in the description. Are you happy to do that @casio?

@casio casio force-pushed the feature/arbitrary-config-filename branch from a189d3d to 69b73c1 Compare November 30, 2016 08:32
@casio
Copy link
Contributor Author

casio commented Nov 30, 2016

@simonsmith yup, here you go

@giuseppeg giuseppeg merged commit 411089d into suitcss:master Nov 30, 2016
@giuseppeg
Copy link
Member

cool thanks @casio!
@simonsmith fwiw it is possible to squash and merge from the github ui

@simonsmith
Copy link
Member

simonsmith commented Nov 30, 2016

CLI forever.

Thanks for this @casio 🎉

@casio
Copy link
Contributor Author

casio commented Nov 30, 2016

CLI forever.

haha :D pleasure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants