1 |
|
2 |
|
3 |
|
4 |
|
5 | import * as gulp from 'gulp'
|
6 | import * as inject from 'gulp-inject'
|
7 | import * as replace from 'gulp-replace'
|
8 |
|
9 | const buildReadMe = () => {
|
10 |
|
11 | const timplaConfigInterface = gulp.src('gulpfile.ts/lib/timplaInterfaces.ts')
|
12 | const timplaConfig = gulp.src('.timplaconfig.js').pipe(replace('./lib/public', 'timpla'))
|
13 | const babelConfig = gulp.src('babel.config.js')
|
14 |
|
15 | const transformJSCodeBlock = (filePath: string, file: any) => {
|
16 | const utText = file.contents.toString('utf8')
|
17 | const extractMatches = utText.match(/\/\/(.?)@extract([\s\S]*?)@endextract/gi)
|
18 | const contents = !!extractMatches
|
19 | ? extractMatches.join('').replace(/\/\/.?@(end)?extract/g, '')
|
20 | : utText
|
21 | const extensionMatchers: any = {
|
22 | js: 'javascript',
|
23 | md: 'markdown',
|
24 | sh: 'shell',
|
25 | ts: 'typescript',
|
26 | }
|
27 | const ext = filePath.split('.').pop()!
|
28 | const extToUse = extensionMatchers[ext] || ext
|
29 |
|
30 |
|
31 | return ['```' + extToUse, contents, '```'].join('\n')
|
32 | }
|
33 |
|
34 | return gulp
|
35 | .src('local.gulpfile.ts/README.md')
|
36 | .pipe(
|
37 | inject(timplaConfigInterface, {
|
38 | starttag: '<!-- inject:timpla_config:{{ext}} -->',
|
39 | transform: transformJSCodeBlock,
|
40 | })
|
41 | )
|
42 | .pipe(
|
43 | inject(timplaConfig, {
|
44 | starttag: '<!-- inject:timpla_config_basic:{{ext}} -->',
|
45 | transform: transformJSCodeBlock,
|
46 | })
|
47 | )
|
48 | .pipe(
|
49 | inject(babelConfig, {
|
50 | starttag: '<!-- inject:babel:{{ext}} -->',
|
51 | transform: transformJSCodeBlock,
|
52 | })
|
53 | )
|
54 | .pipe(gulp.dest('./'))
|
55 | }
|
56 |
|
57 | export default buildReadMe
|