tribe
Version:
Tribe is a platform for building rich, powerful, highly scalable distributed HTML5 web and mobile systems.
189 lines (173 loc) • 6.89 kB
JavaScript
require('tribe/driveLetterHack');
var pubsub = require('tribe.pubsub'),
modules = require('tribe/server/modules'),
log = require('tribe.logger'),
_ = require('underscore'),
path = require('path');
pubsub.options.sync = true;
pubsub.options.handleExceptions = false;
var options = module.exports = {
apply: function (optionsToApply) {
_.extend(options, optionsToApply)
// use this to bump up the level at runtime
log.setLevel(options.logLevel);
return options;
},
port: process.env.PORT || 1678,
appName: appName(),
logLevel: 'info',
basePath: basePath(),
modulePath: modulePath(),
testPaths: testPaths(),
browserTestPaths: browserTestPaths(),
debug: debugMode(),
debugPort: process.debugPort,
inspectorPort: 8081,
enhancedDebug: true,
babel: { plugins: [require('babel-plugin-transform-es2015-arrow-functions')] },
childProcess: false,
watcherDelay: 200,
rebuildThrottle: 200,
startPane: '/layout',
startFlow: '/main',
mobileStartPane: '/layout',
transientTopics: ['ui.*'],
//showDependencies: true, // we will eventually have a built-in app and service for spelunking dependencies
builds: [
{
name: 'app',
phases: ['server', 'prepare', 'render', 'output'],
path: basePath(),
tasks: [
{ activity: 'dependencies', options: { path: 'dependencies' } },
{ activity: 'panes', options: { path: 'panes' } },
{ activity: 'resources', options: { path: 'facets' } },
{ activity: 'resources', options: { path: 'configuration' } },
{ activity: 'resources', options: { path: 'flows' } },
{ activity: 'resources', options: { path: 'vocabulary' } },
{ activity: 'resources', options: { path: 'services' } }, // deprecated. required for test-studio
{ activity: 'scripts', options: { path: 'scripts' } },
{ activity: 'styles', options: { path: 'styles' } },
{ activity: 'templates', options: { path: 'templates' } },
{ activity: 'app' }
]
},
{
name: 'tests',
phases: ['server', 'prepare', 'render', 'output'],
path: path.resolve(__dirname, 'test-studio'),
tasks: [
{ activity: 'panes', options: { path: 'panes' } },
{ activity: 'resources', options: { path: 'facets' } },
{ activity: 'resources', options: { path: 'configuration' } },
{ activity: 'resources', options: { path: 'flows' } },
{ activity: 'app' }
]
},
{
name: 'tests.agent',
phases: ['server', 'prepare', 'render', 'output'],
path: basePath(),
tasks: [
{ activity: 'panes', options: { path: 'panes' } },
{ activity: 'resources', options: { path: 'facets' } },
{ activity: 'resources', options: { path: 'configuration' } },
{ activity: 'resources', options: { path: 'flows' } },
{ activity: 'resources', options: { path: 'vocabulary' } },
{ activity: 'tests.agent' },
{ activity: 'tests.browser', options: { path: 'tests/browser' } } // see below
]
}
],
server: {
modules: dependencyModules().concat(dependencyModules('/tests')).concat([
// map static directories
modules.fs('/content', path.resolve(basePath(), 'content')),
modules.fs('/images', path.resolve(basePath(), 'images')),
modules.fs('/tests/images', path.resolve(modulePath(), 'test-studio/images')),
// memory file collections are created as part of builds
// set directory default pages
modules.memory.mapFile('/', 'app', 'app.htm'),
modules.memory.mapFile('/tests/', 'tests', 'app.htm'),
// map directories -- ensure child directories are done before the root directory
modules.memory('/tests.agent', 'tests.agent'),
modules.memory('/tests', 'tests'),
modules.memory('/', 'app')
]),
services: {
'__tests': 'tribe/test/service'
},
operations: {
'facet': 'tribe/server/operations/facet',
'message': 'tribe/server/operations/message',
'scope': 'tribe/server/operations/scope',
'release': 'tribe/server/operations/release',
'subscribe': 'tribe/server/operations/subscribe'
}
},
test: {
framework: 'mocha',
mocha: {
ui: 'tdd'
},
debugPort: 5859,
restartThrottle: 200,
fileFilter: /\.tests\.js$/,
// suspending watchers causes all watchers against that path to be cancelled
// will be resolved when file changes are broadcast using pubsub
suspendWatchers: false,
browser: {
runOnServer: false,
loadApp: true
}
},
storage: {
type: 'sqlite3',
filename: ':memory:'
},
forBrowser: function () {
return {
appName: options.appName,
logLevel: options.logLevel,
transientTopics: options.transientTopics
};
}
};
function appName() {
return path.basename(basePath());
}
function basePath() {
var basePath = require.resolve(process.argv[1]);
basePath = basePath.substr(0, basePath.lastIndexOf(path.sep) + 1);
return basePath[0].toLowerCase() + basePath.substring(1);
}
function modulePath() {
return __dirname;
}
function debugMode() {
return process.execArgv.some(containsDebug);
function containsDebug(value) {
return value.substring(0, 7) === '--debug';
}
}
// these will be replaced by the config system when implemented
function testPaths() {
return [
basePath() + 'tests/'
];
}
function browserTestPaths() {
return [
basePath() + 'tests/browser'
];
}
function dependencyModules(rootPath) {
return [
// static dependencies. looked at including these with npm and browserify but minification with uglifyjs on them sucks.
modules.fs(dependencyPath('jquery'), path.dirname(require.resolve('jquery/dist/jquery.js'))),
modules.fs(dependencyPath('socket.io'), path.dirname(require.resolve('socket.io-client/dist/socket.io.js')))
];
function dependencyPath(dependency) {
return (rootPath ? rootPath : '') + '/dependencies/' + dependency;
}
}