-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
193 lines (174 loc) · 5.09 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
// ONE Creative Ad ID
var adId = '000000';
// ADTECH Rich Media Lib Version
var version = '2_65_0';
// Dependancies
var gulp = require('gulp');
var fs = require("fs");
var path = require('path');
var browserSync = require('browser-sync').create();
var prettyError = require('gulp-prettyerror');
var sourcemaps = require('gulp-sourcemaps');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var zip = require('gulp-zip');
var template = require('gulp-html-compile');
var merge = require('merge-stream');
var htmlPartial = require('gulp-html-partial');
var modRewrite = require('connect-modrewrite');
var template = require('gulp-html-compile');
var rename = require('gulp-rename');
var order = require("gulp-order");
var injectfile = require("gulp-inject-file");
var inject = require('gulp-inject-string');
var replace = require('gulp-replace-path');
var inject = require('gulp-inject');
var inlinesrc = require('gulp-inline-source');
// Paths
var path = {};
path.src = './src/';
path.build = './dist/';
// Types
var type = {};
type.img = '.{jpeg,jpg,png,gif,svg,cur,ico}';
type.font = '.{eot,ttf,otf,woff,woff2,svg}';
type.video = '.{mp4,ogv,webm}';
type.audio = '.{wav,mp3}';
// Serve files
gulp.task('serve', [], function () {
browserSync.init({
server: {
baseDir: path.build,
index: "parent.html",
}
});
function reload() {
setTimeout(function() {
browserSync.reload();
}, 200)
}
gulp.watch(["src/*.html", "src/app/parent/**/*.js"], ['display']) .on('change', reload);
gulp.watch("src/public/css/sass/**/*.scss", ['sass']);
gulp.watch("src/app/**/*.js", ['ryotcontent']).on('change', reload);
gulp.watch("src/app/one/**/*.js", ['customAd']).on('change', reload);
gulp.watch("src/app/views/**/*.js", ['views']).on('change', reload);
gulp.watch("src/public/img/**/*"+type.img, ['assets']).on('change', reload);
});
// HTML display files
gulp.task('display', function() {
// Parent
gulp.src('src/parent.html')
.pipe(inlinesrc())
.pipe(gulp.dest(path.build));
// Iframe
gulp.src([
"src/index.html"
])
.pipe(gulp.dest(path.build));
});
// Compile Sass
gulp.task('sass', function() {
return gulp.src("src/public/css/sass/*.scss")
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest(path.build+'public/css/'))
.pipe(browserSync.stream({once: true}));
});
// Compile app
gulp.task('ryotcontent', function() {
// Content bootstrap
var ryot = gulp.src([
"src/app/ryot/ryot.core.js",
"src/app/ryot/*.js",
"src/app/components/*.js",
"src/app/run.js",
])
.pipe(prettyError())
// .pipe(sourcemaps.init())
// .pipe(uglify())
.pipe(concat('ryotcontent.js'))
// .pipe(sourcemaps.write())
// .pipe(gulp.dest(path.build+'public/js/'));
// Views
var views = gulp.src('src/app/view/**/*.html')
.pipe(prettyError())
// .pipe(sourcemaps.init())
.pipe(template({
name: function(file) {
return file.relative.split( '.' )[ 0 ];
},
namespace: 'views'
}))
.pipe(concat('app.js'))
// .pipe(sourcemaps.write())
// Merge streams
merge(views, ryot)
.pipe(concat('ryotcontent.js'))
.pipe(gulp.dest(path.build+'public/js/'));
});
// Views
gulp.task('views', function() {
gulp.src('src/app/view/**/*.html')
.pipe(sourcemaps.init())
.pipe(template({
name: function(file) {
return file.relative.split( '.' )[ 0 ];
},
namespace: 'views'
}))
.pipe(concat('views.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(path.build+'public/js/'));
});
// Copy JS Libs
gulp.task('libs', function() {
gulp.src([
"src/app/lib/*.js"
])
.pipe(gulp.dest(path.build+'public/js/libs/'));
});
// ONE customAd
gulp.task('customAd', function() {
// Live customAd
gulp.src('src/app/one/partials/customAd.wrapper.js')
.pipe(prettyError())
.pipe(injectfile({
pattern: '<!--\\s*inject:<filename>-->'
}))
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(concat('customAd.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(path.build));
// Local customAd
gulp.src('src/app/one/partials/customAd.localwrapper.js')
.pipe(prettyError())
.pipe(injectfile({
pattern: '<!--\\s*inject:<filename>-->'
}))
.pipe(sourcemaps.init())
.pipe(replace('$VERSION$', version))
.pipe(replace('$AD_ID$', adId))
.pipe(uglify())
.pipe(concat('customAd.local.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(path.build));
});
// Copy assets
gulp.task('assets', function() {
gulp.src([
"src/public/img/**/*"+type.img
])
.pipe(gulp.dest(path.build+'public/img/'));
});
gulp.task('zip', function() {
gulp.src([
'dist/**/*',
'!dist/parent.html',
])
.pipe(zip('ryot_content_dist.zip'))
.pipe(gulp.dest('zip'))
});
// Default
gulp.task('default', ['serve']);