diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8c68be5e8..e5d973ffb 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.5.0](https://github.com/callstack/react-native-builder-bob/compare/docs@0.4.1...docs@0.5.0) (2025-02-07) + +### Features + +* **bob:** support custom target definitions ([#732](https://github.com/callstack/react-native-builder-bob/issues/732)) ([5b42f44](https://github.com/callstack/react-native-builder-bob/commit/5b42f440fc609d9a49b94a5435276acda9d0ade7)) - by @atlj + ## [0.4.1](https://github.com/callstack/react-native-builder-bob/compare/docs@0.4.0...docs@0.4.1) (2024-12-04) ### Bug Fixes diff --git a/docs/package.json b/docs/package.json index aa97c8471..33a9246f3 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,6 +1,6 @@ { "name": "docs", - "version": "0.4.1", + "version": "0.5.0", "private": true, "description": "Documentation for react-native-builder-bob", "scripts": { diff --git a/docs/pages/build.md b/docs/pages/build.md index e3245b2ba..828eb7506 100644 --- a/docs/pages/build.md +++ b/docs/pages/build.md @@ -188,6 +188,18 @@ Generates the [React Native Codegen](https://reactnative.dev/docs/the-new-archit You can ensure your Codegen generated scaffold code is stable through different React Native versions by shipping it with your library. You can find more in the [React Native Official Docs](https://reactnative.dev/docs/the-new-architecture/codegen-cli#including-generated-code-into-libraries). +#### `custom` + +Define a custom build target. This is useful to call code generators during the build process. + +##### `script` + +Accepts a script name. `bob` will call the matching script defined under `package.json`'s `scripts` property. The build process **will throw and exit** if the target is defined without this option. + +##### `clean` + +You can pass a path to this option and `bob` will delete all the files on that path. The path is resolved relatively to where `build` was called from. + #### `commonjs` Enable compiling source files with Babel and use CommonJS module system. diff --git a/packages/create-react-native-library/CHANGELOG.md b/packages/create-react-native-library/CHANGELOG.md index 2d473dacd..c5e2fe4c7 100644 --- a/packages/create-react-native-library/CHANGELOG.md +++ b/packages/create-react-native-library/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.47.1](https://github.com/callstack/react-native-builder-bob/compare/create-react-native-library@0.47.0...create-react-native-library@0.47.1) (2025-02-07) + +### Bug Fixes + +* `nkdversion` -> `ndkVersion` casing in `gradle.properties` ([#744](https://github.com/callstack/react-native-builder-bob/issues/744)) ([981eea1](https://github.com/callstack/react-native-builder-bob/commit/981eea148bf092fd1107173863417b54353f7202)), closes [/github.com/callstack/react-native-builder-bob/blob/87b0032acd66b7b14a5b358117a3d1497c59baad/packages/create-react-native-library/templates/native-common/android/build.gradle#L62](https://github.com//github.com/callstack/react-native-builder-bob/blob/87b0032acd66b7b14a5b358117a3d1497c59baad/packages/create-react-native-library/templates/native-common/android/build.gradle/issues/L62) - by @KiwiKilian + # [0.47.0](https://github.com/callstack/react-native-builder-bob/compare/create-react-native-library@0.46.0...create-react-native-library@0.47.0) (2025-01-28) ### Bug Fixes diff --git a/packages/create-react-native-library/package.json b/packages/create-react-native-library/package.json index 209e431e5..dc1b655ac 100644 --- a/packages/create-react-native-library/package.json +++ b/packages/create-react-native-library/package.json @@ -1,6 +1,6 @@ { "name": "create-react-native-library", - "version": "0.47.0", + "version": "0.47.1", "description": "CLI to scaffold React Native libraries", "keywords": [ "react-native", diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index f01eed082..a9cdfa92a 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -20,7 +20,7 @@ import { import { getDependencyVersionsFromExampleApp } from './exampleApp/dependencies'; import { printErrorHelp, printNextSteps, printUsedRNVersion } from './inform'; -const FALLBACK_BOB_VERSION = '0.32.0'; +const FALLBACK_BOB_VERSION = '0.36.0'; yargs .command( diff --git a/packages/create-react-native-library/templates/common/$.gitignore b/packages/create-react-native-library/templates/common/$.gitignore index cfe2bb4fd..46c939a7d 100644 --- a/packages/create-react-native-library/templates/common/$.gitignore +++ b/packages/create-react-native-library/templates/common/$.gitignore @@ -28,6 +28,7 @@ DerivedData *.ipa *.xcuserstate project.xcworkspace +**/.xcode.env.local # Android/IJ # diff --git a/packages/create-react-native-library/templates/native-common/android/gradle.properties b/packages/create-react-native-library/templates/native-common/android/gradle.properties index 52515e42a..88563f3c1 100644 --- a/packages/create-react-native-library/templates/native-common/android/gradle.properties +++ b/packages/create-react-native-library/templates/native-common/android/gradle.properties @@ -2,4 +2,4 @@ <%- project.name -%>_minSdkVersion=24 <%- project.name -%>_targetSdkVersion=34 <%- project.name -%>_compileSdkVersion=35 -<%- project.name -%>_ndkversion=27.1.12297006 +<%- project.name -%>_ndkVersion=27.1.12297006 diff --git a/packages/react-native-builder-bob/CHANGELOG.md b/packages/react-native-builder-bob/CHANGELOG.md index e9fb67ccc..073925ee2 100644 --- a/packages/react-native-builder-bob/CHANGELOG.md +++ b/packages/react-native-builder-bob/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.37.0](https://github.com/callstack/react-native-builder-bob/compare/react-native-builder-bob@0.36.0...react-native-builder-bob@0.37.0) (2025-02-07) + +### Features + +* **bob:** support custom target definitions ([#732](https://github.com/callstack/react-native-builder-bob/issues/732)) ([5b42f44](https://github.com/callstack/react-native-builder-bob/commit/5b42f440fc609d9a49b94a5435276acda9d0ade7)) - by @atlj + # [0.36.0](https://github.com/callstack/react-native-builder-bob/compare/react-native-builder-bob@0.35.3...react-native-builder-bob@0.36.0) (2025-01-28) ### Bug Fixes diff --git a/packages/react-native-builder-bob/package.json b/packages/react-native-builder-bob/package.json index aa0d52145..f3935d2d8 100644 --- a/packages/react-native-builder-bob/package.json +++ b/packages/react-native-builder-bob/package.json @@ -1,6 +1,6 @@ { "name": "react-native-builder-bob", - "version": "0.36.0", + "version": "0.37.0", "description": "CLI to build JavaScript files for React Native libraries", "keywords": [ "react-native", diff --git a/packages/react-native-builder-bob/src/index.ts b/packages/react-native-builder-bob/src/index.ts index ca696bdb7..1f1a26a8b 100644 --- a/packages/react-native-builder-bob/src/index.ts +++ b/packages/react-native-builder-bob/src/index.ts @@ -11,6 +11,7 @@ import buildCommonJS from './targets/commonjs'; import buildModule from './targets/module'; import buildTypescript from './targets/typescript'; import buildCodegen from './targets/codegen'; +import customTarget from './targets/custom'; import type { Options, Report, Target } from './types'; type ArgName = 'target'; @@ -584,6 +585,14 @@ async function buildTarget( report, }); break; + case 'custom': + await customTarget({ + options: targetOptions, + source: path.resolve(root, source), + report, + root, + }); + break; default: logger.exit(`Invalid target ${kleur.blue(targetName)}.`); } diff --git a/packages/react-native-builder-bob/src/targets/custom.ts b/packages/react-native-builder-bob/src/targets/custom.ts new file mode 100644 index 000000000..28679260f --- /dev/null +++ b/packages/react-native-builder-bob/src/targets/custom.ts @@ -0,0 +1,72 @@ +import kleur from 'kleur'; +import path from 'path'; +import fs from 'fs-extra'; +import type { Input } from '../types'; +import { spawn } from '../utils/spawn'; +import dedent from 'dedent'; +import del from 'del'; + +type Options = Omit & { + options?: { + script?: string; + clean?: string; + }; +}; + +export default async function customTarget({ options, root, report }: Options) { + if (options?.script == null) { + report.error( + dedent( + `No script was provided with the custom target. + Example: ${kleur.green('{["custom", { "script": "generateTypes" }}')}` + ) + ); + process.exit(1); + } + + const pathToClean = options.clean + ? path.relative(root, options.clean) + : undefined; + + if (pathToClean) { + report.info(`Cleaning up ${kleur.blue(pathToClean)}`); + + await del([path.resolve(root, pathToClean)]); + } + + const packageManagerExecutable = process.env.npm_execpath ?? 'npm'; + const packageManagerArgs = ['run', options.script]; + + // usr/bin/yarn -> yarn + const packageManagerName = path.basename(packageManagerExecutable); + report.info( + `Running ${kleur.blue(packageManagerName)} ${kleur.blue( + packageManagerArgs.join(' ') + )}` + ); + + try { + await spawn(packageManagerExecutable, packageManagerArgs, { + stdio: ['ignore', 'ignore', 'inherit'], + }); + } catch (e) { + report.error( + `An error occurred when running ${kleur.blue(options.script)}` + ); + process.exit(1); + } + + report.success(`Ran the ${kleur.blue(options.script)} script succesfully`); + + if (options.clean && pathToClean && !(await fs.pathExists(pathToClean))) { + report.warn( + `Custom target with the ${kleur.blue( + options.script + )} script has ${kleur.blue(options.clean)} as the ${kleur.bold( + 'clean' + )} option but this path wasn't created after running the script. Are you sure you've defined the ${kleur.bold( + 'clean' + )} path correctly?` + ); + } +} diff --git a/packages/react-native-builder-bob/src/types.ts b/packages/react-native-builder-bob/src/types.ts index 1a20240be..9a8b7419e 100644 --- a/packages/react-native-builder-bob/src/types.ts +++ b/packages/react-native-builder-bob/src/types.ts @@ -13,7 +13,12 @@ export type Input = { report: Report; }; -export type Target = 'commonjs' | 'module' | 'typescript' | 'codegen'; +export type Target = + | 'commonjs' + | 'module' + | 'typescript' + | 'codegen' + | 'custom'; export type Options = { source?: string;