-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgulpfile.js
More file actions
63 lines (54 loc) · 1.67 KB
/
gulpfile.js
File metadata and controls
63 lines (54 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { watch, src, dest, series } = require('gulp');
const inject = require('gulp-inject-string');
const flatten = require('gulp-flatten');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const docsDest = 'docs/src/pages/components';
const mdxSrcGlob = 'core/src/**/*.{md,mdx}';
const mdxLoader =
`import { Playground } from 'docz';
import { JSCodeBlock } from '@components/JSCodeBlock';
import { defineCustomElements } from '@accera/solar-components.core/dist/loader';
defineCustomElements(window);
`;
/**
* Copy all mdx files to docs package.
* @param glob The glob rule to run.
* @param [customDest] The dest path.
* @returns {*}
*/
function docsCopy(glob, customDest) {
return src(glob)
.pipe(replace(
/^````html(.+?(?=````))````$/gms,
'<Playground>$1</Playground>',
{ logs: { enabled: false } })
)
.pipe(replace(
/^````js(.+?(?=````))````$/gms,
'<JSXCodeBlock>{`$1`}</JSXCodeBlock>',
{ logs: { enabled: false } })
)
.pipe(inject.after('\n---\n', mdxLoader))
.pipe(flatten({ includeParents: -1 }))
.pipe(rename(path => {
path.basename = 'code';
path.extname = '.mdx'
}))
.pipe(dest(customDest || docsDest));
}
function docsWatch() {
const watcher = watch(mdxSrcGlob);
watcher.on('change', docsCopyFromPath);
watcher.on('add', docsCopyFromPath);
return watcher;
}
function docsCopyAll() {
return docsCopy(mdxSrcGlob);
}
function docsCopyFromPath(path) {
const splittedPath = path.split('/');
return docsCopy(path, docsDest + '/', splittedPath[splittedPath.length - 2])
}
exports.docsCopy = docsCopyAll;
exports.docsWatch = series(docsCopyAll, docsWatch);