forked from jquery-archive/plugins.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grunt.js
156 lines (131 loc) · 4.08 KB
/
grunt.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
var config = require( "./lib/config" );
var path = require( "path" );
module.exports = function( grunt ) {
var async = grunt.utils.async;
grunt.loadNpmTasks( "grunt-wordpress" );
grunt.loadNpmTasks( "grunt-clean" );
grunt.loadNpmTasks( "grunt-jquery-content" );
grunt.loadNpmTasks( "grunt-check-modules" );
grunt.initConfig({
clean: {
wordpress: "dist/"
},
lint: {
grunt: "grunt.js",
src: [ "lib/**", "scripts/**" ]
},
jshint: {
grunt: { options: grunt.file.readJSON( ".jshintrc" ) },
src: { options: grunt.file.readJSON( ".jshintrc" ) }
},
watch: {
docs: {
files: "pages/**",
tasks: "docs"
}
},
test: {
files: [ "test/**/*.js" ]
},
"build-pages": {
all: grunt.file.expandFiles( "pages/**" )
},
"build-resources": {
all: grunt.file.expandFiles( "resources/**/*" )
},
wordpress: grunt.utils._.extend({
dir: "dist/wordpress"
}, config.wordpress )
});
// We only want to sync the documentation, so we override wordpress-get-postpaths
// to only find pages. This ensures that we don't delete all of the plugin posts.
grunt.registerHelper( "wordpress-get-postpaths", function( fn ) {
var client = grunt.helper( "wordpress-client" );
grunt.verbose.write( "Getting post paths from WordPress..." );
client.call( "gw.getPostPaths", "page", function( error, postPaths ) {
if ( error ) {
grunt.verbose.error();
return fn( error );
}
grunt.verbose.ok();
grunt.verbose.writeln();
fn( null, postPaths );
});
});
grunt.registerTask( "sync-docs", function() {
var done = this.async();
var dir = grunt.config( "wordpress.dir" );
async.waterfall([
function syncPosts( fn ) {
grunt.helper( "wordpress-sync-posts", "dist/wordpress/posts/", fn );
},
function syncResources( fn ) {
grunt.helper( "wordpress-sync-resources", path.join( dir, "resources/" ), fn );
}
], function( error ) {
if ( !error ) {
return done();
}
done( false );
});
});
// clean-all will delete EVERYTHING, including the plugin registery. This is
// useful only for development if you want a clean slate to test from.
grunt.registerTask( "clean-all", function() {
var rimraf = require( "rimraf" ),
retry = require( "./lib/retrydb" );
// clean repo checkouts
rimraf.sync( config.repoDir );
// clean pluginsDb
rimraf.sync( config.pluginsDb );
rimraf.sync( config.lastActionFile );
// clean retrydb
rimraf.sync( retry.dbPath );
});
// clean-retries will only delete information about retries. It will not delete the
// plugin registry and it will not remove local clones. This is useful for
// restoring a WordPress site on a server that already has repos.
grunt.registerTask( "clean-retries", function() {
var rimraf = require( "rimraf" ),
retry = require( "./lib/retrydb" );
rimraf.sync( config.lastActionFile );
rimraf.sync( retry.dbPath );
});
grunt.registerTask( "setup-pluginsdb", function() {
var done = this.async();
require( "./lib/pluginsdb" )._setup(function( error ) {
if ( error ) {
return done( false );
}
done();
});
});
grunt.registerTask( "setup-retrydb", function() {
var done = this.async();
require( "./lib/retrydb" )._setup(function( error ) {
if ( error ) {
return done( false );
}
done();
});
});
grunt.registerTask( "restore-repos", function() {
var service = require( "./lib/service" ),
pluginsDb = require( "./lib/pluginsdb" ),
done = this.async();
pluginsDb.getAllRepos(function( error, repos ) {
grunt.utils.async.mapSeries( repos, function( repo, fn ) {
service.getRepoById( repo ).restore( fn );
}, function( error ) {
if ( error ) {
return done( false );
}
done();
});
});
});
grunt.registerTask( "default", "lint test" );
grunt.registerTask( "setup", "setup-pluginsdb setup-retrydb build-pages sync-docs build-resources" );
grunt.registerTask( "update", "clean build-pages build-resources sync-docs" );
grunt.registerTask( "restore", "clean-retries setup-retrydb build-pages sync-docs build-resources restore-repos" );
};