forked from Semantic-Org/Semantic-UI-React
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(plugins): add a plugin for collect sources of examples (Semantic…
…-Org#2986) docs(plugins): add a plugin for collect sources of examples
- Loading branch information
1 parent
b496fba
commit 6edc7f7
Showing
4 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Vinyl from 'vinyl' | ||
import gutil from 'gulp-util' | ||
import _ from 'lodash' | ||
import path from 'path' | ||
import through from 'through2' | ||
|
||
const pluginName = 'gulp-example-source' | ||
|
||
export default () => { | ||
const exampleSources = {} | ||
|
||
function bufferContents(file, enc, cb) { | ||
if (file.isNull()) { | ||
cb(null, file) | ||
return | ||
} | ||
|
||
if (file.isStream()) { | ||
cb(new gutil.PluginError(pluginName, 'Streaming is not supported')) | ||
return | ||
} | ||
|
||
try { | ||
const sourceName = _ | ||
.split(file.path, path.sep) | ||
.slice(-4) | ||
.join('/') | ||
.slice(0, -3) | ||
|
||
exampleSources[sourceName] = file.contents.toString() | ||
cb() | ||
} catch (err) { | ||
const pluginError = new gutil.PluginError(pluginName, err) | ||
pluginError.message += `\nFile: ${file.path}.` | ||
this.emit('error', pluginError) | ||
// eslint-disable-next-line no-console | ||
console.log(err) | ||
} | ||
} | ||
|
||
function endStream(cb) { | ||
const file = new Vinyl({ | ||
path: './exampleSources.json', | ||
contents: Buffer.from(JSON.stringify(exampleSources, null, 2)), | ||
}) | ||
|
||
this.push(file) | ||
cb() | ||
} | ||
|
||
return through.obj(bufferContents, endStream) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters