Build Rust documentation as part of the demo client build process

This commit is contained in:
Patrick Walton 2017-12-21 18:01:00 -08:00
parent b6236ac835
commit 934086ace8
4 changed files with 60 additions and 1 deletions

View File

@ -0,0 +1,43 @@
const {spawn} = require('child_process');
class RustdocPlugin {
constructor(options) {
this.options = Object.assign({
directories: [],
onBeforeSetup: Function.prototype,
onBeforeAddPartials: Function.prototype,
onBeforeCompile: Function.prototype,
onBeforeRender: Function.prototype,
onBeforeSave: Function.prototype,
onDone: Function.prototype
}, options);
}
apply(compiler) {
compiler.plugin("make", (compilation, done) => {
let directoriesLeft = this.options.directories.length;
for (const directory of this.options.directories) {
console.log("Building documentation for `" + directory + "`...");
const cargo = spawn("cargo", ["doc"], {cwd: directory});
cargo.stdout.setEncoding('utf8');
cargo.stderr.setEncoding('utf8');
cargo.stdout.on('data', data => console.log(data));
cargo.stderr.on('data', data => console.log(data));
cargo.on('close', code => {
if (code !== 0) {
const message = "Failed to build documentation for `" + directory + "`!";
console.error(message);
throw new Error(message);
}
console.log("Built documentation for `" + directory + "`.");
directoriesLeft--;
if (directoriesLeft === 0)
done();
});
}
});
}
}
module.exports = RustdocPlugin;

View File

@ -0,0 +1,11 @@
{
"name": "rustdoc-webpack-plugin",
"version": "0.1.0",
"description": "Webpack plugin for building Rust package documentation",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Patrick Walton",
"license": "MIT OR Apache-2.0"
}

View File

@ -32,6 +32,7 @@
"parse-color": "^1.0.0",
"path-data-polyfill.js": "^1.0.2",
"popper.js": "^1.12.5",
"rustdoc-webpack-plugin": "file:./build/rustdoc-webpack-plugin",
"ts-loader": "^2.3.7",
"typescript": "^2.5.2",
"webpack": "^3.5.6"

View File

@ -1,5 +1,6 @@
const Handlebars = require('handlebars');
const HandlebarsPlugin = require('handlebars-webpack-plugin');
const RustdocPlugin = require('rustdoc-webpack-plugin');
const fs = require('fs');
module.exports = {
@ -48,6 +49,9 @@ module.exports = {
return new Handlebars.SafeString(svg);
}
},
})
}),
new RustdocPlugin({
directories: ["../../font-renderer"],
}),
]
}