@@ -2,8 +2,6 @@ const childProcess = require("child_process");
2
2
const EOL = require ( "os" ) . EOL ;
3
3
const now = new Date ( ) . toISOString ( ) ;
4
4
5
- const CONFIG_JSON_PATH = "config/config.json" ;
6
-
7
5
const ENVIRONMENTS = {
8
6
live : "live" ,
9
7
dev : "dev"
@@ -143,7 +141,7 @@ module.exports = function (grunt) {
143
141
"isWindows" : true ,
144
142
"isMacOS" : true ,
145
143
"isLinux" : true ,
146
- "formatListOfNames" : ( ) => { } ,
144
+ "formatListOfNames" : ( ) => { } ,
147
145
"constants" : ""
148
146
}
149
147
} ,
@@ -166,57 +164,49 @@ module.exports = function (grunt) {
166
164
grunt . loadNpmTasks ( "grunt-template" ) ;
167
165
168
166
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.
169
170
var buildVersion = version !== undefined ? version : buildNumber ;
170
171
if ( process . env [ "BUILD_CAUSE_GHPRBCAUSE" ] ) {
171
172
buildVersion = "PR" + buildVersion ;
172
173
}
173
174
174
175
var packageJson = grunt . file . readJSON ( "package.json" ) ;
175
176
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" ] ) {
180
180
versionParts [ 1 ] = buildVersion ;
181
181
packageJson . version = versionParts . join ( "-" ) ;
182
182
}
183
+
183
184
grunt . file . write ( "package.json" , JSON . stringify ( packageJson , null , " " ) ) ;
184
185
} ) ;
185
186
186
187
grunt . registerTask ( "tslint:build" , function ( version ) {
187
188
childProcess . execSync ( "npm run tslint" , { stdio : "inherit" } ) ;
188
189
} ) ;
189
190
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
-
201
191
const setConfig = ( key , value ) => {
202
192
const configJson = grunt . file . readJSON ( CONFIG_DATA . filePath ) ;
203
193
configJson [ key ] = value ;
204
194
const stringConfigContent = JSON . stringify ( configJson , null , " " ) + EOL ;
205
195
grunt . file . write ( CONFIG_DATA . filePath , stringConfigContent ) ;
206
196
}
207
197
208
- grunt . registerTask ( "set_live_ga_id" , function ( ) {
198
+ grunt . registerTask ( "set_live_ga_id" , function ( ) {
209
199
setConfig ( CONFIG_DATA . gaKey , GA_TRACKING_IDS [ ENVIRONMENTS . live ] ) ;
210
200
} ) ;
211
201
212
- grunt . registerTask ( "set_dev_ga_id" , function ( ) {
202
+ grunt . registerTask ( "set_dev_ga_id" , function ( ) {
213
203
setConfig ( CONFIG_DATA . gaKey , GA_TRACKING_IDS [ ENVIRONMENTS . dev ] ) ;
214
204
} ) ;
215
205
216
- grunt . registerTask ( "verify_live_ga_id" , function ( ) {
206
+ grunt . registerTask ( "verify_live_ga_id" , function ( ) {
217
207
var configJson = grunt . file . readJSON ( CONFIG_DATA . filePath ) ;
218
208
219
- if ( configJson [ CONFIG_DATA . gaKey ] !== GA_TRACKING_IDS [ ENVIRONMENTS . live ] ) {
209
+ if ( configJson [ CONFIG_DATA . gaKey ] !== GA_TRACKING_IDS [ ENVIRONMENTS . live ] ) {
220
210
throw new Error ( "Google Analytics id is not configured correctly." ) ;
221
211
}
222
212
} ) ;
@@ -234,6 +224,16 @@ module.exports = function (grunt) {
234
224
"set_package_version" ,
235
225
"shell:build_package"
236
226
] ) ;
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
+ } ) ;
237
237
grunt . registerTask ( "lint" , [ "tslint:build" ] ) ;
238
238
grunt . registerTask ( "all" , [ "clean" , "test" , "lint" ] ) ;
239
239
grunt . registerTask ( "rebuild" , [ "clean" , "ts:devlib" ] ) ;
0 commit comments