Skip to content

Commit

Permalink
Improvements v2 (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs authored Jan 18, 2024
2 parents ffa784e + eac038e commit 7bc7707
Show file tree
Hide file tree
Showing 28 changed files with 743 additions and 0 deletions.
15 changes: 15 additions & 0 deletions e2e/shadcn-ui-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
displayName: 'shadcn-ui-e2e',
preset: '../../jest.preset.js',
globals: {},
transform: {
'^.+\\.[tj]s$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json'
}
]
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/e2e/shadcn-ui-e2e'
}
19 changes: 19 additions & 0 deletions e2e/shadcn-ui-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "shadcn-ui-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "e2e/shadcn-ui-e2e/src",
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "e2e/shadcn-ui-e2e/jest.config.ts",
"runInBand": true,
"passWithNoTests": false
},
"dependsOn": ["shadcn-ui:build"]
}
},
"tags": [],
"implicitDependencies": ["shadcn-ui"]
}
35 changes: 35 additions & 0 deletions e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ensureNxProject } from '../../utils/workspace'
import { runNxCommandAsync } from '../../utils/run-nx-command-async'
import { checkFilesExist } from '@nx/plugin/testing'

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

beforeAll(() => ensureNxProject([
'@nx-extend/core:dist/packages/core',
'@nx-extend/shadcn-ui:dist/packages/shadcn-ui'
]))

const uiLibName = 'shadcn-ui/ui'
const utilsLibName = 'shadcn-ui/utils'

it('should be able to init', async () => {
await runNxCommandAsync(`generate @nx-extend/shadcn-ui:init ${uiLibName} ${utilsLibName}`)

expect(() => checkFilesExist(
`${utilsLibName}/src/tailwind.config.js`,
`${utilsLibName}/src/global.css`,
`${utilsLibName}/src/cn.ts`,
`${utilsLibName}/src/index.ts`,
'components.json'
)).not.toThrow()
})

// it('should be able add a button', async () => {
// await runNxCommandAsync(`add ${uiLibName} button`)
//
// expect(() => checkFilesExist(
// `${uiLibName}/src/button.tsx`,
// )).not.toThrow()
// })

})
13 changes: 13 additions & 0 deletions e2e/shadcn-ui-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.e2e.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
9 changes: 9 additions & 0 deletions e2e/shadcn-ui-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
37 changes: 37 additions & 0 deletions packages/shadcn-ui/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"extends": "../../.eslintrc.json",
"ignorePatterns": [
"!**/*"
],
"rules": {},
"overrides": [
{
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"parserOptions": {
"project": [
"packages/shadcn-ui/tsconfig.*?.json"
]
},
"rules": {}
},
{
"files": [
"*.ts",
"*.tsx"
],
"rules": {}
},
{
"files": [
"*.js",
"*.jsx"
],
"rules": {}
}
]
}
24 changes: 24 additions & 0 deletions packages/shadcn-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# @nx-extend/shadcn-ui

<a href="https://www.npmjs.com/package/@nx-extend/shadcn-ui" rel="nofollow">
<img src="https://badgen.net/npm/v/@nx-extend/shadcn-ui" alt="@nx-extend/shadcn-ui NPM package">
</a>

