forked from webcyou/apbcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
176 lines (155 loc) · 4.59 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
var gulp = require("gulp"),
path = require('path'),
compass = require('gulp-compass'),
cssmin = require('gulp-cssmin'),
connect = require('gulp-connect'),
watch = require('gulp-watch'),
clean = require('gulp-clean'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
typescript = require('gulp-tsc'),
tsd = require('gulp-tsd'),
bower = require('gulp-bower'),
server = require('gulp-express'),
plumber = require('gulp-plumber'),
stripDebug = require('gulp-strip-debug'),
del = require('del'),
runSequence = require('run-sequence');
var uglifySaveLicense = require('uglify-save-license');
var SOURCE_DIR = 'data',
RELEASE_DIR = 'public';
var htmlFiles = [ SOURCE_DIR + '/html/**/*.html' ];
var tsFiles = [ SOURCE_DIR + '/ts/**/*.ts' ];
var imgFiles = [ SOURCE_DIR + '/img/**/*.{jpg,png,gif}' ];
var scssFiles = [ SOURCE_DIR + '/scss/**/*.scss' ];
var jsFiles = [
SOURCE_DIR + '/js/**/*.js',
'!data/js/contrib/**/*.js'
];
// Clean File
gulp.task('clean-dir', function() {
del([RELEASE_DIR + '/*'], {force: true});
});
gulp.task('clean-ts', function(cb) {
del([RELEASE_DIR + '/**/*.ts'], {force: true}, cb);
});
// compass
gulp.task('compass', function() {
return gulp.src(scssFiles)
.pipe(plumber())
.pipe(compass({
style: 'compressed',
specify: SOURCE_DIR + '/scss/style.scss',
css: RELEASE_DIR + '/css',
sass: SOURCE_DIR + '/scss',
imagesDir: RELEASE_DIR + '/img'
}));
});
gulp.task('copy-html', function () {
gulp.src(htmlFiles).pipe(gulp.dest(RELEASE_DIR + '/html'));
gulp.src(SOURCE_DIR + '/index.html').pipe(gulp.dest(RELEASE_DIR));
});
gulp.task('copy-js', function () {
gulp.src([
SOURCE_DIR + '/js/' + '**/*.js',
'!' + SOURCE_DIR + '/js/' + '**/libs/*.js',
'!' + SOURCE_DIR + '/js/' + '**/contrib/*.js'
]).pipe(gulp.dest( RELEASE_DIR + '/js/' ));
});
gulp.task('copy-img', function () {
gulp.src([
SOURCE_DIR + '/img/' + '**/*.{jpg,png,gif,ico}'
]).pipe(gulp.dest( RELEASE_DIR + '/img/' ));
});
// Copy Dir
gulp.task('copy-dir', function () {
gulp.src([
RELEASE_DIR + '/**/*.*',
'!' + RELEASE_DIR + '/js/**/*.js',
'!' + RELEASE_DIR + '/html/**/*.*',
'!' + RELEASE_DIR + '/**/*.ts'
]).pipe(gulp.dest( RELEASE_DIR + '/' ));
});
// JavaScript uglify
gulp.task('uglify-contrib', function () {
gulp.src([
SOURCE_DIR + '/js/contrib/underscore.js',
SOURCE_DIR + '/js/contrib/angular.js',
SOURCE_DIR + '/js/contrib/angular-resource.js',
SOURCE_DIR + '/js/contrib/angular-sanitize.js'
])
.pipe(uglify())
.pipe(concat('contrib.js'))
.pipe(gulp.dest(RELEASE_DIR + '/js/'));
});
gulp.task('cssmin', function () {
gulp.src(RELEASE_DIR + '/*.css')
.pipe(cssmin())
.pipe(gulp.dest(RELEASE_DIR + '/css/'));
});
// typescript
gulp.task('typescript', function () {
gulp.src([
SOURCE_DIR + '/ts/**/*.ts'
])
.pipe(plumber())
.pipe(typescript({ removeComments: true, module: 'commonjs' }))
.pipe(gulp.dest(RELEASE_DIR + '/js/'));
});
gulp.task('tsd', function () {
tsd({
command: 'reinstall',
config: './tsd.json'
}, callback);
});
// ファイル更新監視
gulp.task('watch', function() {
// compass
gulp.watch([scssFiles],['compass']);
// js
gulp.watch([jsFiles],['copy-js']);
// typescript
gulp.watch([tsFiles],['build-typescript']);
// html
gulp.watch([htmlFiles],['copy-html']);
gulp.watch(SOURCE_DIR + '/index.html',['copy-html']);
// img
gulp.watch([imgFiles],['copy-img']);
});
/**
* Gulp Server
**/
gulp.task('server', ['connect'], function() {
gulp.watch([
SOURCE_DIR + '/**/*.*'
]).on('change', function(changedFile) {
gulp.src(changedFile.path).pipe(connect.reload());
});
});
gulp.task('connect', function() {
connect.server({
root: [__dirname + '/public/'],
port: 8088,
livereload: true
});
console.log('Server started: http://localhost:8088');
});
// Build Task
gulp.task('build-ui', ['compass']);
gulp.task('build-typescript', ['typescript']);
gulp.task('build-javascript', ['copy-js', 'uglify-contrib']);
// All task
gulp.task('default', function(callback) {
runSequence(
'clean-dir',
'copy-html',
'copy-img',
'compass',
'build-ui',
'build-typescript',
'build-javascript',
'watch',
'server',
callback
);
});