11import gulp = require( 'gulp' ) ;
22const markdown = require ( 'gulp-markdown' ) ;
33const 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' ) ;
48const hljs = require ( 'highlight.js' ) ;
9+ const exec = require ( 'child_process' ) . exec ;
510import { task } from 'gulp' ;
611import * as path from 'path' ;
712
@@ -16,7 +21,7 @@ const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/g;
1621// documentation page. Using a RegExp to rewrite links in HTML files to work in the docs.
1722const LINK_PATTERN = / ( < a [ ^ > ] * ) h r e f = " ( [ ^ " ] * ) " / g;
1823
19- gulp . task ( 'docs' , [ 'markdown-docs' , 'api-docs' ] )
24+ gulp . task ( 'docs' , [ 'markdown-docs' , 'highlight-docs' , ' api-docs'] )
2025
2126gulp . task ( 'markdown-docs' , ( ) => {
2227 return gulp . src ( [ 'src/lib/**/*.md' , 'guides/*.md' ] )
@@ -36,6 +41,40 @@ gulp.task('markdown-docs', () => {
3641 . pipe ( gulp . dest ( 'dist/docs/markdown' ) ) ;
3742} ) ;
3843
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+
3978task ( 'api-docs' , ( ) => {
4079 const Dgeni = require ( 'dgeni' ) ;
4180 const docsPackage = require ( path . resolve ( __dirname , '../../dgeni' ) ) ;
0 commit comments