-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typescript): add typescript support, must be enabled via build o…
…ption typescript[client|server].enable
- Loading branch information
Showing
22 changed files
with
385 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 | |||
|
|||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 | |||
|
|||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
Oops, something went wrong.