import { mkdirpSync , writeFileSync } from 'fs-extra' ; import { dest , src , task } from 'gulp' ; import { buildConfig , composeRelease , sequenceTask } from 'material2-build-tools' ; import { join } from 'path' ; import { Bundler } from 'scss-bundle' ; import { materialPackage } from '../packages' ; const gulpRename = require ( 'gulp-rename' ) ; const distDir = buildConfig . outputDir ; const { sourceDir , outputDir } = materialPackage ; /** Path to the directory where all releases are created. */ const releasesDir = join ( distDir , 'releases' ) ; const releasePath = join ( releasesDir , 'material' ) ; const themingEntryPointPath = join ( sourceDir , 'core' , 'theming' , '_all-theme.scss' ) ; const themingBundlePath = join ( releasePath , '_theming.scss' ) ; const prebuiltThemeGlob = join ( outputDir , '**/theming/prebuilt/*.css?(.map)' ) ; const allScssDedupeGlob = join ( buildConfig . packagesDir , '**/*.scss' ) ; /**
 * Overwrite the release task for the material package. The material release will include special
 * files, like a bundled theming SCSS file or all prebuilt themes.
 */ task ( 'material:build-release' , [ 'material:prepare-release' ] , ( ) => composeRelease ( materialPackage ) ) ; /**
 * Task that will build the material package. Special treatment for this package includes:
 * - Copying all prebuilt themes into the package
 * - Bundling theming scss into a single theming file
 */ task ( 'material:prepare-release' , sequenceTask ( [ 'material:build' ] , [ 'material:copy-prebuilt-themes' , 'material:bundle-theming-scss' ] ) ) ; /** Copies all prebuilt themes into the release package under `prebuilt-themes/` */ task ( 'material:copy-prebuilt-themes' , ( ) => { return src ( prebuiltThemeGlob ) . pipe ( gulpRename ( { dirname : '' } ) ) . pipe ( dest ( join ( releasePath , 'prebuilt-themes' ) ) ) ; } ) ; /** Bundles all scss requires for theming into a single scss file in the root of the package. */ task ( 'material:bundle-theming-scss' , ( ) => { return new Bundler ( ) . Bundle ( themingEntryPointPath , [ allScssDedupeGlob ] ) . then ( result => { mkdirpSync ( releasePath ) ; writeFileSync ( themingBundlePath , result . bundledContent ) ; } ) ; } ) ;