This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.coffee
168 lines (140 loc) · 4.21 KB
/
gulpfile.coffee
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
168
'use strict'
gulp = require('gulp')
concat = require('gulp-concat')
concatUtil = require('gulp-concat-util')
del = require('del')
util = require('gulp-util')
es = require('event-stream')
ts = require('gulp-typescript')
bump = require('gulp-bump')
git = require('gulp-git')
through = require('through2')
hyperShaders = require('./tools/gulp-hyper-shaders')
filter = require('gulp-filter')
tagVersion = require('gulp-tag-version')
inquirer = require('inquirer')
path = require('path')
browserify = require('browserify')
uglify = require('gulp-uglify')
browserifyGlobalShim = require('browserify-global-shim')
buffer = require('vinyl-buffer')
source = require('vinyl-source-stream')
rename = require('gulp-rename')
pipe = require('multipipe')
mirror = require('gulp-mirror')
licensify = require('licensify')
fs = require('fs')
tslint = require('gulp-tslint')
# --------------------- path -----------------------
sources =
lib:
js: [ './src/**/*.js' ]
tsd: [ './src/*.d.ts' ]
ts: [
'./src/**/*.ts'
'!./src/*.d.ts'
]
tsMain: [ './src/renderer/public/*.ts' ]
shaders: [ './src/renderer/shaders/**/*.glsl' ]
shaderTemplateSource = './src/renderer/shaders/ShadersTemplate.txt'
bundleMain = 'src/bundle-main.js'
destinations =
pub_js: './dist/'
bundle_js: './build/'
# ---------------- helper functions -----------------
addSource = (inp) ->
p = through.obj()
es.duplex p, es.merge(inp, p)
versionModule = (path) ->
packageInfo = JSON.parse fs.readFileSync('./package.json')
version = packageInfo.version
stream = source(path)
stream.end "exports.REVISION = #{JSON.stringify(version)};\n"
stream
# ---------------------- tasks ----------------------
gulp.task 'dep:lib', ->
return
gulp.task 'js:lib', ->
tsProject = ts.createProject('tsconfig.json', sortOutput: true)
tsFiles = gulp.src(sources.lib.ts)
shaderChunks = gulp.src(sources.lib.shaders)
.pipe(hyperShaders(shaderTemplateSource))
versionFile = versionModule('./renderer/public/Version.js')
tsStream = tsFiles
.pipe(addSource(shaderChunks))
.pipe(ts(tsProject))
es.merge(
tsStream.js
.pipe(gulp.dest(destinations.pub_js)),
gulp.src(sources.lib.js, base: 'src')
.pipe(gulp.dest(destinations.pub_js)),
gulp.src(sources.lib.tsd, base: 'src')
.pipe(gulp.dest(destinations.pub_js)),
versionFile
.pipe(gulp.dest(destinations.pub_js))
)
gulp.task 'js:bundle', [ 'js:lib' ], ->
# replace require('three') with THREE
gs = browserifyGlobalShim.configure('three': 'THREE')
browserify(entries: bundleMain)
.transform(gs)
.plugin(licensify)
.bundle()
.pipe(source('hyper3d.js'))
.pipe(buffer())
.pipe(mirror(
pipe(
uglify(preserveComments: 'license'),
rename('hyper3d.min.js')),
rename('hyper3d.js')))
.pipe(gulp.dest(destinations.bundle_js))
gulp.task 'js:lint', ->
gulp.src(sources.lib.ts)
.pipe(tslint())
.pipe(tslint.report('verbose'))
# deletes the dist folder for a clean build
gulp.task 'clean', ->
del [ './dist', './build' ], (err, deletedFiles) ->
if deletedFiles.length
util.log 'Deleted', util.colors.red(deletedFiles.join(' ,'))
else
util.log util.colors.yellow('empty - nothing to delete')
return
return
gulp.task 'build', [
'js:lib'
'dep:lib'
'js:bundle'
]
gulp.task 'bump', ->
questions = [
type: 'input'
name: 'bump'
message: 'Are you sure you want to bump the patch version? [Y/N]'
]
inquirer.prompt questions, (answers) ->
if answers.bump == 'Y'
gulp.src([ './package.json' ])
.pipe(bump(type: 'patch'))
.pipe(gulp.dest('./'))
.pipe(git.commit('bump patch version'))
.pipe(filter('package.json'))
.pipe(tagVersion())
else
null
return
# watch scripts, styles, and templates
gulp.task 'watch', ->
buildTasks = [ 'js:lint', 'js:lib' ]
gulp.watch sources.lib.ts, buildTasks
gulp.watch sources.lib.tsd, buildTasks
gulp.watch sources.lib.js, buildTasks
gulp.watch sources.lib.shaders, buildTasks
gulp.watch [ shaderTemplateSource ], buildTasks
return
# ---------------- default task -----------------
gulp.task 'default', [
'js:lint',
'js:lib'
'watch'
]