-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Better config resolving #37
Open
tunnckoCore
wants to merge
6
commits into
egoist:master
Choose a base branch
from
tunnckoCore:better-config-resoloving
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6fe8bcf
pass all options to readMaidFile and update error message
1f23ae3
feat: resolves #4 and closes #36
05efdf1
remove opts.cwd reference
17960f3
use equal for passing maidfile
d038aa3
Merge branch 'master' into better-config-resoloving
tunnckoCore d0374ea
Merge branch 'master' into better-config-resoloving
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,44 @@ | ||
const fs = require('fs') | ||
const parseMarkdown = require('./parseMarkdown') | ||
const loadFile = require('./loadFile') | ||
const find = require('find-file-up') | ||
|
||
module.exports = section => { | ||
const { path: filepath, data } = loadFile.loadSync([ | ||
'maidfile.md', | ||
'README.md', | ||
'readme.md' | ||
]) | ||
if (!filepath) return null | ||
// a bit duplication with what we have in parseMarkdown.js, but we can't DRY it | ||
const MAIDFILE = 'maidfile.md' | ||
|
||
return parseMarkdown(data, { section, filepath }) | ||
/** | ||
* Resolving mechanism. Always starts to search for `maidfile.md` from | ||
* the current working directory to 5 levels upwards (probably enough). | ||
* Then repeats this for `.maidfile.md` (with dot) but 10 levels upwards, | ||
* because who knows, someone may have big folder trees. | ||
* | ||
* Second step. If it can't find the Maid files (above ones) and there is | ||
* no given `--config-path / -c` flag on the CLI it throws with error message | ||
* thrown from the main Maid class constructor. | ||
* | ||
* Third step. If config path is given, it treats that config file | ||
* a bit more specifically, as described in the (current) readme - task names should be | ||
* h3 headers and should have some h2 header, which in turn can also be defined on | ||
* the CLI through the `--section` flag. | ||
* | ||
* @param {Object} opts command line global flags | ||
* @returns {Object} like `{ filepath, tasks }`, coming from parseMarkdown | ||
*/ | ||
module.exports = (opts = {}) => { | ||
let filepath = | ||
find.sync(MAIDFILE, opts.cwd, 5) || find.sync(`.${MAIDFILE}`, opts.cwd, 10) | ||
|
||
// in case when it cannot resolve `maidfile.md` or `.maidfile.md` | ||
// files anywhere upwards, and there is no other file given | ||
// through `--maidfile` flag, then inform that you don't have config file | ||
// or it is invalid eg. `[03:39:50] No config file was found. Stop.` | ||
if (!filepath && opts.maidfile === MAIDFILE) return null | ||
|
||
// otherwise resolve the given file from `--config-path` flag | ||
if (opts.maidfile !== MAIDFILE && opts.maidfile !== `.${MAIDFILE}`) { | ||
filepath = opts.maidfile | ||
} | ||
|
||
const content = fs.readFileSync(filepath, 'utf8') | ||
|
||
return parseMarkdown(content, { section: opts.section, filepath }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
oh.. i forgot that, but it's not needed for
find-file-up
to work it uses the cwd by default anyway.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.
use of the
--cwd
flag is not encouraged anyway, because it also may conflict with other CLIs (#35)