1
1
import gulp = require( 'gulp' ) ;
2
2
const markdown = require ( 'gulp-markdown' ) ;
3
3
const transform = require ( 'gulp-transform' ) ;
4
+ const filter = require ( 'gulp-filter' ) ;
5
+ const highlight = require ( 'gulp-highlight-files' ) ;
6
+ const rename = require ( 'gulp-rename' ) ;
7
+ const flatten = require ( 'gulp-flatten' ) ;
4
8
const hljs = require ( 'highlight.js' ) ;
9
+ const exec = require ( 'child_process' ) . exec ;
5
10
import { task } from 'gulp' ;
6
11
import * as path from 'path' ;
7
12
@@ -16,7 +21,7 @@ const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/g;
16
21
// documentation page. Using a RegExp to rewrite links in HTML files to work in the docs.
17
22
const LINK_PATTERN = / ( < a [ ^ > ] * ) h r e f = " ( [ ^ " ] * ) " / g;
18
23
19
- gulp . task ( 'docs' , [ 'markdown-docs' , 'api-docs' ] )
24
+ gulp . task ( 'docs' , [ 'markdown-docs' , 'highlight-docs' , ' api-docs'] )
20
25
21
26
gulp . task ( 'markdown-docs' , ( ) => {
22
27
return gulp . src ( [ 'src/lib/**/*.md' , 'guides/*.md' ] )
@@ -36,6 +41,40 @@ gulp.task('markdown-docs', () => {
36
41
. pipe ( gulp . dest ( 'dist/docs/markdown' ) ) ;
37
42
} ) ;
38
43
44
+ gulp . task ( 'highlight-docs' , ( ) => {
45
+ const cssFilter = filter ( '**/*.css' , { restore : true } ) ;
46
+ const tsFilter = filter ( '**/*.ts' , { restore : true } ) ;
47
+ const htmlFilter = filter ( '**/*.html' , { restore : true } ) ;
48
+
49
+ // rename files to fit format: [filename]-[filetype].html
50
+ const renameFile = ( path : any ) => {
51
+ const extension = path . extname . slice ( 1 ) ;
52
+ path . basename = `${ path . basename } -${ extension } ` ;
53
+ } ;
54
+
55
+ gulp . src ( [ 'src/examples/**/*.{css,ts,html}' , '!src/examples/*.*' ] )
56
+ // Flatten structure so that examples folder has no nested dirs
57
+ . pipe ( flatten ( ) )
58
+
59
+ . pipe ( htmlFilter )
60
+ . pipe ( rename ( renameFile ) )
61
+ . pipe ( highlight ( { language : 'html' } ) )
62
+ . pipe ( gulp . dest ( 'dist/docs/examples' ) )
63
+ . pipe ( htmlFilter . restore )
64
+
65
+ . pipe ( cssFilter )
66
+ . pipe ( rename ( renameFile ) )
67
+ . pipe ( highlight ( { language : 'css' } ) )
68
+ . pipe ( gulp . dest ( 'dist/docs/examples' ) )
69
+ . pipe ( cssFilter . restore )
70
+
71
+ . pipe ( tsFilter )
72
+ . pipe ( rename ( renameFile ) )
73
+ . pipe ( highlight ( { language : 'ts' } ) )
74
+ . pipe ( gulp . dest ( 'dist/docs/examples' ) )
75
+ . pipe ( tsFilter . restore ) ;
76
+ } ) ;
77
+
39
78
task ( 'api-docs' , ( ) => {
40
79
const Dgeni = require ( 'dgeni' ) ;
41
80
const docsPackage = require ( path . resolve ( __dirname , '../../dgeni' ) ) ;
0 commit comments