├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGES.md ├── package.json ├── index.js ├── README.md ├── LICENSE └── tests.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | .travis.yml 3 | tests.js -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 0.10 4 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | ## 0.4.0 / 2015-05-11 2 | 3 | Now depends on msx 0.4.0. 4 | 5 | ## 0.3.0 / 2015-01-27 6 | 7 | Now depends on msx 0.3.0. 8 | 9 | Removed: `@jsx m` pragma checking/adding is no longer necessary as of msx 0.3.0. 10 | 11 | ## 0.2.1 / 2015-01-26 12 | 13 | Fixed: options passed to `msx()` are now passed on to `msx.transform()` 14 | 15 | ## 0.2.0 / 2015-01-24 16 | 17 | Now depends on msx 0.2.0. 18 | 19 | Added: pass options to msx \[[liamcurry]\] 20 | 21 | Changed: only push files which transform without error \[[liamcurry]\] 22 | 23 | ## 0.1.0 / 2014-03-21 24 | 25 | First release. 26 | 27 | [liamcurry]: https://github.com/liamcurry -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-msx", 3 | "version": "0.4.0", 4 | "description": "Precompiles Mithril views which use MSX into JavaScript", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/insin/gulp-msx.git" 9 | }, 10 | "keywords": [ 11 | "gulpplugin", 12 | "jsx", 13 | "mithril", 14 | "msx" 15 | ], 16 | "author": "Jonathan Buchanan (https://github.com/insin)", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/insin/gulp-msx/issues" 20 | }, 21 | "homepage": "https://github.com/insin/gulp-msx", 22 | "dependencies": { 23 | "gulp-util": "^3.0.4", 24 | "msx": "^0.4.0", 25 | "through2": "^0.6.5" 26 | }, 27 | "devDependencies": { 28 | "tape": "^4.0.0" 29 | }, 30 | "scripts": { 31 | "test": "node tests.js" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var path = require('path') 4 | 5 | var gutil = require('gulp-util') 6 | var msx = require('msx') 7 | var through = require('through2') 8 | 9 | module.exports = function(options) { 10 | return through.obj(function(file, enc, cb) { 11 | if (file.isNull()) { 12 | this.push(file) 13 | return cb() 14 | } 15 | 16 | if (file.isStream()) { 17 | this.emit('error', new gutil.PluginError('gulp-msx', 'Streaming not supported')) 18 | return cb() 19 | } 20 | 21 | try { 22 | file.contents = new Buffer(msx.transform(file.contents.toString(), options)) 23 | file.path = gutil.replaceExtension(file.path, '.js') 24 | this.push(file) 25 | } 26 | catch (err) { 27 | err.fileName = file.path 28 | this.emit('error', new gutil.PluginError('gulp-msx', 29 | gutil.colors.magenta(path.relative(file.cwd, file.path)) + ' ' + err.message)) 30 | } 31 | 32 | cb() 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [gulp](http://gulpjs.com/)-msx [![Build Status](https://secure.travis-ci.org/insin/gulp-msx.png?branch=master)](http://travis-ci.org/insin/gulp-msx) 2 | 3 | (Based on [gulp-react](https://github.com/sindresorhus/gulp-react)) 4 | 5 | Precompiles [Mithril](http://lhorie.github.io/mithril/) views which use 6 | [JSX](http://facebook.github.io/jsx/) into JavaScript, using 7 | [msx](https://github.com/insin/msx). 8 | 9 | ## Install 10 | 11 | ``` 12 | npm install --save-dev gulp-msx 13 | ``` 14 | 15 | ## Example 16 | 17 | ```javascript 18 | var gulp = require('gulp') 19 | var msx = require('gulp-msx') 20 | 21 | gulp.task('transform-jsx', function() { 22 | return gulp.src('./src/**/*.jsx') 23 | .pipe(msx({harmony: true})) 24 | .pipe(gulp.dest('./dist')) 25 | }) 26 | ``` 27 | 28 | `.jsx` files are automatically renamed to `.js` for you, ready for output. 29 | 30 | ## API 31 | 32 | ### `msx([options: Object])` 33 | 34 | `options` - options to be passed to the call to 35 | [`msx.transform()`](https://github.com/insin/msx/#module-api). 36 | 37 | --- 38 | 39 | MIT Licensed -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Jonathan Buchanan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | Based on gulp-react [1], MIT [2] (c) Sindre Sorhus [3] 24 | 25 | [1] https://github.com/sindresorhus/gulp-react 26 | [2] http://opensource.org/licenses/MIT 27 | [3] http://sindresorhus.com/ 28 | -------------------------------------------------------------------------------- /tests.js: -------------------------------------------------------------------------------- 1 | var gutil = require('gulp-util') 2 | var test = require('tape').test 3 | 4 | var msx = require('./index') 5 | 6 | var basicTestContents = [ 7 | 'hello.view = function(ctrl) {' 8 | , ' return
Hello {ctrl.name}
' 9 | , '}' 10 | ].join('\n') 11 | 12 | var basicTestExpected = [ 13 | 'hello.view = function(ctrl) {' 14 | , ' return {tag: "div", attrs: {id:"test"}, children: ["Hello ", ctrl.name]}' 15 | , '}' 16 | ].join('\n') 17 | 18 | var testOptionsContents = [ 19 | 'hello.view = ctrl => {' 20 | , ' var {name} = ctrl' 21 | , ' return
{`Hello ${name}`}
' 22 | , '}' 23 | ].join('\n') 24 | 25 | var expectedOptionsOutput = [ 26 | 'hello.view = function(ctrl) {' 27 | , ' var $__0= ctrl,name=$__0.name' 28 | , ' return m("div", {id:"test"}, [("Hello " + name)])' 29 | , '}' 30 | ].join('\n') 31 | 32 | function streamTest(filename, contents, onData, options) { 33 | var stream = msx(options) 34 | stream.on('data', onData) 35 | stream.write(new gutil.File({ 36 | path: filename 37 | , contents: new Buffer(contents) 38 | })) 39 | } 40 | 41 | test('basic transformation', function(t) { 42 | t.plan(2) 43 | streamTest('fixture.jsx', basicTestContents, function(file) { 44 | t.equal(file.relative, 'fixture.js', '.jsx file was renamed to .js in the stream') 45 | t.equal(file.contents.toString(), 46 | basicTestExpected, 47 | 'tags were transformed to raw virtual DOM objects') 48 | }) 49 | }) 50 | 51 | test('passing options', function(t) { 52 | t.plan(1) 53 | streamTest('fixture.jsx', testOptionsContents, function(file) { 54 | t.equal(file.contents.toString(), 55 | expectedOptionsOutput, 56 | 'options were passed to msx.transform()') 57 | }, {harmony: true, precompile: false}) 58 | }) --------------------------------------------------------------------------------