1
1
import { task , src , dest } from 'gulp' ;
2
2
import { Dgeni } from 'dgeni' ;
3
3
import * as path from 'path' ;
4
- import { HTML_MINIFIER_OPTIONS } from '../constants' ;
4
+ import { DIST_ROOT , HTML_MINIFIER_OPTIONS , SOURCE_ROOT } from '../constants' ;
5
5
6
6
// There are no type definitions available for these imports.
7
7
const markdown = require ( 'gulp-markdown' ) ;
@@ -13,6 +13,8 @@ const htmlmin = require('gulp-htmlmin');
13
13
const hljs = require ( 'highlight.js' ) ;
14
14
const dom = require ( 'gulp-dom' ) ;
15
15
16
+ const DIST_DOCS = path . join ( DIST_ROOT , 'docs' ) ;
17
+
16
18
// Our docs contain comments of the form `<!-- example(...) -->` which serve as placeholders where
17
19
// example code should be inserted. We replace these comments with divs that have a
18
20
// `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 = [
46
48
'code' ,
47
49
] ;
48
50
49
- task ( 'docs' , [ 'markdown-docs' , 'highlight-docs' , 'api-docs' , 'minify-html-docs' ] ) ;
50
51
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. */
51
62
task ( 'markdown-docs' , ( ) => {
52
63
return src ( [ 'src/lib/**/*.md' , 'guides/*.md' ] )
53
64
. pipe ( markdown ( {
@@ -67,7 +78,11 @@ task('markdown-docs', () => {
67
78
. pipe ( dest ( 'dist/docs/markdown' ) ) ;
68
79
} ) ;
69
80
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' , ( ) => {
71
86
// rename files to fit format: [filename]-[filetype].html
72
87
const renameFile = ( path : any ) => {
73
88
const extension = path . extname . slice ( 1 ) ;
@@ -81,18 +96,26 @@ task('highlight-docs', () => {
81
96
. pipe ( dest ( 'dist/docs/examples' ) ) ;
82
97
} ) ;
83
98
99
+ /** Generates API docs from the source JsDoc using dgeni. */
84
100
task ( 'api-docs' , ( ) => {
85
101
const docsPackage = require ( path . resolve ( __dirname , '../../dgeni' ) ) ;
86
102
const docs = new Dgeni ( [ docsPackage ] ) ;
87
103
return docs . generate ( ) ;
88
104
} ) ;
89
105
90
- task ( 'minify-html-docs' , [ 'api-docs' ] , ( ) => {
106
+ /** Generates minified html api docs. */
107
+ task ( 'minified-api-docs' , [ 'api-docs' ] , ( ) => {
91
108
return src ( 'dist/docs/api/*.html' )
92
109
. pipe ( htmlmin ( HTML_MINIFIER_OPTIONS ) )
93
110
. pipe ( dest ( 'dist/docs/api/' ) ) ;
94
111
} ) ;
95
112
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
+
96
119
/** Updates the markdown file's content to work inside of the docs app. */
97
120
function transformMarkdownFiles ( buffer : Buffer , file : any ) : string {
98
121
let content = buffer . toString ( 'utf-8' ) ;
0 commit comments