Skip to content
Browse files

Removed builder class which was not clearly defined anyway.

Command line file deals with coordinating separate parts now.
Updated component tests to deal with several regressions.
  • Loading branch information...
1 parent b49bd10 commit 9924f8f36d03fb0371e361e8445616e6207dd5c6 mosen committed
Showing with 110 additions and 174 deletions.
  1. +25 −5 bin/cli.js
  2. +0 −155 lib/builder.js
  3. +11 −1 lib/buildspec.js
  4. +43 −3 lib/component.js
  5. +13 −10 lib/queues.js
  6. +18 −0 test/component.test.js
View
30 bin/cli.js
@@ -9,8 +9,11 @@ var path = require('path'),
fs = require('fs'),
util = require('util'),
events = require('events'),
- component = require('../lib/component.js'),
- Builder = require('../lib/builder.js').Builder;
+ Queue = require('buildy/lib/queue').Queue,
+ Buildy = require('buildy').Buildy,
+ Component = require('../lib/component.js').Component,
+ queues = require('../lib/queues.js');
+// Builder = require('../lib/builder.js').Builder;
var buildFileName = "build.json";
@@ -89,9 +92,10 @@ if (buildDirs.length === 0) {
path.exists(buildFilePath, function(exists) {
if (exists) {
- var buildComponent = component.Component(buildFilePath);
- var builder = new Builder(buildComponent);
- builder.run();
+ var c = Component(buildFilePath);
+// var builder = new Builder(buildComponent);
+// builder.run();
+ build(c);
} else {
console.log('Couldnt find a build file at ' + buildFilePath + ', skipping...');
}
@@ -100,6 +104,22 @@ if (buildDirs.length === 0) {
}
}
+function build(component) {
+ var taskQueues = [];
+
+ taskQueues.push(queues._createSourceQueue(component));
+
+ if (component.skinnable) {
+ taskQueues.push(queues._createSkinsQueue(component));
+ taskQueues.push(queues._createAssetsQueue(component));
+ }
+ //taskQueues.push(queues._createDocsQueue(component));
+
+ taskQueues.forEach(function each_queue(moduleQueue) {
+ var worker = new Buildy();
+ moduleQueue.run(worker);
+ }, this);
+}
// Modified from vowsjs
//
View
155 lib/builder.js
@@ -1,155 +0,0 @@
-"use strict";
-
-var Queue = require('buildy/lib/queue').Queue,
- Buildy = require('buildy').Buildy,
- path = require('path'),
- module_path = __dirname;
-
-/**
- * The builder wraps several yui specific task chains, taking a component object and then
- * executing these chains against the object.
- *
- * @class Builder
- * @constructor
- * @param component {Component} component object.
- */
-function Builder(component) {
- this._component = component;
-
- this._buildy = new Buildy();
- this._taskQueues = [];
-
- var jsQueue = new Queue('build source:' + this._component._config.name);
- this._createSourceQueue(jsQueue);
- this._taskQueues.push(jsQueue);
-
- if (this._component._config.details.skinnable === true) {
- var cssQueue = new Queue('build assets:' + this._component._config.name);
- this._createSkinQueue(cssQueue);
- this._taskQueues.push(cssQueue);
-
- var assetsQueue = new Queue('copy extra assets:' + this._component._config.name);
- this._createAssetsQueue(assetsQueue);
- this._taskQueues.push(assetsQueue);
- }
-}
-
-Builder.prototype = {
-
- _template : path.resolve(path.join(module_path, '/../templates/moduletemplate.handlebars')),
-
- _component : null,
-
- _taskQueues : null,
-
- _buildy : null,
-
-// _createSourceQueue : function(q) {
-// var component = this._component,
-// filename_debug = component.getFilename('debug'),
-// filename_core = component.getFilename('core'),
-// filename_min = component.getFilename('min'),
-// module_template = this._template,
-// component_name = component._config.name,
-// component_ver = component._config.version,
-// component_detail= component.getAllDetailsString();
-//
-// console.log('Building component: ' + component_name + ' v' + component_ver);
-// //console.log(component_detail);
-// console.log('Outputting files:');
-// console.log("\tdebug: " + filename_debug);
-// console.log("\tcore: " + filename_core);
-// console.log("\tmin: " + filename_min);
-// console.log("Builder output follows...");
-//
-// q.task('files', component.getSourceFiles()) // all of these synchronous
-// .task('concat')
-// .task('jslint')
-// .task('template', {
-// templateFile: module_template,
-// model: {
-// yuivar : 'Y',
-// component : component._config.name,
-// version : component._config.version,
-// details : component.getAllDetailsString()
-// }
-// })
-// .task('fork', {
-// 'debug code' : function(b) {
-// this.task('write', { name: filename_debug })
-// .task('log')
-// .run(b);
-// },
-// 'core code' : function(b) {
-// this.task('replace', {
-// regex: '^.*?(?:logger|Y.log).*?(?:;|\\).*;|(?:\r?\n.*?)*?\\).*;).*;?.*?\r?\n',
-// replace: '',
-// flags: 'mg'
-// })
-// .task('fork', {
-// 'write core' : function(b) {
-// this.task('write', {
-// name: filename_core
-// })
-// .run(b);
-// },
-// 'minified code' : function(b) {
-// this.task('minify')
-// .task('write', {
-// name: filename_min
-// })
-// .run(b);
-// }
-// }).run(b);
-// }
-// });
-// },
-//
-// _createSkinQueue : function(q) {
-// var component = this._component,
-// filename_skin = component.getSkinFilename('sam'),
-// filename_core = component.getSkinCoreFilename(),
-// filename_min_out = component.getSkinFilename('sam', true);
-//
-// console.log('Outputting files:');
-// console.log("\tmin: " + filename_min_out);
-//
-// q.task('files', [filename_skin, filename_core])
-// .task('concat')
-// .task('csslint')
-// .task('cssminify')
-// .task('write', {
-// name: filename_min_out
-// });
-// },
-//
-// _createAssetsQueue : function(q) {
-// var component = this._component,
-// assets_source = component.getAssetsDir(),
-// assets_dest = component.getAssetsDir(true);
-//
-// console.log('Copying assets:');
-// console.log("\tfrom: " + assets_source);
-// console.log("\tto: " + assets_dest);
-//
-// q.task('copy', {
-// src: [
-// assets_source + '/*'
-// ],
-// dest: assets_dest,
-// recursive: true,
-// excludes: [
-// path.join(component._baseDir, 'assets/skins/')
-// ]
-// });
-// },
-
- run : function() {
- this._taskQueues.forEach(function(q) {
- var worker = Buildy.factory(Buildy.TYPES.STRING, '');
- q.run(worker);
- }, this);
- }
-};
-
-exports.Builder = Builder;
View
12 lib/buildspec.js
@@ -20,7 +20,17 @@ exports.defaultSpec = {
sourceFiles : ["component.js"],
buildDir : "../build",
assetsDir : "assets",
- tools : {},
+ tools : {
+ template : {
+ yuivar : "Y",
+ module_template : "../templates/moduletemplate.handlebars"
+ },
+ replace : {
+ regex: '^.*?(?:logger|Y.log).*?(?:;|\\).*;|(?:\r?\n.*?)*?\\).*;).*;?.*?\r?\n',
+ replace: '',
+ flags: 'mg'
+ }
+ },
details : {
use : null,
supersedes : null,
View
46 lib/component.js
@@ -3,7 +3,7 @@
* YUI component build specification object
*/
var path = require('path'),
- buildspec = require('buildspec');
+ buildspec = require('./buildspec.js');
/**
* Component - wraps the build specification (build.json) and provides convenience
@@ -66,6 +66,12 @@ Component.prototype._getBuildFileName = function(type) {
}
};
+Component.prototype._getAssetsDirectory = function(isBuildFile) {
+ return path.join(this._sourceDir,
+ (!isBuildFile || this._buildSpec.buildDir),
+ this._buildSpec.assetsDir);
+};
+
/**
* Get the skin source/build filename for a given skin.
*
@@ -76,14 +82,16 @@ Component.prototype._getBuildFileName = function(type) {
* @protected
*/
Component.prototype._getSkinFilename = function(name, isBuildFile) {
+ var cssSuffix = isBuildFile ? '' : '-skin';
name = name || 'sam';
+
return path.join(this._sourceDir,
(!isBuildFile || this._buildSpec.buildDir),
this._buildSpec.assetsDir,
- 'names',
+ 'skins',
name,
- this._buildSpec.name + '-name.css');
+ this._buildSpec.name + cssSuffix + '.css');
};
/**
@@ -149,6 +157,11 @@ Component.prototype._initFileNames = function() {
build : this._getSkinFilename('sam', true)
};
+ this._assets = {
+ source : this._getAssetsDirectory(false),
+ build : this._getAssetsDirectory(true)
+ };
+
};
// Details with these names are treated as javascript arrays in the output template.
@@ -158,7 +171,28 @@ Component.prototype._arrayDetails = ['use', 'supersedes', 'requires', 'optional'
var ATTRS = {
/**
+ * @property skinnable
+ * @type Boolean
+ */
+ skinnable : {
+ get : function() {
+ return this._buildSpec.details.skinnable;
+ }
+ },
+
+ /**
+ * @property assets
+ * @type Object
+ */
+ assets : {
+ get : function() {
+ return this._assets;
+ }
+ },
+
+ /**
* @property sourcedir
+ * @type String
*/
sourcedir : {
get : function() { return this._sourceDir; }
@@ -166,6 +200,7 @@ var ATTRS = {
/**
* @property name
+ * @type String
*/
component : {
get : function() { return this._buildSpec.name; },
@@ -174,6 +209,7 @@ var ATTRS = {
/**
* @property sourcefiles
+ * @type Array
*/
sourcefiles : {
get : function() {
@@ -190,6 +226,7 @@ var ATTRS = {
/**
* @property buildfiles
+ * @type Array
*/
buildfiles : {
get : function() { return this._buildFiles; }
@@ -198,6 +235,7 @@ var ATTRS = {
/**
* @property skins
+ * @type Object
*/
skins : {
get : function() { return this._skins; }
@@ -205,6 +243,7 @@ var ATTRS = {
/**
* @property version
+ * @type String
*/
version : {
get : function() {
@@ -217,6 +256,7 @@ var ATTRS = {
/**
* @property details
+ * @type String
*/
details : {
get : function() {
View
23 lib/queues.js
@@ -3,7 +3,8 @@
/**
* Queue definitions for building Yui3 modules
*/
-var Queue = require('buildy/lib/queue').Queue;
+var path = require('path'),
+ Queue = require('buildy/lib/queue').Queue;
/**
* Create a task chain for building yui3 modules from source.
@@ -12,7 +13,7 @@ var Queue = require('buildy/lib/queue').Queue;
* @return {Queue} Instance of a queue with component build tasks added.
*/
exports._createSourceQueue = function(component) {
- var q = new Queue(),
+ var q = new Queue('collect source files'),
component_sourcefiles = component.sourcefiles,
component_buildfiles = component.buildfiles,
@@ -24,7 +25,7 @@ exports._createSourceQueue = function(component) {
.task('concat')
.task('jslint')
.task('template', {
- templateFile: module_template,
+ templateFile: '../templates/moduletemplate.handlebars', // use build spec
model: {
yuivar : 'Y',
component : component_name,
@@ -72,11 +73,11 @@ exports._createSourceQueue = function(component) {
* @return {Queue} Instance
*/
exports._createSkinsQueue = function(component) {
- var q = new Queue(),
+ var q = new Queue('collect stylesheets'),
component_skin_sourcefile = component.skins.sam.source,
component_skin_buildfile = component.skins.sam.build,
- component_skin_corefile = component.skins.core;
+ component_skin_corefile = component.skins.core.source;
q.task('files', [component_skin_sourcefile, component_skin_corefile])
.task('concat')
@@ -96,20 +97,22 @@ exports._createSkinsQueue = function(component) {
* @return {Queue} Instance
*/
exports._createAssetsQueue = function(component) {
- var q = new Queue(),
+ var q = new Queue('collect assets'),
+ component_skin_sourcefile = component.skins.sam.source,
+ component_skin_corefile = component.skins.core.source,
component_assets_sourcedir = component.assets.source,
component_assets_builddir = component.assets.build;
-
q.task('copy', {
src: [
- component_assets_sourcedir + '/*'
+ component_assets_sourcedir
],
- dest: component_assets_builddir,
+ dest: path.dirname(component_assets_builddir),
recursive: true,
excludes: [
- path.join(component.sourcedir, 'assets/skins/')
+ path.join(component.sourcedir, 'assets/skins/', component_skin_corefile),
+ path.join(component.sourcedir, 'assets/skins/sam/', component_skin_sourcefile)
]
});
View
18 test/component.test.js
@@ -41,5 +41,23 @@ module.exports = {
expected = "./test/fixtures";
assert.equal(sourcedir, expected, 'test sourcedir matches expected sourcedir');
+ },
+
+ 'test skin name is included in path to skins directory' : function(beforeExit, assert) {
+ var c = Component('./test/fixtures/build.json'),
+ skins = c.skins;
+
+ assert.equal(skins.core.source, 'test/fixtures/assets/component-core.css', 'test core source css is correct');
+ assert.equal(skins.sam.source, 'test/fixtures/assets/skins/sam/component-skin.css', 'test sam skin css is correct');
+ },
+
+ 'test assets build directory matches expected build directory' : function(beforeExit, assert) {
+ var c = Component('./test/fixtures/build.json'),
+ assets = c.assets;
+
+ assert.equal(assets.source, 'test/fixtures/assets');
+ assert.equal(assets.build, 'test/build/assets');
}
+
+ //'test absence of one skin file does not abort skins queue'
};

0 comments on commit 9924f8f

Please sign in to comment.
Something went wrong with that request. Please try again.