public
Created

  • Download Gist
bundle.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
##################################################
#resources
##################################################
#http://blogs.msdn.com/b/kalleb/archive/2008/07/19/using-powershell-to-read-xml-files.aspx
#http://tfl09.blogspot.com/2007/11/formatting-with-powershell.html
#http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/
##################################################
#resources
##################################################
 
$solutionDir = ".\"
$projectDir = "{0}BundleMinifyStuffTry\" -f $solutionDir
$bundleXml = "{0}App_Data\Bundle.xml" -f $projectDir
$bundleXmlFullPath = (resolve-path $bundleXml).Path
 
sal ___AjaxMin .\tools\AjaxMin.exe
 
$bundleXmlFile = [xml](get-content($bundleXmlFullPath))
 
$bundleTypes = $bundleXmlFile.metadata.types.item
$bundleBundles = $bundleXmlFile.metadata.bundles.bundle
 
foreach($type in $bundleTypes) {
 
$_type = $type.type
$_fileExtension = $type.fileExtension
$_rootDir = $type.rootDir
$_rootDestination = $type.rootDestination
$_copyFiles = $type.copyFiles
 
$_destinationDir = "{0}{1}" -f $projectDir, $_rootDestination
 
#test if the dir exists and create if not
if(!(Test-Path $_destinationDir)) {
 
#destination dir does not exist, creating it
mkdir $_destinationDir
}
 
$_bundle = $bundleBundles | where { $_.type -eq $_type }
 
foreach($__bundle in $_bundle) {
 
$__output = $__bundle.output
$__outputFileDir = "{0}{1}.min.{2}" -f $_destinationDir, $__output, $_fileExtension
 
$__fileNamesState
foreach($__file in $__bundle.file) {
 
$__fileName = '"{0}{1}{2}.{3}"' -f $projectDir, $_rootDir, $__file.dir, $_fileExtension
$__fileNamesState += "{0} " -f $__fileName
}
 
$__filesToBundle = $__fileNamesState
 
#bundle and minify
___AjaxMin -clobber $__filesToBundle -o $__outputFileDir
 
$__fileNamesState = $null
}
 
if($_copyFiles) {
 
Copy-Item ("{0}{1}*" -f $projectDir, $_rootDir) $_destinationDir -force -recurse
}
}
bundle.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?xml version="1.0" encoding="utf-8" ?>
<metadata>
<types>
<item type="js" fileExtension="js" rootDir="scripts/" rootDestination="assets/js/" />
<item type="css" fileExtension="css" rootDir="content/" rootDestination="assets/css/" copyFiles="true" />
</types>
<bundles>
<!--CSS Bundles-->
<bundle type="css" output="global">
<file dir="bootstrap" />
<file dir="style" />
</bundle>
 
<!--JS Bundles-->
<bundle type="js" output="global">
<file dir="jquery-1.7.2" />
<file dir="jquery-ui-1.8.20" />
<file dir="knockout-2.1.0.debug" />
<file dir="jquery.validate" />
<file dir="jquery.validate.unobtrusive" />
<file dir="bootstrap" />
</bundle>
<bundle type="js" output="app/index">
<file dir="app/index" />
</bundle>
</bundles>
</metadata>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.