11import { task , src , dest } from 'gulp' ;
22import { Dgeni } from 'dgeni' ;
33import * as path from 'path' ;
4- import { HTML_MINIFIER_OPTIONS } from '../constants' ;
4+ import { DIST_ROOT , HTML_MINIFIER_OPTIONS , SOURCE_ROOT } from '../constants' ;
55
66// There are no type definitions available for these imports.
77const markdown = require ( 'gulp-markdown' ) ;
@@ -13,6 +13,8 @@ const htmlmin = require('gulp-htmlmin');
1313const hljs = require ( 'highlight.js' ) ;
1414const dom = require ( 'gulp-dom' ) ;
1515
16+ const DIST_DOCS = path . join ( DIST_ROOT , 'docs' ) ;
17+
1618// Our docs contain comments of the form `<!-- example(...) -->` which serve as placeholders where
1719// example code should be inserted. We replace these comments with divs that have a
1820// `material-docs-example` attribute which can be used to locate the divs and initialize the example
@@ -46,8 +48,17 @@ const MARKDOWN_TAGS_TO_CLASS_ALIAS = [
4648 'code' ,
4749] ;
4850
49- task ( 'docs' , [ 'markdown-docs' , 'highlight-docs' , 'api-docs' , 'minify-html-docs' ] ) ;
5051
52+ /** Generate all docs content. */
53+ task ( 'docs' , [
54+ 'markdown-docs' ,
55+ 'highlight-examples' ,
56+ 'api-docs' ,
57+ 'minified-api-docs' ,
58+ 'plunker-example-assets' ,
59+ ] ) ;
60+
61+ /** Generates html files from the markdown overviews and guides. */
5162task ( 'markdown-docs' , ( ) => {
5263 return src ( [ 'src/lib/**/*.md' , 'guides/*.md' ] )
5364 . pipe ( markdown ( {
@@ -67,7 +78,11 @@ task('markdown-docs', () => {
6778 . pipe ( dest ( 'dist/docs/markdown' ) ) ;
6879} ) ;
6980
70- task ( 'highlight-docs' , ( ) => {
81+ /**
82+ * Creates syntax-highlighted html files from the examples to be used for the source view of
83+ * live examples on the docs site.
84+ */
85+ task ( 'highlight-examples' , ( ) => {
7186 // rename files to fit format: [filename]-[filetype].html
7287 const renameFile = ( path : any ) => {
7388 const extension = path . extname . slice ( 1 ) ;
@@ -81,18 +96,26 @@ task('highlight-docs', () => {
8196 . pipe ( dest ( 'dist/docs/examples' ) ) ;
8297} ) ;
8398
99+ /** Generates API docs from the source JsDoc using dgeni. */
84100task ( 'api-docs' , ( ) => {
85101 const docsPackage = require ( path . resolve ( __dirname , '../../dgeni' ) ) ;
86102 const docs = new Dgeni ( [ docsPackage ] ) ;
87103 return docs . generate ( ) ;
88104} ) ;
89105
90- task ( 'minify-html-docs' , [ 'api-docs' ] , ( ) => {
106+ /** Generates minified html api docs. */
107+ task ( 'minified-api-docs' , [ 'api-docs' ] , ( ) => {
91108 return src ( 'dist/docs/api/*.html' )
92109 . pipe ( htmlmin ( HTML_MINIFIER_OPTIONS ) )
93110 . pipe ( dest ( 'dist/docs/api/' ) ) ;
94111} ) ;
95112
113+ /** Copies example sources to be used as plunker assets for the docs site. */
114+ task ( 'plunker-example-assets' , ( ) => {
115+ src ( path . join ( SOURCE_ROOT , 'examples' , '**/*' ) )
116+ . pipe ( dest ( path . join ( DIST_DOCS , 'plunker' , 'examples' ) ) ) ;
117+ } ) ;
118+
96119/** Updates the markdown file's content to work inside of the docs app. */
97120function transformMarkdownFiles ( buffer : Buffer , file : any ) : string {
98121 let content = buffer . toString ( 'utf-8' ) ;
0 commit comments