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';
1212import buildTypescript from './targets/typescript' ;
1313import buildCodegen from './targets/codegen' ;
1414import type { Options , Report , Target } from './types' ;
15+ import runScript from './targets/script' ;
1516
1617type ArgName = 'target' ;
1718
@@ -584,6 +585,15 @@ async function buildTarget(
584585 report,
585586 } ) ;
586587 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 ;
587597 default :
588598 logger . exit ( `Invalid target ${ kleur . blue ( targetName ) } .` ) ;
589599 }
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 = {
1313 report : Report ;
1414} ;
1515
16- export type Target = 'commonjs' | 'module' | 'typescript' | 'codegen' ;
16+ export type Target = 'commonjs' | 'module' | 'typescript' | 'codegen' | 'script' ;
1717
1818export type Options = {
1919 source ?: string ;
You can’t perform that action at this time.
0 commit comments