Improve src/load.js to directly load the library through PrePro's load.js

This commit is contained in:
Jürg Lehni 2013-06-26 19:14:54 -07:00
parent 4e173a7d35
commit 214db84b84
4 changed files with 25 additions and 23 deletions

View file

@ -10,14 +10,8 @@
#
# All rights reserved.
# Generate a paper.js file that uses load.js to directly load the library from
# the seperate source files in the src directory using PrePro.
# This is very useful during development of the library itself.
# This script simply generates a symbolic link from dist/paper.js to src/load.js
# which loads the library from separate sources through PrePro.
echo "// Paper.js loader for development, as produced by the build/load.sh script
document.write('<script type=\"text/javascript\" src=\"../../node_modules/prepro/lib/load.js\"></script>');
document.write('<script type=\"text/javascript\" src=\"../../src/load.js\"></script>');
// For more information on building the library please refer to the
// 'Building the Library' section of README.md:
// https://github.com/paperjs/paper.js#building-the-library" > ../dist/paper.js;
rm ../dist/paper.js
ln -s ../src/load.js ../dist/paper.js

7
dist/paper.js vendored
View file

@ -1,7 +0,0 @@
// Paper.js loader for development, as produced by the build/load.sh script
document.write('<script type="text/javascript" src="../../node_modules/prepro/lib/load.js"></script>');
document.write('<script type="text/javascript" src="../../src/load.js"></script>');
// For more information on building the library please refer to the
// 'Building the Library' section of README.md:
// https://github.com/paperjs/paper.js#building-the-library

1
dist/paper.js vendored Symbolic link
View file

@ -0,0 +1 @@
../src/load.js

View file

@ -10,9 +10,24 @@
* All rights reserved.
*/
// This file is only used by examples and unit tests, using Prepro's load.js to
// 'preprocess' it on the fly in the browser, avoiding the step of having to
// manually preprocess it after each change.
// This file uses PrePro to preprocess the paper.js source code on the fly in
// the browser, avoiding the step of having to manually preprocess it after each
// change. This is very useful during development of the library itself.
include('options.js');
include('paper.js');
if (!window.include) {
var scripts = document.getElementsByTagName('script');
var src = scripts[scripts.length - 1].getAttribute('src');
// Assume that we're loading load.js from a root folder, either through
// dist/paper.js symbolic link, or directly through src/load.js, and match
// root as all the parts of the path that lead to that folder.
var root = src.match(/^(.*\/)\w*\//)[1];
// First load the PrePro's load.js file, which provides the include()
// function for the browser.
document.write('<script type="text/javascript" src="' + root + 'node_modules/prepro/lib/load.js"></script>');
// Now that we have include(), load this file again, which will execute the
// lower part of the code the 2nd time around.
document.write('<script type="text/javascript" src="' + root + 'src/load.js"></script>');
} else {
include('options.js');
include('paper.js');
}

View file

@ -3,7 +3,6 @@
<head>
<title>Paper.js Tests</title>
<link rel="stylesheet" href="lib/qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../node_modules/prepro/lib/load.js"></script>
<script type="text/javascript" src="../src/load.js"></script>
<script type="text/javascript" src="load.js"></script>
</head>