1
1
#!/usr/bin/env node
2
+ import chalk from 'chalk' ;
2
3
import * as commandLineArgs from 'command-line-args' ;
3
4
5
+ /**
6
+ * Supported output style. Mirrors `style_option_strings[]` in sassc
7
+ * (https://github.com/sass/sassc/blob/6a64d0569205bfcf0794a473f97affcb60b22fcc/sassc.c#L184-L189)
8
+ */
4
9
enum StyleOption {
5
10
SASS_STYLE_COMPRESSED = 'compressed' ,
6
11
SASS_STYLE_COMPACT = 'compact' ,
7
12
SASS_STYLE_EXPANDED = 'expanded' ,
8
13
SASS_STYLE_NESTED = 'nested'
9
14
}
10
15
16
+ /**
17
+ * Definitions of available command line args.
18
+ */
11
19
const optionDefinitions = [
12
20
{ name : 'stdin' , alias : 's' , description : 'Read input from standard input instead of an input file.' } ,
13
21
{
@@ -22,18 +30,43 @@ const optionDefinitions = [
22
30
{ name : 'omit-map-comment' , alias : 'M' , description : 'Omits the source map url comment.' } ,
23
31
{ name : 'precision' , alias : 'p' , description : 'Set the precision for numbers.' } ,
24
32
{ name : 'sass' , alias : 'a' , description : 'Treat input as indented syntax.' } ,
25
- { name : 'version' , alias : 'v' , description : 'Display compiled versions.' } ,
33
+ { name : 'version' , alias : 'v' , description : 'Display compiled versions.' , type : Boolean } ,
26
34
{ name : 'help' , alias : 'h' , description : 'Display this help message.' , type : Boolean }
27
35
] ;
28
36
37
+ /**
38
+ * Get usage definition for library version.
39
+ *
40
+ */
41
+ const buildDisplayVersion = async ( ) => {
42
+ const { loadModule } = await import ( './loadModule' ) ;
43
+ const sassFactory = await loadModule ( ) ;
44
+ const { libsassAsm, libsass, sassLang, sass2scss } = await sassFactory . getVersion ( ) ;
45
+
46
+ return {
47
+ header : chalk . reset ( 'Version' ) ,
48
+ content : [
49
+ { name : 'libsass-asm' , summary : libsassAsm } ,
50
+ { name : 'libsass' , summary : libsass } ,
51
+ { name : 'sass' , summary : sassLang } ,
52
+ { name : 'sass2scss' , summary : sass2scss }
53
+ ]
54
+ } ;
55
+ } ;
56
+
29
57
( async ( ) => {
30
58
const options = commandLineArgs ( optionDefinitions , { camelCase : true } ) ;
31
59
32
- if ( options . help || Object . keys ( options ) . length === 0 ) {
33
- const commandLineUsage = await import ( 'command-line-usage' ) ;
34
- const usage = commandLineUsage ( [ { header : 'Options' , optionList : optionDefinitions } ] ) ;
60
+ const displayHelp = options . help || Object . keys ( options ) . length === 0 ;
61
+ const displayVersion = options . version ;
62
+
63
+ if ( displayHelp || displayVersion ) {
64
+ const cmdUsage = await import ( 'command-line-usage' ) ;
65
+ const usageDefinition = displayHelp
66
+ ? { header : chalk . reset ( 'Options' ) , optionList : optionDefinitions }
67
+ : await buildDisplayVersion ( ) ;
68
+ const usage = cmdUsage ( [ usageDefinition ] ) ;
35
69
console . log ( usage ) ;
36
- } else if ( options . version ) {
37
70
return ;
38
71
}
39
72
} ) ( ) ;
0 commit comments