Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CraigCav committed Jul 26, 2013
0 parents commit 4ca002e
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
20 changes: 20 additions & 0 deletions MIT-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2013 Craig Cavalier

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
mimosa-requirebuild-include
===========

Based on [mimosa-requirebuild-textplugin-include](https://github.com/dbashford/mimosa-requirebuild-textplugin-include)

## Overview

This is a Mimosa module. It intercepts the r.js configurations before optimization occurs in order to include additional dependencies that the optimizer might not find during it's static analysis.

The actual function of this module is to find text dependencies and include them in the `include` array for a r.js run via the requirejs text plugin.

For more information regarding Mimosa, see http://mimosajs.com

## Usage

Add `'requirebuild-include'` to your list of modules. That's all! Mimosa will install the module for you when you start up.

## Functionality

The `'mimosa-requirebuild-include'` module configuration is a pointer to a directory of files to include. The patterns option is an array of [glob patterns](http://en.wikipedia.org/wiki/Glob_%28programming%29) relative to the mimosa base url and is used to identify additional files to add to the 'include' array for r.js.

## Default Config

```
requireBuildInclude:
patterns: ["some/dynamically/loaded/folder/**/*.js"]
```

* `patterns`: an array of glob patterns, used to match files to include in the r.js config's 'include' array. Ex: foo/*.js. All files in the watch.javascriptDir/foo folder will be pushed into the array and already present array entries will be left alone.
21 changes: 21 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";

exports.defaults = function() {
return {
requireBuildInclude: {
patterns: []
}
};
};

exports.placeholder = function() {
return "\t\n\n"+
" # requireBuildInclude: \n" +
" # patterns: [] # \n";
};

exports.validate = function(config, validators) {
var errors = [];
validators.isArrayOfStringsMustExist(errors, "requireBuildInclude.patterns", config.requireBuildInclude.patterns);
return errors;
};
101 changes: 101 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"use strict";
var config, minimatch, fs, wrench, win32, path, pathSeparator, registration, normalize, windowsDrive, wrench, __determinePath, _appendFilesToInclude,
__slice = [].slice;

path = require('path');

fs = require('fs');

wrench = require("wrench");

config = require('./config');

minimatch = require('minimatch');;

windowsDrive = /^[A-Za-z]:\\/;

win32 = process.platform === 'win32';

pathSeparator = win32 ? '\\' : '/';

normalize = function (filepath) {
return win32 ? filepath.replace(/\\/g, '/') : filepath;
};

registration = function(mimosaConfig, register) {
var e;

if (mimosaConfig.isOptimize) {
e = mimosaConfig.extensions;
register(['add', 'update', 'remove'], 'beforeOptimize', _appendFilesToInclude, __slice.call(e.javascript).concat(__slice.call(e.template)));
return register(['postBuild'], 'beforeOptimize', _appendFilesToInclude);
}
};

function getExtension(filename) {
var i = filename.lastIndexOf('.');
return (i < 0) ? '' : filename.substr(i);
}

_appendFilesToInclude = function(mimosaConfig, options, next) {
var hasPatterns, hasRunConfigs, _ref;

hasRunConfigs = ((_ref = options.runConfigs) != null ? _ref.length : void 0) > 0;
if (!hasRunConfigs) {
return next();
}
hasPatterns = mimosaConfig.requireBuildInclude.patterns.length > 0;

if (!hasPatterns) {
return next();
}

options.runConfigs.forEach(function(runConfig) {
var files, includeFolder;

includeFolder = __determinePath(mimosaConfig.requireBuildTextPluginInclude.folder, runConfig.baseUrl);

mimosaConfig.requireBuildInclude.patterns.forEach(function (pattern) {
var base, absPattern;

base = normalize(path.join(runConfig.baseUrl, pathSeparator));
absPattern = normalize(path.resolve(base, pattern));

files = wrench.readdirSyncRecursive(includeFolder)
.map(function(file) {
return path.join(includeFolder, file);
})
.filter(function(file) {
return fs.statSync(file).isFile();
})
.map(normalize)
.filter(function(file) {
return minimatch(file, absPattern);
});

return files.forEach(function(file) {
var fileAMD = file.replace(normalize(runConfig.baseUrl), '').substring(1).replace(/\\/g, "/").replace(getExtension(file), '');
return runConfig.include.push(fileAMD);
});
});
});

next();
};

__determinePath = function(thePath, relativeTo) {
if (windowsDrive.test(thePath)) {
return thePath;
}
if (thePath.indexOf("/") === 0) {
return thePath;
}
return path.join(relativeTo, thePath);
};

module.exports = {
registration: registration,
defaults: config.defaults,
placeholder: config.placeholder,
validate: config.validate
};
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "mimosa-requirebuild-include",
"version": "0.0.1",
"homepage": "https://github.com/craigcav/mimosa-requirebuild-include",
"author": "Craig Cavalier",
"description": "Mimosa module for modifiying the r.js config pre-optimize",
"contributors": [
{
"name": "Craig Cavalier",
"email": "craigcav@gmail.com"
}
],
"repository": {
"type": "git",
"url": "https://github.com/craigcav/mimosa-requirebuild-include"
},
"keywords": [
"mimosa",
"mmodule",
"r.js",
"requirejs"
],
"dependencies": {
"logmimosa": "0.5.0",
"wrench": "1.5.1",
"minimatch": "~0.2.5"
},
"license": "MIT",
"engines": {
"node": ">=0.10"
}
}

0 comments on commit 4ca002e

Please sign in to comment.