-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.babel.js
129 lines (116 loc) · 4.13 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
/*jshint esversion: 6 */
'use strict';
const gulp = require('gulp'),
babelify = require('babelify'),
bitcoin = require('bitcoinjs-lib'),
browserify = require('browserify'),
buffer = require('vinyl-buffer'),
cache = require('gulp-cache'),
defmod = require('gulp-define-module'),
deployment = require('./deployment'),
del = require('del'),
fs = require('fs'),
gulpIf = require('gulp-if'),
handlebars = require('gulp-handlebars'),
imagemin = require('gulp-imagemin'),
minify = require('gulp-minify'),
rename = require('gulp-rename'),
runSequence = require('run-sequence'),
size = require('gulp-size'),
source = require('vinyl-source-stream'),
config = {
name: 'contre',
fileTypes: {
all: '**/*',
handlebars: {
raw: '**/*.hbs',
compiled: '**/*.chbs.js'
},
html: '**/*.html',
images: '**/*.+(png|jpg|jpeg|gif|svg)',
js: 'js/**/*.js',
main: 'js/main.js',
zeronet: {
settings: '**/content.json'
}
},
source: {
baseDir: 'src',
images: 'images'
},
staging: {
baseDir: 'staging',
javascript: 'js'
},
distribution: {
baseDir: 'dist',
javascript: 'js',
images: 'images'
}
};
gulp.task('clean:stage', function () {
let stagingDir = `${config.staging.baseDir}/${config.fileTypes.all}`;
return del.sync(stagingDir);
});
gulp.task('clean:dist', function () {
let distributionDir = `${config.distribution.baseDir}/${config.fileTypes.all}`;
return del.sync(distributionDir);
});
gulp.task('javascript', function () {
let sourceDir = `${config.source.baseDir}/${config.fileTypes.js}`,
stagingDir = `${config.staging.baseDir}/${config.staging.javascript}`;
return gulp.src(sourceDir)
.pipe(gulp.dest(stagingDir));
});
gulp.task('handlebars', function () {
let handlebarSource = `${config.source.baseDir}/${config.fileTypes.handlebars.raw}`,
stagingDir = `${config.staging.baseDir}`;
return gulp.src(handlebarSource)
.pipe(handlebars())
.pipe(defmod('node'))
.pipe(rename({
extname: '.chbs.js'
}))
.pipe(gulp.dest(stagingDir));
});
gulp.task('bundle:javascript', ['handlebars', 'javascript'], function () {
let mainFile = `${config.staging.baseDir}/${config.fileTypes.main}`,
distributionDir = `${config.distribution.baseDir}/${config.distribution.javascript}`;
return browserify(mainFile)
.transform(babelify, { presets: ['es2015'] })
.bundle()
.pipe(source(config.name + '.js'))
.pipe(buffer())
.pipe(minify())
.pipe(size())
.pipe(gulp.dest(distributionDir));
});
gulp.task('images', function () {
let sourceDir = `${config.source.baseDir}/${config.source.images}/${config.fileTypes.images}`,
distributionDir = `${config.distribution.baseDir}/${config.distribution.images}`;
return gulp.src(sourceDir)
// caching images that ran through imagemin
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest(distributionDir));
});
gulp.task('html', function () {
let htmlFiles = `${config.source.baseDir}/${config.fileTypes.html}`;
return gulp.src(htmlFiles)
.pipe(gulp.dest(config.distribution.baseDir));
});
gulp.task('build', function (callback) {
runSequence('clean:dist', 'clean:stage', ['html', 'images', 'bundle:javascript'],
callback);
});
gulp.task('deploy:dev', function () {
let distributionDir = `${config.distribution.baseDir}/${config.fileTypes.all}`,
deploymentDir = `${deployment.zeronet.baseDir}/${deployment.development.address}`;
return gulp.src(distributionDir)
.pipe(gulp.dest(deploymentDir));
});
function signSiteFile(environmentSettings) {
let deploymentDir = `${deployment.zeronet.baseDir}/${environmentSettings.address}`,
siteFilePath = `${deploymentDir}/content.json}`;
}