**Nx plugin for working with [shadcn/ui](https://ui.shadcn.com/)**.

## Setup

### Install

```sh
npm install -D @nx-extend/shadcn-ui
nx g @nx-extend/shadcn-ui:init
```

## Usage

### Add

```sh
nx g @nx-extend/shadcn-ui:add button
```
16 changes: 16 additions & 0 deletions packages/shadcn-ui/executors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"executors": {
"add": {
"implementation": "./src/executors/add/add.impl",
"schema": "./src/executors/add/schema.json",
"description": "add executor"
}
},
"builders": {
"add": {
"implementation": "./src/executors/add/add.impl",
"schema": "./src/executors/add/schema.json",
"description": "add executor"
}
}
}
12 changes: 12 additions & 0 deletions packages/shadcn-ui/generators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://json-schema.org/schema",
"name": "shadcn-ui",
"version": "0.0.1",
"generators": {
"init": {
"factory": "./src/generators/init/init.impl",
"schema": "./src/generators/init/schema.json",
"description": "init generator"
}
}
}
12 changes: 12 additions & 0 deletions packages/shadcn-ui/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable */
export default {
displayName: 'shadcn-ui',
preset: '../../jest.preset.js',
globals: {},
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/packages/shadcn-ui',
testEnvironment: 'node'
}
27 changes: 27 additions & 0 deletions packages/shadcn-ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@nx-extend/shadcn-ui",
"version": "0.0.1",
"keywords": [
"nx",
"shadcn-ui"
],
"homepage": "https://github.com/TriPSs/nx-extend/blob/master/packages/shadcn-ui/README.md",
"bugs": {
"url": "https://github.com/tripss/nx-extend/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tripss/nx-extend"
},
"license": "MIT",
"main": "src/index.js",
"devDependencies": {
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"lucide-react": "^0.312.0",
"tailwind-merge": "^2.2.0",
"tailwindcss-animate": "^1.0.7"
},
"builders": "./executors.json",
"generators": "./generators.json"
}
64 changes: 64 additions & 0 deletions packages/shadcn-ui/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "shadcn-ui",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/shadcn-ui/src",
"projectType": "library",
"targets": {
"lint": {
"executor": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": ["packages/shadcn-ui/**/*.ts"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/packages/shadcn-ui"],
"options": {
"jestConfig": "packages/shadcn-ui/jest.config.ts"
}
},
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/shadcn-ui",
"tsConfig": "packages/shadcn-ui/tsconfig.lib.json",
"packageJson": "packages/shadcn-ui/package.json",
"main": "packages/shadcn-ui/src/index.ts",
"buildableProjectDepsInPackageJsonType": "dependencies",
"assets": [
"packages/shadcn-ui/*.md",
{
"input": "./packages/shadcn-ui/src",
"glob": "**/*.!(ts)",
"output": "./src"
},
{
"input": "./packages/shadcn-ui",
"glob": "generators.json",
"output": "."
},
{
"input": "./packages/shadcn-ui",
"glob": "executors.json",
"output": "."
}
],
"updateBuildableProjectDepsInPackageJson": true
}
},
"version": {
"executor": "@jscutlery/semver:version",
"options": {
"tagPrefix": "${target}@"
}
},
"publish": {
"executor": "nx:run-commands",
"options": {
"command": "npm publish ./dist/packages/shadcn-ui --access public || true"
}
}
},
"tags": []
}
26 changes: 26 additions & 0 deletions packages/shadcn-ui/src/executors/add/add.impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ExecutorContext } from '@nx/devkit'
import { buildCommand, execCommand } from '@nx-extend/core'

export interface ExecutorSchema {
component: string
overwrite?: boolean
}

export async function addExecutor(
options: ExecutorSchema,
context: ExecutorContext
): Promise<{ success: boolean }> {
const { root } = context.workspace.projects[context.projectName]

return execCommand(buildCommand([
'npx shadcn-ui@latest add',
options.component,
options.overwrite && '--overwrite',
'--path=src',
`--cwd=${root}`
]),{

})
}

export default addExecutor
5 changes: 5 additions & 0 deletions packages/shadcn-ui/src/executors/add/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { convertNxExecutor } from '@nx/devkit'

import { addExecutor } from './add.impl'

export default convertNxExecutor(addExecutor)
22 changes: 22 additions & 0 deletions packages/shadcn-ui/src/executors/add/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": 2,
"outputCapture": "direct-nodejs",
"$schema": "http://json-schema.org/schema",
"type": "object",
"title": "add executor",
"description": "",
"properties": {
"component": {
"type": "string",
"description": "",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What component would you like to add?"
}
},
"required": [
"component"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';

export const cn = function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
};
Loading

0 comments on commit 7bc7707

Please sign in to comment.