forked from OpenNHP/opennhp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
170 lines (135 loc) · 4.76 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
var path = require('path');
var fs = require('fs-extra');
var gulp = require('gulp');
var gutil = require('gulp-util');
var less = require('gulp-less');
var changed = require('gulp-changed');
var watch = require('gulp-watch');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var minifyCSS = require('gulp-minify-css');
var rename = require('gulp-rename');
var bower = require('gulp-bower');
var transport = require('gulp-cmd-transport');
var header = require('gulp-header');
var clean = require('gulp-clean');
var zip = require('gulp-zip');
var pkg = require('./package.json');
var transportDir = '.build/ts/';
var buildTmpDir = '.build/tmp/';
var jsPaths = {
widgets: [
'*/src/*.js',
'!{powered_by,switch_mode,toolbar,tech_support,layout*,blank,container}/src/*.js']
};
var now = new Date();
var banner = [
'/*! <%= pkg.name %> - v<%= pkg.version %>',
'(c) ' + gutil.date(now, 'yyyy') + ' AllMobilize, Inc.',
'@license <%= pkg.license %>',
gutil.date(now, 'yyyy-mm-dd HH:mm:ss') + ' */ \r'
].join(' | ');
// build to dist dir
gulp.task('buildLess', function() {
gulp.src(['./less/amui.all.less'])
//.pipe(watch())
.pipe(less({
paths: [path.join(__dirname, 'less'), path.join(__dirname, 'widget/*/src')]
}))
.pipe(gulp.dest('./dist/assets/css'))
.pipe(minifyCSS())
.pipe(rename({
suffix: '.min',
extname: ".css"
}))
.pipe(gulp.dest('./dist/assets/css'));
});
gulp.task('bower', function() {
bower()
.pipe(gulp.dest('vendor/'))
});
// copy ui js files to build dir
gulp.task('copyWidgetJs', function() {
gutil.log(gutil.colors.yellow('Start copy UI js files to build dir....'));
return gulp.src(jsPaths.widgets, {cwd: './widget'})
.pipe(rename(function(path) {
path.dirname = ""; // remove widget dir
}))
.pipe(gulp.dest(buildTmpDir));
});
// copy widgets js files to build dir
gulp.task('copyUIJs', ['copyWidgetJs'], function() {
return gulp.src(['*.js', '!./js/zepto.calendar.js'], {
cwd: './js'
})
.pipe(gulp.dest(buildTmpDir));
});
var modules = [];
// gulp cmd transport
gulp.task('transport', ['copyUIJs'], function() {
return gulp.src(['*.js'], {cwd: buildTmpDir})
.pipe(rename(function(path) {
modules.push(path.basename);
}))
.pipe(transport({paths: [buildTmpDir]}))
.pipe(gulp.dest(transportDir));
});
// concat
gulp.task('concat', ['transport'], function() {
var seajs = path.join(__dirname,'vendor/seajs/sea.js');
var seaUse = path.join(__dirname,'/.build/seaUse.js');
fs.outputFileSync(seaUse, 'seajs.use(' + JSON.stringify(modules) + ');');
modules = [];
//[seajs, '*.js', seaUse]
return gulp.src([seajs, 'core.js', '*!(core)*.js', seaUse], {cwd: transportDir})
.pipe(concat('amui.js'))
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('./dist/assets/js'))
.pipe(uglify({
mangle: {
except: ['require']
},
preserveComments: 'some'
}))
.pipe(rename({
suffix: '.min',
extname: ".js"
}))
.pipe(gulp.dest('./dist/assets/js'))
});
gulp.task('clean', ['concat'], function() {
gutil.log(gutil.colors.green('Finished build js, cleaning...'));
gulp.src('./.build', {read: false})
.pipe(clean({force: true}));
});
gulp.task('hbsHelper', function() {
gulp.src(['docs/assets/helper/handlebars.js', 'vendor/amazeui.partials.js'])
.pipe(concat('amui.widget.helper.js'))
.pipe(gulp.dest('./dist/assets/js'))
.pipe(uglify({
mangle: {
except: ['require']
},
preserveComments: 'some'
}))
.pipe(rename({
suffix: '.min',
extname: ".js"
}))
.pipe(gulp.dest('./dist/assets/js'))
});
// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch(['js/*.js', 'widget/*/src/*.js'], ['buildJs']);
gulp.watch(['less/**/*.less', 'widget/*/src/*.less'], ['buildLess']);
gulp.watch(['dist/amui*js'], ['copyFiles']);
gulp.watch(['docs/assets/js/main.js'], ['amazeMain']);
});
gulp.task('zip', function () {
return gulp.src(['./docs/boilerplate/**', './dist/**', '!dist/demo/**/*', '!dist/test/**/*', '!dist/docs/**/*', '!dist/*.zip'])
.pipe(zip('AmazeUI.zip', {comment: 'Created on ' + gutil.date(now, 'yyyy-mm-dd HH:mm:ss')}))
.pipe(gulp.dest('dist'));
});
gulp.task('buildJs', ['copyWidgetJs', 'copyUIJs', 'transport', 'concat', 'clean']);
gulp.task('init', ['bower', 'buildJs', 'hbsHelper', 'buildLess', 'watch']);
gulp.task('default', ['buildJs', 'buildLess', 'hbsHelper', 'watch']);