This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
gulpfile.babel.js
142 lines (123 loc) · 3.93 KB
/
gulpfile.babel.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
import yargs from 'yargs';
const argv = yargs.argv;
import gulp from 'gulp';
import path from 'path';
import fs from 'fs';
import grommetToolbox, {getOptions} from 'grommet-toolbox';
import del from 'del';
import mkdirp from 'mkdirp';
import gulpWebpack from 'webpack-stream';
const options = getOptions();
gulp.task('set-webpack-alias', () => {
if (options.alias && argv.useAlias) {
console.log('Using local alias for development.');
options.webpack.resolve.alias = options.alias;
}
});
gulp.task('generate-static-site', ['generate-icons-map'], () => {
var staticSiteConfig = require('./site-generator.webpack.config');
options.copyAssets = options.copyAssets.splice(1);
return gulp.src(options.mainJs)
.pipe(gulpWebpack(staticSiteConfig))
.pipe(gulp.dest(options.dist));
});
gulp.task('generate-icons-map', (done) => {
var iconsFolder = path.join(__dirname, './node_modules/grommet/img/icons');
var iconsMap = ['module.exports = {'];
fs.readdir(iconsFolder, function(err, icons) {
icons.forEach(function (icon, index) {
if (/\.svg$/.test(icon)) {
var componentName = icon.replace('.svg', '.js');
componentName = componentName.replace(/^(.)|-([a-z])/g, function (g) {
return g.length > 1 ? g[1].toUpperCase() : g.toUpperCase();
});
var grommetIconPath = "grommet/components/icons/base/";
iconsMap.push(
" \"" + icon.replace('.svg', '') + "\":\n" +
" require('" + grommetIconPath + componentName + "')"
);
if (index === icons.length - 1) {
iconsMap.push('};\n');
var destinationFile = path.join(__dirname,
'src/docs/components/iconsMap.js');
fs.writeFile(destinationFile, iconsMap.join("\n"), function(err) {
if (err) {
throw err;
}
done();
});
} else {
iconsMap.push(',');
}
}
});
});
});
gulp.task('release:createTmp', (done) => {
del.sync(['./tmp']);
mkdirp('./tmp', function(err) {
if (err) {
throw err;
}
done();
});
});
gulp.task('release:gh-pages', ['dist', 'release:createTmp'], (done) => {
if (process.env.CI) {
const git = require('gulp-git');
git.clone('https://' + process.env.GH_TOKEN +
'@github.com/grommet/grommet.github.io.git',
{
cwd: './tmp/'
},
function(err) {
if (err) {
throw err;
}
process.chdir('./tmp/grommet.github.io');
git.checkout('master', (err) => {
if (err) {
throw err;
}
del.sync(['./**/*']);
gulp.src(['../../dist/**', '../../dist/CNAME'])
.pipe(gulp.dest('./')).on('end', () => {
git.status({
args: '--porcelain'
}, function(err, stdout) {
if (err) {
throw err;
}
if (stdout && stdout !== '') {
gulp.src('./')
.pipe(git.add({
args: '--all'
}))
.pipe(git.commit('Heroku dev version update.'))
.on('end', () => {
git.push('origin', 'master', { quiet: true }, (err) => {
if (err) {
throw err;
}
process.chdir(__dirname);
done();
});
});
} else {
console.log("No difference since last commit, " +
"skipping gh-pages release.");
process.chdir(__dirname);
done();
}
});
});
});
}
);
} else {
console.warn("Skipping release. Release:gh-pages task should be " +
"executed by CI only.");
}
});
grommetToolbox(gulp, options);