import { posix as path } from 'path' ; import * as del from 'del' ; import { AngularPackage } from './angular-package' ; import { AngularPackageBundler } from './bundler/angular-package.bundler' ; import { AngularPackageCompiler } from './compiler/angular-package.compiler' ; import { AngularPackageTransformer } from './transformer/angular-package.transformer' ; import { AngularPackageComposer } from './composer/angular-package.composer' ; import { AngularPackageLogger } from './logger/angular-package-logger' ; /**
 * Angular Package Builder
 */ export class AngularPackageBuilder { param angularPackage returns public static async package ( angularPackage ) { await this . cleanupOutputFolder ( angularPackage ) ; await this . transform ( angularPackage ) ; await this . compile ( angularPackage ) ; await this . bundle ( angularPackage ) ; await this . compose ( angularPackage ) ; await this . cleanupTemporaryOutputFolder ( angularPackage ) ; } param angularPackage returns private static async transform ( angularPackage ) { const angularPackageTransformer = new AngularPackageTransformer ( angularPackage ) ; try { AngularPackageLogger . logTaskStart ( 'Apply transformations' ) ; await angularPackageTransformer . transform ( ) ; AngularPackageLogger . logTaskSuccess ( ) ; } catch ( error ) { AngularPackageLogger . logTaskError ( ) ; throw new Error ( ) ; } } param angularPackage returns private static async compile ( angularPackage ) { const angularPackageCompiler = new AngularPackageCompiler ( angularPackage ) ; AngularPackageLogger . logTaskStart ( 'Compile TypeScript to ES2015' ) ; await angularPackageCompiler . compile ( 'esm2015' ) ; AngularPackageLogger . logTaskSuccess ( ) ; AngularPackageLogger . logTaskStart ( 'Compile TypeScript to ES5' ) ; await angularPackageCompiler . compile ( 'esm5' ) ; AngularPackageLogger . logTaskSuccess ( ) ; } param angularPackage returns private static async bundle ( angularPackage ) { const angularPackageBundler = new AngularPackageBundler ( angularPackage ) ; AngularPackageLogger . logTaskStart ( 'Generate flat ES2015 bundle' ) ; await angularPackageBundler . bundle ( 'fesm2015' ) ; AngularPackageLogger . logTaskSuccess ( ) ; AngularPackageLogger . logTaskStart ( 'Generate flat ES5 bundle' ) ; await angularPackageBundler . bundle ( 'fesm5' ) ; AngularPackageLogger . logTaskSuccess ( ) ; AngularPackageLogger . logTaskStart ( 'Generate UMD bundle' ) ; await angularPackageBundler . bundle ( 'umd' ) ; AngularPackageLogger . logTaskSuccess ( ) ; } param angularPackage returns private static async compose ( angularPackage ) { const angularPackageComposer = new AngularPackageComposer ( angularPackage ) ; AngularPackageLogger . logTaskStart ( 'Compose package' ) ; await angularPackageComposer . compose ( ) ; AngularPackageLogger . logTaskSuccess ( ) ; } param angularPackage returns private static async cleanupOutputFolder ( angularPackage ) { try { await del ( [ path . join ( angularPackage . root , angularPackage . outDir , '**' ) ] ) ; } catch ( error ) { throw new Error ( `An error occured while deleting the output folder at "${ angularPackage . outDir }".` ) ; } } param angularPackage returns private static async cleanupTemporaryOutputFolder ( angularPackage ) { try { await del ( [ path . join ( angularPackage . root , angularPackage . outDir , 'temp' , '**' ) ] ) ; } catch ( error ) { throw new Error ( `An error occured while deleting the temporary output folder at "${ angularPackage . outDir }/temp".` ) ; } } }