mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Improve PaperScript extension code for Node.js
This commit is contained in:
parent
4f5dac8567
commit
5245a30930
1 changed files with 21 additions and 22 deletions
|
@ -18,7 +18,7 @@
|
||||||
// main paper scope, and is added to the PaperScope class. This allows for
|
// 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
|
// better minification and the future use of strict mode once it makes sense
|
||||||
// in terms of performance.
|
// in terms of performance.
|
||||||
var PaperScript = paper.PaperScope.prototype.PaperScript = new function() {
|
paper.PaperScope.prototype.PaperScript = new function() {
|
||||||
/*#*/ if (options.parser == 'acorn') {
|
/*#*/ if (options.parser == 'acorn') {
|
||||||
/*#*/ include('../../components/acorn/acorn.min.js');
|
/*#*/ include('../../components/acorn/acorn.min.js');
|
||||||
/*#*/ } else if (options.parser == 'esprima') {
|
/*#*/ } else if (options.parser == 'esprima') {
|
||||||
|
@ -324,6 +324,26 @@ var PaperScript = paper.PaperScope.prototype.PaperScript = new function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/*#*/ } else { // !options.browser
|
/*#*/ } else { // !options.browser
|
||||||
|
/*#*/ if (options.node) {
|
||||||
|
|
||||||
|
// Register the .pjs extension for automatic compilation as PaperScript
|
||||||
|
|
||||||
|
var fs = require('fs'),
|
||||||
|
path = require('path');
|
||||||
|
|
||||||
|
require.extensions['.pjs'] = function(module, uri) {
|
||||||
|
var source = 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;
|
||||||
|
evaluate(source, scope);
|
||||||
|
module.exports = scope;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*#*/ } // options.node
|
||||||
|
|
||||||
return {
|
return {
|
||||||
compile: compile,
|
compile: compile,
|
||||||
|
@ -332,24 +352,3 @@ var PaperScript = paper.PaperScope.prototype.PaperScript = new function() {
|
||||||
|
|
||||||
/*#*/ } // !options.browser
|
/*#*/ } // !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…
Reference in a new issue