Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added /seed entry point, default config and stamping

  • Loading branch information...
commit 9b22b52e2b0b66c4421763e5fd537974a9081fd3 1 parent 368f5c9
@davglass authored
Showing with 71 additions and 0 deletions.
  1. +8 −0 app.js
  2. +47 −0 lib/seed.js
  3. +16 −0 test/index.html
View
8 app.js
@@ -3,6 +3,8 @@
var combo = require('combohandler'),
express = require('express'),
stache = require('stache'),
+ seed = require('./lib/seed'),
+ stamp = 'yui3-nightly',
app = express.createServer();
app.configure(function() {
@@ -26,6 +28,12 @@ app.get('/', function(req, res) {
res.render('index', {});
});
app.get('/yui', combo.combine({rootPath: 'build/www'}), function (req, res) {
+ res.body = res.body.replace(/@VERSION@/g, stamp);
+ res.send(res.body, 200);
+});
+
+app.get('/seed', seed.stamp({rootPath: 'build/www'}), function (req, res) {
+ res.body = res.body.replace(/@VERSION@/g, stamp);
res.send(res.body, 200);
});
View
47 lib/seed.js
@@ -0,0 +1,47 @@
+
+var path = require('path'),
+ fs = require('fs');
+ root = '',
+ seeds = {
+ min: '',
+ raw: '',
+ debug: ''
+ };
+
+
+module.exports = {
+ stamp: function(o) {
+ root = path.join(__dirname, '../', o.rootPath);
+
+ if (!path.existsSync(root)) {
+ throw('Root path does not exist');
+ }
+
+ //All the seed files
+ seeds['min'] = fs.readFileSync(path.join(root, 'yui/yui-min.js'), 'utf8');
+ seeds['raw'] = fs.readFileSync(path.join(root, 'yui/yui.js'), 'utf8');
+ seeds['debug'] = fs.readFileSync(path.join(root, 'yui/yui-debug.js'), 'utf8');
+
+ return function(req, res, next) {
+ //Set the filter type for the seed fetch
+ var filt = seeds[req.query.filter] ? req.query.filter : 'min',
+
+ //Stamp the seed config and version
+ seedStamp = '\n\n/* Stamping Seed File */\n' +
+ 'YUI.applyConfig({\n' +
+ ' comboBase: "http://' + req.headers.host + '/yui?",\n' +
+ ' root: "",\n' +
+ ' filter: "' + filt + '"\n' +
+ '});\n' +
+ '\nYUI.version = "yui3-nightly";';
+
+ //Concat the file with the stamp
+ res.body = seeds[filt] + seedStamp;
+ //Set the content type
+ res.contentType('.js');
+ //Send to next route
+ next();
+
+ }
+ }
+}
View
16 test/index.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<html>
+<head>
+ <title>Nightly test</title>
+</head>
+<body>
+
+
+<script src="http://127.0.0.1:8082/seed"></script>
+<script>
+YUI().use('node', function(Y) {
+ Y.one('body').setStyle('backgroundColor', 'green');
+});
+</script>
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.