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

Commit

Permalink
feat: create package
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed May 13, 2016
0 parents commit d5cec7f
Show file tree
Hide file tree
Showing 14 changed files with 363 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
@@ -0,0 +1,7 @@
{
"extends": "standard",
"rules": {
"comma-dangle": [2, "always-multiline"],
"arrow-parens": [2, "as-needed"]
}
}
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* text eol=lf
33 changes: 33 additions & 0 deletions .gitignore
@@ -0,0 +1,33 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
node_modules

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
17 changes: 17 additions & 0 deletions .travis.yml
@@ -0,0 +1,17 @@
language: node_js
sudo: false
node_js:
- v4

cache:
directories:
- node_modules

before_install:
- npm install -g npm@3
install:
- npm install

after_success:
- npm run coveralls
- npm run semantic-release
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Zoltan Kochan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
66 changes: 66 additions & 0 deletions README.md
@@ -0,0 +1,66 @@
<!--@'# ' + pkg.name-->
# mos-processor
<!--/@-->

<!--@'> ' + pkg.description-->
> A markdown processor for mos
<!--/@-->
<!--@shields.flatSquare('npm', 'travis', 'coveralls')-->
[![NPM version](https://img.shields.io/npm/v/mos-processor.svg?style=flat-square)](https://www.npmjs.com/package/mos-processor) [![Build status for master](https://img.shields.io/travis/zkochan/mos-processor/master.svg?style=flat-square)](https://travis-ci.org/zkochan/mos-processor) [![Test coverage for master](https://img.shields.io/coveralls/zkochan/mos-processor/master.svg?style=flat-square)](https://coveralls.io/r/zkochan/mos-processor?branch=master)
<!--/@-->

<!--@installation()-->
## Installation

```sh
npm install --save mos-processor
```
<!--/@-->

## Usage

```js
const mosProcessor = require('mos-processor')
```

<!--@license()-->
## License

[MIT](./LICENSE) © [Zoltan Kochan](http://kochan.io)
<!--/@-->

* * *

<!--@dependencies({ shield: 'flat-square' })-->
## <a name="dependencies">Dependencies</a> [![Dependency status for master](https://img.shields.io/david/zkochan/mos-processor/master.svg?style=flat-square)](https://david-dm.org/zkochan/mos-processor/master)

- [@zkochan/read-pkg-up](https://github.com/zkochan/read-pkg-up): Read the closest package.json file
- [github-url-to-object](https://github.com/zeke/github-url-to-object): Extract user, repo, and other interesting properties from GitHub URLs
- [magic-hook](https://github.com/zkochan/magic-hook): Extends functions with pre hooks.
- [mos-core](https://github.com/zkochan/mos-core): Markdown parser
- [remi](https://github.com/remijs/remi): A plugin registrator.
- [remi-runner](https://github.com/remijs/remi-runner): A remi extension that allows registering plugins that are returning promises during their registration or are registered synchronously
- [vfile](https://github.com/wooorm/vfile): Virtual file format for text processing

<!--/@-->

<!--@devDependencies({ shield: 'flat-square' })-->
## <a name="dev-dependencies">Dev Dependencies</a> [![devDependency status for master](https://img.shields.io/david/dev/zkochan/mos-processor/master.svg?style=flat-square)](https://david-dm.org/zkochan/mos-processor/master#info=devDependencies)

- [chai](https://github.com/chaijs/chai): BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
- [cz-conventional-changelog](https://github.com/commitizen/cz-conventional-changelog): Commitizen adapter following the conventional-changelog format.
- [eslint](https://github.com/eslint/eslint): An AST-based pattern checker for JavaScript.
- [eslint-config-standard](https://github.com/feross/eslint-config-standard): JavaScript Standard Style - ESLint Shareable Config
- [eslint-plugin-promise](https://github.com/xjamundx/eslint-plugin-promise): Enforce best practices for JavaScript promises
- [eslint-plugin-standard](https://github.com/xjamundx/eslint-plugin-standard): ESlint Plugin for the Standard Linter
- [ghooks](https://github.com/gtramontina/ghooks): Simple git hooks
- [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
- [markdownscript](https://github.com/zkochan/markdownscript): Creates markdown Abstract Syntax Tree
- [mocha](https://github.com/mochajs/mocha): simple, flexible, fun test framework
- [mos](https://github.com/zkochan/mos): A pluggable module that injects content into your markdown files via hidden JavaScript snippets
- [plugiator](https://github.com/zkochan/plugiator): hapi plugins creator
- [semantic-release](https://github.com/semantic-release/semantic-release): automated semver compliant package publishing
- [validate-commit-msg](https://github.com/kentcdodds/validate-commit-msg): Script to validate a commit message follows the conventional changelog standard

<!--/@-->
47 changes: 47 additions & 0 deletions index.js
@@ -0,0 +1,47 @@
'use strict'
const mosCore = require('mos-core')
const remi = require('remi')
const hook = require('magic-hook')
const VFile = require('vfile')
const getMarkdownMeta = require('./lib/get-markdown-meta')

module.exports = function mos (md, plugins) {
plugins = plugins || []
const defaultOpts = {
listItemIndent: '1',
}
const processor = {
inlineTokenizers: mosCore.inlineTokenizers.slice(),
blockTokenizers: mosCore.blockTokenizers.slice(),
visitors: Object.assign({}, mosCore.visitors),
parse: hook(opts => {
return mosCore.parser({
inlineTokenizers: processor.inlineTokenizers,
blockTokenizers: processor.blockTokenizers,
data: mosCore.data,
})(md.vfile, opts)
}),
compile: hook((ast, opts) => {
return Promise.resolve(mosCore.compiler(processor.visitors)(ast, opts))
}),
process: opts => processor
.parse(Object.assign(md, {vfile: new VFile(md.content)}), opts || defaultOpts)
.then(ast => {
return processor.compile(ast, opts || defaultOpts)
}),
}

const register = createRegister(processor)

return getMarkdownMeta(md.filePath)
.then(meta => register(plugins.map(plugin => ({ register: plugin, options: Object.assign({}, md, meta) }))))
.then(() => processor)
}

function createRegister (processor) {
const registrator = remi(processor)
registrator.hook(
require('remi-runner')()
)
return registrator.register
}
36 changes: 36 additions & 0 deletions index.spec.js
@@ -0,0 +1,36 @@
'use strict'
const describe = require('mocha').describe
const it = require('mocha').it
const expect = require('chai').expect
const m = require('markdownscript')
const mos = require('.')
const plugiator = require('plugiator')

describe('mos', () => {
describe.skip('use', () => {
it('should register mos plugin', done => {
const processor = mos().use(md => ({ foo: 'foo' }))
return processor.process('<!--@foo--><!--/@-->', {filePath: __filename})
.then(newmd => {
expect(newmd).to.eq('<!--@foo-->\nfoo\n<!--/@-->\n')
done()
})
.catch(done)
})
})

it.skip('should process AST', done => {
const ast = m('markdownScript', { code: 'foo' }, [])
const processor = mos()
return processor
.register([
plugiator.anonymous(mos => mos.extendScope(md => ({ foo: 'foo' }))),
])
.then(() => processor.process(ast, {filePath: __filename}))
.then(newmd => {
expect(newmd).to.eq('<!--@foo-->\nfoo\n<!--/@-->')
done()
})
.catch(done)
})
})
22 changes: 22 additions & 0 deletions lib/get-markdown-meta/index.js
@@ -0,0 +1,22 @@
'use strict'
module.exports = getMarkdownMeta

const readPkgUp = require('@zkochan/read-pkg-up')
const gh = require('github-url-to-object')
const path = require('path')

function getMarkdownMeta (filePath) {
return readPkgUp({cwd: filePath})
.then(result => {
const pkg = result.pkg

if (!pkg) return {}

return {
pkg,
pkgRoot: path.dirname(result.path),
repo: pkg.repository && pkg.repository.url && gh(pkg.repository.url),
}
})
.then(opts => Object.assign(opts, {filePath}))
}
29 changes: 29 additions & 0 deletions lib/get-markdown-meta/index.spec.js
@@ -0,0 +1,29 @@
'use strict'
const describe = require('mocha').describe
const it = require('mocha').it
const expect = require('chai').expect
const path = require('path')

const getMarkdownMeta = require('.')

describe('getMarkdownMeta', () => {
it('should return case-sensitive repo slug', () => {
return getMarkdownMeta(path.resolve(__dirname, './test/case-sensitive/README.md'))
.then(opts => {
expect(opts.repo.user).to.eq('SomE')
expect(opts.repo.repo).to.eq('RePo')
})
})

it('should return markdown meta', () => {
const filePath = path.resolve(__dirname, './test/package/README.md')
return getMarkdownMeta(filePath)
.then(opts => {
expect(opts.pkg.name).to.eq('foo')
expect(opts.pkgRoot).to.match(/test\/package/)
expect(opts.filePath).to.eq(filePath)
expect(opts.repo.user).to.eq('foo')
expect(opts.repo.repo).to.eq('bar')
})
})
})
3 changes: 3 additions & 0 deletions lib/get-markdown-meta/test/case-sensitive/package.json
@@ -0,0 +1,3 @@
{
"repository": "SomE/RePo"
}
4 changes: 4 additions & 0 deletions lib/get-markdown-meta/test/package/package.json
@@ -0,0 +1,4 @@
{
"name": "foo",
"repository": "foo/bar"
}
76 changes: 76 additions & 0 deletions package.json
@@ -0,0 +1,76 @@
{
"name": "mos-processor",
"version": "0.0.0-placeholder",
"description": "A markdown processor for mos",
"files": [
"index.js",
"lib/"
],
"main": "index.js",
"scripts": {
"test": "mocha && npm run lint && mos test",
"lint": "eslint lib/**/*.js index.js",
"commit": "git-cz",
"coverage": "istanbul cover -x \"**/*.spec.js\" node_modules/mocha/bin/_mocha -- -R spec",
"precoveralls": "istanbul cover -x \"**/*.spec.js\" node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && npm i coveralls@2",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"postcoveralls": "rm -rf ./coverage",
"md": "mos",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"repository": {
"type": "git",
"url": "https://github.com/zkochan/mos-processor"
},
"keywords": [
"mos",
"markdown"
],
"author": {
"name": "Zoltan Kochan",
"email": "zoltan.kochan@gmail.com",
"url": "http://kochan.io"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/zkochan/mos-processor/issues"
},
"homepage": "https://github.com/zkochan/mos-processor#readme",
"dependencies": {
"@zkochan/read-pkg-up": "^1.0.2",
"github-url-to-object": "^2.2.1",
"magic-hook": "^1.0.0",
"mos-core": "0.0.0",
"remi": "^1.0.0",
"remi-runner": "^1.0.0",
"vfile": "^1.4.0"
},
"devDependencies": {
"chai": "^3.4.1",
"cz-conventional-changelog": "1.1.5",
"eslint": "^2.9.0",
"eslint-config-standard": "^5.3.0",
"eslint-plugin-promise": "^1.1.0",
"eslint-plugin-standard": "^1.3.2",
"ghooks": "^1.2.1",
"istanbul": "^0.4.2",
"markdownscript": "^1.1.0",
"mocha": "^2.3.4",
"mos": "^0.17.0",
"plugiator": "^0.1.1",
"semantic-release": "^4.3.5",
"validate-commit-msg": "^2.6.1"
},
"engines": {
"node": ">=4"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
},
"ghooks": {
"commit-msg": "node ./node_modules/validate-commit-msg/index.js",
"pre-commit": "npm test"
}
}
}
1 change: 1 addition & 0 deletions test/mocha.opts
@@ -0,0 +1 @@
{lib/**/*,index}.spec.js

0 comments on commit d5cec7f

Please sign in to comment.