Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge of noopto branch that moves the node/rhin adapter and optimizer…

… to a separate r.js project.
  • Loading branch information...
commit 0b6c3aa621cbd5e9d78206d0ada4457b354bff14 2 parents 72d2840 + 3b4847d
@jrburke authored
Showing with 435 additions and 7,835 deletions.
  1. +0 −73 adapt/dist.js
  2. +0 −77 adapt/node.js
  3. +0 −26 adapt/rhino.js
  4. +0 −49 adapt/tests/all.js
  5. +0 −3  adapt/tests/alpha.js
  6. +0 −6 adapt/tests/beta.js
  7. +0 −37 adapt/tests/node/canvasTest.js
  8. +0 −11 adapt/tests/node/index.js
  9. +0 −6 adapt/tests/node/tests/alpha/foo.js
  10. +0 −9 adapt/tests/node/tests/alpha/hello.html
  11. +0 −3  adapt/tests/node/tests/foo.js
  12. +0 −11 adapt/tests/node/tests/server.js
  13. +0 −10 adapt/tests/relative.js
  14. +0 −3  adapt/tests/sub/betaSub.js
  15. +0 −6 bin/x
  16. +0 −2  bin/x.bat
  17. +0 −131 bin/x.js
  18. +0 −7 bin/xdebug
  19. +0 −2  bin/xdebug.bat
  20. +0 −6 bin/xj
  21. +0 −2  bin/xj.bat
  22. +0 −4 bin/xjdebug
  23. +0 −2  bin/xjdebug.bat
  24. +0 −2  build/build.bat
  25. +0 −49 build/build.js
  26. +0 −4 build/build.sh
  27. +0 −2  build/buildebug.bat
  28. +0 −4 build/buildebug.sh
  29. +0 −4 build/buildebugj.sh
  30. +0 −2  build/buildj.bat
  31. +0 −4 build/buildj.sh
  32. +0 −2  build/buildjdebug.bat
  33. +0 −2  build/convert/commonjs/convert.bat
  34. +0 −33 build/convert/commonjs/convert.js
  35. +0 −4 build/convert/commonjs/convert.sh
  36. +0 −214 build/convert/stealjs/parse.js
  37. +0 −23 build/convert/stealjs/tests/all.js
  38. +0 −20 build/convert/stealjs/tests/parse.js
  39. +0 −183 build/example.build.js
  40. +0 −4 build/jslib/blank.js
  41. +0 −725 build/jslib/build.js
  42. +0 −23 build/jslib/commandLine.js
  43. +0 −152 build/jslib/commonJs.js
  44. +0 −47 build/jslib/env.js
  45. +0 −49 build/jslib/lang.js
  46. +0 −53 build/jslib/logger.js
  47. +0 −15 build/jslib/node/args.js
  48. +0 −223 build/jslib/node/file.js
  49. +0 −17 build/jslib/node/load.js
  50. +0 −10 build/jslib/node/optimize.js
  51. +0 −16 build/jslib/node/print.js
  52. +0 −253 build/jslib/optimize.js
  53. +0 −11 build/jslib/opto.build.js
  54. +0 −387 build/jslib/parse.js
  55. +0 −117 build/jslib/pragma.js
  56. +0 −207 build/jslib/requirePatch.js
  57. +0 −16 build/jslib/rhino/args.js
  58. +0 −239 build/jslib/rhino/file.js
  59. +0 −12 build/jslib/rhino/load.js
  60. +0 −95 build/jslib/rhino/optimize.js
  61. +0 −12 build/jslib/rhino/print.js
  62. +0 −13 build/jslib/uglifyjs/README.md
  63. +0 −5 build/jslib/uglifyjs/index.js
  64. +0 −1,249 build/jslib/uglifyjs/parse-js.js
  65. +0 −1,568 build/jslib/uglifyjs/process.js
  66. +0 −26 build/jslib/uglifyjs/squeeze-more.js
  67. +0 −202 build/lib/closure/COPYING
  68. +0 −261 build/lib/closure/README
  69. BIN  build/lib/closure/compiler.jar
  70. +0 −4 build/lib/rhino/LICENSE
  71. BIN  build/lib/rhino/js.jar
  72. +0 −43 build/tests/all.js
  73. +0 −7 build/tests/anonSimple.build.js
  74. +0 −138 build/tests/builds.js
  75. +0 −18 build/tests/circular.build.js
  76. +0 −18 build/tests/convert.js
  77. +0 −6 build/tests/css.build.js
  78. +0 −4 build/tests/css/common/common.css
  79. +0 −10 build/tests/css/master.css
  80. +0 −7 build/tests/css/sub/sub1.css
  81. +0 −13 build/tests/cssTestCompare.css
  82. +0 −12 build/tests/exports.build.js
  83. +0 −10 build/tests/hasTestModule.build.js
  84. +0 −30 build/tests/hasTestModule.js
  85. +0 −17 build/tests/i18n.build.js
  86. +0 −8 build/tests/indexBuilder.build.js
  87. +0 −16 build/tests/order.build.js
  88. +0 −59 build/tests/packages.build.js
  89. +0 −105 build/tests/parse.js
  90. +0 −13 build/tests/simple.build.js
  91. +0 −15 build/tests/text.build.js
  92. +0 −16 build/tests/textExclude.build.js
  93. +0 −13 dist/dist-build.sh
  94. +96 −97 dist/dist-site.js
  95. +227 −0 dist/file.js
  96. +1 −1  docs/api.html
  97. +1 −1  docs/commonjs.html
  98. +29 −50 docs/download.html
  99. +6 −13 docs/jquery.html
  100. +3 −3 docs/node.html
  101. +19 −38 docs/optimization.html
  102. +1 −1  docs/start.html
  103. +4 −4 require.js
  104. +15 −0 tasks.txt
  105. +33 −0 updatesubs.sh
