@@ -1,6 +1,5 @@ | |||
# Ignore builds | |||
# temporal disabled for git instalation | |||
#build/** | |||
build/** | |||
# Ignore OS X stuff | |||
.DS_Store | |||
@@ -8,5 +7,4 @@ | |||
# Ignore generated docs | |||
utils/doc/generated_docs | |||
#Ignode npm build | |||
/node_modules/ | |||
node_modules |
@@ -1 +1 @@ | |||
2.2.1 | |||
2.3.0 |
@@ -5,11 +5,11 @@ | |||
if (!window.requestAnimationFrame) { | |||
window.requestAnimationFrame = function () { | |||
window.requestAnimationFrame = function () { | |||
return window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function ( /* function FrameRequestCallback */callback, /* DOMElement Element */element) { | |||
return window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function ( /* function FrameRequestCallback */callback, /* DOMElement Element */element) { | |||
window.setTimeout(callback, 1000 / 60); | |||
}; | |||
}(); | |||
window.setTimeout(callback, 1000 / 60); | |||
}; | |||
}(); | |||
} |
@@ -29,41 +29,65 @@ window.libpannellum = function (window, document, undefined) { | |||
* Creates a new panorama renderer. | |||
* @constructor | |||
* @param {HTMLElement} container - The container element for the renderer. | |||
* @param {Image|Array|Object} image - Input image; format varies based on | |||
* `imageType`. For `equirectangular`, this is an image; for `cubemap`, | |||
* this is an array of images for the cube faces in the order [+z, +x, -z, | |||
* -x, +y, -y]; for `multires`, this is a configuration object. | |||
* @param {string} imageType - The type of the image: `equirectangular`, | |||
* `cubemap`, or `multires`. | |||
* @param {boolean} dynamic - Whether or not the image is dynamic (e.g. video). | |||
*/ | |||
function Renderer(container, image, imageType, dynamic) { | |||
function Renderer(container) { | |||
var canvas = document.createElement('canvas'); | |||
canvas.style.width = canvas.style.height = '100%'; | |||
container.appendChild(canvas); | |||
// Default argument for image type | |||
if (typeof imageType === undefined) { | |||
imageType = 'equirectangular'; | |||
} | |||
var program, gl; | |||
var program, gl, vs, fs; | |||
var fallbackImgSize; | |||
var world; | |||
var vtmps; | |||
var pose; | |||
var image, imageType, dynamic; | |||
var texCoordBuffer, cubeVertBuf, cubeVertTexCoordBuf, cubeVertIndBuf; | |||
/** | |||
* Initialize renderer. | |||
* @memberof Renderer | |||
* @instance | |||
* @param {Image|Array|Object} image - Input image; format varies based on | |||
* `imageType`. For `equirectangular`, this is an image; for | |||
* `cubemap`, this is an array of images for the cube faces in the | |||
* order [+z, +x, -z, -x, +y, -y]; for `multires`, this is a | |||
* configuration object. | |||
* @param {string} imageType - The type of the image: `equirectangular`, | |||
* `cubemap`, or `multires`. | |||
* @param {boolean} dynamic - Whether or not the image is dynamic (e.g. video). | |||
* @param {number} haov - Initial horizontal angle of view. | |||
* @param {number} vaov - Initial vertical angle of view. | |||
* @param {number} voffset - Initial vertical offset angle. | |||
* @param {function} callback - Load callback function. | |||
* @param {Object} [params] - Other configuration parameters (`horizonPitch`, `horizonRoll`, `backgroundColor`). | |||
*/ | |||
this.init = function (haov, vaov, voffset, callback) { | |||
this.init = function (_image, _imageType, _dynamic, haov, vaov, voffset, callback, params) { | |||
// Default argument for image type | |||
if (typeof _imageType === undefined) _imageType = 'equirectangular'; | |||
imageType = _imageType; | |||
image = _image; | |||
dynamic = _dynamic; | |||
// Clear old data | |||
if (program) { | |||
if (vs) { | |||
gl.detachShader(program, vs); | |||
gl.deleteShader(vs); | |||
} | |||
if (fs) { | |||
gl.detachShader(program, fs); | |||
gl.deleteShader(fs); | |||
} | |||
gl.bindBuffer(gl.ARRAY_BUFFER, null); | |||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); | |||
if (program.texture) gl.deleteTexture(program.texture); | |||
if (program.nodeCache) for (var i = 0; i < program.nodeCache.length; i++) gl.deleteTexture(program.nodeCache[i].texture); | |||
gl.deleteProgram(program); | |||
program = undefined; | |||
} | |||
pose = undefined; | |||
var s; | |||
// This awful browser specific test exists because iOS 8/9 and IE 11 | |||
@@ -74,7 +98,7 @@ window.libpannellum = function (window, document, undefined) { | |||
// instead. | |||
if (!(imageType == 'cubemap' && (image[0].width & image[0].width - 1) !== 0 && (navigator.userAgent.toLowerCase().match(/(iphone|ipod|ipad).* os 8_/) || navigator.userAgent.toLowerCase().match(/(iphone|ipod|ipad).* os 9_/) || navigator.userAgent.match(/Trident.*rv[ :]*11\./)))) { | |||
// Enable WebGL on canvas | |||
gl = canvas.getContext('experimental-webgl', { alpha: false, depth: false }); | |||
if (!gl) gl = canvas.getContext('experimental-webgl', { alpha: false, depth: false }); | |||
} | |||
// If there is no WebGL, fall back to CSS 3D transform renderer. | |||
@@ -214,9 +238,7 @@ window.libpannellum = function (window, document, undefined) { | |||
} | |||
// Store horizon pitch and roll if applicable | |||
if (image.horizonPitch !== undefined && image.horizonRoll !== undefined) { | |||
pose = [image.horizonPitch, image.horizonRoll]; | |||
} | |||
if (params !== undefined && (params.horizonPitch !== undefined || params.horizonRoll !== undefined)) pose = [params.horizonPitch == undefined ? 0 : params.horizonPitch, params.horizonRoll == undefined ? 0 : params.horizonRoll]; | |||
// Set 2d texture binding | |||
var glBindType = gl.TEXTURE_2D; | |||
@@ -225,7 +247,7 @@ window.libpannellum = function (window, document, undefined) { | |||
gl.viewport(0, 0, canvas.width, canvas.height); | |||
// Create vertex shader | |||
var vs = gl.createShader(gl.VERTEX_SHADER); | |||
vs = gl.createShader(gl.VERTEX_SHADER); | |||
var vertexSrc = v; | |||
if (imageType == 'multires') { | |||
vertexSrc = vMulti; | |||
@@ -234,7 +256,7 @@ window.libpannellum = function (window, document, undefined) { | |||
gl.compileShader(vs); | |||
// Create fragment shader | |||
var fs = gl.createShader(gl.FRAGMENT_SHADER); | |||
fs = gl.createShader(gl.FRAGMENT_SHADER); | |||
var fragmentSrc = fragEquirectangular; | |||
if (imageType == 'cubemap') { | |||
glBindType = gl.TEXTURE_CUBE_MAP; | |||
@@ -267,8 +289,8 @@ window.libpannellum = function (window, document, undefined) { | |||
if (imageType != 'multires') { | |||
// Provide texture coordinates for rectangle | |||
program.texCoordBuffer = gl.createBuffer(); | |||
gl.bindBuffer(gl.ARRAY_BUFFER, program.texCoordBuffer); | |||
if (!texCoordBuffer) texCoordBuffer = gl.createBuffer(); | |||
gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer); | |||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, 1, 1, 1, 1, -1, -1, 1, 1, -1, -1, -1]), gl.STATIC_DRAW); | |||
gl.vertexAttribPointer(program.texCoordLocation, 2, gl.FLOAT, false, 0, 0); | |||
@@ -290,6 +312,13 @@ window.libpannellum = function (window, document, undefined) { | |||
gl.uniform1f(program.v, vaov / Math.PI); | |||
gl.uniform1f(program.vo, voffset / Math.PI * 2); | |||
// Set background color | |||
if (imageType == 'equirectangular') { | |||
program.backgroundColor = gl.getUniformLocation(program, 'u_backgroundColor'); | |||
var color = params.backgroundColor ? params.backgroundColor : [0, 0, 0]; | |||
gl.uniform4fv(program.backgroundColor, color.concat([1])); | |||
} | |||
// Create texture | |||
program.texture = gl.createTexture(); | |||
gl.bindTexture(glBindType, program.texture); | |||
@@ -319,16 +348,16 @@ window.libpannellum = function (window, document, undefined) { | |||
gl.enableVertexAttribArray(program.vertPosLocation); | |||
// Create buffers | |||
program.cubeVertBuf = gl.createBuffer(); | |||
program.cubeVertTexCoordBuf = gl.createBuffer(); | |||
program.cubeVertIndBuf = gl.createBuffer(); | |||
if (!cubeVertBuf) cubeVertBuf = gl.createBuffer(); | |||
if (!cubeVertTexCoordBuf) cubeVertTexCoordBuf = gl.createBuffer(); | |||
if (!cubeVertIndBuf) cubeVertIndBuf = gl.createBuffer(); | |||
// Bind texture coordinate buffer and pass coordinates to WebGL | |||
gl.bindBuffer(gl.ARRAY_BUFFER, program.cubeVertTexCoordBuf); | |||
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertTexCoordBuf); | |||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]), gl.STATIC_DRAW); | |||
// Bind square index buffer and pass indicies to WebGL | |||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, program.cubeVertIndBuf); | |||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertIndBuf); | |||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array([0, 1, 2, 0, 2, 3]), gl.STATIC_DRAW); | |||
// Find uniforms | |||
@@ -366,6 +395,12 @@ window.libpannellum = function (window, document, undefined) { | |||
container.removeChild(world); | |||
} | |||
} | |||
if (gl) { | |||
// The spec says this is only supposed to simulate losing the WebGL | |||
// context, but in practice it tends to actually free the memory. | |||
var extension = gl.getExtension('WEBGL_lose_context'); | |||
if (extension) extension.loseContext(); | |||
} | |||
}; | |||
/** | |||
@@ -406,6 +441,28 @@ window.libpannellum = function (window, document, undefined) { | |||
if (params === undefined) params = {}; | |||
if (params.roll) roll = params.roll; | |||
// Apply pitch and roll transformation if applicable | |||
if (pose !== undefined) { | |||
var horizonPitch = pose[0], | |||
horizonRoll = pose[1]; | |||
// Calculate new pitch and yaw | |||
var orig_pitch = pitch, | |||
orig_yaw = yaw, | |||
x = Math.cos(horizonRoll) * Math.sin(pitch) * Math.sin(horizonPitch) + Math.cos(pitch) * (Math.cos(horizonPitch) * Math.cos(yaw) + Math.sin(horizonRoll) * Math.sin(horizonPitch) * Math.sin(yaw)), | |||
y = -Math.sin(pitch) * Math.sin(horizonRoll) + Math.cos(pitch) * Math.cos(horizonRoll) * Math.sin(yaw), | |||
z = Math.cos(horizonRoll) * Math.cos(horizonPitch) * Math.sin(pitch) + Math.cos(pitch) * (-Math.cos(yaw) * Math.sin(horizonPitch) + Math.cos(horizonPitch) * Math.sin(horizonRoll) * Math.sin(yaw)); | |||
pitch = Math.asin(Math.max(Math.min(z, 1), -1)); | |||
yaw = Math.atan2(y, x); | |||
// Calculate roll | |||
var v = [Math.cos(orig_pitch) * (Math.sin(horizonRoll) * Math.sin(horizonPitch) * Math.cos(orig_yaw) - Math.cos(horizonPitch) * Math.sin(orig_yaw)), Math.cos(orig_pitch) * Math.cos(horizonRoll) * Math.cos(orig_yaw), Math.cos(orig_pitch) * (Math.cos(horizonPitch) * Math.sin(horizonRoll) * Math.cos(orig_yaw) + Math.sin(orig_yaw) * Math.sin(horizonPitch))], | |||
w = [-Math.cos(pitch) * Math.sin(yaw), Math.cos(pitch) * Math.cos(yaw)]; | |||
var roll_adj = Math.acos(Math.max(Math.min((v[0] * w[0] + v[1] * w[1]) / (Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]) * Math.sqrt(w[0] * w[0] + w[1] * w[1])), 1), -1)); | |||
if (v[2] < 0) roll_adj = 2 * Math.PI - roll_adj; | |||
roll += roll_adj; | |||
} | |||
// If no WebGL | |||
if (!gl && (imageType == 'multires' || imageType == 'cubemap')) { | |||
// Determine face transforms | |||
@@ -438,28 +495,6 @@ window.libpannellum = function (window, document, undefined) { | |||
var vfov = 2 * Math.atan(Math.tan(hfov * 0.5) / (canvas.width / canvas.height)); | |||
focal = 1 / Math.tan(vfov * 0.5); | |||
// Apply pitch and roll transformation if applicable | |||
if (imageType == 'equirectangular' && pose !== undefined) { | |||
var horizonPitch = pose[0], | |||
horizonRoll = pose[1]; | |||
// Calculate new pitch and yaw | |||
var orig_pitch = pitch, | |||
orig_yaw = yaw, | |||
x = Math.cos(horizonRoll) * Math.sin(pitch) * Math.sin(horizonPitch) + Math.cos(pitch) * (Math.cos(horizonPitch) * Math.cos(yaw) + Math.sin(horizonRoll) * Math.sin(horizonPitch) * Math.sin(yaw)), | |||
y = -Math.sin(pitch) * Math.sin(horizonRoll) + Math.cos(pitch) * Math.cos(horizonRoll) * Math.sin(yaw), | |||
z = Math.cos(horizonRoll) * Math.cos(horizonPitch) * Math.sin(pitch) + Math.cos(pitch) * (-Math.cos(yaw) * Math.sin(horizonPitch) + Math.cos(horizonPitch) * Math.sin(horizonRoll) * Math.sin(yaw)); | |||
pitch = Math.asin(z); | |||
yaw = Math.atan2(y, x); | |||
// Calculate roll | |||
var v = [Math.cos(orig_pitch) * (Math.sin(horizonRoll) * Math.sin(horizonPitch) * Math.cos(orig_yaw) - Math.cos(horizonPitch) * Math.sin(orig_yaw)), Math.cos(orig_pitch) * Math.cos(horizonRoll) * Math.cos(orig_yaw), Math.cos(orig_pitch) * (Math.cos(horizonPitch) * Math.sin(horizonRoll) * Math.cos(orig_yaw) + Math.sin(orig_yaw) * Math.sin(horizonPitch))], | |||
w = [-Math.cos(pitch) * Math.sin(yaw), Math.cos(pitch) * Math.cos(yaw)]; | |||
var roll_adj = Math.acos((v[0] * w[0] + v[1] * w[1]) / (Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]) * Math.sqrt(w[0] * w[0] + w[1] * w[1]))); | |||
if (v[2] < 0) roll_adj = 2 * Math.PI - roll_adj; | |||
roll += roll_adj; | |||
} | |||
// Pass psi, theta, roll, and focal length | |||
gl.uniform1f(program.psi, yaw); | |||
gl.uniform1f(program.theta, pitch); | |||
@@ -499,7 +534,11 @@ window.libpannellum = function (window, document, undefined) { | |||
program.nodeCache.sort(multiresNodeSort); | |||
if (program.nodeCache.length > 200 && program.nodeCache.length > program.currentNodes.length + 50) { | |||
// Remove older nodes from cache | |||
program.nodeCache.splice(200, program.nodeCache.length - 200); | |||
var removed = program.nodeCache.splice(200, program.nodeCache.length - 200); | |||
for (var i = 0; i < removed.length; i++) { | |||
// Explicitly delete textures | |||
gl.deleteTexture(removed[i].texture); | |||
} | |||
} | |||
program.currentNodes = []; | |||
@@ -603,12 +642,12 @@ window.libpannellum = function (window, document, undefined) { | |||
//gl.uniform4f(program.colorUniform, color[0], color[1], color[2], 1.0); | |||
// Bind vertex buffer and pass vertices to WebGL | |||
gl.bindBuffer(gl.ARRAY_BUFFER, program.cubeVertBuf); | |||
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertBuf); | |||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(program.currentNodes[i].vertices), gl.STATIC_DRAW); | |||
gl.vertexAttribPointer(program.vertPosLocation, 3, gl.FLOAT, false, 0, 0); | |||
// Prep for texture | |||
gl.bindBuffer(gl.ARRAY_BUFFER, program.cubeVertTexCoordBuf); | |||
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertTexCoordBuf); | |||
gl.vertexAttribPointer(program.texCoordLocation, 2, gl.FLOAT, false, 0, 0); | |||
// Bind texture and draw tile | |||
@@ -728,7 +767,7 @@ window.libpannellum = function (window, document, undefined) { | |||
} | |||
} | |||
// Handle small tiles that have fewer than four children | |||
if (doubleTileSize < image.tileResolution) { | |||
if (doubleTileSize <= image.tileResolution) { | |||
if (node.x == numTiles) { | |||
f1 = 0; | |||
i1 = 1; | |||
@@ -750,17 +789,17 @@ window.libpannellum = function (window, document, undefined) { | |||
vtmp = [v[0], v[1], v[2], v[0] * f1 + v[3] * i1, v[1] * f + v[4] * i, v[2] * f3 + v[5] * i3, v[0] * f1 + v[6] * i1, v[1] * f2 + v[7] * i2, v[2] * f3 + v[8] * i3, v[0] * f + v[9] * i, v[1] * f2 + v[10] * i2, v[2] * f3 + v[11] * i3]; | |||
ntmp = new MultiresNode(vtmp, node.side, node.level + 1, node.x * 2, node.y * 2, image.fullpath); | |||
children.push(ntmp); | |||
if (!(node.x == numTiles && doubleTileSize < image.tileResolution)) { | |||
if (!(node.x == numTiles && doubleTileSize <= image.tileResolution)) { | |||
vtmp = [v[0] * f1 + v[3] * i1, v[1] * f + v[4] * i, v[2] * f3 + v[5] * i3, v[3], v[4], v[5], v[3] * f + v[6] * i, v[4] * f2 + v[7] * i2, v[5] * f3 + v[8] * i3, v[0] * f1 + v[6] * i1, v[1] * f2 + v[7] * i2, v[2] * f3 + v[8] * i3]; | |||
ntmp = new MultiresNode(vtmp, node.side, node.level + 1, node.x * 2 + 1, node.y * 2, image.fullpath); | |||
children.push(ntmp); | |||
} | |||
if (!(node.x == numTiles && doubleTileSize < image.tileResolution) && !(node.y == numTiles && doubleTileSize < image.tileResolution)) { | |||
if (!(node.x == numTiles && doubleTileSize <= image.tileResolution) && !(node.y == numTiles && doubleTileSize <= image.tileResolution)) { | |||
vtmp = [v[0] * f1 + v[6] * i1, v[1] * f2 + v[7] * i2, v[2] * f3 + v[8] * i3, v[3] * f + v[6] * i, v[4] * f2 + v[7] * i2, v[5] * f3 + v[8] * i3, v[6], v[7], v[8], v[9] * f1 + v[6] * i1, v[10] * f + v[7] * i, v[11] * f3 + v[8] * i3]; | |||
ntmp = new MultiresNode(vtmp, node.side, node.level + 1, node.x * 2 + 1, node.y * 2 + 1, image.fullpath); | |||
children.push(ntmp); | |||
} | |||
if (!(node.y == numTiles && doubleTileSize < image.tileResolution)) { | |||
if (!(node.y == numTiles && doubleTileSize <= image.tileResolution)) { | |||
vtmp = [v[0] * f + v[9] * i, v[1] * f2 + v[10] * i2, v[2] * f3 + v[11] * i3, v[0] * f1 + v[6] * i1, v[1] * f2 + v[7] * i2, v[2] * f3 + v[8] * i3, v[9] * f1 + v[6] * i1, v[10] * f + v[7] * i, v[11] * f3 + v[8] * i3, v[9], v[10], v[11]]; | |||
ntmp = new MultiresNode(vtmp, node.side, node.level + 1, node.x * 2, node.y * 2 + 1, image.fullpath); | |||
children.push(ntmp); | |||
@@ -869,22 +908,64 @@ window.libpannellum = function (window, document, undefined) { | |||
gl.bindTexture(gl.TEXTURE_2D, null); | |||
} | |||
// Based on http://blog.tojicode.com/2012/03/javascript-memory-optimization-and.html | |||
var loadTexture = function () { | |||
var cacheTop = 4; // Maximum number of concurrents loads | |||
var textureImageCache = {}; | |||
var pendingTextureRequests = []; | |||
function TextureImageLoader() { | |||
var self = this; | |||
this.texture = this.callback = null; | |||
this.image = new Image(); | |||
this.image.crossOrigin = 'anonymous'; | |||
this.image.addEventListener('load', function () { | |||
processLoadedTexture(self.image, self.texture); | |||
self.callback(self.texture); | |||
releaseTextureImageLoader(self); | |||
}); | |||
}; | |||
TextureImageLoader.prototype.loadTexture = function (src, texture, callback) { | |||
this.texture = texture; | |||
this.callback = callback; | |||
this.image.src = src; | |||
}; | |||
function PendingTextureRequest(src, texture, callback) { | |||
this.src = src; | |||
this.texture = texture; | |||
this.callback = callback; | |||
}; | |||
function releaseTextureImageLoader(til) { | |||
if (pendingTextureRequests.length) { | |||
var req = pendingTextureRequests.shift(); | |||
til.loadTexture(req.src, req.texture, req.callback); | |||
} else textureImageCache[cacheTop++] = til; | |||
} | |||
for (var i = 0; i < cacheTop; i++) textureImageCache[i] = new TextureImageLoader(); | |||
return function (src, callback) { | |||
var texture = gl.createTexture(); | |||
if (cacheTop) textureImageCache[--cacheTop].loadTexture(src, texture, callback);else pendingTextureRequests.push(new PendingTextureRequest(src, texture, callback)); | |||
return texture; | |||
}; | |||
}(); | |||
/** | |||
* Loads image and creates texture for a multires node / tile. | |||
* @private | |||
* @param {MultiresNode} node - Input node. | |||
*/ | |||
function processNextTile(node) { | |||
if (!node.texture) { | |||
node.texture = gl.createTexture(); | |||
node.image = new Image(); | |||
node.image.crossOrigin = 'anonymous'; | |||
node.image.onload = function () { | |||
processLoadedTexture(node.image, node.texture); | |||
if (!node.textureLoad) { | |||
node.textureLoad = true; | |||
loadTexture(encodeURI(node.path + '.' + image.extension), function (texture) { | |||
node.texture = texture; | |||
node.textureLoaded = true; | |||
delete node.image; | |||
}; | |||
node.image.src = encodeURI(node.path + '.' + image.extension); | |||
}); | |||
} | |||
} | |||
@@ -988,45 +1069,35 @@ window.libpannellum = function (window, document, undefined) { | |||
'v_texCoord = a_texCoord;', '}'].join(''); | |||
// Fragment shader | |||
var fragCube = ['precision mediump float;', 'uniform float u_aspectRatio;', 'uniform float u_psi;', 'uniform float u_theta;', 'uniform float u_f;', 'uniform float u_h;', 'uniform float u_v;', 'uniform float u_vo;', 'uniform float u_rot;', 'const float PI = 3.14159265358979323846264;', | |||
var fragEquiCubeBase = ['precision mediump float;', 'uniform float u_aspectRatio;', 'uniform float u_psi;', 'uniform float u_theta;', 'uniform float u_f;', 'uniform float u_h;', 'uniform float u_v;', 'uniform float u_vo;', 'uniform float u_rot;', 'const float PI = 3.14159265358979323846264;', | |||
// Texture | |||
'uniform samplerCube u_image;', | |||
'uniform sampler2D u_image;', 'uniform samplerCube u_imageCube;', | |||
// Coordinates passed in from vertex shader | |||
'varying vec2 v_texCoord;', 'void main() {', | |||
// Find the vector of focal point to view plane | |||
'vec3 planePos = vec3(v_texCoord.xy, 0.0);', 'planePos.x *= u_aspectRatio;', 'float sinrot = sin(u_rot);', 'float cosrot = cos(u_rot);', 'vec3 rotPos = vec3(planePos.x * cosrot - planePos.y * sinrot, planePos.x * sinrot + planePos.y * cosrot, 0.0);', 'vec3 viewVector = rotPos - vec3(0.0, 0.0, -u_f);', | |||
'varying vec2 v_texCoord;', | |||
// Rotate vector for psi (yaw) and theta (pitch) | |||
'float sinpsi = sin(-u_psi);', 'float cospsi = cos(-u_psi);', 'float sintheta = sin(u_theta);', 'float costheta = cos(u_theta);', | |||
// Now apply the rotations | |||
'vec3 viewVectorTheta = viewVector;', 'viewVectorTheta.z = viewVector.z * costheta - viewVector.y * sintheta;', 'viewVectorTheta.y = viewVector.z * sintheta + viewVector.y * costheta;', 'vec3 viewVectorPsi = viewVectorTheta;', 'viewVectorPsi.x = viewVectorTheta.x * cospsi - viewVectorTheta.z * sinpsi;', 'viewVectorPsi.z = viewVectorTheta.x * sinpsi + viewVectorTheta.z * cospsi;', | |||
// Background color (display for partial panoramas) | |||
'uniform vec4 u_backgroundColor;', 'void main() {', | |||
// Map canvas/camera to sphere | |||
'float x = v_texCoord.x * u_aspectRatio;', 'float y = v_texCoord.y;', 'float sinrot = sin(u_rot);', 'float cosrot = cos(u_rot);', 'float rot_x = x * cosrot - y * sinrot;', 'float rot_y = x * sinrot + y * cosrot;', 'float sintheta = sin(u_theta);', 'float costheta = cos(u_theta);', 'float a = u_f * costheta - rot_y * sintheta;', 'float root = sqrt(rot_x * rot_x + a * a);', 'float lambda = atan(rot_x / root, a / root) + u_psi;', 'float phi = atan((rot_y * costheta + u_f * sintheta) / root);'].join('\n'); | |||
// Fragment shader | |||
var fragCube = fragEquiCubeBase + [ | |||
// Look up color from texture | |||
'gl_FragColor = textureCube(u_image, viewVectorPsi);', '}'].join('\n'); | |||
'float cosphi = cos(phi);', 'gl_FragColor = textureCube(u_imageCube, vec3(cosphi*sin(lambda), sin(phi), cosphi*cos(lambda)));', '}'].join('\n'); | |||
// Fragment shader | |||
var fragEquirectangular = ['precision mediump float;', 'uniform float u_aspectRatio;', 'uniform float u_psi;', 'uniform float u_theta;', 'uniform float u_f;', 'uniform float u_h;', 'uniform float u_v;', 'uniform float u_vo;', 'uniform float u_rot;', 'const float PI = 3.14159265358979323846264;', | |||
// Texture | |||
'uniform sampler2D u_image;', | |||
// Coordinates passed in from vertex shader | |||
'varying vec2 v_texCoord;', 'void main() {', | |||
// Map canvas/camera to sphere | |||
'float x = v_texCoord.x * u_aspectRatio;', 'float y = v_texCoord.y;', 'float sinrot = sin(u_rot);', 'float cosrot = cos(u_rot);', 'float rot_x = x * cosrot - y * sinrot;', 'float rot_y = x * sinrot + y * cosrot;', 'float sintheta = sin(u_theta);', 'float costheta = cos(u_theta);', 'float a = u_f * costheta - rot_y * sintheta;', 'float root = sqrt(rot_x * rot_x + a * a);', 'float lambda = atan(rot_x / root, a / root) + u_psi;', 'float phi = atan((rot_y * costheta + u_f * sintheta) / root);', | |||
var fragEquirectangular = fragEquiCubeBase + [ | |||
// Wrap image | |||
'if(lambda > PI)', 'lambda = lambda - PI * 2.0;', 'if(lambda < -PI)', 'lambda = lambda + PI * 2.0;', | |||
'lambda = mod(lambda + PI, PI * 2.0) - PI;', | |||
// Map texture to sphere | |||
'vec2 coord = vec2(lambda / PI, phi / (PI / 2.0));', | |||
// Look up color from texture | |||
// Map from [-1,1] to [0,1] and flip y-axis | |||
'if(coord.x < -u_h || coord.x > u_h || coord.y < -u_v + u_vo || coord.y > u_v + u_vo)', 'gl_FragColor = vec4(0, 0, 0, 1.0);', 'else', 'gl_FragColor = texture2D(u_image, vec2((coord.x + u_h) / (u_h * 2.0), (-coord.y + u_v + u_vo) / (u_v * 2.0)));', '}'].join('\n'); | |||
'if(coord.x < -u_h || coord.x > u_h || coord.y < -u_v + u_vo || coord.y > u_v + u_vo)', 'gl_FragColor = u_backgroundColor;', 'else', 'gl_FragColor = texture2D(u_image, vec2((coord.x + u_h) / (u_h * 2.0), (-coord.y + u_v + u_vo) / (u_v * 2.0)));', '}'].join('\n'); | |||
// Fragment shader | |||
var fragMulti = ['varying mediump vec2 v_texCoord;', 'uniform sampler2D u_sampler;', | |||
@@ -2,6 +2,76 @@ Changelog | |||
========= | |||
Changes in Pannellum 2.3.0 | |||
-------------------------- | |||
New Features: | |||
- Device orientation support for mobile devices | |||
- Event framework for API | |||
- Partial panorama background color can now be set using | |||
`backgroundColor` parameter | |||
- Custom hot spots are now supported as are hot spot click handlers | |||
- Hot spots can now specify target HFOV (`targetHfov` parameter) | |||
- Parameter to hide all controls (`showControls`) | |||
- Parameter to disable mouse zooming (`mouseZoom`) | |||
New API functions: | |||
- Destructor (`destroy`) | |||
- Look at position (`lookAt`) | |||
- Get current scene ID (`getScene`) | |||
- Load scene (`loadScene`) | |||
- Add and remove scenes (`addScene` and `removeScene`) | |||
- Add and remove hot spots (`addHotSpot` and `removeHotSpot`) | |||
- Auto rotate start / stop (`startAutoRotate` and `stopAutoRotate`) | |||
- Retrieve current configuration (`getConfig`) | |||
- Toggle fullscreen (`toggleFullscreen`) | |||
- Get and set north offset (`getNorthOffset` and `setNorthOffset`) | |||
Improvements: | |||
- Pitch and yaw limits are now applied to edge of viewer instead of center | |||
- Panorama extents can now be set using URL parameters | |||
- Individual XMP metadata parameters can now be overridden | |||
- Horizon pitch and roll can now be manually set (was previously only | |||
supported via XMP metadata) | |||
- When auto rotate restarts, the pitch and HFOV now return to their | |||
original values | |||
- API movements can now be animated | |||
- Standalone viewer is more mobile friendly | |||
- Improved touch panning interaction | |||
- Fragments identifiers can now be used for standalone viewer configuration | |||
- Blob URLs are now supported | |||
- Added hot spot debug indicator | |||
- Video.js plugin now accepts a Pannellum configuration | |||
Bugfixes: | |||
- Fixed numerous auto rotate bugs | |||
- Auto rotate speed is now actually in degrees per second | |||
- Long error URLs are now properly wrapped | |||
- Fixed mobile device orientation change bug | |||
- Fixed Safari fullscreen bug | |||
- Fullscreen now works in IE | |||
- Fixed Chrome bug where hot spots appeared above controls | |||
- Scene fades with multires now work properly | |||
- Hot spot target pointing now works when set to zero | |||
- Hot spots without text are now properly handled | |||
- Fixed memory leaks | |||
- Fixed multires tile loading error | |||
- Fixed a few URL handling bugs | |||
- Fixed multires zoom jumping when viewer was resized | |||
- Title and author are now reset when changing scenes | |||
- Mouse handlers now work with Hi-DPI displays | |||
- Minimum and maximum HFOV can now both be set to the same value | |||
Backwards-Incompatible Configuration Parameter Changes: | |||
- The deprecated `tour` parameter was removed; tour JSON configuration files | |||
can be used with the `config` parameter | |||
Changes in Pannellum 2.2.1 | |||
-------------------------- | |||
@@ -0,0 +1,32 @@ | |||
# API Events | |||
## `load` | |||
Fired when a panorama finishes loading. | |||
## `scenechange` | |||
Fired when a scene change is initiated. A `load` event will be fired when the | |||
new scene finishes loading. Passes scene ID string to handler. | |||
## `error` | |||
Fired when an error occured. The error message string is passed to the | |||
event listener. | |||
## `errorcleared` | |||
Fired when an error is cleared. | |||
## `mousedown` | |||
Fired when the mouse button is pressed. Passes `MouseEvent` to handler. | |||
## `mouseup` | |||
Fired when the mouse button is released. Passes `MouseEvent` to handler. |
@@ -5,186 +5,233 @@ | |||
## General options | |||
### `type` | |||
### `type` (string) | |||
This specifies the panorama type. Can be `equirectangular`, `cubemap`, or | |||
`multires`. Defaults to `equirectangular`. | |||
### `title` | |||
### `title` (string) | |||
If set, the value is displayed as the panorama's title. If no title is desired, | |||
don't set this parameter. | |||
### `author` | |||
### `author` (string) | |||
If set, the value is displayed as the panorama's author. If no author is | |||
desired, don't set this parameter. | |||
### `basePath` | |||
### `basePath` (string) | |||
This specifies a base path to load the images from. | |||
### `autoLoad` | |||
### `autoLoad` (boolean) | |||
When set to `true`, the panorama will automatically load. When `false`, the | |||
user needs to click on the load button to load the panorama. Defaults to | |||
`false`. | |||
### `autoRotate` | |||
### `autoRotate` (number) | |||
Setting this parameter causes the panorama to automatically rotate when loaded. | |||
The value specifies the rotation speed in degrees per second. Positive is | |||
counter-clockwise, and negative is clockwise. | |||
### `autoRotateInactivityDelay` | |||
### `autoRotateInactivityDelay` (number) | |||
Sets the delay, in milliseconds, to start automatically rotating the panorama | |||
after user activity ceases. This parameter only has an effect if the | |||
`autoRotate` parameter is set. | |||
### `autoRotateStopDelay` | |||
### `autoRotateStopDelay` (number) | |||
Sets the delay, in milliseconds, to stop automatically rotating the panorama | |||
after it is loaded. This parameter only has an effect if the `autoRotate` | |||
parameter is set. | |||
### `fallback` | |||
### `fallback` (string) | |||
If set, the value is used as a URL for a fallback viewer in case Pannellum is | |||
not supported by the user's device. The user will be given the option to click | |||
a link and visit this URL if Pannellum fails to work. | |||
### `showZoomCtrl` | |||
### `orientationOnByDefault` (boolean) | |||
If set to `true`, device orientation control will be used when the panorama is | |||
loaded, if the device supports it. If false, device orientation control needs | |||
to be activated by pressing a button. Defaults to `false`. | |||
### `showZoomCtrl` (boolean) | |||
If set to `false`, the zoom controls will not be displayed. Defaults to `true`. | |||
### `keyboardZoom` | |||
### `keyboardZoom` (boolean) | |||
If set to `false`, zooming with keyboard will be disabled. Defaults to `true`. | |||
### `showFullscreenCtrl` | |||
### `mouseZoom` (boolean) | |||
If set to `false`, zooming with mouse wheel will be disabled. Defaults to `true`. | |||
### `showFullscreenCtrl` (boolean) | |||
If set to `false`, the fullscreen control will not be displayed. Defaults to | |||
`true`. The fullscreen button will only be displayed if the browser supports | |||
the fullscreen API. | |||
### `yaw` | |||
### `showControls` (boolean) | |||
If set to `false`, no controls are displayed. Defaults to `true`. | |||
### `yaw` (number) | |||
Sets the panorama's starting yaw position in degrees. Defaults to `0`. | |||
### `pitch` | |||
### `pitch` (number) | |||
Sets the panorama's starting pitch position in degrees. Defaults to `0`. | |||
### `hfov` | |||
### `hfov` (number) | |||
Sets the panorama's starting horizontal field of view in degrees. Defaults to | |||
`100`. | |||
### `minYaw` and `maxYaw` | |||
### `minYaw` and `maxYaw` (number) | |||
Sets the minimum / maximum yaw the viewer can be centered at, in degrees. | |||
Defaults to `-360` / `360`, i.e. no limit. | |||
Sets the minimum / maximum yaw the viewer edge can be at, in degrees. | |||
Defaults to `-180` / `180`, i.e. no limit. | |||
### `minPitch` and `maxPitch` | |||
### `minPitch` and `maxPitch` (number) | |||
Sets the minimum / maximum pitch the viewer can be centered at, in degrees. | |||
Defaults to `-85` / `85`. | |||
Sets the minimum / maximum pitch the viewer edge can be at, in degrees. | |||
Defaults to `undefined`, so the viewer center can reach `-90` / `90`. | |||
### `minHfov` and `maxHfov` | |||
### `minHfov` and `maxHfov` (number) | |||
Sets the minimum / maximum horizontal field of view, in degrees, that the | |||
viewer can be set to. Defaults to `50` / `120`. | |||
### `compass` | |||
### `compass` (boolean) | |||
If `true`, a compass is displayed. Defaults to `false`. | |||
If `true`, a compass is displayed. Normally defaults to `false`; defaults to | |||
`true` if heading information is present in Photo Sphere XMP metadata. | |||
### `northOffset` | |||
### `northOffset` (number) | |||
Set the offset, in degrees, of the center of the panorama from North. As this | |||
affects the compass, it only has an effect if `compass` is set to `true`. | |||
### `preview` | |||
### `preview` (string) | |||
Specifies a URL for a preview image to display before the panorama is loaded. | |||
### `hotSpots` | |||
### `horizonPitch` and `horizonRoll` (number) | |||
Specifies pitch / roll of image horizon, in degrees (for correcting | |||
non-leveled panoramas). | |||
### `hotSpots` (array) | |||
This specifies an array of hot spots that can be links to other scenes, | |||
information, or external links. Each array element has the following properties. | |||
#### `pitch` | |||
#### `pitch` (number) | |||
Specifies the pitch portion of the hot spot's location. | |||
Specifies the pitch portion of the hot spot's location, in degrees. | |||
#### `yaw` | |||
#### `yaw` (number) | |||
Specifies the yaw portion of the hot spot's location. | |||
Specifies the yaw portion of the hot spot's location, in degrees. | |||
#### `type` | |||
#### `type` (string) | |||
Specifies the type of the hot spot. Can be `scene` for scene links or `info` | |||
for information hot spots. A tour configuration file is required for `scene` | |||
hot spots. | |||
#### `text` | |||
#### `text` (string) | |||
This specifies the text that is displayed when the user hovers over the hot | |||
spot. | |||
#### `URL` | |||
#### `URL` (string) | |||
If specified for an `info` hot spot, the hot spot links to the specified URL. | |||
Not applicable for `scene` hot spots. | |||
#### `sceneId` | |||
#### `sceneId` (string) | |||
Specifies the ID of the scene to link to for `scene` hot spots. Not applicable | |||
for `info` hot spots. | |||
#### `targetPitch` | |||
#### `targetPitch` (number) | |||
Specifies the pitch of the target scene. | |||
Specifies the pitch of the target scene, in degrees. Can also be set to `same`, | |||
which uses the current pitch of the current scene as the initial pitch of the | |||
target scene. | |||
#### `targetYaw` | |||
#### `targetYaw` (number) | |||
Specifies the yaw of the target scene. | |||
Specifies the yaw of the target scene, in degrees. Can also be set to `same` or | |||
`sameAzimuth`. These settings use the current yaw of the current scene as the | |||
initial yaw of the target scene; `same` uses the current yaw directly, while | |||
`sameAzimuth` takes into account the `northOffset` values of both scenes to | |||
maintain the same direction with regard to north. | |||
#### `targetHfov` | |||
#### `targetHfov` (number) | |||
Specifies the HFOV of the target scene. | |||
Specifies the HFOV of the target scene, in degrees. | |||
### `hotSpotDebug` | |||
#### `cssClass` (string) | |||
If specified, string is used as the CSS class for the hot spot instead of the | |||
default CSS classes. | |||
#### `createTooltipFunc` (function) and `createTooltipArgs` (object) | |||
If `createTooltipFunc` is specified, this function is used to create the hot | |||
spot tooltip DOM instead of the default function. The contents of | |||
`createTooltipArgs` are passed to the function as arguments. | |||
#### `clickHandlerFunc` (function) and `clickHandlerArgs` (object) | |||
If `clickHandlerFunc` is specified, this function is added as an event handler | |||
for the hot spot's `click` event. The event object and the contents of | |||
`clickHandlerArgs` are passed to the function as arguments. | |||
### `hotSpotDebug` (boolean) | |||
When `true`, the mouse pointer's pitch and yaw are logged to the console when | |||
the mouse button is clicked. Defaults to `false`. | |||
### `sceneFadeDuration` | |||
### `sceneFadeDuration` (number) | |||
Specifies the fade duration, in milliseconds, when transitioning between | |||
scenes. Not defined by default. Only applicable for tours. Only works with | |||
@@ -194,38 +241,40 @@ WebGL renderer. | |||
## `equirectangular` specific options | |||
### `panorama` | |||
### `panorama` (string) | |||
Sets the URL to the equirectangular panorama image. This is relative to | |||
`basePath` if it is set, else it is relative to the location of | |||
`pannellum.htm`. An absolute URL can also be used. | |||
### `haov` | |||
### `haov` (number) | |||
Sets the panorama's horizontal angle of view, in degrees. Defaults to `360`. | |||
This is used if the equirectangular image does not cover a full 360 degrees in | |||
the horizontal. | |||
### `vaov` | |||
### `vaov` (number) | |||
Sets the panorama's vertical angle of view, in degrees. Defaults to `180`. This | |||
is used if the equirectangular image does not cover a full 180 degrees in the | |||
vertical. | |||
### `vOffset` | |||
### `vOffset` (number) | |||
Sets the vertical offset of the center of the equirectangular image from the | |||
horizon, in degrees. Defaults to `0`. This is used if `vaov` is less than `180` | |||
and the equirectangular image is not cropped symmetrically. | |||
### `ignoreGPanoXMP` | |||
### `ignoreGPanoXMP` (boolean) | |||
If set to `true`, any embedded Photo Sphere XMP data will be ignored; else, | |||
said data will override any existing settings. Defaults to `false`. | |||
### `backgroundColor` ([number, number, number]) | |||
Specifies an array containing RGB values [0, 1] that sets the background color | |||
shown past the edges of a partial panorama. Defaults to `[0, 0, 0]` (black). | |||
## `cubemap` specific options | |||
@@ -246,14 +295,14 @@ used. | |||
This contains information about the multiresolution panorama in sub-keys. | |||
#### `basePath` | |||
#### `basePath` (string) | |||
This is the base path of the URLs for the multiresolution tiles. It is relative | |||
to the regular `basePath` option if it is defined, else it is relative to the | |||
location of `pannellum.htm`. An absolute URL can also be used. | |||
#### `path` | |||
#### `path` (string) | |||
This is a format string for the location of the multiresolution tiles, relative | |||
to `multiRes.basePath`, which is relative to `basePath`. Format parameters are | |||
@@ -261,7 +310,7 @@ to `multiRes.basePath`, which is relative to `basePath`. Format parameters are | |||
`%y` for the y index. For each tile, `.extension` is appended. | |||
#### `fallbackPath` | |||
#### `fallbackPath` (string) | |||
This is a format string for the location of the fallback tiles for the CSS 3D | |||
transform-based renderer if the WebGL renderer is not supported, relative | |||
@@ -269,22 +318,22 @@ to `multiRes.basePath`, which is relative to `basePath`. The only format | |||
parameter is `%s`, for the cube face. For each face, `.extension` is appended. | |||
#### `extension` | |||
#### `extension` (string) | |||
Specifies the tiles' file extension. Do not include the `.`. | |||
#### `tileResolution` | |||
#### `tileResolution` (number) | |||
This specifies the size in pixels of each image tile. | |||
#### `maxLevel` | |||
#### `maxLevel` (number) | |||
This specifies the maximum zoom level. | |||
#### `cubeResolution` | |||
#### `cubeResolution` (number) | |||
This specifies the size in pixels of the full resolution cube faces the image | |||
tiles were created from. | |||
@@ -295,7 +344,7 @@ tiles were created from. | |||
Currently, only equirectangular dynamic content is supported. | |||
### `dynamic` | |||
### `dynamic` (boolean) | |||
The panorama source is considered dynamic when this is set to `true`. Defaults | |||
to `false`. This should be set to `true` for video. | |||
@@ -14,6 +14,7 @@ Specifies the URL of a JSON configuration file. | |||
## Other parameters | |||
A subset of the JSON configuration file options can be used as URL parameters. | |||
These include `panorama`, `config`, `author`, `title`, `hfov`, `pitch`, `yaw`, | |||
These include `panorama`, `config`, `author`, `title`, `hfov`, `minHfov`, `maxHfov`, | |||
`pitch`, `minPitch`, `maxPitch`, `yaw`, `minYaw`, `maxYaw`, | |||
`haov`, `vaov`, `vOffset`, `autoLoad`, `autoRotate`, `firstScene`, | |||
`ignoreGPanoXMP`, `preview`, and `fallback`. |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../babel-cli/bin/babel.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../babel-cli/bin/babel.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../babel-cli/bin/babel-doctor.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../babel-cli/bin/babel-doctor.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,7 @@ | |||
@IF EXIST "%~dp0\node.exe" ( | |||
"%~dp0\node.exe" "%~dp0\..\babel-cli\bin\babel-doctor.js" %* | |||
) ELSE ( | |||
@SETLOCAL | |||
@SET PATHEXT=%PATHEXT:;.JS;=;% | |||
node "%~dp0\..\babel-cli\bin\babel-doctor.js" %* | |||
) |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../babel-cli/bin/babel-external-helpers.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../babel-cli/bin/babel-external-helpers.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,7 @@ | |||
@IF EXIST "%~dp0\node.exe" ( | |||
"%~dp0\node.exe" "%~dp0\..\babel-cli\bin\babel-external-helpers.js" %* | |||
) ELSE ( | |||
@SETLOCAL | |||
@SET PATHEXT=%PATHEXT:;.JS;=;% | |||
node "%~dp0\..\babel-cli\bin\babel-external-helpers.js" %* | |||
) |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../babel-cli/bin/babel-node.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../babel-cli/bin/babel-node.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,7 @@ | |||
@IF EXIST "%~dp0\node.exe" ( | |||
"%~dp0\node.exe" "%~dp0\..\babel-cli\bin\babel-node.js" %* | |||
) ELSE ( | |||
@SETLOCAL | |||
@SET PATHEXT=%PATHEXT:;.JS;=;% | |||
node "%~dp0\..\babel-cli\bin\babel-node.js" %* | |||
) |
@@ -0,0 +1,7 @@ | |||
@IF EXIST "%~dp0\node.exe" ( | |||
"%~dp0\node.exe" "%~dp0\..\babel-cli\bin\babel.js" %* | |||
) ELSE ( | |||
@SETLOCAL | |||
@SET PATHEXT=%PATHEXT:;.JS;=;% | |||
node "%~dp0\..\babel-cli\bin\babel.js" %* | |||
) |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../babylon/bin/babylon.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../babylon/bin/babylon.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,7 @@ | |||
@IF EXIST "%~dp0\node.exe" ( | |||
"%~dp0\node.exe" "%~dp0\..\babylon\bin\babylon.js" %* | |||
) ELSE ( | |||
@SETLOCAL | |||
@SET PATHEXT=%PATHEXT:;.JS;=;% | |||
node "%~dp0\..\babylon\bin\babylon.js" %* | |||
) |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../jsesc/bin/jsesc" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../jsesc/bin/jsesc" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,7 @@ | |||
@IF EXIST "%~dp0\node.exe" ( | |||
"%~dp0\node.exe" "%~dp0\..\jsesc\bin\jsesc" %* | |||
) ELSE ( | |||
@SETLOCAL | |||
@SET PATHEXT=%PATHEXT:;.JS;=;% | |||
node "%~dp0\..\jsesc\bin\jsesc" %* | |||
) |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../json5/lib/cli.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../json5/lib/cli.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,7 @@ | |||
@IF EXIST "%~dp0\node.exe" ( | |||
"%~dp0\node.exe" "%~dp0\..\json5\lib\cli.js" %* | |||
) ELSE ( | |||
@SETLOCAL | |||
@SET PATHEXT=%PATHEXT:;.JS;=;% | |||
node "%~dp0\..\json5\lib\cli.js" %* | |||
) |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../loose-envify/cli.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../loose-envify/cli.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,7 @@ | |||
@IF EXIST "%~dp0\node.exe" ( | |||
"%~dp0\node.exe" "%~dp0\..\loose-envify\cli.js" %* | |||
) ELSE ( | |||
@SETLOCAL | |||
@SET PATHEXT=%PATHEXT:;.JS;=;% | |||
node "%~dp0\..\loose-envify\cli.js" %* | |||
) |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../mkdirp/bin/cmd.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../mkdirp/bin/cmd.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,7 @@ | |||
@IF EXIST "%~dp0\node.exe" ( | |||
"%~dp0\node.exe" "%~dp0\..\mkdirp\bin\cmd.js" %* | |||
) ELSE ( | |||
@SETLOCAL | |||
@SET PATHEXT=%PATHEXT:;.JS;=;% | |||
node "%~dp0\..\mkdirp\bin\cmd.js" %* | |||
) |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../user-home/cli.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../user-home/cli.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,7 @@ | |||
@IF EXIST "%~dp0\node.exe" ( | |||
"%~dp0\node.exe" "%~dp0\..\user-home\cli.js" %* | |||
) ELSE ( | |||
@SETLOCAL | |||
@SET PATHEXT=%PATHEXT:;.JS;=;% | |||
node "%~dp0\..\user-home\cli.js" %* | |||
) |
@@ -0,0 +1,4 @@ | |||
'use strict'; | |||
module.exports = function () { | |||
return /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; | |||
}; |
@@ -0,0 +1,21 @@ | |||
The MIT License (MIT) | |||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. |
@@ -0,0 +1,121 @@ | |||
{ | |||
"_args": [ | |||
[ | |||
{ | |||
"raw": "ansi-regex@^2.0.0", | |||
"scope": null, | |||
"escapedName": "ansi-regex", | |||
"name": "ansi-regex", | |||
"rawSpec": "^2.0.0", | |||
"spec": ">=2.0.0 <3.0.0", | |||
"type": "range" | |||
}, | |||
"D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\has-ansi" | |||
] | |||
], | |||
"_from": "ansi-regex@>=2.0.0 <3.0.0", | |||
"_id": "ansi-regex@2.0.0", | |||
"_inCache": true, | |||
"_location": "/ansi-regex", | |||
"_nodeVersion": "0.12.5", | |||
"_npmUser": { | |||
"name": "sindresorhus", | |||
"email": "sindresorhus@gmail.com" | |||
}, | |||
"_npmVersion": "2.11.2", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"raw": "ansi-regex@^2.0.0", | |||
"scope": null, | |||
"escapedName": "ansi-regex", | |||
"name": "ansi-regex", | |||
"rawSpec": "^2.0.0", | |||
"spec": ">=2.0.0 <3.0.0", | |||
"type": "range" | |||
}, | |||
"_requiredBy": [ | |||
"/has-ansi", | |||
"/strip-ansi" | |||
], | |||
"_resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz", | |||
"_shasum": "c5061b6e0ef8a81775e50f5d66151bf6bf371107", | |||
"_shrinkwrap": null, | |||
"_spec": "ansi-regex@^2.0.0", | |||
"_where": "D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\has-ansi", | |||
"author": { | |||
"name": "Sindre Sorhus", | |||
"email": "sindresorhus@gmail.com", | |||
"url": "sindresorhus.com" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/sindresorhus/ansi-regex/issues" | |||
}, | |||
"dependencies": {}, | |||
"description": "Regular expression for matching ANSI escape codes", | |||
"devDependencies": { | |||
"mocha": "*" | |||
}, | |||
"directories": {}, | |||
"dist": { | |||
"shasum": "c5061b6e0ef8a81775e50f5d66151bf6bf371107", | |||
"tarball": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz" | |||
}, | |||
"engines": { | |||
"node": ">=0.10.0" | |||
}, | |||
"files": [ | |||
"index.js" | |||
], | |||
"gitHead": "57c3f2941a73079fa8b081e02a522e3d29913e2f", | |||
"homepage": "https://github.com/sindresorhus/ansi-regex", | |||
"keywords": [ | |||
"ansi", | |||
"styles", | |||
"color", | |||
"colour", | |||
"colors", | |||
"terminal", | |||
"console", | |||
"cli", | |||
"string", | |||
"tty", | |||
"escape", | |||
"formatting", | |||
"rgb", | |||
"256", | |||
"shell", | |||
"xterm", | |||
"command-line", | |||
"text", | |||
"regex", | |||
"regexp", | |||
"re", | |||
"match", | |||
"test", | |||
"find", | |||
"pattern" | |||
], | |||
"license": "MIT", | |||
"maintainers": [ | |||
{ | |||
"name": "sindresorhus", | |||
"email": "sindresorhus@gmail.com" | |||
}, | |||
{ | |||
"name": "jbnicolai", | |||
"email": "jappelman@xebia.com" | |||
} | |||
], | |||
"name": "ansi-regex", | |||
"optionalDependencies": {}, | |||
"readme": "ERROR: No README data found!", | |||
"repository": { | |||
"type": "git", | |||
"url": "git+https://github.com/sindresorhus/ansi-regex.git" | |||
}, | |||
"scripts": { | |||
"test": "mocha test/test.js", | |||
"view-supported": "node test/viewCodes.js" | |||
}, | |||
"version": "2.0.0" | |||
} |
@@ -0,0 +1,31 @@ | |||
# ansi-regex [![Build Status](https://travis-ci.org/sindresorhus/ansi-regex.svg?branch=master)](https://travis-ci.org/sindresorhus/ansi-regex) | |||
> Regular expression for matching [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code) | |||
## Install | |||
``` | |||
$ npm install --save ansi-regex | |||
``` | |||
## Usage | |||
```js | |||
var ansiRegex = require('ansi-regex'); | |||
ansiRegex().test('\u001b[4mcake\u001b[0m'); | |||
//=> true | |||
ansiRegex().test('cake'); | |||
//=> false | |||
'\u001b[4mcake\u001b[0m'.match(ansiRegex()); | |||
//=> ['\u001b[4m', '\u001b[0m'] | |||
``` | |||
## License | |||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
@@ -0,0 +1,65 @@ | |||
'use strict'; | |||
function assembleStyles () { | |||
var styles = { | |||
modifiers: { | |||
reset: [0, 0], | |||
bold: [1, 22], // 21 isn't widely supported and 22 does the same thing | |||
dim: [2, 22], | |||
italic: [3, 23], | |||
underline: [4, 24], | |||
inverse: [7, 27], | |||
hidden: [8, 28], | |||
strikethrough: [9, 29] | |||
}, | |||
colors: { | |||
black: [30, 39], | |||
red: [31, 39], | |||
green: [32, 39], | |||
yellow: [33, 39], | |||
blue: [34, 39], | |||
magenta: [35, 39], | |||
cyan: [36, 39], | |||
white: [37, 39], | |||
gray: [90, 39] | |||
}, | |||
bgColors: { | |||
bgBlack: [40, 49], | |||
bgRed: [41, 49], | |||
bgGreen: [42, 49], | |||
bgYellow: [43, 49], | |||
bgBlue: [44, 49], | |||
bgMagenta: [45, 49], | |||
bgCyan: [46, 49], | |||
bgWhite: [47, 49] | |||
} | |||
}; | |||
// fix humans | |||
styles.colors.grey = styles.colors.gray; | |||
Object.keys(styles).forEach(function (groupName) { | |||
var group = styles[groupName]; | |||
Object.keys(group).forEach(function (styleName) { | |||
var style = group[styleName]; | |||
styles[styleName] = group[styleName] = { | |||
open: '\u001b[' + style[0] + 'm', | |||
close: '\u001b[' + style[1] + 'm' | |||
}; | |||
}); | |||
Object.defineProperty(styles, groupName, { | |||
value: group, | |||
enumerable: false | |||
}); | |||
}); | |||
return styles; | |||
} | |||
Object.defineProperty(module, 'exports', { | |||
enumerable: true, | |||
get: assembleStyles | |||
}); |
@@ -0,0 +1,21 @@ | |||
The MIT License (MIT) | |||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. |
@@ -0,0 +1,114 @@ | |||
{ | |||
"_args": [ | |||
[ | |||
{ | |||
"raw": "ansi-styles@^2.2.1", | |||
"scope": null, | |||
"escapedName": "ansi-styles", | |||
"name": "ansi-styles", | |||
"rawSpec": "^2.2.1", | |||
"spec": ">=2.2.1 <3.0.0", | |||
"type": "range" | |||
}, | |||
"D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\chalk" | |||
] | |||
], | |||
"_from": "ansi-styles@>=2.2.1 <3.0.0", | |||
"_id": "ansi-styles@2.2.1", | |||
"_inCache": true, | |||
"_location": "/ansi-styles", | |||
"_nodeVersion": "4.3.0", | |||
"_npmOperationalInternal": { | |||
"host": "packages-12-west.internal.npmjs.com", | |||
"tmp": "tmp/ansi-styles-2.2.1.tgz_1459197317833_0.9694824463222176" | |||
}, | |||
"_npmUser": { | |||
"name": "sindresorhus", | |||
"email": "sindresorhus@gmail.com" | |||
}, | |||
"_npmVersion": "3.8.3", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"raw": "ansi-styles@^2.2.1", | |||
"scope": null, | |||
"escapedName": "ansi-styles", | |||
"name": "ansi-styles", | |||
"rawSpec": "^2.2.1", | |||
"spec": ">=2.2.1 <3.0.0", | |||
"type": "range" | |||
}, | |||
"_requiredBy": [ | |||
"/chalk" | |||
], | |||
"_resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", | |||
"_shasum": "b432dd3358b634cf75e1e4664368240533c1ddbe", | |||
"_shrinkwrap": null, | |||
"_spec": "ansi-styles@^2.2.1", | |||
"_where": "D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\chalk", | |||
"author": { | |||
"name": "Sindre Sorhus", | |||
"email": "sindresorhus@gmail.com", | |||
"url": "sindresorhus.com" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/chalk/ansi-styles/issues" | |||
}, | |||
"dependencies": {}, | |||
"description": "ANSI escape codes for styling strings in the terminal", | |||
"devDependencies": { | |||
"mocha": "*" | |||
}, | |||
"directories": {}, | |||
"dist": { | |||
"shasum": "b432dd3358b634cf75e1e4664368240533c1ddbe", | |||
"tarball": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz" | |||
}, | |||
"engines": { | |||
"node": ">=0.10.0" | |||
}, | |||
"files": [ | |||
"index.js" | |||
], | |||
"gitHead": "95c59b23be760108b6530ca1c89477c21b258032", | |||
"homepage": "https://github.com/chalk/ansi-styles#readme", | |||
"keywords": [ | |||
"ansi", | |||
"styles", | |||
"color", | |||
"colour", | |||
"colors", | |||
"terminal", | |||
"console", | |||
"cli", | |||
"string", | |||
"tty", | |||
"escape", | |||
"formatting", | |||
"rgb", | |||
"256", | |||
"shell", | |||
"xterm", | |||
"log", | |||
"logging", | |||
"command-line", | |||
"text" | |||
], | |||
"license": "MIT", | |||
"maintainers": [ | |||
{ | |||
"name": "sindresorhus", | |||
"email": "sindresorhus@gmail.com" | |||
} | |||
], | |||
"name": "ansi-styles", | |||
"optionalDependencies": {}, | |||
"readme": "ERROR: No README data found!", | |||
"repository": { | |||
"type": "git", | |||
"url": "git+https://github.com/chalk/ansi-styles.git" | |||
}, | |||
"scripts": { | |||
"test": "mocha" | |||
}, | |||
"version": "2.2.1" | |||
} |
@@ -0,0 +1,86 @@ | |||
# ansi-styles [![Build Status](https://travis-ci.org/chalk/ansi-styles.svg?branch=master)](https://travis-ci.org/chalk/ansi-styles) | |||
> [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) for styling strings in the terminal | |||
You probably want the higher-level [chalk](https://github.com/chalk/chalk) module for styling your strings. | |||
![](screenshot.png) | |||
## Install | |||
``` | |||
$ npm install --save ansi-styles | |||
``` | |||
## Usage | |||
```js | |||
var ansi = require('ansi-styles'); | |||
console.log(ansi.green.open + 'Hello world!' + ansi.green.close); | |||
``` | |||
## API | |||
Each style has an `open` and `close` property. | |||
## Styles | |||
### Modifiers | |||
- `reset` | |||
- `bold` | |||
- `dim` | |||
- `italic` *(not widely supported)* | |||
- `underline` | |||
- `inverse` | |||
- `hidden` | |||
- `strikethrough` *(not widely supported)* | |||
### Colors | |||
- `black` | |||
- `red` | |||
- `green` | |||
- `yellow` | |||
- `blue` | |||
- `magenta` | |||
- `cyan` | |||
- `white` | |||
- `gray` | |||
### Background colors | |||
- `bgBlack` | |||
- `bgRed` | |||
- `bgGreen` | |||
- `bgYellow` | |||
- `bgBlue` | |||
- `bgMagenta` | |||
- `bgCyan` | |||
- `bgWhite` | |||
## Advanced usage | |||
By default you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module. | |||
- `ansi.modifiers` | |||
- `ansi.colors` | |||
- `ansi.bgColors` | |||
###### Example | |||
```js | |||
console.log(ansi.colors.green.open); | |||
``` | |||
## License | |||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
@@ -0,0 +1,15 @@ | |||
The ISC License | |||
Copyright (c) 2014 Elan Shanker | |||
Permission to use, copy, modify, and/or distribute this software for any | |||
purpose with or without fee is hereby granted, provided that the above | |||
copyright notice and this permission notice appear in all copies. | |||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | |||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
@@ -0,0 +1,91 @@ | |||
anymatch [![Build Status](https://travis-ci.org/es128/anymatch.svg?branch=master)](https://travis-ci.org/es128/anymatch) [![Coverage Status](https://img.shields.io/coveralls/es128/anymatch.svg?branch=master)](https://coveralls.io/r/es128/anymatch?branch=master) | |||
====== | |||
Javascript module to match a string against a regular expression, glob, string, | |||
or function that takes the string as an argument and returns a truthy or falsy | |||
value. The matcher can also be an array of any or all of these. Useful for | |||
allowing a very flexible user-defined config to define things like file paths. | |||
[![NPM](https://nodei.co/npm/anymatch.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/anymatch/) | |||
[![NPM](https://nodei.co/npm-dl/anymatch.png?height=3&months=9)](https://nodei.co/npm-dl/anymatch/) | |||
Usage | |||
----- | |||
```sh | |||
npm install anymatch --save | |||
``` | |||
#### anymatch (matchers, testString, [returnIndex], [startIndex], [endIndex]) | |||
* __matchers__: (_Array|String|RegExp|Function_) | |||
String to be directly matched, string with glob patterns, regular expression | |||
test, function that takes the testString as an argument and returns a truthy | |||
value if it should be matched, or an array of any number and mix of these types. | |||
* __testString__: (_String|Array_) The string to test against the matchers. If | |||
passed as an array, the first element of the array will be used as the | |||
`testString` for non-function matchers, while the entire array will be applied | |||
as the arguments for function matchers. | |||
* __returnIndex__: (_Boolean [optional]_) If true, return the array index of | |||
the first matcher that that testString matched, or -1 if no match, instead of a | |||
boolean result. | |||
* __startIndex, endIndex__: (_Integer [optional]_) Can be used to define a | |||
subset out of the array of provided matchers to test against. Can be useful | |||
with bound matcher functions (see below). When used with `returnIndex = true` | |||
preserves original indexing. Behaves the same as `Array.prototype.slice` (i.e. | |||
includes array members up to, but not including endIndex). | |||
```js | |||
var anymatch = require('anymatch'); | |||
var matchers = [ | |||
'path/to/file.js', | |||
'path/anyjs/**/*.js', | |||
/foo.js$/, | |||
function (string) { | |||
return string.indexOf('bar') !== -1 && string.length > 10 | |||
} | |||
]; | |||
anymatch(matchers, 'path/to/file.js'); // true | |||
anymatch(matchers, 'path/anyjs/baz.js'); // true | |||
anymatch(matchers, 'path/to/foo.js'); // true | |||
anymatch(matchers, 'path/to/bar.js'); // true | |||
anymatch(matchers, 'bar.js'); // false | |||
// returnIndex = true | |||
anymatch(matchers, 'foo.js', true); // 2 | |||
anymatch(matchers, 'path/anyjs/foo.js', true); // 1 | |||
// skip matchers | |||
anymatch(matchers, 'path/to/file.js', false, 1); // false | |||
anymatch(matchers, 'path/anyjs/foo.js', true, 2, 3); // 2 | |||
anymatch(matchers, 'path/to/bar.js', true, 0, 3); // -1 | |||
``` | |||
#### anymatch (matchers) | |||
You can also pass in only your matcher(s) to get a curried function that has | |||
already been bound to the provided matching criteria. This can be used as an | |||
`Array.prototype.filter` callback. | |||
```js | |||
var matcher = anymatch(matchers); | |||
matcher('path/to/file.js'); // true | |||
matcher('path/anyjs/baz.js', true); // 1 | |||
matcher('path/anyjs/baz.js', true, 2); // -1 | |||
['foo.js', 'bar.js'].filter(matcher); // ['foo.js'] | |||
``` | |||
Change Log | |||
---------- | |||
[See release notes page on GitHub](https://github.com/es128/anymatch/releases) | |||
NOTE: As of v1.2.0, anymatch uses [micromatch](https://github.com/jonschlinkert/micromatch) | |||
for glob pattern matching. The glob matching behavior should be functionally | |||
equivalent to the commonly used [minimatch](https://github.com/isaacs/minimatch) | |||
library (aside from some fixed bugs and greater performance), so a major | |||
version bump wasn't merited. Issues with glob pattern matching should be | |||
reported directly to the [micromatch issue tracker](https://github.com/jonschlinkert/micromatch/issues). | |||
License | |||
------- | |||
[ISC](https://raw.github.com/es128/anymatch/master/LICENSE) |
@@ -0,0 +1,64 @@ | |||
'use strict'; | |||
var arrify = require('arrify'); | |||
var micromatch = require('micromatch'); | |||
var path = require('path'); | |||
var anymatch = function(criteria, value, returnIndex, startIndex, endIndex) { | |||
criteria = arrify(criteria); | |||
value = arrify(value); | |||
if (arguments.length === 1) { | |||
return anymatch.bind(null, criteria.map(function(criterion) { | |||
return typeof criterion === 'string' && criterion[0] !== '!' ? | |||
micromatch.matcher(criterion) : criterion; | |||
})); | |||
} | |||
startIndex = startIndex || 0; | |||
var string = value[0]; | |||
var altString; | |||
var matched = false; | |||
var matchIndex = -1; | |||
function testCriteria (criterion, index) { | |||
var result; | |||
switch (toString.call(criterion)) { | |||
case '[object String]': | |||
result = string === criterion || altString && altString === criterion; | |||
result = result || micromatch.isMatch(string, criterion); | |||
break; | |||
case '[object RegExp]': | |||
result = criterion.test(string) || altString && criterion.test(altString); | |||
break; | |||
case '[object Function]': | |||
result = criterion.apply(null, value); | |||
break; | |||
default: | |||
result = false; | |||
} | |||
if (result) { | |||
matchIndex = index + startIndex; | |||
} | |||
return result; | |||
} | |||
var crit = criteria; | |||
var negGlobs = crit.reduce(function(arr, criterion, index) { | |||
if (typeof criterion === 'string' && criterion[0] === '!') { | |||
if (crit === criteria) { | |||
// make a copy before modifying | |||
crit = crit.slice(); | |||
} | |||
crit[index] = null; | |||
arr.push(criterion.substr(1)); | |||
} | |||
return arr; | |||
}, []); | |||
if (!negGlobs.length || !micromatch.any(string, negGlobs)) { | |||
if (path.sep === '\\' && typeof string === 'string') { | |||
altString = string.split('\\').join('/'); | |||
altString = altString === string ? null : altString; | |||
} | |||
matched = crit.slice(startIndex, endIndex).some(testCriteria); | |||
} | |||
return returnIndex === true ? matchIndex : matched; | |||
}; | |||
module.exports = anymatch; |
@@ -0,0 +1,103 @@ | |||
{ | |||
"_args": [ | |||
[ | |||
{ | |||
"raw": "anymatch@^1.3.0", | |||
"scope": null, | |||
"escapedName": "anymatch", | |||
"name": "anymatch", | |||
"rawSpec": "^1.3.0", | |||
"spec": ">=1.3.0 <2.0.0", | |||
"type": "range" | |||
}, | |||
"D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\chokidar" | |||
] | |||
], | |||
"_from": "anymatch@>=1.3.0 <2.0.0", | |||
"_id": "anymatch@1.3.0", | |||
"_inCache": true, | |||
"_location": "/anymatch", | |||
"_nodeVersion": "1.6.2", | |||
"_npmUser": { | |||
"name": "es128", | |||
"email": "elan.shanker+npm@gmail.com" | |||
}, | |||
"_npmVersion": "2.7.3", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"raw": "anymatch@^1.3.0", | |||
"scope": null, | |||
"escapedName": "anymatch", | |||
"name": "anymatch", | |||
"rawSpec": "^1.3.0", | |||
"spec": ">=1.3.0 <2.0.0", | |||
"type": "range" | |||
}, | |||
"_requiredBy": [ | |||
"/chokidar" | |||
], | |||
"_resolved": "https://registry.npmjs.org/anymatch/-/anymatch-1.3.0.tgz", | |||
"_shasum": "a3e52fa39168c825ff57b0248126ce5a8ff95507", | |||
"_shrinkwrap": null, | |||
"_spec": "anymatch@^1.3.0", | |||
"_where": "D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\chokidar", | |||
"author": { | |||
"name": "Elan Shanker", | |||
"url": "http://github.com/es128" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/es128/anymatch/issues" | |||
}, | |||
"dependencies": { | |||
"arrify": "^1.0.0", | |||
"micromatch": "^2.1.5" | |||
}, | |||
"description": "Matches strings against configurable strings, globs, regular expressions, and/or functions", | |||
"devDependencies": { | |||
"coveralls": "^2.11.2", | |||
"istanbul": "^0.3.13", | |||
"mocha": "^2.2.4" | |||
}, | |||
"directories": {}, | |||
"dist": { | |||
"shasum": "a3e52fa39168c825ff57b0248126ce5a8ff95507", | |||
"tarball": "https://registry.npmjs.org/anymatch/-/anymatch-1.3.0.tgz" | |||
}, | |||
"files": [ | |||
"index.js" | |||
], | |||
"gitHead": "253d2ad42f644ed18557f561312a7f8426daca84", | |||
"homepage": "https://github.com/es128/anymatch", | |||
"keywords": [ | |||
"match", | |||
"any", | |||
"string", | |||
"file", | |||
"fs", | |||
"list", | |||
"glob", | |||
"regex", | |||
"regexp", | |||
"regular", | |||
"expression", | |||
"function" | |||
], | |||
"license": "ISC", | |||
"maintainers": [ | |||
{ | |||
"name": "es128", | |||
"email": "elan.shanker+npm@gmail.com" | |||
} | |||
], | |||
"name": "anymatch", | |||
"optionalDependencies": {}, | |||
"readme": "ERROR: No README data found!", | |||
"repository": { | |||
"type": "git", | |||
"url": "git+https://github.com/es128/anymatch.git" | |||
}, | |||
"scripts": { | |||
"test": "istanbul cover _mocha && cat ./coverage/lcov.info | coveralls" | |||
}, | |||
"version": "1.3.0" | |||
} |
@@ -0,0 +1,21 @@ | |||
The MIT License (MIT) | |||
Copyright (c) 2014-2015, Jon Schlinkert. | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. |
@@ -0,0 +1,74 @@ | |||
# arr-diff [![NPM version](https://img.shields.io/npm/v/arr-diff.svg)](https://www.npmjs.com/package/arr-diff) [![Build Status](https://img.shields.io/travis/jonschlinkert/base.svg)](https://travis-ci.org/jonschlinkert/base) | |||
> Returns an array with only the unique values from the first array, by excluding all values from additional arrays using strict equality for comparisons. | |||
## Install | |||
Install with [npm](https://www.npmjs.com/) | |||
```sh | |||
$ npm i arr-diff --save | |||
``` | |||
Install with [bower](http://bower.io/) | |||
```sh | |||
$ bower install arr-diff --save | |||
``` | |||
## API | |||
### [diff](index.js#L33) | |||
Return the difference between the first array and additional arrays. | |||
**Params** | |||
* `a` **{Array}** | |||
* `b` **{Array}** | |||
* `returns` **{Array}** | |||
**Example** | |||
```js | |||
var diff = require('arr-diff'); | |||
var a = ['a', 'b', 'c', 'd']; | |||
var b = ['b', 'c']; | |||
console.log(diff(a, b)) | |||
//=> ['a', 'd'] | |||
``` | |||
## Related projects | |||
* [arr-flatten](https://www.npmjs.com/package/arr-flatten): Recursively flatten an array or arrays. This is the fastest implementation of array flatten. | [homepage](https://github.com/jonschlinkert/arr-flatten) | |||
* [array-filter](https://www.npmjs.com/package/array-filter): Array#filter for older browsers. | [homepage](https://github.com/juliangruber/array-filter) | |||
* [array-intersection](https://www.npmjs.com/package/array-intersection): Return an array with the unique values present in _all_ given arrays using strict equality… [more](https://www.npmjs.com/package/array-intersection) | [homepage](https://github.com/jonschlinkert/array-intersection) | |||
## Running tests | |||
Install dev dependencies: | |||
```sh | |||
$ npm i -d && npm test | |||
``` | |||
## Contributing | |||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/arr-diff/issues/new). | |||
## Author | |||
**Jon Schlinkert** | |||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | |||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | |||
## License | |||
Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert) | |||
Released under the MIT license. | |||
*** | |||
_This file was generated by [verb](https://github.com/verbose/verb) on Sat Dec 05 2015 23:24:53 GMT-0500 (EST)._ |
@@ -0,0 +1,58 @@ | |||
/*! | |||
* arr-diff <https://github.com/jonschlinkert/arr-diff> | |||
* | |||
* Copyright (c) 2014 Jon Schlinkert, contributors. | |||
* Licensed under the MIT License | |||
*/ | |||
'use strict'; | |||
var flatten = require('arr-flatten'); | |||
var slice = [].slice; | |||
/** | |||
* Return the difference between the first array and | |||
* additional arrays. | |||
* | |||
* ```js | |||
* var diff = require('{%= name %}'); | |||
* | |||
* var a = ['a', 'b', 'c', 'd']; | |||
* var b = ['b', 'c']; | |||
* | |||
* console.log(diff(a, b)) | |||
* //=> ['a', 'd'] | |||
* ``` | |||
* | |||
* @param {Array} `a` | |||
* @param {Array} `b` | |||
* @return {Array} | |||
* @api public | |||
*/ | |||
function diff(arr, arrays) { | |||
var argsLen = arguments.length; | |||
var len = arr.length, i = -1; | |||
var res = [], arrays; | |||
if (argsLen === 1) { | |||
return arr; | |||
} | |||
if (argsLen > 2) { | |||
arrays = flatten(slice.call(arguments, 1)); | |||
} | |||
while (++i < len) { | |||
if (!~arrays.indexOf(arr[i])) { | |||
res.push(arr[i]); | |||
} | |||
} | |||
return res; | |||
} | |||
/** | |||
* Expose `diff` | |||
*/ | |||
module.exports = diff; |
@@ -0,0 +1,119 @@ | |||
{ | |||
"_args": [ | |||
[ | |||
{ | |||
"raw": "arr-diff@^2.0.0", | |||
"scope": null, | |||
"escapedName": "arr-diff", | |||
"name": "arr-diff", | |||
"rawSpec": "^2.0.0", | |||
"spec": ">=2.0.0 <3.0.0", | |||
"type": "range" | |||
}, | |||
"D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\micromatch" | |||
] | |||
], | |||
"_from": "arr-diff@>=2.0.0 <3.0.0", | |||
"_id": "arr-diff@2.0.0", | |||
"_inCache": true, | |||
"_location": "/arr-diff", | |||
"_nodeVersion": "5.0.0", | |||
"_npmUser": { | |||
"name": "jonschlinkert", | |||
"email": "github@sellside.com" | |||
}, | |||
"_npmVersion": "3.3.6", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"raw": "arr-diff@^2.0.0", | |||
"scope": null, | |||
"escapedName": "arr-diff", | |||
"name": "arr-diff", | |||
"rawSpec": "^2.0.0", | |||
"spec": ">=2.0.0 <3.0.0", | |||
"type": "range" | |||
}, | |||
"_requiredBy": [ | |||
"/micromatch" | |||
], | |||
"_resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz", | |||
"_shasum": "8f3b827f955a8bd669697e4a4256ac3ceae356cf", | |||
"_shrinkwrap": null, | |||
"_spec": "arr-diff@^2.0.0", | |||
"_where": "D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\micromatch", | |||
"author": { | |||
"name": "Jon Schlinkert", | |||
"url": "https://github.com/jonschlinkert" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/jonschlinkert/arr-diff/issues" | |||
}, | |||
"dependencies": { | |||
"arr-flatten": "^1.0.1" | |||
}, | |||
"description": "Returns an array with only the unique values from the first array, by excluding all values from additional arrays using strict equality for comparisons.", | |||
"devDependencies": { | |||
"array-differ": "^1.0.0", | |||
"array-slice": "^0.2.3", | |||
"benchmarked": "^0.1.4", | |||
"chalk": "^1.1.1", | |||
"mocha": "*", | |||
"should": "*" | |||
}, | |||
"directories": {}, | |||
"dist": { | |||
"shasum": "8f3b827f955a8bd669697e4a4256ac3ceae356cf", | |||
"tarball": "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz" | |||
}, | |||
"engines": { | |||
"node": ">=0.10.0" | |||
}, | |||
"files": [ | |||
"index.js" | |||
], | |||
"gitHead": "b89f54eb88ca51afd0e0ea6be9a4a63e5ccecf27", | |||
"homepage": "https://github.com/jonschlinkert/arr-diff", | |||
"keywords": [ | |||
"arr", | |||
"array", | |||
"diff", | |||
"differ", | |||
"difference" | |||
], | |||
"license": "MIT", | |||
"main": "index.js", | |||
"maintainers": [ | |||
{ | |||
"name": "doowb", | |||
"email": "brian.woodward@gmail.com" | |||
}, | |||
{ | |||
"name": "jonschlinkert", | |||
"email": "github@sellside.com" | |||
}, | |||
{ | |||
"name": "paulmillr", | |||
"email": "paul@paulmillr.com" | |||
} | |||
], | |||
"name": "arr-diff", | |||
"optionalDependencies": {}, | |||
"readme": "ERROR: No README data found!", | |||
"repository": { | |||
"type": "git", | |||
"url": "git+https://github.com/jonschlinkert/arr-diff.git" | |||
}, | |||
"scripts": { | |||
"test": "mocha" | |||
}, | |||
"verb": { | |||
"related": { | |||
"list": [ | |||
"arr-flatten", | |||
"array-filter", | |||
"array-intersection" | |||
] | |||
} | |||
}, | |||
"version": "2.0.0" | |||
} |
@@ -0,0 +1,21 @@ | |||
The MIT License (MIT) | |||
Copyright (c) 2014-2015, Jon Schlinkert. | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. |
@@ -0,0 +1,73 @@ | |||
# arr-flatten [![NPM version](https://badge.fury.io/js/arr-flatten.svg)](http://badge.fury.io/js/arr-flatten) [![Build Status](https://travis-ci.org/jonschlinkert/arr-flatten.svg)](https://travis-ci.org/jonschlinkert/arr-flatten) | |||
> Recursively flatten an array or arrays. This is the fastest implementation of array flatten. | |||
Why another flatten utility? I wanted the fastest implementation I could find, with implementation choices that should work for 95% of use cases, but no cruft to cover the other 5%. | |||
## Run benchmarks | |||
```bash | |||
npm run benchmarks | |||
``` | |||
Benchmark results comparing this library to [array-flatten]: | |||
```bash | |||
#1: large.js | |||
arr-flatten.js x 487,030 ops/sec ±0.67% (92 runs sampled) | |||
array-flatten.js x 347,020 ops/sec ±0.57% (98 runs sampled) | |||
#2: medium.js | |||
arr-flatten.js x 1,914,516 ops/sec ±0.76% (94 runs sampled) | |||
array-flatten.js x 1,391,661 ops/sec ±0.63% (96 runs sampled) | |||
#3: small.js | |||
arr-flatten.js x 5,158,980 ops/sec ±0.85% (94 runs sampled) | |||
array-flatten.js x 3,683,173 ops/sec ±0.79% (97 runs sampled) | |||
``` | |||
## Run tests | |||
Install dev dependencies: | |||
```bash | |||
npm i -d && npm test | |||
``` | |||
## Install with [npm](npmjs.org) | |||
```bash | |||
npm i arr-flatten --save | |||
``` | |||
### Install with [bower](https://github.com/bower/bower) | |||
```bash | |||
bower install arr-flatten --save | |||
``` | |||
## Usage | |||
```js | |||
var flatten = require('arr-flatten'); | |||
flatten(['a', ['b', ['c']], 'd', ['e']]); | |||
//=> ['a', 'b', 'c', 'd', 'e'] | |||
``` | |||
## Author | |||
**Jon Schlinkert** | |||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | |||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | |||
## License | |||
Copyright (c) 2014-2015 Jon Schlinkert | |||
Released under the MIT license | |||
*** | |||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 11, 2015._ | |||
[array-flatten]: https://github.com/blakeembrey/array-flatten |
@@ -0,0 +1,27 @@ | |||
/*! | |||
* arr-flatten <https://github.com/jonschlinkert/arr-flatten> | |||
* | |||
* Copyright (c) 2014-2015, Jon Schlinkert. | |||
* Licensed under the MIT License. | |||
*/ | |||
'use strict'; | |||
module.exports = function flatten(arr) { | |||
return flat(arr, []); | |||
}; | |||
function flat(arr, res) { | |||
var len = arr.length; | |||
var i = -1; | |||
while (len--) { | |||
var cur = arr[++i]; | |||
if (Array.isArray(cur)) { | |||
flat(cur, res); | |||
} else { | |||
res.push(cur); | |||
} | |||
} | |||
return res; | |||
} |
@@ -0,0 +1,108 @@ | |||
{ | |||
"_args": [ | |||
[ | |||
{ | |||
"raw": "arr-flatten@^1.0.1", | |||
"scope": null, | |||
"escapedName": "arr-flatten", | |||
"name": "arr-flatten", | |||
"rawSpec": "^1.0.1", | |||
"spec": ">=1.0.1 <2.0.0", | |||
"type": "range" | |||
}, | |||
"D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\arr-diff" | |||
] | |||
], | |||
"_from": "arr-flatten@>=1.0.1 <2.0.0", | |||
"_id": "arr-flatten@1.0.1", | |||
"_inCache": true, | |||
"_location": "/arr-flatten", | |||
"_nodeVersion": "0.12.0", | |||
"_npmUser": { | |||
"name": "jonschlinkert", | |||
"email": "github@sellside.com" | |||
}, | |||
"_npmVersion": "2.5.1", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"raw": "arr-flatten@^1.0.1", | |||
"scope": null, | |||
"escapedName": "arr-flatten", | |||
"name": "arr-flatten", | |||
"rawSpec": "^1.0.1", | |||
"spec": ">=1.0.1 <2.0.0", | |||
"type": "range" | |||
}, | |||
"_requiredBy": [ | |||
"/arr-diff" | |||
], | |||
"_resolved": "https://registry.npmjs.org/arr-flatten/-/arr-flatten-1.0.1.tgz", | |||
"_shasum": "e5ffe54d45e19f32f216e91eb99c8ce892bb604b", | |||
"_shrinkwrap": null, | |||
"_spec": "arr-flatten@^1.0.1", | |||
"_where": "D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\arr-diff", | |||
"author": { | |||
"name": "Jon Schlinkert", | |||
"url": "https://github.com/jonschlinkert" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/jonschlinkert/arr-flatten/issues" | |||
}, | |||
"dependencies": {}, | |||
"description": "Recursively flatten an array or arrays. This is the fastest implementation of array flatten.", | |||
"devDependencies": { | |||
"array-flatten": "^1.0.2", | |||
"array-slice": "^0.2.2", | |||
"benchmarked": "^0.1.3", | |||
"chalk": "^0.5.1", | |||
"glob": "^4.3.5", | |||
"kind-of": "^1.0.0" | |||
}, | |||
"directories": {}, | |||
"dist": { | |||
"shasum": "e5ffe54d45e19f32f216e91eb99c8ce892bb604b", | |||
"tarball": "https://registry.npmjs.org/arr-flatten/-/arr-flatten-1.0.1.tgz" | |||
}, | |||
"engines": { | |||
"node": ">=0.10.0" | |||
}, | |||
"files": [ | |||
"index.js" | |||
], | |||
"gitHead": "7b3706eaa0093d8f5ba65af8ed590b6fcb3fe7cf", | |||
"homepage": "https://github.com/jonschlinkert/arr-flatten", | |||
"keywords": [ | |||
"arr", | |||
"array", | |||
"elements", | |||
"flat", | |||
"flatten", | |||
"nested", | |||
"recurse", | |||
"recursive", | |||
"recursively" | |||
], | |||
"license": { | |||
"type": "MIT", | |||
"url": "https://github.com/jonschlinkert/arr-flatten/blob/master/LICENSE" | |||
}, | |||
"main": "index.js", | |||
"maintainers": [ | |||
{ | |||
"name": "jonschlinkert", | |||
"email": "github@sellside.com" | |||
} | |||
], | |||
"name": "arr-flatten", | |||
"optionalDependencies": {}, | |||
"readme": "ERROR: No README data found!", | |||
"repository": { | |||
"type": "git", | |||
"url": "git://github.com/jonschlinkert/arr-flatten.git" | |||
}, | |||
"scripts": { | |||
"benchmarks": "node benchmark", | |||
"test": "mocha" | |||
}, | |||
"version": "1.0.1" | |||
} |
@@ -0,0 +1,21 @@ | |||
The MIT License (MIT) | |||
Copyright (c) 2014-2015, Jon Schlinkert. | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. |
@@ -0,0 +1,51 @@ | |||
# array-unique [![NPM version](https://badge.fury.io/js/array-unique.svg)](http://badge.fury.io/js/array-unique) [![Build Status](https://travis-ci.org/jonschlinkert/array-unique.svg)](https://travis-ci.org/jonschlinkert/array-unique) | |||
> Return an array free of duplicate values. Fastest ES5 implementation. | |||
## Install with [npm](npmjs.org) | |||
```bash | |||
npm i array-unique --save | |||
``` | |||
## Usage | |||
```js | |||
var unique = require('array-unique'); | |||
unique(['a', 'b', 'c', 'c']); | |||
//=> ['a', 'b', 'c'] | |||
``` | |||
## Related | |||
* [arr-diff](https://github.com/jonschlinkert/arr-diff): Returns an array with only the unique values from the first array, by excluding all values from additional arrays using strict equality for comparisons. | |||
* [arr-union](https://github.com/jonschlinkert/arr-union): Returns an array of unique values using strict equality for comparisons. | |||
* [arr-flatten](https://github.com/jonschlinkert/arr-flatten): Recursively flatten an array or arrays. This is the fastest implementation of array flatten. | |||
* [arr-reduce](https://github.com/jonschlinkert/arr-reduce): Fast array reduce that also loops over sparse elements. | |||
* [arr-map](https://github.com/jonschlinkert/arr-map): Faster, node.js focused alternative to JavaScript's native array map. | |||
* [arr-pluck](https://github.com/jonschlinkert/arr-pluck): Retrieves the value of a specified property from all elements in the collection. | |||
## Run tests | |||
Install dev dependencies. | |||
```bash | |||
npm i -d && npm test | |||
``` | |||
## Contributing | |||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/array-unique/issues) | |||
## Author | |||
**Jon Schlinkert** | |||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | |||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | |||
## License | |||
Copyright (c) 2015 Jon Schlinkert | |||
Released under the MIT license | |||
*** | |||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 24, 2015._ |
@@ -0,0 +1,28 @@ | |||
/*! | |||
* array-unique <https://github.com/jonschlinkert/array-unique> | |||
* | |||
* Copyright (c) 2014-2015, Jon Schlinkert. | |||
* Licensed under the MIT License. | |||
*/ | |||
'use strict'; | |||
module.exports = function unique(arr) { | |||
if (!Array.isArray(arr)) { | |||
throw new TypeError('array-unique expects an array.'); | |||
} | |||
var len = arr.length; | |||
var i = -1; | |||
while (i++ < len) { | |||
var j = i + 1; | |||
for (; j < arr.length; ++j) { | |||
if (arr[i] === arr[j]) { | |||
arr.splice(j--, 1); | |||
} | |||
} | |||
} | |||
return arr; | |||
}; |
@@ -0,0 +1,94 @@ | |||
{ | |||
"_args": [ | |||
[ | |||
{ | |||
"raw": "array-unique@^0.2.1", | |||
"scope": null, | |||
"escapedName": "array-unique", | |||
"name": "array-unique", | |||
"rawSpec": "^0.2.1", | |||
"spec": ">=0.2.1 <0.3.0", | |||
"type": "range" | |||
}, | |||
"D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\micromatch" | |||
] | |||
], | |||
"_from": "array-unique@>=0.2.1 <0.3.0", | |||
"_id": "array-unique@0.2.1", | |||
"_inCache": true, | |||
"_location": "/array-unique", | |||
"_nodeVersion": "1.6.2", | |||
"_npmUser": { | |||
"name": "jonschlinkert", | |||
"email": "github@sellside.com" | |||
}, | |||
"_npmVersion": "2.7.1", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"raw": "array-unique@^0.2.1", | |||
"scope": null, | |||
"escapedName": "array-unique", | |||
"name": "array-unique", | |||
"rawSpec": "^0.2.1", | |||
"spec": ">=0.2.1 <0.3.0", | |||
"type": "range" | |||
}, | |||
"_requiredBy": [ | |||
"/micromatch" | |||
], | |||
"_resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.2.1.tgz", | |||
"_shasum": "a1d97ccafcbc2625cc70fadceb36a50c58b01a53", | |||
"_shrinkwrap": null, | |||
"_spec": "array-unique@^0.2.1", | |||
"_where": "D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\micromatch", | |||
"author": { | |||
"name": "Jon Schlinkert", | |||
"url": "https://github.com/jonschlinkert" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/jonschlinkert/array-unique/issues" | |||
}, | |||
"dependencies": {}, | |||
"description": "Return an array free of duplicate values. Fastest ES5 implementation.", | |||
"devDependencies": { | |||
"array-uniq": "^1.0.2", | |||
"benchmarked": "^0.1.3", | |||
"mocha": "*", | |||
"should": "*" | |||
}, | |||
"directories": {}, | |||
"dist": { | |||
"shasum": "a1d97ccafcbc2625cc70fadceb36a50c58b01a53", | |||
"tarball": "https://registry.npmjs.org/array-unique/-/array-unique-0.2.1.tgz" | |||
}, | |||
"engines": { | |||
"node": ">=0.10.0" | |||
}, | |||
"files": [ | |||
"index.js" | |||
], | |||
"gitHead": "36fde8e586fb7cf880b8b3aa6515df889e64ed85", | |||
"homepage": "https://github.com/jonschlinkert/array-unique", | |||
"license": { | |||
"type": "MIT", | |||
"url": "https://github.com/jonschlinkert/array-unique/blob/master/LICENSE" | |||
}, | |||
"main": "index.js", | |||
"maintainers": [ | |||
{ | |||
"name": "jonschlinkert", | |||
"email": "github@sellside.com" | |||
} | |||
], | |||
"name": "array-unique", | |||
"optionalDependencies": {}, | |||
"readme": "ERROR: No README data found!", | |||
"repository": { | |||
"type": "git", | |||
"url": "git://github.com/jonschlinkert/array-unique.git" | |||
}, | |||
"scripts": { | |||
"test": "mocha" | |||
}, | |||
"version": "0.2.1" | |||
} |
@@ -0,0 +1,8 @@ | |||
'use strict'; | |||
module.exports = function (val) { | |||
if (val === null || val === undefined) { | |||
return []; | |||
} | |||
return Array.isArray(val) ? val : [val]; | |||
}; |
@@ -0,0 +1,21 @@ | |||
The MIT License (MIT) | |||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. |
@@ -0,0 +1,97 @@ | |||
{ | |||
"_args": [ | |||
[ | |||
{ | |||
"raw": "arrify@^1.0.0", | |||
"scope": null, | |||
"escapedName": "arrify", | |||
"name": "arrify", | |||
"rawSpec": "^1.0.0", | |||
"spec": ">=1.0.0 <2.0.0", | |||
"type": "range" | |||
}, | |||
"D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\anymatch" | |||
] | |||
], | |||
"_from": "arrify@>=1.0.0 <2.0.0", | |||
"_id": "arrify@1.0.1", | |||
"_inCache": true, | |||
"_location": "/arrify", | |||
"_nodeVersion": "4.2.1", | |||
"_npmUser": { | |||
"name": "sindresorhus", | |||
"email": "sindresorhus@gmail.com" | |||
}, | |||
"_npmVersion": "3.5.2", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"raw": "arrify@^1.0.0", | |||
"scope": null, | |||
"escapedName": "arrify", | |||
"name": "arrify", | |||
"rawSpec": "^1.0.0", | |||
"spec": ">=1.0.0 <2.0.0", | |||
"type": "range" | |||
}, | |||
"_requiredBy": [ | |||
"/anymatch" | |||
], | |||
"_resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", | |||
"_shasum": "898508da2226f380df904728456849c1501a4b0d", | |||
"_shrinkwrap": null, | |||
"_spec": "arrify@^1.0.0", | |||
"_where": "D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\anymatch", | |||
"author": { | |||
"name": "Sindre Sorhus", | |||
"email": "sindresorhus@gmail.com", | |||
"url": "sindresorhus.com" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/sindresorhus/arrify/issues" | |||
}, | |||
"dependencies": {}, | |||
"description": "Convert a value to an array", | |||
"devDependencies": { | |||
"ava": "*", | |||
"xo": "*" | |||
}, | |||
"directories": {}, | |||
"dist": { | |||
"shasum": "898508da2226f380df904728456849c1501a4b0d", | |||
"tarball": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz" | |||
}, | |||
"engines": { | |||
"node": ">=0.10.0" | |||
}, | |||
"files": [ | |||
"index.js" | |||
], | |||
"gitHead": "087edee1a58d5adaac6cae5a107886121ef43783", | |||
"homepage": "https://github.com/sindresorhus/arrify#readme", | |||
"keywords": [ | |||
"array", | |||
"arr", | |||
"arrify", | |||
"arrayify", | |||
"convert", | |||
"value" | |||
], | |||
"license": "MIT", | |||
"maintainers": [ | |||
{ | |||
"name": "sindresorhus", | |||
"email": "sindresorhus@gmail.com" | |||
} | |||
], | |||
"name": "arrify", | |||
"optionalDependencies": {}, | |||
"readme": "ERROR: No README data found!", | |||
"repository": { | |||
"type": "git", | |||
"url": "git+https://github.com/sindresorhus/arrify.git" | |||
}, | |||
"scripts": { | |||
"test": "xo && ava" | |||
}, | |||
"version": "1.0.1" | |||
} |
@@ -0,0 +1,36 @@ | |||
# arrify [![Build Status](https://travis-ci.org/sindresorhus/arrify.svg?branch=master)](https://travis-ci.org/sindresorhus/arrify) | |||
> Convert a value to an array | |||
## Install | |||
``` | |||
$ npm install --save arrify | |||
``` | |||
## Usage | |||
```js | |||
const arrify = require('arrify'); | |||
arrify('unicorn'); | |||
//=> ['unicorn'] | |||
arrify(['unicorn']); | |||
//=> ['unicorn'] | |||
arrify(null); | |||
//=> [] | |||
arrify(undefined); | |||
//=> [] | |||
``` | |||
*Supplying `null` or `undefined` results in an empty array.* | |||
## License | |||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
@@ -0,0 +1,3 @@ | |||
bower.json | |||
component.json | |||
CHANGELOG.md |
@@ -0,0 +1,23 @@ | |||
# async-each 1.0.0 (26 November 2015) | |||
* Bumped version to 1.0.0 (no functional changes) | |||
# async-each 0.1.6 (5 November 2014) | |||
* Add license to package.json | |||
# async-each 0.1.5 (22 October 2014) | |||
* Clean up package.json to fix npm warning about `repo` | |||
# async-each 0.1.4 (12 November 2013) | |||
* Fixed AMD definition. | |||
# async-each 0.1.3 (25 July 2013) | |||
* Fixed double wrapping of errors. | |||
# async-each 0.1.2 (7 July 2013) | |||
* Fixed behaviour on empty arrays. | |||
# async-each 0.1.1 (14 June 2013) | |||
* Wrapped function in closure, enabled strict mode. | |||
# async-each 0.1.0 (14 June 2013) | |||
* Initial release. |
@@ -0,0 +1,38 @@ | |||
# async-each | |||
No-bullshit, ultra-simple, 35-lines-of-code async parallel forEach function for JavaScript. | |||
We don't need junky 30K async libs. Really. | |||
For browsers and node.js. | |||
## Installation | |||
* Just include async-each before your scripts. | |||
* `npm install async-each` if you’re using node.js. | |||
* `bower install async-each` if you’re using [Bower](http://bower.io). | |||
## Usage | |||
* `each(array, iterator, callback);` — `Array`, `Function`, `(optional) Function` | |||
* `iterator(item, next)` receives current item and a callback that will mark the item as done. `next` callback receives optional `error, transformedItem` arguments. | |||
* `callback(error, transformedArray)` optionally receives first error and transformed result `Array`. | |||
Node.js: | |||
```javascript | |||
var each = require('async-each'); | |||
each(['a.js', 'b.js', 'c.js'], fs.readFile, function(error, contents) { | |||
if (error) console.error(error); | |||
console.log('Contents for a, b and c:', contents); | |||
}); | |||
``` | |||
Browser: | |||
```javascript | |||
window.asyncEach(list, fn, callback); | |||
``` | |||
## License | |||
[The MIT License](https://raw.githubusercontent.com/paulmillr/mit/master/README.md) |
@@ -0,0 +1,38 @@ | |||
// async-each MIT license (by Paul Miller from http://paulmillr.com). | |||
(function(globals) { | |||
'use strict'; | |||
var each = function(items, next, callback) { | |||
if (!Array.isArray(items)) throw new TypeError('each() expects array as first argument'); | |||
if (typeof next !== 'function') throw new TypeError('each() expects function as second argument'); | |||
if (typeof callback !== 'function') callback = Function.prototype; // no-op | |||
if (items.length === 0) return callback(undefined, items); | |||
var transformed = new Array(items.length); | |||
var count = 0; | |||
var returned = false; | |||
items.forEach(function(item, index) { | |||
next(item, function(error, transformedItem) { | |||
if (returned) return; | |||
if (error) { | |||
returned = true; | |||
return callback(error); | |||
} | |||
transformed[index] = transformedItem; | |||
count += 1; | |||
if (count === items.length) return callback(undefined, transformed); | |||
}); | |||
}); | |||
}; | |||
if (typeof define !== 'undefined' && define.amd) { | |||
define([], function() { | |||
return each; | |||
}); // RequireJS | |||
} else if (typeof module !== 'undefined' && module.exports) { | |||
module.exports = each; // CommonJS | |||
} else { | |||
globals.asyncEach = each; // <script> | |||
} | |||
})(this); |
@@ -0,0 +1,101 @@ | |||
{ | |||
"_args": [ | |||
[ | |||
{ | |||
"raw": "async-each@^1.0.0", | |||
"scope": null, | |||
"escapedName": "async-each", | |||
"name": "async-each", | |||
"rawSpec": "^1.0.0", | |||
"spec": ">=1.0.0 <2.0.0", | |||
"type": "range" | |||
}, | |||
"D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\chokidar" | |||
] | |||
], | |||
"_from": "async-each@>=1.0.0 <2.0.0", | |||
"_id": "async-each@1.0.1", | |||
"_inCache": true, | |||
"_location": "/async-each", | |||
"_nodeVersion": "6.3.0", | |||
"_npmOperationalInternal": { | |||
"host": "packages-12-west.internal.npmjs.com", | |||
"tmp": "tmp/async-each-1.0.1.tgz_1472080935649_0.032988218357786536" | |||
}, | |||
"_npmUser": { | |||
"name": "paulmillr", | |||
"email": "paul@paulmillr.com" | |||
}, | |||
"_npmVersion": "3.10.3", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"raw": "async-each@^1.0.0", | |||
"scope": null, | |||
"escapedName": "async-each", | |||
"name": "async-each", | |||
"rawSpec": "^1.0.0", | |||
"spec": ">=1.0.0 <2.0.0", | |||
"type": "range" | |||
}, | |||
"_requiredBy": [ | |||
"/chokidar" | |||
], | |||
"_resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.1.tgz", | |||
"_shasum": "19d386a1d9edc6e7c1c85d388aedbcc56d33602d", | |||
"_shrinkwrap": null, | |||
"_spec": "async-each@^1.0.0", | |||
"_where": "D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\chokidar", | |||
"author": { | |||
"name": "Paul Miller", | |||
"url": "http://paulmillr.com/" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/paulmillr/async-each/issues" | |||
}, | |||
"dependencies": {}, | |||
"description": "No-bullshit, ultra-simple, 35-lines-of-code async parallel forEach / map function for JavaScript.", | |||
"devDependencies": {}, | |||
"directories": {}, | |||
"dist": { | |||
"shasum": "19d386a1d9edc6e7c1c85d388aedbcc56d33602d", | |||
"tarball": "https://registry.npmjs.org/async-each/-/async-each-1.0.1.tgz" | |||
}, | |||
"gitHead": "f2342d85633d0dc1034a49387ca01c08c1189823", | |||
"homepage": "https://github.com/paulmillr/async-each/", | |||
"keywords": [ | |||
"async", | |||
"forEach", | |||
"each", | |||
"map", | |||
"asynchronous", | |||
"iteration", | |||
"iterate", | |||
"loop", | |||
"parallel", | |||
"concurrent", | |||
"array", | |||
"flow", | |||
"control flow" | |||
], | |||
"license": "MIT", | |||
"main": "index.js", | |||
"maintainers": [ | |||
{ | |||
"name": "paulmillr", | |||
"email": "paul@paulmillr.com" | |||
}, | |||
{ | |||
"name": "es128", | |||
"email": "elan.shanker+npm@gmail.com" | |||
} | |||
], | |||
"name": "async-each", | |||
"optionalDependencies": {}, | |||
"readme": "ERROR: No README data found!", | |||
"repository": { | |||
"type": "git", | |||
"url": "git://github.com/paulmillr/async-each.git" | |||
}, | |||
"scripts": {}, | |||
"version": "1.0.1" | |||
} |
@@ -0,0 +1,3 @@ | |||
src | |||
test | |||
node_modules |
@@ -0,0 +1,21 @@ | |||
# babel-cli | |||
> Babel command line. | |||
In addition, various entry point scripts live in the top-level package at `babel-cli/bin`. | |||
There are some shell-executable utility scripts, `babel-doctor.js`, `babel-external-helpers.js` and `babel-node.js`, and the main Babel cli script, `babel.js`. | |||
## Install | |||
```sh | |||
$ npm install babel-cli | |||
``` | |||
## Usage | |||
```sh | |||
$ babel script.js | |||
``` | |||
For more in depth documentation see: http://babeljs.io/docs/usage/cli/ |
@@ -0,0 +1,3 @@ | |||
#!/usr/bin/env node | |||
throw new Error("babel-doctor has been removed."); |
@@ -0,0 +1,3 @@ | |||
#!/usr/bin/env node | |||
require("../lib/babel-external-helpers"); |
@@ -0,0 +1,3 @@ | |||
#!/usr/bin/env node | |||
require("../lib/babel-node"); |
@@ -0,0 +1,3 @@ | |||
#!/usr/bin/env node | |||
require("../lib/babel"); |
@@ -0,0 +1 @@ | |||
throw new Error("Use the `babel-core` package not `babel`."); |
@@ -0,0 +1,191 @@ | |||
"use strict"; | |||
var _pathIsAbsolute = require("path-is-absolute"); | |||
var _pathIsAbsolute2 = _interopRequireDefault(_pathIsAbsolute); | |||
var _commander = require("commander"); | |||
var _commander2 = _interopRequireDefault(_commander); | |||
var _module2 = require("module"); | |||
var _module3 = _interopRequireDefault(_module2); | |||
var _util = require("util"); | |||
var _path = require("path"); | |||
var _path2 = _interopRequireDefault(_path); | |||
var _repl = require("repl"); | |||
var _repl2 = _interopRequireDefault(_repl); | |||
var _babelCore = require("babel-core"); | |||
var babel = _interopRequireWildcard(_babelCore); | |||
var _vm = require("vm"); | |||
var _vm2 = _interopRequireDefault(_vm); | |||
var _lodash = require("lodash"); | |||
var _lodash2 = _interopRequireDefault(_lodash); | |||
require("babel-polyfill"); | |||
var _babelRegister = require("babel-register"); | |||
var _babelRegister2 = _interopRequireDefault(_babelRegister); | |||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
var program = new _commander2.default.Command("babel-node"); | |||
program.option("-e, --eval [script]", "Evaluate script"); | |||
program.option("-p, --print [code]", "Evaluate script and print result"); | |||
program.option("-o, --only [globs]", ""); | |||
program.option("-i, --ignore [globs]", ""); | |||
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]"); | |||
program.option("-w, --plugins [string]", "", _babelCore.util.list); | |||
program.option("-b, --presets [string]", "", _babelCore.util.list); | |||
var pkg = require("../package.json"); | |||
program.version(pkg.version); | |||
program.usage("[options] [ -e script | script.js ] [arguments]"); | |||
program.parse(process.argv); | |||
(0, _babelRegister2.default)({ | |||
extensions: program.extensions, | |||
ignore: program.ignore, | |||
only: program.only, | |||
plugins: program.plugins, | |||
presets: program.presets | |||
}); | |||
var replPlugin = function replPlugin(_ref) { | |||
var t = _ref.types; | |||
return { | |||
visitor: { | |||
ModuleDeclaration: function ModuleDeclaration(path) { | |||
throw path.buildCodeFrameError("Modules aren't supported in the REPL"); | |||
}, | |||
VariableDeclaration: function VariableDeclaration(path) { | |||
if (path.node.kind !== "var") { | |||
throw path.buildCodeFrameError("Only `var` variables are supported in the REPL"); | |||
} | |||
}, | |||
Program: function Program(path) { | |||
if (path.get("body").some(function (child) { | |||
return child.isExpressionStatement(); | |||
})) return; | |||
path.pushContainer("body", t.expressionStatement(t.identifier("undefined"))); | |||
} | |||
} | |||
}; | |||
}; | |||
var _eval = function _eval(code, filename) { | |||
code = code.trim(); | |||
if (!code) return undefined; | |||
code = babel.transform(code, { | |||
filename: filename, | |||
presets: program.presets, | |||
plugins: (program.plugins || []).concat([replPlugin]) | |||
}).code; | |||
return _vm2.default.runInThisContext(code, { | |||
filename: filename | |||
}); | |||
}; | |||
if (program.eval || program.print) { | |||
var code = program.eval; | |||
if (!code || code === true) code = program.print; | |||
global.__filename = "[eval]"; | |||
global.__dirname = process.cwd(); | |||
var _module = new _module3.default(global.__filename); | |||
_module.filename = global.__filename; | |||
_module.paths = _module3.default._nodeModulePaths(global.__dirname); | |||
global.exports = _module.exports; | |||
global.module = _module; | |||
global.require = _module.require.bind(_module); | |||
var result = _eval(code, global.__filename); | |||
if (program.print) { | |||
var output = _lodash2.default.isString(result) ? result : (0, _util.inspect)(result); | |||
process.stdout.write(output + "\n"); | |||
} | |||
} else { | |||
if (program.args.length) { | |||
(function () { | |||
var args = process.argv.slice(2); | |||
var i = 0; | |||
var ignoreNext = false; | |||
_lodash2.default.each(args, function (arg, i2) { | |||
if (ignoreNext) { | |||
ignoreNext = false; | |||
return; | |||
} | |||
if (arg[0] === "-") { | |||
var parsedArg = program[arg.slice(2)]; | |||
if (parsedArg && parsedArg !== true) { | |||
ignoreNext = true; | |||
} | |||
} else { | |||
i = i2; | |||
return false; | |||
} | |||
}); | |||
args = args.slice(i); | |||
var filename = args[0]; | |||
if (!(0, _pathIsAbsolute2.default)(filename)) args[0] = _path2.default.join(process.cwd(), filename); | |||
process.argv = ["node"].concat(args); | |||
process.execArgv.unshift(__filename); | |||
_module3.default.runMain(); | |||
})(); | |||
} else { | |||
replStart(); | |||
} | |||
} | |||
function replStart() { | |||
_repl2.default.start({ | |||
prompt: "> ", | |||
input: process.stdin, | |||
output: process.stdout, | |||
eval: replEval, | |||
useGlobal: true | |||
}); | |||
} | |||
function replEval(code, context, filename, callback) { | |||
var err = void 0; | |||
var result = void 0; | |||
try { | |||
if (code[0] === "(" && code[code.length - 1] === ")") { | |||
code = code.slice(1, -1); | |||
} | |||
result = _eval(code, filename); | |||
} catch (e) { | |||
err = e; | |||
} | |||
callback(err, result); | |||
} |
@@ -0,0 +1,17 @@ | |||
"use strict"; | |||
var _commander = require("commander"); | |||
var _commander2 = _interopRequireDefault(_commander); | |||
var _babelCore = require("babel-core"); | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
_commander2.default.option("-l, --whitelist [whitelist]", "Whitelist of helpers to ONLY include", _babelCore.util.list); | |||
_commander2.default.option("-t, --output-type [type]", "Type of output (global|umd|var)", "global"); | |||
_commander2.default.usage("[options]"); | |||
_commander2.default.parse(process.argv); | |||
console.log((0, _babelCore.buildExternalHelpers)(_commander2.default.whitelist, _commander2.default.outputType)); |
@@ -0,0 +1,83 @@ | |||
"use strict"; | |||
var getV8Flags = require("v8flags"); | |||
var path = require("path"); | |||
var args = [path.join(__dirname, "_babel-node")]; | |||
var babelArgs = process.argv.slice(2); | |||
var userArgs = void 0; | |||
var argSeparator = babelArgs.indexOf("--"); | |||
if (argSeparator > -1) { | |||
userArgs = babelArgs.slice(argSeparator); | |||
babelArgs = babelArgs.slice(0, argSeparator); | |||
} | |||
function getNormalizedV8Flag(arg) { | |||
var matches = arg.match(/--(.+)/); | |||
if (matches) { | |||
return "--" + matches[1].replace(/-/g, "_"); | |||
} | |||
return arg; | |||
} | |||
getV8Flags(function (err, v8Flags) { | |||
babelArgs.forEach(function (arg) { | |||
var flag = arg.split("=")[0]; | |||
switch (flag) { | |||
case "-d": | |||
args.unshift("--debug"); | |||
break; | |||
case "debug": | |||
case "--debug": | |||
case "--debug-brk": | |||
case "--inspect": | |||
args.unshift(arg); | |||
break; | |||
case "-gc": | |||
args.unshift("--expose-gc"); | |||
break; | |||
case "--nolazy": | |||
args.unshift(flag); | |||
break; | |||
default: | |||
if (v8Flags.indexOf(getNormalizedV8Flag(flag)) >= 0 || arg.indexOf("--trace") === 0) { | |||
args.unshift(arg); | |||
} else { | |||
args.push(arg); | |||
} | |||
break; | |||
} | |||
}); | |||
if (argSeparator > -1) { | |||
args = args.concat(userArgs); | |||
} | |||
try { | |||
var kexec = require("kexec"); | |||
kexec(process.argv[0], args); | |||
} catch (err) { | |||
if (err.code !== "MODULE_NOT_FOUND") throw err; | |||
var child_process = require("child_process"); | |||
var proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" }); | |||
proc.on("exit", function (code, signal) { | |||
process.on("exit", function () { | |||
if (signal) { | |||
process.kill(process.pid, signal); | |||
} else { | |||
process.exit(code); | |||
} | |||
}); | |||
}); | |||
} | |||
}); |
@@ -0,0 +1,98 @@ | |||
"use strict"; | |||
var _stringify = require("babel-runtime/core-js/json/stringify"); | |||
var _stringify2 = _interopRequireDefault(_stringify); | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
var outputFileSync = require("output-file-sync"); | |||
var slash = require("slash"); | |||
var path = require("path"); | |||
var util = require("./util"); | |||
var fs = require("fs"); | |||
var _ = require("lodash"); | |||
module.exports = function (commander, filenames) { | |||
function write(src, relative) { | |||
relative = relative.replace(/\.(\w*?)$/, "") + ".js"; | |||
var dest = path.join(commander.outDir, relative); | |||
var data = util.compile(src, { | |||
sourceFileName: slash(path.relative(dest + "/..", src)), | |||
sourceMapTarget: path.basename(relative) | |||
}); | |||
if (!commander.copyFiles && data.ignored) return; | |||
if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") { | |||
var mapLoc = dest + ".map"; | |||
data.code = util.addSourceMappingUrl(data.code, mapLoc); | |||
outputFileSync(mapLoc, (0, _stringify2.default)(data.map)); | |||
} | |||
outputFileSync(dest, data.code); | |||
util.chmod(src, dest); | |||
util.log(src + " -> " + dest); | |||
} | |||
function handleFile(src, filename) { | |||
if (util.shouldIgnore(src)) return; | |||
if (util.canCompile(filename, commander.extensions)) { | |||
write(src, filename); | |||
} else if (commander.copyFiles) { | |||
var dest = path.join(commander.outDir, filename); | |||
outputFileSync(dest, fs.readFileSync(src)); | |||
util.chmod(src, dest); | |||
} | |||
} | |||
function handle(filename) { | |||
if (!fs.existsSync(filename)) return; | |||
var stat = fs.statSync(filename); | |||
if (stat.isDirectory(filename)) { | |||
(function () { | |||
var dirname = filename; | |||
_.each(util.readdir(dirname), function (filename) { | |||
var src = path.join(dirname, filename); | |||
handleFile(src, filename); | |||
}); | |||
})(); | |||
} else { | |||
write(filename, filename); | |||
} | |||
} | |||
if (!commander.skipInitialBuild) { | |||
_.each(filenames, handle); | |||
} | |||
if (commander.watch) { | |||
(function () { | |||
var chokidar = util.requireChokidar(); | |||
_.each(filenames, function (dirname) { | |||
var watcher = chokidar.watch(dirname, { | |||
persistent: true, | |||
ignoreInitial: true | |||
}); | |||
_.each(["add", "change"], function (type) { | |||
watcher.on(type, function (filename) { | |||
var relative = path.relative(dirname, filename) || filename; | |||
try { | |||
handleFile(filename, relative); | |||
} catch (err) { | |||
console.error(err.stack); | |||
} | |||
}); | |||
}); | |||
}); | |||
})(); | |||
} | |||
}; |
@@ -0,0 +1,189 @@ | |||
"use strict"; | |||
var _stringify = require("babel-runtime/core-js/json/stringify"); | |||
var _stringify2 = _interopRequireDefault(_stringify); | |||
var _set = require("babel-runtime/core-js/set"); | |||
var _set2 = _interopRequireDefault(_set); | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
var convertSourceMap = require("convert-source-map"); | |||
var sourceMap = require("source-map"); | |||
var slash = require("slash"); | |||
var path = require("path"); | |||
var util = require("./util"); | |||
var fs = require("fs"); | |||
var _ = require("lodash"); | |||
module.exports = function (commander, filenames, opts) { | |||
if (commander.sourceMaps === "inline") { | |||
opts.sourceMaps = true; | |||
} | |||
var results = []; | |||
var buildResult = function buildResult() { | |||
var map = new sourceMap.SourceMapGenerator({ | |||
file: path.basename(commander.outFile || "") || "stdout", | |||
sourceRoot: opts.sourceRoot | |||
}); | |||
var code = ""; | |||
var offset = 0; | |||
_.each(results, function (result) { | |||
code += result.code + "\n"; | |||
if (result.map) { | |||
(function () { | |||
var consumer = new sourceMap.SourceMapConsumer(result.map); | |||
var sources = new _set2.default(); | |||
consumer.eachMapping(function (mapping) { | |||
if (mapping.source != null) sources.add(mapping.source); | |||
map.addMapping({ | |||
generated: { | |||
line: mapping.generatedLine + offset, | |||
column: mapping.generatedColumn | |||
}, | |||
source: mapping.source, | |||
original: mapping.source == null ? null : { | |||
line: mapping.originalLine, | |||
column: mapping.originalColumn | |||
} | |||
}); | |||
}); | |||
sources.forEach(function (source) { | |||
var content = consumer.sourceContentFor(source, true); | |||
if (content !== null) { | |||
map.setSourceContent(source, content); | |||
} | |||
}); | |||
offset = code.split("\n").length; | |||
})(); | |||
} | |||
}); | |||
if (commander.sourceMaps === "inline" || !commander.outFile && commander.sourceMaps) { | |||
code += "\n" + convertSourceMap.fromObject(map).toComment(); | |||
} | |||
return { | |||
map: map, | |||
code: code | |||
}; | |||
}; | |||
var output = function output() { | |||
var result = buildResult(); | |||
if (commander.outFile) { | |||
if (commander.sourceMaps && commander.sourceMaps !== "inline") { | |||
var mapLoc = commander.outFile + ".map"; | |||
result.code = util.addSourceMappingUrl(result.code, mapLoc); | |||
fs.writeFileSync(mapLoc, (0, _stringify2.default)(result.map)); | |||
} | |||
fs.writeFileSync(commander.outFile, result.code); | |||
} else { | |||
process.stdout.write(result.code + "\n"); | |||
} | |||
}; | |||
var stdin = function stdin() { | |||
var code = ""; | |||
process.stdin.setEncoding("utf8"); | |||
process.stdin.on("readable", function () { | |||
var chunk = process.stdin.read(); | |||
if (chunk !== null) code += chunk; | |||
}); | |||
process.stdin.on("end", function () { | |||
results.push(util.transform(commander.filename, code, { | |||
sourceFileName: "stdin" | |||
})); | |||
output(); | |||
}); | |||
}; | |||
var walk = function walk() { | |||
var _filenames = []; | |||
results = []; | |||
_.each(filenames, function (filename) { | |||
if (!fs.existsSync(filename)) return; | |||
var stat = fs.statSync(filename); | |||
if (stat.isDirectory()) { | |||
(function () { | |||
var dirname = filename; | |||
_.each(util.readdirFilter(filename), function (filename) { | |||
_filenames.push(path.join(dirname, filename)); | |||
}); | |||
})(); | |||
} else { | |||
_filenames.push(filename); | |||
} | |||
}); | |||
_.each(_filenames, function (filename) { | |||
if (util.shouldIgnore(filename)) return; | |||
var sourceFilename = filename; | |||
if (commander.outFile) { | |||
sourceFilename = path.relative(path.dirname(commander.outFile), sourceFilename); | |||
} | |||
sourceFilename = slash(sourceFilename); | |||
var data = util.compile(filename, { | |||
sourceFileName: sourceFilename | |||
}); | |||
if (data.ignored) return; | |||
results.push(data); | |||
}); | |||
output(); | |||
}; | |||
var files = function files() { | |||
if (!commander.skipInitialBuild) { | |||
walk(); | |||
} | |||
if (commander.watch) { | |||
var chokidar = util.requireChokidar(); | |||
chokidar.watch(filenames, { | |||
persistent: true, | |||
ignoreInitial: true | |||
}).on("all", function (type, filename) { | |||
if (util.shouldIgnore(filename) || !util.canCompile(filename, commander.extensions)) return; | |||
if (type === "add" || type === "change") { | |||
util.log(type + " " + filename); | |||
try { | |||
walk(); | |||
} catch (err) { | |||
console.error(err.stack); | |||
} | |||
} | |||
}); | |||
} | |||
}; | |||
if (filenames.length) { | |||
files(); | |||
} else { | |||
stdin(); | |||
} | |||
}; |
@@ -0,0 +1,123 @@ | |||
#!/usr/bin/env node | |||
"use strict"; | |||
require("babel-core"); | |||
var fs = require("fs"); | |||
var commander = require("commander"); | |||
var kebabCase = require("lodash/kebabCase"); | |||
var options = require("babel-core").options; | |||
var util = require("babel-core").util; | |||
var uniq = require("lodash/uniq"); | |||
var each = require("lodash/each"); | |||
var glob = require("glob"); | |||
each(options, function (option, key) { | |||
if (option.hidden) return; | |||
var arg = kebabCase(key); | |||
if (option.type !== "boolean") { | |||
arg += " [" + (option.type || "string") + "]"; | |||
} | |||
if (option.type === "boolean" && option.default === true) { | |||
arg = "no-" + arg; | |||
} | |||
arg = "--" + arg; | |||
if (option.shorthand) { | |||
arg = "-" + option.shorthand + ", " + arg; | |||
} | |||
var desc = []; | |||
if (option.deprecated) desc.push("[DEPRECATED] " + option.deprecated); | |||
if (option.description) desc.push(option.description); | |||
commander.option(arg, desc.join(" ")); | |||
}); | |||
commander.option("-x, --extensions [extensions]", "List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx]"); | |||
commander.option("-w, --watch", "Recompile files on changes"); | |||
commander.option("--skip-initial-build", "Do not compile files before watching"); | |||
commander.option("-o, --out-file [out]", "Compile all input files into a single file"); | |||
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory"); | |||
commander.option("-D, --copy-files", "When compiling a directory copy over non-compilable files"); | |||
commander.option("-q, --quiet", "Don't log anything"); | |||
var pkg = require("../../package.json"); | |||
commander.version(pkg.version + " (babel-core " + require("babel-core").version + ")"); | |||
commander.usage("[options] <files ...>"); | |||
commander.parse(process.argv); | |||
if (commander.extensions) { | |||
commander.extensions = util.arrayify(commander.extensions); | |||
} | |||
var errors = []; | |||
var filenames = commander.args.reduce(function (globbed, input) { | |||
var files = glob.sync(input); | |||
if (!files.length) files = [input]; | |||
return globbed.concat(files); | |||
}, []); | |||
filenames = uniq(filenames); | |||
each(filenames, function (filename) { | |||
if (!fs.existsSync(filename)) { | |||
errors.push(filename + " doesn't exist"); | |||
} | |||
}); | |||
if (commander.outDir && !filenames.length) { | |||
errors.push("filenames required for --out-dir"); | |||
} | |||
if (commander.outFile && commander.outDir) { | |||
errors.push("cannot have --out-file and --out-dir"); | |||
} | |||
if (commander.watch) { | |||
if (!commander.outFile && !commander.outDir) { | |||
errors.push("--watch requires --out-file or --out-dir"); | |||
} | |||
if (!filenames.length) { | |||
errors.push("--watch requires filenames"); | |||
} | |||
} | |||
if (commander.skipInitialBuild && !commander.watch) { | |||
errors.push("--skip-initial-build requires --watch"); | |||
} | |||
if (errors.length) { | |||
console.error(errors.join(". ")); | |||
process.exit(2); | |||
} | |||
var opts = exports.opts = {}; | |||
each(options, function (opt, key) { | |||
if (commander[key] !== undefined && commander[key] !== opt.default) { | |||
opts[key] = commander[key]; | |||
} | |||
}); | |||
opts.ignore = util.arrayify(opts.ignore, util.regexify); | |||
if (opts.only) { | |||
opts.only = util.arrayify(opts.only, util.regexify); | |||
} | |||
var fn = void 0; | |||
if (commander.outDir) { | |||
fn = require("./dir"); | |||
} else { | |||
fn = require("./file"); | |||
} | |||
fn(commander, filenames, exports.opts); |
@@ -0,0 +1,90 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
exports.chmod = chmod; | |||
exports.readdirFilter = readdirFilter; | |||
exports.shouldIgnore = shouldIgnore; | |||
exports.addSourceMappingUrl = addSourceMappingUrl; | |||
exports.log = log; | |||
exports.transform = transform; | |||
exports.compile = compile; | |||
exports.requireChokidar = requireChokidar; | |||
var commander = require("commander"); | |||
var readdir = require("fs-readdir-recursive"); | |||
var index = require("./index"); | |||
var babel = require("babel-core"); | |||
var util = require("babel-core").util; | |||
var path = require("path"); | |||
var fs = require("fs"); | |||
var _ = require("lodash"); | |||
function chmod(src, dest) { | |||
fs.chmodSync(dest, fs.statSync(src).mode); | |||
} | |||
function readdirFilter(filename) { | |||
return readdir(filename).filter(function (filename) { | |||
return util.canCompile(filename); | |||
}); | |||
} | |||
exports.readdir = readdir; | |||
var canCompile = exports.canCompile = util.canCompile; | |||
function shouldIgnore(loc) { | |||
return util.shouldIgnore(loc, index.opts.ignore, index.opts.only); | |||
} | |||
function addSourceMappingUrl(code, loc) { | |||
return code + "\n//# sourceMappingURL=" + path.basename(loc); | |||
} | |||
function log(msg) { | |||
if (!commander.quiet) console.log(msg); | |||
} | |||
function transform(filename, code, opts) { | |||
opts = _.defaults(opts || {}, index.opts); | |||
opts.filename = filename; | |||
var result = babel.transform(code, opts); | |||
result.filename = filename; | |||
result.actual = code; | |||
return result; | |||
} | |||
function compile(filename, opts) { | |||
try { | |||
var code = fs.readFileSync(filename, "utf8"); | |||
return transform(filename, code, opts); | |||
} catch (err) { | |||
if (commander.watch) { | |||
console.error(toErrorStack(err)); | |||
return { ignored: true }; | |||
} else { | |||
throw err; | |||
} | |||
} | |||
} | |||
function toErrorStack(err) { | |||
if (err._babel && err instanceof SyntaxError) { | |||
return err.name + ": " + err.message + "\n" + err.codeFrame; | |||
} else { | |||
return err.stack; | |||
} | |||
} | |||
process.on("uncaughtException", function (err) { | |||
console.error(toErrorStack(err)); | |||
process.exit(1); | |||
}); | |||
function requireChokidar() { | |||
try { | |||
return require("chokidar"); | |||
} catch (err) { | |||
console.error("The optional dependency chokidar failed to install and is required for " + "--watch. Chokidar is likely not supported on your platform."); | |||
throw err; | |||
} | |||
} |
@@ -0,0 +1,123 @@ | |||
{ | |||
"_args": [ | |||
[ | |||
{ | |||
"raw": "babel-cli@^6.7.5", | |||
"scope": null, | |||
"escapedName": "babel-cli", | |||
"name": "babel-cli", | |||
"rawSpec": "^6.7.5", | |||
"spec": ">=6.7.5 <7.0.0", | |||
"type": "range" | |||
}, | |||
"D:\\develop\\wserver\\htdocs\\lib\\pannellum" | |||
] | |||
], | |||
"_from": "babel-cli@>=6.7.5 <7.0.0", | |||
"_id": "babel-cli@6.18.0", | |||
"_inCache": true, | |||
"_location": "/babel-cli", | |||
"_nodeVersion": "6.9.0", | |||
"_npmOperationalInternal": { | |||
"host": "packages-12-west.internal.npmjs.com", | |||
"tmp": "tmp/babel-cli-6.18.0.tgz_1477343918006_0.38022179482504725" | |||
}, | |||
"_npmUser": { | |||
"name": "hzoo", | |||
"email": "hi@henryzoo.com" | |||
}, | |||
"_npmVersion": "3.10.8", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"raw": "babel-cli@^6.7.5", | |||
"scope": null, | |||
"escapedName": "babel-cli", | |||
"name": "babel-cli", | |||
"rawSpec": "^6.7.5", | |||
"spec": ">=6.7.5 <7.0.0", | |||
"type": "range" | |||
}, | |||
"_requiredBy": [ | |||
"#DEV:/" | |||
], | |||
"_resolved": "https://registry.npmjs.org/babel-cli/-/babel-cli-6.18.0.tgz", | |||
"_shasum": "92117f341add9dead90f6fa7d0a97c0cc08ec186", | |||
"_shrinkwrap": null, | |||
"_spec": "babel-cli@^6.7.5", | |||
"_where": "D:\\develop\\wserver\\htdocs\\lib\\pannellum", | |||
"author": { | |||
"name": "Sebastian McKenzie", | |||
"email": "sebmck@gmail.com" | |||
}, | |||
"bin": { | |||
"babel-doctor": "./bin/babel-doctor.js", | |||
"babel": "./bin/babel.js", | |||
"babel-node": "./bin/babel-node.js", | |||
"babel-external-helpers": "./bin/babel-external-helpers.js" | |||
}, | |||
"dependencies": { | |||
"babel-core": "^6.18.0", | |||
"babel-polyfill": "^6.16.0", | |||
"babel-register": "^6.18.0", | |||
"babel-runtime": "^6.9.0", | |||
"chokidar": "^1.0.0", | |||
"commander": "^2.8.1", | |||
"convert-source-map": "^1.1.0", | |||
"fs-readdir-recursive": "^1.0.0", | |||
"glob": "^5.0.5", | |||
"lodash": "^4.2.0", | |||
"output-file-sync": "^1.1.0", | |||
"path-is-absolute": "^1.0.0", | |||
"slash": "^1.0.0", | |||
"source-map": "^0.5.0", | |||
"v8flags": "^2.0.10" | |||
}, | |||
"description": "Babel command line.", | |||
"devDependencies": { | |||
"babel-helper-fixtures": "^6.18.0" | |||
}, | |||
"directories": {}, | |||
"dist": { | |||
"shasum": "92117f341add9dead90f6fa7d0a97c0cc08ec186", | |||
"tarball": "https://registry.npmjs.org/babel-cli/-/babel-cli-6.18.0.tgz" | |||
}, | |||
"homepage": "https://babeljs.io/", | |||
"license": "MIT", | |||
"maintainers": [ | |||
{ | |||
"name": "amasad", | |||
"email": "amjad.masad@gmail.com" | |||
}, | |||
{ | |||
"name": "hzoo", | |||
"email": "hi@henryzoo.com" | |||
}, | |||
{ | |||
"name": "jmm", | |||
"email": "npm-public@jessemccarthy.net" | |||
}, | |||
{ | |||
"name": "loganfsmyth", | |||
"email": "loganfsmyth@gmail.com" | |||
}, | |||
{ | |||
"name": "sebmck", | |||
"email": "sebmck@gmail.com" | |||
}, | |||
{ | |||
"name": "thejameskyle", | |||
"email": "me@thejameskyle.com" | |||
} | |||
], | |||
"name": "babel-cli", | |||
"optionalDependencies": { | |||
"chokidar": "^1.0.0" | |||
}, | |||
"readme": "ERROR: No README data found!", | |||
"repository": { | |||
"type": "git", | |||
"url": "https://github.com/babel/babel/tree/master/packages/babel-cli" | |||
}, | |||
"scripts": {}, | |||
"version": "6.18.0" | |||
} |
@@ -0,0 +1,3 @@ | |||
#!/bin/sh | |||
set -e | |||
npm link babel-core |
@@ -0,0 +1,3 @@ | |||
src | |||
test | |||
node_modules |
@@ -0,0 +1,42 @@ | |||
# babel-code-frame | |||
> Generate errors that contain a code frame that point to source locations. | |||
## Install | |||
```sh | |||
$ npm install babel-code-frame | |||
``` | |||
## Usage | |||
```js | |||
import codeFrame from 'babel-code-frame'; | |||
const rawLines = `class Foo { | |||
constructor() | |||
}`; | |||
const lineNumber = 2; | |||
const colNumber = 16; | |||
const result = codeFrame(rawLines, lineNumber, colNumber, { /* options */ }); | |||
console.log(result); | |||
``` | |||
```sh | |||
1 | class Foo { | |||
> 2 | constructor() | |||
| ^ | |||
3 | } | |||
``` | |||
If the column number is not known, you may pass `null` instead. | |||
## Options | |||
name | type | default | description | |||
-----------------------|----------|-----------------|------------------------------------------------------ | |||
highlightCode | boolean | `false` | Syntax highlight the code as JavaScript for terminals | |||
linesAbove | number | 2 | The number of lines to show above the error | |||
linesBelow | number | 3 | The number of lines to show below the error |
@@ -0,0 +1,135 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
exports.default = function (rawLines, lineNumber, colNumber) { | |||
var opts = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | |||
colNumber = Math.max(colNumber, 0); | |||
var highlighted = opts.highlightCode && _chalk2.default.supportsColor; | |||
var maybeHighlight = function maybeHighlight(chalkFn, string) { | |||
return highlighted ? chalkFn(string) : string; | |||
}; | |||
if (highlighted) rawLines = highlight(rawLines); | |||
var linesAbove = opts.linesAbove || 2; | |||
var linesBelow = opts.linesBelow || 3; | |||
var lines = rawLines.split(NEWLINE); | |||
var start = Math.max(lineNumber - (linesAbove + 1), 0); | |||
var end = Math.min(lines.length, lineNumber + linesBelow); | |||
if (!lineNumber && !colNumber) { | |||
start = 0; | |||
end = lines.length; | |||
} | |||
var numberMaxWidth = String(end).length; | |||
var frame = lines.slice(start, end).map(function (line, index) { | |||
var number = start + 1 + index; | |||
var paddedNumber = (" " + number).slice(-numberMaxWidth); | |||
var gutter = " " + paddedNumber + " | "; | |||
if (number === lineNumber) { | |||
var markerLine = ""; | |||
if (colNumber) { | |||
var markerSpacing = line.slice(0, colNumber - 1).replace(/[^\t]/g, " "); | |||
markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^")].join(""); | |||
} | |||
return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join(""); | |||
} else { | |||
return " " + maybeHighlight(defs.gutter, gutter) + line; | |||
} | |||
}).join("\n"); | |||
if (highlighted) { | |||
return _chalk2.default.reset(frame); | |||
} else { | |||
return frame; | |||
} | |||
}; | |||
var _jsTokens = require("js-tokens"); | |||
var _jsTokens2 = _interopRequireDefault(_jsTokens); | |||
var _esutils = require("esutils"); | |||
var _esutils2 = _interopRequireDefault(_esutils); | |||
var _chalk = require("chalk"); | |||
var _chalk2 = _interopRequireDefault(_chalk); | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
var defs = { | |||
keyword: _chalk2.default.cyan, | |||
capitalized: _chalk2.default.yellow, | |||
jsx_tag: _chalk2.default.yellow, | |||
punctuator: _chalk2.default.yellow, | |||
number: _chalk2.default.magenta, | |||
string: _chalk2.default.green, | |||
regex: _chalk2.default.magenta, | |||
comment: _chalk2.default.grey, | |||
invalid: _chalk2.default.white.bgRed.bold, | |||
gutter: _chalk2.default.grey, | |||
marker: _chalk2.default.red.bold | |||
}; | |||
var NEWLINE = /\r\n|[\n\r\u2028\u2029]/; | |||
var JSX_TAG = /^[a-z][\w-]*$/i; | |||
var BRACKET = /^[()\[\]{}]$/; | |||
function getTokenType(match) { | |||
var _match$slice = match.slice(-2); | |||
var offset = _match$slice[0]; | |||
var text = _match$slice[1]; | |||
var token = _jsTokens2.default.matchToToken(match); | |||
if (token.type === "name") { | |||
if (_esutils2.default.keyword.isReservedWordES6(token.value)) { | |||
return "keyword"; | |||
} | |||
if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) { | |||
return "jsx_tag"; | |||
} | |||
if (token.value[0] !== token.value[0].toLowerCase()) { | |||
return "capitalized"; | |||
} | |||
} | |||
if (token.type === "punctuator" && BRACKET.test(token.value)) { | |||
return "bracket"; | |||
} | |||
return token.type; | |||
} | |||
function highlight(text) { | |||
return text.replace(_jsTokens2.default, function () { | |||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | |||
args[_key] = arguments[_key]; | |||
} | |||
var type = getTokenType(args); | |||
var colorize = defs[type]; | |||
if (colorize) { | |||
return args[0].split(NEWLINE).map(function (str) { | |||
return colorize(str); | |||
}).join("\n"); | |||
} else { | |||
return args[0]; | |||
} | |||
}); | |||
} | |||
module.exports = exports["default"]; |
@@ -0,0 +1,103 @@ | |||
{ | |||
"_args": [ | |||
[ | |||
{ | |||
"raw": "babel-code-frame@^6.16.0", | |||
"scope": null, | |||
"escapedName": "babel-code-frame", | |||
"name": "babel-code-frame", | |||
"rawSpec": "^6.16.0", | |||
"spec": ">=6.16.0 <7.0.0", | |||
"type": "range" | |||
}, | |||
"D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\babel-core" | |||
] | |||
], | |||
"_from": "babel-code-frame@>=6.16.0 <7.0.0", | |||
"_id": "babel-code-frame@6.16.0", | |||
"_inCache": true, | |||
"_location": "/babel-code-frame", | |||
"_nodeVersion": "5.11.1", | |||
"_npmOperationalInternal": { | |||
"host": "packages-16-east.internal.npmjs.com", | |||
"tmp": "tmp/babel-code-frame-6.16.0.tgz_1475091527344_0.9727453696541488" | |||
}, | |||
"_npmUser": { | |||
"name": "hzoo", | |||
"email": "hi@henryzoo.com" | |||
}, | |||
"_npmVersion": "3.10.8", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"raw": "babel-code-frame@^6.16.0", | |||
"scope": null, | |||
"escapedName": "babel-code-frame", | |||
"name": "babel-code-frame", | |||
"rawSpec": "^6.16.0", | |||
"spec": ">=6.16.0 <7.0.0", | |||
"type": "range" | |||
}, | |||
"_requiredBy": [ | |||
"/babel-core", | |||
"/babel-traverse" | |||
], | |||
"_resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.16.0.tgz", | |||
"_shasum": "f90e60da0862909d3ce098733b5d3987c97cb8de", | |||
"_shrinkwrap": null, | |||
"_spec": "babel-code-frame@^6.16.0", | |||
"_where": "D:\\develop\\wserver\\htdocs\\lib\\pannellum\\node_modules\\babel-core", | |||
"author": { | |||
"name": "Sebastian McKenzie", | |||
"email": "sebmck@gmail.com" | |||
}, | |||
"dependencies": { | |||
"chalk": "^1.1.0", | |||
"esutils": "^2.0.2", | |||
"js-tokens": "^2.0.0" | |||
}, | |||
"description": "Generate errors that contain a code frame that point to source locations.", | |||
"devDependencies": {}, | |||
"directories": {}, | |||
"dist": { | |||
"shasum": "f90e60da0862909d3ce098733b5d3987c97cb8de", | |||
"tarball": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.16.0.tgz" | |||
}, | |||
"homepage": "https://babeljs.io/", | |||
"license": "MIT", | |||
"main": "lib/index.js", | |||
"maintainers": [ | |||
{ | |||
"name": "amasad", | |||
"email": "amjad.masad@gmail.com" | |||
}, | |||
{ | |||
"name": "hzoo", | |||
"email": "hi@henryzoo.com" | |||
}, | |||
{ | |||
"name": "jmm", | |||
"email": "npm-public@jessemccarthy.net" | |||
}, | |||
{ | |||
"name": "loganfsmyth", | |||
"email": "loganfsmyth@gmail.com" | |||
}, | |||
{ | |||
"name": "sebmck", | |||
"email": "sebmck@gmail.com" | |||
}, | |||
{ | |||
"name": "thejameskyle", | |||
"email": "me@thejameskyle.com" | |||
} | |||
], | |||
"name": "babel-code-frame", | |||
"optionalDependencies": {}, | |||
"readme": "ERROR: No README data found!", | |||
"repository": { | |||
"type": "git", | |||
"url": "https://github.com/babel/babel/tree/master/packages/babel-code-frame" | |||
}, | |||
"scripts": {}, | |||
"version": "6.16.0" | |||
} |
@@ -0,0 +1,24 @@ | |||
# babel-core | |||
> Babel compiler core. | |||
## Install | |||
``` | |||
$ npm install babel-core | |||
``` | |||
## Usage | |||
```js | |||
import * as babel from 'babel-core'; | |||
const code = `class Example {}`; | |||
const result = babel.transform(code, { /* options */ }); | |||
result.code; // Generated code | |||
result.map; // Sourcemap | |||
result.ast; // AST | |||
``` | |||
For more in depth documentation see: http://babeljs.io/docs/usage/api/ |
@@ -0,0 +1 @@ | |||
module.exports = require("./lib/api/node.js"); |
@@ -0,0 +1,190 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
exports.transformFileSync = exports.transformFile = exports.transformFromAst = exports.transform = exports.analyse = exports.Pipeline = exports.Plugin = exports.OptionManager = exports.traverse = exports.types = exports.messages = exports.util = exports.version = exports.template = exports.buildExternalHelpers = exports.options = exports.File = undefined; | |||
var _node = require("./node"); | |||
Object.defineProperty(exports, "File", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.File; | |||
} | |||
}); | |||
Object.defineProperty(exports, "options", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.options; | |||
} | |||
}); | |||
Object.defineProperty(exports, "buildExternalHelpers", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.buildExternalHelpers; | |||
} | |||
}); | |||
Object.defineProperty(exports, "template", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.template; | |||
} | |||
}); | |||
Object.defineProperty(exports, "version", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.version; | |||
} | |||
}); | |||
Object.defineProperty(exports, "util", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.util; | |||
} | |||
}); | |||
Object.defineProperty(exports, "messages", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.messages; | |||
} | |||
}); | |||
Object.defineProperty(exports, "types", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.types; | |||
} | |||
}); | |||
Object.defineProperty(exports, "traverse", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.traverse; | |||
} | |||
}); | |||
Object.defineProperty(exports, "OptionManager", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.OptionManager; | |||
} | |||
}); | |||
Object.defineProperty(exports, "Plugin", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.Plugin; | |||
} | |||
}); | |||
Object.defineProperty(exports, "Pipeline", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.Pipeline; | |||
} | |||
}); | |||
Object.defineProperty(exports, "analyse", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.analyse; | |||
} | |||
}); | |||
Object.defineProperty(exports, "transform", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.transform; | |||
} | |||
}); | |||
Object.defineProperty(exports, "transformFromAst", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.transformFromAst; | |||
} | |||
}); | |||
Object.defineProperty(exports, "transformFile", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.transformFile; | |||
} | |||
}); | |||
Object.defineProperty(exports, "transformFileSync", { | |||
enumerable: true, | |||
get: function get() { | |||
return _node.transformFileSync; | |||
} | |||
}); | |||
exports.run = run; | |||
exports.load = load; | |||
function run(code) { | |||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | |||
return new Function((0, _node.transform)(code, opts).code)(); | |||
} | |||
function load(url, callback) { | |||
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | |||
var hold = arguments[3]; | |||
opts.filename = opts.filename || url; | |||
var xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest(); | |||
xhr.open("GET", url, true); | |||
if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain"); | |||
xhr.onreadystatechange = function () { | |||
if (xhr.readyState !== 4) return; | |||
var status = xhr.status; | |||
if (status === 0 || status === 200) { | |||
var param = [xhr.responseText, opts]; | |||
if (!hold) run(param); | |||
if (callback) callback(param); | |||
} else { | |||
throw new Error("Could not load " + url); | |||
} | |||
}; | |||
xhr.send(null); | |||
} | |||
function runScripts() { | |||
var scripts = []; | |||
var types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"]; | |||
var index = 0; | |||
function exec() { | |||
var param = scripts[index]; | |||
if (param instanceof Array) { | |||
run(param, index); | |||
index++; | |||
exec(); | |||
} | |||
} | |||
function run(script, i) { | |||
var opts = {}; | |||
if (script.src) { | |||
load(script.src, function (param) { | |||
scripts[i] = param; | |||
exec(); | |||
}, opts, true); | |||
} else { | |||
opts.filename = "embedded"; | |||
scripts[i] = [script.innerHTML, opts]; | |||
} | |||
} | |||
var _scripts = global.document.getElementsByTagName("script"); | |||
for (var i = 0; i < _scripts.length; ++i) { | |||
var _script = _scripts[i]; | |||
if (types.indexOf(_script.type) >= 0) scripts.push(_script); | |||
} | |||
for (var _i = 0; _i < scripts.length; _i++) { | |||
run(scripts[_i], _i); | |||
} | |||
exec(); | |||
} | |||
if (global.addEventListener) { | |||
global.addEventListener("DOMContentLoaded", runScripts, false); | |||
} else if (global.attachEvent) { | |||
global.attachEvent("onload", runScripts); | |||
} |
@@ -0,0 +1,139 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
exports.transformFromAst = exports.transform = exports.analyse = exports.Pipeline = exports.OptionManager = exports.traverse = exports.types = exports.messages = exports.util = exports.version = exports.template = exports.buildExternalHelpers = exports.options = exports.File = undefined; | |||
var _file = require("../transformation/file"); | |||
Object.defineProperty(exports, "File", { | |||
enumerable: true, | |||
get: function get() { | |||
return _interopRequireDefault(_file).default; | |||
} | |||
}); | |||
var _config = require("../transformation/file/options/config"); | |||
Object.defineProperty(exports, "options", { | |||
enumerable: true, | |||
get: function get() { | |||
return _interopRequireDefault(_config).default; | |||
} | |||
}); | |||
var _buildExternalHelpers = require("../tools/build-external-helpers"); | |||
Object.defineProperty(exports, "buildExternalHelpers", { | |||
enumerable: true, | |||
get: function get() { | |||
return _interopRequireDefault(_buildExternalHelpers).default; | |||
} | |||
}); | |||
var _babelTemplate = require("babel-template"); | |||
Object.defineProperty(exports, "template", { | |||
enumerable: true, | |||
get: function get() { | |||
return _interopRequireDefault(_babelTemplate).default; | |||
} | |||
}); | |||
var _package = require("../../package"); | |||
Object.defineProperty(exports, "version", { | |||
enumerable: true, | |||
get: function get() { | |||
return _package.version; | |||
} | |||
}); | |||
exports.Plugin = Plugin; | |||
exports.transformFile = transformFile; | |||
exports.transformFileSync = transformFileSync; | |||
var _isFunction = require("lodash/isFunction"); | |||
var _isFunction2 = _interopRequireDefault(_isFunction); | |||
var _fs = require("fs"); | |||
var _fs2 = _interopRequireDefault(_fs); | |||
var _util = require("../util"); | |||
var util = _interopRequireWildcard(_util); | |||
var _babelMessages = require("babel-messages"); | |||
var messages = _interopRequireWildcard(_babelMessages); | |||
var _babelTypes = require("babel-types"); | |||
var t = _interopRequireWildcard(_babelTypes); | |||
var _babelTraverse = require("babel-traverse"); | |||
var _babelTraverse2 = _interopRequireDefault(_babelTraverse); | |||
var _optionManager = require("../transformation/file/options/option-manager"); | |||
var _optionManager2 = _interopRequireDefault(_optionManager); | |||
var _pipeline = require("../transformation/pipeline"); | |||
var _pipeline2 = _interopRequireDefault(_pipeline); | |||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
exports.util = util; | |||
exports.messages = messages; | |||
exports.types = t; | |||
exports.traverse = _babelTraverse2.default; | |||
exports.OptionManager = _optionManager2.default; | |||
function Plugin(alias) { | |||
throw new Error("The (" + alias + ") Babel 5 plugin is being run with Babel 6."); | |||
} | |||
exports.Pipeline = _pipeline2.default; | |||
var pipeline = new _pipeline2.default(); | |||
var analyse = exports.analyse = pipeline.analyse.bind(pipeline); | |||
var transform = exports.transform = pipeline.transform.bind(pipeline); | |||
var transformFromAst = exports.transformFromAst = pipeline.transformFromAst.bind(pipeline); | |||
function transformFile(filename, opts, callback) { | |||
if ((0, _isFunction2.default)(opts)) { | |||
callback = opts; | |||
opts = {}; | |||
} | |||
opts.filename = filename; | |||
_fs2.default.readFile(filename, function (err, code) { | |||
var result = void 0; | |||
if (!err) { | |||
try { | |||
result = transform(code, opts); | |||
} catch (_err) { | |||
err = _err; | |||
} | |||
} | |||
if (err) { | |||
callback(err); | |||
} else { | |||
callback(null, result); | |||
} | |||
}); | |||
} | |||
function transformFileSync(filename) { | |||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | |||
opts.filename = filename; | |||
return transform(_fs2.default.readFileSync(filename, "utf8"), opts); | |||
} |
@@ -0,0 +1,46 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
var _getIterator2 = require("babel-runtime/core-js/get-iterator"); | |||
var _getIterator3 = _interopRequireDefault(_getIterator2); | |||
exports.default = function (dest, src) { | |||
if (!dest || !src) return; | |||
return (0, _mergeWith2.default)(dest, src, function (a, b) { | |||
if (b && Array.isArray(a)) { | |||
var newArray = b.slice(0); | |||
for (var _iterator = a, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) { | |||
var _ref; | |||
if (_isArray) { | |||
if (_i >= _iterator.length) break; | |||
_ref = _iterator[_i++]; | |||
} else { | |||
_i = _iterator.next(); | |||
if (_i.done) break; | |||
_ref = _i.value; | |||
} | |||
var item = _ref; | |||
if (newArray.indexOf(item) < 0) { | |||
newArray.push(item); | |||
} | |||
} | |||
return newArray; | |||
} | |||
}); | |||
}; | |||
var _mergeWith = require("lodash/mergeWith"); | |||
var _mergeWith2 = _interopRequireDefault(_mergeWith); | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
module.exports = exports["default"]; |
@@ -0,0 +1,23 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
exports.default = function (ast, comments, tokens) { | |||
if (ast) { | |||
if (ast.type === "Program") { | |||
return t.file(ast, comments || [], tokens || []); | |||
} else if (ast.type === "File") { | |||
return ast; | |||
} | |||
} | |||
throw new Error("Not a valid ast?"); | |||
}; | |||
var _babelTypes = require("babel-types"); | |||
var t = _interopRequireWildcard(_babelTypes); | |||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | |||
module.exports = exports["default"]; |
@@ -0,0 +1,46 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
var _typeof2 = require("babel-runtime/helpers/typeof"); | |||
var _typeof3 = _interopRequireDefault(_typeof2); | |||
exports.default = function (loc) { | |||
var relative = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : process.cwd(); | |||
if ((typeof _module2.default === "undefined" ? "undefined" : (0, _typeof3.default)(_module2.default)) === "object") return null; | |||
var relativeMod = relativeModules[relative]; | |||
if (!relativeMod) { | |||
relativeMod = new _module2.default(); | |||
var filename = _path2.default.join(relative, ".babelrc"); | |||
relativeMod.id = filename; | |||
relativeMod.filename = filename; | |||
relativeMod.paths = _module2.default._nodeModulePaths(relative); | |||
relativeModules[relative] = relativeMod; | |||
} | |||
try { | |||
return _module2.default._resolveFilename(loc, relativeMod); | |||
} catch (err) { | |||
return null; | |||
} | |||
}; | |||
var _module = require("module"); | |||
var _module2 = _interopRequireDefault(_module); | |||
var _path = require("path"); | |||
var _path2 = _interopRequireDefault(_path); | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
var relativeModules = {}; | |||
module.exports = exports["default"]; |
@@ -0,0 +1,55 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
var _map = require("babel-runtime/core-js/map"); | |||
var _map2 = _interopRequireDefault(_map); | |||
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck"); | |||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | |||
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn"); | |||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | |||
var _inherits2 = require("babel-runtime/helpers/inherits"); | |||
var _inherits3 = _interopRequireDefault(_inherits2); | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
var Store = function (_Map) { | |||
(0, _inherits3.default)(Store, _Map); | |||
function Store() { | |||
(0, _classCallCheck3.default)(this, Store); | |||
var _this = (0, _possibleConstructorReturn3.default)(this, _Map.call(this)); | |||
_this.dynamicData = {}; | |||
return _this; | |||
} | |||
Store.prototype.setDynamic = function setDynamic(key, fn) { | |||
this.dynamicData[key] = fn; | |||
}; | |||
Store.prototype.get = function get(key) { | |||
if (this.has(key)) { | |||
return _Map.prototype.get.call(this, key); | |||
} else { | |||
if (Object.prototype.hasOwnProperty.call(this.dynamicData, key)) { | |||
var val = this.dynamicData[key](); | |||
this.set(key, val); | |||
return val; | |||
} | |||
} | |||
}; | |||
return Store; | |||
}(_map2.default); | |||
exports.default = Store; | |||
module.exports = exports["default"]; |
@@ -0,0 +1,105 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
exports.default = function (whitelist) { | |||
var outputType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "global"; | |||
var namespace = t.identifier("babelHelpers"); | |||
var builder = function builder(body) { | |||
return buildHelpers(body, namespace, whitelist); | |||
}; | |||
var tree = void 0; | |||
var build = { | |||
global: buildGlobal, | |||
umd: buildUmd, | |||
var: buildVar | |||
}[outputType]; | |||
if (build) { | |||
tree = build(namespace, builder); | |||
} else { | |||
throw new Error(messages.get("unsupportedOutputType", outputType)); | |||
} | |||
return (0, _babelGenerator2.default)(tree).code; | |||
}; | |||
var _babelHelpers = require("babel-helpers"); | |||
var helpers = _interopRequireWildcard(_babelHelpers); | |||
var _babelGenerator = require("babel-generator"); | |||
var _babelGenerator2 = _interopRequireDefault(_babelGenerator); | |||
var _babelMessages = require("babel-messages"); | |||
var messages = _interopRequireWildcard(_babelMessages); | |||
var _babelTemplate = require("babel-template"); | |||
var _babelTemplate2 = _interopRequireDefault(_babelTemplate); | |||
var _each = require("lodash/each"); | |||
var _each2 = _interopRequireDefault(_each); | |||
var _babelTypes = require("babel-types"); | |||
var t = _interopRequireWildcard(_babelTypes); | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | |||
var buildUmdWrapper = (0, _babelTemplate2.default)("\n (function (root, factory) {\n if (typeof define === \"function\" && define.amd) {\n define(AMD_ARGUMENTS, factory);\n } else if (typeof exports === \"object\") {\n factory(COMMON_ARGUMENTS);\n } else {\n factory(BROWSER_ARGUMENTS);\n }\n })(UMD_ROOT, function (FACTORY_PARAMETERS) {\n FACTORY_BODY\n });\n"); | |||
function buildGlobal(namespace, builder) { | |||
var body = []; | |||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body)); | |||
var tree = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]); | |||
body.push(t.variableDeclaration("var", [t.variableDeclarator(namespace, t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([])))])); | |||
builder(body); | |||
return tree; | |||
} | |||
function buildUmd(namespace, builder) { | |||
var body = []; | |||
body.push(t.variableDeclaration("var", [t.variableDeclarator(namespace, t.identifier("global"))])); | |||
builder(body); | |||
return t.program([buildUmdWrapper({ | |||
FACTORY_PARAMETERS: t.identifier("global"), | |||
BROWSER_ARGUMENTS: t.assignmentExpression("=", t.memberExpression(t.identifier("root"), namespace), t.objectExpression([])), | |||
COMMON_ARGUMENTS: t.identifier("exports"), | |||
AMD_ARGUMENTS: t.arrayExpression([t.stringLiteral("exports")]), | |||
FACTORY_BODY: body, | |||
UMD_ROOT: t.identifier("this") | |||
})]); | |||
} | |||
function buildVar(namespace, builder) { | |||
var body = []; | |||
body.push(t.variableDeclaration("var", [t.variableDeclarator(namespace, t.objectExpression([]))])); | |||
builder(body); | |||
body.push(t.expressionStatement(namespace)); | |||
return t.program(body); | |||
} | |||
function buildHelpers(body, namespace, whitelist) { | |||
(0, _each2.default)(helpers.list, function (name) { | |||
if (whitelist && whitelist.indexOf(name) < 0) return; | |||
var key = t.identifier(name); | |||
body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(namespace, key), helpers.get(name)))); | |||
}); | |||
} | |||
module.exports = exports["default"]; |
@@ -0,0 +1,747 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
exports.File = undefined; | |||
var _typeof2 = require("babel-runtime/helpers/typeof"); | |||
var _typeof3 = _interopRequireDefault(_typeof2); | |||
var _getIterator2 = require("babel-runtime/core-js/get-iterator"); | |||
var _getIterator3 = _interopRequireDefault(_getIterator2); | |||
var _create = require("babel-runtime/core-js/object/create"); | |||
var _create2 = _interopRequireDefault(_create); | |||
var _assign = require("babel-runtime/core-js/object/assign"); | |||
var _assign2 = _interopRequireDefault(_assign); | |||
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck"); | |||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | |||
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn"); | |||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | |||
var _inherits2 = require("babel-runtime/helpers/inherits"); | |||
var _inherits3 = _interopRequireDefault(_inherits2); | |||
var _babelHelpers = require("babel-helpers"); | |||
var _babelHelpers2 = _interopRequireDefault(_babelHelpers); | |||
var _metadata = require("./metadata"); | |||
var metadataVisitor = _interopRequireWildcard(_metadata); | |||
var _convertSourceMap = require("convert-source-map"); | |||
var _convertSourceMap2 = _interopRequireDefault(_convertSourceMap); | |||
var _optionManager = require("./options/option-manager"); | |||
var _optionManager2 = _interopRequireDefault(_optionManager); | |||
var _pluginPass = require("../plugin-pass"); | |||
var _pluginPass2 = _interopRequireDefault(_pluginPass); | |||
var _babelTraverse = require("babel-traverse"); | |||
var _babelTraverse2 = _interopRequireDefault(_babelTraverse); | |||
var _sourceMap = require("source-map"); | |||
var _sourceMap2 = _interopRequireDefault(_sourceMap); | |||
var _babelGenerator = require("babel-generator"); | |||
var _babelGenerator2 = _interopRequireDefault(_babelGenerator); | |||
var _babelCodeFrame = require("babel-code-frame"); | |||
var _babelCodeFrame2 = _interopRequireDefault(_babelCodeFrame); | |||
var _defaults = require("lodash/defaults"); | |||
var _defaults2 = _interopRequireDefault(_defaults); | |||
var _logger = require("./logger"); | |||
var _logger2 = _interopRequireDefault(_logger); | |||
var _store = require("../../store"); | |||
var _store2 = _interopRequireDefault(_store); | |||
var _babylon = require("babylon"); | |||
var _util = require("../../util"); | |||
var util = _interopRequireWildcard(_util); | |||
var _path = require("path"); | |||
var _path2 = _interopRequireDefault(_path); | |||
var _babelTypes = require("babel-types"); | |||
var t = _interopRequireWildcard(_babelTypes); | |||
var _resolve = require("../../helpers/resolve"); | |||
var _resolve2 = _interopRequireDefault(_resolve); | |||
var _blockHoist = require("../internal-plugins/block-hoist"); | |||
var _blockHoist2 = _interopRequireDefault(_blockHoist); | |||
var _shadowFunctions = require("../internal-plugins/shadow-functions"); | |||
var _shadowFunctions2 = _interopRequireDefault(_shadowFunctions); | |||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
var shebangRegex = /^#!.*/; | |||
var INTERNAL_PLUGINS = [[_blockHoist2.default], [_shadowFunctions2.default]]; | |||
var errorVisitor = { | |||
enter: function enter(path, state) { | |||
var loc = path.node.loc; | |||
if (loc) { | |||
state.loc = loc; | |||
path.stop(); | |||
} | |||
} | |||
}; | |||
var File = function (_Store) { | |||
(0, _inherits3.default)(File, _Store); | |||
function File() { | |||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | |||
var pipeline = arguments[1]; | |||
(0, _classCallCheck3.default)(this, File); | |||
var _this = (0, _possibleConstructorReturn3.default)(this, _Store.call(this)); | |||
_this.pipeline = pipeline; | |||
_this.log = new _logger2.default(_this, opts.filename || "unknown"); | |||
_this.opts = _this.initOptions(opts); | |||
_this.parserOpts = { | |||
sourceType: _this.opts.sourceType, | |||
sourceFileName: _this.opts.filename, | |||
plugins: [] | |||
}; | |||
_this.pluginVisitors = []; | |||
_this.pluginPasses = []; | |||
_this.buildPluginsForOptions(_this.opts); | |||
if (_this.opts.passPerPreset) { | |||
_this.perPresetOpts = []; | |||
_this.opts.presets.forEach(function (presetOpts) { | |||
var perPresetOpts = (0, _assign2.default)((0, _create2.default)(_this.opts), presetOpts); | |||
_this.perPresetOpts.push(perPresetOpts); | |||
_this.buildPluginsForOptions(perPresetOpts); | |||
}); | |||
} | |||
_this.metadata = { | |||
usedHelpers: [], | |||
marked: [], | |||
modules: { | |||
imports: [], | |||
exports: { | |||
exported: [], | |||
specifiers: [] | |||
} | |||
} | |||
}; | |||
_this.dynamicImportTypes = {}; | |||
_this.dynamicImportIds = {}; | |||
_this.dynamicImports = []; | |||
_this.declarations = {}; | |||
_this.usedHelpers = {}; | |||
_this.path = null; | |||
_this.ast = {}; | |||
_this.code = ""; | |||
_this.shebang = ""; | |||
_this.hub = new _babelTraverse.Hub(_this); | |||
return _this; | |||
} | |||
File.prototype.getMetadata = function getMetadata() { | |||
var has = false; | |||
for (var _iterator = this.ast.program.body, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) { | |||
var _ref; | |||
if (_isArray) { | |||
if (_i >= _iterator.length) break; | |||
_ref = _iterator[_i++]; | |||
} else { | |||
_i = _iterator.next(); | |||
if (_i.done) break; | |||
_ref = _i.value; | |||
} | |||
var node = _ref; | |||
if (t.isModuleDeclaration(node)) { | |||
has = true; | |||
break; | |||
} | |||
} | |||
if (has) { | |||
this.path.traverse(metadataVisitor, this); | |||
} | |||
}; | |||
File.prototype.initOptions = function initOptions(opts) { | |||
opts = new _optionManager2.default(this.log, this.pipeline).init(opts); | |||
if (opts.inputSourceMap) { | |||
opts.sourceMaps = true; | |||
} | |||
if (opts.moduleId) { | |||
opts.moduleIds = true; | |||
} | |||
opts.basename = _path2.default.basename(opts.filename, _path2.default.extname(opts.filename)); | |||
opts.ignore = util.arrayify(opts.ignore, util.regexify); | |||
if (opts.only) opts.only = util.arrayify(opts.only, util.regexify); | |||
(0, _defaults2.default)(opts, { | |||
moduleRoot: opts.sourceRoot | |||
}); | |||
(0, _defaults2.default)(opts, { | |||
sourceRoot: opts.moduleRoot | |||
}); | |||
(0, _defaults2.default)(opts, { | |||
filenameRelative: opts.filename | |||
}); | |||
var basenameRelative = _path2.default.basename(opts.filenameRelative); | |||
(0, _defaults2.default)(opts, { | |||
sourceFileName: basenameRelative, | |||
sourceMapTarget: basenameRelative | |||
}); | |||
return opts; | |||
}; | |||
File.prototype.buildPluginsForOptions = function buildPluginsForOptions(opts) { | |||
if (!Array.isArray(opts.plugins)) { | |||
return; | |||
} | |||
var plugins = opts.plugins.concat(INTERNAL_PLUGINS); | |||
var currentPluginVisitors = []; | |||
var currentPluginPasses = []; | |||
for (var _iterator2 = plugins, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) { | |||
var _ref2; | |||
if (_isArray2) { | |||
if (_i2 >= _iterator2.length) break; | |||
_ref2 = _iterator2[_i2++]; | |||
} else { | |||
_i2 = _iterator2.next(); | |||
if (_i2.done) break; | |||
_ref2 = _i2.value; | |||
} | |||
var ref = _ref2; | |||
var plugin = ref[0], | |||
pluginOpts = ref[1]; | |||
currentPluginVisitors.push(plugin.visitor); | |||
currentPluginPasses.push(new _pluginPass2.default(this, plugin, pluginOpts)); | |||
if (plugin.manipulateOptions) { | |||
plugin.manipulateOptions(opts, this.parserOpts, this); | |||
} | |||
} | |||
this.pluginVisitors.push(currentPluginVisitors); | |||
this.pluginPasses.push(currentPluginPasses); | |||
}; | |||
File.prototype.getModuleName = function getModuleName() { | |||
var opts = this.opts; | |||
if (!opts.moduleIds) { | |||
return null; | |||
} | |||
if (opts.moduleId != null && !opts.getModuleId) { | |||
return opts.moduleId; | |||
} | |||
var filenameRelative = opts.filenameRelative; | |||
var moduleName = ""; | |||
if (opts.moduleRoot != null) { | |||
moduleName = opts.moduleRoot + "/"; | |||
} | |||
if (!opts.filenameRelative) { | |||
return moduleName + opts.filename.replace(/^\//, ""); | |||
} | |||
if (opts.sourceRoot != null) { | |||
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?"); | |||
filenameRelative = filenameRelative.replace(sourceRootRegEx, ""); | |||
} | |||
filenameRelative = filenameRelative.replace(/\.(\w*?)$/, ""); | |||
moduleName += filenameRelative; | |||
moduleName = moduleName.replace(/\\/g, "/"); | |||
if (opts.getModuleId) { | |||
return opts.getModuleId(moduleName) || moduleName; | |||
} else { | |||
return moduleName; | |||
} | |||
}; | |||
File.prototype.resolveModuleSource = function resolveModuleSource(source) { | |||
var resolveModuleSource = this.opts.resolveModuleSource; | |||
if (resolveModuleSource) source = resolveModuleSource(source, this.opts.filename); | |||
return source; | |||
}; | |||
File.prototype.addImport = function addImport(source, imported) { | |||
var name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : imported; | |||
var alias = source + ":" + imported; | |||
var id = this.dynamicImportIds[alias]; | |||
if (!id) { | |||
source = this.resolveModuleSource(source); | |||
id = this.dynamicImportIds[alias] = this.scope.generateUidIdentifier(name); | |||
var specifiers = []; | |||
if (imported === "*") { | |||
specifiers.push(t.importNamespaceSpecifier(id)); | |||
} else if (imported === "default") { | |||
specifiers.push(t.importDefaultSpecifier(id)); | |||
} else { | |||
specifiers.push(t.importSpecifier(id, t.identifier(imported))); | |||
} | |||
var declar = t.importDeclaration(specifiers, t.stringLiteral(source)); | |||
declar._blockHoist = 3; | |||
this.path.unshiftContainer("body", declar); | |||
} | |||
return id; | |||
}; | |||
File.prototype.addHelper = function addHelper(name) { | |||
var declar = this.declarations[name]; | |||
if (declar) return declar; | |||
if (!this.usedHelpers[name]) { | |||
this.metadata.usedHelpers.push(name); | |||
this.usedHelpers[name] = true; | |||
} | |||
var generator = this.get("helperGenerator"); | |||
var runtime = this.get("helpersNamespace"); | |||
if (generator) { | |||
var res = generator(name); | |||
if (res) return res; | |||
} else if (runtime) { | |||
return t.memberExpression(runtime, t.identifier(name)); | |||
} | |||
var ref = (0, _babelHelpers2.default)(name); | |||
var uid = this.declarations[name] = this.scope.generateUidIdentifier(name); | |||
if (t.isFunctionExpression(ref) && !ref.id) { | |||
ref.body._compact = true; | |||
ref._generated = true; | |||
ref.id = uid; | |||
ref.type = "FunctionDeclaration"; | |||
this.path.unshiftContainer("body", ref); | |||
} else { | |||
ref._compact = true; | |||
this.scope.push({ | |||
id: uid, | |||
init: ref, | |||
unique: true | |||
}); | |||
} | |||
return uid; | |||
}; | |||
File.prototype.addTemplateObject = function addTemplateObject(helperName, strings, raw) { | |||
var stringIds = raw.elements.map(function (string) { | |||
return string.value; | |||
}); | |||
var name = helperName + "_" + raw.elements.length + "_" + stringIds.join(","); | |||
var declar = this.declarations[name]; | |||
if (declar) return declar; | |||
var uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject"); | |||
var helperId = this.addHelper(helperName); | |||
var init = t.callExpression(helperId, [strings, raw]); | |||
init._compact = true; | |||
this.scope.push({ | |||
id: uid, | |||
init: init, | |||
_blockHoist: 1.9 }); | |||
return uid; | |||
}; | |||
File.prototype.buildCodeFrameError = function buildCodeFrameError(node, msg) { | |||
var Error = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : SyntaxError; | |||
var loc = node && (node.loc || node._loc); | |||
var err = new Error(msg); | |||
if (loc) { | |||
err.loc = loc.start; | |||
} else { | |||
(0, _babelTraverse2.default)(node, errorVisitor, this.scope, err); | |||
err.message += " (This is an error on an internal node. Probably an internal error"; | |||
if (err.loc) { | |||
err.message += ". Location has been estimated."; | |||
} | |||
err.message += ")"; | |||
} | |||
return err; | |||
}; | |||
File.prototype.mergeSourceMap = function mergeSourceMap(map) { | |||
var inputMap = this.opts.inputSourceMap; | |||
if (inputMap) { | |||
var _ret = function () { | |||
var inputMapConsumer = new _sourceMap2.default.SourceMapConsumer(inputMap); | |||
var outputMapConsumer = new _sourceMap2.default.SourceMapConsumer(map); | |||
var mergedGenerator = new _sourceMap2.default.SourceMapGenerator({ | |||
file: inputMapConsumer.file, | |||
sourceRoot: inputMapConsumer.sourceRoot | |||
}); | |||
var source = outputMapConsumer.sources[0]; | |||
inputMapConsumer.eachMapping(function (mapping) { | |||
var generatedPosition = outputMapConsumer.generatedPositionFor({ | |||
line: mapping.generatedLine, | |||
column: mapping.generatedColumn, | |||
source: source | |||
}); | |||
if (generatedPosition.column != null) { | |||
mergedGenerator.addMapping({ | |||
source: mapping.source, | |||
original: mapping.source == null ? null : { | |||
line: mapping.originalLine, | |||
column: mapping.originalColumn | |||
}, | |||
generated: generatedPosition | |||
}); | |||
} | |||
}); | |||
var mergedMap = mergedGenerator.toJSON(); | |||
inputMap.mappings = mergedMap.mappings; | |||
return { | |||
v: inputMap | |||
}; | |||
}(); | |||
if ((typeof _ret === "undefined" ? "undefined" : (0, _typeof3.default)(_ret)) === "object") return _ret.v; | |||
} else { | |||
return map; | |||
} | |||
}; | |||
File.prototype.parse = function parse(code) { | |||
var parseCode = _babylon.parse; | |||
var parserOpts = this.opts.parserOpts; | |||
if (parserOpts) { | |||
parserOpts = (0, _assign2.default)({}, this.parserOpts, parserOpts); | |||
if (parserOpts.parser) { | |||
if (typeof parserOpts.parser === "string") { | |||
var dirname = _path2.default.dirname(this.opts.filename) || process.cwd(); | |||
var parser = (0, _resolve2.default)(parserOpts.parser, dirname); | |||
if (parser) { | |||
parseCode = require(parser).parse; | |||
} else { | |||
throw new Error("Couldn't find parser " + parserOpts.parser + " with \"parse\" method relative to directory " + dirname); | |||
} | |||
} else { | |||
parseCode = parserOpts.parser; | |||
} | |||
parserOpts.parser = { | |||
parse: function parse(source) { | |||
return (0, _babylon.parse)(source, parserOpts); | |||
} | |||
}; | |||
} | |||
} | |||
this.log.debug("Parse start"); | |||
var ast = parseCode(code, parserOpts || this.parserOpts); | |||
this.log.debug("Parse stop"); | |||
return ast; | |||
}; | |||
File.prototype._addAst = function _addAst(ast) { | |||
this.path = _babelTraverse.NodePath.get({ | |||
hub: this.hub, | |||
parentPath: null, | |||
parent: ast, | |||
container: ast, | |||
key: "program" | |||
}).setContext(); | |||
this.scope = this.path.scope; | |||
this.ast = ast; | |||
this.getMetadata(); | |||
}; | |||
File.prototype.addAst = function addAst(ast) { | |||
this.log.debug("Start set AST"); | |||
this._addAst(ast); | |||
this.log.debug("End set AST"); | |||
}; | |||
File.prototype.transform = function transform() { | |||
for (var i = 0; i < this.pluginPasses.length; i++) { | |||
var pluginPasses = this.pluginPasses[i]; | |||
this.call("pre", pluginPasses); | |||
this.log.debug("Start transform traverse"); | |||
var visitor = _babelTraverse2.default.visitors.merge(this.pluginVisitors[i], pluginPasses, this.opts.wrapPluginVisitorMethod); | |||
(0, _babelTraverse2.default)(this.ast, visitor, this.scope); | |||
this.log.debug("End transform traverse"); | |||
this.call("post", pluginPasses); | |||
} | |||
return this.generate(); | |||
}; | |||
File.prototype.wrap = function wrap(code, callback) { | |||
code = code + ""; | |||
try { | |||
if (this.shouldIgnore()) { | |||
return this.makeResult({ code: code, ignored: true }); | |||
} else { | |||
return callback(); | |||
} | |||
} catch (err) { | |||
if (err._babel) { | |||
throw err; | |||
} else { | |||
err._babel = true; | |||
} | |||
var message = err.message = this.opts.filename + ": " + err.message; | |||
var loc = err.loc; | |||
if (loc) { | |||
err.codeFrame = (0, _babelCodeFrame2.default)(code, loc.line, loc.column + 1, this.opts); | |||
message += "\n" + err.codeFrame; | |||
} | |||
if (process.browser) { | |||
err.message = message; | |||
} | |||
if (err.stack) { | |||
var newStack = err.stack.replace(err.message, message); | |||
err.stack = newStack; | |||
} | |||
throw err; | |||
} | |||
}; | |||
File.prototype.addCode = function addCode(code) { | |||
code = (code || "") + ""; | |||
code = this.parseInputSourceMap(code); | |||
this.code = code; | |||
}; | |||
File.prototype.parseCode = function parseCode() { | |||
this.parseShebang(); | |||
var ast = this.parse(this.code); | |||
this.addAst(ast); | |||
}; | |||
File.prototype.shouldIgnore = function shouldIgnore() { | |||
var opts = this.opts; | |||
return util.shouldIgnore(opts.filename, opts.ignore, opts.only); | |||
}; | |||
File.prototype.call = function call(key, pluginPasses) { | |||
for (var _iterator3 = pluginPasses, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) { | |||
var _ref3; | |||
if (_isArray3) { | |||
if (_i3 >= _iterator3.length) break; | |||
_ref3 = _iterator3[_i3++]; | |||
} else { | |||
_i3 = _iterator3.next(); | |||
if (_i3.done) break; | |||
_ref3 = _i3.value; | |||
} | |||
var pass = _ref3; | |||
var plugin = pass.plugin; | |||
var fn = plugin[key]; | |||
if (fn) fn.call(pass, this); | |||
} | |||
}; | |||
File.prototype.parseInputSourceMap = function parseInputSourceMap(code) { | |||
var opts = this.opts; | |||
if (opts.inputSourceMap !== false) { | |||
var inputMap = _convertSourceMap2.default.fromSource(code); | |||
if (inputMap) { | |||
opts.inputSourceMap = inputMap.toObject(); | |||
code = _convertSourceMap2.default.removeComments(code); | |||
} | |||
} | |||
return code; | |||
}; | |||
File.prototype.parseShebang = function parseShebang() { | |||
var shebangMatch = shebangRegex.exec(this.code); | |||
if (shebangMatch) { | |||
this.shebang = shebangMatch[0]; | |||
this.code = this.code.replace(shebangRegex, ""); | |||
} | |||
}; | |||
File.prototype.makeResult = function makeResult(_ref4) { | |||
var code = _ref4.code, | |||
map = _ref4.map, | |||
ast = _ref4.ast, | |||
ignored = _ref4.ignored; | |||
var result = { | |||
metadata: null, | |||
options: this.opts, | |||
ignored: !!ignored, | |||
code: null, | |||
ast: null, | |||
map: map || null | |||
}; | |||
if (this.opts.code) { | |||
result.code = code; | |||
} | |||
if (this.opts.ast) { | |||
result.ast = ast; | |||
} | |||
if (this.opts.metadata) { | |||
result.metadata = this.metadata; | |||
} | |||
return result; | |||
}; | |||
File.prototype.generate = function generate() { | |||
var opts = this.opts; | |||
var ast = this.ast; | |||
var result = { ast: ast }; | |||
if (!opts.code) return this.makeResult(result); | |||
var gen = _babelGenerator2.default; | |||
if (opts.generatorOpts.generator) { | |||
gen = opts.generatorOpts.generator; | |||
if (typeof gen === "string") { | |||
var dirname = _path2.default.dirname(this.opts.filename) || process.cwd(); | |||
var generator = (0, _resolve2.default)(gen, dirname); | |||
if (generator) { | |||
gen = require(generator).print; | |||
} else { | |||
throw new Error("Couldn't find generator " + gen + " with \"print\" method relative to directory " + dirname); | |||
} | |||
} | |||
} | |||
this.log.debug("Generation start"); | |||
var _result = gen(ast, opts.generatorOpts ? (0, _assign2.default)(opts, opts.generatorOpts) : opts, this.code); | |||
result.code = _result.code; | |||
result.map = _result.map; | |||
this.log.debug("Generation end"); | |||
if (this.shebang) { | |||
result.code = this.shebang + "\n" + result.code; | |||
} | |||
if (result.map) { | |||
result.map = this.mergeSourceMap(result.map); | |||
} | |||
if (opts.sourceMaps === "inline" || opts.sourceMaps === "both") { | |||
result.code += "\n" + _convertSourceMap2.default.fromObject(result.map).toComment(); | |||
} | |||
if (opts.sourceMaps === "inline") { | |||
result.map = null; | |||
} | |||
return this.makeResult(result); | |||
}; | |||
return File; | |||
}(_store2.default); | |||
exports.default = File; | |||
exports.File = File; |
@@ -0,0 +1,72 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck"); | |||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | |||
var _node = require("debug/node"); | |||
var _node2 = _interopRequireDefault(_node); | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
var verboseDebug = (0, _node2.default)("babel:verbose"); | |||
var generalDebug = (0, _node2.default)("babel"); | |||
var seenDeprecatedMessages = []; | |||
var Logger = function () { | |||
function Logger(file, filename) { | |||
(0, _classCallCheck3.default)(this, Logger); | |||
this.filename = filename; | |||
this.file = file; | |||
} | |||
Logger.prototype._buildMessage = function _buildMessage(msg) { | |||
var parts = "[BABEL] " + this.filename; | |||
if (msg) parts += ": " + msg; | |||
return parts; | |||
}; | |||
Logger.prototype.warn = function warn(msg) { | |||
console.warn(this._buildMessage(msg)); | |||
}; | |||
Logger.prototype.error = function error(msg) { | |||
var Constructor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Error; | |||
throw new Constructor(this._buildMessage(msg)); | |||
}; | |||
Logger.prototype.deprecate = function deprecate(msg) { | |||
if (this.file.opts && this.file.opts.suppressDeprecationMessages) return; | |||
msg = this._buildMessage(msg); | |||
if (seenDeprecatedMessages.indexOf(msg) >= 0) return; | |||
seenDeprecatedMessages.push(msg); | |||
console.error(msg); | |||
}; | |||
Logger.prototype.verbose = function verbose(msg) { | |||
if (verboseDebug.enabled) verboseDebug(this._buildMessage(msg)); | |||
}; | |||
Logger.prototype.debug = function debug(msg) { | |||
if (generalDebug.enabled) generalDebug(this._buildMessage(msg)); | |||
}; | |||
Logger.prototype.deopt = function deopt(node, msg) { | |||
this.debug(msg); | |||
}; | |||
return Logger; | |||
}(); | |||
exports.default = Logger; | |||
module.exports = exports["default"]; |
@@ -0,0 +1,178 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
exports.ImportDeclaration = exports.ModuleDeclaration = undefined; | |||
var _getIterator2 = require("babel-runtime/core-js/get-iterator"); | |||
var _getIterator3 = _interopRequireDefault(_getIterator2); | |||
exports.ExportDeclaration = ExportDeclaration; | |||
exports.Scope = Scope; | |||
var _babelTypes = require("babel-types"); | |||
var t = _interopRequireWildcard(_babelTypes); | |||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
var ModuleDeclaration = exports.ModuleDeclaration = { | |||
enter: function enter(path, file) { | |||
var node = path.node; | |||
if (node.source) { | |||
node.source.value = file.resolveModuleSource(node.source.value); | |||
} | |||
} | |||
}; | |||
var ImportDeclaration = exports.ImportDeclaration = { | |||
exit: function exit(path, file) { | |||
var node = path.node; | |||
var specifiers = []; | |||
var imported = []; | |||
file.metadata.modules.imports.push({ | |||
source: node.source.value, | |||
imported: imported, | |||
specifiers: specifiers | |||
}); | |||
for (var _iterator = path.get("specifiers"), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) { | |||
var _ref; | |||
if (_isArray) { | |||
if (_i >= _iterator.length) break; | |||
_ref = _iterator[_i++]; | |||
} else { | |||
_i = _iterator.next(); | |||
if (_i.done) break; | |||
_ref = _i.value; | |||
} | |||
var specifier = _ref; | |||
var local = specifier.node.local.name; | |||
if (specifier.isImportDefaultSpecifier()) { | |||
imported.push("default"); | |||
specifiers.push({ | |||
kind: "named", | |||
imported: "default", | |||
local: local | |||
}); | |||
} | |||
if (specifier.isImportSpecifier()) { | |||
var importedName = specifier.node.imported.name; | |||
imported.push(importedName); | |||
specifiers.push({ | |||
kind: "named", | |||
imported: importedName, | |||
local: local | |||
}); | |||
} | |||
if (specifier.isImportNamespaceSpecifier()) { | |||
imported.push("*"); | |||
specifiers.push({ | |||
kind: "namespace", | |||
local: local | |||
}); | |||
} | |||
} | |||
} | |||
}; | |||
function ExportDeclaration(path, file) { | |||
var node = path.node; | |||
var source = node.source ? node.source.value : null; | |||
var exports = file.metadata.modules.exports; | |||
var declar = path.get("declaration"); | |||
if (declar.isStatement()) { | |||
var bindings = declar.getBindingIdentifiers(); | |||
for (var name in bindings) { | |||
exports.exported.push(name); | |||
exports.specifiers.push({ | |||
kind: "local", | |||
local: name, | |||
exported: path.isExportDefaultDeclaration() ? "default" : name | |||
}); | |||
} | |||
} | |||
if (path.isExportNamedDeclaration() && node.specifiers) { | |||
for (var _iterator2 = node.specifiers, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) { | |||
var _ref2; | |||
if (_isArray2) { | |||
if (_i2 >= _iterator2.length) break; | |||
_ref2 = _iterator2[_i2++]; | |||
} else { | |||
_i2 = _iterator2.next(); | |||
if (_i2.done) break; | |||
_ref2 = _i2.value; | |||
} | |||
var specifier = _ref2; | |||
var exported = specifier.exported.name; | |||
exports.exported.push(exported); | |||
if (t.isExportDefaultSpecifier(specifier)) { | |||
exports.specifiers.push({ | |||
kind: "external", | |||
local: exported, | |||
exported: exported, | |||
source: source | |||
}); | |||
} | |||
if (t.isExportNamespaceSpecifier(specifier)) { | |||
exports.specifiers.push({ | |||
kind: "external-namespace", | |||
exported: exported, | |||
source: source | |||
}); | |||
} | |||
var local = specifier.local; | |||
if (!local) continue; | |||
if (source) { | |||
exports.specifiers.push({ | |||
kind: "external", | |||
local: local.name, | |||
exported: exported, | |||
source: source | |||
}); | |||
} | |||
if (!source) { | |||
exports.specifiers.push({ | |||
kind: "local", | |||
local: local.name, | |||
exported: exported | |||
}); | |||
} | |||
} | |||
} | |||
if (path.isExportAllDeclaration()) { | |||
exports.specifiers.push({ | |||
kind: "external-all", | |||
source: source | |||
}); | |||
} | |||
} | |||
function Scope(path) { | |||
path.skip(); | |||
} |
@@ -0,0 +1,215 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
var _assign = require("babel-runtime/core-js/object/assign"); | |||
var _assign2 = _interopRequireDefault(_assign); | |||
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck"); | |||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | |||
exports.default = buildConfigChain; | |||
var _resolve = require("../../../helpers/resolve"); | |||
var _resolve2 = _interopRequireDefault(_resolve); | |||
var _json = require("json5"); | |||
var _json2 = _interopRequireDefault(_json); | |||
var _pathIsAbsolute = require("path-is-absolute"); | |||
var _pathIsAbsolute2 = _interopRequireDefault(_pathIsAbsolute); | |||
var _path = require("path"); | |||
var _path2 = _interopRequireDefault(_path); | |||
var _fs = require("fs"); | |||
var _fs2 = _interopRequireDefault(_fs); | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
var existsCache = {}; | |||
var jsonCache = {}; | |||
var BABELIGNORE_FILENAME = ".babelignore"; | |||
var BABELRC_FILENAME = ".babelrc"; | |||
var PACKAGE_FILENAME = "package.json"; | |||
function exists(filename) { | |||
var cached = existsCache[filename]; | |||
if (cached == null) { | |||
return existsCache[filename] = _fs2.default.existsSync(filename); | |||
} else { | |||
return cached; | |||
} | |||
} | |||
function buildConfigChain() { | |||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | |||
var log = arguments[1]; | |||
var filename = opts.filename; | |||
var builder = new ConfigChainBuilder(log); | |||
if (opts.babelrc !== false) { | |||
builder.findConfigs(filename); | |||
} | |||
builder.mergeConfig({ | |||
options: opts, | |||
alias: "base", | |||
dirname: filename && _path2.default.dirname(filename) | |||
}); | |||
return builder.configs; | |||
} | |||
var ConfigChainBuilder = function () { | |||
function ConfigChainBuilder(log) { | |||
(0, _classCallCheck3.default)(this, ConfigChainBuilder); | |||
this.resolvedConfigs = []; | |||
this.configs = []; | |||
this.log = log; | |||
} | |||
ConfigChainBuilder.prototype.findConfigs = function findConfigs(loc) { | |||
if (!loc) return; | |||
if (!(0, _pathIsAbsolute2.default)(loc)) { | |||
loc = _path2.default.join(process.cwd(), loc); | |||
} | |||
var foundConfig = false; | |||
var foundIgnore = false; | |||
while (loc !== (loc = _path2.default.dirname(loc))) { | |||
if (!foundConfig) { | |||
var configLoc = _path2.default.join(loc, BABELRC_FILENAME); | |||
if (exists(configLoc)) { | |||
this.addConfig(configLoc); | |||
foundConfig = true; | |||
} | |||
var pkgLoc = _path2.default.join(loc, PACKAGE_FILENAME); | |||
if (!foundConfig && exists(pkgLoc)) { | |||
foundConfig = this.addConfig(pkgLoc, "babel", JSON); | |||
} | |||
} | |||
if (!foundIgnore) { | |||
var ignoreLoc = _path2.default.join(loc, BABELIGNORE_FILENAME); | |||
if (exists(ignoreLoc)) { | |||
this.addIgnoreConfig(ignoreLoc); | |||
foundIgnore = true; | |||
} | |||
} | |||
if (foundIgnore && foundConfig) return; | |||
} | |||
}; | |||
ConfigChainBuilder.prototype.addIgnoreConfig = function addIgnoreConfig(loc) { | |||
var file = _fs2.default.readFileSync(loc, "utf8"); | |||
var lines = file.split("\n"); | |||
lines = lines.map(function (line) { | |||
return line.replace(/#(.*?)$/, "").trim(); | |||
}).filter(function (line) { | |||
return !!line; | |||
}); | |||
if (lines.length) { | |||
this.mergeConfig({ | |||
options: { ignore: lines }, | |||
alias: loc, | |||
dirname: _path2.default.dirname(loc) | |||
}); | |||
} | |||
}; | |||
ConfigChainBuilder.prototype.addConfig = function addConfig(loc, key) { | |||
var json = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _json2.default; | |||
if (this.resolvedConfigs.indexOf(loc) >= 0) { | |||
return false; | |||
} | |||
this.resolvedConfigs.push(loc); | |||
var content = _fs2.default.readFileSync(loc, "utf8"); | |||
var options = void 0; | |||
try { | |||
options = jsonCache[content] = jsonCache[content] || json.parse(content); | |||
if (key) options = options[key]; | |||
} catch (err) { | |||
err.message = loc + ": Error while parsing JSON - " + err.message; | |||
throw err; | |||
} | |||
this.mergeConfig({ | |||
options: options, | |||
alias: loc, | |||
dirname: _path2.default.dirname(loc) | |||
}); | |||
return !!options; | |||
}; | |||
ConfigChainBuilder.prototype.mergeConfig = function mergeConfig(_ref) { | |||
var options = _ref.options, | |||
alias = _ref.alias, | |||
loc = _ref.loc, | |||
dirname = _ref.dirname; | |||
if (!options) { | |||
return false; | |||
} | |||
options = (0, _assign2.default)({}, options); | |||
dirname = dirname || process.cwd(); | |||
loc = loc || alias; | |||
if (options.extends) { | |||
var extendsLoc = (0, _resolve2.default)(options.extends, dirname); | |||
if (extendsLoc) { | |||
this.addConfig(extendsLoc); | |||
} else { | |||
if (this.log) this.log.error("Couldn't resolve extends clause of " + options.extends + " in " + alias); | |||
} | |||
delete options.extends; | |||
} | |||
this.configs.push({ | |||
options: options, | |||
alias: alias, | |||
loc: loc, | |||
dirname: dirname | |||
}); | |||
var envOpts = void 0; | |||
var envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development"; | |||
if (options.env) { | |||
envOpts = options.env[envKey]; | |||
delete options.env; | |||
} | |||
this.mergeConfig({ | |||
options: envOpts, | |||
alias: alias + ".env." + envKey, | |||
dirname: dirname | |||
}); | |||
}; | |||
return ConfigChainBuilder; | |||
}(); | |||
module.exports = exports["default"]; |
@@ -0,0 +1,211 @@ | |||
"use strict"; | |||
module.exports = { | |||
filename: { | |||
type: "filename", | |||
description: "filename to use when reading from stdin - this will be used in source-maps, errors etc", | |||
default: "unknown", | |||
shorthand: "f" | |||
}, | |||
filenameRelative: { | |||
hidden: true, | |||
type: "string" | |||
}, | |||
inputSourceMap: { | |||
hidden: true | |||
}, | |||
env: { | |||
hidden: true, | |||
default: {} | |||
}, | |||
mode: { | |||
description: "", | |||
hidden: true | |||
}, | |||
retainLines: { | |||
type: "boolean", | |||
default: false, | |||
description: "retain line numbers - will result in really ugly code" | |||
}, | |||
highlightCode: { | |||
description: "enable/disable ANSI syntax highlighting of code frames (on by default)", | |||
type: "boolean", | |||
default: true | |||
}, | |||
suppressDeprecationMessages: { | |||
type: "boolean", | |||
default: false, | |||
hidden: true | |||
}, | |||
presets: { | |||
type: "list", | |||
description: "", | |||
default: [] | |||
}, | |||
plugins: { | |||
type: "list", | |||
default: [], | |||
description: "" | |||
}, | |||
ignore: { | |||
type: "list", | |||
description: "list of glob paths to **not** compile", | |||
default: [] | |||
}, | |||
only: { | |||
type: "list", | |||
description: "list of glob paths to **only** compile" | |||
}, | |||
code: { | |||
hidden: true, | |||
default: true, | |||
type: "boolean" | |||
}, | |||
metadata: { | |||
hidden: true, | |||
default: true, | |||
type: "boolean" | |||
}, | |||
ast: { | |||
hidden: true, | |||
default: true, | |||
type: "boolean" | |||
}, | |||
extends: { | |||
type: "string", | |||
hidden: true | |||
}, | |||
comments: { | |||
type: "boolean", | |||
default: true, | |||
description: "write comments to generated output (true by default)" | |||
}, | |||
shouldPrintComment: { | |||
hidden: true, | |||
description: "optional callback to control whether a comment should be inserted, when this is used the comments option is ignored" | |||
}, | |||
wrapPluginVisitorMethod: { | |||
hidden: true, | |||
description: "optional callback to wrap all visitor methods" | |||
}, | |||
compact: { | |||
type: "booleanString", | |||
default: "auto", | |||
description: "do not include superfluous whitespace characters and line terminators [true|false|auto]" | |||
}, | |||
minified: { | |||
type: "boolean", | |||
default: false, | |||
description: "save as much bytes when printing [true|false]" | |||
}, | |||
sourceMap: { | |||
alias: "sourceMaps", | |||
hidden: true | |||
}, | |||
sourceMaps: { | |||
type: "booleanString", | |||
description: "[true|false|inline]", | |||
default: false, | |||
shorthand: "s" | |||
}, | |||
sourceMapTarget: { | |||
type: "string", | |||
description: "set `file` on returned source map" | |||
}, | |||
sourceFileName: { | |||
type: "string", | |||
description: "set `sources[0]` on returned source map" | |||
}, | |||
sourceRoot: { | |||
type: "filename", | |||
description: "the root from which all sources are relative" | |||
}, | |||
babelrc: { | |||
description: "Whether or not to look up .babelrc and .babelignore files", | |||
type: "boolean", | |||
default: true | |||
}, | |||
sourceType: { | |||
description: "", | |||
default: "module" | |||
}, | |||
auxiliaryCommentBefore: { | |||
type: "string", | |||
description: "print a comment before any injected non-user code" | |||
}, | |||
auxiliaryCommentAfter: { | |||
type: "string", | |||
description: "print a comment after any injected non-user code" | |||
}, | |||
resolveModuleSource: { | |||
hidden: true | |||
}, | |||
getModuleId: { | |||
hidden: true | |||
}, | |||
moduleRoot: { | |||
type: "filename", | |||
description: "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions" | |||
}, | |||
moduleIds: { | |||
type: "boolean", | |||
default: false, | |||
shorthand: "M", | |||
description: "insert an explicit id for modules" | |||
}, | |||
moduleId: { | |||
description: "specify a custom name for module ids", | |||
type: "string" | |||
}, | |||
passPerPreset: { | |||
description: "Whether to spawn a traversal pass per a preset. By default all presets are merged.", | |||
type: "boolean", | |||
default: false, | |||
hidden: true | |||
}, | |||
parserOpts: { | |||
description: "Options to pass into the parser, or to change parsers (parserOpts.parser)", | |||
default: false | |||
}, | |||
generatorOpts: { | |||
description: "Options to pass into the generator, or to change generators (generatorOpts.generator)", | |||
default: false | |||
} | |||
}; |
@@ -0,0 +1,38 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
exports.config = undefined; | |||
exports.normaliseOptions = normaliseOptions; | |||
var _parsers = require("./parsers"); | |||
var parsers = _interopRequireWildcard(_parsers); | |||
var _config = require("./config"); | |||
var _config2 = _interopRequireDefault(_config); | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | |||
exports.config = _config2.default; | |||
function normaliseOptions() { | |||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | |||
for (var key in options) { | |||
var val = options[key]; | |||
if (val == null) continue; | |||
var opt = _config2.default[key]; | |||
if (opt && opt.alias) opt = _config2.default[opt.alias]; | |||
if (!opt) continue; | |||
var parser = parsers[opt.type]; | |||
if (parser) val = parser(val); | |||
options[key] = val; | |||
} | |||
return options; | |||
} |
@@ -0,0 +1,389 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
var _objectWithoutProperties2 = require("babel-runtime/helpers/objectWithoutProperties"); | |||
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2); | |||
var _stringify = require("babel-runtime/core-js/json/stringify"); | |||
var _stringify2 = _interopRequireDefault(_stringify); | |||
var _assign = require("babel-runtime/core-js/object/assign"); | |||
var _assign2 = _interopRequireDefault(_assign); | |||
var _getIterator2 = require("babel-runtime/core-js/get-iterator"); | |||
var _getIterator3 = _interopRequireDefault(_getIterator2); | |||
var _typeof2 = require("babel-runtime/helpers/typeof"); | |||
var _typeof3 = _interopRequireDefault(_typeof2); | |||
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck"); | |||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | |||
var _node = require("../../../api/node"); | |||
var context = _interopRequireWildcard(_node); | |||
var _plugin2 = require("../../plugin"); | |||
var _plugin3 = _interopRequireDefault(_plugin2); | |||
var _babelMessages = require("babel-messages"); | |||
var messages = _interopRequireWildcard(_babelMessages); | |||
var _index = require("./index"); | |||
var _resolve = require("../../../helpers/resolve"); | |||
var _resolve2 = _interopRequireDefault(_resolve); | |||
var _cloneDeepWith = require("lodash/cloneDeepWith"); | |||
var _cloneDeepWith2 = _interopRequireDefault(_cloneDeepWith); | |||
var _clone = require("lodash/clone"); | |||
var _clone2 = _interopRequireDefault(_clone); | |||
var _merge = require("../../../helpers/merge"); | |||
var _merge2 = _interopRequireDefault(_merge); | |||
var _config2 = require("./config"); | |||
var _config3 = _interopRequireDefault(_config2); | |||
var _removed = require("./removed"); | |||
var _removed2 = _interopRequireDefault(_removed); | |||
var _buildConfigChain = require("./build-config-chain"); | |||
var _buildConfigChain2 = _interopRequireDefault(_buildConfigChain); | |||
var _path = require("path"); | |||
var _path2 = _interopRequireDefault(_path); | |||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
var OptionManager = function () { | |||
function OptionManager(log) { | |||
(0, _classCallCheck3.default)(this, OptionManager); | |||
this.resolvedConfigs = []; | |||
this.options = OptionManager.createBareOptions(); | |||
this.log = log; | |||
} | |||
OptionManager.memoisePluginContainer = function memoisePluginContainer(fn, loc, i, alias) { | |||
for (var _iterator = OptionManager.memoisedPlugins, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) { | |||
var _ref; | |||
if (_isArray) { | |||
if (_i >= _iterator.length) break; | |||
_ref = _iterator[_i++]; | |||
} else { | |||
_i = _iterator.next(); | |||
if (_i.done) break; | |||
_ref = _i.value; | |||
} | |||
var cache = _ref; | |||
if (cache.container === fn) return cache.plugin; | |||
} | |||
var obj = void 0; | |||
if (typeof fn === "function") { | |||
obj = fn(context); | |||
} else { | |||
obj = fn; | |||
} | |||
if ((typeof obj === "undefined" ? "undefined" : (0, _typeof3.default)(obj)) === "object") { | |||
var _plugin = new _plugin3.default(obj, alias); | |||
OptionManager.memoisedPlugins.push({ | |||
container: fn, | |||
plugin: _plugin | |||
}); | |||
return _plugin; | |||
} else { | |||
throw new TypeError(messages.get("pluginNotObject", loc, i, typeof obj === "undefined" ? "undefined" : (0, _typeof3.default)(obj)) + loc + i); | |||
} | |||
}; | |||
OptionManager.createBareOptions = function createBareOptions() { | |||
var opts = {}; | |||
for (var _key in _config3.default) { | |||
var opt = _config3.default[_key]; | |||
opts[_key] = (0, _clone2.default)(opt.default); | |||
} | |||
return opts; | |||
}; | |||
OptionManager.normalisePlugin = function normalisePlugin(plugin, loc, i, alias) { | |||
plugin = plugin.__esModule ? plugin.default : plugin; | |||
if (!(plugin instanceof _plugin3.default)) { | |||
if (typeof plugin === "function" || (typeof plugin === "undefined" ? "undefined" : (0, _typeof3.default)(plugin)) === "object") { | |||
plugin = OptionManager.memoisePluginContainer(plugin, loc, i, alias); | |||
} else { | |||
throw new TypeError(messages.get("pluginNotFunction", loc, i, typeof plugin === "undefined" ? "undefined" : (0, _typeof3.default)(plugin))); | |||
} | |||
} | |||
plugin.init(loc, i); | |||
return plugin; | |||
}; | |||
OptionManager.normalisePlugins = function normalisePlugins(loc, dirname, plugins) { | |||
return plugins.map(function (val, i) { | |||
var plugin = void 0, | |||
options = void 0; | |||
if (!val) { | |||
throw new TypeError("Falsy value found in plugins"); | |||
} | |||
if (Array.isArray(val)) { | |||
plugin = val[0]; | |||
options = val[1]; | |||
} else { | |||
plugin = val; | |||
} | |||
var alias = typeof plugin === "string" ? plugin : loc + "$" + i; | |||
if (typeof plugin === "string") { | |||
var pluginLoc = (0, _resolve2.default)("babel-plugin-" + plugin, dirname) || (0, _resolve2.default)(plugin, dirname); | |||
if (pluginLoc) { | |||
plugin = require(pluginLoc); | |||
} else { | |||
throw new ReferenceError(messages.get("pluginUnknown", plugin, loc, i, dirname)); | |||
} | |||
} | |||
plugin = OptionManager.normalisePlugin(plugin, loc, i, alias); | |||
return [plugin, options]; | |||
}); | |||
}; | |||
OptionManager.prototype.mergeOptions = function mergeOptions(_ref2) { | |||
var _this = this; | |||
var rawOpts = _ref2.options, | |||
extendingOpts = _ref2.extending, | |||
alias = _ref2.alias, | |||
loc = _ref2.loc, | |||
dirname = _ref2.dirname; | |||
alias = alias || "foreign"; | |||
if (!rawOpts) return; | |||
if ((typeof rawOpts === "undefined" ? "undefined" : (0, _typeof3.default)(rawOpts)) !== "object" || Array.isArray(rawOpts)) { | |||
this.log.error("Invalid options type for " + alias, TypeError); | |||
} | |||
var opts = (0, _cloneDeepWith2.default)(rawOpts, function (val) { | |||
if (val instanceof _plugin3.default) { | |||
return val; | |||
} | |||
}); | |||
dirname = dirname || process.cwd(); | |||
loc = loc || alias; | |||
for (var _key2 in opts) { | |||
var option = _config3.default[_key2]; | |||
if (!option && this.log) { | |||
if (_removed2.default[_key2]) { | |||
this.log.error("Using removed Babel 5 option: " + alias + "." + _key2 + " - " + _removed2.default[_key2].message, ReferenceError); | |||
} else { | |||
var unknownOptErr = "Unknown option: " + alias + "." + _key2 + ". Check out http://babeljs.io/docs/usage/options/ for more information about options."; | |||
var presetConfigErr = "A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:\n\nInvalid:\n `{ presets: [{option: value}] }`\nValid:\n `{ presets: [['presetName', {option: value}]] }`\n\nFor more detailed information on preset configuration, please see http://babeljs.io/docs/plugins/#pluginpresets-options."; | |||
this.log.error(unknownOptErr + "\n\n" + presetConfigErr, ReferenceError); | |||
} | |||
} | |||
} | |||
(0, _index.normaliseOptions)(opts); | |||
if (opts.plugins) { | |||
opts.plugins = OptionManager.normalisePlugins(loc, dirname, opts.plugins); | |||
} | |||
if (opts.presets) { | |||
if (opts.passPerPreset) { | |||
opts.presets = this.resolvePresets(opts.presets, dirname, function (preset, presetLoc) { | |||
_this.mergeOptions({ | |||
options: preset, | |||
extending: preset, | |||
alias: presetLoc, | |||
loc: presetLoc, | |||
dirname: dirname | |||
}); | |||
}); | |||
} else { | |||
this.mergePresets(opts.presets, dirname); | |||
delete opts.presets; | |||
} | |||
} | |||
if (rawOpts === extendingOpts) { | |||
(0, _assign2.default)(extendingOpts, opts); | |||
} else { | |||
(0, _merge2.default)(extendingOpts || this.options, opts); | |||
} | |||
}; | |||
OptionManager.prototype.mergePresets = function mergePresets(presets, dirname) { | |||
var _this2 = this; | |||
this.resolvePresets(presets, dirname, function (presetOpts, presetLoc) { | |||
_this2.mergeOptions({ | |||
options: presetOpts, | |||
alias: presetLoc, | |||
loc: presetLoc, | |||
dirname: _path2.default.dirname(presetLoc || "") | |||
}); | |||
}); | |||
}; | |||
OptionManager.prototype.resolvePresets = function resolvePresets(presets, dirname, onResolve) { | |||
return presets.map(function (val) { | |||
var options = void 0; | |||
if (Array.isArray(val)) { | |||
if (val.length > 2) { | |||
throw new Error("Unexpected extra options " + (0, _stringify2.default)(val.slice(2)) + " passed to preset."); | |||
} | |||
var _val = val; | |||
val = _val[0]; | |||
options = _val[1]; | |||
} | |||
var presetLoc = void 0; | |||
try { | |||
if (typeof val === "string") { | |||
presetLoc = (0, _resolve2.default)("babel-preset-" + val, dirname) || (0, _resolve2.default)(val, dirname); | |||
if (!presetLoc) { | |||
var matches = val.match(/^(@[^/]+)\/(.+)$/); | |||
if (matches) { | |||
var orgName = matches[1], | |||
presetPath = matches[2]; | |||
val = orgName + "/babel-preset-" + presetPath; | |||
presetLoc = (0, _resolve2.default)(val, dirname); | |||
} | |||
} | |||
if (!presetLoc) { | |||
throw new Error("Couldn't find preset " + (0, _stringify2.default)(val) + " relative to directory " + (0, _stringify2.default)(dirname)); | |||
} | |||
val = require(presetLoc); | |||
} | |||
if ((typeof val === "undefined" ? "undefined" : (0, _typeof3.default)(val)) === "object" && val.__esModule) { | |||
if (val.default) { | |||
val = val.default; | |||
} else { | |||
var _val2 = val, | |||
__esModule = _val2.__esModule, | |||
rest = (0, _objectWithoutProperties3.default)(_val2, ["__esModule"]); | |||
val = rest; | |||
} | |||
} | |||
if ((typeof val === "undefined" ? "undefined" : (0, _typeof3.default)(val)) === "object" && val.buildPreset) val = val.buildPreset; | |||
if (typeof val !== "function" && options !== undefined) { | |||
throw new Error("Options " + (0, _stringify2.default)(options) + " passed to " + (presetLoc || "a preset") + " which does not accept options."); | |||
} | |||
if (typeof val === "function") val = val(context, options); | |||
if ((typeof val === "undefined" ? "undefined" : (0, _typeof3.default)(val)) !== "object") { | |||
throw new Error("Unsupported preset format: " + val + "."); | |||
} | |||
onResolve && onResolve(val, presetLoc); | |||
} catch (e) { | |||
if (presetLoc) { | |||
e.message += " (While processing preset: " + (0, _stringify2.default)(presetLoc) + ")"; | |||
} | |||
throw e; | |||
} | |||
return val; | |||
}); | |||
}; | |||
OptionManager.prototype.normaliseOptions = function normaliseOptions() { | |||
var opts = this.options; | |||
for (var _key3 in _config3.default) { | |||
var option = _config3.default[_key3]; | |||
var val = opts[_key3]; | |||
if (!val && option.optional) continue; | |||
if (option.alias) { | |||
opts[option.alias] = opts[option.alias] || val; | |||
} else { | |||
opts[_key3] = val; | |||
} | |||
} | |||
}; | |||
OptionManager.prototype.init = function init() { | |||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | |||
for (var _iterator2 = (0, _buildConfigChain2.default)(opts, this.log), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) { | |||
var _ref3; | |||
if (_isArray2) { | |||
if (_i2 >= _iterator2.length) break; | |||
_ref3 = _iterator2[_i2++]; | |||
} else { | |||
_i2 = _iterator2.next(); | |||
if (_i2.done) break; | |||
_ref3 = _i2.value; | |||
} | |||
var _config = _ref3; | |||
this.mergeOptions(_config); | |||
} | |||
this.normaliseOptions(opts); | |||
return this.options; | |||
}; | |||
return OptionManager; | |||
}(); | |||
exports.default = OptionManager; | |||
OptionManager.memoisedPlugins = []; | |||
module.exports = exports["default"]; |
@@ -0,0 +1,33 @@ | |||
"use strict"; | |||
exports.__esModule = true; | |||
exports.filename = undefined; | |||
exports.boolean = boolean; | |||
exports.booleanString = booleanString; | |||
exports.list = list; | |||
var _slash = require("slash"); | |||
var _slash2 = _interopRequireDefault(_slash); | |||
var _util = require("../../../util"); | |||
var util = _interopRequireWildcard(_util); | |||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | |||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |||
var filename = exports.filename = _slash2.default; | |||
function boolean(val) { | |||
return !!val; | |||
} | |||
function booleanString(val) { | |||
return util.booleanify(val); | |||
} | |||
function list(val) { | |||
return util.list(val); | |||
} |
@@ -0,0 +1,50 @@ | |||
"use strict"; | |||
module.exports = { | |||
"auxiliaryComment": { | |||
"message": "Use `auxiliaryCommentBefore` or `auxiliaryCommentAfter`" | |||
}, | |||
"blacklist": { | |||
"message": "Put the specific transforms you want in the `plugins` option" | |||
}, | |||
"breakConfig": { | |||
"message": "This is not a necessary option in Babel 6" | |||
}, | |||
"experimental": { | |||
"message": "Put the specific transforms you want in the `plugins` option" | |||
}, | |||
"externalHelpers": { | |||
"message": "Use the `external-helpers` plugin instead. Check out http://babeljs.io/docs/plugins/external-helpers/" | |||
}, | |||
"extra": { | |||
"message": "" | |||
}, | |||
"jsxPragma": { | |||
"message": "use the `pragma` option in the `react-jsx` plugin . Check out http://babeljs.io/docs/plugins/transform-react-jsx/" | |||
}, | |||
"loose": { | |||
"message": "Specify the `loose` option for the relevant plugin you are using or use a preset that sets the option." | |||
}, | |||
"metadataUsedHelpers": { | |||
"message": "Not required anymore as this is enabled by default" | |||
}, | |||
"modules": { | |||
"message": "Use the corresponding module transform plugin in the `plugins` option. Check out http://babeljs.io/docs/plugins/#modules" | |||
}, | |||
"nonStandard": { | |||
"message": "Use the `react-jsx` and `flow-strip-types` plugins to support JSX and Flow. Also check out the react preset http://babeljs.io/docs/plugins/preset-react/" | |||
}, | |||
"optional": { | |||
"message": "Put the specific transforms you want in the `plugins` option" | |||
}, | |||
"sourceMapName": { | |||
"message": "Use the `sourceMapTarget` option" | |||
}, | |||
"stage": { | |||
"message": "Check out the corresponding stage-x presets http://babeljs.io/docs/plugins/#presets" | |||
}, | |||
"whitelist": { | |||
"message": "Put the specific transforms you want in the `plugins` option" | |||
} | |||
}; |