@@ -30,6 +30,7 @@ import { Options } from "./options"
3030import { touch } from "./touch"
3131import { watch } from "./watch"
3232import { compile } from "./compile"
33+ import { delay } from "./delay"
3334import { shim } from "./shim"
3435import { help , version , info , errors , done } from "./help"
3536
@@ -43,42 +44,69 @@ import * as path from "path"
4344 * @returns {Promise<any> }
4445 */
4546export const bundle = async ( options : Options , log : Function ) => {
46- // run validation, help and version checks.
47- if ( options . errors . length > 0 ) return log ( errors ( options ) )
48- if ( options . properties . help ) return log ( help ( ) )
49- if ( options . properties . version ) return log ( await version ( ) )
50-
51- // display compiler settings.
52- log ( info ( options ) )
53-
54- // if we are loading from a project, then we need to resolve
55- // the output file path from the view of the config.
56- const outputFile = ( options . properties . project === undefined )
57- ? path . resolve ( process . cwd ( ) , options . properties . outputFile )
58- : path . resolve (
59- path . dirname (
60- path . resolve ( process . cwd ( ) , options . properties . project
61- ) ) , options . properties . outputFile )
62-
63-
64- // ensure the output file exists.
47+ // ----------------------------------------------------------
48+ //
49+ // run validation, help and version checks.
50+ //
51+ // ----------------------------------------------------------
52+ if ( options . errors . length > 0 ) { return log ( errors ( options ) ) }
53+ if ( options . properties . help ) { return log ( help ( ) ) }
54+ if ( options . properties . version ) { return log ( await version ( ) ) }
55+
56+ // ----------------------------------------------------------
57+ //
58+ // display compiler settings.
59+ //
60+ // ----------------------------------------------------------
61+ log ( info ( options ) )
62+
63+ // ----------------------------------------------------------
64+ //
65+ // if we are loading from a project, then we need to resolve
66+ // the output file path from the view of the config.
67+ //
68+ // ----------------------------------------------------------
69+ const outputFile = ( options . properties . project === undefined )
70+ ? path . resolve ( process . cwd ( ) , options . properties . outputFile )
71+ : path . resolve (
72+ path . dirname (
73+ path . resolve ( process . cwd ( ) , options . properties . project
74+ ) ) , options . properties . outputFile ) ;
75+
76+ // ----------------------------------------------------------
77+ //
78+ // watch
79+ //
80+ // ----------------------------------------------------------
81+ if ( options . properties . watch === true ) {
82+
83+ // ensure the output file exists..
6584 await touch ( outputFile )
85+
86+ // start watcher process..
87+ watch ( outputFile , ( ) => shim ( outputFile , options . properties . exportAs , options . properties . importAs ) )
88+
89+ // compile..
90+ compile ( options . command , log )
91+ }
92+
93+ // ----------------------------------------------------------
94+ //
95+ // standard
96+ //
97+ // ----------------------------------------------------------
98+ else {
99+
100+ // compile
101+ await compile ( options . command , log )
102+
103+ // wait a bit..
104+ await delay ( 100 )
66105
67- // watch output file for changes. (compile on save support)
68- const watcher = watch ( outputFile , ( ) => {
69- shim ( outputFile , options . properties . exportAs , options . properties . importAs )
70- } )
106+ // shim
107+ await shim ( outputFile , options . properties . exportAs , options . properties . importAs )
71108
72- // run compilation.
73- const start = new Date ( )
74- try {
75- await compile ( options . command , log )
76- await shim ( outputFile , options . properties . exportAs , options . properties . importAs )
77- watcher . close ( )
78- log ( done ( ) )
79- } catch ( e ) {
80- shim ( outputFile , options . properties . exportAs , options . properties . importAs )
81- watcher . close ( )
82- log ( done ( ) )
83- }
109+ // complete
110+ log ( done ( ) )
111+ }
84112}
0 commit comments