@@ -11,34 +11,39 @@ interface PackageJson {
11
11
12
12
function main ( ) : void {
13
13
const sys = ts . sys ;
14
- if ( sys . args . length < 2 ) {
14
+ if ( sys . args . length < 3 ) {
15
15
sys . write ( "Usage:" + sys . newLine )
16
- sys . write ( "\tnode configureNightly.js <package.json location> <file containing version>" + sys . newLine ) ;
16
+ sys . write ( "\tnode configureNightly.js <dev|insiders> < package.json location> <file containing version>" + sys . newLine ) ;
17
17
return ;
18
18
}
19
19
20
+ const tag = sys . args [ 0 ] ;
21
+ if ( tag !== "dev" && tag !== "insiders" ) {
22
+ throw new Error ( `Unexpected tag name '${ tag } '.` ) ;
23
+ }
24
+
20
25
// Acquire the version from the package.json file and modify it appropriately.
21
- const packageJsonFilePath = ts . normalizePath ( sys . args [ 0 ] ) ;
26
+ const packageJsonFilePath = ts . normalizePath ( sys . args [ 1 ] ) ;
22
27
const packageJsonValue : PackageJson = JSON . parse ( sys . readFile ( packageJsonFilePath ) ) ;
23
28
24
29
const { majorMinor, patch } = parsePackageJsonVersion ( packageJsonValue . version ) ;
25
- const nightlyPatch = getNightlyPatch ( patch ) ;
30
+ const prereleasePatch = getPrereleasePatch ( tag , patch ) ;
26
31
27
32
// Acquire and modify the source file that exposes the version string.
28
- const tsFilePath = ts . normalizePath ( sys . args [ 1 ] ) ;
33
+ const tsFilePath = ts . normalizePath ( sys . args [ 2 ] ) ;
29
34
const tsFileContents = ts . sys . readFile ( tsFilePath ) ;
30
- const modifiedTsFileContents = updateTsFile ( tsFilePath , tsFileContents , majorMinor , patch , nightlyPatch ) ;
35
+ const modifiedTsFileContents = updateTsFile ( tsFilePath , tsFileContents , majorMinor , patch , prereleasePatch ) ;
31
36
32
37
// Ensure we are actually changing something - the user probably wants to know that the update failed.
33
38
if ( tsFileContents === modifiedTsFileContents ) {
34
- let err = `\n '${ tsFilePath } ' was not updated while configuring for a nightly publish.\n ` ;
39
+ let err = `\n '${ tsFilePath } ' was not updated while configuring for a prerelease publish for ' ${ tag } ' .\n ` ;
35
40
err += `Ensure that you have not already run this script; otherwise, erase your changes using 'git checkout -- "${ tsFilePath } "'.` ;
36
- throw err + "\n" ;
41
+ throw new Error ( err + "\n" ) ;
37
42
}
38
43
39
44
// Finally write the changes to disk.
40
45
// Modify the package.json structure
41
- packageJsonValue . version = `${ majorMinor } .${ nightlyPatch } ` ;
46
+ packageJsonValue . version = `${ majorMinor } .${ prereleasePatch } ` ;
42
47
sys . writeFile ( packageJsonFilePath , JSON . stringify ( packageJsonValue , /*replacer:*/ undefined , /*space:*/ 4 ) )
43
48
sys . writeFile ( tsFilePath , modifiedTsFileContents ) ;
44
49
}
@@ -69,15 +74,15 @@ function parsePackageJsonVersion(versionString: string): { majorMinor: string, p
69
74
}
70
75
71
76
/** e.g. 0-dev.20170707 */
72
- function getNightlyPatch ( plainPatch : string ) : string {
77
+ function getPrereleasePatch ( tag : string , plainPatch : string ) : string {
73
78
// We're going to append a representation of the current time at the end of the current version.
74
79
// String.prototype.toISOString() returns a 24-character string formatted as 'YYYY-MM-DDTHH:mm:ss.sssZ',
75
80
// but we'd prefer to just remove separators and limit ourselves to YYYYMMDD.
76
81
// UTC time will always be implicit here.
77
82
const now = new Date ( ) ;
78
83
const timeStr = now . toISOString ( ) . replace ( / : | T | \. | - / g, "" ) . slice ( 0 , 8 ) ;
79
84
80
- return `${ plainPatch } -dev .${ timeStr } ` ;
85
+ return `${ plainPatch } -${ tag } .${ timeStr } ` ;
81
86
}
82
87
83
88
main ( ) ;
0 commit comments