-
Notifications
You must be signed in to change notification settings - Fork 56
/
gulpfile.js
68 lines (55 loc) · 1.92 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
var gulp = require('gulp'),
fs = require('fs'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
insert = require('gulp-insert')
;
var packageName = 'freezer';
var pack = require( './package.json' );
var core = function( fileContents ){
//Transform the buffer to string
return ( '' + fileContents).split('//#build')[1];
};
var wrap = function( src ) {
var now = new Date(),
wrapper = fs.readFileSync('./build/wrapper.txt', {encoding: 'utf8'})
;
return wrapper
.replace( /%%name%%/g, pack.name)
.replace( /%%version%%/g, pack.version)
.replace( /%%author%%/g, pack.author)
.replace( /%%license%%/g, pack.license)
.replace( /%%homepage%%/g, pack.homepage)
.replace( /%%packageName%%/g, packageName[0].toUpperCase() + packageName.slice(1) )
.replace( /%%date%%/g, now.getDate() + '-' + (now.getMonth() + 1) + '-' + now.getFullYear() )
.replace( /%%contents%%/g, src );
};
var cr = ('/*\n%%name%% v%%version%%\n%%homepage%%\n%%license%%: https://github.com/arqex/' + packageName + '/raw/master/LICENSE\n*/\n')
.replace( '%%name%%', pack.name)
.replace( '%%version%%', pack.version)
.replace( '%%license%%', pack.license)
.replace( '%%homepage%%', pack.homepage)
;
function handleErrors( err ){
console.log( err );
}
gulp.task( 'build', function(){
var src = core( fs.readFileSync('./src/utils.js') ) +
core( fs.readFileSync('./src/nodeCreator.js') ) +
core( fs.readFileSync('./src/emitter.js') ) +
core( fs.readFileSync('./src/frozen.js') ) +
core( fs.readFileSync('./src/' + packageName + '.js')),
build = wrap( src )
;
fs.writeFileSync( './build/' + packageName + '.js', build );
gulp.src('./build/' + packageName + '.js')
.pipe( uglify().on('error', handleErrors) )
.pipe( rename( packageName + '.min.js' ))
.pipe( insert.prepend( cr ))
.pipe( gulp.dest('./build') )
;
});
gulp.task( 'dev', function(){
gulp.watch( './src/*', ['build'] );
});
gulp.task( 'default', ['build'] );