-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathgrunt.js
More file actions
104 lines (94 loc) · 2.5 KB
/
grunt.js
File metadata and controls
104 lines (94 loc) · 2.5 KB
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
/*jshint node:true */
module.exports = function( grunt ) {
var // modules
fs = require( "fs" ),
path = require( "path" ),
spawn = require( "child_process" ).spawn,
// files
entryFiles = grunt.file.expandFiles( "entries/*.xml" );
grunt.loadNpmTasks( "grunt-wordpress" );
grunt.initConfig({
lint: {
grunt: "grunt.js"
},
xmllint: {
all: entryFiles
},
wordpress: grunt.file.readJSON( "config.json" )
});
grunt.registerTask( "xmllint", function() {
var task = this,
taskDone = task.async();
grunt.utils.async.forEachSeries( entryFiles, function( fileName, fileDone ) {
grunt.verbose.write( "Linting " + fileName + "..." );
grunt.utils.spawn({
cmd: "xmllint",
args: [ "--noout", fileName ]
}, function( err, result ) {
if ( err ) {
grunt.verbose.error();
grunt.log.error( err );
fileDone();
return;
}
grunt.verbose.ok();
fileDone();
});
}, function() {
if ( task.errorCount ) {
grunt.warn( "Task \"" + task.name + "\" failed." );
taskDone();
return;
}
grunt.log.writeln( "Lint free files: " + entryFiles.length );
taskDone();
});
});
grunt.registerTask( "build-entries", function() {
var task = this,
taskDone = task.async(),
// TODO make `entry` a custom post type instead of (ab)using `post`?
targetDir = "dist/post/";
grunt.file.mkdir( targetDir );
grunt.utils.async.forEachSeries( entryFiles, function( fileName, fileDone ) {
grunt.verbose.write( "Reading " + fileName + "..." );
grunt.utils.spawn({
cmd: "xsltproc",
args: [ "entries2html.xsl", fileName ]
}, function( err, result ) {
var targetFileName;
if ( err ) {
grunt.verbose.error();
grunt.log.error( err );
fileDone();
return;
}
grunt.verbose.ok();
targetFileName = targetDir + path.basename( fileName );
targetFileName = targetFileName.substr( 0, targetFileName.length - "xml".length ) + "html";
grunt.verbose.write( "Writing " + targetFileName + "..." );
fs.writeFile( targetFileName, result, function( err ) {
if ( err ) {
grunt.verbose.error();
grunt.log.error( err );
fileDone();
return;
}
grunt.verbose.ok();
fileDone();
});
});
}, function() {
if ( task.errorCount ) {
grunt.warn( "Task \"" + task.name + "\" failed." );
taskDone();
return;
}
grunt.log.writeln( "Built " + entryFiles.length + " entries." );
taskDone();
});
});
grunt.registerTask( "default", "build" );
grunt.registerTask( "build", "lint xmllint build-entries" );
grunt.registerTask( "deploy", "wordpress-deploy" );
};