-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request box#57 from Box/buildupdate
Switch to ShellJS and create dist files
- Loading branch information
Showing
28 changed files
with
2,487 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
_site | ||
node_modules | ||
dist | ||
doc | ||
*.swp | ||
*.iml | ||
.idea | ||
.DS_Store | ||
npm-debug.log | ||
dist/t3-*.js |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
/** | ||
* @fileoverview Build file | ||
* @author nzakas | ||
*/ | ||
/*global target, exec, echo, find, which, test, exit, mkdir*/ | ||
|
||
'use strict'; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
require('shelljs/make'); | ||
|
||
var util = require('util'), | ||
nodeCLI = require('shelljs-nodecli'); | ||
|
||
//------------------------------------------------------------------------------ | ||
// Data | ||
//------------------------------------------------------------------------------ | ||
|
||
var NODE = 'node ', // intentional extra space | ||
NODE_MODULES = './node_modules/', | ||
BUILD_DIR = './build/', | ||
DIST_DIR = './dist/', | ||
LIB_DIR = './lib/', | ||
|
||
// Utilities - intentional extra space at the end of each string | ||
ISTANBUL = NODE + NODE_MODULES + 'istanbul/lib/cli.js ', | ||
MOCHA = NODE_MODULES + 'mocha/bin/_mocha ', | ||
JSDOC = NODE + NODE_MODULES + 'jsdoc/jsdoc.js ', | ||
|
||
// Directories | ||
JS_DIRS = getSourceDirectories(), | ||
SRC_FILES = ['lib/box.js', 'lib/event-target.js', 'lib/context.js', 'lib/application.js'], | ||
|
||
// Files | ||
JS_FILES = find(JS_DIRS).filter(fileType('js')).join(' '), | ||
TEST_FILES = find('tests/').filter(fileType('js')).join(' '); | ||
|
||
//------------------------------------------------------------------------------ | ||
// Helpers | ||
//------------------------------------------------------------------------------ | ||
|
||
/** | ||
* Executes a Node CLI and exits with a non-zero exit code if the | ||
* CLI execution returns a non-zero exit code. Otherwise, it does | ||
* not exit. | ||
* @param {...string} [args] Arguments to pass to the Node CLI utility. | ||
* @returns {void} | ||
* @private | ||
*/ | ||
function nodeExec(args) { | ||
args = arguments; // make linting happy | ||
var code = nodeCLI.exec.apply(nodeCLI, args).code; | ||
if (code !== 0) { | ||
exit(code); | ||
} | ||
} | ||
|
||
/** | ||
* Runs exec() but exits if the exit code is non-zero. | ||
* @param {string} cmd The command to execute. | ||
* @returns {void} | ||
* @private | ||
*/ | ||
function execOrExit(cmd) { | ||
var code = exec(cmd).code; | ||
if (code !== 0) { | ||
exit(code); | ||
} | ||
} | ||
|
||
/** | ||
* Generates a function that matches files with a particular extension. | ||
* @param {string} extension The file extension (i.e. 'js') | ||
* @returns {Function} The function to pass into a filter method. | ||
* @private | ||
*/ | ||
function fileType(extension) { | ||
return function(filename) { | ||
return filename.substring(filename.lastIndexOf('.') + 1) === extension; | ||
}; | ||
} | ||
|
||
/** | ||
* Determines which directories are present that might have JavaScript files. | ||
* @returns {string[]} An array of directories that exist. | ||
* @private | ||
*/ | ||
function getSourceDirectories() { | ||
var dirs = [ 'lib', 'src', 'app' ], | ||
result = []; | ||
|
||
dirs.forEach(function(dir) { | ||
if (test('-d', dir)) { | ||
result.push(dir); | ||
} | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Creates a release version tag and pushes to origin. | ||
* @param {string} type The type of release to do (patch, minor, major) | ||
* @returns {void} | ||
*/ | ||
function release(type) { | ||
target.test(); | ||
|
||
target.dist(); | ||
|
||
execOrExit('git add -A'); | ||
execOrExit('git commit --amend --no-edit'); | ||
|
||
execOrExit('npm version ' + type); | ||
|
||
// ...and publish | ||
execOrExit('git push origin master --tags'); | ||
} | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
// Tasks | ||
//------------------------------------------------------------------------------ | ||
|
||
target.all = function() { | ||
target.test(); | ||
}; | ||
|
||
target.lint = function() { | ||
echo('Validating JavaScript files'); | ||
nodeExec('eslint', JS_FILES); | ||
}; | ||
|
||
target.test = function() { | ||
target.lint(); | ||
|
||
echo('Running browser tests'); | ||
var code = exec('node ./node_modules/karma/bin/karma start config/karma-conf.js').code; | ||
if (code !== 0) { | ||
exit(code); | ||
} | ||
}; | ||
|
||
target.docs = function() { | ||
echo('Generating documentation'); | ||
exec(JSDOC + '-d jsdoc ' + JS_DIRS.join(' ')); | ||
echo('Documentation has been output to /jsdoc'); | ||
}; | ||
|
||
target.dist = function() { | ||
var pkg = require('./package.json'), | ||
distFilename = DIST_DIR + pkg.name + '.js', | ||
minDistFilename = distFilename.replace(/\.js$/, '.min.js'); | ||
|
||
if (test('-d', DIST_DIR)) { | ||
rm('-r', DIST_DIR + '*'); | ||
} else { | ||
mkdir(DIST_DIR); | ||
} | ||
|
||
// concatenate files together | ||
cat(SRC_FILES).to(distFilename); | ||
|
||
// create minified version | ||
nodeExec('uglifyjs', distFilename, '-o', minDistFilename); | ||
|
||
// Add copyrights and version info | ||
var versionComment = '/*! ' + pkg.name + ' v ' + pkg.version + '*/\n', | ||
copyrightComment = cat('./config/copyright.txt'); | ||
|
||
(copyrightComment + versionComment + cat(distFilename)).to(distFilename); | ||
(copyrightComment + versionComment + cat(minDistFilename)).to(minDistFilename); | ||
|
||
// ensure there's a newline at the end of each file | ||
(cat(distFilename) + '\n').to(distFilename); | ||
(cat(minDistFilename) + '\n').to(minDistFilename); | ||
|
||
// create filenames with version in them | ||
cp(distFilename, distFilename.replace('.js', '-' + pkg.version + '.js')); | ||
cp(minDistFilename, minDistFilename.replace('.min.js', '-' + pkg.version + '.min.js')); | ||
}; | ||
|
||
target.patch = function() { | ||
release('patch'); | ||
}; | ||
|
||
target.minor = function() { | ||
release('minor'); | ||
}; | ||
|
||
target.major = function() { | ||
release('major'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/*! | ||
Copyright 2015 Box, Inc. All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ |
Oops, something went wrong.