forked from gfxfundamentals/webgl-fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
181 lines (165 loc) · 4.72 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
/*eslint-env node*/
'use strict';
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/primitives.js',
'webgl/resources/2d-math.js',
'webgl/resources/3d-math.js',
],
},
examples: {
src: [
'webgl/*.html',
],
},
},
jsdoc: {
docs: {
src: [
'webgl/resources/primitives.js',
'webgl/resources/webgl-2d-math.js',
'webgl/resources/webgl-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://webglfundamentals.org',
rootFolder: 'webgl',
lessonGrep: 'webgl*.md',
siteName: 'WebGLFundamentals',
siteThumbnail: 'webglfundamentals.jpg', // in rootFolder/lessons/resources
templatePath: 'build/templates',
thumbnailOptions: {
font: 'bold 100px sans-serif',
verticalSpacing: 100,
offset: [100, 120],
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']);
};