Skip to content
Permalink
Browse files

fix(typescript prod build): windows fix for client typescript prod build

  • Loading branch information
jyounce committed Aug 17, 2016
1 parent 563a32b commit e7536a4f110756f936da306627ed08c38e60e2bc
Showing with 43 additions and 30 deletions.
  1. +1 −0 package.json
  2. +42 −30 src/tasks/compile/typescript-client.coffee
@@ -108,6 +108,7 @@
"sha1": "1.1.1",
"through2": "2.0.1",
"tsify": "1.0.3",
"typescript": "1.8.10",
"vinyl-source-stream": "1.1.0",
"watchify": "3.7.0"
},
@@ -1,28 +1,36 @@
module.exports = (config, gulp, taskOpts={}) ->
q = require 'q'
fs = require 'fs'
path = require 'path'
browserify = require 'browserify'
tsify = require 'tsify'
watchify = require 'watchify'
fse = require 'fs-extra'
browserify = require 'browserify'
source = require 'vinyl-source-stream'
log = require "#{config.req.helpers}/log"
promiseHelp = require "#{config.req.helpers}/promise"

# helpers
# =======
help =
getBrowserify: (opts) ->
browserify(opts.b).plugin tsify, opts.ts

getOpts: (paths) ->
bundleFile = 'bundle.js'
bundlePath = path.join paths.dest.scripts, bundleFile
b:
basedir: paths.src.scripts
entries: config.compile.typescript.client.entries
cache: {}
cache: {}
packageCache: {}
ts:
project: paths.tsconfig
watch:
ignoreWatch: ['**/node_modules/**']
bundle:
fileName: 'bundle.js' # todo build option
path: bundlePath
fileName: bundleFile

getPaths: ->
paths =
@@ -37,45 +45,49 @@ module.exports = (config, gulp, taskOpts={}) ->
paths.tsconfig = path.join paths.src.dir, 'tsconfig.json'
paths

# tasks
# =====
runTask = (paths, opts) ->
defer = q.defer()
b = browserify(opts.b).plugin tsify, opts.ts

bundle = (watchPaths) ->
b.bundle()
.on 'error', (e) ->
log.task e.message, 'error'
.pipe source opts.bundle.fileName
.pipe gulp.dest paths.dest.scripts
.on 'end', ->
return defer.resolve() unless watchPaths
log.watchTS watchPaths

bundle() # init bundle

if config.env.is.dev # create watch
b.plugin(watchify, opts.watch).on 'update', bundle
log.task 'watching client typescript files', 'minor'

defer.promise

# API
# ===
api =
runTask: ->
runTask: (b, paths, opts) -> # bundle only
fse.ensureDirSync paths.dest.scripts # needed for createWriteStream
defer = q.defer()
bundle = b.bundle()
bundle.on 'error', (e) -> log.task e.message, 'error'
bundle.pipe fs.createWriteStream opts.bundle.path
bundle.on 'end', ->
defer.resolve()
defer.promise

runWatchTask: (b, paths, opts) -> # bundle then watch
defer = q.defer()
bundler = (watchPaths) ->
b.bundle()
.on 'error', (e) -> log.task e.message, 'error'
.pipe source opts.bundle.fileName
.pipe gulp.dest paths.dest.scripts
.on 'end', ->
return defer.resolve() unless watchPaths # init
log.watchTS watchPaths
bundler()
b.plugin(watchify, opts.watch).on 'update', bundler
defer.promise

init: ->
return promiseHelp.get() unless config.compile.typescript.client.enable
isDev = config.env.is.dev
task = if isDev then 'runWatchTask' else 'runTask'
paths = help.getPaths()
opts = help.getOpts paths
promise = runTask paths, opts
b = help.getBrowserify opts
promise = @[task] b, paths, opts
promise.done ->
log.task "compiled typescript to: #{paths.dest.dir}"
log.task 'watching client typescript files', 'minor' if isDev
promise

# return
# ======
api.runTask()
api.init()



0 comments on commit e7536a4

Please sign in to comment.
You can’t perform that action at this time.