-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
162 lines (129 loc) · 3.28 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
var gulp = require('gulp'),
sass = require('gulp-sass'),
less = require('gulp-less'),
mini = require('gulp-minify'),
concat = require('gulp-concat'),
http = require('http'),
fs = require('fs'),
paths = {
'docs': {
index: '/',
selectmenu: '/docs/selectmenu.html',
tooltip: '/docs/tooltip.html',
loader: '/docs/loader.html',
dialog: '/docs/dialog.html',
autocomplete: '/docs/autocomplete.html',
datepicker: '/docs/datepicker.html',
},
'style': {
sass: './dist/scss/*.scss',
less: './dist/less/*.less',
output: './dist/css'
},
'scripts': {
src: './src/js/*.js',
output: './dist/js',
original: '.js',
minified: '.min.js'
},
'dom': {
files: [
'./src/js/core/dom/intro.js',
'./src/js/core/dom/data.js',
'./src/js/core/dom/markup.js',
'./src/js/core/dom/remove.js',
'./src/js/core/dom/events.js',
'./src/js/core/dom/core.js',
'./src/js/core/dom/outro.js'
]
},
'core': {
files: [
'./src/js/core/intro.js',
'./src/js/core/uid.js',
'./src/js/core/type.js',
'./src/js/core/iterators.js',
'./src/js/core/dom.js',
'./src/js/core/property.js',
'./src/js/core/templates.js',
'./src/js/core/event-emitter.js',
'./src/js/core/transitions.js',
'./src/js/core/keycodes.js',
'./src/js/core/statics.js',
'./src/js/core/prototype.js',
'./src/js/core/outro.js'
]
}
};
function createFile (filename, filepath) {
var isIndex = filename === 'index';
if (!isIndex) {
filename = './docs/' + filename;
}
filename = filename + '.html';
var req = http.request({
host: 'localhost',
port: 5280,
path: filepath,
method: 'GET',
headers: {
'Content-Type': 'text/html'
}
}, function (res) {
res.setEncoding('utf8');
var data = [];
res.on('data', function (chunk) {
var newChunk = chunk
.replace(/\/docs\/assets/g, isIndex ? 'docs/assets' : '../docs/assets')
.replace(/\/src\/js/g, isIndex ? 'src/js' : '../src/js')
.replace(/\/dist\/css/g, isIndex ? 'dist/' : '../dist/css');
data.push(newChunk);
});
res.on('end', function () {
fs.writeFileSync(filename, data.join(''));
});
});
req.end();
}
gulp.task('static-site', function () {
var docs = paths.docs, file;
for (file in docs) {
createFile(file, docs[file]);
}
});
gulp.task('build-core', function () {
gulp.src(paths.core.files)
.pipe(concat('core.js'))
.pipe(gulp.dest('./src/js'))
});
gulp.task('build-dom', function () {
gulp.src(paths.dom.files)
.pipe(concat('dom.js'))
.pipe(gulp.dest('./src/js/core'))
});
gulp.task('minify', function () {
gulp.src(paths.scripts.src)
.pipe(mini({
ext: {
src: paths.scripts.original,
min: paths.scripts.minified
},
mangle: true
}))
.pipe(gulp.dest(paths.scripts.output));
});
gulp.task('sass', function () {
gulp.src(paths.style.sass)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(paths.style.output));
});
//
// for testing purposes only
// our compiled css comes from sass and we provide the raw sass in our node module
// but for projcts running on less, we want to provide you with working less files as well
// --------------------------------------
gulp.task('less', function () {
gulp.src(paths.style.less)
.pipe(less())
.pipe(gulp.dest(paths.style.output));
});