This repository has been archived by the owner on Nov 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
201 lines (153 loc) · 5.3 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
var gulp = require('gulp')
// server + live-reload
connect = require('gulp-connect'),
livereload = require('gulp-livereload'),
// task run sequancial
runSequence = require('run-sequence'),
// clean before running
clean = require('del'),
// styling
sass = require('gulp-sass'),
// source tracking
sourcemaps = require('gulp-sourcemaps'),
// html template
extender = require('gulp-html-extend'),
// comment remove
removeHtmlComment = require('gulp-remove-html-comments')
// 루트에 간추린 파일을 만듬
makeIndex = require('gulp-index'),
// gulp-gh-pages
publish = require('gulp-gh-pages')
;
// 환경설정
var path = {
source : {
root : 'src',
style : 'src/stylesheets',
js : 'src/js',
template : 'src',
image : 'src/image',
conf : 'src/conf',
html : 'src/html'
},
deploy : 'deploy'
};
// 도움말
gulp.task('help',function () {
var comment = `
elm 파 볼 시간이 안되서 미리 만드는 eoshub UI 전용 저장소입니다.
# 환경설정
> npm install gulp -g
전역으로 gulp 설치가 완료되고 나면 사전 정의된 각종 플러그인을 설치합니다.
> npm install --save
설치가 마무리되면 아래처럼 명령어를 실행합니다.
# 실행
로컬에서 실행해볼떄
> gulp local
자세한 사항은 없습니다.
`;
console.log(comment);
});
// --------------------------------------------------------------------------------
// task running 설정
// --------------------------------------------------------------------------------
// index 파일 자동 생성
var buildIndexHtmlOption = require('./_config/build-index-option.js'); // 설정파일 로딩
gulp.task('make:index.html', function () {
return gulp.src([
path.source.html + '/**/*.html', // 전체를 포함
'!**/_common/**', // 공통파일은 포함하지 않음.
'!**/@snippet/**', // 조각파일도 포함하지 않음.
'!**/_resource/**', // 로컬 리소스 폴더도 포함하지 않음.
'!**/template/**', // 로컬 리소스 폴더도 포함하지 않음.
'!**/index.html' // index 파일도 포함하지 않음.
])
.pipe(makeIndex(buildIndexHtmlOption))
.pipe(gulp.dest(path.deploy));
});
// 로컬 서버 설정 :: host 설정 해주지 않으면 외부에서 보이질 않는구나.
gulp.task('connect', function() {
connect.server({
root: path.deploy,
port : 7000,
livereload: true,
directory:true,
host:'0.0.0.0'
});
});
// 파일 변경 감지 :: local
gulp.task('watch', function(callback) {
livereload.listen();
gulp.watch(path.source.style+'/*.{scss,sass,css}',['convert:sass:sourcemap'],callback);
// index 재생성
gulp.watch(path.source.html+'/**/*.html', ['make:index.html'],callback);
// 탬플릿은 세밀하게 지정해줘야 될지도...
gulp.watch([
path.source.template+'/**/*.html',
path.source.html+'/**/*.html',
], ['html'],callback);
// 이미지 수정처3
gulp.watch(path.source.image+'/*.{png,jpg,gif,svg}', ['copy:image'],callback);
});
// 빌드 전 청소
gulp.task('clean',function () {
return clean(path.deploy);
});
// scss 변환 :: local
gulp.task('convert:sass:sourcemap', function () {
return gulp.src(path.source.style + '/**/style.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded'
}))
.on('error', function (err) {
console.log(err.toString());
this.emit('end');
})
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(path.deploy + '/css'))
.pipe(livereload());
});
// html 처리
gulp.task('html',function () {
return gulp.src(path.source.html + '/**/*.html')
.pipe(extender({
annotations: false,
verbose: false
})) // default options
.pipe(removeHtmlComment())
.pipe(gulp.dest(path.deploy))
.pipe(livereload());
});
// image :: local, copy
gulp.task('copy:image', function () {
return gulp.src(path.source.image + '/*.{jpg,png,gif,svg}')
.pipe(gulp.dest(path.deploy + '/image'))
.pipe(livereload());
});
// conference file copy :: local, deploy 공통
gulp.task('copy:conf',function () {
return gulp.src(path.source.conf + '/*')
.pipe(gulp.dest(path.deploy))
.pipe(livereload());
});
// 배포
gulp.task('release', function () {
return gulp.src(path.deploy + '/**/*')
.pipe(publish({
force : true,
message : 'eoshub :: 깃허브 페이지에 반영됨. Published to Github pages'
}))
});
// --------------------------------------------------------------------------------
// pipe running
// --------------------------------------------------------------------------------
// gulp.task('default', ['help']);
// 여기서 running task는 gulp밖에 없으니깐..
gulp.task('default', ['local']);
gulp.task('local', function () {
runSequence('clean','make:index.html',['copy:image','copy:conf'],'convert:sass:sourcemap', 'html',['connect','watch']);
});
gulp.task('deploy', function () {
runSequence('clean','make:index.html',['copy:image','copy:conf'],'convert:sass:sourcemap', 'html','release');
});