feat(cli options): now support --web for web compilations targeting Google Chrome
This commit is contained in:
		| @@ -2,8 +2,4 @@ export * from './tsbuild.exports'; | ||||
|  | ||||
| import * as tsbuild from './tsbuild.exports'; | ||||
|  | ||||
| if (process.env.CLI_CALL_TSBUILD === 'true') { | ||||
|   tsbuild.compileGlobStringObject({ | ||||
|     './ts/**/*.ts': './dist' | ||||
|   }); | ||||
| } | ||||
| import './tsbuild.cli'; | ||||
| @@ -19,13 +19,26 @@ export const compilerOptionsDefault: CompilerOptions = { | ||||
|   target: plugins.typescript.ScriptTarget.ES2015 | ||||
| }; | ||||
|  | ||||
| export const compilerOptionsWebDefault: CompilerOptions = { | ||||
|   ...compilerOptionsDefault, | ||||
|   lib: [...compilerOptionsDefault.lib, 'dom'] | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * merges compilerOptions with the default compiler options | ||||
|  */ | ||||
| export const mergeCompilerOptions = function(customTsOptions: CompilerOptions): CompilerOptions { | ||||
| export const mergeCompilerOptions = (customTsOptions: CompilerOptions, argvArg?: any): CompilerOptions => { | ||||
|   const defaultOptionsToMerge = (() => { | ||||
|     if (argvArg && argvArg.web) { | ||||
|       return compilerOptionsWebDefault; | ||||
|     } else { | ||||
|       return compilerOptionsDefault; | ||||
|     } | ||||
|   })(); | ||||
|  | ||||
|   // create merged options | ||||
|   let mergedOptions: CompilerOptions = { | ||||
|     ...compilerOptionsDefault, | ||||
|     ...defaultOptionsToMerge, | ||||
|     ...customTsOptions | ||||
|   }; | ||||
|  | ||||
| @@ -37,7 +50,8 @@ export const mergeCompilerOptions = function(customTsOptions: CompilerOptions): | ||||
|  */ | ||||
| export const compiler = ( | ||||
|   fileNames: string[], | ||||
|   options: plugins.typescript.CompilerOptions | ||||
|   options: plugins.typescript.CompilerOptions, | ||||
|   argvArg?: any, | ||||
| ): Promise<any[]> => { | ||||
|   console.log(`Compiling ${fileNames.length} files...`); | ||||
|   let done = plugins.smartpromise.defer<any[]>(); | ||||
|   | ||||
							
								
								
									
										17
									
								
								ts/tsbuild.cli.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								ts/tsbuild.cli.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| import * as plugins from './tsbuild.plugins'; | ||||
| import * as tsbuild from './tsbuild.exports'; | ||||
|  | ||||
| const tsbuildCli = new plugins.smartcli.Smartcli(); | ||||
|  | ||||
| tsbuildCli.standardTask().subscribe(argvArg => { | ||||
|   if (process.env.CLI_CALL_TSBUILD === 'true') { | ||||
|     tsbuild.compileGlobStringObject( | ||||
|       { | ||||
|         './ts/**/*.ts': './dist' | ||||
|       }, | ||||
|       {}, | ||||
|       process.cwd(), | ||||
|       argvArg | ||||
|     ); | ||||
|   } | ||||
| }); | ||||
| @@ -8,9 +8,10 @@ export * from './tsbuild.classes.compiler'; | ||||
|  */ | ||||
| export let compileFileArray = ( | ||||
|   fileStringArrayArg: string[], | ||||
|   compilerOptionsArg: CompilerOptions = {} | ||||
|   compilerOptionsArg: CompilerOptions = {}, | ||||
|   argvArg?: any, | ||||
| ): Promise<any[]> => { | ||||
|   return compiler(fileStringArrayArg, mergeCompilerOptions(compilerOptionsArg)); | ||||
|   return compiler(fileStringArrayArg, mergeCompilerOptions(compilerOptionsArg, argvArg), argvArg); | ||||
| }; | ||||
|  | ||||
| /** | ||||
| @@ -23,30 +24,33 @@ export let compileFileArray = ( | ||||
| export let compileGlobStringObject = async ( | ||||
|   globStringObjectArg: any, | ||||
|   tsOptionsArg: CompilerOptions = {}, | ||||
|   cwdArg: string = process.cwd() | ||||
|   cwdArg: string = process.cwd(), | ||||
|   argvArg?: any, | ||||
| ) => { | ||||
|   let compiledFiles = []; | ||||
|   for (let keyArg in globStringObjectArg) { | ||||
|     console.log( | ||||
|       `TypeScript assignment: transpile from ${keyArg} to ${globStringObjectArg[keyArg]}` | ||||
|     ); | ||||
|     const fileTreeArray = await plugins.smartfile.fs.listFileTree(cwdArg, keyArg); | ||||
|     let absoluteFilePathArray: string[] = plugins.smartpath.transform.toAbsolute( | ||||
|       fileTreeArray, | ||||
|       cwdArg | ||||
|     ); | ||||
|     let destDir: string = plugins.smartpath.transform.toAbsolute( | ||||
|       globStringObjectArg[keyArg], | ||||
|       cwdArg | ||||
|     ); | ||||
|     tsOptionsArg = { | ||||
|       ...tsOptionsArg, | ||||
|       outDir: destDir | ||||
|     }; | ||||
|     compiledFiles = compiledFiles.concat( | ||||
|       compiledFiles, | ||||
|       await compileFileArray(absoluteFilePathArray, tsOptionsArg) | ||||
|     ); | ||||
|   for (const keyArg in globStringObjectArg) { | ||||
|     if(globStringObjectArg[keyArg]) { | ||||
|       console.log( | ||||
|         `TypeScript assignment: transpile from ${keyArg} to ${globStringObjectArg[keyArg]}` | ||||
|       ); | ||||
|       const fileTreeArray = await plugins.smartfile.fs.listFileTree(cwdArg, keyArg); | ||||
|       let absoluteFilePathArray: string[] = plugins.smartpath.transform.toAbsolute( | ||||
|         fileTreeArray, | ||||
|         cwdArg | ||||
|       ); | ||||
|       let destDir: string = plugins.smartpath.transform.toAbsolute( | ||||
|         globStringObjectArg[keyArg], | ||||
|         cwdArg | ||||
|       ); | ||||
|       tsOptionsArg = { | ||||
|         ...tsOptionsArg, | ||||
|         outDir: destDir | ||||
|       }; | ||||
|       compiledFiles = compiledFiles.concat( | ||||
|         compiledFiles, | ||||
|         await compileFileArray(absoluteFilePathArray, tsOptionsArg, argvArg) | ||||
|       ); | ||||
|     } | ||||
|   } | ||||
|   return compiledFiles; | ||||
| }; | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| import * as smartcli from '@pushrocks/smartcli'; | ||||
| import * as smartfile from '@pushrocks/smartfile'; | ||||
| import * as smartpath from '@pushrocks/smartpath'; | ||||
| import * as smartpromise from '@pushrocks/smartpromise'; | ||||
| import * as typescript from 'typescript'; | ||||
|  | ||||
| export { smartfile, smartpath, smartpromise, typescript }; | ||||
| export { smartcli, smartfile, smartpath, smartpromise, typescript }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user