1
- import { Command } from " @oclif/core" ;
2
- import path from " path" ;
3
- import { PromptsIO } from " boilersmith/io" ;
4
- import { exit } from " @oclif/errors" ;
5
- import { execSync , exec } from " child_process" ;
6
- import util from " util" ;
7
- import chalk from " chalk" ;
1
+ import { Command } from ' @oclif/core' ;
2
+ import path from ' path' ;
3
+ import { PromptsIO } from ' boilersmith/io' ;
4
+ import { exit } from ' @oclif/errors' ;
5
+ import { execSync , exec } from ' child_process' ;
6
+ import util from ' util' ;
7
+ import chalk from ' chalk' ;
8
8
9
9
const execAsync = util . promisify ( exec ) ;
10
10
@@ -14,7 +14,7 @@ export default class Info extends Command {
14
14
/**
15
15
* Should only need to keep two registered at all times.
16
16
*/
17
- static map : { cli :string | number , flarum :string | number } [ ] = [
17
+ static map : { cli : string | number ; flarum : string | number } [ ] = [
18
18
{ cli : 3 , flarum : 2 } ,
19
19
{ cli : 2 , flarum : 1 } ,
20
20
] ;
@@ -26,9 +26,9 @@ export default class Info extends Command {
26
26
const currentFlarumVersion = Number ( json . flarum . split ( '.' ) [ 0 ] ) ;
27
27
const currentCliVersion = Number ( json . version . split ( '.' ) [ 0 ] ) ;
28
28
29
- const other = Info . map . find ( i => i . cli !== currentCliVersion ) ;
29
+ const other = Info . map . find ( ( i ) => i . cli !== currentCliVersion ) ;
30
30
31
- if ( ! other ) {
31
+ if ( ! other ) {
32
32
this . error ( 'No other versions to switch to.' ) ;
33
33
}
34
34
@@ -53,7 +53,7 @@ export default class Info extends Command {
53
53
initial : true ,
54
54
} ) ;
55
55
56
- if ( ! yes ) {
56
+ if ( ! yes ) {
57
57
return ;
58
58
}
59
59
@@ -63,30 +63,30 @@ export default class Info extends Command {
63
63
const otherBin = `fl${ otherFlarumVersion } ` ;
64
64
let otherBinPath = this . binPath ( otherBin ) ;
65
65
66
- if ( ! otherBinPath ) {
66
+ if ( ! otherBinPath ) {
67
67
this . install ( otherCliVersion , otherFlarumVersion ) ;
68
68
otherBinPath = this . binPath ( otherBin ) ;
69
69
70
- if ( ! otherBinPath ) {
70
+ if ( ! otherBinPath ) {
71
71
this . error ( 'Could not install the other version.' ) ;
72
72
}
73
73
}
74
74
75
75
const defaultBinPath = otherBinPath . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) + '/fl' ;
76
76
77
77
if ( ! this . isWindows ( ) ) {
78
- const which = execSync ( 'which ' + otherBin , { encoding : 'utf8' } ) . trim ( ) ;
78
+ const which = execSync ( 'which ' + otherBin , { encoding : 'utf8' } ) . trim ( ) ;
79
79
// replace the default fl bin with the now installed fl2 or fl1 bin
80
80
// the path to the fl bin is the same as the path to the fl2 or fl1 bin, just without the 2 or 1
81
81
this . execRetryingAsSudo ( `ln -sf ${ which } ${ defaultBinPath } ` ) ;
82
82
} else {
83
- const where = execSync ( 'where ' + otherBin , { encoding : 'utf8' } ) . trim ( ) ;
83
+ const where = execSync ( 'where ' + otherBin , { encoding : 'utf8' } ) . trim ( ) ;
84
84
execSync ( `mklink /H C:\\Windows\\System32\\fl.exe ${ where } ` , { stdio : 'inherit' } ) ;
85
85
}
86
86
}
87
87
88
- install ( cli : number | string , flarum : number | string , sudo = false ) {
89
- execAsync ( ( sudo ? 'sudo ' : '' ) + `npm install -g fl${ flarum } @npm:@flarum/cli@${ cli } --force` ) . then ( ( { stdout, stderr } ) => {
88
+ install ( cli : number | string , flarum : number | string , sudo = false ) {
89
+ execAsync ( ( sudo ? 'sudo ' : '' ) + `npm install -g fl${ flarum } @npm:@flarum/cli@${ cli } --force` ) . then ( ( { stdout } ) => {
90
90
if ( stdout && stdout . toString ( ) . includes ( 'Permission denied' ) && ! sudo && ! this . isWindows ( ) ) {
91
91
this . log ( chalk . red ( 'Permission denied. Running with sudo.' ) ) ;
92
92
this . install ( cli , flarum , true ) ;
@@ -98,21 +98,19 @@ export default class Info extends Command {
98
98
return process . platform === 'win32' ;
99
99
}
100
100
101
- binPath ( bin : string ) : null | string {
102
- const result = this . isWindows ( )
103
- ? execSync ( 'where ' + bin , { encoding : 'utf8' } ) . trim ( )
104
- : execSync ( 'which ' + bin , { encoding : 'utf8' } ) . trim ( ) ;
101
+ binPath ( bin : string ) : null | string {
102
+ const result = this . isWindows ( ) ? execSync ( 'where ' + bin , { encoding : 'utf8' } ) . trim ( ) : execSync ( 'which ' + bin , { encoding : 'utf8' } ) . trim ( ) ;
105
103
106
104
this . log ( result ) ;
107
105
108
106
return result || null ;
109
107
}
110
108
111
109
protected execRetryingAsSudo ( command : string ) : void {
112
- execAsync ( command ) . catch ( ( { stderr} ) => {
110
+ execAsync ( command ) . catch ( ( { stderr } ) => {
113
111
if ( stderr && stderr . toString ( ) . includes ( 'Permission denied' ) ) {
114
112
this . log ( chalk . red ( 'Permission denied. Running with sudo.' ) ) ;
115
- execSync ( 'sudo ' + command , { stdio : 'inherit' } ) ;
113
+ execSync ( 'sudo ' + command , { stdio : 'inherit' } ) ;
116
114
}
117
115
} ) ;
118
116
}
0 commit comments