Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mbackonja committed Aug 15, 2017
0 parents commit 1e0d2ae
Show file tree
Hide file tree
Showing 33 changed files with 12,557 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"presets": [
[
"env",
{
"targets": {
"browsers": [
"last 2 versions"
]
}
}
]
],
"plugins": [
"transform-vue-jsx",
"transform-object-rest-spread"
],
"env": {
"test": {
"plugins": [
"istanbul"
]
}
}
}
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/*.js
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
extends: 'vue',
// add your custom rules here
'rules': {
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
},
globals: {
requestAnimationFrame: true,
performance: true
}
}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
node_modules/
npm-debug.log
test/coverage
dist
yarn-error.log
reports
7 changes: 7 additions & 0 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"processors": ["stylelint-processor-html"],
"extends": "stylelint-config-standard",
"rules": {
"no-empty-source": null
}
}
36 changes: 36 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

We accept contributions via Pull Requests on [Github](https://github.com/mbackonja/vue-simple-markdown).


## Pull Requests

- **Keep the same style** - eslint will automatically be ran before committing

- **Tip** to pass lint tests easier use the `npm run lint:fix` command

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

- **Create feature branches** - Don't ask us to pull from your master branch.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure your commits message means something


## Running Tests

Launch visual tests and watch the components at the same time

``` bash
$ npm run dev
```


**Happy coding**!
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2017 Milan Bačkonja

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.
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# VueSimpleMarkdown

[![npm](https://img.shields.io/npm/v/vue-simple-markdown.svg)](https://www.npmjs.com/package/vue-simple-markdown) [![vue2](https://img.shields.io/badge/vue-2.x-brightgreen.svg)](https://vuejs.org/)

> A Simple and Highspeed Markdown Parser for Vue
## Installation

```bash
npm install --save vue-simple-markdown
```

## Usage

### Bundler (Webpack, Rollup)

```js
import Vue from 'vue'
import VueSimpleMarkdown from 'vue-simple-markdown'
// You need a specific loader for CSS files like https://github.com/webpack/css-loader
import 'vue-simple-markdown/dist/vue-simple-markdown.css'

Vue.use(VueSimpleMarkdown)
```

### Browser

```html
<!-- Include after Vue -->
<!-- Local files -->
<link rel="stylesheet" href="vue-simple-markdown/dist/vue-simple-markdown.css"></link>
<script src="vue-simple-markdown/dist/vue-simple-markdown.js"></script>

<!-- From CDN -->
<link rel="stylesheet" href="https://unpkg.com/vue-simple-markdown/dist/vue-simple-markdown.css"></link>
<script src="https://unpkg.com/vue-simple-markdown"></script>
```

## Development

### Launch visual tests

```bash
npm run dev
```

### Launch Karma with coverage

```bash
npm run dev:coverage
```

### Build

Bundle the js and css of to the `dist` folder:

```bash
npm run build
```


## Publishing

The `prepublish` hook will ensure dist files are created before publishing. This
way you don't need to commit them in your repository.

```bash
# Bump the version first
# It'll also commit it and create a tag
npm version
# Push the bumped package and tags
git push --follow-tags
# Ship it 🚀
npm publish
```

## License

[MIT](http://opensource.org/licenses/MIT)
66 changes: 66 additions & 0 deletions build/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const { join } = require('path')

const {
red,
logError
} = require('./log')

const {
processStyle
} = require('./style')

const uppercamelcase = require('uppercamelcase')

exports.write = require('./write')

const {
author,
name,
version,
dllPlugin
} = require('../../package.json')

const authorName = author.replace(/\s+<.*/, '')
const minExt = process.env.NODE_ENV === 'production' ? '.min' : ''

exports.author = authorName
exports.version = version
exports.dllName = dllPlugin.name
exports.moduleName = uppercamelcase(name)
exports.name = name
exports.filename = name + minExt
exports.banner = `/*!
* ${name} v${version}
* (c) ${new Date().getFullYear()} ${authorName}
* Released under the MIT License.
*/
`

// log.js
exports.red = red
exports.logError = logError

// It'd be better to add a sass property to the vue-loader options
// but it simply don't work
const sassOptions = {
includePaths: [
join(__dirname, '../../node_modules')
]
}

// don't extract css in test mode
const nullLoader = process.env.NODE_ENV === 'common' ? 'null-loader!' : ''
exports.vueLoaders =
process.env.BABEL_ENV === 'test' ? {
css: 'css-loader',
scss: `css-loader!sass-loader?${JSON.stringify(sassOptions)}`
} : {
css: ExtractTextPlugin.extract(`${nullLoader}css-loader`),
scss: ExtractTextPlugin.extract(
`${nullLoader}css-loader!sass-loader?${JSON.stringify(sassOptions)}`
)
}

// style.js
exports.processStyle = processStyle
27 changes: 27 additions & 0 deletions build/utils/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function logError (e) {
console.log(e)
}

function blue (str) {
return `\x1b[1m\x1b[34m${str}\x1b[39m\x1b[22m`
}

function green (str) {
return `\x1b[1m\x1b[32m${str}\x1b[39m\x1b[22m`
}

function red (str) {
return `\x1b[1m\x1b[31m${str}\x1b[39m\x1b[22m`
}

function yellow (str) {
return `\x1b[1m\x1b[33m${str}\x1b[39m\x1b[22m`
}

module.exports = {
blue,
green,
red,
yellow,
logError
}
66 changes: 66 additions & 0 deletions build/utils/style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const path = require('path')
const postcss = require('postcss')
const cssnext = require('postcss-cssnext')
const CleanCSS = require('clean-css')
const { logError } = require('./log.js')
const write = require('./write.js')

function processCss (style) {
const componentName = path.basename(style.id, '.vue')
return postcss([cssnext()])
.process(style.code, {})
.then(result => {
return {
name: componentName,
css: result.css,
map: result.map
}
})
}

let stylus
function processStylus (style) {
try {
stylus = stylus || require('stylus')
} catch (e) {
logError(e)
}
const componentName = path.basename(style.id, '.vue')
return new Promise((resolve, reject) => {
stylus.render(style.code, function (err, css) {
if (err) return reject(err)
resolve({
original: {
code: style.code,
ext: 'styl'
},
name: componentName,
css
})
})
})
}

function processStyle (style) {
if (style.lang === 'css') {
return processCss(style)
} else if (style.lang === 'stylus') {
return processStylus(style)
} else {
throw new Error(`Unknown style language '${style.lang}'`)
}
}

function writeCss (style) {
write(`dist/${style.name}.css`, style.css)
if (style.original) {
write(`dist/${style.name}.${style.original.ext}`, style.original.code)
}
if (style.map) write(`dist/${style.name}.css.map`, style.map)
write(`dist/${style.name}.min.css`, new CleanCSS().minify(style.css).styles)
}

module.exports = {
writeCss,
processStyle
}
19 changes: 19 additions & 0 deletions build/utils/write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require('fs')

const { blue } = require('./log.js')

function write (dest, code) {
return new Promise(function (resolve, reject) {
fs.writeFile(dest, code, function (err) {
if (err) return reject(err)
console.log(blue(dest) + ' ' + getSize(code))
resolve(code)
})
})
}

function getSize (code) {
return (code.length / 1024).toFixed(2) + 'kb'
}

module.exports = write
Loading

0 comments on commit 1e0d2ae

Please sign in to comment.