1
- /// <reference path="../src/compiler/sys.ts" />
1
+ /// <reference types="node"/>
2
+ import { normalize } from "path" ;
3
+ import assert = require( "assert" ) ;
4
+ import { readFileSync , writeFileSync } from "fs" ;
5
+ const args = process . argv . slice ( 2 ) ;
6
+
2
7
3
8
/**
4
9
* A minimal description for a parsed package.json object.
@@ -10,28 +15,27 @@ interface PackageJson {
10
15
}
11
16
12
17
function main ( ) : void {
13
- const sys = ts . sys ;
14
- if ( sys . args . length < 3 ) {
15
- sys . write ( "Usage:" + sys . newLine )
16
- sys . write ( "\tnode configureNightly.js <dev|insiders> <package.json location> <file containing version>" + sys . newLine ) ;
18
+ if ( args . length < 3 ) {
19
+ console . log ( "Usage:" ) ;
20
+ console . log ( "\tnode configureNightly.js <dev|insiders> <package.json location> <file containing version>" ) ;
17
21
return ;
18
22
}
19
23
20
- const tag = sys . args [ 0 ] ;
24
+ const tag = args [ 0 ] ;
21
25
if ( tag !== "dev" && tag !== "insiders" ) {
22
26
throw new Error ( `Unexpected tag name '${ tag } '.` ) ;
23
27
}
24
28
25
29
// Acquire the version from the package.json file and modify it appropriately.
26
- const packageJsonFilePath = ts . normalizePath ( sys . args [ 1 ] ) ;
27
- const packageJsonValue : PackageJson = JSON . parse ( sys . readFile ( packageJsonFilePath ) ) ;
30
+ const packageJsonFilePath = normalize ( args [ 1 ] ) ;
31
+ const packageJsonValue : PackageJson = JSON . parse ( readFileSync ( packageJsonFilePath ) . toString ( ) ) ;
28
32
29
33
const { majorMinor, patch } = parsePackageJsonVersion ( packageJsonValue . version ) ;
30
34
const prereleasePatch = getPrereleasePatch ( tag , patch ) ;
31
35
32
36
// Acquire and modify the source file that exposes the version string.
33
- const tsFilePath = ts . normalizePath ( sys . args [ 2 ] ) ;
34
- const tsFileContents = ts . sys . readFile ( tsFilePath ) ;
37
+ const tsFilePath = normalize ( args [ 2 ] ) ;
38
+ const tsFileContents = readFileSync ( tsFilePath ) . toString ( ) ;
35
39
const modifiedTsFileContents = updateTsFile ( tsFilePath , tsFileContents , majorMinor , patch , prereleasePatch ) ;
36
40
37
41
// Ensure we are actually changing something - the user probably wants to know that the update failed.
@@ -44,20 +48,20 @@ function main(): void {
44
48
// Finally write the changes to disk.
45
49
// Modify the package.json structure
46
50
packageJsonValue . version = `${ majorMinor } .${ prereleasePatch } ` ;
47
- sys . writeFile ( packageJsonFilePath , JSON . stringify ( packageJsonValue , /*replacer:*/ undefined , /*space:*/ 4 ) )
48
- sys . writeFile ( tsFilePath , modifiedTsFileContents ) ;
51
+ writeFileSync ( packageJsonFilePath , JSON . stringify ( packageJsonValue , /*replacer:*/ undefined , /*space:*/ 4 ) )
52
+ writeFileSync ( tsFilePath , modifiedTsFileContents ) ;
49
53
}
50
54
51
55
function updateTsFile ( tsFilePath : string , tsFileContents : string , majorMinor : string , patch : string , nightlyPatch : string ) : string {
52
56
const majorMinorRgx = / e x p o r t c o n s t v e r s i o n M a j o r M i n o r = " ( \d + \. \d + ) " / ;
53
57
const majorMinorMatch = majorMinorRgx . exec ( tsFileContents ) ;
54
- ts . Debug . assert ( majorMinorMatch !== null , "" , ( ) => `The file seems to no longer have a string matching '${ majorMinorRgx } '.` ) ;
58
+ assert ( majorMinorMatch !== null , `The file seems to no longer have a string matching '${ majorMinorRgx } '.` ) ;
55
59
const parsedMajorMinor = majorMinorMatch [ 1 ] ;
56
- ts . Debug . assert ( parsedMajorMinor === majorMinor , " versionMajorMinor does not match." , ( ) => ` ${ tsFilePath } : '${ parsedMajorMinor } '; package.json: '${ majorMinor } '`) ;
60
+ assert ( parsedMajorMinor === majorMinor , ` versionMajorMinor does not match. ${ tsFilePath } : '${ parsedMajorMinor } '; package.json: '${ majorMinor } '`) ;
57
61
58
62
const versionRgx = / e x p o r t c o n s t v e r s i o n = ` \$ \{ v e r s i o n M a j o r M i n o r \} \. ( \d ) ( - d e v ) ? ` ; / ;
59
63
const patchMatch = versionRgx . exec ( tsFileContents ) ;
60
- ts . Debug . assert ( patchMatch !== null , "The file seems to no longer have a string matching" , ( ) => versionRgx . toString ( ) ) ;
64
+ assert ( patchMatch !== null , "The file seems to no longer have a string matching " + versionRgx . toString ( ) ) ;
61
65
const parsedPatch = patchMatch [ 1 ] ;
62
66
if ( parsedPatch !== patch ) {
63
67
throw new Error ( `patch does not match. ${ tsFilePath } : '${ parsedPatch } ; package.json: '${ patch } '` ) ;
@@ -69,7 +73,7 @@ function updateTsFile(tsFilePath: string, tsFileContents: string, majorMinor: st
69
73
function parsePackageJsonVersion ( versionString : string ) : { majorMinor : string , patch : string } {
70
74
const versionRgx = / ( \d + \. \d + ) \. ( \d + ) ( $ | \- ) / ;
71
75
const match = versionString . match ( versionRgx ) ;
72
- ts . Debug . assert ( match !== null , "package.json 'version' should match" , ( ) => versionRgx . toString ( ) ) ;
76
+ assert ( match !== null , "package.json 'version' should match " + versionRgx . toString ( ) ) ;
73
77
return { majorMinor : match [ 1 ] , patch : match [ 2 ] } ;
74
78
}
75
79
0 commit comments