forked from mathigon/textbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gruntfile.js
executable file
·117 lines (97 loc) · 2.68 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
// =============================================================================
// Grunt Configuration
// (c) Mathigon
// =============================================================================
const grunt = require('grunt');
const rollup = require('rollup');
const rollupResolve = require('rollup-plugin-node-resolve');
// -----------------------------------------------------------------------------
// Plugins and Setup
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
require('@mathigon/parser')(grunt);
grunt.registerMultiTask('rollup', '', function() {
const done = this.async();
function onwarn(error) {
if (error.code !== 'CIRCULAR_DEPENDENCY') grunt.log.error(error.message);
}
const promises = this.files.map(f => {
return rollup.rollup({input: f.src[0], plugins: [rollupResolve()], onwarn})
.then(bundle => bundle.generate({format: 'iife', name: '_stepFunctions'}))
.then(result => grunt.file.write(f.dest, result.output[0].code));
});
Promise.all(promises)
.then(() => done())
.catch(error => grunt.fail.warn(error));
});
// -----------------------------------------------------------------------------
// Grunt Configuration
grunt.initConfig({
less: {
options: {
rootpath: ['server/assets'],
paths: ['server/assets'],
optimisation: 1,
banner: '/* (c) Mathigon */\n'
},
app: {
files: [{
expand: true,
cwd: 'content',
src: ['*/*.less', '!node_modules/**'],
dest: 'server/assets/resources',
ext: '.css'
}]
}
},
autoprefixer: {
app: {
files: [{
expand: true,
src: 'server/assets/resources/**/*.css'
}]
}
},
textbooks: {
options: {languages: ['en', 'ru', 'vn', 'cn'], cache: true},
app: {
files: [{
expand: true,
cwd: 'content',
src: ['*', '!shared'],
dest: 'server/assets/resources'
}]
}
},
rollup: {
app: {
files: [{
expand: true,
cwd: 'content',
src: '*/functions.js',
dest: 'server/assets/resources'
}]
}
},
watch: {
css: {
files: ['content/**/*.less'],
tasks: ['less', 'autoprefixer']
},
js: {
files: ['content/**/*.js'],
tasks: ['rollup']
},
textbooks: {
files: ['content/**/*.md'],
tasks: ['textbooks']
}
},
concurrent: {
options: {limit: 3, logConcurrentOutput: true},
app: { tasks: ['watch:css', 'watch:js', 'watch:textbooks'] }
}
});
grunt.registerTask('default', ['less', 'autoprefixer', 'textbooks', 'rollup']);