@@ -2,6 +2,7 @@ import * as historyApiFallback from 'connect-history-api-fallback'
22import * as express from 'express'
33import { task , src , dest , lastRun , parallel , series , watch } from 'gulp'
44import * as remember from 'gulp-remember'
5+ import * as fs from 'fs'
56import * as path from 'path'
67import * as rimraf from 'rimraf'
78import * as through2 from 'through2'
@@ -14,7 +15,9 @@ import config from '../../../config'
1415import gulpComponentMenu from '../plugins/gulp-component-menu'
1516import gulpComponentMenuBehaviors from '../plugins/gulp-component-menu-behaviors'
1617import gulpExampleMenu from '../plugins/gulp-example-menu'
18+ import gulpExampleSource from '../plugins/gulp-example-source'
1719import gulpReactDocgen from '../plugins/gulp-react-docgen'
20+ import { getRelativePathToSourceFile } from '../plugins/util'
1821
1922const { paths } = config
2023const g = require ( 'gulp-load-plugins' ) ( )
@@ -46,13 +49,18 @@ task('clean:docs:example-menus', cb => {
4649 rimraf ( paths . docsSrc ( 'exampleMenus' ) , cb )
4750} )
4851
52+ task ( 'clean:docs:example-sources' , cb => {
53+ rimraf ( paths . docsSrc ( 'exampleSources' ) , cb )
54+ } )
55+
4956task (
5057 'clean:docs' ,
5158 parallel (
5259 'clean:docs:component-menu' ,
5360 'clean:docs:component-menu-behaviors' ,
5461 'clean:docs:dist' ,
5562 'clean:docs:example-menus' ,
63+ 'clean:docs:example-sources' ,
5664 ) ,
5765)
5866
6270
6371const componentsSrc = [ `${ paths . posix . src ( ) } /components/*/[A-Z]*.tsx` , '!**/Slot.tsx' ]
6472const behaviorSrc = [ `${ paths . posix . src ( ) } /lib/accessibility/Behaviors/*/[a-z]*.ts` ]
65- const examplesSrc = `${ paths . posix . docsSrc ( ) } /examples/*/*/*/index.tsx`
73+ const examplesIndexSrc = `${ paths . posix . docsSrc ( ) } /examples/*/*/*/index.tsx`
74+ const examplesSrc = `${ paths . posix . docsSrc ( ) } /examples/*/*/*/!(*index|.knobs).tsx`
6675const markdownSrc = [
6776 '.github/CONTRIBUTING.md' ,
6877 '.github/setup-local-development.md' ,
@@ -92,18 +101,25 @@ task('build:docs:component-menu-behaviors', () =>
92101)
93102
94103task ( 'build:docs:example-menu' , ( ) =>
95- src ( examplesSrc , { since : lastRun ( 'build:docs:example-menu' ) } )
104+ src ( examplesIndexSrc , { since : lastRun ( 'build:docs:example-menu' ) } )
96105 . pipe ( remember ( 'example-menu' ) ) // FIXME: with watch this unnecessarily processes index files for all examples
97106 . pipe ( gulpExampleMenu ( ) )
98107 . pipe ( dest ( paths . docsSrc ( 'exampleMenus' ) ) ) ,
99108)
100109
110+ task ( 'build:docs:example-sources' , ( ) =>
111+ src ( examplesSrc , { since : lastRun ( 'build:docs:example-sources' ) } )
112+ . pipe ( gulpExampleSource ( ) )
113+ . pipe ( dest ( paths . docsSrc ( 'exampleSources' ) ) ) ,
114+ )
115+
101116task (
102117 'build:docs:json' ,
103118 parallel (
104119 series ( 'build:docs:docgen' , 'build:docs:component-menu' ) ,
105120 'build:docs:component-menu-behaviors' ,
106121 'build:docs:example-menu' ,
122+ 'build:docs:example-sources' ,
107123 ) ,
108124)
109125
@@ -218,10 +234,21 @@ task('watch:docs', cb => {
218234 watch ( componentsSrc , series ( 'build:docs:docgen' ) ) . on ( 'change' , handleWatchChange )
219235
220236 // rebuild example menus
221- watch ( examplesSrc , series ( 'build:docs:example-menu' ) )
237+ watch ( examplesIndexSrc , series ( 'build:docs:example-menu' ) )
222238 . on ( 'change' , handleWatchChange )
223239 . on ( 'unlink' , path => handleWatchUnlink ( 'example-menu' , path ) )
224240
241+ watch ( examplesSrc , series ( 'build:docs:example-sources' ) )
242+ . on ( 'change' , handleWatchChange )
243+ . on ( 'unlink' , filePath => {
244+ log ( `File ${ filePath } was deleted, running tasks...` )
245+
246+ const sourceFilename = getRelativePathToSourceFile ( filePath )
247+ const sourcePath = config . paths . docsSrc ( 'exampleSources' , sourceFilename )
248+
249+ fs . unlinkSync ( sourcePath )
250+ } )
251+
225252 watch ( behaviorSrc , series ( 'build:docs:component-menu-behaviors' ) )
226253 . on ( 'change' , handleWatchChange )
227254 . on ( 'unlink' , path => handleWatchUnlink ( 'component-menu-behaviors' , path ) )
0 commit comments