Skip to content

Instantly share code, notes, and snippets.

@HendrikRoth
Last active September 22, 2016 23:52
Show Gist options
  • Save HendrikRoth/5b5c0c99175cf22730f1c50452b08580 to your computer and use it in GitHub Desktop.
Save HendrikRoth/5b5c0c99175cf22730f1c50452b08580 to your computer and use it in GitHub Desktop.
/**
* workflow for:
* - transpiling tsx to mithril hyperscript
* - replacing simple typed class names to cssobj's helper function res.mapClass, keep in mind to safely set this object
*/
var gulp = require('gulp')
var browserSync = require('browser-sync').create()
var ts = require('gulp-typescript')
var replace = require('gulp-replace')
var tsProject = ts.createProject('tsconfig.json')
gulp.task('typescript', function () {
var tsResult = tsProject.src()
.pipe(ts(tsProject))
return tsResult.js
.pipe(replace(/React.createElement/g, 'm'))
.pipe(gulp.dest('.'))
})
gulp.task('replace', ['typescript'], function () {
gulp.src('**/*.js', { base: './' })
.pipe(replace(/class: \"(.*?)\"/g, 'class: res.mapClass(".$1")'))
.pipe(gulp.dest('.'))
.pipe(browserSync.reload({stream: true}))
})
gulp.task('serve', ['replace'], function () {
browserSync.init({
proxy: 'http://localhost:3309', // listening express application
reloadDelay: 0,
logLevel: 'silent',
port: 3305
})
})
gulp.task('watch', ['serve'], function () {
gulp.watch(['!node_modules/**', '**/*.{ts,tsx}'], ['replace'])
})
gulp.task('default', ['watch'])
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"experimentalDecorators": true,
"jsx": "react",
"sourceMap": true
},
"filesGlob": [
"typings/index.d.ts",
"_lib/**/*.ts",
"_lib/**/*.tsx"
],
"compileOnSave": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment