Skip to content

Commit

Permalink
references #316, to javascript, references #378, tests, file lifecycl…
Browse files Browse the repository at this point in the history
…e module
  • Loading branch information
dbashford committed Jan 31, 2015
1 parent 88683bd commit 7fe87f6
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 114 deletions.
101 changes: 75 additions & 26 deletions lib/modules/file/init.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,82 @@
"use strict";
var _initMultiAsset, _initSingleAsset,
__slice = [].slice;

_initSingleAsset = function(config, options, next) {
var fileUtils;
fileUtils = require('../../util/file');
fileUtils.setFileFlags(config, options);
options.files = [
{
inputFileName: options.inputFile,
outputFileName: null,
inputFileText: null,
outputFileText: null

var fileUtils = require( "../../util/file" );

var _setFileFlags = function( config, options ) {
var exts = config.extensions;
var ext = options.extension;

options.isJavascript = false;
options.isCSS = false;
options.isVendor = false;
options.isJSNotVendor = false;
options.isCopy = false;
options.isTemplate = false;

if ( exts.template.indexOf( ext ) > -1 ) {
options.isTemplate = true;
options.isJavascript = true;
options.isJSNotVendor = true;
}

if ( exts.copy.indexOf( ext ) > -1 ) {
options.isCopy = true;
}

if (
exts.javascript.indexOf( ext ) > -1 ||
( options.inputFile && fileUtils.isJavascript( options.inputFile ) )
){
options.isJavascript = true;
if ( options.inputFile ) {
options.isVendor = fileUtils.isVendorJS( config, options.inputFile );
options.isJSNotVendor = !options.isVendor;
}
}

if (
exts.css.indexOf( ext ) > -1 ||
( options.inputFile && fileUtils.isCSS( options.inputFile ) )
){
options.isCSS = true;
if ( options.inputFile ) {
options.isVendor = fileUtils.isVendorCSS( config, options.inputFile );
}
];
return next();
}
};

_initMultiAsset = function(config, options, next) {
var fileUtils;
fileUtils = require('../../util/file');
fileUtils.setFileFlags(config, options);
options.files = [];
return next();
var _initSingleAsset = function( config, options, next ) {
_setFileFlags( config, options );

options.files = [{
inputFileName:options.inputFile,
outputFileName:null,
inputFileText:null,
outputFileText:null
}];

next();
};

exports.registration = function(config, register) {
var e;
e = config.extensions;
register(['add', 'update', 'remove', 'cleanFile', 'buildExtension'], 'init', _initMultiAsset, __slice.call(e.template).concat(__slice.call(e.css)));
return register(['add', 'update', 'remove', 'cleanFile', 'buildFile'], 'init', _initSingleAsset, __slice.call(e.javascript).concat(__slice.call(e.copy), __slice.call(e.misc)));
var _initMultiAsset = function( config, options, next ) {
_setFileFlags( config, options );
options.files = [];
next();
};

exports.registration = function( config, register ) {
var e = config.extensions;
register(
["add", "update", "remove", "cleanFile", "buildExtension"],
"init",
_initMultiAsset,
[].concat.apply(e.template, e.css)
);

register(
["add", "update", "remove", "cleanFile", "buildFile"],
"init",
_initSingleAsset,
[].concat.apply(e.javascript, e.copy, e.misc)
);
};
32 changes: 0 additions & 32 deletions lib/util/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,35 +156,3 @@ exports.readdirSyncRecursive = function(baseDir, excludes, excludeRegex, ignoreD
};
return readdirSyncRecursive(baseDir);
};

exports.setFileFlags = function(config, options) {
var ext, exts;
exts = config.extensions;
ext = options.extension;
options.isJavascript = false;
options.isCSS = false;
options.isVendor = false;
options.isJSNotVendor = false;
options.isCopy = false;
if (exts.template.indexOf(ext) > -1) {
options.isTemplate = true;
options.isJavascript = true;
options.isJSNotVendor = true;
}
if (exts.copy.indexOf(ext) > -1) {
options.isCopy = true;
}
if (exts.javascript.indexOf(ext) > -1 || (options.inputFile && isJavascript(options.inputFile))) {
options.isJavascript = true;
if (options.inputFile) {
options.isVendor = isVendorJS(config, options.inputFile);
options.isJSNotVendor = !options.isVendor;
}
}
if (exts.css.indexOf(ext) > -1 || (options.inputFile && isCSS(options.inputFile))) {
options.isCSS = true;
if (options.inputFile) {
return options.isVendor = isVendorCSS(config, options.inputFile);
}
}
};
25 changes: 0 additions & 25 deletions src/modules/file/init.coffee

This file was deleted.

82 changes: 82 additions & 0 deletions src/modules/file/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"use strict";

var fileUtils = require( "../../util/file" );

var _setFileFlags = function( config, options ) {
var exts = config.extensions;
var ext = options.extension;

options.isJavascript = false;
options.isCSS = false;
options.isVendor = false;
options.isJSNotVendor = false;
options.isCopy = false;
options.isTemplate = false;

if ( exts.template.indexOf( ext ) > -1 ) {
options.isTemplate = true;
options.isJavascript = true;
options.isJSNotVendor = true;
}

if ( exts.copy.indexOf( ext ) > -1 ) {
options.isCopy = true;
}

if (
exts.javascript.indexOf( ext ) > -1 ||
( options.inputFile && fileUtils.isJavascript( options.inputFile ) )
){
options.isJavascript = true;
if ( options.inputFile ) {
options.isVendor = fileUtils.isVendorJS( config, options.inputFile );
options.isJSNotVendor = !options.isVendor;
}
}

if (
exts.css.indexOf( ext ) > -1 ||
( options.inputFile && fileUtils.isCSS( options.inputFile ) )
){
options.isCSS = true;
if ( options.inputFile ) {
options.isVendor = fileUtils.isVendorCSS( config, options.inputFile );
}
}
};

var _initSingleAsset = function( config, options, next ) {
_setFileFlags( config, options );

options.files = [{
inputFileName:options.inputFile,
outputFileName:null,
inputFileText:null,
outputFileText:null
}];

next();
};

var _initMultiAsset = function( config, options, next ) {
_setFileFlags( config, options );
options.files = [];
next();
};

exports.registration = function( config, register ) {
var e = config.extensions;
register(
["add", "update", "remove", "cleanFile", "buildExtension"],
"init",
_initMultiAsset,
[].concat.apply(e.template, e.css)
);

register(
["add", "update", "remove", "cleanFile", "buildFile"],
"init",
_initSingleAsset,
[].concat.apply(e.javascript, e.copy, e.misc)
);
};
31 changes: 1 addition & 30 deletions src/util/file.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,4 @@ exports.readdirSyncRecursive = (baseDir, excludes = [], excludeRegex, ignoreDire
files = files.concat(readdirSyncRecursive(nextDirs.shift()))
files

readdirSyncRecursive(baseDir)

exports.setFileFlags = (config, options) ->
exts = config.extensions
ext = options.extension

options.isJavascript = false
options.isCSS = false
options.isVendor = false
options.isJSNotVendor = false
options.isCopy = false

if exts.template.indexOf(ext) > -1
options.isTemplate = true
options.isJavascript = true
options.isJSNotVendor = true

if exts.copy.indexOf(ext) > -1
options.isCopy = true

if exts.javascript.indexOf(ext) > -1 or (options.inputFile and isJavascript(options.inputFile))
options.isJavascript = true
if options.inputFile
options.isVendor = isVendorJS(config, options.inputFile)
options.isJSNotVendor = not options.isVendor

if exts.css.indexOf(ext) > -1 or (options.inputFile and isCSS(options.inputFile))
options.isCSS = true
if options.inputFile
options.isVendor = isVendorCSS(config, options.inputFile)
readdirSyncRecursive(baseDir)
3 changes: 2 additions & 1 deletion test/unit-test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
require("./units/modules/file/write-test");
require("./units/modules/file/read-test");
require("./units/modules/file/read-test");
require("./units/modules/file/init-test");
Loading

0 comments on commit 7fe87f6

Please sign in to comment.