Skip to content

Instantly share code, notes, and snippets.

@ericf
Created December 10, 2012 23:38
Show Gist options
  • Select an option

  • Save ericf/4254362 to your computer and use it in GitHub Desktop.

Select an option

Save ericf/4254362 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
path = require('path'),
Y = require('yui/oop'),
CONFIG_FILE = 'config.json',
NODE_ENV = process.env.NODE_ENV,
PORT = process.env.PORT,
ENV = {
development: NODE_ENV !== 'production',
production : NODE_ENV === 'production'
},
appRoot = process.cwd(),
configFile = path.join(__dirname, CONFIG_FILE),
yuiFilter = ENV.production ? 'min' : 'raw',
config;
// Poor-mans object clone.
function clone(config) {
return JSON.parse(JSON.stringify(config));
}
// Wrap crazy YUI API.
function mix(config, overrides) {
return Y.mix(config, overrides, true, null, 0, true);
}
if (fs.existsSync(configFile)) {
try {
config = JSON.parse(fs.readFileSync(configFile, 'utf8'));
} catch (e) {
console.error('Could not parse config file.');
}
} else {
console.error('Could not read config file: ' + configFile);
}
// Quit if we cannot process the config file.
if (!config) {
process.exit(1);
}
config.env = ENV;
config.port = PORT || config.port;
Y.Object.each(config.dirs, function (dir, name, dirs) {
dirs[name] = path.join(appRoot, dir);
});
// YUI on the server.
mix(config.yui.server, {
filter: yuiFilter,
groups: {
server: {
base : appRoot,
filter : yuiFilter,
modules: clone(config.yui.modules.server)
},
shared: {
base : path.join(appRoot, config.yui.server.groups.shared.base),
filter : yuiFilter,
modules: clone(config.yui.modules.shared)
}
}
});
// YUI on the client.
mix(config.yui.client, {
combine: ENV.production,
filter : yuiFilter,
groups: {
client: {
combine: ENV.production,
filter : yuiFilter,
modules: clone(config.yui.modules.client)
},
shared: {
combine: ENV.production,
filter : yuiFilter,
modules: clone(config.yui.modules.shared)
}
}
});
// Remove modules from parsed YUI config.
delete config.yui.modules;
module.exports = config;
{
"name" : "Photos Near Me",
"title": "Photos Near Me",
"port" : 3000,
"dirs": {
"pub" : "public/",
"views" : "views/",
"shared" : "shared/",
"templates": "shared/templates/"
},
"layouts": {
"main": "layouts/main"
},
"flickr": {
"api_key": "0984607e2222db7a1be6a5692741ca08"
},
"typekit": {
"id": "wkh7ffm"
},
"yui": {
"version": "3.7.3",
"modules": {
"shared": {
"pnm-place": {
"path" : "models/place.js",
"requires": [
"cache-offline",
"gallery-model-sync-yql",
"model",
"yql"
]
},
"pnm-photo": {
"path" : "models/photo.js",
"requires": [
"gallery-model-sync-yql",
"cache-offline",
"model",
"pnm-place",
"yql"
]
},
"pnm-photos": {
"path" : "models/photos.js",
"requires": [
"cache-offline",
"gallery-model-sync-yql",
"model-list",
"pnm-photo",
"yql"
]
}
},
"client": {
"ios-oc-fix": "/vendor/ios-orientationchange-fix.js",
"pnm-templates": {
"fullpath": "/templates.js",
"requires": ["handlebars-base"]
},
"pnm-grid-view": {
"path" : "views/grid.js",
"requires": [
"node-style",
"node-screen",
"pnm-templates",
"view"
]
},
"pnm-lightbox-view": {
"path" : "views/lightbox.js",
"requires": [
"event-key",
"pnm-templates",
"transition",
"view"
]
},
"pnm-no-location-view": {
"path" : "views/no-location.js",
"requires": [
"pnm-templates",
"view"
]
},
"pnm-app": {
"path" : "app.js",
"requires": [
"app-base",
"app-transitions",
"gallery-geo",
"pnm-grid-view",
"pnm-lightbox-view",
"pnm-no-location-view",
"pnm-photos",
"pnm-place",
"pnm-templates"
]
}
},
"server": {
"gallery-model-sync-yql": {
"path": "/vendor/gallery-model-sync-yql/gallery-model-sync-yql-min.js",
"requires": [
"model",
"yql"
],
"optional": [
"cache",
"cache-offline"
]
}
}
},
"server": {
"useSync": true,
"combine": false,
"groups": {
"server": {},
"shared": {
"base": "shared/js/"
}
}
},
"client": {
"allowRollup": false,
"groups": {
"client": {
"base" : "/js/",
"comboBase": "/combo?",
"root" : "/"
},
"shared": {
"base" : "/js/",
"comboBase": "/shared/combo?",
"root" : "/"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment