Skip to content

Commit

Permalink
Merge pull request #19 from NickLarsen/master
Browse files Browse the repository at this point in the history
Add command line options
  • Loading branch information
NickLarsen committed Jun 19, 2012
2 parents a199b6c + 55ee359 commit 9e9cd43
Show file tree
Hide file tree
Showing 43 changed files with 18,101 additions and 32 deletions.
52 changes: 36 additions & 16 deletions src/bundler.js
Expand Up @@ -22,11 +22,39 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

function clone(o) {
var ret = {};
Object.keys(o).forEach(function (val) {
ret[val] = o[val];
});
return ret;
}
String.prototype.startsWith = function (str){
return this.indexOf(str) === 0;
};
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
String.prototype.endsWithAny = function (endings) {
var str = this;
return endings.some(function (ending) { return str.endsWith(ending); });
}

//recursively scans the directory below for *.js.bundle and *.css.bundle files
var SCAN_ROOT_DIRS = process.argv.splice(2); //directories specified in bundler.cmd
var commandLineArgs = process.argv.splice(2); //directories specified in bundler.cmd

var commandLineOptions = commandLineArgs.filter(function (arg) { return arg.startsWith('#'); });
var defaultOptions = {};
commandLineOptions.forEach(function (option) {
while (option.startsWith('#')) { option = option.substring(1); }
var parts = option.split(':');
defaultOptions[parts[0].toLowerCase()] = parts.length > 1 ? parts[1] : true;
});

var SCAN_ROOT_DIRS = commandLineArgs.filter(function (arg) { return !arg.startsWith('#'); });
if (!SCAN_ROOT_DIRS.length) {
console.log("No directories were specified.");
console.log("Usage: bundler.cmd ../Content ../Scripts");
console.log("Usage: bundler.js [#option:value] ../Content [../Scripts]");
return;
}

Expand All @@ -41,16 +69,6 @@ var fs = require("fs"),
Step = require('step'),
startedAt = Date.now();

String.prototype.startsWith = function (str){
return this.indexOf(str) === 0;
};
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
String.prototype.endsWithAny = function (endings) {
var str = this;
return endings.some(function (ending) { return str.endsWith(ending); });
}

var walk = function (dir, done) {
var results = [];
Expand Down Expand Up @@ -100,8 +118,10 @@ function scanDir(allFiles, cb) {
var jsBundles = allFiles.filter(function (file) { return file.endsWith(".js.bundle"); });
var cssBundles = allFiles.filter(function (file) { return file.endsWith(".css.bundle"); });

function getOptions(optionsString) {
var options = {};
function getOptions(fileLines) {
var options = clone(defaultOptions);
if (fileLines.length === 0) return options;
var optionsString = fileLines[0];
if (!optionsString.startsWith('#options ')) return options;
optionsString.substring(9).split(',').forEach(function (option) {
var parts = option.split(':');
Expand All @@ -125,7 +145,7 @@ function scanDir(allFiles, cb) {
var bundleName = jsBundle.replace('.bundle', '');
readTextFile(jsBundle, function (data) {
var jsFiles = removeCR(data).split("\n");
var options = jsFiles.length > 0 ? getOptions(jsFiles[0]) : {};
var options = getOptions(jsFiles);
if (options.folder !== undefined) {
options.nobundle = true;
var recursive = options.folder === 'recursive';
Expand Down Expand Up @@ -156,7 +176,7 @@ function scanDir(allFiles, cb) {
var bundleName = cssBundle.replace('.bundle', '');
readTextFile(cssBundle, function (data) {
var cssFiles = removeCR(data).split("\n");
var options = cssFiles.length > 0 ? getOptions(cssFiles[0]) : {};
var options = getOptions(cssFiles);
if (options.folder !== undefined) {
options.nobundle = true;
var recursive = options.folder === 'recursive';
Expand Down
1 change: 1 addition & 0 deletions src/vs/BundlerRunOnSave/BundlerRunOnSavePackage.cs
Expand Up @@ -202,6 +202,7 @@ private void RunBundler(string bundleCommandFullName)
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
};

process.Exited += (sender, args) =>
Expand Down
31 changes: 31 additions & 0 deletions tests/Bootstrap.Mvc/Bootstrap.Mvc.csproj
Expand Up @@ -72,8 +72,39 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Content-CommandLineOptions\app.css" />
<Content Include="Content-CommandLineOptions\app.js" />
<Content Include="Content-CommandLineOptions\css\bootstrap-responsive.css" />
<Content Include="Content-CommandLineOptions\css\bootstrap.css" />
<Content Include="Content-CommandLineOptions\img\glyphicons-halflings-white.png" />
<Content Include="Content-CommandLineOptions\img\glyphicons-halflings.png" />
<Content Include="Content-CommandLineOptions\js\backbone.js" />
<Content Include="Content-CommandLineOptions\js\base.js" />
<Content Include="Content-CommandLineOptions\js\bootstrap.js" />
<Content Include="Content-CommandLineOptions\js\ss-validation.js" />
<Content Include="Content-CommandLineOptions\js\underscore.js" />
<Content Include="Content-CommandLineOptions\options\folder\app.js" />
<Content Include="Content-CommandLineOptions\options\folder\something\something.js" />
<Content Include="Content-CommandLineOptions\options\folder\thirdparty\thirdparty.js" />
<Content Include="Content-CommandLineOptions\options\nobundle\app.js" />
<Content Include="Content-CommandLineOptions\options\skipmin\app.js" />
<Content Include="Content\css\bootstrap-responsive.css" />
<Content Include="Content\css\bootstrap.css" />
<None Include="Content-CommandLineOptions\app.css.bundle" />
<None Include="Content-CommandLineOptions\app.js.bundle" />
<None Include="Content-CommandLineOptions\css\default.less" />
<None Include="Content-CommandLineOptions\js\app.coffee" />
<None Include="Content-CommandLineOptions\options\folder\app.less" />
<None Include="Content-CommandLineOptions\options\folder\folder-recursive.css.bundle" />
<None Include="Content-CommandLineOptions\options\folder\folder-recursive.js.bundle" />
<None Include="Content-CommandLineOptions\options\folder\folder.css.bundle" />
<None Include="Content-CommandLineOptions\options\folder\folder.js.bundle" />
<None Include="Content-CommandLineOptions\options\nobundle\app.less" />
<None Include="Content-CommandLineOptions\options\nobundle\nobundle.css.bundle" />
<None Include="Content-CommandLineOptions\options\nobundle\nobundle.js.bundle" />
<None Include="Content-CommandLineOptions\options\skipmin\app.less" />
<None Include="Content-CommandLineOptions\options\skipmin\skipmin.css.bundle" />
<None Include="Content-CommandLineOptions\options\skipmin\skipmin.js.bundle" />
<None Include="Content\app.css.bundle" />
<None Include="Content\app.js.bundle" />
<None Include="Content\css\default.less" />
Expand Down

0 comments on commit 9e9cd43

Please sign in to comment.