funcunit
Version:
<!-- @hide title
1,366 lines (1,171 loc) • 36.2 kB
JavaScript
(function(global){
// helpers
var camelize = function(str){
return str.replace(/-+(.)?/g, function(match, chr){
return chr ? chr.toUpperCase() : ''
});
},
each = function( o, cb){
var i, len;
// weak array detection, but we only use this internally so don't
// pass it weird stuff
if ( typeof o.length == 'number' && (o.length - 1) in o) {
for ( i = 0, len = o.length; i < len; i++ ) {
cb.call(o[i], o[i], i, o);
}
} else {
for ( i in o ) {
if(o.hasOwnProperty(i)){
cb.call(o[i], o[i], i, o);
}
}
}
return o;
},
map = function(o, cb) {
var arr = [];
each(o, function(item, i){
arr[i] = cb(item, i);
});
return arr;
},
isString = function(o) {
return typeof o == "string";
},
extend = function(d,s){
each(s, function(v, p){
d[p] = v;
});
return d;
},
dir = function(uri){
var lastSlash = uri.lastIndexOf("/");
//if no / slashes, check for \ slashes since it might be a windows path
if(lastSlash === -1)
lastSlash = uri.lastIndexOf("\\");
if(lastSlash !== -1) {
return uri.substr(0, lastSlash);
} else {
return uri;
}
},
last = function(arr){
return arr[arr.length - 1];
},
parseURI = function(url) {
var m = String(url).replace(/^\s+|\s+$/g, '').match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
// authority = '//' + user + ':' + pass '@' + hostname + ':' port
return (m ? {
href : m[0] || '',
protocol : m[1] || '',
authority: m[2] || '',
host : m[3] || '',
hostname : m[4] || '',
port : m[5] || '',
pathname : m[6] || '',
search : m[7] || '',
hash : m[8] || ''
} : null);
},
joinURIs = function(base, href) {
function removeDotSegments(input) {
var output = [];
input.replace(/^(\.\.?(\/|$))+/, '')
.replace(/\/(\.(\/|$))+/g, '/')
.replace(/\/\.\.$/, '/../')
.replace(/\/?[^\/]*/g, function (p) {
if (p === '/..') {
output.pop();
} else {
output.push(p);
}
});
return output.join('').replace(/^\//, input.charAt(0) === '/' ? '/' : '');
}
href = parseURI(href || '');
base = parseURI(base || '');
return !href || !base ? null : (href.protocol || base.protocol) +
(href.protocol || href.authority ? href.authority : base.authority) +
removeDotSegments(href.protocol || href.authority || href.pathname.charAt(0) === '/' ? href.pathname : (href.pathname ? ((base.authority && !base.pathname ? '/' : '') + base.pathname.slice(0, base.pathname.lastIndexOf('/') + 1) + href.pathname) : base.pathname)) +
(href.protocol || href.authority || href.pathname ? href.search : (href.search || base.search)) +
href.hash;
},
relativeURI = function(base, path) {
var uriParts = path.split("/"),
baseParts = base.split("/"),
result = [];
while ( uriParts.length && baseParts.length && uriParts[0] == baseParts[0] ) {
uriParts.shift();
baseParts.shift();
}
for(var i = 0 ; i< baseParts.length-1; i++) {
result.push("../");
}
return "./" + result.join("") + uriParts.join("/");
},
isWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope,
isNode = typeof process === "object" && {}.toString.call(process) === "[object process]",
isBrowserWithWindow = !isNode && typeof window !== "undefined",
isNW = isNode && (function(){
try {
return require("nw.gui") !== "undefined";
} catch(e) {
return false;
}
})(),
getStealScript = function(){
if(isBrowserWithWindow || isNW) {
if(document.currentScript) {
return document.currentScript;
}
var scripts = document.scripts;
if (scripts.length) {
var currentScript = scripts[scripts.length - 1];
return currentScript;
}
}
},
stealScript = getStealScript();
isNode = isNode && !isNW;
var filename = function(uri){
var lastSlash = uri.lastIndexOf("/");
//if no / slashes, check for \ slashes since it might be a windows path
if(lastSlash === -1)
lastSlash = uri.lastIndexOf("\\");
var matches = ( lastSlash == -1 ? uri : uri.substr(lastSlash+1) ).match(/^[\w-\s\.!]+/);
return matches ? matches[0] : "";
};
var ext = function(uri){
var fn = filename(uri);
var dot = fn.lastIndexOf(".");
if(dot !== -1) {
return fn.substr(dot+1);
} else {
return "";
}
};
var pluginCache = {};
var normalize = function(name, loader){
// Detech if this name contains a plugin part like: app.less!steal/less
// and catch the plugin name so that when it is normalized we do not perform
// Steal's normalization against it.
var pluginIndex = name.lastIndexOf('!');
var pluginPart = "";
if (pluginIndex != -1) {
// argumentName is the part before the !
var argumentName = name.substr(0, pluginIndex);
var pluginName = name.substr(pluginIndex + 1);
pluginPart = "!" + pluginName;
// Set the name to the argument name so that we can normalize it alone.
name = argumentName;
}
var last = filename(name),
extension = ext(name);
// if the name ends with /
if( name[name.length -1] === "/" ) {
return name+filename( name.substr(0, name.length-1) ) + pluginPart;
} else if( !/^(\w+(?:s)?:\/\/|\.|file|\/)/.test(name) &&
// and doesn't end with a dot
last.indexOf(".") === -1
) {
return name+"/"+last + pluginPart;
} else {
if(extension === "js") {
return name.substr(0, name.lastIndexOf(".")) + pluginPart;
} else {
return name + pluginPart;
}
}
};
var cloneSteal = function(System){
var loader = System || this.System;
return makeSteal(this.addSteal(loader.clone()));
};
var makeSteal = function(System){
System.set('@loader', System.newModule({'default':System, __useDefault: true}));
System.config({
map: {
"@loader/@loader": "@loader",
"@steal/@steal": "@steal"
}
});
var configDeferred,
devDeferred,
appDeferred;
var steal = function(){
var args = arguments;
var afterConfig = function(){
var imports = [];
var factory;
each(args, function(arg){
if(isString(arg)) {
imports.push( steal.System['import']( normalize(arg) ) );
} else if(typeof arg === "function") {
factory = arg;
}
});
var modules = Promise.all(imports);
if(factory) {
return modules.then(function(modules) {
return factory && factory.apply(null, modules);
});
} else {
return modules;
}
};
if(System.isEnv("production")) {
return afterConfig();
} else {
// wait until the config has loaded
return configDeferred.then(afterConfig,afterConfig);
}
};
System.set("@steal", System.newModule({"default":steal, __useDefault:true}));
steal.System = System;
steal.parseURI = parseURI;
steal.joinURIs = joinURIs;
steal.normalize = normalize;
steal.relativeURI = relativeURI;
// System.ext = {bar: "path/to/bar"}
// foo.bar! -> foo.bar!path/to/bar
var addExt = function(loader) {
if (loader._extensions) {
loader._extensions.push(addExt);
}
loader.ext = {};
var normalize = loader.normalize,
endingExtension = /\.(\w+)!?$/;
loader.normalize = function(name, parentName, parentAddress, pluginNormalize){
if(pluginNormalize) {
return normalize.apply(this, arguments);
}
var matches = name.match(endingExtension),
ext,
newName = name;
if(matches && loader.ext[ext = matches[1]]) {
var hasBang = name[name.length - 1] === "!";
newName = name + (hasBang ? "" : "!") + loader.ext[ext];
}
return normalize.call(this, newName, parentName, parentAddress);
};
};
if(typeof System){
addExt(System);
}
// "path/to/folder/" -> "path/to/folder/folder"
var addForwardSlash = function(loader) {
if (loader._extensions) {
loader._extensions.push(addForwardSlash);
}
var normalize = loader.normalize;
var npmLike = /@.+#.+/;
loader.normalize = function(name, parentName, parentAddress, pluginNormalize) {
var lastPos = name.length - 1,
secondToLast,
folderName;
if (name[lastPos] === "/") {
secondToLast = name.substring(0, lastPos).lastIndexOf("/");
folderName = name.substring(secondToLast + 1, lastPos);
if(npmLike.test(folderName)) {
folderName = folderName.substr(folderName.lastIndexOf("#") + 1);
}
name += folderName;
}
return normalize.call(this, name, parentName, parentAddress, pluginNormalize);
};
};
if (typeof System) {
addForwardSlash(System);
}
// override loader.translate to rewrite 'locate://' & 'pkg://' path schemes found
// in resources loaded by supporting plugins
var addLocate = function(loader){
/**
* @hide
* @function normalizeAndLocate
* @description Run a module identifier through Normalize and Locate hooks.
* @param {String} moduleName The module to run through normalize and locate.
* @return {Promise} A promise to resolve when the address is found.
*/
var normalizeAndLocate = function(moduleName, parentName){
var loader = this;
return Promise.resolve(loader.normalize(moduleName, parentName))
.then(function(name){
return loader.locate({name: name, metadata: {}});
}).then(function(address){
if(address.substr(address.length - 3) === ".js") {
address = address.substr(0, address.length - 3);
}
return address;
});
};
var relative = function(base, path){
var uriParts = path.split("/"),
baseParts = base.split("/"),
result = [];
while ( uriParts.length && baseParts.length && uriParts[0] == baseParts[0] ) {
uriParts.shift();
baseParts.shift();
}
for(var i = 0 ; i< baseParts.length-1; i++) {
result.push("../");
}
return result.join("") + uriParts.join("/");
};
var schemePattern = /(locate):\/\/([a-z0-9/._@-]*)/ig,
parsePathSchemes = function(source, parent) {
var locations = [];
source.replace(schemePattern, function(whole, scheme, path, index){
locations.push({
start: index,
end: index+whole.length,
name: path,
postLocate: function(address){
return relative(parent, address);
}
});
});
return locations;
};
var _translate = loader.translate;
loader.translate = function(load){
var loader = this;
// This only applies to plugin resources.
if(!load.metadata.plugin) {
return _translate.call(this, load);
}
// Use the translator if this file path scheme is supported by the plugin
var locateSupport = load.metadata.plugin.locateScheme;
if(!locateSupport) {
return _translate.call(this, load);
}
// Parse array of module names
var locations = parsePathSchemes(load.source, load.address);
// no locations found
if(!locations.length) {
return _translate.call(this, load);
}
// normalize and locate all of the modules found and then replace those instances in the source.
var promises = [];
for(var i = 0, len = locations.length; i < len; i++) {
promises.push(
normalizeAndLocate.call(this, locations[i].name, load.name)
);
}
return Promise.all(promises).then(function(addresses){
for(var i = locations.length - 1; i >= 0; i--) {
load.source = load.source.substr(0, locations[i].start)
+ locations[i].postLocate(addresses[i])
+ load.source.substr(locations[i].end, load.source.length);
}
return _translate.call(loader, load);
});
};
};
if(typeof System !== "undefined") {
addLocate(System);
}
function addContextual(loader){
if (loader._extensions) {
loader._extensions.push(addContextual);
}
loader._contextualModules = {};
loader.setContextual = function(moduleName, definer){
this._contextualModules[moduleName] = definer;
};
var normalize = loader.normalize;
loader.normalize = function(name, parentName){
var loader = this;
if (parentName) {
var definer = this._contextualModules[name];
// See if `name` is a contextual module
if (definer) {
name = name + '/' + parentName;
if(!loader.has(name)) {
// `definer` could be a function or could be a moduleName
if (typeof definer === 'string') {
definer = loader['import'](definer);
}
return Promise.resolve(definer)
.then(function(definer) {
if (definer['default']) {
definer = definer['default'];
}
loader.set(name, loader.newModule(definer.call(loader, parentName)));
return name;
});
}
return Promise.resolve(name);
}
}
return normalize.apply(this, arguments);
};
}
if(typeof System !== "undefined") {
addContextual(System);
}
function applyTraceExtension(loader){
if(loader._extensions) {
loader._extensions.push(applyTraceExtension);
}
loader._traceData = {
loads: {},
parentMap: {}
};
loader.getDependencies = function(moduleName){
var load = this.getModuleLoad(moduleName);
return load ? load.metadata.dependencies : undefined;
};
loader.getDependants = function(moduleName){
var deps = [];
var pars = this._traceData.parentMap[moduleName] || {};
eachOf(pars, function(name) { deps.push(name); });
return deps;
};
loader.getModuleLoad = function(moduleName){
return this._traceData.loads[moduleName];
};
loader.getBundles = function(moduleName, visited){
visited = visited || {};
visited[moduleName] = true;
var loader = this;
var parentMap = loader._traceData.parentMap;
var parents = parentMap[moduleName];
if(!parents) return [moduleName];
var bundles = [];
eachOf(parents, function(parentName, value){
if(!visited[parentName])
bundles = bundles.concat(loader.getBundles(parentName, visited));
});
return bundles;
};
loader._allowModuleExecution = {};
loader.allowModuleExecution = function(name){
var loader = this;
return loader.normalize(name).then(function(name){
loader._allowModuleExecution[name] = true;
});
};
function eachOf(obj, callback){
var name, val;
for(name in obj) {
callback(name, obj[name]);
}
}
var normalize = loader.normalize;
loader.normalize = function(name, parentName){
var normalizePromise = normalize.apply(this, arguments);
if(parentName) {
var parentMap = this._traceData.parentMap;
return normalizePromise.then(function(name){
if(!parentMap[name]) {
parentMap[name] = {};
}
parentMap[name][parentName] = true;
return name;
});
}
return normalizePromise;
};
var emptyExecute = function(){
return loader.newModule({});
};
var passThroughModules = {
traceur: true,
babel: true
};
var isAllowedToExecute = function(load){
return passThroughModules[load.name] || this._allowModuleExecution[load.name];
};
var map = [].map || function(callback){
var res = [];
for(var i = 0, len = this.length; i < len; i++) {
res.push(callback(this[i]));
}
return res;
};
var esImportDepsExp = /import [\s\S]*?["'](.+)["']/g;
var esExportDepsExp = /export .+ from ["'](.+)["']/g;
var commentRegEx = /(^|[^\\])(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg;
var stringRegEx = /(?:("|')[^\1\\\n\r]*(?:\\.[^\1\\\n\r]*)*\1|`[^`]*`)/g;
function getESDeps(source) {
esImportDepsExp.lastIndex = commentRegEx.lastIndex =
esExportDepsExp.lastIndex = stringRegEx.lastIndex = 0;
var deps = [];
var match;
// track string and comment locations for unminified source
var stringLocations = [], commentLocations = [];
function inLocation(locations, match) {
for (var i = 0; i < locations.length; i++)
if (locations[i][0] < match.index && locations[i][1] > match.index)
return true;
return false;
}
function addDeps(exp) {
while (match = exp.exec(source)) {
// ensure we're not within a string or comment location
if (!inLocation(stringLocations, match) && !inLocation(commentLocations, match)) {
var dep = match[1];//.substr(1, match[1].length - 2);
deps.push(dep);
}
}
}
if (source.length / source.split('\n').length < 200) {
while (match = stringRegEx.exec(source))
stringLocations.push([match.index, match.index + match[0].length]);
while (match = commentRegEx.exec(source)) {
// only track comments not starting in strings
if (!inLocation(stringLocations, match))
commentLocations.push([match.index, match.index + match[0].length]);
}
}
addDeps(esImportDepsExp);
addDeps(esExportDepsExp);
return deps;
}
var instantiate = loader.instantiate;
loader.instantiate = function(load){
this._traceData.loads[load.name] = load;
var loader = this;
var instantiatePromise = Promise.resolve(instantiate.apply(this, arguments));
function finalizeResult(result){
var preventExecution = loader.preventModuleExecution &&
!isAllowedToExecute.call(loader, load);
// deps either comes from the instantiate result, or if an
// es6 module it was found in the transpile hook.
var deps = result ? result.deps : load.metadata.deps;
return Promise.all(map.call(deps, function(depName){
return loader.normalize(depName, load.name);
})).then(function(dependencies){
load.metadata.deps = deps;
load.metadata.dependencies = dependencies;
if(preventExecution) {
return {
deps: deps,
execute: emptyExecute
};
}
return result;
});
}
return instantiatePromise.then(function(result){
// This must be es6
if(!result) {
var deps = getESDeps(load.source);
load.metadata.deps = deps;
}
return finalizeResult(result);
});
};
var transpile = loader.transpile;
// Allow transpile to be memoized, but only once
loader.transpile = function(load){
var transpiled = load.metadata.transpiledSource;
if(transpiled) {
delete load.metadata.transpiledSource;
return Promise.resolve(transpiled);
}
return transpile.apply(this, arguments);
};
loader.eachModule = function(cb){
for (var moduleName in this._loader.modules) {
cb.call(this, moduleName, this.get(moduleName));
}
};
}
if(typeof System !== "undefined") {
applyTraceExtension(System);
}
// Overwrites System.config with setter hooks
var setterConfig = function(loader, configSpecial){
var oldConfig = loader.config;
loader.config = function(cfg){
var data = extend({},cfg);
// check each special
each(configSpecial, function(special, name){
// if there is a setter and a value
if(special.set && data[name]){
// call the setter
var res = special.set.call(loader,data[name], cfg);
// if the setter returns a value
if(res !== undefined) {
// set that on the loader
loader[name] = res;
}
// delete the property b/c setting is done
delete data[name];
}
});
oldConfig.call(this, data);
};
};
var setIfNotPresent = function(obj, prop, value){
if(!obj[prop]) {
obj[prop] = value;
}
};
// steal.js's default configuration values
System.configMain = "@config";
System.paths[System.configMain] = "stealconfig.js";
System.env = (isWebWorker ? "worker" : "window") + "-development";
System.ext = {
css: '$css',
less: '$less'
};
System.logLevel = 0;
System.transpiler = "traceur";
var cssBundlesNameGlob = "bundles/*.css",
jsBundlesNameGlob = "bundles/*";
setIfNotPresent(System.paths,cssBundlesNameGlob, "dist/bundles/*css");
setIfNotPresent(System.paths,jsBundlesNameGlob, "dist/bundles/*.js");
var configSetter = {
set: function(val){
var name = filename(val),
root = dir(val);
if(!isNode) {
System.configPath = joinURIs( location.href, val);
}
System.configMain = name;
System.paths[name] = name;
addProductionBundles.call(this);
this.config({ baseURL: (root === val ? "." : root) + "/" });
}
},
mainSetter = {
set: function(val){
this.main = val;
addProductionBundles.call(this);
}
};
// checks if we're running in node, then prepends the "file:" protocol if we are
var envPath = function(val) {
if(isNode && !/^file:/.test(val)) {
// If relative join with the current working directory
if(val[0] === "." && (val[1] === "/" ||
(val[1] === "." && val[2] === "/"))) {
val = require("path").join(process.cwd(), val);
}
if(!val) return val;
return "file:" + val;
}
return val;
};
var fileSetter = function(prop) {
return {
set: function(val) {
this[prop] = envPath(val);
}
};
};
var setToSystem = function(prop){
return {
set: function(val){
if(typeof val === "object" && typeof steal.System[prop] === "object") {
this[prop] = extend(this[prop] || {},val || {});
} else {
this[prop] = val;
}
}
};
};
var pluginPart = function(name) {
var bang = name.lastIndexOf("!");
if(bang !== -1) {
return name.substr(bang+1);
}
};
var pluginResource = function(name){
var bang = name.lastIndexOf("!");
if(bang !== -1) {
return name.substr(0, bang);
}
};
var addProductionBundles = function(){
if(this.loadBundles && this.main) {
var main = this.main,
bundlesDir = this.bundlesName || "bundles/",
mainBundleName = bundlesDir+main;
setIfNotPresent(this.meta, mainBundleName, {format:"amd"});
// If the configMain has a plugin like package.json!npm,
// plugin has to be defined prior to importing.
var plugin = pluginPart(System.configMain);
var bundle = [main, System.configMain];
if(plugin){
System.set(plugin, System.newModule({}));
}
plugin = pluginPart(main);
if(plugin) {
var resource = pluginResource(main);
bundle.push(plugin);
bundle.push(resource);
mainBundleName = bundlesDir+resource.substr(0, resource.indexOf("."));
}
this.bundles[mainBundleName] = bundle;
}
};
var setEnvsConfig = function(){
if(this.envs) {
var envConfig = this.envs[this.env];
if(envConfig) {
this.config(envConfig);
}
}
};
var setupLiveReload = function(){
if(this.liveReloadInstalled) {
var loader = this;
this.import("live-reload", { name: "@@steal" }).then(function(reload){
reload(loader.configMain, function(){
setEnvsConfig.call(loader);
});
});
}
};
var specialConfig;
var envsSpecial = { map: true, paths: true, meta: true };
setterConfig(System, specialConfig = {
env: {
set: function(val){
this.env = val;
if(this.isEnv("production")) {
this.loadBundles = true;
}
addProductionBundles.call(this);
}
},
envs: {
set: function(val){
// envs should be set, deep
var envs = this.envs;
if(!envs) envs = this.envs = {};
each(val, function(cfg, name){
var env = envs[name];
if(!env) env = envs[name] = {};
each(cfg, function(val, name){
if(envsSpecial[name] && env[name]) {
extend(env[name], val);
} else {
env[name] = val;
}
});
//extend(env, cfg);
});
}
},
baseUrl: fileSetter("baseURL"),
baseURL: fileSetter("baseURL"),
root: fileSetter("baseURL"), //backwards comp
config: configSetter,
configPath: configSetter,
loadBundles: {
set: function(val){
this.loadBundles = val;
addProductionBundles.call(this);
}
},
startId: {
set: function(val){
mainSetter.set.call(this, normalize(val) );
}
},
main: mainSetter,
stealURL: {
// http://domain.com/steal/steal.js?moduleName,env&
set: function(url, cfg) {
System.stealURL = url;
var urlParts = url.split("?");
var path = urlParts.shift(),
search = urlParts.join("?"),
searchParts = search.split("&"),
paths = path.split("/"),
lastPart = paths.pop(),
stealPath = paths.join("/"),
platform = this.getPlatform() || (isWebWorker ? "worker" : "window");
// if steal is bundled we always are in production environment
if(this.stealBundled && this.stealBundled === true) {
this.config({ env: platform+"-production" });
}else{
specialConfig.stealPath.set.call(this,stealPath, cfg);
if (lastPart.indexOf("steal.production") > -1 && !cfg.env) {
this.config({ env: platform+"-production" });
addProductionBundles.call(this);
}
}
if(searchParts.length && searchParts[0].length) {
var searchConfig = {},
searchPart;
for(var i =0; i < searchParts.length; i++) {
searchPart = searchParts[i];
var paramParts = searchPart.split("=");
if(paramParts.length > 1) {
searchConfig[paramParts[0]] = paramParts.slice(1).join("=");
} else {
if(steal.dev) {
steal.dev.warn("Please use search params like ?main=main&env=production");
}
var oldParamParts = searchPart.split(",");
if (oldParamParts[0]) {
searchConfig.startId = oldParamParts[0];
}
if (oldParamParts[1]) {
searchConfig.env = oldParamParts[1];
}
}
}
this.config(searchConfig);
}
// Split on / to get rootUrl
}
},
// this gets called with the __dirname steal is in
stealPath: {
set: function(dirname, cfg) {
dirname = envPath(dirname);
var parts = dirname.split("/");
// steal keeps this around to make things easy no matter how you are using it.
setIfNotPresent(this.paths,"@dev", dirname+"/ext/dev.js");
setIfNotPresent(this.paths,"$css", dirname+"/ext/css.js");
setIfNotPresent(this.paths,"$less", dirname+"/ext/less.js");
setIfNotPresent(this.paths,"@less-engine", dirname+"/ext/less-engine.js");
setIfNotPresent(this.paths,"npm", dirname+"/ext/npm.js");
setIfNotPresent(this.paths,"npm-extension", dirname+"/ext/npm-extension.js");
setIfNotPresent(this.paths,"npm-utils", dirname+"/ext/npm-utils.js");
setIfNotPresent(this.paths,"npm-crawl", dirname+"/ext/npm-crawl.js");
setIfNotPresent(this.paths,"npm-load", dirname+"/ext/npm-load.js");
setIfNotPresent(this.paths,"npm-convert", dirname+"/ext/npm-convert.js");
setIfNotPresent(this.paths,"semver", dirname+"/ext/semver.js");
setIfNotPresent(this.paths,"bower", dirname+"/ext/bower.js");
setIfNotPresent(this.paths,"live-reload", dirname+"/ext/live-reload.js");
setIfNotPresent(this.paths,"steal-clone", dirname+"/ext/steal-clone.js");
this.paths["traceur"] = dirname+"/ext/traceur.js";
this.paths["traceur-runtime"] = dirname+"/ext/traceur-runtime.js";
this.paths["babel"] = dirname+"/ext/babel.js";
this.paths["babel-runtime"] = dirname+"/ext/babel-runtime.js";
// steal-clone is contextual so it can override modules using relative paths
this.setContextual('steal-clone', 'steal-clone');
if(isNode) {
System.register("@less-engine", [], false, function(){
var r = require;
return r('less');
});
if(this.configMain === "@config" && last(parts) === "steal") {
parts.pop();
if(last(parts) === "node_modules") {
this.configMain = "package.json!npm";
addProductionBundles.call(this);
parts.pop();
}
}
} else {
setIfNotPresent(this.paths, "@less-engine", dirname + "/ext/less-engine.js");
// make sure we don't set baseURL if something else is going to set it
if(!cfg.root && !cfg.baseUrl && !cfg.baseURL && !cfg.config && !cfg.configPath) {
if ( last(parts) === "steal" ) {
parts.pop();
if ( last(parts) === cfg.bowerPath || last(parts) === "bower_components" ) {
System.configMain = "bower.json!bower";
addProductionBundles.call(this);
parts.pop();
}
if (last(parts) === "node_modules") {
System.configMain = "package.json!npm";
addProductionBundles.call(this);
parts.pop();
}
}
this.config({ baseURL: parts.join("/")+"/"});
}
}
System.stealPath = dirname;
}
},
// System.config does not like being passed arrays.
bundle: {
set: function(val){
System.bundle = val;
}
},
bundlesPath: {
set: function(val){
this.paths[cssBundlesNameGlob] = val+"/*css";
this.paths[jsBundlesNameGlob] = val+"/*.js";
return val;
}
},
instantiated: {
set: function(val){
var loader = this;
each(val || {}, function(value, name){
loader.set(name, loader.newModule(value));
});
}
},
meta: {
set: function(cfg){
var loader = this;
each(cfg || {}, function(value, name){
if(typeof value !== "object") {
return;
}
var cur = loader.meta[name];
if(cur && cur.format === value.format) {
// Keep the deps, if we have any
var deps = value.deps;
extend(value, cur);
if(deps) {
value.deps = deps;
}
}
});
extend(this.meta, cfg);
}
}
});
steal.config = function(cfg){
if(typeof cfg === "string") {
return System[cfg];
} else {
System.config(cfg);
}
};
if(typeof System !== "undefined") {
addEnv(System);
}
function addEnv(loader){
// Add the extension to _extensions so that it can be cloned.
loader._extensions.push(addEnv);
loader.getEnv = function(){
var envParts = (this.env || "").split("-");
// Fallback to this.env for legacy
return envParts[1] || this.env;
};
loader.getPlatform = function(){
var envParts = (this.env || "").split("-");
return envParts.length === 2 ? envParts[0] : undefined;
};
loader.isEnv = function(name){
return this.getEnv() === name;
};
loader.isPlatform = function(name){
return this.getPlatform() === name;
};
}
var getScriptOptions = function () {
var options = {},
parts, src, query, startFile, env,
scripts = document.getElementsByTagName("script");
var script = stealScript || getStealScript();
if (script) {
options.stealURL = script.src;
// Split on question mark to get query
each(script.attributes, function(attr){
var optionName =
camelize( attr.nodeName.indexOf("data-") === 0 ?
attr.nodeName.replace("data-","") :
attr.nodeName );
options[optionName] = (attr.value === "") ? true : attr.value;
});
var source = script.innerHTML;
if(/\S/.test(source)){
options.mainSource = source;
}
}
return options;
};
steal.startup = function(config){
// Get options from the script tag
if (isWebWorker) {
var urlOptions = {
stealURL: location.href
};
} else if(isBrowserWithWindow || isNW) {
var urlOptions = getScriptOptions();
} else {
// or the only option is where steal is.
var urlOptions = {
stealPath: __dirname
};
}
// first set the config that is set with a steal object
if(config){
System.config(config);
}
// B: DO THINGS WITH OPTIONS
// CALCULATE CURRENT LOCATION OF THINGS ...
System.config(urlOptions);
setEnvsConfig.call(this.System);
// Read the env now because we can't overwrite everything yet
// immediate steals we do
var steals = [];
// we only load things with force = true
if ( System.loadBundles ) {
if(!System.main && System.isEnv("production") && !System.stealBundled) {
// prevent this warning from being removed by Uglify
var warn = console && console.warn || function() {};
warn.call(console, "Attribute 'main' is required in production environment. Please add it to the script tag.");
}
configDeferred = System["import"](System.configMain);
appDeferred = configDeferred.then(function(cfg){
setEnvsConfig.call(System);
return System.main ? System["import"](System.main) : cfg;
});
} else {
configDeferred = System["import"](System.configMain);
devDeferred = configDeferred.then(function(){
setEnvsConfig.call(System);
setupLiveReload.call(System);
// If a configuration was passed to startup we'll use that to overwrite
// what was loaded in stealconfig.js
// This means we call it twice, but that's ok
if(config) {
System.config(config);
}
return System["import"]("@dev");
},function(e){
console.log("steal - error loading @config.",e);
return steal.System["import"]("@dev");
});
appDeferred = devDeferred.then(function(){
// if there's a main, get it, otherwise, we are just loading
// the config.
if(!System.main || System.env === "build") {
return configDeferred;
}
var main = System.main;
if(typeof main === "string") {
main = [main];
}
return Promise.all( map(main,function(main){
return System["import"](main);
}) );
});
}
if(System.mainSource) {
appDeferred = appDeferred.then(function(){
return System.module(System.mainSource);
});
}
return appDeferred;
};
steal.done = function(){
return appDeferred;
};
steal["import"] = function(){
var names = arguments;
var loader = this.System;
function afterConfig(){
var imports = [];
each(names, function(name){
imports.push(loader["import"](name));
});
if(imports.length > 1) {
return Promise.all(imports);
} else {
return imports[0];
}
}
if(!configDeferred) {
steal.startup();
}
return configDeferred.then(afterConfig);
};
return steal;
};
/*
SystemJS Steal Format
Provides the Steal module format definition.
*/
function addSteal(loader) {
if (loader._extensions) {
loader._extensions.push(addSteal);
}
// Steal Module Format Detection RegEx
// steal(module, ...)
var stealRegEx = /(?:^\s*|[}{\(\);,\n\?\&]\s*)steal\s*\(\s*((?:"[^"]+"\s*,|'[^']+'\s*,\s*)*)/;
// What we stole.
var stealInstantiateResult;
function createSteal(loader) {
stealInstantiateResult = null;
// ensure no NodeJS environment detection
loader.global.module = undefined;
loader.global.exports = undefined;
function steal() {
var deps = [];
var factory;
for( var i = 0; i < arguments.length; i++ ) {
if (typeof arguments[i] === 'string') {
deps.push( normalize(arguments[i]) );
} else {
factory = arguments[i];
}
}
if (typeof factory !== 'function') {
factory = (function(factory) {
return function() { return factory; };
})(factory);
}
stealInstantiateResult = {
deps: deps,
execute: function(require, exports, moduleName) {
var depValues = [];
for (var i = 0; i < deps.length; i++) {
depValues.push(require(deps[i]));
}
var output = factory.apply(loader.global, depValues);
if (typeof output !== 'undefined') {
return output;
}
}
};
}
loader.global.steal = steal;
}
var loaderInstantiate = loader.instantiate;
loader.instantiate = function(load) {
var loader = this;
if (load.metadata.format === 'steal' || !load.metadata.format && load.source.match(stealRegEx)) {
load.metadata.format = 'steal';
var oldSteal = loader.global.steal;
createSteal(loader);
loader.__exec(load);
loader.global.steal = oldSteal;
if (!stealInstantiateResult) {
throw "Steal module " + load.name + " did not call steal";
}
if (stealInstantiateResult) {
load.metadata.deps = load.metadata.deps ? load.metadata.deps.concat(stealInstantiateResult.deps) : stealInstantiateResult.deps;
load.metadata.execute = stealInstantiateResult.execute;
}
}
return loaderInstantiate.call(loader, load);
};
return loader;
}
if (typeof System !== "undefined") {
addSteal(System);
}
if( isNode && !isNW ) {
require('steal-systemjs');
global.steal = makeSteal(System);
global.steal.System = System;
global.steal.dev = require("./ext/dev.js");
steal.clone = cloneSteal;
module.exports = global.steal;
global.steal.addSteal = addSteal;
require("system-json");
} else {
var oldSteal = global.steal;
global.steal = makeSteal(System);
global.steal.startup(oldSteal && typeof oldSteal == 'object' && oldSteal)
.then(null, function(error){
if(typeof console !== "undefined") {
// Hide from uglify
var c = console;
var type = c.error ? "error" : "log";
c[type](error, error.stack);
}
});
global.steal.clone = cloneSteal;
global.steal.addSteal = addSteal;
}
})(typeof window == "undefined" ? (typeof global === "undefined" ? this : global) : window);