Skip to content
This repository has been archived by the owner on Nov 3, 2019. It is now read-only.

Commit

Permalink
feat: support different methods of configuring mos
Browse files Browse the repository at this point in the history
Use rcfile to support configs via package.json, yaml, json and js files.
  • Loading branch information
zkochan committed May 29, 2016
1 parent f4c4618 commit 1b9a732
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ To disable a default plugin, pass `false` instead of a config object:
- [mos-processor](https://github.com/mosjs/mos-processor): A markdown processor for mos
- [normalize-newline](https://github.com/sindresorhus/normalize-newline): Normalize the newline characters in a string to `\n`
- [normalize-path](https://github.com/jonschlinkert/normalize-path): Normalize file path slashes to be unix-like forward slashes. Also condenses repeat slashes to a single slash and removes and trailing slashes.
- [rcfile](https://github.com/zkochan/rcfile): Loads library configuration in all possible ways
- [relative](https://github.com/jonschlinkert/relative): Get the relative filepath from path A to path B. Calculates from file-to-directory, file-to-file, directory-to-file, and directory-to-directory.
- [resolve](https://github.com/substack/node-resolve): resolve like require.resolve() on behalf of files asynchronously and synchronously
- [tape](https://github.com/substack/tape): tap-producing test harness for node and browsers
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"scripts": {
"commit": "git-cz",
"md:test": "bin/mos.js test -x=\"src/test-cli/**\"",
"md:test": "bin/mos.js test -x=\"**/test-cli/**\"",
"lint": "eslint src/ bin/",
"test:code": "mocha --compilers js:babel-register",
"pretest": "npm run transpile",
Expand All @@ -25,7 +25,7 @@
"precoveralls": "istanbul cover -x \"**/*.spec.js\" node_modules/mocha/bin/_mocha --report lcovonly -- --compilers js:babel-register -R spec && npm i coveralls@2",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"postcoveralls": "rm -rf ./coverage",
"md": "bin/mos.js -x=\"src/test-cli/**\"",
"md": "bin/mos.js -x=\"**/test-cli/**\"",
"prepublish": "npm run transpile",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"transpile": "babel src --out-dir dist"
Expand Down Expand Up @@ -82,6 +82,7 @@
"mos-processor": "^1.2.0",
"normalize-newline": "~2.0.0",
"normalize-path": "~2.0.1",
"rcfile": "^1.0.2",
"relative": "~3.0.2",
"resolve": "~1.1.7",
"tape": "~4.5.1",
Expand Down
13 changes: 7 additions & 6 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const path = require('path')
const test = require('tape')
const tapDiff = require('@zkochan/tap-diff')
const readPkgUp = require('@zkochan/read-pkg-up')
const rcfile = require('rcfile')
const mos = require('mos-processor')
const defaultPlugins = require('./default-plugins')
const resolve = require('resolve')
Expand Down Expand Up @@ -58,13 +59,13 @@ if (cli.flags.init) {

const processMD = md => readPkgUp({ cwd: md.filePath })
.then(result => {
const pkg = result.pkg
const config = rcfile('mos', { cwd: path.dirname(md.filePath) })
const allDeps = new Set(Object
.keys(result.pkg.dependencies || {})
.concat(Object.keys(result.pkg.devDependencies || {})))
.keys(pkg.dependencies || {})
.concat(Object.keys(pkg.devDependencies || {})))

result.pkg.mos = result.pkg.mos || {}

const pkgPlugins = (result.pkg.mos.plugins || [])
const pkgPlugins = (config.plugins || [])
.map(plugin => plugin instanceof Array
? { name: plugin[0], options: plugin[1] || {} }
: { name: plugin, options: {} }
Expand All @@ -85,7 +86,7 @@ if (cli.flags.init) {

const defaultPluginsWithOpts = defaultPlugins.reduce((defPlugins, defPlugin) => {
const defPluginName = defPlugin.attributes.pkg && defPlugin.attributes.pkg.name || defPlugin.attributes.name
const options = result.pkg.mos[defPluginName] || result.pkg.mos[defPluginName.replace(/^mos-plugin-/, '')]
const options = config[defPluginName] || config[defPluginName.replace(/^mos-plugin-/, '')]
if (options === false) {
return defPlugins
}
Expand Down

0 comments on commit 1b9a732

Please sign in to comment.