This repository was archived by the owner on May 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
110 lines (98 loc) · 3.4 KB
/
Copy pathgulpfile.babel.js
File metadata and controls
110 lines (98 loc) · 3.4 KB
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
'use strict'
var args = require('yargs').argv
var browserify = require('browserify')
var gulp = require('gulp')
var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer')
var metaMarkdown = require('gulp-meta-marked')
var browserSync = require('browser-sync').create()
var buildBranch = require('buildbranch')
var sass = require('gulp-sass')
var uglify = require('gulp-uglify')
var rename = require('gulp-rename')
var path = require('path')
var Transform = require('stream').Transform
var React = require('react')
var createReactApp = require('./src/assets/js/app.js')
var prod = args.prod
var baseUrl = 'http://localhost:3000/'
if (prod) {
baseUrl = 'https://boxydev.github.io/wiki-doc/'
}
gulp.task('css', function() {
return gulp.src('src/assets/sass/**/*.scss')
.pipe(sass({outputStyle: (prod) ? 'compressed' : 'nested'}).on('error', sass.logError))
.pipe(gulp.dest('./dist/css'))
})
gulp.task('js', function() {
return browserify({
entries: './src/assets/js/client.js'
}).transform('babelify', { presets: ['es2015', 'react'] })
.bundle()
.pipe(source('client.js'))
.pipe(buffer())
.pipe(uglify({
mangle: false,
compress: false
}))
.pipe(rename('app.js'))
.pipe(gulp.dest('./dist/js'))
})
gulp.task('img', function() {
return gulp.src('src/assets/img/**/*')
.pipe(gulp.dest('./dist/img'))
})
gulp.task('html', function() {
return gulp.src('src/data/**/*.md')
.pipe(metaMarkdown())
.pipe(new Transform({
objectMode: true,
transform: function(file, encoding, callback) {
var fileContents = JSON.parse(file.contents)
var html = fileContents.html
var meta = fileContents.meta
if ('undefined' === typeof meta) {
meta = {title: null};
}
var relativePath = path.join(path.dirname(path.relative(file.cwd, file.path)), path.basename(file.path, path.extname(file.path)))
var sourceUrl = relativePath + '.md'
var url = '/' + path.relative('src/data/pages/', relativePath) + '.html'
var htmlRender = '<!DOCTYPE html>'
var reactRender = createReactApp({ html: html, meta: meta, baseUrl: baseUrl, sourceUrl: sourceUrl, url: url })
htmlRender += reactRender
file.contents = new Buffer(htmlRender)
callback(null, file)
}
}))
.pipe(rename(function(file) {
file.dirname = './' + path.relative('pages', file.dirname)
}))
.pipe(gulp.dest('dist'))
})
gulp.task('build', ['css', 'js', 'img', 'html'])
gulp.task('html-watch', ['html'], function (done) {
browserSync.reload()
done()
})
gulp.task('dev', ['build'], function() {
browserSync.init({
server: './dist'
})
gulp.watch(['src/assets/js/**/*.js'], ['js', 'html'])
gulp.watch(['src/data/**/*.md'], ['html-watch'])
gulp.watch(['src/assets/sass/**/*.scss'], ['css'])
})
gulp.task('deploy', ['build'], function() {
buildBranch({
branch: 'gh-pages',
remote: 'origin',
ignore: ['.git', 'dist', 'node_modules'],
folder: 'dist'
}, function(err) {
if(err) {
throw err
}
console.log('Published!')
})
})
gulp.task('default', ['build'])