This repository was archived by the owner on Mar 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcompile.js
More file actions
33 lines (30 loc) · 1.22 KB
/
compile.js
File metadata and controls
33 lines (30 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Compile processing code into javascript, so that can be used in webpage more effectively (no p5 lang parsing step by client needed)
// Intended to use with Grunt when developing and deploying web applications
// contribution by kroko.me
var fs = require('fs');
var p5 = require('processing');
if (process.argv.length != 5) {
console.log("Usage: node compile.js <input_sketch.pde> <output_filename.js> <variable_name_to_store_p5js_app_into>");
process.exit(code = 1);
}
else {
console.log("Reading file: " + process.argv[2]);
console.log("Output will be: " + process.argv[3]);
console.log("Variable will be: " + process.argv[4]);
}
console.log("Compiling sketch...");
fs.readFile(process.argv[2], function(err, data) {
var compiled = p5.Processing.compile(data.toString('utf-8'));
compiled = "var " + process.argv[4] + " = " + compiled + ";";
fs.writeFile(process.argv[3], compiled, function(err) {
if (err) {
console.log(err);
} else {
console.log("...done!");
}
});
});
// Usage in web
// var domCanvas = document.getElementById('id_of_canvas_dom_element');
// pjsPtr = new Processing(domCanvas, valiable_name_as_passed_to_this_script);
// if (pjsPtr) { }