This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
167 lines (140 loc) · 4.2 KB
/
gulpfile.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const vueify = require('vueify')
const gulp = require('gulp')
const browserify = require('browserify')
const source = require('vinyl-source-stream')
const gutil = require('gulp-util')
const sourcemaps = require('gulp-sourcemaps')
const buffer = require('vinyl-buffer')
const sass = require('gulp-sass')
const minify = require('gulp-minify-css')
const concat = require('gulp-concat')
const path = require('path')
const { exec } = require('child_process')
const paths = {
content: './src/content.json',
entries: ['src/js/index.js'],
src: {
static: ['src/**/*', '!src/css/**/*.css', '!src/sass/**/*.sass', '!src/js/**/*.js', '!src/main.js'],
styles: ['src/css/**/*.css', '.src/sass/**/*.sass'],
scripts: ['src/js/**/*.js']
},
dist: {
static: 'dist/',
styles: 'dist/css/',
scripts: 'dist/js/'
}
}
gulp.task('static', function () {
return gulp.src(paths.src.static)
.pipe(gulp.dest(paths.dist.static))
})
gulp.task('styles', function () {
return gulp.src(paths.src.styles)
.pipe(sass({
'includePaths': [
'node_modules'
]
}).on('error', sass.logError))
.pipe(minify())
.pipe(concat('all.css'))
.pipe(gulp.dest(paths.dist.styles))
})
gulp.task('scripts', function () {
return browserify({
basedir: '.',
debug: true,
entries: paths.entries,
cache: {},
packageCache: {},
insertGlobals: true
})
.transform(vueify)
.bundle()
.pipe(source('all.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.dist.scripts))
})
gulp.task('build', gulp.parallel('scripts', 'styles', 'static'))
gulp.task('watch', function () {
gulp.watch(paths.src.scripts, gulp.series('scripts'))
gulp.watch(paths.src.styles, gulp.series('styles'))
gulp.watch(paths.src.static, gulp.series('static'))
})
gulp.task('deploy', gulp.series('build', function (done) {
let silent = gutil.env.silent
let zeronet = gutil.env.zeronet
let privkey = gutil.env.privkey ? gutil.env.privkey : ''
if (!zeronet) {
throw new gutil.PluginError({
plugin: 'deploy',
message: 'Empty path for ZeroNet installation'
})
}
let content = require(paths.content)
let address = content.address
let from = [ path.join(paths.dist.static, '**/*') ]
let to = path.join(zeronet, 'data', address)
gutil.log('Downloading site')
let download = exec('python zeronet.py siteDownload ' + address, { cwd: zeronet })
if (!silent) {
download.stdout.pipe(process.stdout)
download.stderr.pipe(process.stderr)
}
download.stderr.on('data', function (data) {
if (data.indexOf('Error') >= 0) {
throw new gutil.PluginError({
plugin: 'deploy',
message: 'Error while downloading'
})
}
})
download.on('exit', function (code, signal) {
gutil.log('Downloading done')
gulp.src(from)
.pipe(gulp.dest(to))
gutil.log('Signing site')
let sign = exec('python zeronet.py siteSign ' + address + ' ' + privkey, { cwd: zeronet })
if (!silent) {
sign.stdout.pipe(process.stdout)
sign.stderr.pipe(process.stderr)
}
sign.stderr.on('data', function (data) {
if (data.indexOf('SignError') >= 0) {
throw new gutil.PluginError({
plugin: 'deploy',
message: 'Private key invalid'
})
}
if (data.indexOf('Error') >= 0) {
throw new gutil.PluginError({
plugin: 'deploy',
message: 'Error while signing'
})
}
})
sign.on('exit', function (code, signal) {
gutil.log('Signing done')
gutil.log('Publishing site')
let publish = exec('python zeronet.py sitePublish ' + address, { cwd: zeronet })
if (!silent) {
publish.stdout.pipe(process.stdout)
publish.stderr.pipe(process.stderr)
}
publish.stderr.on('data', function (data) {
if (data.indexOf('Error') >= 0) {
throw new gutil.PluginError({
plugin: 'deploy',
message: 'Error while publishing'
})
}
})
publish.on('exit', function (code, signal) {
gutil.log('Publishing done')
done()
})
})
})
}))
gulp.task('default', gulp.series('build'))