1
1
import { version as swcCoreVersion } from "@swc/core" ;
2
2
import { BundleOptions , compileBundleOptions } from "@swc/core/spack" ;
3
3
import commander from "commander" ;
4
- import * as path from ' path' ;
4
+ import * as path from " path" ;
5
5
6
6
const pkg = require ( "../../package.json" ) ;
7
7
8
8
export interface SpackCliOptions {
9
- debug : boolean
9
+ debug : boolean ;
10
10
}
11
11
12
12
commander . option ( "--config [path]" , "Path to a spack.config.js file to use." ) ;
@@ -16,17 +16,17 @@ commander.option("--mode <development | production | none>", "Mode to use");
16
16
commander . option ( "--target [browser | node]" , "Target runtime environment" ) ;
17
17
18
18
commander . option (
19
- '--context [path]' , `The base directory (absolute path!) for resolving the 'entry'`
20
- + ` option. If 'output.pathinfo' is set, the included pathinfo is shortened to this directory` ,
21
- 'The current directory'
19
+ "--context [path]" ,
20
+ `The base directory (absolute path!) for resolving the 'entry'` +
21
+ ` option. If 'output.pathinfo' is set, the included pathinfo is shortened to this directory` ,
22
+ "The current directory"
22
23
) ;
23
24
24
- commander . option ( ' --entry [list]' , "List of entries" , collect ) ;
25
+ commander . option ( " --entry [list]" , "List of entries" , collect ) ;
25
26
26
27
// commander.option('-W --watch', `Enter watch mode, which rebuilds on file change.`)
27
28
28
-
29
- commander . option ( '--debug' , `Switch loaders to debug mode` )
29
+ commander . option ( "--debug" , `Switch loaders to debug mode` ) ;
30
30
// commander.option('--devtool', `Select a developer tool to enhance debugging.`)
31
31
32
32
// -d shortcut for --debug --devtool eval-cheap-module-source-map
@@ -40,8 +40,11 @@ commander.option('--debug', `Switch loaders to debug mode`)
40
40
// --module-bind-pre Bind an extension to a pre loader [문자열]
41
41
42
42
// Output options:
43
- commander . option ( '-o --output' , `The output path and file for compilation assets` ) ;
44
- commander . option ( '--output-path' , `The output directory as **absolute path**` ) ;
43
+ commander . option (
44
+ "-o --output" ,
45
+ `The output path and file for compilation assets`
46
+ ) ;
47
+ commander . option ( "--output-path" , `The output directory as **absolute path**` ) ;
45
48
// --output-filename Specifies the name of each output file on disk.
46
49
// You must **not** specify an absolute path here!
47
50
// The `output.path` option determines the location
@@ -156,60 +159,61 @@ commander.option('--output-path', `The output directory as **absolute path**`);
156
159
// --json, -j Prints the result as JSON. [boolean]
157
160
158
161
commander . version (
159
- `@swc/cli: ${ pkg . version }
162
+ `@swc/cli: ${ pkg . version }
160
163
@swc/core: ${ swcCoreVersion } `
161
164
) ;
162
165
163
166
export default async function parseSpackArgs ( args : string [ ] ) : Promise < {
164
- cliOptions : SpackCliOptions ,
165
- spackOptions : BundleOptions ,
167
+ cliOptions : SpackCliOptions ;
168
+ spackOptions : BundleOptions ;
166
169
} > {
167
- //
168
- const cmd = commander . parse ( args ) ;
169
- const opts = cmd . opts ( ) ;
170
-
171
- const cliOptions : SpackCliOptions = {
172
- // watch: !!opts.watch,
173
- debug : ! ! opts . debug ,
174
- } ;
175
-
176
- const configOpts : BundleOptions = await compileBundleOptions ( opts . config ?? path . resolve ( 'spack.config.js' ) ) as any ;
177
- if ( opts . entry ) {
178
- configOpts . entry = opts . entry ;
179
- }
180
- if ( opts . mode ) {
181
- configOpts . mode = opts . mode ;
182
- }
183
- if ( opts . target ) {
184
- configOpts . target = opts . target ;
185
- }
186
- if ( ! configOpts . output ) {
187
- configOpts . output = { } as any ;
188
- }
189
- if ( ! configOpts . output . path ) {
190
- configOpts . output . path = opts . outputPath ?? '[name].js' ;
191
- }
192
- if ( ! configOpts . output . name ) {
193
- configOpts . output . name = opts . output ?? '[name].js' ;
194
- }
195
- // if (!configOpts.output.name) {
196
- // configOpts.output.path = opts.outputPath;
197
- // }
198
-
199
- return {
200
- cliOptions,
201
- spackOptions : {
202
- ...configOpts ,
203
- } ,
204
- }
170
+ //
171
+ const cmd = commander . parse ( args ) ;
172
+ const opts = cmd . opts ( ) ;
173
+
174
+ const cliOptions : SpackCliOptions = {
175
+ // watch: !!opts.watch,
176
+ debug : ! ! opts . debug ,
177
+ } ;
178
+
179
+ const configOpts : BundleOptions = ( await compileBundleOptions (
180
+ opts . config ?? path . resolve ( "spack.config.js" )
181
+ ) ) as any ;
182
+ if ( opts . entry ) {
183
+ configOpts . entry = opts . entry ;
184
+ }
185
+ if ( opts . mode ) {
186
+ configOpts . mode = opts . mode ;
187
+ }
188
+ if ( opts . target ) {
189
+ configOpts . target = opts . target ;
190
+ }
191
+ if ( ! configOpts . output ) {
192
+ configOpts . output = { } as any ;
193
+ }
194
+ if ( ! configOpts . output . path ) {
195
+ configOpts . output . path = opts . outputPath ?? "[name].js" ;
196
+ }
197
+ if ( ! configOpts . output . name ) {
198
+ configOpts . output . name = opts . output ?? "[name].js" ;
199
+ }
200
+ // if (!configOpts.output.name) {
201
+ // configOpts.output.path = opts.outputPath;
202
+ // }
203
+
204
+ return {
205
+ cliOptions,
206
+ spackOptions : {
207
+ ...configOpts ,
208
+ } ,
209
+ } ;
205
210
}
206
211
207
-
208
212
function collect ( value : any , previousValue : any ) : Array < string > {
209
- // If the user passed the option with no value, like "babel file.js --presets", do nothing.
210
- if ( typeof value !== "string" ) return previousValue ;
213
+ // If the user passed the option with no value, like "babel file.js --presets", do nothing.
214
+ if ( typeof value !== "string" ) return previousValue ;
211
215
212
- const values = value . split ( "," ) ;
216
+ const values = value . split ( "," ) ;
213
217
214
- return previousValue ? previousValue . concat ( values ) : values ;
218
+ return previousValue ? previousValue . concat ( values ) : values ;
215
219
}
0 commit comments