diff --git a/build/load.sh b/build/load.sh index ba0f385e..8462ad5b 100755 --- a/build/load.sh +++ b/build/load.sh @@ -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(''); -document.write(''); - -// 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; \ No newline at end of file +rm ../dist/paper.js +ln -s ../src/load.js ../dist/paper.js diff --git a/dist/paper.js b/dist/paper.js deleted file mode 100644 index 4e35797c..00000000 --- a/dist/paper.js +++ /dev/null @@ -1,7 +0,0 @@ -// Paper.js loader for development, as produced by the build/load.sh script -document.write(''); -document.write(''); - -// 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 diff --git a/dist/paper.js b/dist/paper.js new file mode 120000 index 00000000..37e257c7 --- /dev/null +++ b/dist/paper.js @@ -0,0 +1 @@ +../src/load.js \ No newline at end of file diff --git a/src/load.js b/src/load.js index 53e3dcdb..5d274ca5 100644 --- a/src/load.js +++ b/src/load.js @@ -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(''); + // Now that we have include(), load this file again, which will execute the + // lower part of the code the 2nd time around. + document.write(''); +} else { + include('options.js'); + include('paper.js'); +} diff --git a/test/index.html b/test/index.html index 54c9315b..956a0e40 100644 --- a/test/index.html +++ b/test/index.html @@ -3,7 +3,6 @@