1
- import path from " path"
2
- import yargs from " yargs/yargs"
3
- import { Argv } from " yargs"
4
- import { Compiler , DartCompiler , ExecutableCompiler } from " ./compiler"
1
+ import path from ' path' ;
2
+ import yargs from ' yargs/yargs' ;
3
+ import { Argv } from ' yargs' ;
4
+ import { Compiler , DartCompiler , ExecutableCompiler } from ' ./compiler' ;
5
5
6
6
export interface CliArgs {
7
- root : string
8
- verbose : boolean
9
- impl : string
10
- compiler : Compiler
11
- interactive : boolean
12
- testDirs : string [ ]
13
- todoMode ?: string
7
+ root : string ;
8
+ verbose : boolean ;
9
+ impl : string ;
10
+ compiler : Compiler ;
11
+ interactive : boolean ;
12
+ testDirs : string [ ] ;
13
+ todoMode ?: string ;
14
14
}
15
15
16
16
const implArgs : Record < string , string [ ] > = {
17
- " dart-sass" : [ " --verbose" , " --no-unicode" , " --no-color" ] ,
18
- libsass : [ " --style" , " expanded" ] ,
19
- }
17
+ ' dart-sass' : [ ' --verbose' , ' --no-unicode' , ' --no-color' ] ,
18
+ libsass : [ ' --style' , ' expanded' ] ,
19
+ } ;
20
20
21
21
const usageText = `
22
22
Usage: ts-node ./sass-spec.ts [options] [spec_directory...]
@@ -26,7 +26,7 @@ that are named input.scss. It will then run a specified binary and check that
26
26
the output matches the expected output.
27
27
28
28
Make sure the command you provide prints to stdout.
29
- ` . trim ( )
29
+ ` . trim ( ) ;
30
30
31
31
/**
32
32
* Parse command line args into options used by the sass-spec runner.
@@ -39,93 +39,96 @@ export async function parseArgs(
39
39
wrap = ( t : Argv < { } > ) => t
40
40
) : Promise < CliArgs > {
41
41
const argv = wrap ( yargs ( cliArgs ) )
42
+ . parserConfiguration ( {
43
+ 'parse-numbers' : false ,
44
+ } )
42
45
. usage ( usageText )
43
46
. example (
44
- " npm run ./sass-spec.js -- spec/basic" ,
45
- " Run tests only in the spec/basic folder"
47
+ ' npm run ./sass-spec.js -- spec/basic' ,
48
+ ' Run tests only in the spec/basic folder'
46
49
)
47
- . option ( " verbose" , {
48
- alias : "v" ,
49
- description : " Run verbosely" ,
50
- type : " boolean" ,
50
+ . option ( ' verbose' , {
51
+ alias : 'v' ,
52
+ description : ' Run verbosely' ,
53
+ type : ' boolean' ,
51
54
} )
52
- . option ( " dart" , {
53
- description : " Run Dart Sass, whose repo should be at the given path" ,
54
- type : " string" ,
55
+ . option ( ' dart' , {
56
+ description : ' Run Dart Sass, whose repo should be at the given path' ,
57
+ type : ' string' ,
55
58
} )
56
- . option ( " command" , {
57
- alias : "c" ,
58
- description : " Sets a specific binary to run" ,
59
- type : " string" ,
59
+ . option ( ' command' , {
60
+ alias : 'c' ,
61
+ description : ' Sets a specific binary to run' ,
62
+ type : ' string' ,
60
63
} )
61
- . conflicts ( " dart" , " command" )
62
- . check ( ( { dart, command } ) => {
64
+ . conflicts ( ' dart' , ' command' )
65
+ . check ( ( { dart, command} ) => {
63
66
if ( ! dart && ! command ) {
64
- throw new Error ( " Must specify --dart or --command" )
67
+ throw new Error ( ' Must specify --dart or --command' ) ;
65
68
} else {
66
- return true
69
+ return true ;
67
70
}
68
71
} )
69
- . option ( " cmd-args" , {
70
- description : " Pass args to command or Dart Sass" ,
71
- type : " string" ,
72
+ . option ( ' cmd-args' , {
73
+ description : ' Pass args to command or Dart Sass' ,
74
+ type : ' string' ,
72
75
} )
73
- . option ( " impl" , {
74
- description : " Sets the name of the implementation being tested." ,
75
- type : " string" ,
76
+ . option ( ' impl' , {
77
+ description : ' Sets the name of the implementation being tested.' ,
78
+ type : ' string' ,
76
79
} )
77
- . options ( " run-todo" , {
78
- description : " Run any tests marked as todo" ,
79
- type : " boolean" ,
80
+ . options ( ' run-todo' , {
81
+ description : ' Run any tests marked as todo' ,
82
+ type : ' boolean' ,
80
83
} )
81
- . options ( " probe-todo" , {
82
- description : " Run and report tests marked as todo that unexpectedly pass" ,
83
- type : " boolean" ,
84
+ . options ( ' probe-todo' , {
85
+ description : ' Run and report tests marked as todo that unexpectedly pass' ,
86
+ type : ' boolean' ,
84
87
} )
85
- . conflicts ( " run-todo" , " probe-todo" )
86
- . option ( " root-path" , {
88
+ . conflicts ( ' run-todo' , ' probe-todo' )
89
+ . option ( ' root-path' , {
87
90
description :
88
- " The root path to start searching for tests and test configuration, and the path to pass into --load-path" ,
89
- type : " string" ,
90
- default : " spec" ,
91
+ ' The root path to start searching for tests and test configuration, and the path to pass into --load-path' ,
92
+ type : ' string' ,
93
+ default : ' spec' ,
91
94
} )
92
- . options ( " interactive" , {
95
+ . options ( ' interactive' , {
93
96
description :
94
- " When a test fails, enter into a dialog for how to handle it" ,
95
- type : " boolean" ,
97
+ ' When a test fails, enter into a dialog for how to handle it' ,
98
+ type : ' boolean' ,
96
99
default : false ,
97
- } ) . argv
100
+ } ) . argv ;
98
101
99
- const root = path . resolve ( process . cwd ( ) , argv [ " root-path" ] )
102
+ const root = path . resolve ( process . cwd ( ) , argv [ ' root-path' ] ) ;
100
103
101
104
const args : Partial < CliArgs > = {
102
105
root,
103
106
verbose : argv . verbose ,
104
107
interactive : argv . interactive ,
105
- testDirs : argv . _ ,
106
- todoMode : argv [ " run-todo" ]
107
- ? " run"
108
- : argv [ " probe-todo" ]
109
- ? " probe"
108
+ testDirs : argv . _ as string [ ] ,
109
+ todoMode : argv [ ' run-todo' ]
110
+ ? ' run'
111
+ : argv [ ' probe-todo' ]
112
+ ? ' probe'
110
113
: undefined ,
111
- }
112
- args . impl = argv . dart ? " dart-sass" : argv . impl !
113
- let cmdArgs = implArgs [ args . impl ] ?? [ ]
114
- cmdArgs . push ( `--load-path=${ root } ` )
115
- if ( argv [ " cmd-args" ] ) {
116
- cmdArgs = cmdArgs . concat ( argv [ " cmd-args" ] . split ( " " ) )
114
+ } ;
115
+ args . impl = argv . dart ? ' dart-sass' : argv . impl ! ;
116
+ let cmdArgs = implArgs [ args . impl ] ?? [ ] ;
117
+ cmdArgs . push ( `--load-path=${ root } ` ) ;
118
+ if ( argv [ ' cmd-args' ] ) {
119
+ cmdArgs = cmdArgs . concat ( argv [ ' cmd-args' ] . split ( ' ' ) ) ;
117
120
}
118
121
119
122
if ( argv . command ) {
120
123
args . compiler = new ExecutableCompiler (
121
124
path . resolve ( process . cwd ( ) , argv . command ) ,
122
125
cmdArgs
123
- )
126
+ ) ;
124
127
}
125
128
if ( argv . dart ) {
126
- const repoPath = path . resolve ( process . cwd ( ) , argv . dart )
127
- args . compiler = await DartCompiler . fromRepo ( repoPath , cmdArgs )
129
+ const repoPath = path . resolve ( process . cwd ( ) , argv . dart ) ;
130
+ args . compiler = await DartCompiler . fromRepo ( repoPath , cmdArgs ) ;
128
131
}
129
132
130
- return args as CliArgs
133
+ return args as CliArgs ;
131
134
}
0 commit comments