-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.js
86 lines (83 loc) · 2.29 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
module.exports = function(grunt) {
const chalk = require('chalk');
const publicFolder = 'docs';
const traceFile = function(f) {
if ( grunt.file.isFile(f) ) {
console.log(chalk.cyan(f), '→', chalk.cyan(grunt.task.current.data.dest));
}
return true;
}
grunt.initConfig({
copy: {
main: {
expand: true,
src: '{assets/**,*.html}',
dest: publicFolder+'/',
filter: traceFile,
},
JSLibs: {
expand: true,
flatten: true,
src: 'node_modules/leader-line/leader-line.min.js',
dest: publicFolder+'/assets/js/',
filter: traceFile,
},
licence: {
src: 'LICENSE',
dest: publicFolder+'/LICENSE.txt',
filter: traceFile,
},
},
twigRender: {
options: {
functions: {
asset: function(arg) {
return grunt.file.expand({cwd: publicFolder}, 'assets/**/'+ arg)[0];
},
meta: function(arg){
let spawn = require('node:child_process').spawnSync;
let gitStatus = spawn('git', ['status', '-z', arg], { encoding: 'utf8'});
let commit, date;
if ( gitStatus.stdout ) {
commit = '';
date = (new Date()).toISOString().split('T')[0];
} else {
gitStatus = spawn('git', ['log', '--format=%h:%cs', '-1',arg], { encoding: 'utf8'});
gitStatus = gitStatus.stdout.trimEnd().split(':');
commit = gitStatus[0];
date = gitStatus[1];
}
let dataFile = grunt.task.current.data.files[0].data;
let data = dataFile? (grunt.file.readJSON(dataFile)): [];
return {
file: arg,
home: data.homepage,
path: (arg.match(/^(.+)-\d/)[1]) + '.html',
slug: (arg.match(/^.+-\d+-(.*)\.twig$/i))[1],
commit: commit,
date: date,
};
},
},
filters: {
glob: function(arg) { return grunt.file.expand(arg); },
},
},
main: {
files: [
{
data: 'package.json',
expand: true,
src: ["*.twig", "!*-+([0-9])?(-*).twig", "!_*.twig"],
// tous les modèles TWIG, hormis les composants et les partiels
dest: publicFolder+'/',
ext: ".html"
}
]
}
}
});
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-twig-render');
grunt.registerTask('default', ['copy', 'twigRender']);
};