Skip to content

Commit 4ebed78

Browse files
thymikeeartus9033mateusz1913
authored
feat: extracted packages: license-kit CLI and @callstack/react-native-legal-shared (#44)
* refactor: extract common logic to shared package * feat: rename to license-kit * chore: update bin * chore: not private * chore: set version instead of workspace * chore: changeset * v0.1.1 * fix: set shebang * chore: license-kit@0.1.2 * refactor!: refactor extracted parts of code to the shared module * chore: tsc watch script for development in shared package, updated docs * feat: print version of the CLI * feat: output and format flags to export to file in a given format, impl of presentation layer logic * chore: added dev script to CLI package * docs: rewrite of docs for all packages * docs: added badges to README.md * docs: added links to documentation website in README.md * chore: stripped obsolete style rule for docs * feat!: split the CLI into commands: report, copyleft * docs: reorganized landing page layout * chore: stripped obsolete console.log statements * chore: remove obsolete config file * fix: import shared utilities from dependency package rather than local build in react-native-legal * fix: revert accidental removal of plugin-utils dir from package.json files in react-native-legal * chore: remove obsolete development plugin to reduce obsolete indirect dependencies * chore: replace del-cli with rimraf * chore: remove obsolete eslint configuration * chore: updated project banner * docs: rspress typedoc plugin for API docs for @callstack/react-native-legal-shared * chore: changes after CR * chore: added changesets * feat: improve docs * feat: improve shared package * feat: improve license-kit copyleft output and detection of copyleft licenses * chore: implement integration tests for license-kit --------- Co-authored-by: artus9033 <artus9033@gmail.com> Co-authored-by: Mateusz Mędrek <mateusz.medrek@callstack.com>
1 parent 4cb4478 commit 4ebed78

67 files changed

Lines changed: 3487 additions & 603 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/bright-bags-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'license-kit': minor
3+
---
4+
5+
Separated copyleft and report commands, general code refactor

.changeset/bright-bags-scream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-native-legal': minor
3+
---
4+
5+
Consume extracted core logic from @callstack/react-native-legal-shared

.changeset/many-things-joke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@callstack/react-native-legal-shared': minor
3+
---
4+
5+
Complete refactor, renamed generate* functions to write* and extracted generation logic to functions under previous generate\* names

.changeset/tall-ghosts-stick.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'license-kit': patch
3+
'@callstack/react-native-legal-shared': patch
4+
---
5+
6+
feat: setup new packages in monorepo

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @type {import("eslint").Linter.Config} */
22
const config = {
33
root: true,
4-
extends: '@callstack',
4+
extends: ['@callstack'],
55
ignorePatterns: ['node_modules/', '**/node_modules/', 'lib/', '**/lib/', 'build/', '**/build/'],
66
rules: {
77
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
@@ -15,6 +15,7 @@ const config = {
1515
'**/babel.config.js',
1616
'**/jest.config.js',
1717
'**/metro.config.js',
18+
'**/rspress.config.ts',
1819
],
1920
},
2021
],

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ project.xcworkspace
4848

4949
# Library
5050
build/
51-
packages/react-native-legal/lib/
51+
packages/*/lib/
52+
packages/*/build/
5253

5354
# Expo example
5455
examples/expo-example/android

CONTRIBUTING.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ To get started with the project, run `yarn` in the root directory to install the
1010
yarn
1111
```
1212

13+
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:
14+
15+
```sh
16+
yarn workspace @callstack/react-native-legal-shared dev
17+
```
18+
1319
While developing, you will have 2 example apps that can be used to test your changes.
1420
Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild.
1521
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:
7985
- `packages/react-native-legal/plugin`
8086
- `packages/react-native-legal/plugin-utils`
8187
- `packages/react-native-legal/app.plugin.js` (the entry point)
88+
- `packages/license-kit` (logic)
8289

8390
To test the changes, build the plugin run (from the root directory, the one with consisting all workspaces):
8491

@@ -99,8 +106,9 @@ The codebase of RN CLI plugin is located in:
99106
- `packages/react-native-legal/bare-plugin`
100107
- `packages/react-native-legal/plugin-utils`
101108
- `packages/react-native-legal/react-native.config.js` (the entry point)
109+
- `packages/license-kit` (logic)
102110

103-
To test the changes, build the plugin run (from the root directory, the one with consisting all workspaces):
111+
To test the changes, build the plugin (run from the root directory, the one with consisting all workspaces):
104112

105113
```sh
106114
yarn workspace react-native-legal build-plugins
@@ -145,23 +153,27 @@ yarn format:swift
145153
Objective-C code is linted and formatted using following commands:
146154

147155
Lint code
156+
148157
```sh
149158
yarn lint:objc
150159
```
151160

152161
Fixing formatting errors
162+
153163
```sh
154164
yarn format:objc
155165
```
156166

157167
For Kotlin codebase, run the following to verify code quality:
158168

159169
Lint Kotlin code
170+
160171
```sh
161172
yarn lint:android
162173
```
163174

164175
Format Kotlin code
176+
165177
```sh
166178
yarn format:android
167179
```

README.md

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<a href="https://www.callstack.com/open-source?utm_campaign=generic&utm_source=github&utm_medium=referral&utm_content=react-native-legal" align="center">
22
<picture>
3-
<img alt="React Native Legal" src="https://github.com/user-attachments/assets/dd266822-1f3c-48ff-816c-7aaeb95d85aa">
3+
<img alt="React Native Legal" src="./images/banner.jpg">
44
</picture>
55
</a>
66

@@ -10,12 +10,40 @@
1010

1111
---
1212

13-
| Android | iOS | AndroidTV | tvOS |
14-
| - | - | - | - |
13+
![E2E tests - Android](https://github.com/callstackincubator/react-native-legal/actions/workflows/test-e2e-android.yaml/badge.svg)
14+
![E2E tests - iOS](https://github.com/callstackincubator/react-native-legal/actions/workflows/test-e2e-ios.yaml/badge.svg)
15+
![Release](https://github.com/callstackincubator/react-native-legal/actions/workflows/release.yml/badge.svg)
16+
![Deploy Docs](https://github.com/callstackincubator/react-native-legal/actions/workflows/deploy-docs.yml/badge.svg)
17+
18+
- [Documentation](#documentation)
19+
- [Installation](#installation)
20+
- [React Native](#react-native)
21+
- [Standalone CLI](#standalone-cli)
22+
- [Node.js - API](#nodejs---api)
23+
- [Usage](#usage)
24+
- [I want to generate licenses in my Expo project ](#i-want-to-generate-licenses-in-my-expo-project-)
25+
- [I want to generate licenses reports in my bare RN project ](#i-want-to-generate-licenses-reports-in-my-bare-rn-project-)
26+
- [I want to generate licenses reports in my Node.js project](#i-want-to-generate-licenses-reports-in-my-nodejs-project)
27+
- [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)
28+
- [Expo](#expo)
29+
- [Contributing](#contributing)
30+
- [Acknowledgements](#acknowledgements)
31+
- [License](#license)
32+
33+
Automagically generate license acknowledgements for your React Native app and any Node.js project 🚀
34+
35+
| Android | iOS | AndroidTV | tvOS |
36+
| ------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
1537
| ![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) |
1638

39+
## Documentation
40+
41+
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/).
42+
1743
## Installation
1844

45+
### React Native
46+
1947
```sh
2048
yarn add react-native-legal
2149
```
@@ -26,11 +54,38 @@ or
2654
npm i --save react-native-legal
2755
```
2856

57+
### Standalone CLI
58+
59+
```sh
60+
yarn add -D license-kit
61+
```
62+
63+
or
64+
65+
```sh
66+
npm i --save-dev license-kit
67+
```
68+
69+
### Node.js - API
70+
71+
```sh
72+
yarn add @callstack/react-native-legal-shared
73+
```
74+
75+
or
76+
77+
```sh
78+
npm i --save @callstack/react-native-legal-shared
79+
```
80+
2981
## Usage
3082

31-
This tool is split into 2 parts:
32-
- a library that lets you display native screen with a list of all dependencies and their licenses
33-
- 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)
83+
This tool is split into 4 parts:
84+
85+
- a React Native library that lets you display native screen with a list of all dependencies and their licenses
86+
- 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)
87+
- a standalone CLI tool that can be used in any Node.js project to generate license metadata
88+
- a shared package that exposes the core functionality of the license management tool, allowing customization of presentation logic in your Node.js scripts
3489

3590
### I want to generate licenses in my Expo project <a name="usage-expo"></a>
3691

@@ -68,7 +123,7 @@ function MyComponent() {
68123

69124
3. Use [Prebuild](https://docs.expo.dev/workflow/prebuild/) or [EAS](https://docs.expo.dev/eas/) to build the app
70125

71-
### I want to generate licenses in my bare RN project <a name="usage-bare-rn"></a>
126+
### I want to generate licenses reports in my bare RN project <a name="usage-bare-rn"></a>
72127

73128
1. Invoke the CLI plugin from the root of your RN app
74129

@@ -102,6 +157,49 @@ function MyComponent() {
102157
}
103158
```
104159

160+
### I want to generate licenses reports in my Node.js project
161+
162+
You can use the `license-kit` CLI tool to generate license reports in your Node.js project. Here's how to do it:
163+
164+
1. Run the CLI tool from the root of your Node.js project:
165+
166+
```sh
167+
npx license-kit report --format markdown --output ./public/licenses.md
168+
```
169+
170+
or
171+
172+
```sh
173+
yarn license-kit report --format markdown --output ./public/licenses.md
174+
```
175+
176+
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).
177+
178+
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 <command> --help`, e.g. `npx license-kit report --help`.
179+
180+
### I want to customize the presentation of the licenses in my JS/TS project
181+
182+
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:
183+
184+
```typescript
185+
import {
186+
generateAboutLibrariesNPMOutput,
187+
generateLicensePlistNPMOutput,
188+
scanDependencies,
189+
} from '@callstack/react-native-legal-shared';
190+
191+
// scan dependencies of a package
192+
const licenses = scanDependencies(packageJsonPath);
193+
194+
// generate AboutLibraries-compatible JSON metadata
195+
const aboutLibrariesCompatibleReport = generateAboutLibrariesNPMOutput(licenses);
196+
197+
// generate LicensePlist-compatible metadata
198+
const licensePlistReport = generateLicensePlistNPMOutput(licenses);
199+
```
200+
201+
For more advanced usage, read the [programmatic usage documentation](https://callstackincubator.github.io/react-native-legal/docs/programmatic-usage#usage).
202+
105203
## Expo
106204

107205
- ✅ 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.

docs/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ doc_build/
1212
.vscode/*
1313
!.vscode/extensions.json
1414
.idea
15+
16+
# @rspress/plugin-typedoc
17+
docs/api

docs/components/CustomHomePage.tsx

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { usePageData } from 'rspress/runtime';
2+
import { Button, HomeFeature, HomeFooter, HomeHero } from 'rspress/theme';
3+
4+
export function CustomHomePage() {
5+
const {
6+
page: { routePath },
7+
} = usePageData();
8+
9+
return (
10+
<>
11+
<HomeHero
12+
frontmatter={{
13+
hero: {
14+
name:
15+
`<span class="hero-name">React Native Legal</span>` +
16+
'<br/>' +
17+
`<span class="hero-name">License Kit</span>`,
18+
text: '',
19+
tagline:
20+
`<span class="hero-tagline" style="line-height: 1.4;">` +
21+
'Automagically generate license acknowledgements' +
22+
'\n' +
23+
'for your <ins>React Native app</ins> & <ins>any Node.js</ins> project' +
24+
`</span>`,
25+
actions: [
26+
{ theme: 'brand', text: 'React Native', link: '/docs/react-native' },
27+
{ theme: 'brand', text: 'CLI', link: '/docs/standalone-cli' },
28+
{ theme: 'brand', text: 'API', link: '/docs/programmatic-usage' },
29+
{ theme: 'alt', text: 'GitHub', link: 'https://github.com/callstackincubator/react-native-legal' },
30+
],
31+
},
32+
}}
33+
routePath={routePath}
34+
/>
35+
36+
<HomeFeature
37+
frontmatter={{
38+
features: [
39+
{
40+
title: 'Native Integration',
41+
details:
42+
'Uses native platform tools (LicensePlist for iOS and AboutLibraries for Android) to generate and display licenses.',
43+
icon: '📱',
44+
link: '/docs/react-native',
45+
},
46+
{
47+
title: 'Expo & Bare Workflow Support',
48+
details:
49+
'Works with both Expo managed workflow via Config Plugin and React Native CLI via custom command.',
50+
icon: '🔌',
51+
link: '/docs/react-native#setup',
52+
},
53+
{
54+
title: 'NodeJS / Non-RN Projects Support',
55+
details:
56+
'Works with any Node.js project, not just React Native apps. Use it to generate license reports for any Node.js application.',
57+
icon: '💻',
58+
link: '/docs/standalone-cli',
59+
},
60+
{
61+
title: 'Versatile output formats (CLI & Programmatic)',
62+
details:
63+
'Generate license reports in a format of choice (JSON, Markdown, raw text, AboutLibraries-compatible JSON metadata).',
64+
icon: '📝',
65+
link: '/docs/standalone-cli#command-line-options',
66+
},
67+
{
68+
title: 'Programmatic API',
69+
details:
70+
'Core functionalities are exposed as an importable package you can use programmatically and adjust the presentation / processing of the report contents.',
71+
icon: '🛠️',
72+
link: '/docs/programmatic-usage',
73+
},
74+
{
75+
title: 'Automatic Scanning',
76+
details:
77+
'Automatically scans your dependencies and generates license information for both iOS and Android platforms.',
78+
icon: '🔎',
79+
link: '/docs/react-native',
80+
},
81+
],
82+
}}
83+
routePath={routePath}
84+
/>
85+
86+
<div className="docs-introduction-cta">
87+
<span
88+
onClick={() => {
89+
window.location.pathname = routePath + (routePath.endsWith('/') ? '' : '/') + 'docs/introduction';
90+
}}
91+
>
92+
<Button text="Not sure, which to choose?" theme="alt" type="button" size="medium" />
93+
</span>
94+
</div>
95+
96+
<div className="home-footer-wrapper">
97+
<HomeFooter />
98+
</div>
99+
</>
100+
);
101+
}

0 commit comments

Comments
 (0)