@@ -2,8 +2,6 @@ const childProcess = require("child_process");
22const EOL = require ( "os" ) . EOL ;
33const now = new Date ( ) . toISOString ( ) ;
44
5- const CONFIG_JSON_PATH = "config/config.json" ;
6-
75const ENVIRONMENTS = {
86 live : "live" ,
97 dev : "dev"
@@ -143,7 +141,7 @@ module.exports = function (grunt) {
143141 "isWindows" : true ,
144142 "isMacOS" : true ,
145143 "isLinux" : true ,
146- "formatListOfNames" : ( ) => { } ,
144+ "formatListOfNames" : ( ) => { } ,
147145 "constants" : ""
148146 }
149147 } ,
@@ -166,57 +164,49 @@ module.exports = function (grunt) {
166164 grunt . loadNpmTasks ( "grunt-template" ) ;
167165
168166 grunt . registerTask ( "set_package_version" , function ( version ) {
167+ // NOTE: DO NOT call this task in npm's prepack script - it will change the version in package.json,
168+ // but npm will still try to publish the version that was originally specified in the package.json/
169+ // Also this may break some Jenkins builds as the produced package will have unexpected name.
169170 var buildVersion = version !== undefined ? version : buildNumber ;
170171 if ( process . env [ "BUILD_CAUSE_GHPRBCAUSE" ] ) {
171172 buildVersion = "PR" + buildVersion ;
172173 }
173174
174175 var packageJson = grunt . file . readJSON ( "package.json" ) ;
175176 var versionParts = packageJson . version . split ( "-" ) ;
176- if ( process . env [ "RELEASE_BUILD" ] ) {
177- // HACK - excluded until 1.0.0 release or we refactor our project infrastructure (whichever comes first)
178- // packageJson.version = versionParts[0];
179- } else {
177+
178+ // The env is used in Jenkins job to produce package that will be releasd with "latest" tag in npm (i.e. strict version).
179+ if ( ! process . env [ "RELEASE_BUILD" ] ) {
180180 versionParts [ 1 ] = buildVersion ;
181181 packageJson . version = versionParts . join ( "-" ) ;
182182 }
183+
183184 grunt . file . write ( "package.json" , JSON . stringify ( packageJson , null , " " ) ) ;
184185 } ) ;
185186
186187 grunt . registerTask ( "tslint:build" , function ( version ) {
187188 childProcess . execSync ( "npm run tslint" , { stdio : "inherit" } ) ;
188189 } ) ;
189190
190- grunt . registerTask ( "enableScripts" , function ( enable ) {
191- var enableTester = / f a l s e / i;
192- var newScriptsAttr = ! enableTester . test ( enable ) ? "scripts" : "skippedScripts" ;
193- var packageJson = grunt . file . readJSON ( "package.json" ) ;
194- var oldScriptsAttrValue = packageJson . scripts || packageJson . skippedScripts ;
195- delete packageJson . scripts ;
196- delete packageJson . skippedScripts ;
197- packageJson [ newScriptsAttr ] = oldScriptsAttrValue ;
198- grunt . file . write ( "package.json" , JSON . stringify ( packageJson , null , " " ) ) ;
199- } ) ;
200-
201191 const setConfig = ( key , value ) => {
202192 const configJson = grunt . file . readJSON ( CONFIG_DATA . filePath ) ;
203193 configJson [ key ] = value ;
204194 const stringConfigContent = JSON . stringify ( configJson , null , " " ) + EOL ;
205195 grunt . file . write ( CONFIG_DATA . filePath , stringConfigContent ) ;
206196 }
207197
208- grunt . registerTask ( "set_live_ga_id" , function ( ) {
198+ grunt . registerTask ( "set_live_ga_id" , function ( ) {
209199 setConfig ( CONFIG_DATA . gaKey , GA_TRACKING_IDS [ ENVIRONMENTS . live ] ) ;
210200 } ) ;
211201
212- grunt . registerTask ( "set_dev_ga_id" , function ( ) {
202+ grunt . registerTask ( "set_dev_ga_id" , function ( ) {
213203 setConfig ( CONFIG_DATA . gaKey , GA_TRACKING_IDS [ ENVIRONMENTS . dev ] ) ;
214204 } ) ;
215205
216- grunt . registerTask ( "verify_live_ga_id" , function ( ) {
206+ grunt . registerTask ( "verify_live_ga_id" , function ( ) {
217207 var configJson = grunt . file . readJSON ( CONFIG_DATA . filePath ) ;
218208
219- if ( configJson [ CONFIG_DATA . gaKey ] !== GA_TRACKING_IDS [ ENVIRONMENTS . live ] ) {
209+ if ( configJson [ CONFIG_DATA . gaKey ] !== GA_TRACKING_IDS [ ENVIRONMENTS . live ] ) {
220210 throw new Error ( "Google Analytics id is not configured correctly." ) ;
221211 }
222212 } ) ;
@@ -234,6 +224,16 @@ module.exports = function (grunt) {
234224 "set_package_version" ,
235225 "shell:build_package"
236226 ] ) ;
227+
228+ grunt . registerTask ( "travisPack" , function ( ) {
229+ if ( travis && process . env . TRAVIS_PULL_REQUEST_BRANCH ) {
230+ return grunt . task . run ( "pack" ) ;
231+ }
232+
233+ // Set correct version in Travis job, so the deploy will not publish strict version (for example 5.2.0).
234+ grunt . task . run ( "set_package_version" ) ;
235+ console . log ( `Skipping pack step as the current build is not from PR, so it will be packed from the deploy provider.` ) ;
236+ } ) ;
237237 grunt . registerTask ( "lint" , [ "tslint:build" ] ) ;
238238 grunt . registerTask ( "all" , [ "clean" , "test" , "lint" ] ) ;
239239 grunt . registerTask ( "rebuild" , [ "clean" , "ts:devlib" ] ) ;
0 commit comments