import { dest , src , task } from 'gulp' ; import { join } from 'path' ; import { tsCompile } from '../ts-compile' ; import { composeRelease } from '../build-release' ; import { inlineResourcesForDirectory } from '../inline-resources' ; import { buildScssPipeline } from './build-scss-pipeline' ; import { sequenceTask } from './sequence-task' ; import { watchFiles } from './watch-files' ; import { BuildPackage } from '../build-package' ; const htmlmin = require ( 'gulp-htmlmin' ) ; const htmlMinifierOptions = { collapseWhitespace : true , removeComments : true , caseSensitive : true , removeAttributeQuotes : false } ; param buildPackage param preBuildTasks export function createPackageBuildTasks ( buildPackage , preBuildTasks = [ ] ) { const taskName = buildPackage . name ; const dependencyNames = buildPackage . dependencies . map ( p => p . name ) ; const styleGlobs = [ join ( buildPackage . sourceDir , '**/*.css' ) , join ( buildPackage . sourceDir , '**/_*.scss' ) , ] ; const htmlGlob = join ( buildPackage . sourceDir , '**/*.html' ) ; const dependentWatchTasks = buildPackage . dependencies . map ( p => `${ p . name }:watch` ) ; const schematicsDir = join ( buildPackage . sourceDir , 'schematics' ) ; const schematicsGlobs = [ join ( schematicsDir , '**/+(data|files)/**/*' ) , join ( schematicsDir , '**/+(schema|collection|migration).json' ) , ] ; /**
     * Main tasks for the package building. Tasks execute the different sub-tasks in the correct
     * order.
     */ task ( `${ taskName }:clean-build` , sequenceTask ( 'clean' , `${ taskName }:build` ) ) ; task ( `${ taskName }:build` , sequenceTask ( ... preBuildTasks , ... dependencyNames . map ( pkgName => `${ pkgName }:build` ) , `${ taskName }:assets` , `${ taskName }:build:esm` , `${ taskName }:assets:inline` , `${ taskName }:build:bundles` ) ) ; task ( `${ taskName }:build-no-bundles` , sequenceTask ( `${ taskName }:assets` , `${ taskName }:build:esm:tests` , `${ taskName }:assets:inline` ) ) ; /**
     * Release tasks for the package. Tasks compose the release output for the package.
     */ task ( `${ taskName }:build-release:clean` , sequenceTask ( 'clean' , `${ taskName }:build-release` ) ) ; task ( `${ taskName }:build-release` , [ `${ taskName }:build` ] , ( ) => composeRelease ( buildPackage ) ) ; /**
     * TypeScript compilation tasks. Tasks are creating ESM, FESM, UMD bundles for releases.
     */ task ( `${ taskName }:build:esm` , ( ) => buildPackage . compile ( ) ) ; task ( `${ taskName }:build:esm:tests` , ( ) => buildPackage . compileTests ( ) ) ; task ( `${ taskName }:build:bundles` , ( ) => buildPackage . createBundles ( ) ) ; /**
     * Asset tasks. Building Sass files and inlining CSS, HTML files into the ESM output.
     */ const assetTasks = [ `${ taskName }:assets:scss` , `${ taskName }:assets:copy-styles` , `${ taskName }:assets:html` ] ; if ( buildPackage . hasSchematics ) { assetTasks . push ( `${ taskName }:assets:schematics` ) ; } task ( `${ taskName }:assets` , assetTasks ) ; task ( `${ taskName }:assets:scss` , ( ) => { buildScssPipeline ( buildPackage . sourceDir , true ) . pipe ( dest ( buildPackage . outputDir ) ) . pipe ( dest ( buildPackage . esm5OutputDir ) ) ; } ) ; task ( `${ taskName }:assets:copy-styles` , ( ) => { return src ( styleGlobs ) . pipe ( dest ( buildPackage . outputDir ) ) . pipe ( dest ( buildPackage . esm5OutputDir ) ) ; } ) ; task ( `${ taskName }:assets:html` , ( ) => { return src ( htmlGlob ) . pipe ( htmlmin ( htmlMinifierOptions ) ) . pipe ( dest ( buildPackage . outputDir ) ) . pipe ( dest ( buildPackage . esm5OutputDir ) ) ; } ) ; task ( `${ taskName }:assets:inline` , ( ) => inlineResourcesForDirectory ( buildPackage . outputDir ) ) ; task ( `${ taskName }:assets:schematics-ts` , ( ) => { return tsCompile ( 'tsc' , [ '-p' , join ( schematicsDir , 'tsconfig.json' ) ] ) ; } ) ; task ( `${ taskName }:assets:schematics` , [ `${ taskName }:assets:schematics-ts` ] , ( ) => { return src ( schematicsGlobs ) . pipe ( dest ( join ( buildPackage . outputDir , 'schematics' ) ) ) ; } ) ; /**
     * Watch tasks, that will rebuild the package whenever TS, SCSS, or HTML files change.
     */ task ( `${ taskName }:watch` , dependentWatchTasks , ( ) => { watchFiles ( join ( buildPackage . sourceDir , '**/*.+(ts|scss|html)' ) , [ `${ taskName }:build` ] ) ; } ) ; }