Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/260-trailing-white-space'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbest committed Apr 14, 2012
2 parents 0384099 + cbfc4b9 commit 5c6d813
Show file tree
Hide file tree
Showing 55 changed files with 907 additions and 841 deletions.
12 changes: 10 additions & 2 deletions build/build-linux
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#!/bin/sh

handle_fail() {
echo; echo "Build failed"
exit 1
}

tools/check-trailing-space-linux || handle_fail

OutDebugFile='output/knockout-latest.debug.js'
OutMinFile='output/knockout-latest.js'

# Combine the source files
SourceFiles=`grep js < fragments/source-references.js | # Find JS references
SourceFiles=`grep js < fragments/source-references.js | # Find JS references
sed "s/[ \',]//g" | # Strip off JSON fluff (whitespace, commas, quotes)
sed -e 's/.*/..\/&/' | # Fix the paths by prefixing with ../
tr '\n' ' '` # Combine into single line
Expand Down Expand Up @@ -34,4 +41,5 @@ Version=`cat fragments/version.txt`
sed -i~ -e "s/##VERSION##/$Version/g" $OutDebugFile $OutMinFile

# Delete the odd files left behind on Mac
rm -f output/*.js~
rm -f output/*.js~
echo; echo "Build succeeded"
36 changes: 24 additions & 12 deletions build/build-windows.bat
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
@echo off
@echo off

call tools/check-trailing-space-windows.bat
if %errorlevel% NEQ 0 goto Fail

set OutDebugFile=output\knockout-latest.debug.js
set OutMinFile=output\knockout-latest.js
set AllFiles=
for /f "eol=] skip=1 delims=' " %%i in (fragments\source-references.js) do set Filename=%%i& call :Concatenate
for /f "eol=] skip=1 delims=' " %%i in (fragments\source-references.js) do set Filename=%%i& call :Concatenate

goto :Combine
:Concatenate
if /i "%AllFiles%"=="" (
:Concatenate
if /i "%AllFiles%"=="" (
set AllFiles=..\%Filename:/=\%
) else (
) else (
set AllFiles=%AllFiles% ..\%Filename:/=\%
)
goto :EOF
)
goto :EOF

:Combine
type fragments\amd-pre.js > %OutDebugFile%.temp
type %AllFiles% >> %OutDebugFile%.temp
type %AllFiles% >> %OutDebugFile%.temp 2>nul
type fragments\amd-post.js >> %OutDebugFile%.temp

@rem Now call Google Closure Compiler to produce a minified version
tools\curl -d output_info=compiled_code -d output_format=text -d compilation_level=ADVANCED_OPTIMIZATIONS --data-urlencode "js_code=/**@const*/var DEBUG=false;" --data-urlencode js_code@%OutDebugFile%.temp "http://closure-compiler.appspot.com/compile" > %OutMinFile%.temp

@rem Finalise each file by prefixing with version header and surrounding in function closure
copy /y fragments\version-header.js %OutDebugFile%
copy /y fragments\version-header.js %OutDebugFile% >nul
echo (function(window,document,navigator,undefined){>> %OutDebugFile%
echo var DEBUG=true;>> %OutDebugFile%
type %OutDebugFile%.temp >> %OutDebugFile%
echo })(window,document,navigator);>> %OutDebugFile%
del %OutDebugFile%.temp

copy /y fragments\version-header.js %OutMinFile%
copy /y fragments\version-header.js %OutMinFile% >nul
echo (function(window,document,navigator,undefined){>> %OutMinFile%
type %OutMinFile%.temp >> %OutMinFile%
echo })(window,document,navigator);>> %OutMinFile%
del %OutMinFile%.temp

@rem Inject the version number string
set /p Version= <fragments\version.txt
cscript tools\searchReplace.js "##VERSION##" %VERSION% %OutDebugFile% %OutMinFile%
cscript tools\searchReplace.js "\r\n" "\n" %OutDebugFile% %OutMinFile%
cscript tools\searchReplace.js "##VERSION##" %VERSION% %OutDebugFile% %OutMinFile% >nul
cscript tools\searchReplace.js "\r\n" "\n" %OutDebugFile% %OutMinFile% >nul

echo.
echo Build succeeded
exit /b 0

:Fail
echo.
echo Build failed
2 changes: 1 addition & 1 deletion build/knockout-raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ var DEBUG=true;
referenceScript(buildFolderPath + scriptUrls[i]);
};
referenceScript(buildFolderPath + sourcesReferenceFile);
})();
})();
16 changes: 16 additions & 0 deletions build/tools/check-trailing-space-linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

# Check that all files have trailing spaces stripped
OutTrailingSpaceListFile='output/knockout-files-to-clean.txt'
cd ..
grep -nrI '[ ]$' `find * | grep -E "\.(js|html|css|bat|ps1)$"` | grep -v "^build/output/" > build/$OutTrailingSpaceListFile
cd build
if [ -s $OutTrailingSpaceListFile ]
then
echo "The following files have trailing spaces that need to be cleaned up:"
echo ""
cat $OutTrailingSpaceListFile
rm $OutTrailingSpaceListFile
exit 1
fi
rm $OutTrailingSpaceListFile
19 changes: 19 additions & 0 deletions build/tools/check-trailing-space-windows.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@echo off

@rem Check that all files have trailing spaces stripped
set OutTrailingSpaceListFile=output\knockout-files-to-clean.txt
cd ..
findstr -nrs -c:"[ ]$" *.js *.html *.css *.bat *.ps1 | findstr -rv "^build\\output" > build\%OutTrailingSpaceListFile%
cd build
for %%R in (%OutTrailingSpaceListFile%) do if %%~zR gtr 0 goto :NeedFixTrailingSpace
del %OutTrailingSpaceListFile%
goto :TrailingSpaceOkay

:NeedFixTrailingSpace
echo The following files have trailing spaces that need to be cleaned up:
echo.
type %OutTrailingSpaceListFile%
del %OutTrailingSpaceListFile%
exit /b 1

:TrailingSpaceOkay
11 changes: 11 additions & 0 deletions build/tools/normaliseAllFiles.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# If needed, first run: Set-ExecutionPolicy Unrestricted

$allFiles = (Get-ChildItem -Path ..\..\ -Include *.js,*.css,*.bat,*.html -Recurse)

$allFiles | %{
# Read file, remove trailing spaces/tabs, output back to file in CP1252 format (default for Git on Windows)
# This will also ensure the file has a trailing linebreak
Write-Host "Processing $_..."
$fileContent = (Get-Content $_) -replace "[ \t]+$", ""
[System.IO.File]::WriteAllLines($_, $fileContent, [System.Text.Encoding]::GetEncoding(1252))
}
2 changes: 1 addition & 1 deletion build/tools/searchReplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ for (var i = 2; i < WScript.Arguments.Length; i++) {
var original = readText(filename);
var updated = original.replace(new RegExp(find, "g"), replace);
writeText(filename, updated);
}
}
6 changes: 3 additions & 3 deletions spec/asyncBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ asyncTest("Should notify subscribers asynchronously after writes stop for the sp
observable('C');
observable('D');
equal(notifiedValues.length, 0, "Should not notify synchronously");

// Wait
stop();
setTimeout(function() {
Expand Down Expand Up @@ -104,6 +104,6 @@ asyncTest("Should run evaluator only once when dependencies stop updating for th
start();
equal(evaluationCount, 2); // Finally, it's evaluated
equal(asyncDepObs(), "D");
}, 110);
}, 110);
}, 10);
});
});
Loading

0 comments on commit 5c6d813

Please sign in to comment.