Skip to content

Commit da83fc5

Browse files
committed
Build: Publish machine-readable file list and SRI data to resources/
Let "wordpress-deploy" upload this to the site, which the gw-resources plugin exposes via addresses like <https://releases.jquery.com/resources/foo>. See <https://github.com/jquery/api.jquery.com/> for an example of this. Local test plan: ``` nobody$ npm ci nobody$ cp config-sample.json config.json nobody$ ./node_modules/.bin/grunt sri nobody$ less resources/sri-directives.json {"@cdn/color/2.2.0/jquery.color.js":{"hashes":{"sha256":"gvMJWDH... nobody$ ./node_modules/.bin/grunt build-index build-resources nobody$ less dist/wordpress/resources/sri-directives.json {"@cdn/color/2.2.0/jquery.color.js":{"hashes":{"sha256":"gvMJWDH... nobody$ less dist/wordpress/resources/cdn.json { "jquery": [ [ "3", { "latestStable": { "filename": "jquery-3.6.0.js", ... ``` Closes #40.
1 parent 6e13f6e commit da83fc5

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/node_modules/
22
/dist/
3+
/resources/sri-directives.json
34
/git/
45
/config.js*

Gruntfile.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ grunt.initConfig( {
1717
],
1818
options: {
1919
algorithms: ["sha256"],
20-
dest: "dist/resources/sri-directives.json"
20+
dest: "resources/sri-directives.json"
2121
}
2222
}
2323
},
@@ -28,7 +28,14 @@ grunt.initConfig( {
2828
var config = require( "./config" );
2929
config.dir = "dist/wordpress";
3030
return config;
31-
})()
31+
})(),
32+
33+
// This copies /resources/* to /dist/wordpress/resources/*,
34+
// This is flattened (subpaths not preserved) to just base filenames,
35+
// and then uploaded by "wordpress-deploy" to the web server.
36+
"build-resources": {
37+
all: "resources/**"
38+
}
3239
} );
3340

3441
grunt.registerTask( "build-index", function() {
@@ -310,7 +317,7 @@ grunt.registerTask( "build-index", function() {
310317
};
311318
}
312319

313-
var sriHashes = require( "./dist/resources/sri-directives.json" );
320+
var sriHashes = require( "./resources/sri-directives.json" );
314321

315322
function cdnSriLink( file, label ) {
316323
var sri = "sha256-" + sriHashes[ `@cdn/${ file }` ].hashes.sha256,
@@ -426,6 +433,9 @@ grunt.registerTask( "build-index", function() {
426433

427434
grunt.file.write( "dist/wordpress/posts/page/pep.html",
428435
Handlebars.compile( grunt.file.read( "templates/pep.hbs" ) )( data ) );
436+
437+
grunt.file.write( "dist/wordpress/resources/cdn.json",
438+
JSON.stringify( data, null, 2 ) );
429439
} );
430440

431441
grunt.registerTask( "reload-listings", function() {
@@ -455,16 +465,12 @@ grunt.registerTask( "reload-listings", function() {
455465
} );
456466
} );
457467

458-
grunt.registerTask( "ensure-dist-resources", function() {
459-
grunt.file.mkdir( "dist/resources" );
460-
} );
461-
462468
grunt.registerTask( "sri-generate", ["ensure-dist-resources", "sri:generate"] );
463469

464470
// The "grunt deploy" command is automatically invoked on git-commit by the server that
465471
// will deploy the WordPress site.
466472
// Task tree: "deploy" > "wordpress-deploy" > "build-wordpress" > "build".
467-
grunt.registerTask( "build", ["sri-generate", "build-index"] );
473+
grunt.registerTask( "build", ["sri-generate", "build-index", "build-resources"] );
468474
grunt.registerTask( "deploy", ["wordpress-deploy", "reload-listings"] );
469475

470476
};

resources/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)