Permalink
Browse files

Perform ##VERSION## substitution during Windows build without new bin…

…ary tool dependencies, and simplify Linux build to match
  • Loading branch information...
1 parent c9abfe6 commit 7c9ed5897064c9b9fb52f2db65734e4ccb944303 @SteveSanderson SteveSanderson committed Jan 10, 2012
Showing with 38 additions and 26 deletions.
  1. +5 −11 build/build-linux
  2. +5 −14 build/build-windows.bat
  3. +27 −0 build/tools/searchReplace.js
  4. +1 −1 src/version.js
View
@@ -3,17 +3,10 @@
OutDebugFile='output/knockout-latest.debug.js'
OutMinFile='output/knockout-latest.js'
-Version=`cat fragments/version.txt`
-VersionHeaderPath='fragments/version-header.js'
-VersionJsFile='../src/version.js'
-sed "s/##VERSION##/$Version/" <$VersionHeaderPath > $VersionHeaderPath.temp
-sed "s/Working-Debug/$Version/" <$VersionJsFile > $VersionJsFile.temp
-
# Combine the source files
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 ../
- sed "s/version\.js/version\.js\.temp/" | # Use a temporary version with correct version number
tr '\n' ' '` # Combine into single line
cat fragments/amd-pre.js > $OutDebugFile.temp
cat $SourceFiles >> $OutDebugFile.temp
@@ -23,17 +16,18 @@ cat fragments/amd-post.js >> $OutDebugFile.temp
curl -d output_info=compiled_code -d output_format=text -d compilation_level=ADVANCED_OPTIMIZATIONS --data-urlencode js_code@$OutDebugFile.temp "http://closure-compiler.appspot.com/compile" > $OutMinFile.temp
# Finalise each file by prefixing with version header and surrounding in function closure
-cp $VersionHeaderPath.temp $OutDebugFile
+cp fragments/version-header.js $OutDebugFile
echo "(function(window,document,navigator,undefined){" >> $OutDebugFile
cat $OutDebugFile.temp >> $OutDebugFile
echo "})(window,document,navigator);" >> $OutDebugFile
rm $OutDebugFile.temp
-cp $VersionHeaderPath.temp $OutMinFile
+cp fragments/version-header.js $OutMinFile
echo "(function(window,document,navigator,undefined){" >> $OutMinFile
cat $OutMinFile.temp >> $OutMinFile
echo "})(window,document,navigator);" >> $OutMinFile
rm $OutMinFile.temp
-rm $VersionHeaderPath.temp
-rm $VersionJsFile.temp
+# Inject the version number string
+Version=`cat fragments/version.txt`
+sed -i "s/##VERSION##/$Version/" $OutDebugFile $OutMinFile
@@ -4,18 +4,8 @@ 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
-set /p Version= <fragments\version.txt
-set VersionHeaderPath=fragments\version-header.js
-set VersionJsFile=..\src\version.js
-tools\sed "s/##VERSION##/%Version%/" <%VersionHeaderPath% > %VersionHeaderPath%.temp
-tools\sed "s/Working-Debug/%Version%/" <%VersionJsFile% > %VersionJsFile%.temp
-
goto :Combine
:Concatenate
- if /i "%Filename%"=="src/version.js" (
- set Filename="src/version.js.temp"
- )
-
if /i "%AllFiles%"=="" (
set AllFiles=..\%Filename:/=\%
) else (
@@ -32,17 +22,18 @@ type fragments\amd-post.js >> %OutDebugFile%.temp
tools\curl -d output_info=compiled_code -d output_format=text -d compilation_level=ADVANCED_OPTIMIZATIONS --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.temp %OutDebugFile%
+copy /y fragments\version-header.js %OutDebugFile%
echo (function(window,document,navigator,undefined){ >> %OutDebugFile%
type %OutDebugFile%.temp >> %OutDebugFile%
echo })(window,document,navigator); >> %OutDebugFile%
del %OutDebugFile%.temp
-copy /y fragments\version-header.js.temp %OutMinFile%
+copy /y fragments\version-header.js %OutMinFile%
echo (function(window,document,navigator,undefined){ >> %OutMinFile%
type %OutMinFile%.temp >> %OutMinFile%
echo })(window,document,navigator); >> %OutMinFile%
del %OutMinFile%.temp
-del %VersionHeaderPath%.temp
-del %VersionJsFile%.temp
+@rem Inject the version number string
+set /p Version= <fragments\version.txt
+cscript tools\searchReplace.js "##VERSION##" %VERSION% %OutDebugFile% %OutMinFile%
@@ -0,0 +1,27 @@
+// Syntax: cscript searchReplace.js searchRegex replaceText file1 file2 file3 ...
+// Example: cscript searchReplace.js Thursday Friday weatherReport.txt
+
+function readText(filename) {
+ var fso = WSH.CreateObject("Scripting.FileSystemObject");
+ var file = fso.OpenTextFile(filename, 1 /* readonly */);
+ var txt = file.ReadAll();
+ file.Close();
+ return txt;
+}
+
+function writeText(filename, text) {
+ var fso = WSH.CreateObject("Scripting.FileSystemObject");
+ var file = fso.OpenTextFile(filename, 2 /* readwrite */, true);
+ file.WriteLine(text);
+ file.Close();
+}
+
+var find = WScript.Arguments.Item(0),
+ replace = WScript.Arguments.Item(1);
+for (var i = 2; i < WScript.Arguments.Length; i++) {
+ var filename = WScript.Arguments.Item(i);
+ WSH.Echo("Replacing content in " + filename + "...");
+ var original = readText(filename);
+ var updated = original.replace(new RegExp(find, "g"), replace);
+ writeText(filename, updated);
+}
View
@@ -1,3 +1,3 @@
-ko.version = "Working-Debug";
+ko.version = "##VERSION##";
ko.exportSymbol('version', ko.version);

0 comments on commit 7c9ed58

Please sign in to comment.