@@ -18,8 +18,6 @@ if (projectDir) {
1818 if ( ! hasModules30 ) {
1919 createReferenceFile ( ) ;
2020 }
21-
22- installTypescript ( ) ;
2321}
2422
2523function createReferenceFile ( ) {
@@ -48,59 +46,3 @@ function createTsconfig(tsconfigPath) {
4846
4947 fs . writeFileSync ( tsconfigPath , JSON . stringify ( tsconfig , null , 4 ) ) ;
5048}
51-
52- function getProjectTypeScriptVersion ( ) {
53- try {
54- var packageJsonPath = path . join ( projectDir , "package.json" ) ,
55- packageJsonContent = fs . readFileSync ( packageJsonPath , "utf8" ) ,
56- jsonContent = JSON . parse ( packageJsonContent ) ;
57-
58- return ( jsonContent . dependencies && jsonContent . dependencies . typescript ) ||
59- ( jsonContent . devDependencies && jsonContent . devDependencies . typescript ) ;
60- } catch ( err ) {
61- console . error ( err ) ;
62- return null ;
63- }
64- }
65-
66- function installTypescript ( ) {
67- const installedTypeScriptVersion = getProjectTypeScriptVersion ( ) ;
68- const force = shouldInstallLatest ( installedTypeScriptVersion ) ;
69-
70- if ( installedTypeScriptVersion && ! force ) {
71- console . log ( `Project already targets TypeScript ${ installedTypeScriptVersion } ` ) ;
72- } else {
73- const command = "npm install -D typescript@latest" ;
74-
75- console . log ( "Installing TypeScript..." ) ;
76-
77- require ( "child_process" ) . exec ( command , { cwd : projectDir } , ( err , stdout , stderr ) => {
78- if ( err ) {
79- console . warn ( `npm: ${ err . toString ( ) } ` ) ;
80- }
81-
82- process . stdout . write ( stdout ) ;
83- process . stderr . write ( stderr ) ;
84- } ) ;
85- }
86- }
87-
88- function shouldInstallLatest ( tsVersion ) {
89- if ( ! tsVersion ) {
90- return true ;
91- }
92-
93- const justVersion = clearPatch ( tsVersion ) ;
94- const majorVer = justVersion [ 0 ] ;
95- const minorVer = justVersion [ 2 ] ;
96-
97- return tsVersion === "2.2.0" ||
98- majorVer < 2 || // ex. 1.8.10
99- ( majorVer === "2" && minorVer < 2 ) ; // ex. 2.1.6
100- }
101-
102- function clearPatch ( version ) {
103- return version && ( version . startsWith ( "~" ) || version . startsWith ( "^" ) ) ?
104- version . substring ( 1 ) :
105- version ;
106- }
0 commit comments