1- var concat = require ( 'gulp-concat' ) ;
2- var ts = require ( 'gulp-typescript' ) ;
3- var gulp = require ( 'gulp' ) ;
4- var Elixir = require ( 'laravel-elixir' ) ;
5- var fileExists = require ( 'file-exists' ) ;
6- var path = require ( 'path' ) ;
1+ const concat = require ( 'gulp-concat' ) ;
2+ const ts = require ( 'gulp-typescript' ) ;
3+ const gulp = require ( 'gulp' ) ;
4+ const path = require ( 'path' ) ;
5+ const fs = require ( 'fs' ) ;
76
8- var _ = require ( 'underscore ' ) ;
7+ const Elixir = require ( 'laravel-elixir ' ) ;
98
10- var $ = Elixir . Plugins ;
11- var config = Elixir . config ;
9+ const _ = require ( 'underscore' ) ;
1210
13- var tsFolder = config . assetsPath ;
14- var tsOutput = config . publicPath ;
11+ const $ = Elixir . Plugins ;
12+ const config = Elixir . config ;
1513
16- Elixir . extend ( 'typescript' , function ( src , output , options ) {
17- var paths = prepGulpPaths ( src , output ) ;
14+ let assetsPath = config . assetsPath ;
15+ let publicPath = config . publicPath ;
16+ let jsOutputFolder = config . js . outputFolder ;
1817
19- new Elixir . Task ( 'typescript' , function ( ) {
20- this . log ( paths . src , paths . output ) ;
18+ // overwrite elixir config values
19+ var tsFolder = path . join ( assetsPath , "typescript" ) ; // would be config.get('assets.js.typescript.folder');
20+ var tsOutput = path . join ( publicPath , jsOutputFolder ) ;
21+
22+ Elixir . extend ( 'typescript' , function ( src , baseDir , output , options ) {
23+ var paths = prepGulpPaths ( src , baseDir , output ) ;
24+
25+ new Elixir . Task ( 'typescript' , function ( ) {
26+ // this.log(paths.src, paths.output);
27+
28+ // register watchers
29+ this . watch ( path . join ( paths . src . baseDir , "**/*.ts" ) )
30+ . ignore ( paths . output . path )
31+
32+ this . recordStep ( 'Transpiling Typescript files' ) ;
2133
2234 // check if there is an tsconfig.json file --> initialize ts project
2335 var tsProject = null ;
24- var tsConfigPath = path . join ( tsFolder , 'tsconfig.json' ) ;
25- if ( fileExists ( tsConfigPath ) ) {
26- tsProject = ts . createProject ( tsConfigPath , options ) ;
27- } else {
36+ if ( fs . existsSync ( 'tsconfig.json' ) ) {
37+ this . recordStep ( 'Using tsconfig.json' ) ;
38+ tsProject = ts . createProject ( 'tsconfig.json' , options ) ;
39+ } else {
2840 // useful default options
2941 options = _ . extend ( {
3042 sortOutput : true
@@ -33,23 +45,17 @@ Elixir.extend('typescript', function(src, output, options) {
3345
3446 return (
3547 gulp
36- . src ( paths . src . path )
37- . pipe ( $ . if ( config . sourcemaps , $ . sourcemaps . init ( ) ) )
38- . pipe ( ts ( tsProject == null ? options : tsProject )
39- . on ( 'error' , function ( e ) {
40- new Elixir . Notification ( ) . error ( e , 'TypeScript Compilation Failed!' ) ;
41-
42- this . emit ( 'end' ) ;
43- } ) )
44- . pipe ( $ . concat ( paths . output . name ) )
45- . pipe ( $ . if ( config . production , $ . uglify ( ) ) )
46- . pipe ( $ . if ( config . sourcemaps , $ . sourcemaps . write ( '.' ) ) )
47- . pipe ( gulp . dest ( paths . output . baseDir ) )
48- . pipe ( new Elixir . Notification ( 'TypeScript Compiled!' ) )
48+ . src ( paths . src . path )
49+ . pipe ( $ . if ( config . sourcemaps , $ . sourcemaps . init ( ) ) )
50+ . pipe ( ts ( tsProject == null ? options : tsProject )
51+ . on ( 'error' , this . onError ( ) ) )
52+ . pipe ( $ . concat ( paths . output . name ) )
53+ . pipe ( $ . if ( config . production , $ . uglify ( ) ) )
54+ . pipe ( $ . if ( config . sourcemaps , $ . sourcemaps . write ( '.' ) ) )
55+ . pipe ( this . saveAs ( gulp ) )
56+ . pipe ( this . onSuccess ( ) )
4957 ) ;
50- } )
51- . watch ( path . join ( paths . src . baseDir , "**/*.ts" ) )
52- . ignore ( paths . output . path ) ;
58+ } , paths ) ;
5359} ) ;
5460
5561/**
@@ -59,8 +65,8 @@ Elixir.extend('typescript', function(src, output, options) {
5965 * @param {string|null } output
6066 * @return {GulpPaths }
6167 */
62- var prepGulpPaths = function ( src , output ) {
68+ var prepGulpPaths = function ( src , baseDir , output ) {
6369 return new Elixir . GulpPaths ( )
64- . src ( src , tsFolder )
65- . output ( output || tsOutput , 'app .js' ) ;
70+ . src ( src , baseDir || tsFolder )
71+ . output ( output || Elixir . config . get ( 'public.js.outputFolder' ) , 'all .js' ) ;
6672} ;
0 commit comments