View
73 adapt/dist.js
@@ -1,73 +0,0 @@
-/**
- * @license Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
- * Available via the MIT or new BSD license.
- * see: http://github.com/jrburke/requirejs for details
- */
-
-/*
- * This script will create the final r.js file used in node projects to use
- * RequireJS.
- *
- * This file uses Node to run:
- * node dist.js
- */
-
-/*jslint strict: false */
-/*global require: false, process: false, console: false */
-
-/**
- * Escapes a string so it is safe as a JS string
- * Taken from Dojo's buildUtil.jsEscape
- * @param {String} str
- * @returns {String}
- */
-function jsEscape(str) {
- return ('"' + str.replace(/(["\\])/g, '\\$1') + '"'
- ).replace(/[\f]/g, '\\f'
- ).replace(/[\b]/g, '\\b'
- ).replace(/[\n]/g, '\\n'
- ).replace(/[\t]/g, '\\t'
- ).replace(/[\r]/g, '\\r'); // string
-}
-
-var fs = require('fs'),
- child_process = require('child_process'),
- contents = fs.readFileSync('../bin/x.js', 'utf8'),
- loadRegExp = /readFile\(requireBuildPath \+ '([\w\/\.]+)'\)/g;
-
-//Inline file contents
-contents = contents.replace(loadRegExp, function (match, fileName) {
- return jsEscape(fs.readFileSync('../' + fileName, 'utf8'));
-});
-
-//Switch the behavior to "inlined mode"
-contents = contents.replace(/useRequireBuildPath \= true/, 'useRequireBuildPath = false');
-
-if (process.argv[2] === 'opto') {
- //Build the optimizer into one file, opto.js
- //Run the opto.build.js and insert the result into the built file.
- child_process.exec('cd ../build/jslib && ../build.sh opto.build.js && cd ../../adapt',
- function (error, stdout, stderr) {
- if (error) {
- console.log('Could not build opto: ' + error);
- return;
- }
-
- var optoBuildFileName = '../build/jslib/optotext.js',
- optoText = fs.readFileSync(optoBuildFileName, 'utf8');
-
- //Inject the content into the final output.
- contents = contents.replace('exec(readFile(fileName), fileName);', optoText);
-
- //Set the isOpto flag to true
- contents = contents.replace('isOpto = false', 'isOpto = true');
- fs.writeFileSync('opto.js', contents, 'utf8');
-
- //Remove build output since no longer needed.
- fs.unlinkSync(optoBuildFileName);
-
- }
- );
-} else {
- fs.writeFileSync('r.js', contents, 'utf8');
-}
View
77 adapt/node.js
@@ -1,77 +0,0 @@
-/**
- * @license RequireJS node Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
- * Available via the MIT or new BSD license.
- * see: http://github.com/jrburke/requirejs for details
- */
-
-/*jslint regexp: false, strict: false */
-/*global require: false, define: false, nodeRequire: true, process: false */
-
-/**
- * This adapter assumes that x.js has loaded it and set up
- * some variables. This adapter just allows limited RequireJS
- * usage from within the requirejs directory. The general
- * node adapater is r.js.
- */
-(function () {
- var req = nodeRequire,
- fs = req('fs'),
- path = req('path'),
- vm = req('vm');
-
- //Clear out the global set by x.js
- nodeRequire = null;
-
- //Make nodeRequire available off of require, to allow a script to
- //add things to its require.paths for example.
- require.nodeRequire = req;
-
- //Supply an implementation that allows synchronous get of a module.
- require.get = function (context, moduleName, relModuleMap) {
- if (moduleName === "require" || moduleName === "exports" || moduleName === "module") {
- require.onError(new Error("Explicit require of " + moduleName + " is not allowed."));
- }
-
- var ret,
- moduleMap = context.makeModuleMap(moduleName, relModuleMap);
-
- //Normalize module name, if it contains . or ..
- moduleName = moduleMap.fullName;
-
- if (moduleName in context.defined) {
- ret = context.defined[moduleName];
- } else {
- if (ret === undefined) {
- //Try to dynamically fetch it.
- require.load(context, moduleName, moduleMap.url);
- //The above call is sync, so can do the next thing safely.
- ret = context.defined[moduleName];
- }
- }
-
- return ret;
- };
-
- require.load = function (context, moduleName, url) {
- var contents;
-
- //isDone is used by require.ready()
- require.s.isDone = false;
-
- //Indicate a the module is in process of loading.
- context.loaded[moduleName] = false;
- context.scriptCount += 1;
-
- if (path.existsSync(url)) {
- contents = fs.readFileSync(url, 'utf8');
- vm.runInThisContext(contents, url);
- } else {
- define(moduleName, function () {
- return req(moduleName);
- });
- }
-
- //Support anonymous modules.
- context.completeLoad(moduleName);
- };
-}());
View
26 adapt/rhino.js
@@ -1,26 +0,0 @@
-/**
- * @license RequireJS rhino Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
- * Available via the MIT or new BSD license.
- * see: http://github.com/jrburke/requirejs for details
- */
-
-/*jslint strict: false */
-/*global require: false, java: false, load: false */
-
-(function () {
-
- require.load = function (context, moduleName, url) {
- //isDone is used by require.ready()
- require.s.isDone = false;
-
- //Indicate a the module is in process of loading.
- context.loaded[moduleName] = false;
- context.scriptCount += 1;
-
- load(url);
-
- //Support anonymous modules.
- context.completeLoad(moduleName);
- };
-
-}());
View
49 adapt/tests/all.js
@@ -1,49 +0,0 @@
-/**
- * @license RequireJS Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
- * Available via the MIT or new BSD license.
- * see: http://github.com/jrburke/requirejs for details
- */
-
-/**
- * BUILD r.js IN THIS DIRECTORY FIRST BEFORE RUNNING THIS FILE
- *
- * To run in Node:
- * node ../r.js all.js
- *
- * To run in Rhino:
- * java -jar ../../build/lib/rhino/js.jar ../r.js all.js
- * Debug:
- * java -classpath ../../build/lib/rhino/js.jar org.mozilla.javascript.tools.debugger.Main ../r.js all.js
- */
-
-/*jslint strict: false */
-/*global require: false, doh: false */
-
-//Special global flag used by DOH.
-skipDohSetup = true;
-
-require({
- paths: {
- env: '../../build/jslib/env'
- }
-}, [
- 'alpha',
- 'beta',
- '../../tests/doh/runner.js',
- 'env!../../tests/doh/_{env}Runner.js'
-], function (alpha, beta) {
-
- doh.register('rjsTests',
- [
- function rjsTests(t) {
- t.is('alpha', alpha.name);
- t.is('beta', beta.name);
- t.is('betaSubName', beta.subName);
- }
- ]
- );
- doh.run();
-
- //Print out the test summary.
- doh.run();
-});
View
3  adapt/tests/alpha.js
@@ -1,3 +0,0 @@
-define(function(require, exports) {
- exports.name = 'alpha';
-});
View
6 adapt/tests/beta.js
@@ -1,6 +0,0 @@
-define(['./sub/betaSub'], function (betaSub) {
- return {
- name: 'beta',
- subName: betaSub.name
- };
-});
View
37 adapt/tests/node/canvasTest.js
@@ -1,37 +0,0 @@
-//Tested with nave, node 0.2.5,
-//npm install canvas
-//npm install express
-
-/*jslint strict: false */
-/*global require: false, console: false */
-
-var Canvas = require('canvas'),
- express = require('express'),
- canvas = new Canvas(200, 200),
- ctx = canvas.getContext('2d'),
- app = express.createServer();
-
-
-app.configure(function () {
-
- app.get('/', function (req, res) {
- res.send('hello world');
- });
-
- app.use(express.gzip());
- app.listen(3000);
-});
-
-
-ctx.font = '30px Impact';
-ctx.rotate(0.1);
-ctx.fillText("Awesome!", 50, 100);
-
-var te = ctx.measureText('Awesome!');
-ctx.strokeStyle = 'rgba(0,0,0,0.5)';
-ctx.beginPath();
-ctx.lineTo(50, 102);
-ctx.lineTo(50 + te.width, 102);
-ctx.stroke();
-
-console.log('<img src="' + canvas.toDataURL() + '" />');
View
11 adapt/tests/node/index.js
@@ -1,11 +0,0 @@
-//The traditional nodejs http example
-
-require(['sys', 'http'], function (sys, http) {
- http.createServer(function (req, res) {
- setTimeout(function () {
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.end('Hello World\n');
- }, 2000);
- }).listen(8000);
- sys.puts('Server running at http://127.0.0.1:8000/');
-});
View
6 adapt/tests/node/tests/alpha/foo.js
@@ -1,6 +0,0 @@
-define(function (require) {
- var foo = require('../foo');
- return {
- name: 'ALPHA' + foo.name
- };
-});
View
9 adapt/tests/node/tests/alpha/hello.html
@@ -1,9 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>Hello World</title>
-</head>
-<body>
- <h1>Hello World</h1>
-</body>
-</html>
View
3  adapt/tests/node/tests/foo.js
@@ -1,3 +0,0 @@
-define({
- name: 'foo'
-});
View
11 adapt/tests/node/tests/server.js
@@ -1,11 +0,0 @@
-//The traditional nodejs http example
-
-require(['sys', 'foo', 'http', 'alpha/foo', 'text!alpha/hello.html'], function (sys, foo, http, alphaFoo, helloHtml) {
- http.createServer(function (req, res) {
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.write('Hello ' + foo.name + '\nHello ' + alphaFoo.name + '\n');
- res.write(helloHtml)
- res.end('\n');
- }).listen(8000);
- sys.puts('Server running at http://127.0.0.1:8000/');
-});
View
10 adapt/tests/relative.js
@@ -1,10 +0,0 @@
-/*
-Run this file from a directory that is not the directory containing this file
-to see if the baseUrl of this file is used instead of the current directory.
-*/
-
-require(['alpha', 'beta'], function (alpha, beta) {
- console.log('alpha === ' + alpha.name);
- console.log('beta === ' + beta.name);
- console.log('betaSubName === ' + beta.subName);
-});
View
3  adapt/tests/sub/betaSub.js
@@ -1,3 +0,0 @@
-define({
- name: 'betaSubName'
-});
View
6 bin/x
@@ -1,6 +0,0 @@
-#!/bin/sh
-
-# A command line tool to run some RequireJS scripts via Node
-
-MYDIR=`cd \`dirname "$0"\`; pwd`
-node $MYDIR/x.js $MYDIR "$@"
View
2  bin/x.bat
@@ -1,2 +0,0 @@
-set MYDIR=%~dp0
-node %MYDIR%x.js %MYDIR% %*
View
131 bin/x.js
@@ -1,131 +0,0 @@
-/**
- * @license Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
- * Available via the MIT or new BSD license.
- * see: http://github.com/jrburke/requirejs for details
- */
-
-/*
- * This is a bootstrap script to allow running RequireJS in the command line
- * in either a Java/Rhino or Node environment. It is best to call this script
- * via the x script that is a sibling to it.
- */
-
-/*jslint strict: false, evil: true */
-/*global readFile: true, process: false, Packages: false, require: true
- print: false, console: false */
-
-var require, define;
-(function (console, args, readFileFunc) {
-
- var fileName, env, fs, vm, exec, rhinoContext, dir,
- requireBuildPath = '',
- jsSuffixRegExp = /\.js$/,
- //This flag is turned to false by the distribution script,
- //because a requireBuildPath is not needed since the scripts
- //are inlined in this script.
- useRequireBuildPath = true,
- //This flag is turned to true if the distribution script built this
- //file as opto.js. Needed to update path args correctly in build.js
- isOpto = false,
- argOffset = useRequireBuildPath ? 0 : 1,
- readFile = typeof readFileFunc !== 'undefined' ? readFileFunc : null;
-
- if (typeof Packages !== 'undefined') {
- env = 'rhino';
-
- if (useRequireBuildPath) {
- requireBuildPath = args[0];
- }
- fileName = args[1 - argOffset];
-
- //Set up execution context.
- rhinoContext = Packages.org.mozilla.javascript.ContextFactory.getGlobal().enterContext();
-
- exec = function (string, name) {
- return rhinoContext.evaluateString(this, string, name, 0, null);
- };
-
- //Define a console.log for easier logging. Don't
- //get fancy though.
- if (typeof console === 'undefined') {
- console = {
- log: function () {
- print.apply(undefined, arguments);
- }
- };
- }
- } else if (typeof process !== 'undefined') {
- env = 'node';
-
- //Get the fs module via Node's require before it
- //gets replaced. Used in require/node.js
- fs = require('fs');
- vm = require('vm');
- this.nodeRequire = require;
- require = null;
-
- readFile = function (path) {
- return fs.readFileSync(path, 'utf8');
- };
-
- exec = function (string, name) {
- return vm.runInThisContext(string, name);
- };
-
- if (useRequireBuildPath) {
- requireBuildPath = process.argv[2];
- }
-
- fileName = process.argv[3 - argOffset];
- }
-
- //Make sure build path ends in a slash.
- requireBuildPath = requireBuildPath.replace(/\\/g, '/');
- if (requireBuildPath.charAt(requireBuildPath.length - 1) !== "/") {
- requireBuildPath += "/";
- }
-
- //Actual base directory is up one directory from this script.
- requireBuildPath += '../';
-
- exec(readFile(requireBuildPath + 'require.js'), 'require.js');
-
- //These are written out long-form so that they can be replaced by
- //the distribution script.
- if (env === 'rhino') {
- exec(readFile(requireBuildPath + 'adapt/rhino.js'), 'rhino.js');
- } else if (env === 'node') {
- require = this.require;
- define = this.define;
- exec(readFile(requireBuildPath + 'adapt/node.js'), 'node.js');
- }
-
- if (useRequireBuildPath) {
- exec("require({" +
- "baseUrl: '" + requireBuildPath + "build/jslib/'" +
- "})", 'bootstrap');
- }
-
- //Support a default file name to execute. Useful for hosted envs
- //like Joyent where it defaults to a server.js as the only executed
- //script.
- if (!fileName || !jsSuffixRegExp.test(fileName)) {
- fileName = 'main.js';
- }
-
- if (!useRequireBuildPath) {
- //Use the file name's directory as the baseUrl if available.
- dir = fileName.replace(/\\/g, '/');
- if (dir.indexOf('/') !== -1) {
- dir = dir.split('/');
- dir.pop();
- dir = dir.join('/');
- exec("require({baseUrl: '" + dir + "'});");
- }
- }
-
- exec(readFile(fileName), fileName);
-
-}((typeof console !== 'undefined' ? console : undefined),
- (typeof Packages !== 'undefined' ? arguments : []),
- (typeof readFile !== 'undefined' ? readFile : undefined)));
View
7 bin/xdebug
@@ -1,7 +0,0 @@
-#!/bin/sh
-
-# A command line tool to run some scripts used in the RequireJS project, in
-# debug mode.
-
-MYDIR=`cd \`dirname "$0"\`; pwd`
-node --debug-brk $MYDIR/x.js $MYDIR "$@"
View
2  bin/xdebug.bat
@@ -1,2 +0,0 @@
-set MYDIR=%~dp0
-node --debug-brk %MYDIR%x.js %MYDIR% %*
View
6 bin/xj
@@ -1,6 +0,0 @@
-#!/bin/sh
-
-# A command line tool to run some RequireJS scripts via Java/Rhino
-
-MYDIR=`cd \`dirname "$0"\`; pwd`
-java -classpath $MYDIR/../build/lib/rhino/js.jar:$MYDIR/../build/lib/closure/compiler.jar org.mozilla.javascript.tools.shell.Main $MYDIR/x.js $MYDIR "$@"
View
2  bin/xj.bat
@@ -1,2 +0,0 @@
-set MYDIR=%~dp0
-java -classpath %MYDIR%..\build\lib\rhino\js.jar;%MYDIR%..\build\lib\closure\compiler.jar org.mozilla.javascript.tools.shell.Main %MYDIR%x.js %MYDIR% %*
View
4 bin/xjdebug
@@ -1,4 +0,0 @@
-#!/bin/sh
-
-MYDIR=`cd \`dirname "$0"\`; pwd`
-java -classpath $MYDIR/../build/lib/rhino/js.jar:$MYDIR/../build/lib/closure/compiler.jar org.mozilla.javascript.tools.debugger.Main $MYDIR/x.js $MYDIR "$@"
View
2  bin/xjdebug.bat
@@ -1,2 +0,0 @@
-set MYDIR=%~dp0
-java -classpath %MYDIR%..\build\lib\rhino\js.jar;%MYDIR%..\build\lib\closure\compiler.jar org.mozilla.javascript.tools.debugger.Main %MYDIR%x.js %MYDIR% %*
View
2  build/build.bat
@@ -1,2 +0,0 @@
-set MYDIR=%~dp0
-%MYDIR%..\bin\x.bat %MYDIR%build.js %*
View
49 build/build.js
@@ -1,49 +0,0 @@
-/**
- * @license Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
- * Available via the MIT or new BSD license.
- * see: http://github.com/jrburke/requirejs for details
- */
-
-/*
- * Use the .sh or .bat build scripts to run this script. General use:
- * executingEnv build.js directory/containing/build.js/ profile.build.js
- *
- * General use:
- *
- * Create a build.js file that has the build options you want and pass that
- * build file to this file to do the build. See example.build.js for more information.
- */
-
-/*jslint strict: false */
-/*global require: false */
-
-require({
- baseUrl: require.s.contexts._.config.baseUrl,
- //Use a separate context than the default context so that the
- //build can use the default context.
- context: 'build'
-}, ['env!env/args', 'build'],
-function (args, build) {
- var buildArgs = args, rjsBuildDir;
-
- if (typeof isOpto !== 'undefined' && isOpto) {
- //Shift on a base path used to find optimizer modules. However,
- //since this case is for opto.js that has them built in, just
- //use some arbitrary path.
- buildArgs.unshift('.');
- } else {
- //This is call was done via opto.js,
- //so take off the first argument since it is for
- //are a path inside requirejs for use by the bootstrap.
- buildArgs = buildArgs.slice(1);
- rjsBuildDir = buildArgs[0].replace(/\\/g, '/');
-
- //The second arg is the full path for this script. The
- //directory portion is the only part needed though, so adjust it.
- rjsBuildDir = rjsBuildDir.split('/');
- rjsBuildDir.pop();
- buildArgs[0] = rjsBuildDir.length ? rjsBuildDir.join('/') : '.';
- }
-
- build(buildArgs);
-});
View
4 build/build.sh
@@ -1,4 +0,0 @@
-#!/bin/sh
-
-MYDIR=`cd \`dirname "$0"\`; pwd`
-$MYDIR/../bin/x $MYDIR/build.js "$@"
View
2  build/buildebug.bat
@@ -1,2 +0,0 @@
-set MYDIR=%~dp0
-%MYDIR%..\bin\xdebug.bat %MYDIR%build.js %*
View
4 build/buildebug.sh
@@ -1,4 +0,0 @@
-#!/bin/sh
-
-MYDIR=`cd \`dirname "$0"\`; pwd`
-$MYDIR/../bin/xdebug $MYDIR/build.js "$@"
View
4 build/buildebugj.sh
@@ -1,4 +0,0 @@
-#!/bin/sh
-
-MYDIR=`cd \`dirname "$0"\`; pwd`
-$MYDIR/../bin/xjdebug $MYDIR/build.js "$@"
View
2  build/buildj.bat
@@ -1,2 +0,0 @@
-set MYDIR=%~dp0
-%MYDIR%..\bin\xj.bat %MYDIR%build.js %*
View
4 build/buildj.sh
@@ -1,4 +0,0 @@
-#!/bin/sh
-
-MYDIR=`cd \`dirname "$0"\`; pwd`
-$MYDIR/../bin/xj $MYDIR/build.js "$@"
View
2  build/buildjdebug.bat
@@ -1,2 +0,0 @@
-set MYDIR=%~dp0
-%MYDIR%..\bin\xjdebug.bat %MYDIR%build.js %*
View
2  build/convert/commonjs/convert.bat
@@ -1,2 +0,0 @@
-set MYDIR=%~dp0
-java -classpath %MYDIR%/../lib/rhino/js.jar;%MYDIR%/../lib/closure/compiler.jar org.mozilla.javascript.tools.shell.Main %MYDIR%/convertCommonJs.js %MYDIR% %*
View
33 build/convert/commonjs/convert.js
@@ -1,33 +0,0 @@
-/**
- * Converts CommonJS modules to be requirejs compliant modules.
- *
- * Usage:
- * ../../../bin/x convert.js path/to/commonjs/modules output/dir
- *
- */
-/*jslint strict: false */
-/*global require: false */
-
-require(['env!env/args', 'commonJs', 'env!env/print'],
-function (args, commonJs, print) {
-
- var foundConvert = false,
- srcDir, outDir;
-
- //strip off arguments until there is no more convert.js.
- //Node and Rhino give different numbers of args.
- //Revisit this later as other code gets moved around.
- while(!foundConvert) {
- foundConvert = args.shift() === 'convert.js';
- }
-
- srcDir = args[0];
- outDir = args[1];
-
- if (!srcDir || !outDir) {
- print('Usage: convert.js path/to/commonjs/modules output/dir');
- return;
- }
-
- commonJs.convertDir(args[0], args[1]);
-});
View
4 build/convert/commonjs/convert.sh
@@ -1,4 +0,0 @@
-#!/bin/sh
-
-MYDIR=`cd \`dirname "$0"\`; pwd`
-java -classpath $MYDIR/../lib/rhino/js.jar:$MYDIR/../lib/closure/compiler.jar org.mozilla.javascript.tools.shell.Main $MYDIR/convert.js $MYDIR "$@"
View
214 build/convert/stealjs/parse.js
@@ -1,214 +0,0 @@
-/*jslint plusplus: false, strict: false */
-/*global define: false */
-
-/**
- * An override for the jslib/parse.js to convert stealjs calls into
- * require/define calls.
- */
-
-define(['../../jslib/parse'], function (baseParse) {
-
- var parse = baseParse,
- allowedCalls = {
- plugins: true,
- views: true
- },
- viewStringRegExp = /^\/\//;
-
- /**
- * Finds a steal node in a nested, backwards AST tree structure.
- */
- function getStealCall(node) {
- if (!baseParse.isArray(node)) {
- return false;
- }
-
- if (node[0] === 'name' && node[1] === 'steal' && !node.isRequireJSParsed) {
- return node;
- } else if (node[0] === 'call') {
- if (node[1][0] === 'name' && node[1][1] === 'steal') {
- return getStealCall(node[1]);
- } else if (node[1][0] === 'dot') {
- return getStealCall(node[1][1]);
- }
- }
-
- return null;
- }
-
- /**
- * Mark the steal node tree as processed. Need to do this given the
- * backwards structure of the AST.
- */
- function markStealTreeProcessed(node) {
- getStealCall(node).isRequireJSParsed = true;
- }
-
- /**
- * Transform a .views depdencency to an ejs! plugin loaded depdendency
- * @param {String} value the .views string name.
- * @returns {String} an 'ejs!' string
- */
- function viewTransform(value) {
- return 'ejs!' + value.replace(viewStringRegExp, '');
- }
-
- function addStringsToArray(node, array, transform) {
- var i, item, matches = [];
- for (i = 0; i < node.length; i++) {
- item = node[i];
- if (item && baseParse.isArray(item) && item[0] === 'string') {
- matches.push((transform ? transform(item[1]) : item[1]));
- }
- }
-
- if (matches.length) {
- //Build up arguments to splice, since we need to put these
- //matches before other matches, given the backwards nature of
- //the call traversal in the AST.
- matches.unshift(0);
- matches.unshift(0);
- array.splice.apply(array, matches);
- }
- }
-
- function generateRequireCall(node, array) {
- if (!baseParse.isArray(node)) {
- return;
- }
-
- var args, previous, call;
-
- if (node[0] === 'call' && node[1][0] === 'name' && node[1][1] === 'steal') {
- //A simple steal() call.
- addStringsToArray(node[2], array);
- } else {
- //A chained call
- //Need to unwind the call since the dot access shows up "backwards"
- //in the AST.
- args = node[node.length - 1];
- previous = node[node.length - 2];
- call = previous[previous.length - 1];
-
- if (typeof call === 'string' && allowedCalls[call]) {
- if (call === 'plugins') {
- addStringsToArray(args, array);
- } else if (call === 'views') {
- addStringsToArray(args, array, viewTransform);
- }
-
- //Find out if there are any other chained calls.
- previous = previous[previous.length - 2];
-
- generateRequireCall(previous, array);
- }
- }
- }
-
- parse.oldParseNode = parse.parseNode;
-
- parse.parseNode = function (node) {
- var value;
-
- if (!this.isArray(node)) {
- return null;
- }
-
- //Allow files with regular define/require calls to be co-mingled
- //with StealJS APIs.
- value = this.oldParseNode(node);
- if (value) {
- return value;
- }
-
- if (getStealCall(node)) {
- value = [];
- generateRequireCall(node, value);
- if (value.length) {
- markStealTreeProcessed(node);
- return "require(" + JSON.stringify(value) + ");";
- } else {
- return '';
- }
- }
-
- return null;
- };
-
-/*
- use console.log(JSON.stringify(node, null, ' ')) to print out AST
-
- Using this:
- steal.plugins('foo','bar').views('//abc/init.ejs').then(function(){})
-
- Has this for one of the nodes.
-
-[
- "call",
- [
- "dot",
- [
- "call",
- [
- "dot",
- [
- "name",
- "steal"
- ],
- "plugins"
- ],
- [
- [
- "string",
- "foo"
- ],
- [
- "string",
- "bar"
- ]
- ]
- ],
- "views"
- ],
- [
- [
- "string",
- "//abc/init.ejs"
- ]
- ]
-]
-
-**************************
-
-steal('one', 'two')
-
-[
- "toplevel",
- [
- [
- "stat",
- [
- "call",
- [
- "name",
- "steal"
- ],
- [
- [
- "string",
- "one"
- ],
- [
- "string",
- "two"
- ]
- ]
- ]
- ]
- ]
-]
-
-*/
-
- return parse;
-});
View
23 build/convert/stealjs/tests/all.js
@@ -1,23 +0,0 @@
-/**
- * Run the tests in Node:
- * ../../../../bin/x all-node.js
- */
-
-/*jslint plusplus: false, strict: false */
-/*global load: false, doh: false, skipDohSetup: true */
-
-//A hack to doh to avoid dojo setup stuff in doh/runner.js
-skipDohSetup = true;
-
-require({
- baseUrl: '../../../jslib/',
- paths: {
- parse: '../convert/stealjs/parse'
- }
-}, [
- '../../../../tests/doh/runner.js',
- 'env!../../../../tests/doh/_{env}Runner.js',
- './parse'
-], function () {
- doh.run();
-});
View
20 build/convert/stealjs/tests/parse.js
@@ -1,20 +0,0 @@
-/*jslint plusplus: false, strict: false */
-/*global load: false, doh: false, require:false */
-
-define(['require', 'parse'], function (require, parse) {
-
- doh.register(
- "parseStealCalls",
- [
- function parseStealCalls(t) {
- var good1 = "steal.plugins('foo','bar').views('//abc/init.ejs').then(function(){})",
- good2 = "steal('one', 'two')";
-
- t.is('require(["foo","bar","ejs!abc/init.ejs"]);', parse("good1", good1));
- t.is('require(["one","two"]);', parse("good2", good2));
- }
- ]
- );
- doh.run();
-
-});
View
183 build/example.build.js
@@ -1,183 +0,0 @@
-/*
- * This is an example build file that demonstrates how to use the build system for
- * require.js.
- *
- * THIS BUILD FILE WILL NOT WORK. It is referencing paths that probably
- * do not exist on your machine. Just use it as a guide.
- *
- *
- */
-
-({
- //The top level directory that contains your app. If this option is used
- //then it assumed your scripts are in a subdirectory under this path.
- //This option is not required. If it is not specified, then baseUrl
- //below is the anchor point for finding things. If this option is specified,
- //then all the files from the app directory will be copied to the dir:
- //output area, and baseUrl will assume to be a relative path under
- //this directory.
- appDir: "some/path/",
-
- //By default, all modules are located relative to this path. If baseUrl
- //is not explicitly set, then all modules are loaded relative to
- //the directory that holds the build file.
- baseUrl: "./",
-
- //Set paths for modules. If relative paths, set relative to baseUrl above.
- paths: {
- "foo.bar": "../scripts/foo/bar",
- "baz": "../another/path/baz"
- },
-
- //Configure CommonJS packages. See http://requirejs.org/docs/api.html#packages
- //for more information.
- packagePaths: [],
- packages: [],
-
- //The directory path to save the output. If not specified, then
- //the path will default to be a directory called "build" as a sibling
- //to the build file. All relative paths are relative to the build file.
- dir: "../some/path",
-
- //Used to inline i18n resources into the built file. If no locale
- //is specified, i18n resources will not be inlined. Only one locale
- //can be inlined for a build. Root bundles referenced by a build layer
- //will be included in a build layer regardless of locale being set.
- locale: "en-us",
-
- //How to optimize all the JS files in the build output directory.
- //Right now only the following values
- //are supported:
- //- "uglify": (default) uses UglifyJS to minify the code.
- //- "closure": uses Google's Closure Compiler in simple optimization
- //mode to minify the code. Only available if running the optimizer using
- //Java.
- //- "closure.keepLines": Same as closure option, but keeps line returns
- //in the minified files.
- //- "none": no minification will be done.
- optimize: "uglify",
-
- //If using UglifyJS for script optimization, these config options can be
- //used to pass configuration values to UglifyJS.
- //See https://github.com/mishoo/UglifyJS for the possible values.
- uglify: {
- gen_codeOptions: {},
- strict_semicolons: {},
- do_toplevel: {},
- ast_squeezeOptions: {}
- },
-
- //If using Closure Compiler for script optimization, these config options
- //can be used to configure Closure Compiler. See the documentation for
- //Closure compiler for more information.
- closure: {
- CompilerOptions: {},
- CompilationLevel: 'SIMPLE_OPTIMIZATIONS',
- loggingLevel: 'WARNING'
- }
-
- //Allow CSS optimizations. Allowed values:
- //- "standard": @import inlining, comment removal and line returns.
- //Removing line returns may have problems in IE, depending on the type
- //of CSS.
- //- "standard.keepLines": like "standard" but keeps line returns.
- //- "none": skip CSS optimizations.
- optimizeCss: "standard.keepLines",
-
- //If optimizeCss is in use, a list of of files to ignore for the @import
- //inlining. The value of this option should be a comma separated list
- //of CSS file names to ignore. The file names should match whatever
- //strings are used in the @import calls.
- cssImportIgnore: null,
-
- //Inlines the text for any text! dependencies, to avoid the separate
- //async XMLHttpRequest calls to load those dependencies.
- inlineText: true,
-
- //Allow "use strict"; be included in the RequireJS files.
- //Default is false because there are not many browsers that can properly
- //process and give errors on code for ES5 strict mode,
- //and there is a lot of legacy code that will not work in strict mode.
- useStrict: false,
-
- //Specify build pragmas. If the source files contain comments like so:
- //>>excludeStart("fooExclude", pragmas.fooExclude);
- //>>excludeEnd("fooExclude");
- //Then the comments that start with //>> are the build pragmas.
- //excludeStart/excludeEnd and includeStart/includeEnd work, and the
- //the pragmas value to the includeStart or excludeStart lines
- //is evaluated to see if the code between the Start and End pragma
- //lines should be included or excluded.
- pragmas: {
- fooExclude: true
- },
-
- //Skip processing for pragmas.
- skipPragmas: false,
-
- //If skipModuleInsertion is false, then files that do not use require.def
- //to define modules will get a require.def() placeholder inserted for them.
- //Also, require.pause/resume calls will be inserted.
- //Set it to true to avoid this. This is useful if you are building code that
- //does not use require() in the built project or in the JS files, but you
- //still want to use the optimization tool from RequireJS to concatenate modules
- //together.
- skipModuleInsertion: false,
-
- //List the modules that will be optimized. All their immediate and deep
- //dependencies will be included in the module's file when the build is
- //done. If that module or any of its dependencies includes i18n bundles,
- //only the root bundles will be included unless the locale: section is set above.
- modules: [
- //Just specifying a module name means that module will be converted into
- //a built file that contains all of its dependencies. If that module or any
- //of its dependencies includes i18n bundles, they may not be included in the
- //built file unless the locale: section is set above.
- {
- name: "foo/bar/bop",
-
- //For build profiles that contain more than one modules entry,
- //allow overrides for the properties that set for the whole build,
- //for example a different set of pragmas for this module.
- //The override's value is an object that can
- //contain any of the other build options in this file.
- override: {
- pragmas: {
- fooExclude: true
- }
- }
- },
-
- //This module entry combines all the dependencies of foo/bar/bop and foo/bar/bee
- //and any of their dependencies into one file.
- {
- name: "foo/bar/bop",
- include: ["foo/bar/bee"]
- },
-
- //This module entry combines all the dependencies of foo/bar/bip into one file,
- //but excludes foo/bar/bop and its dependencies from the built file. If you want
- //to exclude a module that is also another module being optimized, it is more
- //efficient if you define that module optimization entry before using it
- //in an exclude array.
- {
- name: "foo/bar/bip",
- exclude: [
- "foo/bar/bop"
- ]
- },
-
- //This module entry shows how to specify a specific module be excluded
- //from the built module file. excludeShallow means just exclude that
- //specific module, but if that module has nested dependencies that are
- //part of the built file, keep them in there. This is useful during
- //development when you want to have a fast bundled set of modules, but
- //just develop/debug one or two modules at a time.
- {
- name: "foo/bar/bin",
- excludeShallow: [
- "foo/bar/bot"
- ]
- }
- ]
-})
View
4 build/jslib/blank.js
@@ -1,4 +0,0 @@
-//Just a blank file to use when building the optimizer with the optimizer,
-//so that the build does not attempt to inline some env modules,
-//like Node's fs and path.
-
View
725 build/jslib/build.js
@@ -1,725 +0,0 @@
-/**
- * @license Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
- * Available via the MIT or new BSD license.
- * see: http://github.com/jrburke/requirejs for details
- */
-
-/*jslint regexp: false, plusplus: false, nomen: false, strict: false */
-/*global define: false, require: false */
-
-
-define([ 'lang', 'logger', 'env!env/file', 'parse', 'optimize', 'pragma',
- 'env!env/load', 'requirePatch'],
-function (lang, logger, file, parse, optimize, pragma,
- load, requirePatch) {
- var build, buildBaseConfig;
-
- buildBaseConfig = {
- requireBuildPath: "../",
- appDir: "",
- pragmas: {},
- paths: {},
- optimize: "uglify",
- optimizeCss: "standard.keepLines",
- inlineText: true,
- isBuild: true
- };
-
- function endsWithSlash(dirName) {
- if (dirName.charAt(dirName.length - 1) !== "/") {
- dirName += "/";
- }
- return dirName;
- }
-
-
- /**
- * Main API entry point into the build. The args argument can either be
- * an array of arguments (like the onese passed on a command-line),
- * or it can be a JavaScript object that has the format of a build profile
- * file.
- *
- * If it is an object, then in addition to the normal properties allowed in
- * a build profile file, the object should contain one other property:
- *
- * requireBuildPath: a string that is the path to find require.js and the
- * require/ directory. This should be a pristine require.js with only
- * require.js contents (no plugins or jQuery).
- *
- * The object could also contain a "buildFile" property, which is a string
- * that is the file path to a build profile that contains the rest
- * of the build profile directives.
- *
- * This function does not return a status, it should throw an error if
- * there is a problem completing the build.
- */
- build = function (args) {
- var requireBuildPath, buildFile, cmdConfig;
-
- if (!args || lang.isArray(args)) {
- if (!args || args.length < 2) {
- logger.error("build.js directory/containing/build.js/ buildProfile.js\n" +
- "where buildProfile.js is the name of the build file (see example.build.js for hints on how to make a build file).");
- return;
- }
-
- //Second argument should be the directory on where to find this script.
- //This path should end in a slash.
- requireBuildPath = args[0];
- requireBuildPath = endsWithSlash(requireBuildPath);
-
- //Next args can include a build file path as well as other build args.
- //build file path comes first. If it does not contain an = then it is
- //a build file path. Otherwise, just all build args.
- if (args[1].indexOf("=") === -1) {
- buildFile = args[1];
- args.splice(0, 2);
- } else {
- args.splice(0, 1);
- }
-
- //Remaining args are options to the build
- cmdConfig = build.convertArrayToObject(args);
- cmdConfig.buildFile = buildFile;
- cmdConfig.requireBuildPath = requireBuildPath;
- } else {
- cmdConfig = args;
- }
-
- build._run(cmdConfig);
- };
-
- build._run = function (cmdConfig) {
- var buildFileContents = "",
- buildPaths, fileName, fileNames,
- prop, paths, i,
- baseConfig, config,
- modules, builtModule, srcPath, buildContext,
- destPath;
-
- //Can now run the patches to require.js to allow it to be used for
- //build generation. Do it here instead of at the top of the module
- //because we want normal require behavior to load the build tool
- //then want to switch to build mode.
- requirePatch();
-
- config = build.createConfig(cmdConfig);
- paths = config.paths;
-
- if (!config.out && !config.cssIn) {
- //This is not just a one-off file build but a full build profile, with
- //lots of files to process.
-
- //First copy all the baseUrl content
- file.copyDir((config.appDir || config.baseUrl), config.dir, /\w/, true);
-
- //Adjust baseUrl if config.appDir is in play, and set up build output paths.
- buildPaths = {};
- if (config.appDir) {
- //All the paths should be inside the appDir
- buildPaths = paths;
- } else {
- //If no appDir, then make sure to copy the other paths to this directory.
- for (prop in paths) {
- if (paths.hasOwnProperty(prop)) {
- //Set up build path for each path prefix.
- buildPaths[prop] = prop.replace(/\./g, "/");
-
- //Make sure source path is fully formed with baseUrl,
- //if it is a relative URL.
- srcPath = paths[prop];
- if (srcPath.indexOf('/') !== 0 && srcPath.indexOf(':') === -1) {
- srcPath = config.baseUrl + srcPath;
- }
-
- destPath = config.dirBaseUrl + buildPaths[prop];
-
- //If the srcPath is a directory, copy the whole directory.
- if (file.exists(srcPath) && file.isDirectory(srcPath)) {
- //Copy files to build area. Copy all files (the /\w/ regexp)
- file.copyDir(srcPath, destPath, /\w/, true);
- } else {
- //Try a .js extension
- srcPath += '.js';
- destPath += '.js';
- file.copyFile(srcPath, destPath);
- }
- }
- }
- }
- }
-
- //Figure out source file location for each module layer. Do this by seeding require
- //with source area configuration. This is needed so that later the module layers
- //can be manually copied over to the source area, since the build may be
- //require multiple times and the above copyDir call only copies newer files.
- require({
- baseUrl: config.baseUrl,
- paths: paths,
- packagePaths: config.packagePaths,
- packages: config.packages
- });
- buildContext = require.s.contexts._;
- modules = config.modules;
-
- if (modules) {
- modules.forEach(function (module) {
- if (module.name) {
- module._sourcePath = buildContext.nameToUrl(module.name);
- //If the module does not exist, and this is not a "new" module layer,
- //as indicated by a true "create" property on the module, and
- //it is not a plugin-loaded resource, then throw an error.
- if (!file.exists(module._sourcePath) && !module.create &&
- module.name.indexOf('!') === -1) {
- throw new Error("ERROR: module path does not exist: " +
- module._sourcePath + " for module named: " + module.name +
- ". Path is relative to: " + file.absPath('.'));
- }
- }
- });
- }
-
- if (config.out) {
- //Just set up the _buildPath for the module layer.
- require(config);
- if (!config.cssIn) {
- config.modules[0]._buildPath = config.out;
- }
- } else if (!config.cssIn) {
- //Now set up the config for require to use the build area, and calculate the
- //build file locations. Pass along any config info too.
- baseConfig = {
- baseUrl: config.dirBaseUrl,
- paths: buildPaths
- };
-
- lang.mixin(baseConfig, config);
- require(baseConfig);
-
- if (modules) {
- modules.forEach(function (module) {
- if (module.name) {
- module._buildPath = buildContext.nameToUrl(module.name, null);
- if (!module.create) {
- file.copyFile(module._sourcePath, module._buildPath);
- }
- }
- });
- }
- }
-
- if (modules) {
- //For each module layer, call require to calculate dependencies.
- modules.forEach(function (module) {
- module.layer = build.traceDependencies(module, config);
- });
-
- //Now build up shadow layers for anything that should be excluded.
- //Do this after tracing dependencies for each module, in case one
- //of those modules end up being one of the excluded values.
- modules.forEach(function (module) {
- if (module.exclude) {
- module.excludeLayers = [];
- module.exclude.forEach(function (exclude, i) {
- //See if it is already in the list of modules.
- //If not trace dependencies for it.
- module.excludeLayers[i] = build.findBuildModule(exclude, modules) ||
- {layer: build.traceDependencies({name: exclude}, config)};
- });
- }
- });
-
- modules.forEach(function (module) {
- if (module.exclude) {
- //module.exclude is an array of module names. For each one,
- //get the nested dependencies for it via a matching entry
- //in the module.excludeLayers array.
- module.exclude.forEach(function (excludeModule, i) {
- var excludeLayer = module.excludeLayers[i].layer, map = excludeLayer.buildPathMap, prop;
- for (prop in map) {
- if (map.hasOwnProperty(prop)) {
- build.removeModulePath(prop, map[prop], module.layer);
- }
- }
- });
- }
- if (module.excludeShallow) {
- //module.excludeShallow is an array of module names.
- //shallow exclusions are just that module itself, and not
- //its nested dependencies.
- module.excludeShallow.forEach(function (excludeShallowModule) {
- var path = module.layer.buildPathMap[excludeShallowModule];
- if (path) {
- build.removeModulePath(excludeShallowModule, path, module.layer);
- }
- });
- }
-
- //Flatten them and collect the build output for each module.
- builtModule = build.flattenModule(module, module.layer, config);
- file.saveUtf8File(module._buildPath, builtModule.text);
- buildFileContents += builtModule.buildText;
- });
- }
-
- //Do other optimizations.
- if (config.out && !config.cssIn) {
- //Just need to worry about one JS file.
- fileName = config.modules[0]._buildPath;
- optimize.jsFile(fileName, fileName, config);
- } else if (!config.cssIn) {
- //Normal optimizations across modules.
-
- //JS optimizations.
- fileNames = file.getFilteredFileList(config.dir, /\.js$/, true);
- for (i = 0; (fileName = fileNames[i]); i++) {
- optimize.jsFile(fileName, fileName, config);
- }
-
- //CSS optimizations
- if (config.optimizeCss && config.optimizeCss !== "none") {
- optimize.css(config.dir, config);
- }
-
- //All module layers are done, write out the build.txt file.
- file.saveUtf8File(config.dir + "build.txt", buildFileContents);
- }
-
- //If just have one CSS file to optimize, do that here.
- if (config.cssIn) {
- optimize.cssFile(config.cssIn, config.out, config);
- }
-
- //Print out what was built into which layers.
- if (buildFileContents) {
- logger.info(buildFileContents);
- }
- };
-
- /**
- * Converts an array that has String members of "name=value"
- * into an object, where the properties on the object are the names in the array.
- * Also converts the strings "true" and "false" to booleans for the values.
- * member name/value pairs, and converts some comma-separated lists into
- * arrays.
- * @param {Array} ary
- */
- build.convertArrayToObject = function (ary) {
- var result = {}, i, separatorIndex, prop, value,
- needArray = {
- "include": true,
- "exclude": true,
- "excludeShallow": true
- };
-
- for (i = 0; i < ary.length; i++) {
- separatorIndex = ary[i].indexOf("=");
- if (separatorIndex === -1) {
- throw "Malformed name/value pair: [" + ary[i] + "]. Format should be name=value";
- }
-
- value = ary[i].substring(separatorIndex + 1, ary[i].length);
- if (value === "true") {
- value = true;
- } else if (value === "false") {
- value = false;
- }
-
- prop = ary[i].substring(0, separatorIndex);
-
- //Convert to array if necessary
- if (needArray[prop]) {
- value = value.split(",");
- }
-
- if (prop.indexOf("paths.") === 0) {
- //Special handling of paths properties. paths.foo=bar is transformed
- //to data.paths = {foo: 'bar'}
- if (!result.paths) {
- result.paths = {};
- }
- prop = prop.substring("paths.".length, prop.length);
- result.paths[prop] = value;
- } else {
- result[prop] = value;
- }
- }
- return result; //Object
- };
-
- build.makeAbsPath = function (path, absFilePath) {
- //Add abspath if necessary. If path starts with a slash or has a colon,
- //then already is an abolute path.
- if (path.indexOf('/') !== 0 && path.indexOf(':') === -1) {
- path = absFilePath +
- (absFilePath.charAt(absFilePath.length - 1) === '/' ? '' : '/') +
- path;
- path = file.normalize(path);
- }
- return path;
- };
-
- /**
- * Creates a config object for an optimization build.
- * It will also read the build profile if it is available, to create
- * the configuration.
- *
- * @param {Object} cfg config options that take priority
- * over defaults and ones in the build file. These options could
- * be from a command line, for instance.
- *
- * @param {Object} the created config object.
- */
- build.createConfig = function (cfg) {
- /*jslint evil: true */
- var config = {}, buildFileContents, buildFileConfig,
- paths, props, i, prop, buildFile, absFilePath, originalBaseUrl;
-
- lang.mixin(config, buildBaseConfig);
- lang.mixin(config, cfg, true);
-
- //Normalize build directory location, and set up path to require.js
- if (config.requireBuildPath.charAt(config.requireBuildPath.length - 1) !== "/") {
- config.requireBuildPath += "/";
- //Also adjust the override config params, since it
- //may be re-applied later after reading the build file.
- if (cfg.requireBuildPath) {
- cfg.requireBuildPath = config.requireBuildPath;
- }
- }
-
- if (config.buildFile) {
- //A build file exists, load it to get more config.
- buildFile = file.absPath(config.buildFile);
-
- //Find the build file, and make sure it exists, if this is a build
- //that has a build profile, and not just command line args with an in=path
- if (!file.exists(buildFile)) {
- throw new Error("ERROR: build file does not exist: " + buildFile);
- }
-
- absFilePath = config.baseUrl = file.absPath(file.parent(buildFile));
- config.dir = config.baseUrl + "/build/";
-
- //Load build file options.
- buildFileContents = file.readFile(buildFile);
- try {
- buildFileConfig = eval("(" + buildFileContents + ")");
- } catch(e) {
- throw new Error("Build file " + buildFile + " is malformed: " + e);
- }
- lang.mixin(config, buildFileConfig, true);
-
- //Re-apply the override config values, things like command line
- //args should take precedence over build file values.
- lang.mixin(config, cfg, true);
- } else {
- if (!config.out && !config.cssIn) {
- throw new Error("ERROR: 'out' or 'cssIn' option missing.");
- }
- if (!config.out) {
- throw new Error("ERROR: 'out' option missing.");
- } else {
- config.out = config.out.replace(lang.backSlashRegExp, "/");
- }
-
- if (!config.cssIn && !cfg.baseUrl) {
- throw new Error("ERROR: 'baseUrl' option missing.");
- }
-
- //In this scenario, the absFile path is current directory
- absFilePath = file.absPath('.');
- }
-
- if (config.out && !config.cssIn) {
- //Just one file to optimize.
-
- //Set up dummy module layer to build.
- config.modules = [
- {
- name: config.name,
- out: config.out,
- include: config.include,
- exclude: config.exclude,
- excludeShallow: config.excludeShallow
- }
- ];
-
- //Does not have a build file, so set up some defaults.
- //Optimizing CSS should not be allowed, unless explicitly
- //asked for on command line. In that case the only task is
- //to optimize a CSS file.
- if (!cfg.optimizeCss) {
- config.optimizeCss = "none";
- }
- }
-
- //Adjust the path properties as appropriate.
- //First make sure build paths use front slashes and end in a slash,
- //and make sure they are aboslute paths.
- props = ["appDir", "dir", "baseUrl"];
- for (i = 0; (prop = props[i]); i++) {
- if (config[prop]) {
- config[prop] = config[prop].replace(lang.backSlashRegExp, "/");
-
- //Add abspath if necessary.
- if (prop === "baseUrl") {
- originalBaseUrl = config.baseUrl;
- if (config.appDir) {
- //If baseUrl with an appDir, the baseUrl is relative to
- //the appDir, *not* the absFilePath. appDir and dir are
- //made absolute before baseUrl, so this will work.
- config.baseUrl = build.makeAbsPath(originalBaseUrl, config.appDir);
- //Set up dir output baseUrl.
- config.dirBaseUrl = build.makeAbsPath(originalBaseUrl, config.dir);
- } else {
- //The dir output baseUrl is same as regular baseUrl, both
- //relative to the absFilePath.
- config.baseUrl = build.makeAbsPath(config[prop], absFilePath);
- config.dirBaseUrl = config.dir || config.baseUrl;
- }
-
- //Make sure dirBaseUrl ends in a slash, since it is
- //concatenated with other strings.
- config.dirBaseUrl = endsWithSlash(config.dirBaseUrl);
- } else {
- config[prop] = build.makeAbsPath(config[prop], absFilePath);
- }
-
- config[prop] = endsWithSlash(config[prop]);
- }
- }
-
- //Make sure some other paths are absolute.
- props = ["out", "cssIn"];
- for (i = 0; (prop = props[i]); i++) {
- if (config[prop]) {
- config[prop] = build.makeAbsPath(config[prop], absFilePath);
- }
- }
-
- return config;
- };
-
- /**
- * finds the module being built/optimized with the given moduleName,
- * or returns null.
- * @param {String} moduleName
- * @param {Array} modules
- * @returns {Object} the module object from the build profile, or null.
- */
- build.findBuildModule = function (moduleName, modules) {
- var i, module;
- for (i = 0; (module = modules[i]); i++) {
- if (module.name === moduleName) {
- return module;
- }
- }
- return null;
- };
-
- /**
- * Removes a module name and path from a layer, if it is supposed to be
- * excluded from the layer.
- * @param {String} moduleName the name of the module
- * @param {String} path the file path for the module
- * @param {Object} layer the layer to remove the module/path from
- */
- build.removeModulePath = function (module, path, layer) {
- var index = layer.buildFilePaths.indexOf(path);
- if (index !== -1) {
- layer.buildFilePaths.splice(index, 1);
- }
-
- //Take it out of the specified modules. Specified modules are mostly
- //used to find require modifiers.
- delete layer.specified[module];
- };
-
- /**
- * Uses the module build config object to trace the dependencies for the
- * given module.
- *
- * @param {Object} module the module object from the build config info.
- * @param {Object} the build config object.
- *
- * @returns {Object} layer information about what paths and modules should
- * be in the flattened module.
- */
- build.traceDependencies = function (module, config) {
- var include, override, layer, context, baseConfig, oldContext;
-
- //Reset some state set up in requirePatch.js, and clean up require's
- //current context.
- oldContext = require._buildReset();
-
- //Grab the reset layer and context after the reset, but keep the
- //old config to reuse in the new context.
- baseConfig = oldContext.config;
- layer = require._layer;
- context = layer.context;
-
- //Put back basic config, use a fresh object for it.
- //WARNING: probably not robust for paths and packages/packagePaths,
- //since those property's objects can be modified. But for basic
- //config clone it works out.
- require(lang.delegate(baseConfig));
-
- logger.trace("\nTracing dependencies for: " + (module.name || module.out));
- include = module.name && !module.create ? [module.name] : [];
- if (module.include) {
- include = include.concat(module.include);
- }
-
- //If there are overrides to basic config, set that up now.;
- if (module.override) {
- override = lang.delegate(baseConfig);
- lang.mixin(override, module.override, true);
- require(override);
- }
-
- //Figure out module layer dependencies by calling require to do the work.
- require(include);
-
- //Pull out the layer dependencies.
- layer.specified = context.specified;
-
- //Reset config
- if (module.override) {
- require(baseConfig);
- }
-
- return layer;
- };
-
- /**
- * Uses the module build config object to create an flattened version
- * of the module, with deep dependencies included.
- *
- * @param {Object} module the module object from the build config info.
- *
- * @param {Object} layer the layer object returned from build.traceDependencies.
- *
- * @param {Object} the build config object.
- *
- * @returns {Object} with two properties: "text", the text of the flattened
- * module, and "buildText", a string of text representing which files were
- * included in the flattened module text.
- */
- build.flattenModule = function (module, layer, config) {
- var buildFileContents = "",
- context = layer.context,
- path, reqIndex, fileContents, currContents,
- i, moduleName,
- parts, builder, writeApi;
-
- //Use override settings, particularly for pragmas
- if (module.override) {
- config = lang.delegate(config);
- lang.mixin(config, module.override, true);
- }
-
- //Start build output for the module.
- buildFileContents += "\n" +
- (config.dir ? module._buildPath.replace(config.dir, "") : module._buildPath) +
- "\n----------------\n";
-
- //If there was an existing file with require in it, hoist to the top.
- if (layer.existingRequireUrl) {
- reqIndex = layer.buildFilePaths.indexOf(layer.existingRequireUrl);
- if (reqIndex !== -1) {
- layer.buildFilePaths.splice(reqIndex, 1);
- layer.buildFilePaths.unshift(layer.existingRequireUrl);
- }
- }
-
- //Write the built module to disk, and build up the build output.
- fileContents = "";
- for (i = 0; (path = layer.buildFilePaths[i]); i++) {
- moduleName = layer.buildFileToModule[path];
-
- //Figure out if the module is a result of a build plugin, and if so,
- //then delegate to that plugin.
- parts = context.makeModuleMap(moduleName);
- builder = parts.prefix && context.pluginBuilders[parts.prefix];
- if (builder) {
- if (builder.write) {
- writeApi = function (input) {
- fileContents += input;
- };
- writeApi.asModule = function (moduleName, input) {
- fileContents += build.toTransport(moduleName, path, input, layer);
- };
- builder.write(parts.prefix, parts.name, writeApi);
- }
- } else {
- //Add the contents but remove any pragmas.
- currContents = pragma.process(path, file.readFile(path), config);
-
- currContents = build.toTransport(moduleName, path, currContents, layer);
-
- fileContents += currContents;
- }
-
- buildFileContents += path.replace(config.dir, "") + "\n";
- //Some files may not have declared a require module, and if so,
- //put in a placeholder call so the require does not try to load them
- //after the module is processed.
- //If we have a name, but no defined module, then add in the placeholder.
- if (moduleName && !layer.modulesWithNames[moduleName] && !config.skipModuleInsertion) {
- //If including jquery, register the module correctly, otherwise
- //register an empty function. For jquery, make sure jQuery is
- //a real object, and perhaps not some other file mapping, like
- //to zepto.
- if (moduleName === 'jquery') {
- fileContents += '\n(function () {\n' +
- 'var jq = typeof jQuery !== "undefined" && jQuery;\n' +
- 'define("jquery", [], function () { return jq; });\n' +
- '}());\n';
- } else {
- fileContents += 'define("' + moduleName + '", function(){});\n';
- }
- }
- }
-
- return {
- text: fileContents,
- buildText: buildFileContents
- };
- };
-
- //This regexp is not bullet-proof, and it has one optional part to
- //avoid issues with some Dojo transition modules that use a
- //define(\n//begin v1.x content
- //for a comment.
- build.anonDefRegExp = /(require\s*\.\s*def|define)\s*\(\s*(\/\/[^\n\r]*[\r\n])?(\[|f|\{)/;
-
- build.toTransport = function (moduleName, path, contents, layer) {
- //If anonymous module, insert the module name.
- return contents.replace(build.anonDefRegExp, function (match, callName, possibleComment, suffix) {
- layer.modulesWithNames[moduleName] = true;
-
- //Look for CommonJS require calls inside the function if this is
- //an anonymous define/require.def call that just has a function registered.
- var deps = null;
- if (suffix.indexOf('f') !== -1) {
- deps = parse.getAnonDeps(path, contents);
-
- if (deps.length) {
- deps = deps.map(function (dep) {
- return "'" + dep + "'";
- });
- } else {
- deps = [];
- }
- }
-
- return "define('" + moduleName + "'," +
- (deps ? ('[' + deps.toString() + '],') : '') +
- suffix;
- });
-
- };
-
- return build;
-});
View
23 build/jslib/commandLine.js
@@ -1,23 +0,0 @@
-/**
- * @license RequireJS Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
- * Available via the MIT or new BSD license.
- * see: http://github.com/jrburke/requirejs for details
- */
-
-/*jslint strict: false */
-/*global Packages: false */
-
-var commandLine = {};
-(function () {
- var runtime = Packages.java.lang.Runtime.getRuntime();
-
- /**
- * Executes a command on the command line. May not work right in
- * Windows environments, except maybe via something like cygwin.
- * @param {String} command the command to run on the command line.
- */
- commandLine.exec = function (command) {
- var process = runtime.exec(["/bin/sh", "-c", command]);
- process.waitFor();
- };
-}());
View
152 build/jslib/commonJs.js
@@ -1,152 +0,0 @@
-/**
- * @license RequireJS Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
- * Available via the MIT or new BSD license.
- * see: http://github.com/jrburke/requirejs for details
- */
-
-/*jslint plusplus: false, regexp: false, strict: false */
-/*global define: false, console: false */
-
-define(['env!env/file', 'uglifyjs/index'], function (file, uglify) {
- var commonJs = {
- depRegExp: /require\s*\(\s*["']([\w-_\.\/]+)["']\s*\)/g,
-
- //Set this to false in non-rhino environments. If rhino, then it uses
- //rhino's decompiler to remove comments before looking for require() calls,
- //otherwise, it will use a crude regexp approach to remove comments. The
- //rhino way is more robust, but he regexp is more portable across environments.
- useRhino: true,
-
- //Set to false if you do not want this file to log. Useful in environments
- //like node where you want the work to happen without noise.
- useLog: true,
-
- convertDir: function (commonJsPath, savePath) {
- var fileList, i,
- jsFileRegExp = /\.js$/,
- fileName, convertedFileName, fileContents;
-
- //Get list of files to convert.
- fileList = file.getFilteredFileList(commonJsPath, /\w/, true);
-
- //Normalize on front slashes and make sure the paths do not end in a slash.
- commonJsPath = commonJsPath.replace(/\\/g, "/");
- savePath = savePath.replace(/\\/g, "/");
- if (commonJsPath.charAt(commonJsPath.length - 1) === "/") {
- commonJsPath = commonJsPath.substring(0, commonJsPath.length - 1);
- }
- if (savePath.charAt(savePath.length - 1) === "/") {
- savePath = savePath.substring(0, savePath.length - 1);
- }
-
- //Cycle through all the JS files and convert them.
- if (!fileList || !fileList.length) {
- if (commonJs.useLog) {
- if (commonJsPath === "convert") {
- //A request just to convert one file.
- console.log('\n\n' + commonJs.convert(savePath, file.readFile(savePath)));
- } else {
- console.log("No files to convert in directory: " + commonJsPath);
- }
- }
- } else {
- for (i = 0; (fileName = fileList[i]); i++) {
- convertedFileName = fileName.replace(commonJsPath, savePath);
-
- //Handle JS files.
- if (jsFileRegExp.test(fileName)) {
- fileContents = file.readFile(fileName);
- fileContents = commonJs.convert(fileName, fileContents);
- file.saveUtf8File(convertedFileName, fileContents);
- } else {
- //Just copy the file over.
- file.copyFile(fileName, convertedFileName, true);
- }
- }
- }
- },
-
- /**
- * Removes the comments from a string.
- *
- * @param {String} fileContents
- * @param {String} fileName mostly used for informative reasons if an error.
- *
- * @returns {String} a string of JS with comments removed.
- */
- removeComments: function (fileContents, fileName) {
- //Uglify's ast generation removes comments, so just convert to ast,
- //then back to source code to get rid of comments.
- return uglify.uglify.gen_code(uglify.parser.parse(fileContents), true);
- },
-
- /**
- * Regexp for testing if there is already a require.def call in the file,
- * in which case do not try to convert it.
- */
- defRegExp: /(require\s*\.\s*def|define)\s*\(/,
-
- /**
- * Regexp for testing if there is a require([]) or require(function(){})
- * call, indicating the file is already in requirejs syntax.
- */
- rjsRegExp: /require\s*\(\s*(\[|function)/,
-
- /**
- * Does the actual file conversion.
- *
- * @param {String} fileName the name of the file.
- *
- * @param {String} fileContents the contents of a file :)
- *
- * @param {Boolean} skipDeps if true, require("") dependencies
- * will not be searched, but the contents will just be wrapped in the
- * standard require, exports, module dependencies. Only usable in sync
- * environments like Node where the require("") calls can be resolved on
- * the fly.
- *
- * @returns {String} the converted contents
- */
- convert: function (fileName, fileContents, skipDeps) {
- //Strip out comments.
- try {
- var deps = [], depName, match,
- //Remove comments
- tempContents = commonJs.removeComments(fileContents, fileName);
-
- //First see if the module is not already RequireJS-formatted.
- if (commonJs.defRegExp.test(tempContents) || commonJs.rjsRegExp.test(tempContents)) {
- return fileContents;
- }
-
- //Reset the regexp to start at beginning of file. Do this
- //since the regexp is reused across files.
- commonJs.depRegExp.lastIndex = 0;
-
- if (!skipDeps) {
- //Find dependencies in the code that was not in comments.
- while ((match = commonJs.depRegExp.exec(tempContents))) {
- depName = match[1];
- if (depName) {
- deps.push('"' + depName + '"');
- }
- }
- }
-
- //Construct the wrapper boilerplate.
- fileContents = 'define(["require", "exports", "module"' +
- (deps.length ? ', ' + deps.join(",") : '') + '], ' +
- 'function(require, exports, module) {\n' +
- fileContents +
- '\n});\n';
- } catch (e) {
- console.log("COULD NOT CONVERT: " + fileName + ", so skipping it. Error was: " + e);
- return fileContents;
- }
-
- return fileContents;
- }
- };
-
- return commonJs;
-});
View
47 build/jslib/env.js
@@ -1,47 +0,0 @@
-/**
- * @license Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
- * Available via the MIT or new BSD license.
- * see: http://github.com/jrburke/requirejs for details
- */
-
-/*jslint strict: false */
-/*global Packages: false, process: false, window: false, navigator: false,
- document: false, define: false */
-
-/**
- * A plugin that modifies any /env/ path to be the right path based on
- * the host environment. Right now only works for Node, Rhino and browser.
- */
-(function () {
- var pathRegExp = /(\/|^)env\/|\{env\}/,
- env = 'unknown';
-
- if (typeof Packages !== 'undefined') {
- env = 'rhino';
- } else if (typeof process !== 'undefined') {
- env = 'node';
- } else if (typeof window !== "undefined" && navigator && document) {
- env = 'browser';
- }
-
- define({
- load: function (name, req, load, config) {
- //Allow override in the config.
- if (config.env) {
- env = config.env;
- }
-
- name = name.replace(pathRegExp, function (match, prefix) {
- if (match.indexOf('{') === -1) {
- return prefix + env + '/';
- } else {
- return env;
- }
- });
-
- req([name], function (mod) {
- load(mod);
- });
- }
- });
-}());
View
49 build/jslib/lang.js
@@ -1,49 +0,0 @@
-/**
- * @license Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
- * Available via the MIT or new BSD license.
- * see: http://github.com/jrburke/requirejs for details
- */
-
-/*jslint plusplus: false, strict: false */
-/*global define: false */
-
-define(function () {
- var lang = {
- backSlashRegExp: /\\/g,
- ostring: Object.prototype.toString,
-
- isArray: Array.isArray ? Array.isArray : function (it) {
- return lang.ostring.call(it) === "[object Array]";
- },
-
- /**
- * Simple function to mix in properties from source into target,
- * but only if target does not already have a property of the same name.
- */
- mixin: function (target, source, override) {
- //Use an empty object to avoid other bad JS code that modifies
- //Object.prototype.
- var empty = {}, prop;
- for (prop in source) {
- if (override || !(prop in target)) {
- target[prop] = source[prop];
- }
- }
- },
-
- delegate: (function () {
- // boodman/crockford delegation w/ cornford optimization
- function TMP() {}
- return function (obj, props) {
- TMP.prototype = obj;
- var tmp = new TMP();
- TMP.prototype = null;
- if (props) {
- lang.mixin(tmp, props);
- }
- return tmp; // Object
- };
- }())
- };
- return lang;
-});
View
53 build/jslib/logger.js
@@ -1,53 +0,0 @@
-/**
- * @license RequireJS Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
- * Available via the MIT or new BSD license.
- * see: http://github.com/jrburke/requirejs for details
- */
-
-/*jslint nomen: false, strict: false */
-/*global define: false */
-
-define(['env!env/print'], function (print) {
- var logger = {
- TRACE: 0,
- INFO: 1,
- WARN: 2,
- ERROR: 3,
- level: 0,
- logPrefix: "",
-
- trace: function (message) {
- if (this.level <= this.TRACE) {
- this._print(message);
- }
- },
-
- info: function (message) {
- if (this.level <= this.INFO) {
- this._print(message);
- }
- },
-
- warn: function (message) {
- if (this.level <= this.WARN) {
- this._print(message);
- }
- },
-
- error: function (message) {
- if (this.level <= this.ERROR) {
- this._print(message);
- }
- },
-
- _print: function (message) {
- this._sysPrint((this.logPrefix ? (this.logPrefix + " ") : "") + message);
- },
-
- _sysPrint: function (message) {