mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-07-29 23:29:06 -04:00
Improved PrePro to be able to dynamically load Node.js code too, and improve load.js to handle both environments.
Also moved PaperScript .pjs extension code to PaperScript, and DOM related Node.js code to dom/node.js
This commit is contained in:
parent
94ce1f1312
commit
4f5dac8567
10 changed files with 148 additions and 139 deletions
src/core
|
@ -18,7 +18,7 @@
|
|||
// main paper scope, and is added to the PaperScope class. This allows for
|
||||
// better minification and the future use of strict mode once it makes sense
|
||||
// in terms of performance.
|
||||
paper.PaperScope.prototype.PaperScript = new function() {
|
||||
var PaperScript = paper.PaperScope.prototype.PaperScript = new function() {
|
||||
/*#*/ if (options.parser == 'acorn') {
|
||||
/*#*/ include('../../components/acorn/acorn.min.js');
|
||||
/*#*/ } else if (options.parser == 'esprima') {
|
||||
|
@ -332,3 +332,24 @@ paper.PaperScope.prototype.PaperScript = new function() {
|
|||
|
||||
/*#*/ } // !options.browser
|
||||
};
|
||||
|
||||
/*#*/ if (options.node) {
|
||||
|
||||
// Register the .pjs extension and have it automatically compile as PaperScript
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path');
|
||||
|
||||
require.extensions['.pjs'] = function(module, uri) {
|
||||
var source = PaperScript.compile(fs.readFileSync(uri, 'utf8')),
|
||||
scope = new PaperScope();
|
||||
scope.__filename = uri;
|
||||
scope.__dirname = path.dirname(uri);
|
||||
// Expose core methods and values
|
||||
scope.require = require;
|
||||
scope.console = console;
|
||||
PaperScript.evaluate(source, scope);
|
||||
module.exports = scope;
|
||||
};
|
||||
|
||||
/*#*/ } // options.node
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue