Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cli support beta components #109

Merged
merged 11 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Usage: nextui [command]
Options:
-v, --version Output the current version
--no-cache Disable cache, by default data will be cached for 30m after the first request
-d, --debug Debug mode will not install dependencies
-h --help Display help information for commands

Commands:
Expand Down Expand Up @@ -132,6 +133,7 @@ nextui add [components...] [options]
- `-app --appPath` [string] The path to the App.tsx file
- `--prettier` [boolean] Add prettier format in the add content which required installed prettier - (default: `false`)
- `--addApp` [boolean] Add App.tsx file content which required provider (default: `false`)
- `-b --beta` [boolean] Add beta components (default: `false`)

##### Example

Expand Down Expand Up @@ -208,6 +210,7 @@ nextui upgrade [components...] [options]
- `-p --packagePath` [string] The path to the package.json file
- `-a --all` [boolean] Upgrade all the NextUI components (default: `false`)
- `-w --write` [boolean] Write the upgrade version to package.json file (default: `false`)
- `-b --beta` [boolean] Upgrade beta components (default: `false`)
- `-h --help` Display help for command

##### Example
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"async-retry": "1.3.3",
"chalk": "5.3.0",
"commander": "11.0.0",
"compare-versions": "6.1.1",
"fast-glob": "3.3.2",
"find-up": "7.0.0",
"gradient-string": "2.0.2",
Expand Down
79 changes: 49 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions src/actions/add-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {existsSync, writeFileSync} from 'node:fs';

import chalk from 'chalk';

import {getBetaComponents} from '@helpers/beta';
import {
checkApp,
checkIllegalComponents,
Expand Down Expand Up @@ -36,13 +37,15 @@ interface AddActionOptions {
tailwindPath?: string;
appPath?: string;
addApp?: boolean;
beta?: boolean;
}

export async function addAction(components: string[], options: AddActionOptions) {
const {
addApp = false,
all = false,
appPath = findFiles('**/App.(j|t)sx')[0],
beta = false,
packagePath = resolver('package.json'),
tailwindPath = findFiles('**/tailwind.config.(j|t)s')[0]
} = options;
Expand Down Expand Up @@ -73,7 +76,7 @@ export async function addAction(components: string[], options: AddActionOptions)
}

/** ======================== Add judge whether illegal component exist ======================== */
if (!all && !checkIllegalComponents(components)) {
if (!all && !checkIllegalComponents(components, true)) {
return;
}

Expand Down Expand Up @@ -113,7 +116,8 @@ export async function addAction(components: string[], options: AddActionOptions)
if (all) {
const [, ...missingDependencies] = await checkRequiredContentInstalled(
'all',
allDependenciesKeys
allDependenciesKeys,
{beta}
);

if (missingDependencies.length) {
Expand All @@ -131,12 +135,13 @@ export async function addAction(components: string[], options: AddActionOptions)
} else {
const [, ..._missingDependencies] = await checkRequiredContentInstalled(
'partial',
allDependenciesKeys
allDependenciesKeys,
{beta}
);
const missingDependencies = [
..._missingDependencies,
...components.map((c) => store.nextUIComponentsMap[c]!.package)
];
const mergedComponents = beta
? await getBetaComponents(components)
: components.map((c) => store.nextUIComponentsMap[c]!.package);
const missingDependencies = [..._missingDependencies, ...mergedComponents];

Logger.info(
`Adding required dependencies: ${[...missingDependencies]
Expand Down
Loading
Loading