UNPKG

12.5 kBMarkdownView Raw
1<!--#preview-->
2<!--@h1([pkg.name])-->
3# mos
4<!--/@-->
5
6<!--@blockquote([pkg.description])-->
7> A pluggable module that injects content into your markdown files via hidden JavaScript snippets
8<!--/@-->
9
10<!--@shields.flatSquare('npm', 'travis', 'coveralls')-->
11[![NPM version](https://img.shields.io/npm/v/mos.svg?style=flat-square)](https://www.npmjs.com/package/mos) [![Build status for master](https://img.shields.io/travis/zkochan/mos/master.svg?style=flat-square)](https://travis-ci.org/zkochan/mos) [![Test coverage for master](https://img.shields.io/coveralls/zkochan/mos/master.svg?style=flat-square)](https://coveralls.io/r/zkochan/mos?branch=master)
12<!--/@-->
13
14<!--#-->
15
16## Why mos?
17
18- Markdown files are always up to date
19- [Examples are always correct][mos-plugin-example]
20- [Shields (a.k.a. badges) are auto-generated][mos-plugin-shields]
21- Commonly used README sections are auto-generated using info from `package.json`
22- Plugins can be used for tons of additional features
23
24## Preview
25
26The [readme][] you are currently reading uses mos!
27
28<!--@snippet('README.md#preview')-->
29```md
30<!--@h1([pkg.name])-->
31# mos
32<!--/@-->
33
34<!--@blockquote([pkg.description])-->
35> A pluggable module that injects content into your markdown files via hidden JavaScript snippets
36<!--/@-->
37
38<!--@shields.flatSquare('npm', 'travis', 'coveralls')-->
39[![NPM version](https://img.shields.io/npm/v/mos.svg?style=flat-square)](https://www.npmjs.com/package/mos) [![Build status for master](https://img.shields.io/travis/zkochan/mos/master.svg?style=flat-square)](https://travis-ci.org/zkochan/mos) [![Test coverage for master](https://img.shields.io/coveralls/zkochan/mos/master.svg?style=flat-square)](https://coveralls.io/r/zkochan/mos?branch=master)
40<!--/@-->
41```
42<!--/@-->
43
44## Table of Contents
45
46- [Installation](#installation)
47 - [Manual installation](#manual-installation)
48- [Usage](#usage)
49- [CLI Usage](#cli-usage)
50 - [mos](#mos)
51 - [mos test](#mos-test)
52 - [Optional TAP output](#optional-tap-output)
53- [API Usage](#api-usage)
54- [Mos plugins](#mos-plugins)
55- [Who uses mos?](#who-uses-mos)
56- [License](#license)
57- [Dependencies](#dependencies)
58- [Dev Dependencies](#dev-dependencies)
59
60## Installation
61
62Install mos globally:
63
64```sh
65npm i -g mos
66```
67
68Make mos configure your `package.json`:
69
70```sh
71mos --init
72```
73
74Your `package.json` will be updated with some new dependencies and `script` properties:
75
76```json
77{
78 "name": "awesome-package",
79 "scripts": {
80 "test": "mos test",
81 "md": "mos",
82 "?md": "echo \"Update the markdown files\""
83 },
84 "devDependencies": {
85 "mos": "^0.17.0"
86 }
87}
88```
89
90### Manual installation
91
92You can also install mos directly:
93
94```sh
95npm i -D mos
96```
97
98You'll have to configure the `script` property in your `package.json` to use mos (see above).
99
100## Usage
101
102Mos uses a simple templating syntax to execute JavaScript inside markdown files. The result of the JavaScript execution is then inserted into the markdown file.
103
104The 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.
105
106Lets 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:
107
108**README.md**
109
110```md
111<!--@h1([pkg.name])-->
112<!--/@-->
113```
114
115If 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.
116
117Once you've run `mos`, the readme will look like this:
118
119```md
120<!--@h1([pkg.name])-->
121# my-awesome-module
122<!--/@-->
123```
124
125Now 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!
126
127![Happy cat](http://i.imgur.com/JG9BXxe.jpg)
128
129## CLI Usage
130
131### `mos`
132
133Regenerate the markdown files if they are out of date.
134
135### `mos test`
136
137Test 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`.
138
139![](http://i.imgur.com/t6CLmMS.png?1)
140
141#### Optional TAP output
142
143Mos can generate TAP output via `--tap` option for use with any [TAP reporter](https://github.com/sindresorhus/awesome-tap#reporters).
144
145```console
146mos test --tap | tap-nyan
147```
148
149![](http://i.imgur.com/jet4ZAG.png?2)
150
151**NOTE:** the CLI will use your local install of mos when available, even when run globally.
152
153## API Usage
154
155<!--@example('example.js')-->
156Require the package
157
158```js
159const mos = require('mos')
160```
161
162Create a processor and use some mos plugins
163
164```js
165const processor = mos().use(require('mos-plugin-scripts'))
166```
167
168Process raw markdown
169
170```js
171processor.process('# Header', { filePath: 'README.md' })
172 .then(newmd => console.log(newmd))
173 //> # Header
174```
175
176Process a markdown AST
177
178```js
179const m = require('markdownscript')
180const h1 = m.h1
181const p = m.paragraph
182const ast = m.root([
183 h1(['Foo']),
184 p(['Bar qar qax']),
185])
186processor.process(ast, { filePath: 'README.md' })
187 .then(newmd => console.log(newmd))
188 //> # Foo
189 //
190 // Bar qar qax
191```
192<!--/@-->
193
194## Mos plugins
195
196In 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][mos-plugin-package-json] plugin.
197
198There are a few mos plugins that are installed with mos by default:
199
200- [package-json][mos-plugin-package-json]
201- [shields][mos-plugin-shields]
202- [license](https://github.com/zkochan/mos-plugin-license)
203- [installation](https://github.com/zkochan/mos-plugin-installation)
204- [example][mos-plugin-example]
205- [dependencies](https://github.com/zkochan/mos-plugin-dependencies)
206- [snippet](https://github.com/zkochan/mos-plugin-snippet)
207- [table-of-contents](https://github.com/zkochan/remark-toc)
208- [markdownscript](https://github.com/zkochan/mos-plugin-markdownscript)
209
210Do you want to write a new one? Read the [plugins readme](./docs/PLUGINS.md).
211
212## Who uses mos?
213
214- [npm-scripts-info](https://github.com/srph/npm-scripts-info)
215- [magic-hook](https://github.com/zkochan/magic-hook)
216
217<!--@license()-->
218## License
219
220[MIT](./LICENSE) © [Zoltan Kochan](http://kochan.io)
221<!--/@-->
222
223* * *
224
225<!--@dependencies({ shield: 'flat-square' })-->
226## <a name="dependencies">Dependencies</a> [![Dependency status for master](https://img.shields.io/david/zkochan/mos/master.svg?style=flat-square)](https://david-dm.org/zkochan/mos/master)
227
228- [@zkochan/read-pkg-up](https://github.com/zkochan/read-pkg-up): Read the closest package.json file
229- [@zkochan/remark](https://github.com/wooorm/remark): Markdown processor powered by plugins
230- [@zkochan/remark-toc](https://github.com/wooorm/remark-toc): Generate a Table of Contents (TOC) for Markdown files
231- [@zkochan/tap-diff](https://github.com/zkochan/tap-diff): The most human-friendly TAP reporter
232- [async-unist-util-visit](https://github.com/wooorm/unist-util-visit): Recursively walk over unist nodes
233- [chalk](https://github.com/chalk/chalk): Terminal string styling done right. Much color.
234- [file-exists](https://github.com/scottcorgan/file-exists): Check if filepath exists and is a file
235- [github-url-to-object](https://github.com/zeke/github-url-to-object): Extract user, repo, and other interesting properties from GitHub URLs
236- [glob](https://github.com/isaacs/node-glob): a little globber
237- [meow](https://github.com/sindresorhus/meow): CLI app helper
238- [mos-init](https://github.com/zkochan/mos-init): Add mos to your project
239- [mos-plugin-dependencies](https://github.com/zkochan/mos-plugin-dependencies): A mos plugin that creates dependencies sections
240- [mos-plugin-example](https://github.com/zkochan/mos-plugin-example): A mos plugin that combines example code files with their output
241- [mos-plugin-installation](https://github.com/zkochan/mos-plugin-installation): A mos plugin for creating installation section
242- [mos-plugin-license](https://github.com/zkochan/mos-plugin-license): A mos plugin for generating a license section
243- [mos-plugin-markdownscript](https://github.com/zkochan/mos-plugin-markdownscript): A [mos](https://github.com/zkochan/mos) plugin that adds markownscript helpers to the markdown scope
244- [mos-plugin-package-json](https://github.com/zkochan/mos-plugin-package-json): A mos plugin that makes the package.json available in the markdown scope
245- [mos-plugin-shields](https://github.com/zkochan/mos-plugin-shields): A mos plugin for creating markdown shields
246- [mos-plugin-snippet](https://github.com/zkochan/mos-plugin-snippet): A mos plugin for embedding snippets from files
247- [normalize-newline](https://github.com/sindresorhus/normalize-newline): Normalize the newline characters in a string to `\n`
248- [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.
249- [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.
250- [remark-mos](https://github.com/zkochan/remark-mos): Inject parts of markdown via hidden JavaScript snippets
251- [reserved-words](https://github.com/zxqfox/reserved-words): ECMAScript reserved words checker
252- [resolve](https://github.com/substack/node-resolve): resolve like require.resolve() on behalf of files asynchronously and synchronously
253- [run-async](https://github.com/sboudrias/run-async): Utility method to run function either synchronously or asynchronously using the common `this.async()` style.
254- [tape](https://github.com/substack/tape): tap-producing test harness for node and browsers
255- [update-notifier](https://github.com/yeoman/update-notifier): Update notifications for your CLI app
256
257<!--/@-->
258
259<!--@devDependencies({ shield: 'flat-square' })-->
260## <a name="dev-dependencies">Dev Dependencies</a> [![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)
261
262- [chai](https://github.com/chaijs/chai): BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
263- [cz-conventional-changelog](https://github.com/commitizen/cz-conventional-changelog): Commitizen adapter following the conventional-changelog format.
264- [eslint](https://github.com/eslint/eslint): An AST-based pattern checker for JavaScript.
265- [eslint-config-standard](https://github.com/feross/eslint-config-standard): JavaScript Standard Style - ESLint Shareable Config
266- [eslint-plugin-promise](https://github.com/xjamundx/eslint-plugin-promise): Enforce best practices for JavaScript promises
267- [eslint-plugin-standard](https://github.com/xjamundx/eslint-plugin-standard): ESlint Plugin for the Standard Linter
268- [execa](https://github.com/sindresorhus/execa): A better `child_process`
269- [ghooks](https://github.com/gtramontina/ghooks): Simple git hooks
270- [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
271- [markdownscript](https://github.com/zkochan/markdownscript): Creates markdown Abstract Syntax Tree
272- [mocha](https://github.com/mochajs/mocha): simple, flexible, fun test framework
273- [mos-plugin-scripts](https://github.com/zkochan/mos-plugin-scripts): A mos plugin that generates a section with npm scripts descriptions
274- [semantic-release](https://github.com/semantic-release/semantic-release): automated semver compliant package publishing
275- [validate-commit-msg](https://github.com/kentcdodds/validate-commit-msg): Script to validate a commit message follows the conventional changelog standard
276
277<!--/@-->
278
279* * *
280
281**What does mos mean?**
282<br>
283It means _Markdown on Steroids_!
284
285[readme]: https://raw.githubusercontent.com/zkochan/mos/master/README.md
286
287[mos-plugin-package-json]: https://github.com/zkochan/mos-plugin-package-json
288
289[mos-plugin-example]: https://github.com/zkochan/mos-plugin-example
290
291[mos-plugin-shields]: https://github.com/zkochan/mos-plugin-shields