diff --git a/.changeset/bright-bags-peel.md b/.changeset/bright-bags-peel.md new file mode 100644 index 0000000..c45d87b --- /dev/null +++ b/.changeset/bright-bags-peel.md @@ -0,0 +1,5 @@ +--- +'license-kit': minor +--- + +Separated copyleft and report commands, general code refactor diff --git a/.changeset/bright-bags-scream.md b/.changeset/bright-bags-scream.md new file mode 100644 index 0000000..3bf607c --- /dev/null +++ b/.changeset/bright-bags-scream.md @@ -0,0 +1,5 @@ +--- +'react-native-legal': minor +--- + +Consume extracted core logic from @callstack/react-native-legal-shared diff --git a/.changeset/many-things-joke.md b/.changeset/many-things-joke.md new file mode 100644 index 0000000..6f1ed5a --- /dev/null +++ b/.changeset/many-things-joke.md @@ -0,0 +1,5 @@ +--- +'@callstack/react-native-legal-shared': minor +--- + +Complete refactor, renamed generate* functions to write* and extracted generation logic to functions under previous generate\* names diff --git a/.changeset/tall-ghosts-stick.md b/.changeset/tall-ghosts-stick.md new file mode 100644 index 0000000..dd346ee --- /dev/null +++ b/.changeset/tall-ghosts-stick.md @@ -0,0 +1,6 @@ +--- +'license-kit': patch +'@callstack/react-native-legal-shared': patch +--- + +feat: setup new packages in monorepo diff --git a/.eslintrc.js b/.eslintrc.js index 8d2523a..9684f1b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,7 @@ /** @type {import("eslint").Linter.Config} */ const config = { root: true, - extends: '@callstack', + extends: ['@callstack'], ignorePatterns: ['node_modules/', '**/node_modules/', 'lib/', '**/lib/', 'build/', '**/build/'], rules: { // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs @@ -15,6 +15,7 @@ const config = { '**/babel.config.js', '**/jest.config.js', '**/metro.config.js', + '**/rspress.config.ts', ], }, ], diff --git a/.gitignore b/.gitignore index 86fb96d..c76836d 100644 --- a/.gitignore +++ b/.gitignore @@ -48,7 +48,8 @@ project.xcworkspace # Library build/ -packages/react-native-legal/lib/ +packages/*/lib/ +packages/*/build/ # Expo example examples/expo-example/android diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4c6a374..c789e02 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,12 @@ To get started with the project, run `yarn` in the root directory to install the yarn ``` +All packages in this monorepo depend on the [shared package](packages/shared) (`@callstack/react-native-legal-shared`). This package needs to be rebuilt whenever you make changes to it since other packages consume the exported, built JS code with emitted typings. You can do this by running the following command from the root directory, which will start `tsc` in watch mode: + +```sh +yarn workspace @callstack/react-native-legal-shared dev +``` + While developing, you will have 2 example apps that can be used to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app. @@ -79,6 +85,7 @@ The codebase of Expo Config Plugin is located in: - `packages/react-native-legal/plugin` - `packages/react-native-legal/plugin-utils` - `packages/react-native-legal/app.plugin.js` (the entry point) +- `packages/license-kit` (logic) To test the changes, build the plugin run (from the root directory, the one with consisting all workspaces): @@ -99,8 +106,9 @@ The codebase of RN CLI plugin is located in: - `packages/react-native-legal/bare-plugin` - `packages/react-native-legal/plugin-utils` - `packages/react-native-legal/react-native.config.js` (the entry point) +- `packages/license-kit` (logic) -To test the changes, build the plugin run (from the root directory, the one with consisting all workspaces): +To test the changes, build the plugin (run from the root directory, the one with consisting all workspaces): ```sh yarn workspace react-native-legal build-plugins @@ -145,11 +153,13 @@ yarn format:swift Objective-C code is linted and formatted using following commands: Lint code + ```sh yarn lint:objc ``` Fixing formatting errors + ```sh yarn format:objc ``` @@ -157,11 +167,13 @@ yarn format:objc For Kotlin codebase, run the following to verify code quality: Lint Kotlin code + ```sh yarn lint:android ``` Format Kotlin code + ```sh yarn format:android ``` diff --git a/README.md b/README.md index 9e4b5ef..4d9866f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ - React Native Legal + React Native Legal @@ -10,12 +10,40 @@ --- -| Android | iOS | AndroidTV | tvOS | -| - | - | - | - | +![E2E tests - Android](https://github.com/callstackincubator/react-native-legal/actions/workflows/test-e2e-android.yaml/badge.svg) +![E2E tests - iOS](https://github.com/callstackincubator/react-native-legal/actions/workflows/test-e2e-ios.yaml/badge.svg) +![Release](https://github.com/callstackincubator/react-native-legal/actions/workflows/release.yml/badge.svg) +![Deploy Docs](https://github.com/callstackincubator/react-native-legal/actions/workflows/deploy-docs.yml/badge.svg) + +- [Documentation](#documentation) +- [Installation](#installation) + - [React Native](#react-native) + - [Standalone CLI](#standalone-cli) + - [Node.js - API](#nodejs---api) +- [Usage](#usage) + - [I want to generate licenses in my Expo project ](#i-want-to-generate-licenses-in-my-expo-project-) + - [I want to generate licenses reports in my bare RN project ](#i-want-to-generate-licenses-reports-in-my-bare-rn-project-) + - [I want to generate licenses reports in my Node.js project](#i-want-to-generate-licenses-reports-in-my-nodejs-project) + - [I want to customize the presentation of the licenses in my JS/TS project](#i-want-to-customize-the-presentation-of-the-licenses-in-my-jsts-project) +- [Expo](#expo) +- [Contributing](#contributing) +- [Acknowledgements](#acknowledgements) +- [License](#license) + +Automagically generate license acknowledgements for your React Native app and any Node.js project πŸš€ + +| Android | iOS | AndroidTV | tvOS | +| ------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | | ![Android example](https://github.com/callstackincubator/react-native-legal/raw/main/static/android-expo.gif) | ![iOS example](https://github.com/callstackincubator/react-native-legal/raw/main/static/ios-expo.gif) | ![AndroidTV example](https://github.com/callstackincubator/react-native-legal/raw/main/static/android-tv.gif) | ![tvOS example](https://github.com/callstackincubator/react-native-legal/raw/main/static/tvos.gif) | +## Documentation + +You can find the full documentation for all packages in this repository at [callstackincubator.github.io/react-native-legal](https://callstackincubator.github.io/react-native-legal/). + ## Installation +### React Native + ```sh yarn add react-native-legal ``` @@ -26,11 +54,38 @@ or npm i --save react-native-legal ``` +### Standalone CLI + +```sh +yarn add -D license-kit +``` + +or + +```sh +npm i --save-dev license-kit +``` + +### Node.js - API + +```sh +yarn add @callstack/react-native-legal-shared +``` + +or + +```sh +npm i --save @callstack/react-native-legal-shared +``` + ## Usage -This tool is split into 2 parts: -- a library that lets you display native screen with a list of all dependencies and their licenses -- a [config plugin](https://docs.expo.dev/config-plugins/introduction/?redirected) (for Expo projects) and a [custom community cli plugin](https://github.com/react-native-community/cli/blob/main/docs/plugins.md) (for bare RN projects) +This tool is split into 4 parts: + +- a React Native library that lets you display native screen with a list of all dependencies and their licenses +- an [Expo config plugin](https://docs.expo.dev/config-plugins/introduction/?redirected) (for Expo projects) and a [custom community cli plugin](https://github.com/react-native-community/cli/blob/main/docs/plugins.md) (for bare RN projects) +- a standalone CLI tool that can be used in any Node.js project to generate license metadata +- a shared package that exposes the core functionality of the license management tool, allowing customization of presentation logic in your Node.js scripts ### I want to generate licenses in my Expo project @@ -68,7 +123,7 @@ function MyComponent() { 3. Use [Prebuild](https://docs.expo.dev/workflow/prebuild/) or [EAS](https://docs.expo.dev/eas/) to build the app -### I want to generate licenses in my bare RN project +### I want to generate licenses reports in my bare RN project 1. Invoke the CLI plugin from the root of your RN app @@ -102,6 +157,49 @@ function MyComponent() { } ``` +### I want to generate licenses reports in my Node.js project + +You can use the `license-kit` CLI tool to generate license reports in your Node.js project. Here's how to do it: + +1. Run the CLI tool from the root of your Node.js project: + +```sh +npx license-kit report --format markdown --output ./public/licenses.md +``` + +or + +```sh +yarn license-kit report --format markdown --output ./public/licenses.md +``` + +This will scan your project's dependencies and generate a license report in the specified format (JSON, Markdown, raw text, or AboutLibraries-compatible JSON metadata). + +For a list of supported flags and the default values, run `npx license-kit --help` or read them documented [in the package's README](./packages/license-kit/README.md#command-line-options). To read more about a specific command, run `npx license-kit --help`, e.g. `npx license-kit report --help`. + +### I want to customize the presentation of the licenses in my JS/TS project + +You can use the `@callstack/react-native-legal-shared` package to access the core functionalities of the license management tool. Here's a basic example of how to use it: + +```typescript +import { + generateAboutLibrariesNPMOutput, + generateLicensePlistNPMOutput, + scanDependencies, +} from '@callstack/react-native-legal-shared'; + +// scan dependencies of a package +const licenses = scanDependencies(packageJsonPath); + +// generate AboutLibraries-compatible JSON metadata +const aboutLibrariesCompatibleReport = generateAboutLibrariesNPMOutput(licenses); + +// generate LicensePlist-compatible metadata +const licensePlistReport = generateLicensePlistNPMOutput(licenses); +``` + +For more advanced usage, read the [programmatic usage documentation](https://callstackincubator.github.io/react-native-legal/docs/programmatic-usage#usage). + ## Expo - βœ… You can use this library with [Development Builds](https://docs.expo.dev/development/introduction/) by adding `react-native-legal` to your `app.json`/`app.config.js` plugins array. diff --git a/docs/.gitignore b/docs/.gitignore index 23a4bc9..21e50a6 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -12,3 +12,6 @@ doc_build/ .vscode/* !.vscode/extensions.json .idea + +# @rspress/plugin-typedoc +docs/api diff --git a/docs/components/CustomHomePage.tsx b/docs/components/CustomHomePage.tsx new file mode 100644 index 0000000..ab1b918 --- /dev/null +++ b/docs/components/CustomHomePage.tsx @@ -0,0 +1,101 @@ +import { usePageData } from 'rspress/runtime'; +import { Button, HomeFeature, HomeFooter, HomeHero } from 'rspress/theme'; + +export function CustomHomePage() { + const { + page: { routePath }, + } = usePageData(); + + return ( + <> + React Native Legal` + + '
' + + `License Kit`, + text: '', + tagline: + `` + + 'Automagically generate license acknowledgements' + + '\n' + + 'for your React Native app & any Node.js project' + + ``, + actions: [ + { theme: 'brand', text: 'React Native', link: '/docs/react-native' }, + { theme: 'brand', text: 'CLI', link: '/docs/standalone-cli' }, + { theme: 'brand', text: 'API', link: '/docs/programmatic-usage' }, + { theme: 'alt', text: 'GitHub', link: 'https://github.com/callstackincubator/react-native-legal' }, + ], + }, + }} + routePath={routePath} + /> + + + +
+ { + window.location.pathname = routePath + (routePath.endsWith('/') ? '' : '/') + 'docs/introduction'; + }} + > +
+ +
+ +
+ + ); +} diff --git a/docs/components/PackagesPresentation.tsx b/docs/components/PackagesPresentation.tsx new file mode 100644 index 0000000..152adb8 --- /dev/null +++ b/docs/components/PackagesPresentation.tsx @@ -0,0 +1,25 @@ +import { LinkCard } from 'rspress/theme'; + +export function PackagesPresentation() { + return ( +
+ + + + + +
+ ); +} diff --git a/docs/docs/_meta.json b/docs/docs/_meta.json index a55ff81..41809dc 100644 --- a/docs/docs/_meta.json +++ b/docs/docs/_meta.json @@ -1,7 +1,18 @@ [ { - "text": "Docs", - "link": "/docs/introduction.html", - "activeMatch": "/docs/" + "text": "Introduction", + "link": "/docs/introduction.html" + }, + { + "text": "React Native", + "link": "/docs/react-native.html" + }, + { + "text": "CLI", + "link": "/docs/standalone-cli.html" + }, + { + "text": "API", + "link": "/docs/programmatic-usage.html" } ] diff --git a/docs/docs/docs/_meta.json b/docs/docs/docs/_meta.json new file mode 100644 index 0000000..a874782 --- /dev/null +++ b/docs/docs/docs/_meta.json @@ -0,0 +1,34 @@ +[ + { + "type": "section-header", + "label": "Quickstart" + }, + { + "type": "custom-link", + "link": "/index", + "label": "Home" + }, + { + "type": "file", + "name": "introduction" + }, + { + "type": "divider" + }, + { + "type": "section-header", + "label": "Packages documentation" + }, + { + "type": "file", + "name": "react-native" + }, + { + "type": "file", + "name": "standalone-cli" + }, + { + "type": "file", + "name": "programmatic-usage" + } +] diff --git a/docs/docs/docs/introduction.mdx b/docs/docs/docs/introduction.mdx index f3f1ab1..be624fa 100644 --- a/docs/docs/docs/introduction.mdx +++ b/docs/docs/docs/introduction.mdx @@ -1,7 +1,17 @@ +--- +sidebar_position: 1 +--- + +import { PackagesPresentation } from '@components/PackagesPresentation'; + # Introduction -React Native Legal helps you acknowledge open-source libraries in your React Native app by automatically generating and displaying license information using native platform tools. This ensures compliance with open-source licenses while maintaining a native user experience. + + +
+ +React Native Legal (`react-native-legal`) helps you acknowledge open-source libraries in your React Native app by automatically generating and displaying license information using native platform tools. This ensures compliance with open-source licenses while maintaining a native user experience. + +We expose the core functionality related to Node.JS dependencies as a standalone CLI tool, `license-kit`, which can be used in any Node.js project, not just React Native apps. This allows you to generate license reports for any Node.js application. -| ![Android example](https://github.com/callstackincubator/react-native-legal/raw/main/static/android-expo.gif) | ![iOS example](https://github.com/callstackincubator/react-native-legal/raw/main/static/ios-expo.gif) | ![AndroidTV example](https://github.com/callstackincubator/react-native-legal/raw/main/static/android-tv.gif) | ![tvOS example](https://github.com/callstackincubator/react-native-legal/raw/main/static/tvos.gif) | -| :-: | :-: | :-: | :-: | -| **Android** | **iOS** | **AndroidTV** | **tvOS** | \ No newline at end of file +In case your use case involves programmatic usage of the functionality provided by `license-kit`, you can use the `@callstack/react-native-legal-shared` package. This package exposes the core functionalities of the license management tool, allowing you to integrate it into your Node.js applications. diff --git a/docs/docs/docs/programmatic-usage.mdx b/docs/docs/docs/programmatic-usage.mdx new file mode 100644 index 0000000..3d5a993 --- /dev/null +++ b/docs/docs/docs/programmatic-usage.mdx @@ -0,0 +1,81 @@ +--- +sidebar_position: 4 +--- + +import { PackageManagerTabs, Badge } from '@theme'; + +# Programmatic Usage (API) + +In case your use case involves programmatic usage of the functionality provided by `license-kit`, you can use the `@callstack/react-native-legal-shared` package. This package exposes the core functionalities of the license management tool, allowing you to integrate it into your Node.js applications. + +## Installation + +To get started, install the package using your preferred package manager: + + + +## Usage + +### Basic Usage + +```typescript +import { + generateAboutLibrariesNPMOutput, + generateLicensePlistNPMOutput, + scanDependencies, +} from '@callstack/react-native-legal-shared'; +import * as md from 'ts-markdown-builder'; + +// scan dependencies of a package +const licenses = scanDependencies(packageJsonPath); + +// generate AboutLibraries-compatible JSON metadata +const aboutLibrariesCompatibleReport = generateAboutLibrariesNPMOutput(licenses); + +// generate LicensePlist-compatible metadata +const licensePlistReport = generateLicensePlistNPMOutput(licenses); + +// generate a Markdown report +const markdownString = md + .joinBlocks( + Object.entries(licenses) + .flatMap(([packageName, { version, author, content, description, file, type, url }]) => [ + md.heading(packageName, { level: 2 }), + '\n', + `Version: ${version}
\n`, + url ? `URL: ${url}
\n` : '', + author ? `Author: ${author}
\n\n` : '', + content ?? '', + '\n', + description ? `Description: ${description}\n` : '', + file ? `\nFile: ${file}\n` : '', + type ? `Type: ${type}` : '', + '\n', + md.horizontalRule, + ]) + .join('\n'), + ) + .toString(); +``` + +### API Documentation + +The API documentation is published under: https://callstackincubator.github.io/react-native-legal/api/. + +## Additional details + +### License Types + +The tool recognizes various license types: + +- **Strong Copyleft**: Licenses that require derivative works to be released under the same license (e.g., GPL-3.0) +- **Weak Copyleft**: Licenses that require derivative works to be released under the same license, but with some exceptions (e.g., LGPL-3.0) +- **Permissive**: Licenses that allow for more flexible use (e.g., MIT, Apache-2.0) + +### Monorepo Support + +`react-native-legal` scans dependencies from workspace packages with the `workspace:*` notation in your `package.json` in addition to the app's direct dependencies. + +:::info +If a monorepo package is private, its name and license won't be included in the license list, but its dependencies will still be scanned and included. +::: diff --git a/docs/docs/docs/quick-start.mdx b/docs/docs/docs/react-native.mdx similarity index 50% rename from docs/docs/docs/quick-start.mdx rename to docs/docs/docs/react-native.mdx index 2ad44cf..4c17d68 100644 --- a/docs/docs/docs/quick-start.mdx +++ b/docs/docs/docs/react-native.mdx @@ -1,6 +1,10 @@ +--- +sidebar_position: 2 +--- + import { PackageManagerTabs, Badge } from '@theme'; -# Quick Start +# React Native Legal ## Installation @@ -8,6 +12,10 @@ To get started, install the package using your preferred package manager: +| ![Android example](https://github.com/callstackincubator/react-native-legal/raw/main/static/android-expo.gif) | ![iOS example](https://github.com/callstackincubator/react-native-legal/raw/main/static/ios-expo.gif) | ![AndroidTV example](https://github.com/callstackincubator/react-native-legal/raw/main/static/android-tv.gif) | ![tvOS example](https://github.com/callstackincubator/react-native-legal/raw/main/static/tvos.gif) | +| :-----------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------: | +| **Android** | **iOS** | **AndroidTV** | **tvOS** | + ## Setup The setup process varies depending on whether you are using Expo or a bare React Native project. Follow the steps below based on your project type. @@ -62,10 +70,7 @@ function launchNotice() { function MyComponent() { return ( -