-
Notifications
You must be signed in to change notification settings - Fork 23
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 #113 from nymag/auto-bootstrap
auto-bootstrap
- Loading branch information
Showing
12 changed files
with
421 additions
and
145 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,13 +1,77 @@ | ||
// this will set up things | ||
'use strict'; | ||
|
||
var app = require('express')(), | ||
routes = require('./lib/routes'); | ||
var _ = require('lodash'), | ||
app = require('express')(), | ||
siteService = require('./lib/sites'), | ||
files = require('./lib/files'), | ||
routes = require('./lib/routes'), | ||
bootstrap = require('./lib/bootstrap'), | ||
bluebird = require('bluebird'), | ||
log = require('./lib/log'), | ||
chalk = require('chalk'); | ||
|
||
/** | ||
* Dims the log slightly. | ||
* @param {string} msg | ||
*/ | ||
function logLess(msg) { | ||
log.info(chalk.dim(msg)); | ||
} | ||
|
||
/** | ||
* @returns {Promise} | ||
*/ | ||
function bootstrapCurrentProject() { | ||
return bootstrap('.').catch(function () { | ||
logLess('No bootstrap found at root of project.'); | ||
}); | ||
} | ||
|
||
/** | ||
* @returns {Promise} | ||
*/ | ||
function bootstrapComponents() { | ||
var components = files.getComponents(); | ||
|
||
return bluebird.all(_.map(components, function (component) { | ||
var componentPath = files.getComponentPath(component); | ||
return bootstrap(componentPath).catch(function () { | ||
logLess('No bootstrap found for ' + component); | ||
}); | ||
})); | ||
} | ||
|
||
/** | ||
* @returns {Promise} | ||
*/ | ||
function bootstrapSites() { | ||
var sites = siteService.sites(); | ||
|
||
return bluebird.all(_.map(sites, function (site) { | ||
return bootstrap(site.dirPath, {uriPrefix: site.host + site.path}).catch(function () { | ||
logLess('No bootstrap found for ' + site.slug); | ||
}); | ||
})); | ||
} | ||
|
||
/** | ||
* @returns {Promise} | ||
*/ | ||
module.exports = function () { | ||
return routes(app); | ||
var router = routes(app); | ||
|
||
//look for bootstraps in components | ||
return bootstrapComponents().then(function () { | ||
return bootstrapSites(); | ||
}).then(function () { | ||
return bootstrapCurrentProject(); | ||
}).then(function () { | ||
return router; | ||
}); | ||
}; | ||
|
||
//services to outside | ||
//services exposed to outside | ||
module.exports.db = require('./lib/services/db'); | ||
module.exports.components = require('./lib/services/components'); | ||
module.exports.pages = require('./lib/services/pages'); |
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
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
Oops, something went wrong.