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(shadcn-ui): move shadcn-ui to shadcn #341

Merged
merged 6 commits into from
Nov 15, 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
34 changes: 26 additions & 8 deletions e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ensureNxProject } from '../../utils/workspace'
import { runNxCommandAsync } from '../../utils/run-nx-command-async'
import { checkFilesExist } from '@nx/plugin/testing'
import { checkFilesExist, readJson } from '@nx/plugin/testing'

describe('shadcn/ui e2e', () => {

Expand All @@ -22,14 +22,32 @@ describe('shadcn/ui e2e', () => {
`${utilsLibName}/src/index.ts`,
'components.json'
)).not.toThrow()

const componentsJSON = readJson('components.json')
expect(componentsJSON.tailwind.config).toEqual(`${utilsLibName}/src/tailwind.config.ts`)
expect(componentsJSON.tailwind.css).toEqual(`${utilsLibName}/src/global.css`)
expect(componentsJSON.aliases.hooks).toEqual(`@proj/${uiLibName}/hooks`)

const tsconfigJSON = readJson('tsconfig.base.json')
expect(tsconfigJSON.compilerOptions.paths[`@proj/${uiLibName}`][0]).toEqual(`${uiLibName}/src`)
expect(tsconfigJSON.compilerOptions.paths[`@proj/${utilsLibName}`][0]).toEqual(`${utilsLibName}/src`)
})

// it('should be able add a button', async () => {
// await runNxCommandAsync(`add ${uiLibName} button`)
//
// expect(() => checkFilesExist(
// `${uiLibName}/src/button.tsx`,
// )).not.toThrow()
// })
bzp2010 marked this conversation as resolved.
Show resolved Hide resolved
it('should be able add button ui', async () => {
await runNxCommandAsync(`add-component ${uiLibName} button`)

expect(() => checkFilesExist(
`${uiLibName}/src/ui/button.tsx`,
)).not.toThrow()
})

it('should be able add sidebar ui', async () => {
await runNxCommandAsync(`add-component ${uiLibName} sidebar --overwrite`) // Overwrites are needed because of button ui conflicts

expect(() => checkFilesExist(
`${uiLibName}/src/ui/sidebar.tsx`,
`${uiLibName}/src/hooks/use-mobile.tsx`,
)).not.toThrow()
})

})
15 changes: 8 additions & 7 deletions packages/shadcn-ui/src/executors/add/add.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ export async function addExecutor(
options: ExecutorSchema,
context: ExecutorContext
): Promise<{ success: boolean }> {
const { root } = context.projectsConfigurations.projects[context.projectName]

return execPackageManagerCommand(
buildCommand([
'shadcn[email protected] add',
'shadcn@latest add',
(options.component ?? '').length === 0 ? '--all' : options.component,
options.overwrite && '--overwrite',
'--path=src',
`--cwd=${root}`
options.overwrite && '--overwrite'
]),
{}
{
env: {
...process.env,
TS_NODE_PROJECT: 'tsconfig.base.json'
}
}
)
}

Expand Down
15 changes: 10 additions & 5 deletions packages/shadcn-ui/src/generators/init/init.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default async function (tree: Tree, options: ShadecnUiSchema) {
skipFormat: true,
style: 'css',
linter: Linter.EsLint,
directory: uiLibOptions.projectRoot
directory: uiLibOptions.projectRoot,
skipTsConfig: true
})

const utilsLibOptions = await determineProjectNameAndRootOptions(tree, {
Expand All @@ -64,9 +65,12 @@ export default async function (tree: Tree, options: ShadecnUiSchema) {
skipFormat: true,
style: 'css',
linter: Linter.EsLint,
directory: utilsLibOptions.projectRoot
directory: utilsLibOptions.projectRoot,
skipTsConfig: true
})

addTsConfigPath(tree, `${uiLibOptions.importPath}`, [`${uiLibOptions.projectRoot}/src`])
addTsConfigPath(tree, `${utilsLibOptions.importPath}`, [`${utilsLibOptions.projectRoot}/src`])
addTsConfigPath(tree, `${uiLibOptions.importPath}/*`, [`${uiLibOptions.projectRoot}/src/*`])
addTsConfigPath(tree, `${utilsLibOptions.importPath}/*`, [`${utilsLibOptions.projectRoot}/src/*`])
cleanupLib(tree, uiLibOptions.projectRoot)
Expand All @@ -79,14 +83,15 @@ export default async function (tree: Tree, options: ShadecnUiSchema) {
'style': 'default',
'rsc': false,
'tailwind': {
'config': join(utilsLibOptions.projectRoot, 'tailwind.config.js'),
'css': join(utilsLibOptions.projectRoot, 'global.css'),
'config': join(utilsLibOptions.projectRoot, 'src/tailwind.config.ts'),
'css': join(utilsLibOptions.projectRoot, 'src/global.css'),
'baseColor': 'neutral',
'cssVariables': true
},
'aliases': {
'components': uiLibOptions.importPath,
'utils': utilsLibOptions.importPath
'utils': utilsLibOptions.importPath,
"hooks": `${uiLibOptions.importPath}/hooks`
}
})

Expand Down
Loading