forked from egoist/maid
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add `yarn maid` script - add implementations of egoist#36 - replace occurances pf `node bin/cli` with `yarn maid` because it uses the --maidfile flag Signed-off-by: Charlike Mike Reagent <[email protected]>
- Loading branch information
Charlike Mike Reagent
committed
Jun 6, 2018
1 parent
6fe8bcf
commit 752f1ca
Showing
5 changed files
with
100 additions
and
18 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ | |
"lib" | ||
], | ||
"scripts": { | ||
"test": "node bin/cli lint && node bin/cli test" | ||
"maid": "node bin/cli --maidfile README.md", | ||
"test": "yarn maid lint && yarn maid test" | ||
}, | ||
"author": "egoist <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -22,6 +23,7 @@ | |
"chalk": "^2.4.1", | ||
"cross-spawn": "^6.0.5", | ||
"fancy-log": "^1.3.2", | ||
"find-file-up": "^2.0.1", | ||
"joycon": "^1.0.4", | ||
"markdown-it": "^8.4.1", | ||
"micromatch": "^3.1.10", | ||
|
@@ -58,11 +60,11 @@ | |
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"node bin/cli lint --fix", | ||
"yarn maid lint --fix", | ||
"git add" | ||
], | ||
"README.md": [ | ||
"node bin/cli toc", | ||
"yarn maid toc", | ||
"git add" | ||
] | ||
} | ||
|
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