-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
127 lines (120 loc) · 4.5 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
module.exports = function(grunt) {
var pkgJson = require('./package.json');
// console.log(pkgJson);
grunt.initConfig({
// lint this file
jshint: {
files: ['Gruntfile.js'],
options: {
jshintrc: true // tell JSHint to search for .jshintrc
}
},
// convert markdown to html
md2html: {
// index.html
one_file: {
options: {
layout: "tutorial/assets/md2html/templates/bootstrap.html",
templateData: {
basePath: "",
author: pkgJson.author,
projectTitle: pkgJson.title,
filename: function(src) {
return src[0].match(/\/(.*).md/);
},
},
},
files: [{
src: ['README.md'],
dest: 'index.html'
}]
},
// www/*
multiple_files: {
options: {
layout: "tutorial/assets/md2html/templates/bootstrap.html",
templateData: {
basePath: "../",
author: pkgJson.author,
projectTitle: pkgJson.title,
filename: function(src) {
return src[0].match(/\/(.*).md/);
},
},
},
files: [{
expand: true,
cwd: 'tutorial/markdown',
src: ['**/*.md'],
dest: 'tutorial/www', // destination directory
ext: '.html' // new file ext
}]
}
},
watch: {
grunt: {
// if changes made to these files ...
files: ['Gruntfile.js', 'tutorial/assets/css/*', 'tutorial/assets/md2html/templates/*'],
// run these tasks ...
tasks: ['shell:marp', 'md2html', 'alldone']
},
configFiles: {
files: ['Gruntfile.js'], // watch/validate grunt config
tasks: ['jshint'],
options: {
reload: true
}
},
markdown: {
files: ['tutorial/markdown/*.md', 'README.md'], // files to watch
tasks: ['shell:marp', 'md2html', 'alldone'], // run these tasks
options: {
spawn: false,
},
},
copyAssets: {
// if final extension assets are updated ...
files: ['extension/explode-tutorial-final/**/*'],
tasks: ['shell:copyAssets', 'alldone']
}
},
// individual shell tasks (called from watch tasks)
shell: {
hello: {
command: "echo [🙌 running grunt-shell:hello]"
},
// call marp for slides
marp: {
command: concatBash([
"echo [🎁 running grunt-shell:marp]",
// "touch hello.txt", //test
"marp",
])
},
// copy assets if they are updated
copyAssets: {
command: concatBash([
"echo [📄 running grunt-shell:copyAssets]",
// sub dir in destination must exist
"cp -R extension/explode-tutorial-final/assets extension/explode-tutorial-3/",
"cp -R extension/explode-tutorial-final/assets extension/explode-tutorial-4/",
// parentheses temporarily changes directory, to get only assets dir, then hide zip output
"(cd extension/explode-tutorial-final/ && zip -r ../assets.zip ./assets > /dev/null)"
])
},
}
});
// a custom task
grunt.task.registerTask('alldone', 'run when finished', function() {
console.log("🔥 all done");
});
function concatBash(arr) {
return arr.join('&&');
}
// enable plugins, register tasks
grunt.loadNpmTasks('grunt-md2html');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('default', ['jshint', 'md2html', 'shell:hello', 'shell:marp', 'shell:copyAssets', 'alldone']);
};