Skip to content

Commit

Permalink
feat: cli support beta components (#109)
Browse files Browse the repository at this point in the history
* feat: add command support beta package

* fix: undefined component

* feat: add beta component suppport

* fix: doctor command

* feat: add command add beta option

* feat: upgrade command add beta option

* docs: update README.md

* fix: lock

* fix: upgrade version

* fix: upgrade select version

* fix: compare issue
  • Loading branch information
winchesHe authored Nov 29, 2024
1 parent 294a886 commit b9ce3ac
Show file tree
Hide file tree
Showing 15 changed files with 1,038 additions and 158 deletions.
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

0 comments on commit b9ce3ac

Please sign in to comment.