forked from pivotal-cf/pivotal-ui
-
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.
- Loading branch information
1 parent
0c4ca64
commit 934f2ad
Showing
8 changed files
with
122 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,5 @@ vendor/ruby | |
|
||
## Sinopia storage | ||
/.sinopia/storage | ||
|
||
src/react/iconography/icons.js |
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
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 |
---|---|---|
@@ -1,19 +1,79 @@ | ||
import del from 'del'; | ||
import gulp from 'gulp'; | ||
import runSequence from 'run-sequence'; | ||
import svgToJs from 'svg-to-jsx'; | ||
import fs from 'fs'; | ||
|
||
const plugins = require('gulp-load-plugins')(); | ||
const COPYRIGHT = '/*(c) Copyright 2015 Pivotal Software, Inc. All Rights Reserved.*/\n'; | ||
const srcFolder = 'src/react'; | ||
const buildFolder = 'dist/react'; | ||
|
||
gulp.task('react-build-src', function() { | ||
return gulp.src('src/react/**/*.js') | ||
function readdir(path) { | ||
return new Promise((res, rej) => { | ||
fs.readdir(path, (err, items) => { | ||
if (err) return rej(err); | ||
res(items); | ||
}); | ||
}); | ||
} | ||
|
||
function readFile(path) { | ||
return new Promise((res, rej) => { | ||
fs.readFile(path, (err, data) => { | ||
if (err) return rej(err); | ||
res(data); | ||
}); | ||
}); | ||
} | ||
|
||
function mkdir(path) { | ||
return new Promise((res, rej) => { | ||
fs.mkdir(path, err => { | ||
if (err) return rej(err); | ||
res(); | ||
}); | ||
}); | ||
} | ||
|
||
function writeFile(path, data) { | ||
return new Promise((res, rej) => { | ||
fs.writeFile(path, data, err => { | ||
if (err) return rej(err); | ||
res(); | ||
}); | ||
}); | ||
} | ||
|
||
gulp.task('react-build-src', function () { | ||
return gulp.src(`${srcFolder}/**/*.js`) | ||
.pipe(plugins.plumber()) | ||
.pipe(plugins.babel()) | ||
.pipe(plugins.header(COPYRIGHT)) | ||
.pipe(gulp.dest(buildFolder)); | ||
}); | ||
|
||
gulp.task('react-build-svgs', async() => { | ||
const items = await readdir('./src/css/iconography/svgs'); | ||
const svgInfos = items.map(item => ({item, promise: readFile(`./src/css/iconography/svgs/${item}`)})); | ||
const svgs = []; | ||
for (let i = 0; i < svgInfos.length; i++) { | ||
const {item, promise} = svgInfos[i]; | ||
const name = item.replace(/\.svg$/, ''); | ||
const svg = await promise; | ||
svgs.push({name, svg}); | ||
} | ||
const jsxInfos = svgs.map(({name, svg}) => ({name, promise: svgToJs(svg)})); | ||
const jsxs = []; | ||
for (let i = 0; i < jsxInfos.length; i++) { | ||
const {name, promise} = jsxInfos[i]; | ||
jsxs.push(` '${name}': (${(await promise).toString()})`); | ||
} | ||
const iconsPath = `${srcFolder}/iconography/icons.js`; | ||
const icons = `import React from 'react';\n\nexport default {\n${jsxs.join(',\n')}\n}`; | ||
await writeFile(iconsPath, icons); | ||
}); | ||
|
||
gulp.task('react-clean', callback => del([buildFolder], callback)); | ||
|
||
gulp.task('react-build', callback => runSequence('react-clean', 'react-build-src', callback)); | ||
gulp.task('react-build', callback => runSequence('react-clean', 'react-build-svgs', 'react-build-src', callback)); |
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