Skip to content
Permalink
Browse files

feat(typescript): add typescript support, must be enabled via build o…

…ption typescript[client|server].enable
  • Loading branch information
jyounce committed Aug 8, 2016
1 parent 3cbd8ee commit 1a94a60af7f832017ad13ac345b7acb7365502bc
@@ -180,6 +180,8 @@ rapid-build.json (build options - can be cson, json or js file)
# extra.compile.server[less|sass] = (array of strings) = file paths: additional files to compile to dist/server that the build didn't compile
# extra.minify.client[css|js] = (array of strings) = file paths: additional files to minify in dist/client that the build didn't minify (by default, the build does not minify files in libs or bower_components)
# security.client.clickjacking = (boolean) defaults to true = includes a clickjacking defense script in the default spa.html (set to false to disable)
# compile.typescript[client|server].enable = (boolean) defaults to false = Set to true to enable client and or server typescript compiler.
# compile.typescript.client.entries = (array of strings) defaults to ['main.ts'] = Entry point(s) of your app. This file(s) is required. Browserify is used for module loading. Must use commonjs for typescript's module code generation.
# ======================================================================================================================================================================================================================================================================================================
```

@@ -18,8 +18,9 @@ angular.module('rapid-build').constant 'ABOUT', [
label: 'css, less and sass'
info: 'client'
,
label: 'js, <a target="_blank" href="http://babeljs.io/">es6</a>
and coffeescript'
label: 'js, <a target="_blank" href="http://babeljs.io/">es6</a>,
coffeescript and
<a href="/build-options#compile.typescript[client|server].enable">typescript</a>'
info: 'client and server'
]
,
@@ -44,6 +44,9 @@ angular.module('rapid-build').constant 'BUILD_COMMON_TASKS', [
,
label: '<a target="_blank" href="http://babeljs.io/">es6</a> &#8594; js'
info: '@dir client and server'
,
label: '<a href="/build-options#compile.typescript[client|server].enable">typescript</a> &#8594; js'
info: '@dir client and server'
,
label: 'less &#8594; css'
info: '@dir client'
@@ -191,6 +191,62 @@ angular.module('rapid-build').constant 'BUILD_OPTS', [
}
}
"""
, # =================================================================
label: 'compile'
icon: 'fa-cog'
html:
class: items2: list: 'small'
items: [
label: 'typescript[client|server].enable'
info: '@type boolean, @default false'
items: [
label: 'Set to true to enable client and or server typescript compiler.'
,
label: 'Place client typescript files in src/client/scripts/ directory.'
icon: 'fa-exclamation-circle'
,
label: 'Place server typescript files in src/server/ directory.'
icon: 'fa-exclamation-circle'
]
,
label: 'typescript.client.entries'
info: '@type array of strings, @default [\'main.ts\']'
items: [
label: 'Entry point(s) of your app.'
icon: 'fa-exclamation-circle'
items: [
label: 'This file(s) is required.'
,
label: 'File path(s) must be relative to scripts directory.'
]
,
label: '<a target="_blank" href="http://browserify.org/">Browserify</a>
is used for module loading.'
,
label: 'Must use commonjs for typescript\'s
<a target="_blank" href="https://www.typescriptlang.org/docs/handbook/compiler-options.html">module code generation</a>.'
]
]
example:
label: 'Example'
info: '<a href="/getting-started#rapid-build.json">for rapid-build.json</a>'
lang: 'js'
size: 'small'
code: """
{
compile: {
typescript: {
client: {
enable: true,
entries: ['init.ts']
},
server: {
enable: true
}
}
}
}
"""
, # =================================================================
label: 'dist'
icon: 'fa-cog'
@@ -61,7 +61,7 @@ angular.module('rapid-build').constant 'GETTING_STARTED', [
│ ├── libs/
│ │ └── # (3rd party libraries that aren't bower components)
│ ├── scripts/
│ │ └── coffee, es6 or js
│ │ └── coffee, es6, js or typescript
│ ├── styles/
│ │ └── css, less, sass or scss
│ ├── test/
@@ -72,7 +72,7 @@ angular.module('rapid-build').constant 'GETTING_STARTED', [
└── server/
├── test/
│ └── coffee, es6 or js
└── routes.{coffee,es6,js} # (optional, see build options dist.server.fileName)
└── routes.{coffee,es6,js,ts} # (optional, see build options dist.server.fileName)
nodes_modules/ # (generated folder via package.json)
bower.json
package.json # (required)
@@ -26,6 +26,7 @@ <h1>
{ caption: 'angular', url: '#angular' },
{ caption: 'browser', url: '#browser' },
{ caption: 'build', url: '#build' },
{ caption: 'compile', url: '#compile' },
{ caption: 'dist', url: '#dist' },
{ caption: 'exclude', url: '#exclude' },
{ caption: 'extra', url: '#extra' },
@@ -51,6 +51,7 @@
"body-parser": "1.15.2",
"bower": "1.7.9",
"browser-sync": "2.13.0",
"browserify": "13.1.0",
"coffee-script": "1.10.0",
"colors": "1.1.2",
"commander": "2.9.0",
@@ -81,7 +82,8 @@
"gulp-sass": "2.3.2",
"gulp-sequence": "0.4.5",
"gulp-template": "4.0.0",
"gulp-uglify": "1.5.4",
"gulp-typescript": "2.13.6",
"gulp-uglify": "2.0.0",
"gulp-util": "3.0.7",
"gulp-watch": "4.3.8",
"http-proxy-middleware": "0.17.0",
@@ -103,7 +105,10 @@
"postcss-import": "7.1.3",
"q": "1.4.1",
"sha1": "1.1.1",
"through2": "2.0.1"
"through2": "2.0.1",
"tsify": "1.0.3",
"vinyl-source-stream": "1.1.0",
"watchify": "3.7.0"
},
"keywords": [
"build system",
@@ -6,6 +6,7 @@ module.exports = (config, options) ->
# format options
# ==============
options = require("#{config.req.config.options}/option-build") config, options
options = require("#{config.req.config.options}/option-compile") config, options
options = require("#{config.req.config.options}/option-dist-and-src") config, options
options = require("#{config.req.config.options}/option-ports") config, options
options = require("#{config.req.config.options}/option-order") config, options
@@ -24,6 +24,7 @@ module.exports = (rbDir, options) ->
config = require("#{config.req.config.configs}/config-angular") config, options
config = require("#{config.req.config.configs}/config-spa") config, options
config = require("#{config.req.config.configs}/config-exclude") config, options
config = require("#{config.req.config.configs}/config-compile") config, options
config = require("#{config.req.config.configs}/config-extra") config
config = require("#{config.req.config.configs}/config-extra-copy") config, options
config = require("#{config.req.config.configs}/config-extra-compile") config, options
@@ -0,0 +1,34 @@
module.exports = (config, options) ->
log = require "#{config.req.helpers}/log"
isType = require "#{config.req.helpers}/isType"
test = require("#{config.req.helpers}/test")()

# init compile
# ============
compile =
typescript:
client:
enable: options.compile.typescript.client.enable
entries: options.compile.typescript.client.entries
server:
enable: options.compile.typescript.server.enable

compile.typescript.client.entries = ['main.ts'] if isType.null compile.typescript.client.entries

# add compile to config
# =====================
config.compile = compile

# logs
# ====
# log.json compile, 'compile ='

# tests
# =====
test.log 'true', config.compile, 'add compile to config'

# return
# ======
config


@@ -15,6 +15,7 @@ module.exports = (config, options) ->
scripts: 'scripts'
styles: 'styles'
test: 'test'
typings: 'typings'
views: 'views'

file =
@@ -67,6 +68,8 @@ module.exports = (config, options) ->
dir: o.clientStyles or dir.styles
test:
dir: o.clientTest or dir.test
typings:
dir: dir.typings
views:
dir: o.clientViews or dir.views
server:
@@ -76,7 +79,11 @@ module.exports = (config, options) ->
dir: o.serverDir or dir.scripts
test:
dir: o.serverTest or dir.test
typings:
dir: dir.typings
if loc is 'dist'
delete info.client.typings
delete info.server.typings
unless isApp
info.client.dirName = config.rb.prefix.distDir
info.server.dirName = config.rb.prefix.distDir
@@ -17,6 +17,8 @@ module.exports = (config) ->
js: 'js'
less: 'less'
sass: 'sass,scss'
ts: 'ts' # typescript src files
defs: 'd.ts' # typescript definition files

getExts = (_exts) -> # _exts = string array
_exts = _exts.split ','
@@ -40,6 +42,8 @@ module.exports = (config) ->
js: "/**/*.#{exts.js}"
less: "/**/*.#{exts.less}"
sass: "/**/*.{#{exts.sass}}"
ts: "/**/*.#{exts.ts}"
defs: "/**/*.#{exts.defs}"
bustFiles: "/**/*.{#{getExts 'css,js,images'}}"
bustRefs: "/**/*.{#{getExts 'html,css,js'}}"

@@ -60,7 +64,7 @@ module.exports = (config) ->
addGlob = (loc, type, langs, includeBower, includeLibs) ->
for own k1, v1 of glob[loc]
for own k2, v2 of v1
continue if k2 is 'server' and ['scripts','test'].indexOf(type) is -1
continue if k2 is 'server' and ['scripts','test','typings'].indexOf(type) is -1
continue if k2 is 'server' and (includeBower or includeLibs)
v2[type] = {} unless isType.object v2[type]
for v3 in langs
@@ -88,11 +92,14 @@ module.exports = (config) ->
addGlob 'src', 'scripts', ['js']
addGlob 'src', 'scripts', ['coffee']
addGlob 'src', 'scripts', ['es6']
addGlob 'src', 'scripts', ['ts']
addGlob 'src', 'typings', ['defs']
addGlob 'src', 'styles', ['css']
addGlob 'src', 'styles', ['less']
addGlob 'src', 'styles', ['sass']
addGlob 'src', 'test', ['css', 'js']
addGlob 'src', 'test', ['coffee']
addGlob 'src', 'test', ['ts']
addGlob 'src', 'test', ['es6']
addGlob 'src', 'views', ['html']

@@ -0,0 +1,23 @@
module.exports = (config, options) ->
isType = require "#{config.req.helpers}/isType"

# init compile options
# ====================
compile = options.compile
compile = {} unless isType.object compile
compile.typescript = {} unless isType.object compile.typescript
compile.typescript.client = {} unless isType.object compile.typescript.client
compile.typescript.server = {} unless isType.object compile.typescript.server
compile.typescript.client.enable = false unless isType.boolean compile.typescript.client.enable
compile.typescript.server.enable = false unless isType.boolean compile.typescript.server.enable
compile.typescript.client.entries = null unless isType.array compile.typescript.client.entries

# add compile options
# ===================
options.compile = compile

# return
# ======
options


@@ -0,0 +1,50 @@
# TYPESCRIPT PROJECT FACTORY
# needed for watch to use same ts project
# =======================================
fs = require 'fs'

class TsProject
# typescript instance locations
# =============================
instances = {}

# private
# =======
help =
fileExists: (_path) ->
try fs.lstatSync(_path).isFile()
catch e then false

hasTsConfig: (tsconfigPath) ->
hasTsConfig = @fileExists tsconfigPath
# console.log "Has tsconfig.json: #{hasTsConfig}".alert
hasTsConfig

# @id = location (ex: client or server)
# @ts = gulp-typescript
# @tsconfig = tsconfig.json path
# @opts = ts project options
# ===========================================
class Typescript
constructor: (@id, @ts, @tsconfig, @opts={}) ->
@setProject()

setProject: ->
if help.hasTsConfig @tsconfig
@project = @ts.createProject @tsconfig, @opts
else
@project = @ts.createProject @opts
@

# static method to retrieve an
# instance or create a new one
# ============================
@get: (id, ts, tsconfig, opts) ->
if not instances[id] # create new instance
# console.log "TS INSTANCE ID: #{id}".alert
instances[id] = new Typescript id, ts, tsconfig, opts
instances[id]

# Export Class!
# =============
module.exports = TsProject
@@ -11,4 +11,7 @@ module.exports =

watch: (taskName, file, opts={}) ->
taskName = opts.logTaskName or taskName
@task "#{taskName} #{file.event}: #{file.path}", 'minor'
@task "#{taskName} #{file.event}: #{file.path}", 'minor'

watchTS: (paths) ->
@task "typescript changed: #{_path}", 'minor' for _path in paths
@@ -42,12 +42,14 @@ module.exports = (gulp, config) ->

# compile
# =======
taskHelp.addTask 'coffee:client', '/compile/coffee', loc: 'client'
taskHelp.addTask 'coffee:server', '/compile/coffee', loc: 'server'
taskHelp.addTask 'es6:client', '/compile/es6', loc: 'client'
taskHelp.addTask 'es6:server', '/compile/es6', loc: 'server'
taskHelp.addTask 'less', '/compile/less'
taskHelp.addTask 'sass', '/compile/sass'
taskHelp.addTask 'coffee:client', '/compile/coffee', loc: 'client'
taskHelp.addTask 'coffee:server', '/compile/coffee', loc: 'server'
taskHelp.addTask 'es6:client', '/compile/es6', loc: 'client'
taskHelp.addTask 'es6:server', '/compile/es6', loc: 'server'
taskHelp.addTask 'typescript:client', '/compile/typescript-client'
taskHelp.addTask 'typescript:server', '/compile/typescript-server'
taskHelp.addTask 'less', '/compile/less'
taskHelp.addTask 'sass', '/compile/sass'

# config
# ======
@@ -0,0 +1,19 @@
PLUGIN_NAME = 'gulp-update-file-base'
through = require 'through2'
gutil = require 'gulp-util'
PluginError = gutil.PluginErrors

# Plugin level function(dealing with files)
# Effects gulp.dest(dest).
# Ensure file copies to correct dist location.
# ============================================
updateFileBase = (fileBase) ->
through.obj (file, enc, cb) ->
return cb null, file unless fileBase
return cb null, file unless file
return cb new PluginError PLUGIN_NAME, 'streaming not supported' if file.isStream()
return cb null, file unless file.isBuffer()
file.base = fileBase
cb null, file

module.exports = updateFileBase

0 comments on commit 1a94a60

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