Skip to content

Commit 30e83d0

Browse files
committed
feat: add script target
1 parent e4649c6 commit 30e83d0

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

packages/react-native-builder-bob/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import buildModule from './targets/module';
1212
import buildTypescript from './targets/typescript';
1313
import buildCodegen from './targets/codegen';
1414
import type { Options, Report, Target } from './types';
15+
import runScript from './targets/script';
1516

1617
type 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
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

packages/react-native-builder-bob/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

1818
export type Options = {
1919
source?: string;

0 commit comments

Comments
 (0)