forked from HabitRPG/habitica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
182 lines (165 loc) · 5.46 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
var gulp = require('gulp'),
_ = require('lodash'),
glob = require('glob'),
browserify = require('browserify'),
coffeeify = require('coffeeify'),
source = require('vinyl-source-stream');
transform = require('vinyl-transform'),
rimraf = require('rimraf'),
nodemon = require('gulp-nodemon'),
karma = require('karma').server,
stylus = require('gulp-stylus'),
nib = require('nib'),
minifycss = require('gulp-minify-css'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
spritesmith = require('gulp.spritesmith'),
csso = require('gulp-csso'),
cssmin = require('gulp-cssmin'),
pkg = require('./package');
var paths = {
stylus: {
src: {
app: './website/public/css/index.styl',
staticPage: './website/public/css/static.styl' // static is a 'future' reserved word
},
dest: './website/build/'
},
common: {
src: ['./common/index.js'],
dest: './common/dist/scripts/'
},
sprites: {
src: './common/img/sprites/spritesmith/**/*.png',
dest: './common/dist/sprites/',
cssminSrc: ['./common/dist/sprites/spritesmith*.css',
'./common/css/backer.css',
'./common/css/Mounts.css',
'./common/css/index.css'],
cssminDest: './common/dist/sprites/'
},
copy: {
src: ['./common/img/sprites/backer-only/*.gif',
'./common/img/sprites/npc_ian.gif',
'./bower_components/bootstrap/dist/fonts/*'],
dest: './build/'
}
};
gulp.task('karma', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done);
});
gulp.task('git_changelog', function() {
// @TODO: Finish this
});
gulp.task('clean', function(cb) {
rimraf('./build', cb);
});
gulp.task('stylus', function() {
gulp.src(paths.stylus.src.app)
.pipe(stylus({use: [nib()]}))
.pipe(rename('app.css'))
.pipe(gulp.dest(paths.stylus.dest));
gulp.src(paths.stylus.src.staticPage)
.pipe(stylus({use: [nib()]}))
.pipe(rename('static.css'))
.pipe(gulp.dest(paths.stylus.dest));
});
gulp.task('copy', function() {
gulp.src(paths.copy.src)
.pipe(gulp.dest(paths.copy.dest));
});
gulp.task('hashres', function() {
// @TODO: Finish this
});
gulp.task('sprite', function(cb) {
var images = glob.sync('./common/img/sprites/spritesmith/**/*.png');
// var totalDims = {width:0,height:0};
// _.each(images, function(img){
// var dims = sizeOf(img);
// if(!dims.width || !dims.height) console.log(dims);
// totalDims.width += dims.width;
// totalDims.height += dims.height;
// })
var COUNT = 6;//Math.ceil( (totalDims.width * totalDims.height) / (1024*1024*3) );
var STEP = 0;
//console.log({totalDims:totalDims,COUNT:COUNT});
var sprite = {};
_.times(COUNT, function(i){
sprite[''+i] = {
slice: images.slice(i * (images.length/COUNT), (i+1) * images.length/COUNT),
imgName: 'spritesmith'+i+'.png',
cssName: 'spritesmith'+i+'.css',
engine: 'phantomjssmith',
algorithm: 'binary-tree',
padding:1,
cssTemplate: './common/css/css.template.mustache',
cssVarMap: function (sprite) {
// For hair, skins, beards, etc. we want to output a '.customize-options.WHATEVER' class, which works as a
// 60x60 image pointing at the proper part of the 90x90 sprite.
// We set up the custom info here, and the template makes use of it.
if (sprite.name.match(/hair|skin|beard|mustach|shirt|flower/) || sprite.name=='head_0') {
sprite.custom = {
px: {
offset_x: "-" + (sprite.x + 25) + "px",
offset_y: "-" + (sprite.y + 15) + "px",
width: "" + 60 + "px",
height: "" + 60 + "px"
}
}
}
if (~sprite.name.indexOf('shirt'))
sprite.custom.px.offset_y = "-" + (sprite.y + 30) + "px"; // even more for shirts
}
/*,cssOpts: {
cssClass: function (item) {
return '.' + item.name; //'.sprite-' + item.name;
}
}*/
}
})
_.forIn(sprite, function(value, key){
console.log("Starting spritesmith" + key + ".png");
var spriteData = gulp.src(sprite[key].slice).pipe(spritesmith(sprite[key]));
spriteData.img
//.pipe(imagemin())
.pipe(gulp.dest(paths.sprites.dest));
// Pipe CSS stream through CSS optimizer and onto disk
spriteData.css
.pipe(csso())
.pipe(gulp.dest(paths.sprites.dest))
.on('end', function(){
STEP++;
console.log("Finished spritesmith" + key + ".png");
if(STEP >= COUNT) {
gulp.src(paths.sprites.cssminSrc)
.pipe(concat('habitrpg-shared.css'))
.pipe(cssmin())
.pipe(gulp.dest(paths.sprites.cssminDest))
.on('end', function(){cb()});
}
});
});
});
gulp.task('browserify', function() {
var bundleStream = browserify(paths.common.src)
.transform(coffeeify)
.bundle()
bundleStream
.pipe(source('habitrpg-shared.js'))
.pipe(gulp.dest(paths.common.dest))
})
gulp.task('watch', ['stylus'], function() {
// @TODO: Finish this
});
gulp.task('dev', ['watch'], function() {
// @TODO: Finish this
nodemon({ script: pkg.main });
});
gulp.task('prod', ['clean', 'stylus', 'copy'], function() {
// @TODO: Finish this
});
gulp.task('default', ['dev']);