File tree Expand file tree Collapse file tree 3 files changed +58
-1
lines changed
packages/react-native-builder-bob/src Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import buildModule from './targets/module';
12
12
import buildTypescript from './targets/typescript' ;
13
13
import buildCodegen from './targets/codegen' ;
14
14
import type { Options , Report , Target } from './types' ;
15
+ import runScript from './targets/script' ;
15
16
16
17
type ArgName = 'target' ;
17
18
@@ -584,6 +585,15 @@ async function buildTarget(
584
585
report,
585
586
} ) ;
586
587
break ;
588
+ case 'script' :
589
+ await runScript ( {
590
+ options : targetOptions ,
591
+ source : path . resolve ( root , source ) ,
592
+ output : path . resolve ( root , output , 'typescript' ) ,
593
+ report,
594
+ root,
595
+ } )
596
+ break ;
587
597
default :
588
598
logger . exit ( `Invalid target ${ kleur . blue ( targetName ) } .` ) ;
589
599
}
Original file line number Diff line number Diff line change
1
+ import kleur from 'kleur' ;
2
+ import type { Input } from '../types' ;
3
+ import { spawn } from '../utils/spawn' ;
4
+ import dedent from 'dedent' ;
5
+
6
+ type Options = Input & {
7
+ options ?: {
8
+ run ?: string ;
9
+ cwd ?: string ;
10
+ }
11
+ } ;
12
+
13
+ export default async function runScript ( {
14
+ options,
15
+ root,
16
+ report
17
+ } : Options ) {
18
+ if ( options ?. run === undefined ) {
19
+ report . error (
20
+ dedent (
21
+ `No runnable provided with the script target.
22
+ Example: ${ kleur . green ( '{["script", { run: "yarn generateTypes" }}' ) } `
23
+ )
24
+ )
25
+ process . exit ( 1 )
26
+ }
27
+
28
+ const [ scriptBinary , ...scriptParams ] = options . run . split ( " " ) ;
29
+ if ( scriptBinary === undefined ) {
30
+ report . error (
31
+ "No runnable provided with the script target."
32
+ )
33
+ process . exit ( 1 )
34
+ }
35
+
36
+ const cwd = options ?. cwd ?? root
37
+
38
+ report . info (
39
+ `Running ${ kleur . blue ( options . run ) } `
40
+ ) ;
41
+
42
+ await spawn ( scriptBinary , scriptParams , {
43
+ cwd,
44
+ } )
45
+
46
+ report . success ( `Ran ${ kleur . blue ( options . run ) } succesfully` )
47
+ }
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ export type Input = {
13
13
report : Report ;
14
14
} ;
15
15
16
- export type Target = 'commonjs' | 'module' | 'typescript' | 'codegen' ;
16
+ export type Target = 'commonjs' | 'module' | 'typescript' | 'codegen' | 'script' ;
17
17
18
18
export type Options = {
19
19
source ?: string ;
You can’t perform that action at this time.
0 commit comments