Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added build-demos task to generate all necessary resources for demos.

  • Loading branch information...
commit 5a2c73f35c6a0180cff902e2a012c3d9f490c662 1 parent 93a067b
@scottgonzalez scottgonzalez authored
Showing with 95 additions and 9 deletions.
  1. +90 −8 grunt.js
  2. +1 −1  package.json
  3. +4 −0 resources/demos/style.css
View
98 grunt.js
@@ -43,7 +43,7 @@ grunt.registerTask( "build-download", function() {
dir = path.dirname( require.resolve( "download.jqueryui.com" ) ),
done = this.async();
// at this point, the download builder repo is available, so let's initialize it
- grunt.log.writeln("Initializing download module, might take a while");
+ grunt.log.writeln( "Initializing download module, might take a while..." );
grunt.utils.spawn({
cmd: "grunt",
// TODO need to set this as config property or use the version from package.json
@@ -51,25 +51,107 @@ grunt.registerTask( "build-download", function() {
opts: {
cwd: "node_modules/download.jqueryui.com"
}
- }, function(error, result, stringResult) {
- if (error) {
+ }, function( error, result, stringResult ) {
+ if ( error ) {
grunt.log.error( error, stringResult );
- done(false);
+ done( false );
return;
}
- var markup = require( "download.jqueryui.com" )( "http://download.jqueryui.com/download" );
- grunt.file.write( grunt.config( "wordpress.dir" ) + "/posts/page/download.html", "<script>{\n \"title\": \"Downloadbuilder\"\n}</script>\n" + markup );
- var resources = grunt.file.expandFiles( dir + "/app/**" );
+
+ var markup = require( "download.jqueryui.com" )( "http://download.jqueryui.com/download" ),
+ resources = grunt.file.expandFiles( dir + "/app/**" );
+
+ grunt.file.write( grunt.config( "wordpress.dir" ) + "/posts/page/download.html",
+ "<script>{\n \"title\": \"Download Builder\"\n}</script>\n" + markup );
+
resources.forEach(function( file ) {
grunt.file.copy( file, file.replace( dir + "/app", grunt.config( "wordpress.dir" ) ) );
});
+
grunt.log.write( "Wrote page/download.html and " + resources.length + " resources." );
done();
});
+});
+
+grunt.registerTask( "build-demos", function() {
+ // We hijack the jquery-ui checkout from download.jqueryui.com
+ this.requires( "build-download" );
+
+ var path = require( "path" ),
+ repoDir = path.dirname( require.resolve( "download.jqueryui.com" ) ) +
+ "/tmp/jquery-ui",
+ demosDir = repoDir + "/demos",
+ distDir = repoDir + "/dist",
+ targetDir = grunt.config( "wordpress.dir" ) + "/resources/demos";
+
+ // Copy all demos files to /resources/demos
+ grunt.file.recurse( demosDir, function( abspath, rootdir, subdir, filename ) {
+ // skip the main index page
+ if ( !subdir ) {
+ return;
+ }
+
+ var dest = targetDir + "/" + subdir + "/" + filename;
+ if ( /html$/.test( filename ) ) {
+ grunt.file.copy( abspath, dest, {
+ process: replaceResources
+ });
+ } else {
+ grunt.file.copy( abspath, dest );
+ }
+ });
+
+ // Copy the built files into /resources/demos
+ grunt.file.copy(
+ grunt.file.expandFiles( repoDir + "/jquery-*.js" )[ 0 ],
+ targetDir + "/jquery.js" );
+ grunt.file.copy( distDir + "/jquery-ui.js", targetDir + "/jquery-ui.js" );
+ grunt.file.copy( distDir + "/jquery-ui.css", targetDir + "/theme/jquery-ui.css" );
+ grunt.file.expandFiles( distDir + "/images/**" ).forEach(function( filename ) {
+ grunt.file.copy( filename, targetDir + "/theme/images/" + path.basename( filename ) );
+ });
+
+ // Copy externals into /resources/demos/external
+ grunt.file.expandFiles( repoDir + "/external/**" ).forEach(function( filename ) {
+ grunt.file.copy( filename, targetDir + "/external/" + path.basename( filename ) );
+ });
+
+ function replaceResources( source ) {
+ // ../../jquery-x.y.z.js -> /resources/demos/jquery.js
+ source = source.replace(
+ /<script src="\.\.\/\.\.\/jquery-\d+\.\d+(\.\d+)?\.js">/,
+ "<script src=\"/resources/demos/jquery.js\">" );
+
+ // ../../ui/* -> /resources/demos/jquery-ui.js
+ // Only the first script is replaced, all subsequent scripts are dropped,
+ // including the full line
+ source = source.replace(
+ /<script src="\.\.\/\.\.\/ui\/[^>]+/,
+ "<script src=\"/resources/demos/jquery-ui.js\">" );
+ source = source.replace(
+ /^.*<script src="\.\.\/\.\.\/ui\/[^>]+><\/script>\n/gm,
+ "" );
+
+ // ../../external/* -> /resources/demos/external/*
+ source = source.replace(
+ /<script src="\.\.\/\.\.\/external\//g,
+ "<script src=\"/resources/demos/external/" );
+
+ // ../../ui/themes/* -> /resources/demos/theme/jquery-ui.css
+ source = source.replace(
+ /<link rel="stylesheet" href="\.\.\/\.\.\/themes[^>]+>/,
+ "<link rel=\"stylesheet\" href=\"/resources/demos/theme/jquery-ui.css\">" );
+
+ // ../demos.css -> /resources/demos/style.css
+ source = source.replace(
+ /<link rel="stylesheet" href="\.\.\/demos.css\">/,
+ "<link rel=\"stylesheet\" href=\"/resources/demos/style.css\">" );
+ return source;
+ }
});
grunt.registerTask( "default", "lint" );
-grunt.registerTask( "build-wordpress", "clean lint build-pages build-resources build-download");
+grunt.registerTask( "build-wordpress", "clean lint build-pages build-resources build-download build-demos" );
};
View
2  package.json
@@ -23,7 +23,7 @@
"grunt": "0.3.x",
"grunt-clean": "0.3.0",
"grunt-html": "0.1.1",
- "grunt-wordpress": "1.0.2",
+ "grunt-wordpress": "1.0.3",
"grunt-jquery-content": "0.4.x",
"download.jqueryui.com": "git://github.com/jquery/download.jqueryui.com.git"
},
View
4 resources/demos/style.css
@@ -0,0 +1,4 @@
+body {
+ font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
+ font-size: 62.5%;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.