Skip to content

Instantly share code, notes, and snippets.

@therewasaguy
Last active July 12, 2017 04:16
Show Gist options
  • Save therewasaguy/8da82de2b948955d5baaa0fbffb71b0c to your computer and use it in GitHub Desktop.
Save therewasaguy/8da82de2b948955d5baaa0fbffb71b0c to your computer and use it in GitHub Desktop.
p5.sound documentation watch script
/*
Place this in the same directory as your p5.js, p5.js-sound, and p5.js-website repos.
Tested on nodejs version 6+
Usage:
- Run `node docwatch.js` in the root directory.
- Run `grunt watch` in p5.js-sound directory.
- Run `grunt run` in p5.js-website directory.
*/
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
// watch p5.sound for changes and copy the output to p5.js `addons`
fs.watchFile('./p5.js-sound/lib/p5.sound.js', function() {
process.chdir(__dirname);
const cmd = spawn('cp', ['./p5.js-sound/lib/p5.sound.js', './p5.js/lib/addons/p5.sound.js']);
// once the compiled p5.js-sound has been moved to p5.js `addons`, generate documentation
cmd.on('close', function() {
process.chdir(path.join(__dirname, './p5.js'));
console.log('running grunt yui:docs');
const gruntTask = spawn('grunt', ['yui:docs']);
gruntTask.stdout.on('data', function(data) {
console.log(`stdout: ${data}`)
});
gruntTask.stderr.on('data', function(data) {
console.log(`stderr: ${data}`)
});
});
cmd.stdout.on('data', function(data) {
console.log(`stdout: ${data}`)
});
cmd.stderr.on('data', function(data) {
console.log(`stderr: ${data}`)
});
});
// watch for output of `grunt yui:docs` and copy it to p5.js-website repo
fs.watchFile('./p5.js/docs/reference/data.min.json', function() {
console.log('copying docs');
process.chdir(__dirname);
spawn('cp', ['./p5.js/docs/reference/data.min.json', './p5.js-website/dist/reference/data.min.json']);
console.log('copied');
});
console.log('watching files for changes');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment