forked from gfxfundamentals/webgl2-fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
200 lines (183 loc) · 5.16 KB
/
Gruntfile.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
/*eslint-env node*/
'use strict';
process.on('unhandledRejection', up => {
throw up;
});
const fs = require('fs');
const path = require('path');
const liveEditor = require('@gfxfundamentals/live-editor');
const liveEditorPath = path.dirname(require.resolve('@gfxfundamentals/live-editor'));
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
const s_ignoreRE = /\.(md|py|sh|enc)$/i;
function noMds(filename) {
return !s_ignoreRE.test(filename);
}
const s_isMdRE = /\.md$/i;
function mdsOnly(filename) {
return s_isMdRE.test(filename);
}
function notFolder(filename) {
return !fs.statSync(filename).isDirectory();
}
function noMdsNoFolders(filename) {
return noMds(filename) && notFolder(filename);
}
grunt.initConfig({
eslint: {
lib: {
src: [
'webgl/resources/webgl-utils.js',
'webgl/resources/lessons-helper.js',
'webgl/resources/flattened-primitives.js',
'webgl/resources/2d-math.js',
'webgl/resources/3d-math.js',
'build/js/*.js',
],
},
examples: {
src: [
'webgl/*.html',
'!webgl/webgl-qna-*.html',
// 'webgl/lessons/*.md',
],
},
diagram: {
src: [
'webgl/lessons/resources/webgl-state-diagram/*.js',
],
},
},
jsdoc: {
docs: {
src: [
'webgl/resources/2d-math.js',
'webgl/resources/3d-math.js',
'webgl/resources/webgl-utils.js',
'docs.md',
],
options: {
destination: 'out/docs',
configure: 'build/conf/jsdoc.conf.json',
template: './node_modules/minami',
},
},
},
copy: {
main: {
files: [
{ expand: false, src: '*', dest: 'out/', filter: noMdsNoFolders, },
{ expand: true, cwd: `${liveEditor.monacoEditor}/`, src: 'min/**', dest: 'out/monaco-editor/', nonull: true, },
{ expand: true, cwd: `${liveEditorPath}/src/`, src: '**', dest: 'out/webgl/resources/', nonull: true, },
{ expand: true, src: 'webgl/**', dest: 'out/', filter: noMds, },
{ expand: true, src: '3rdparty/**', dest: 'out/', },
],
},
},
clean: [
'out/**/*',
],
buildlesson: {
main: {
files: [],
},
},
watch: {
main: {
files: [
'webgl/**',
'3rdparty/**',
'node_modules/@gfxfundamentals/live-editor/src/**',
],
tasks: ['copy'],
options: {
spawn: false,
},
},
lessons: {
files: [
'webgl/lessons/**/webgl*.md',
],
tasks: ['buildlesson'],
options: {
spawn: false,
},
},
},
});
let changedFiles = {};
const onChange = grunt.util._.debounce(function() {
grunt.config('copy.main.files', Object.keys(changedFiles).filter(noMds).map((file) => {
const copy = {
src: file,
dest: 'out/',
};
if (file.indexOf('live-editor') >= 0) {
copy.cwd = `${path.dirname(file)}/`;
copy.src = path.basename(file);
copy.expand = true;
copy.dest = 'out/webgl/resources/';
}
return copy;
}));
grunt.config('buildlesson.main.files', Object.keys(changedFiles).filter(mdsOnly).map((file) => {
return {
src: file,
};
}));
changedFiles = {};
}, 200);
grunt.event.on('watch', function(action, filepath) {
changedFiles[filepath] = action;
onChange();
});
const buildSettings = {
outDir: 'out',
baseUrl: 'https://webgl2fundamentals.org',
rootFolder: 'webgl',
lessonGrep: 'webgl*.md',
siteName: 'WebGL2Fundamentals',
siteThumbnail: 'webgl2fundamentals.jpg', // in rootFolder/lessons/resources
templatePath: 'build/templates',
owner: 'gfxfundamentals',
repo: 'webgl2-fundamentals',
thumbnailOptions: {
thumbnailBackground: 'webgl2fundamentals.jpg',
text: [
{
font: 'bold 100px lesson-font',
verticalSpacing: 100,
offset: [100, 120],
textAlign: 'left',
shadowOffset: [15, 15],
strokeWidth: 15,
textWrapWidth: 1000,
},
],
},
};
// just the hackiest way to get this working.
grunt.registerMultiTask('buildlesson', 'build a lesson', function() {
const filenames = new Set();
this.files.forEach((files) => {
files.src.forEach((filename) => {
filenames.add(filename);
});
});
const buildStuff = require('@gfxfundamentals/lesson-builder');
const settings = Object.assign({}, buildSettings, {
filenames,
});
const finish = this.async();
buildStuff(settings).finally(finish);
});
grunt.registerTask('buildlessons', function() {
const buildStuff = require('@gfxfundamentals/lesson-builder');
const finish = this.async();
buildStuff(buildSettings).finally(finish);
});
grunt.registerTask('build', ['clean', 'copy', 'buildlessons']);
grunt.registerTask('buildwatch', ['build', 'watch']);
grunt.registerTask('pre-push', ['eslint']);
grunt.registerTask('default', ['eslint', 'build', 'jsdoc']);
};