Skip to content

Commit

Permalink
ES6ify and add eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
cognitom committed Nov 25, 2016
1 parent 33ec6df commit bc737e6
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 93 deletions.
20 changes: 20 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,20 @@
{
"env": {
"mocha": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"eqeqeq": ["error", "smart"],
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"no-cond-assign": "off",
"no-console": "off",
"no-unexpected-multiline": "error",
"quotes": ["error", "single", "avoid-escape"],
"semi": ["error", "never"]
}
}
6 changes: 1 addition & 5 deletions .travis.yml
@@ -1,9 +1,5 @@
---
language: node_js
node_js:
- '0.10'
script:
- npm install
- npm test
- '4.*'
notifications:
email: false
29 changes: 16 additions & 13 deletions index.js
@@ -1,23 +1,26 @@
var through = require('through');
var riot = require('riot');
var preamble = "var riot = require('riot');\n";
'use strict'

const through = require('through')
const compiler = require('riot-compiler')
const preamble = "var riot = require('riot');\n"

module.exports = function (file, o) {
var opts = o || {};
var ext = opts.ext || 'tag';
var content = '';
const opts = o || {}
const ext = opts.ext || 'tag'
let content = ''

return !file.match('\.' + ext + '$') ? through() : through(
return !file.match(`\.${ ext }$`) ? through() : through(
function (chunk) { // write
content += chunk.toString();
content += chunk.toString()
},
function () { // end
try {
this.queue(preamble + 'module.exports = ' + riot.compile(content, opts, file));
this.emit('end');
const compiled = compiler.compile(content, opts, file)
this.queue(`${ preamble }module.exports = ${ compiled }`)
this.emit('end')
} catch (e) {
this.emit('error', e);
this.emit('error', e)
}
}
);
};
)
}
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -9,11 +9,14 @@
},
"devDependencies": {
"concat-stream": "^1.4.0",
"eslint": "^3.10.2",
"module-deps": "^3.6.0",
"tape": "^2.12.1"
},
"scripts": {
"test": "tape test/*.js"
"test": "npm run eslint && npm run tape",
"tape": "tape test/*.js",
"eslint": "eslint index.js test/*.js"
},
"repository": {
"type": "git",
Expand Down
148 changes: 74 additions & 74 deletions test/compile.js
@@ -1,89 +1,89 @@
var test = require('tape');
var concat = require('concat-stream');
var moduleDeps = require('module-deps');
var path = require('path');
var riotify = require('../');
const test = require('tape')
const concat = require('concat-stream')
const moduleDeps = require('module-deps')
const path = require('path')
const riotify = require('../')

test('ignore', function (t) {
var file = path.join(__dirname, 'ignore.ext');
var p = moduleDeps();
test('ignore', t => {
const file = path.join(__dirname, 'ignore.ext')
const p = moduleDeps()

p.write({ transform: riotify, options: {} });
p.write({ file: file, id: file, entry: true });
p.end();
p.write({ transform: riotify, options: {} })
p.write({ file, id: file, entry: true })
p.end()

t.plan(3);
p.pipe(concat(function (out) {
t.ok(out[0], 'got output element');
t.ok(out[0].source.length, 'got output element with source');
t.ok(out[0].source.match(/^<todo>/), 'skipped ignore.ext');
}));
});
t.plan(3)
p.pipe(concat(out => {
t.ok(out[0], 'got output element')
t.ok(out[0].source.length, 'got output element with source')
t.ok(out[0].source.match(/^<todo>/), 'skipped ignore.ext')
}))
})

test('compile', function (t) {
var file = path.join(__dirname, 'todo.tag');
var p = moduleDeps();
test('compile', t => {
const file = path.join(__dirname, 'todo.tag')
const p = moduleDeps()

p.write({ transform: riotify, options: {} });
p.write({ file: file, id: file, entry: true });
p.end();
p.write({ transform: riotify, options: {} })
p.write({ file, id: file, entry: true })
p.end()

t.plan(6);
p.pipe(concat(function (out) {
t.is(out.length, 2, 'got two files as output');
t.ok(out[0].id.match(/riot\.js$/), 'out.0 is riot.js');
t.ok(out[0].source.match(/module.exports/), 'riot.js');
t.ok(out[1].id.match(/todo\.tag$/), 'out.1 is todo.tag');
t.ok(out[1].source.match(/var riot = require\('riot'\);/), 'require riot');
t.ok(out[1].source.match(/riot.tag2\(.*todo/), 'compiled compile.tag');
}));
});
t.plan(6)
p.pipe(concat(out => {
t.is(out.length, 2, 'got two files as output')
t.ok(out[0].id.match(/riot\.js$/), 'out.0 is riot.js')
t.ok(out[0].source.match(/module.exports/), 'riot.js')
t.ok(out[1].id.match(/todo\.tag$/), 'out.1 is todo.tag')
t.ok(out[1].source.match(/var riot = require\('riot'\);/), 'require riot')
t.ok(out[1].source.match(/riot.tag2\(.*todo/), 'compiled compile.tag')
}))
})

test('compile-custom-ext', function (t) {
var file = path.join(__dirname, 'customext.html');
var p = moduleDeps();
test('compile-custom-ext', t => {
const file = path.join(__dirname, 'customext.html')
const p = moduleDeps()

p.write({ transform: riotify, options: {ext: "html"} });
p.write({ file: file, id: file, entry: true });
p.end();
p.write({ transform: riotify, options: {ext: 'html'} })
p.write({ file, id: file, entry: true })
p.end()

t.plan(6);
p.pipe(concat(function (out) {
t.is(out.length, 2, 'got two files as output');
t.ok(out[0].id.match(/riot\.js$/), 'out.0 is riot.js');
t.ok(out[0].source.match(/module.exports/), 'riot.js');
t.ok(out[1].id.match(/customext\.html$/), 'out.1 is customext.html');
t.ok(out[1].source.match(/var riot = require\('riot'\);/), 'require riot');
t.ok(out[1].source.match(/riot.tag2\(.*customext/), 'compiled compile.tag');
}));
});
t.plan(6)
p.pipe(concat(out => {
t.is(out.length, 2, 'got two files as output')
t.ok(out[0].id.match(/riot\.js$/), 'out.0 is riot.js')
t.ok(out[0].source.match(/module.exports/), 'riot.js')
t.ok(out[1].id.match(/customext\.html$/), 'out.1 is customext.html')
t.ok(out[1].source.match(/var riot = require\('riot'\);/), 'require riot')
t.ok(out[1].source.match(/riot.tag2\(.*customext/), 'compiled compile.tag')
}))
})

test('compile-custom-ext-ignore', function (t) {
var file = path.join(__dirname, 'todo.tag');
var p = moduleDeps();
test('compile-custom-ext-ignore', t => {
const file = path.join(__dirname, 'todo.tag')
const p = moduleDeps()

p.write({ transform: riotify, options: {ext: "html"} });
p.write({ file: file, id: file, entry: true });
p.end();
p.write({ transform: riotify, options: {ext: 'html'} })
p.write({ file, id: file, entry: true })
p.end()

t.plan(3);
p.pipe(concat(function (out) {
t.ok(out[0], 'got output element');
t.ok(out[0].source.length, 'got output element with source');
t.ok(out[0].source.match(/^<todo>/), 'skipped todo.tag');
}));
});
t.plan(3)
p.pipe(concat(out => {
t.ok(out[0], 'got output element')
t.ok(out[0].source.length, 'got output element with source')
t.ok(out[0].source.match(/^<todo>/), 'skipped todo.tag')
}))
})

test('module exports riot tag', function (t) {
var file = path.join(__dirname, 'todo.tag');
var p = moduleDeps();
test('module exports riot tag', t => {
const file = path.join(__dirname, 'todo.tag')
const p = moduleDeps()

p.write({ transform: riotify });
p.write({ file: file, id: file, entry: true });
p.end();
p.write({ transform: riotify })
p.write({ file, id: file, entry: true })
p.end()

t.plan(1);
p.pipe(concat(function (out) {
t.ok(out[1].source.match(/module.exports = riot.tag2/), 'riot tag');
}));
});
t.plan(1)
p.pipe(concat(out => {
t.ok(out[1].source.match(/module.exports = riot.tag2/), 'riot tag')
}))
})

0 comments on commit bc737e6

Please sign in to comment.