forked from jquery-archive/plugins.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grunt.js
189 lines (157 loc) · 4.75 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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.registerMultiTask( "build-resources", "Copy resources", function() {
var task = this,
taskDone = task.async(),
files = this.data,
targetDir = grunt.config( "wordpress.dir" ) + "/resources/";
grunt.file.mkdir( targetDir );
grunt.utils.async.forEachSeries( files, function( fileName, fileDone ) {
grunt.file.copy( fileName, targetDir + fileName.replace( /^.+?\//, "" ) );
fileDone();
}, function() {
if ( task.errorCount ) {
grunt.warn( "Error building resources." );
return taskDone( false );
}
grunt.log.writeln( "Built " + files.length + " resources." );
// Build validate.js
grunt.file.write( targetDir + "/validate.js",
"(function() {" +
grunt.file.read( require.resolve( "semver" ) ) + ";" +
grunt.file.read( "lib/manifest.js" ) +
grunt.file.read( "resources/validate.js" ) +
"})();" );
taskDone();
});
});
grunt.registerTask( "sync-docs", function() {
var done = this.async(),
dir = grunt.config( "wordpress.dir" );
async.waterfall([
function syncPosts( fn ) {
grunt.helper( "wordpress-sync-posts", path.join( dir, "posts/" ), fn );
},
function syncResources( fn ) {
grunt.helper( "wordpress-sync-resources", path.join( dir, "resources/" ), fn );
}
], function( error ) {
if ( error ) {
return done( false );
}
done();
});
});
// 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( "publish-docs", "build-pages build-resources sync-docs" );
grunt.registerTask( "setup", "setup-pluginsdb setup-retrydb publish-docs" );
grunt.registerTask( "update", "clean publish-docs" );
grunt.registerTask( "restore", "clean-retries setup-retrydb publish-docs restore-repos" );
};