Skip to content

Commit

Permalink
Add sources plugin, remove obsolete handler map.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpfs committed Jul 17, 2016
1 parent 0ec6042 commit d71849b
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 23 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"cheerio": "~0.20.0",
"merge": "~1.2.0",
"trucks-plugin-sources": "*",
"trucks-plugin-load": "*",
"trucks-plugin-parse": "*",
"trucks-plugin-transform": "*",
Expand Down
58 changes: 58 additions & 0 deletions packages/plugin-sources/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Sources

> Reads the component tree
Combines the load and parse plugins to read the full component tree.

## Install

```
npm i trucks-plugin-load --save-dev
```

For the command line interface see [trucks-cli][].

---

- [Install](#install)
- [Usage](#usage)
- [License](#license)

---

## Usage

This plugin is bundled with the core library.

For command line usage see [trucks-cli][].

## License

MIT

---

Created by [mkdoc](https://github.com/mkdoc/mkdoc) on July 17, 2016

[trucks]: https://github.com/tmpfs/trucks
[trucks-cli]: https://github.com/tmpfs/trucks/blob/master/packages/trucks-cli
[skatejs]: https://github.com/skatejs/skatejs
[webcomponents]: https://github.com/w3c/webcomponents
[shadow-dom]: https://w3c.github.io/webcomponents/spec/shadow/
[custom-elements]: https://www.w3.org/TR/custom-elements/
[html-imports]: https://w3c.github.io/webcomponents/spec/imports/
[html-templates]: https://html.spec.whatwg.org/multipage/scripting.html#the-template-element
[polymer]: https://www.polymer-project.org/1.0/
[react]: https://facebook.github.io/react/
[react-webcomponents]: https://github.com/facebook/react/issues/5052
[react-integration]: https://github.com/skatejs/react-integration
[mozilla-webcomponents]: https://hacks.mozilla.org/2014/12/mozilla-and-web-components/
[csp]: http://content-security-policy.com/
[npm]: https://www.npmjs.com/
[postcss]: https://github.com/postcss/postcss
[mkdoc]: https://github.com/mkdoc/mkdoc
[mkapi]: https://github.com/mkdoc/mkapi
[mkparse]: https://github.com/mkdoc/mkparse
[jshint]: http://jshint.com
[jscs]: http://jscs.info

17 changes: 17 additions & 0 deletions packages/plugin-sources/doc/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Sources

> Reads the component tree
Combines the load and parse plugins to read the full component tree.

<? @include {=readme}
install.md ?>

***
<!-- @toc -->
***

<? @include {=readme} usage.md ?>

<? @include ../../../doc/readme/license.md ?>
<? @include ../../../doc/readme/links.md ?>
7 changes: 7 additions & 0 deletions packages/plugin-sources/doc/readme/install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Install

```
npm i trucks-plugin-load --save-dev
```

For the command line interface see [trucks-cli][].
12 changes: 12 additions & 0 deletions packages/plugin-sources/doc/readme/usage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const trucks = require('../../../../lib/index');

trucks(
{
files: ['example/components.html']
}, (err, res) => {
if(err) {
throw err;
}
console.log(res);
}
);
6 changes: 6 additions & 0 deletions packages/plugin-sources/doc/readme/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Usage

This plugin is bundled with the core library.

For command line usage see [trucks-cli][].

7 changes: 7 additions & 0 deletions packages/plugin-sources/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

function sources() {
return [require('trucks-plugin-load'), require('trucks-plugin-parse')];
}

module.exports = sources;
30 changes: 30 additions & 0 deletions packages/plugin-sources/mkdoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var mk = require('mktask');

function doc(src, dest, opts, cb) {
mk.doc(src)
.pipe(mk.pi())
.pipe(mk.ref())
.pipe(mk.abs())
.pipe(mk.msg())
.pipe(mk.toc(opts.toc))
//.pipe(mk.ast.stringify())
//.pipe(process.stdout)
.pipe(mk.out())
.pipe(mk.dest(dest))
.on('finish', cb);
}

// @task readme build the readme file
function readme(cb) {
doc(
'doc/readme.md', 'README.md',
{toc: {depth: 2, max: 3}}, cb);
}

// @task docs build all docs
function docs(cb){
cb();
}

mk.task(readme);
mk.task([readme], docs)
36 changes: 36 additions & 0 deletions packages/plugin-sources/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "trucks-plugin-sources",
"version": "1.0.0",
"description": "Reads the full component tree",
"author": "muji <noop@xpm.io>",
"license": "MIT",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "https://github.com/tmpfs/trucks"
},
"engines": {
"node": ">=4.0"
},
"devDependencies": {
"babel-cli": "~6.10.1",
"babel-preset-es2015": "~6.9.0",
"chai": "~3.5.0",
"coveralls": "~2.11.9",
"express": "~4.14.0",
"istanbul": "~0.4.4",
"mocha": "~2.5.3"
},
"scripts": {
"clean": "rm -rf coverage target lib",
"build": "babel --presets es2015 src --out-dir lib",
"prepublish": "npm run build",
"lint": "jshint src test doc && jscs src test/spec",
"target": "rm -rf target && mkdir target",
"pretest": "npm run target",
"test": "NODE_ENV=test mocha ${SPEC:-test/spec}",
"precover": "npm run pretest",
"cover": "NODE_ENV=test istanbul cover _mocha -- ${SPEC:-test/spec}",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
}
}
8 changes: 8 additions & 0 deletions packages/plugin-sources/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function sources() {
return [
require('trucks-plugin-load'),
require('trucks-plugin-parse')
];
}

module.exports = sources;
5 changes: 5 additions & 0 deletions packages/plugin-sources/test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-u bdd
--recursive
--bail
--reporter list
-A
22 changes: 22 additions & 0 deletions packages/plugin-sources/test/spec/sources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var expect = require('chai').expect
, trucks = require('../../../../src');

describe('sources:', function() {

it('should use default options', function(done) {
const src = '../../test/fixtures/simple-inline/components.html';
trucks(
{
files: [src],
out: 'target',
name: 'sources',
plugins: [require('../../src')]
}, (err, result) => {
expect(err).to.eql(null);
expect(result).to.be.an('object');
done();
}
);
});

});
15 changes: 4 additions & 11 deletions src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const path = require('path');
function middleware(state, options) {
let i
, phases = options.phases
, handlers = options.handlers || {}
, lookup = options.lookup || {}
, prefix = options.prefix
, phase
Expand Down Expand Up @@ -52,17 +51,11 @@ function middleware(state, options) {
if(phase instanceof Function) {
closure = phase(state, detail.conf);
}else if(phase === String(phase)) {
// see if the phase is a known built in plugin
if(handlers[phase]) {
closure = handlers[phase](state, detail.conf);
// treat as plugin module
}else{
let file = phase;
if(prefix && !path.isAbsolute(phase) && !/^\.*\//.test(phase)) {
file = prefix + file;
}
closure = require(file)(state, detail.conf);
let file = phase;
if(prefix && !path.isAbsolute(phase) && !/^\.*\//.test(phase)) {
file = prefix + file;
}
closure = require(file)(state, detail.conf);
}else if(phase && phase === Object(phase)) {
if(!phase.plugin || !(phase.plugin instanceof Function)) {
throw new Error(
Expand Down
12 changes: 0 additions & 12 deletions src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,6 @@ function options(state, cb) {
cb(null, state);
}

function getHandlers() {
return {
sources: function sources() {
return [
require('trucks-plugin-load'),
require('trucks-plugin-parse')
];
}
}
}

function run(opts, cb) {
const state = new State(opts);

Expand All @@ -131,7 +120,6 @@ function run(opts, cb) {
closures = state.getMiddleware(
{
phases: phases,
handlers: getHandlers(),
prefix: PREFIX,
lookup: state.options.conf.plugins
});
Expand Down

0 comments on commit d71849b

Please sign in to comment.