diff --git a/lib/css.js b/lib/css.js index 50f2b26..df0ab19 100644 --- a/lib/css.js +++ b/lib/css.js @@ -21,8 +21,8 @@ function buildBundles( baseName, workspaceDir, relBaseUrl, compiledDir, amdModul // get the dependency map for all modules dependencies.buildMap( workspaceDir, relBaseUrl, compiledDir, amdModules ).then( function( modules ) { - var absBaseUrl = path.normalize( path.join( workspaceDir, relBaseUrl ) ); - var cssFiles = { + var absBaseUrl = path.normalize( path.join( workspaceDir, relBaseUrl ) ), + cssFiles = { default: [] }, contents = { @@ -32,8 +32,7 @@ function buildBundles( baseName, workspaceDir, relBaseUrl, compiledDir, amdModul async.waterfall([ function( next ) { - var name, - processed = {}, + var processed = {}, addCssDependencies = function( m ) { processed[ m ] = true; if ( !processed[ m ] && modules[ m ] && modules[ m ].deps ) { @@ -44,7 +43,7 @@ function buildBundles( baseName, workspaceDir, relBaseUrl, compiledDir, amdModul // logger.log( "Adding: " + modules[ m ].css ); cssFiles.default = _.union( cssFiles.default, modules[ m ].css.split( "," ) ); } else { - for ( name in modules[ m ].css ) { + for ( var name in modules[ m ].css ) { if ( modules[ m ].css.hasOwnProperty( name ) ) { cssFiles[ name ] = cssFiles[ name ] || []; // logger.log( "Adding css." + name + ": " + modules[ m ].css[ name ]); @@ -140,7 +139,7 @@ function buildBundles( baseName, workspaceDir, relBaseUrl, compiledDir, amdModul optimizeCss: "standard", logLevel: 4 // SILENT }, - function( response ) { + function() { async.waterfall([ function( step ) { fs.readFile( optimizedOut, "utf-8", step ); diff --git a/lib/dependencies.js b/lib/dependencies.js index 904d001..a8419b2 100644 --- a/lib/dependencies.js +++ b/lib/dependencies.js @@ -11,7 +11,7 @@ var async = require( "async" ), redefineRequireJSLogging = require( "./requirejs-utils" ).redefineRequireJSLogging; var log, - bid = 0, +// bid = 0, dependenciesPromises = {}; function getFiles( dir, pattern, mapFn, callback ) { @@ -23,11 +23,11 @@ function getFiles( dir, pattern, mapFn, callback ) { next( null, matches.map( mapFn ) ); } ], callback); -}; +} function buildMap( workspaceDir, baseUrl, compiledDir, include ) { - var id = bid++; - // logger.log( "buildMap["+id+"]()" ); +// var id = bid++; +// logger.log( "buildMap["+id+"]()" ); var promise = new Promise(), shasum = crypto.createHash( 'sha1' ), filename = ""; @@ -63,7 +63,7 @@ function buildMap( workspaceDir, baseUrl, compiledDir, include ) { filename += path.join( compiledDir, "deps-" + digest + ".json" ); fs.exists( filename, function( exists ) { - next( null, digest, exists ) + next( null, digest, exists ); }); }, function( digest, exists, next ) { @@ -83,7 +83,7 @@ function buildMap( workspaceDir, baseUrl, compiledDir, include ) { function( cb ) { // logger.log( "buildMap["+id+"](): step 3.1" ); fs.mkdir( compiledDir, function( err ) { - if ( err && err.code != "EEXIST" ) { + if ( err && err.code !== "EEXIST" ) { cb( err ); } else { cb(); @@ -97,7 +97,7 @@ function buildMap( workspaceDir, baseUrl, compiledDir, include ) { requirejs.tools.useLib( function( r ) { r([ 'parse' ], function( parse ) { cb( null, parse ); - }) + }); }); }, function( parse, cb ) { @@ -134,9 +134,8 @@ function buildMap( workspaceDir, baseUrl, compiledDir, include ) { // logger.log( "buildMap["+id+"](): step 3.4" ); // Walk through the dep map and remove baseUrl and js extension var module, - modules = [], - baseUrlRE = new RegExp( "^" + regexp.escapeString( baseUrl + "/" ) ), - jsExtRE = new RegExp( regexp.escapeString( ".js" ) + "$" ); + modules = []; + for ( module in deps ) { modules.push( module ); } @@ -151,7 +150,7 @@ function buildMap( workspaceDir, baseUrl, compiledDir, include ) { function( data, next ) { // logger.log( "buildMap["+id+"](): step 3.4.2" ); var lines = data.split( "\n" ), - matches = lines.filter( function( line, index ) { + matches = lines.filter( function( line ) { return /^.*\/\/>>\s*[^:]+:.*$/.test( line ); }); if ( matches && matches.length ) { @@ -182,7 +181,7 @@ function buildMap( workspaceDir, baseUrl, compiledDir, include ) { cb( null, deps ); } } - ) + ); }, function( deps, cb ) { // logger.log( "buildMap["+id+"](): step 3.5" ); diff --git a/lib/git.js b/lib/git.js index 1accb61..b20e113 100644 --- a/lib/git.js +++ b/lib/git.js @@ -20,8 +20,6 @@ SOFTWARE. */ - - var ChildProcess = require( 'child_process' ), path = require( 'path' ), tools = require( './tools' ), @@ -32,7 +30,7 @@ var gitCommands, gitDir, workTree; var gitENOENT = /fatal: (Path '([^']+)' does not exist in '([0-9a-f]{40})'|ambiguous argument '([^']+)': unknown revision or path not in the working tree.)/; // Set up the git configs for the subprocess -var Git = module.exports = function ( repo, workspace ) { +module.exports.init = function ( repo, workspace ) { // Check the directory exists first. try { fs.statSync( repo ); @@ -87,4 +85,4 @@ function gitExec( commands, encoding, callback ) { child.stdin.end(); } -Git.exec = gitExec; \ No newline at end of file +module.exports.exec = gitExec; \ No newline at end of file diff --git a/lib/project.js b/lib/project.js index e965b32..6748b90 100644 --- a/lib/project.js +++ b/lib/project.js @@ -14,28 +14,39 @@ var repoBaseDir, module.exports.repoDir = function setRepoDir( dir ) { repoBaseDir = path.normalize ( dir ); return module.exports; -} +}; module.exports.stagingDir = function setWorkBaseDir( dir ) { workBaseDir = path.normalize ( dir ); return module.exports; -} +}; function fetch( repoDir, callback ) { - Git( repoDir ); + Git.init( repoDir ); Git.exec( [ "fetch", "origin", "+refs/heads/*:refs/heads/*" ], callback ); } function remoteUpdate( repoDir, callback ) { - Git( repoDir ); + Git.init( repoDir ); Git.exec( [ "remote", "update" ], callback ); } function getLastCommitHash( repoDir, callback ) { - Git( repoDir ); + Git.init( repoDir ); Git.exec( [ "log", "-1", "--pretty=format:%H" ], callback ); } +function getWorkspaceDirSync( project ) { + var workspaceDir; + if ( project.getOwner() ) { + workspaceDir = path.join( project.getWorkspaceBaseDirSync(), project.getRef(), project.getRepo() ); + } else { + path.join(project.getRepo(), project.getRef() ); + } + + return workspaceDir; +} + function cleanup( project, callback ) { var compiled = project.getCompiledDirSync(); @@ -58,7 +69,7 @@ function _checkout( project, callback ) { project.getRepoDir( next ); }, function( dir, next ) { - Git( dir, workDir ); + Git.init( dir, workDir ); Git.exec( [ "checkout", "-f", project.getRef() ], next ); } ], callback ); @@ -81,7 +92,7 @@ function checkout( project, force, callback ){ }, function( next ) { mkdirp( workDir, function( err ) { - if ( err && err.code != "EEXIST" ) { + if ( err && err.code !== "EEXIST" ) { next( err ); } else { next( null ); @@ -109,7 +120,7 @@ function checkoutIfEmpty( project, callback ){ fs.readdir( workDir, next ); }, function( files, next ) { - if ( files.length == 0 ) { + if ( files.length === 0 ) { _checkout( project, function() { next(); } ); } else { next(); @@ -157,17 +168,6 @@ function getRepoDir( project, callback ) { getFirstExistingDir( [ repoDir, repoDir + ".git" ], callback ); } -function getWorkspaceDirSync( project ) { - var workspaceDir; - if ( project.getOwner() ) { - workspaceDir = path.join( project.getWorkspaceBaseDirSync(), project.getRef(), project.getRepo() ) - } else { - path.join(project.getRepo(), project.getRef() ) - } - - return workspaceDir; -} - function getCompiledDirSync( project ) { return path.join( getWorkspaceDirSync( project ), "__compiled" ); } @@ -180,50 +180,50 @@ var Project = module.exports.Project = function ( owner, repo, ref ) { Project.prototype.getOwner = function() { return this.owner; -} +}; Project.prototype.getRepo = function() { return this.repo; -} +}; Project.prototype.getRef = function() { return this.ref; -} +}; Project.prototype.checkout = function( force, callback ) { return checkout( this, force, callback ); -} +}; Project.prototype.checkoutIfEmpty = function( callback ) { return checkoutIfEmpty( this, callback ); -} +}; Project.prototype.cleanup = function( callback ) { return cleanup( this, callback ); -} +}; Project.prototype.getRepoDir = function( callback ) { return getRepoDir( this, callback ); -} +}; Project.prototype.getCompiledDirSync = function() { return getCompiledDirSync( this ); -} +}; Project.prototype.getWorkspaceBaseDirSync = function() { return getWorkspaceBaseDirSync( this ); -} +}; Project.prototype.getWorkspaceDirSync = function() { return getWorkspaceDirSync( this ); -} +}; Project.prototype.fetch = function( callback ) { async.waterfall([ _.bind( this.getRepoDir, this ), fetch ], callback ); -} +}; Project.prototype.remoteUpdate = function( callback ) { async.waterfall([ @@ -231,13 +231,13 @@ Project.prototype.remoteUpdate = function( callback ) { remoteUpdate ], callback ); -} +}; Project.prototype.getLastCommitHash = function( callback ) { async.waterfall([ _.bind( this.getRepoDir, this ), getLastCommitHash ], callback ); -} +}; module.exports.fetch = fetch; \ No newline at end of file diff --git a/lib/regexp.js b/lib/regexp.js index 80e8be2..2f4be36 100644 --- a/lib/regexp.js +++ b/lib/regexp.js @@ -13,7 +13,7 @@ regexp.escapeString = function(/*String*/str, /*String?*/except){ // a String with special characters to be left unescaped return str.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, function(ch){ - if(except && except.indexOf(ch) != -1){ + if(except && except.indexOf(ch) !== -1){ return ch; } return "\\" + ch; diff --git a/server.js b/server.js index c14dde1..6d2ba81 100644 --- a/server.js +++ b/server.js @@ -74,13 +74,13 @@ app.get( '/', function( req, res ) { app.post( '/post_receive', function( req, res ) { var payload = req.body.payload, - owner, repo, repoUrl, ref, refType, refName, project, + owner, repo, ref, refType, refName, project, fetchIfExists = function( candidates, callback ) { var dir = candidates.shift(); fs.exists( dir, function( exists ) { if ( exists ) { fetch( dir, - function( error, stdout, stderr ) { + function( error /*, stdout, stderr */ ) { if ( error !== null ) { res.send( error, 500 ); } else { @@ -184,7 +184,6 @@ function redefineRequireJSLogging() { }); } -var bid = 0; function buildDependencyMap( project, baseUrl, include ) { var promise = new Promise(); @@ -215,13 +214,12 @@ function buildCSSBundles( project, config, baseName, filter, optimize ) { return css.buildBundles( baseName, project.getWorkspaceDirSync(), config.baseUrl, project.getCompiledDirSync(), config.include, filter, optimize ); } -var bjsid = 0; +//var bjsid = 0; function buildJSBundle( project, config, name, filter, optimize ) { - var id = bjsid++; - // logger.log( "buildJSBundle["+id+"]()" ); +// var id = bjsid++; +// logger.log( "buildJSBundle["+id+"]()" ); var promise = new Promise(), baseUrl = path.normalize( path.join( project.getWorkspaceDirSync(), config.baseUrl ) ), - wsDir = project.getWorkspaceDirSync(), ext = ( optimize ? ".min" : "" ) + ".js", out = path.join( project.getCompiledDirSync(), name + ext ); @@ -236,7 +234,7 @@ function buildJSBundle( project, config, name, filter, optimize ) { var outDir = path.dirname( config.out ); // logger.log( "mkdir '" + outDir + "'" ); fs.mkdir( outDir, function( err ) { - if ( err && err.code != "EEXIST" ) { + if ( err && err.code !== "EEXIST" ) { next( err ); } else { next(); @@ -300,8 +298,6 @@ function buildJSBundle( project, config, name, filter, optimize ) { function buildZipBundle( project, name, config, digest, filter ) { // logger.log( "buildZipBundle()" ); var promise = new Promise(), - baseUrl = config.baseUrl, - basename = path.basename( name, ".zip" ), out = path.join( project.getCompiledDirSync(), digest + ".zip" ); fs.exists( out, function( exists ) { @@ -354,7 +350,7 @@ function buildZipBundle( project, name, config, digest, filter ) { function( err ) { promise.reject( err ); } - ) + ); } }); return promise; @@ -518,9 +514,8 @@ app.get( '/v1/bundle/:owner/:repo/:ref/:name?', function( req, res ) { app.get( '/v1/dependencies/:owner/:repo/:ref', function( req, res ) { var project = new Project( req.params.owner, req.params.repo, req.params.ref ), names = req.param( "names", "" ).split( "," ).filter(function( name ) { - return !!name + return !!name; }).sort(), - exclude = req.param( "exclude", "" ).split( "," ).sort(), baseUrl = req.param( "baseUrl", "." ); buildDependencyMap( project, baseUrl, names )