1
1
import gulp from "gulp" ;
2
2
import cp from "child_process" ;
3
- import hugoBin from "hugo-bin"
3
+ import hugoBin from "hugo-bin" ;
4
4
import gutil from "gulp-util" ;
5
5
import postcss from "gulp-postcss" ;
6
+ import transform from "gulp-transform" ;
7
+ import yaml from "yamljs" ;
8
+ import rename from "gulp-rename" ;
6
9
import cssImport from "postcss-import" ;
7
10
import neatgrid from "postcss-neat" ;
8
11
import nestedcss from "postcss-nested" ;
@@ -18,53 +21,94 @@ import webpackConfig from "./webpack.conf";
18
21
const browserSync = BrowserSync . create ( ) ;
19
22
const defaultArgs = [ "-d" , "../dist" , "-s" , "site" , "-v" ] ;
20
23
21
- gulp . task ( "hugo" , ( cb ) => buildSite ( cb ) ) ;
22
- gulp . task ( "hugo-preview" , ( cb ) => buildSite ( cb , [ "--buildDrafts" , "--buildFuture" ] ) ) ;
24
+ function buildSite ( cb , options ) {
25
+ const args = options ? defaultArgs . concat ( options ) : defaultArgs ;
26
+ return cp . spawn ( hugoBin , args , { stdio : "inherit" } ) . on ( "close" , code => {
27
+ if ( code === 0 ) {
28
+ browserSync . reload ( ) ;
29
+ cb ( ) ;
30
+ } else {
31
+ browserSync . notify ( "Hugo build failed :(" ) ;
32
+ cb ( "Hugo build failed" ) ;
33
+ }
34
+ } ) ;
35
+ }
36
+
37
+ gulp . task ( "hugo" , [ "copy" ] , cb => buildSite ( cb ) ) ;
38
+ gulp . task ( "hugo-preview" , [ "copy" ] , cb =>
39
+ buildSite ( cb , [ "--buildDrafts" , "--buildFuture" ] )
40
+ ) ;
23
41
24
42
gulp . task ( "build" , [ "css" , "js" , "fonts" , "images" , "hugo" ] ) ;
25
43
gulp . task ( "build-preview" , [ "css" , "js" , "fonts" , "images" , "hugo-preview" ] ) ;
26
44
27
- gulp . task ( "css" , ( ) => (
28
- gulp . src ( "./src/css/**/*.css" )
29
- . pipe ( postcss ( [
30
- cssImport ( { from : "./src/css/main.css" } ) ,
31
- neatgrid ( ) ,
32
- nestedcss ( ) ,
33
- colorfunctions ( ) ,
34
- hdBackgrounds ( ) ,
35
- cssextend ( ) ,
36
- cssvars ( { variables : styleVariables } ) ] ) )
45
+ gulp . task ( "css" , ( ) =>
46
+ gulp
47
+ . src ( "./src/css/**/*.css" )
48
+ . pipe (
49
+ postcss ( [
50
+ cssImport ( { from : "./src/css/main.css" } ) ,
51
+ neatgrid ( ) ,
52
+ nestedcss ( ) ,
53
+ colorfunctions ( ) ,
54
+ hdBackgrounds ( ) ,
55
+ cssextend ( ) ,
56
+ cssvars ( { variables : styleVariables } )
57
+ ] )
58
+ )
37
59
. pipe ( gulp . dest ( "./dist/css" ) )
38
60
. pipe ( browserSync . stream ( ) )
39
- ) ) ;
61
+ ) ;
40
62
41
- gulp . task ( "js" , ( cb ) => {
63
+ gulp . task ( "js" , cb => {
42
64
const myConfig = Object . assign ( { } , webpackConfig ) ;
43
65
44
66
webpack ( myConfig , ( err , stats ) => {
45
67
if ( err ) throw new gutil . PluginError ( "webpack" , err ) ;
46
- gutil . log ( "[webpack]" , stats . toString ( {
47
- colors : true ,
48
- progress : true
49
- } ) ) ;
68
+ gutil . log (
69
+ "[webpack]" ,
70
+ stats . toString ( {
71
+ colors : true ,
72
+ progress : true
73
+ } )
74
+ ) ;
50
75
browserSync . reload ( ) ;
51
76
cb ( ) ;
52
77
} ) ;
53
78
} ) ;
54
79
55
- gulp . task ( "fonts" , ( ) => (
56
- gulp . src ( "./src/fonts/**/*" )
80
+ gulp . task ( "fonts" , ( ) =>
81
+ gulp
82
+ . src ( "./src/fonts/**/*" )
57
83
. pipe ( gulp . dest ( "./dist/fonts" ) )
58
84
. pipe ( browserSync . stream ( ) )
59
- ) ) ;
85
+ ) ;
60
86
61
- gulp . task ( "images" , ( ) => (
62
- gulp . src ( "./src/img/**/*" )
87
+ gulp . task ( "images" , ( ) =>
88
+ gulp
89
+ . src ( "./src/img/**/*" )
63
90
. pipe ( gulp . dest ( "./dist/img" ) )
64
91
. pipe ( browserSync . stream ( ) )
65
- ) ) ;
92
+ ) ;
93
+
94
+ gulp . task ( "copy" , ( ) =>
95
+ gulp
96
+ . src ( "../.all-contributorsrc" )
97
+ . pipe (
98
+ transform (
99
+ "utf8" ,
100
+ content =>
101
+ new Promise ( ( resolve , reject ) => {
102
+ const contributors = JSON . parse ( content ) ;
103
+ resolve ( yaml . dump ( { contributors : contributors . contributors } ) ) ;
104
+ } )
105
+ )
106
+ )
107
+ . pipe ( rename ( "contributors.yml" ) )
108
+ . pipe ( gulp . dest ( "./site/data" ) )
109
+ ) ;
66
110
67
- gulp . task ( "server" , [ "hugo" , " css", "js" , "fonts" , "images" ] , ( ) => {
111
+ gulp . task ( "server" , [ "css" , "js" , "fonts" , "images" , "hugo "] , ( ) => {
68
112
browserSync . init ( {
69
113
server : {
70
114
baseDir : "./dist"
@@ -77,18 +121,3 @@ gulp.task("server", ["hugo", "css", "js", "fonts", "images"], () => {
77
121
gulp . watch ( "./src/fonts/**/*" , [ "fonts" ] ) ;
78
122
gulp . watch ( "./site/**/*" , [ "hugo" ] ) ;
79
123
} ) ;
80
-
81
- function buildSite ( cb , options ) {
82
- const args = options ? defaultArgs . concat ( options ) : defaultArgs ;
83
-
84
- return cp . spawn ( hugoBin , args , { stdio : "inherit" } ) . on ( "close" , ( code ) => {
85
- if ( code === 0 ) {
86
- browserSync . reload ( ) ;
87
- cb ( ) ;
88
- } else {
89
- browserSync . notify ( "Hugo build failed :(" ) ;
90
- cb ( "Hugo build failed" ) ;
91
- }
92
- } ) ;
93
- }
94
-
0 commit comments