11/*
22 * Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
3- *
3+ *
44 * Permission is hereby granted, free of charge, to any person obtaining a
5- * copy of this software and associated documentation files (the "Software"),
6- * to deal in the Software without restriction, including without limitation
7- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8- * and/or sell copies of the Software, and to permit persons to whom the
5+ * copy of this software and associated documentation files (the "Software"),
6+ * to deal in the Software without restriction, including without limitation
7+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+ * and/or sell copies of the Software, and to permit persons to whom the
99 * Software is furnished to do so, subject to the following conditions:
10- *
10+ *
1111 * The above copyright notice and this permission notice shall be included in
1212 * all copies or substantial portions of the Software.
13- *
13+ *
1414 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1616 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2020 * DEALINGS IN THE SOFTWARE.
21- *
21+ *
2222 */
2323/*global module, require*/
2424
2525module . exports = function ( grunt ) {
2626 "use strict" ;
27-
28- var common = require ( "./common" ) ( grunt ) ;
27+
28+ var common = require ( "./common" ) ( grunt ) ,
29+ semver = require ( "semver" ) ;
2930
3031 function safeReplace ( content , regexp , replacement ) {
32+ if ( ! regexp . test ( content ) ) {
33+ grunt . fail . fatal ( "Regexp " + regexp + " did not match" ) ;
34+ }
35+
3136 var newContent = content . replace ( regexp , replacement ) ;
3237
3338 if ( newContent === content ) {
34- grunt . fail . fatal ( "Regexp " + regexp + " did not match ") ;
39+ grunt . log . warn ( "Buildnumber for " , regexp , "hasn't been updated, because it's already set. ") ;
3540 }
3641
3742 return newContent ;
3843 }
39-
44+
4045 // task: set-release
4146 grunt . registerTask ( "set-release" , "Update occurrences of release number for all native installers and binaries" , function ( ) {
4247 var packageJsonPath = "package.json" ,
@@ -46,68 +51,68 @@ module.exports = function (grunt) {
4651 wxsPath = "installer/win/Brackets.wxs" ,
4752 versionRcPath = "appshell/version.rc" ,
4853 infoPlistPath = "appshell/mac/Info.plist" ,
49- release = grunt . option ( "release" ) || 0 ,
50- versionShort = packageJSON . version . substr ( 0 , packageJSON . version . indexOf ( "-" ) ) ,
51- text ;
52-
53- // replace release number in short version, e.g. N.<release>.N
54- versionShort = versionShort . replace ( / ( [ 0 - 9 ] + \. ) ( [ 0 - 9 ] + ) ( \. [ 0 - 9 ] + ) / , "$1" + release + "$3" ) ;
54+ release = grunt . option ( "release" ) || "" ,
55+ text ,
56+ newVersion ;
5557
56- if ( ! release ) {
57- grunt . fail . fatal ( "Please specify a release. e.g. grunt set-release --release=21 " ) ;
58+ if ( ! release || ! semver . valid ( release ) ) {
59+ grunt . fail . fatal ( "Please specify a release. e.g. grunt set-release --release=1.0.0 " ) ;
5860 }
59-
61+
62+ newVersion = semver . parse ( release ) ;
63+
6064 // 1. Update package.json
61- packageJSON . version = safeReplace (
62- packageJSON . version ,
63- / ( [ 0 - 9 ] + \. ) ( [ 0 - 9 ] + ) ( [ \. \- a - z A - Z 0 - 9 ] * ) ? / ,
64- "$1" + release + "$3"
65- ) ;
65+ packageJSON . version = newVersion . version + "-0" ;
6666 common . writeJSON ( packageJsonPath , packageJSON ) ;
67-
67+
6868 // 2. Open installer/win/brackets-win-install-build.xml and change `product.release.number`
6969 text = grunt . file . read ( winInstallerBuildXmlPath ) ;
7070 text = safeReplace (
7171 text ,
72- / < p r o p e r t y n a m e = " p r o d u c t \. r e l e a s e \. n u m b e r \. m i n o r " v a l u e = " ( [ 0 - 9 ] + ) " \/ > / ,
73- '<property name="product.release.number.minor" value="' + release + '"/>'
72+ / < p r o p e r t y n a m e = " p r o d u c t \. r e l e a s e \. n u m b e r \. m a j o r " v a l u e = " ( \d + ) " \/ > / ,
73+ '<property name="product.release.number.major" value="' + newVersion . major + '"/>'
74+ ) ;
75+ text = safeReplace (
76+ text ,
77+ / < p r o p e r t y n a m e = " p r o d u c t \. r e l e a s e \. n u m b e r \. m i n o r " v a l u e = " ( \d + ) " \/ > / ,
78+ '<property name="product.release.number.minor" value="' + newVersion . minor + '"/>'
7479 ) ;
7580 grunt . file . write ( winInstallerBuildXmlPath , text ) ;
76-
81+
7782 // 3. Open installer/mac/buildInstaller.sh and change `dmgName`
7883 text = grunt . file . read ( buildInstallerScriptPath ) ;
7984 text = safeReplace (
8085 text ,
81- / ( R e l e a s e [ 0 - 9 ] + \. ) ( [ 0 - 9 ] + ) / ,
82- "$1" + release
86+ / v e r s i o n = " \d + \. \d + " / ,
87+ "version=\"" + newVersion . major + "." + newVersion . minor + "\""
8388 ) ;
8489 grunt . file . write ( buildInstallerScriptPath , text ) ;
85-
90+
8691 // 4. Open appshell/version.rc and change `FILEVERSION` and `"FileVersion"`
8792 text = grunt . file . read ( versionRcPath ) ;
8893 text = safeReplace (
8994 text ,
90- / ( F I L E V E R S I O N \s + [ 0 - 9 ] + , ) ( [ 0 - 9 ] + ) / ,
91- "$1" + release
95+ / ( F I L E V E R S I O N \s + ) \d + , \d + , \d + , \d + / ,
96+ "$1" + newVersion . major + "," + newVersion . minor + "," + newVersion . patch + "," + ( newVersion . build . length ? newVersion . build : "0" )
9297 ) ;
9398 text = safeReplace (
9499 text ,
95- / ( R e l e a s e [ 0 - 9 ] + \. ) ( [ 0 - 9 ] + ) / ,
96- "$1" + release
100+ / ( R e l e a s e ) ( [ \d + . ] + ) / ,
101+ "$1" + newVersion . version
97102 ) ;
98103 grunt . file . write ( versionRcPath , text ) ;
99-
100- // 5. Open appshell/mac/Info.plist and change `CFBundleShortVersionString` and `CFBundleVersion`text = grunt.file.read(wxsPath);
104+
105+ // 5. Open appshell/mac/Info.plist and change `CFBundleShortVersionString` and `CFBundleVersion`
101106 text = grunt . file . read ( infoPlistPath ) ;
102107 text = safeReplace (
103108 text ,
104- / ( < k e y > C F B u n d l e V e r s i o n < \/ k e y > \s * < s t r i n g > ) ( [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + ) ( < \/ s t r i n g > ) / ,
105- "$1" + versionShort + "$3"
109+ / ( < k e y > C F B u n d l e V e r s i o n < \/ k e y > \s * < s t r i n g > ) ( \d + \. \d + \. \d + ) ( < \/ s t r i n g > ) / ,
110+ "$1" + newVersion . version + "$3"
106111 ) ;
107112 text = safeReplace (
108113 text ,
109- / ( < k e y > C F B u n d l e S h o r t V e r s i o n S t r i n g < \/ k e y > \s * < s t r i n g > ) ( [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + ) ( < \/ s t r i n g > ) / ,
110- "$1" + versionShort + "$3"
114+ / ( < k e y > C F B u n d l e S h o r t V e r s i o n S t r i n g < \/ k e y > \s * < s t r i n g > ) ( \d + \. \d + \. \d + ) ( < \/ s t r i n g > ) / ,
115+ "$1" + newVersion . version + "$3"
111116 ) ;
112117 grunt . file . write ( infoPlistPath , text ) ;
113118 } ) ;
0 commit comments