UNPKG

10.6 kBMarkdownView Raw
1<!--@'# ' + package.name-->
2# mos
3<!--/@-->
4
5<!--@'> ' + package.description-->
6> A pluggable module that injects content into your markdown files via hidden JavaScript snippets
7<!--/@-->
8
9<!--@shields.flatSquare('npm', 'travis', 'coveralls')-->
10[![NPM version](https://img.shields.io/npm/v/mos.svg?style=flat-square)](https://www.npmjs.com/package/mos)
11[![Build status for master](https://img.shields.io/travis/zkochan/mos/master.svg?style=flat-square)](https://travis-ci.org/zkochan/mos)
12[![Test coverage for master](https://img.shields.io/coveralls/zkochan/mos/master.svg?style=flat-square)](https://coveralls.io/r/zkochan/mos?branch=master)
13<!--/@-->
14
15## Why mos?
16
17- Markdown files are always up to date
18- [Examples are always correct][mos-plugin-example]
19- [Shields (a.k.a. badges) are auto-generated][mos-plugin-shields]
20- Commonly used README sections are auto-generated using info from `package.json`
21- Plugins can be used for tons of additional features
22
23## Preview
24
25The [readme][] you are currently reading uses mos!
26
27```md
28<!--@'# ' + package.name-->
29# mos
30<!--/@-->
31
32<!--@'> ' + package.description-->
33> A pluggable module that injects content into your markdown files via hidden JavaScript snippets
34<!--/@-->
35
36<!--@shields.flatSquare('npm', 'travis', 'coveralls')-->
37[![NPM version](https://img.shields.io/npm/v/mos.svg?style=flat-square)](https://www.npmjs.com/package/mos)
38[![Build status for master](https://img.shields.io/travis/zkochan/mos/master.svg?style=flat-square)](https://travis-ci.org/zkochan/mos)
39[![Test coverage](https://img.shields.io/coveralls/zkochan/mos.svg?style=flat-square)](https://coveralls.io/r/zkochan/mos?branch=master)
40<!--/@-->
41```
42
43<!--@installation()-->
44## Installation
45
46This module is installed via npm:
47
48``` sh
49npm install mos --save
50```
51<!--/@-->
52
53## Usage
54
55Mos uses a simple templating syntax to execute JavaScript inside markdown files. The result of the JavaScript execution is then inserted into the markdown file.
56
57The great thing is, that the template and the markdown file are actually the same file! The code snippets are written inside markdown comments, which are invisible when reading the generated markdown file.
58
59Lets use mos to write a readme with some dynamic data. Have you ever renamed your package and forgotten to update the readme? Good news! With mos it won't ever happen again:
60
61**README.md**
62
63```md
64<!--@'# ' + package.name-->
65<!--/@-->
66```
67
68If you view your readme now, it will be empty. However, you have the code that can insert the title in your readme. All you have to do now is to run `mos` in a terminal.
69
70Once you've ran `mos`, the readme will look like this:
71
72```md
73<!--@'# ' + package.name-->
74# my-awesome-module
75<!--/@-->
76```
77
78Now your readme has both the code that generates the content and the content itself. However, only the content is visible after the readme is generated to HTML by GitHub or npm. Awesome!
79
80![Happy cat](http://i.imgur.com/JG9BXxe.jpg)
81
82## CLI Usage
83
84### `mos`
85
86Regenerate the markdown files if they are out of date.
87
88### `mos test`
89
90Test the markdown files. Fails if can't generate one of the markdown files or one of the markdown files is out of date. It is recommended to add this command to the `scripts.test` property of `package.json`.
91
92![](http://i.imgur.com/t6CLmMS.png?1)
93
94#### Optional TAP output
95
96Mos can generate TAP output via `--tap` option for use with any [TAP reporter](https://github.com/sindresorhus/awesome-tap#reporters).
97
98```console
99mos test --tap | tap-nyan
100```
101
102![](http://i.imgur.com/jet4ZAG.png?2)
103
104## API Usage
105
106```js
107const mos = require('mos')
108
109const processor = mos()
110 .use(require('mos-plugin-scripts')) // use mos plugins
111 .useRemarkPlugin(require('remark-word-wrap')) // use remark plugins
112
113processor.process('# Header', { filePath: '/home/src/README.md' })
114 .then(newmd => console.log(newmd))
115```
116
117## Mos plugins
118
119In the usage example the `package` variable was used to access the package info. The variables available in the markdown scope are _declared by mos plugins_. The `package` variable is created by the [package-json](./plugins/package-json) plugin.
120
121There are a few mos plugins that are installed with mos by default:
122
123- [package-json](./plugins/mos-plugin-package-json)
124- [shields][mos-plugin-shields]
125- [license](./plugins/mos-plugin-license)
126- [installation](./plugins/mos-plugin-installation)
127- [example][mos-plugin-example]
128- [dependencies](./plugins/mos-plugin-dependencies)
129- [snippet](./plugins/mos-plugin-snippet)
130
131Do you want to write a new one? Read the [plugins readme](./plugins/README.md).
132
133## Remark plugins
134
135Mos uses [remark](https://github.com/wooorm/remark) under the hood and as a consequence, can use remark plugins for processing the markdown files.
136
137These are the remark plugins installed with mos by default:
138
139- [remark-toc](https://github.com/wooorm/remark-toc)
140
141It is possible to extend mos with additional remark plugins, by registering them through a `mosfile.js`.
142
143Lets suppose we want to use [remark-word-wrap](https://www.npmjs.com/package/remark-word-wrap) to wrap the lines of markdown files to a specified width. We can install this remark plugin as a dev dependency and create a `mosfile` in the root directory of the package.
144
145```js
146const wordWrap = require('remark-word-wrap')
147
148module.exports = function (mos) {
149 mos.useRemarkPlugin(wordWrap, { width: 80 })
150}
151```
152
153Next time mos will be run, the markdown files will be processed by the remark plugins registered via mosfile (in this case by remark-word-wrap).
154
155## Who uses mos?
156
157- [magic-hook](https://github.com/zkochan/magic-hook)
158
159<!--@license()-->
160## License
161
162[MIT](./LICENSE) © [Zoltan Kochan](http://kochan.io)
163<!--/@-->
164
165* * *
166
167<!--@dependencies({ shield: 'flat-square' })-->
168## Dependencies [![Dependency status for master](https://img.shields.io/david/zkochan/mos/master.svg?style=flat-square)](https://david-dm.org/zkochan/mos/master)
169
170- [async-unist-util-visit](https://github.com/wooorm/unist-util-visit): Recursively walk over unist nodes
171- [chalk](https://github.com/chalk/chalk): Terminal string styling done right. Much color.
172- [codemo](https://github.com/zkochan/codemo): Embeds console output to the code
173- [file-exists](https://github.com/scottcorgan/file-exists): Check if filepath exists and is a file
174- [github-url-to-object](https://github.com/zeke/github-url-to-object): Extract user, repo, and other interesting properties from GitHub URLs
175- [glob](https://github.com/isaacs/node-glob): a little globber
176- [independent](https://github.com/zkochan/independent): Change relative requires to import actual modules
177- [meow](https://github.com/sindresorhus/meow): CLI app helper
178- [normalize-newline](https://github.com/sindresorhus/normalize-newline): Normalize the newline characters in a string to `\n`
179- [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.
180- [read-pkg-up](https://github.com/sindresorhus/read-pkg-up): Read the closest package.json file
181- [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.
182- [remark](https://github.com/wooorm/remark): Markdown processor powered by plugins
183- [remark-toc](https://github.com/wooorm/remark-toc): Generate a Table of Contents (TOC) for Markdown files
184- [resolve](https://github.com/substack/node-resolve): resolve like require.resolve() on behalf of files asynchronously and synchronously
185- [run-async](https://github.com/sboudrias/run-async): Utility method to run function either synchronously or asynchronously using the common `this.async()` style.
186- [shields](https://github.com/kenany/shields): Generate shields for your current project's README
187- [tap-diff](https://github.com/axross/tap-diff): The most human-friendly TAP reporter
188- [tape](https://github.com/substack/tape): tap-producing test harness for node and browsers
189
190<!--/@-->
191
192<!--@devDependencies({ shield: 'flat-square' })-->
193## Dev Dependencies [![devDependency status for master](https://img.shields.io/david/dev/zkochan/mos/master.svg?style=flat-square)](https://david-dm.org/zkochan/mos/master#info=devDependencies)
194
195- [babel-cli](https://github.com/babel/babel/blob/master/packages): Babel command line.
196- [babel-preset-es2015-rollup](https://npmjs.org/package/babel-preset-es2015-rollup): This is [babel-preset-es2015](http://babeljs.io/docs/plugins/preset-es2015/), minus [modules-commonjs](http://babeljs.io/docs/plugins/transform-es2015-modules-commonjs/), plus [external-helpers](http://babeljs.io/docs/plugins/external-helpers/). Use it wi
197- [chai](https://github.com/chaijs/chai): BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
198- [cz-conventional-changelog](https://github.com/commitizen/cz-conventional-changelog): Commitizen adapter following the conventional-changelog format.
199- [eslint](https://github.com/eslint/eslint): An AST-based pattern checker for JavaScript.
200- [eslint-config-standard](https://github.com/feross/eslint-config-standard): JavaScript Standard Style - ESLint Shareable Config
201- [eslint-plugin-promise](https://github.com/xjamundx/eslint-plugin-promise): Enforce best practices for JavaScript promises
202- [eslint-plugin-standard](https://github.com/xjamundx/eslint-plugin-standard): ESlint Plugin for the Standard Linter
203- [execa](https://github.com/sindresorhus/execa): A better `child_process`
204- [ghooks](https://github.com/gtramontina/ghooks): Simple git hooks
205- [istanbul](https://github.com/gotwarlost/istanbul): Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests
206- [mocha](https://github.com/mochajs/mocha): simple, flexible, fun test framework
207- [semantic-release](https://github.com/semantic-release/semantic-release): automated semver compliant package publishing
208- [validate-commit-msg](https://github.com/kentcdodds/validate-commit-msg): Script to validate a commit message follows the conventional changelog standard
209
210<!--/@-->
211
212* * *
213
214**What does mos mean?**
215<br>
216It means _Markdown on Steroids_!
217
218[readme]: https://raw.githubusercontent.com/zkochan/mos/master/README.md
219
220[mos-plugin-example]: ./plugins/mos-plugin-example
221
222[mos-plugin-shields]: ./plugins/mos-plugin-shields