Skip to content

Commit df3587e

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 88bcd07 commit df3587e

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

.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
@@ -19,7 +19,7 @@ grunt.initConfig( {
1919
],
2020
options: {
2121
algorithms: ["sha256"],
22-
dest: "dist/resources/sri-directives.json"
22+
dest: "resources/sri-directives.json"
2323
}
2424
}
2525
},
@@ -30,7 +30,14 @@ grunt.initConfig( {
3030
var config = require( "./config" );
3131
config.dir = "dist/wordpress";
3232
return config;
33-
})()
33+
})(),
34+
35+
// This copies /resources/* to /dist/wordpress/resources/*,
36+
// This is flattened (subpaths not preserved) to just base filenames,
37+
// and then uploaded by "wordpress-deploy" to the web server.
38+
"build-resources": {
39+
all: "resources/**"
40+
}
3441
} );
3542

3643
grunt.registerTask( "build-index", function() {
@@ -312,7 +319,7 @@ grunt.registerTask( "build-index", function() {
312319
};
313320
}
314321

315-
var sriHashes = require( "./dist/resources/sri-directives.json" );
322+
var sriHashes = require( "./resources/sri-directives.json" );
316323

317324
function cdnSriLink( file, label ) {
318325
var sri = "sha256-" + sriHashes[ `@cdn/${ file }` ].hashes.sha256,
@@ -428,6 +435,9 @@ grunt.registerTask( "build-index", function() {
428435

429436
grunt.file.write( "dist/wordpress/posts/page/pep.html",
430437
Handlebars.compile( grunt.file.read( "templates/pep.hbs" ) )( data ) );
438+
439+
grunt.file.write( "dist/wordpress/resources/cdn.json",
440+
JSON.stringify( data, null, 2 ) );
431441
} );
432442

433443
grunt.registerTask( "reload-listings", function() {
@@ -457,16 +467,12 @@ grunt.registerTask( "reload-listings", function() {
457467
} );
458468
} );
459469

460-
grunt.registerTask( "ensure-dist-resources", function() {
461-
grunt.file.mkdir( "dist/resources" );
462-
} );
463-
464470
grunt.registerTask( "sri-generate", ["ensure-dist-resources", "sri:generate"] );
465471

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

472478
};

resources/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)