1- import { fromJS } from "immutable" ;
1+ import { fromJS , List } from "immutable" ;
22import { BsTempOptions , makeFilesArg , TransformResult } from "../cli-options" ;
3- import { FilesNamespaces } from "../../types" ;
3+ import { FilesNamespace , FilesNamespaces , runnerOption } from "../../types" ;
4+ import { z } from "zod" ;
45
56export function handleFilesOption ( incoming : BsTempOptions ) : TransformResult {
6- const value = incoming . get ( "files" ) ;
77 const namespaces : FilesNamespaces = {
88 core : {
99 globs : [ ] ,
1010 objs : [ ]
1111 }
1212 } ;
1313
14- const processed = makeFilesArg ( value ) ;
14+ const processed = makeFilesArg ( incoming . get ( "files" ) ) ;
1515
1616 if ( processed . globs . length ) {
1717 namespaces . core . globs = processed . globs ;
@@ -21,5 +21,36 @@ export function handleFilesOption(incoming: BsTempOptions): TransformResult {
2121 namespaces . core . objs = processed . objs ;
2222 }
2323
24- return [ incoming . set ( "files" , fromJS ( namespaces ) ) , [ ] ] ;
24+ const runners = convertRunnerOption ( incoming ) ;
25+
26+ return [ incoming . set ( "files" , fromJS ( { ...namespaces , ...runners } ) ) , [ ] ] ;
27+ }
28+
29+ export function convertRunnerOption ( incoming : BsTempOptions ) : FilesNamespaces | null {
30+ const runners = incoming . has ( "runners" ) ;
31+ if ( ! runners ) return null ;
32+
33+ const parser = z . array ( runnerOption ) ;
34+ const parsed = parser . safeParse ( incoming . get ( "runners" ) . toJS ( ) ) ;
35+ if ( ! parsed . success ) {
36+ // todo: what to do in this case?
37+ return null ;
38+ }
39+ const runnerData = parsed . data ;
40+ const output : FilesNamespaces = { } ;
41+
42+ runnerData . forEach ( ( runner , index ) => {
43+ const next : FilesNamespace = {
44+ index,
45+ globs : [ ] ,
46+ objs : [ ]
47+ } ;
48+ runner . files . forEach ( fileOption => {
49+ if ( typeof fileOption === "string" ) {
50+ next . globs . push ( fileOption ) ;
51+ }
52+ } ) ;
53+ output [ "__unstable_runner_" + index ] = next ;
54+ } ) ;
55+ return output ;
2556}
0 commit comments