From 2aebc32c2b44988f0a64cb51d7a7fc9d9dcc8ef6 Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Thu, 18 Jan 2024 13:28:41 +0100 Subject: [PATCH 1/4] fix(vercel): Added `remix` as framework option --- packages/vercel/src/executors/build/schema.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vercel/src/executors/build/schema.json b/packages/vercel/src/executors/build/schema.json index ea2bfa70..96e26f46 100644 --- a/packages/vercel/src/executors/build/schema.json +++ b/packages/vercel/src/executors/build/schema.json @@ -24,6 +24,7 @@ "docusaurus", "docusaurus-2", "vue", + "remix", "other" ] } From 954889dff1b7b618a002b6f38ba62f8254806232 Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Thu, 18 Jan 2024 14:55:29 +0100 Subject: [PATCH 2/4] feat(shadcn-ui): Added package --- e2e/shadcn-ui-e2e/jest.config.ts | 15 +++ e2e/shadcn-ui-e2e/project.json | 19 ++++ e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts | 26 +++++ e2e/shadcn-ui-e2e/tsconfig.json | 13 +++ e2e/shadcn-ui-e2e/tsconfig.spec.json | 9 ++ packages/shadcn-ui/.eslintrc.json | 37 +++++++ packages/shadcn-ui/README.md | 24 +++++ packages/shadcn-ui/executors.json | 6 ++ packages/shadcn-ui/generators.json | 12 +++ packages/shadcn-ui/jest.config.ts | 12 +++ packages/shadcn-ui/package.json | 27 +++++ packages/shadcn-ui/project.json | 64 +++++++++++ .../init/files-utils/cn.ts.template | 6 ++ .../init/files-utils/global.css.template | 60 +++++++++++ .../files-utils/tailwind.config.js.template | 74 +++++++++++++ .../src/generators/init/init.impl.ts | 102 ++++++++++++++++++ .../shadcn-ui/src/generators/init/schema.d.ts | 4 + .../shadcn-ui/src/generators/init/schema.json | 30 ++++++ packages/shadcn-ui/src/index.ts | 0 packages/shadcn-ui/tsconfig.json | 13 +++ packages/shadcn-ui/tsconfig.lib.json | 12 +++ packages/shadcn-ui/tsconfig.spec.json | 16 +++ yarn.lock | 71 ++++++++++++ 23 files changed, 652 insertions(+) create mode 100644 e2e/shadcn-ui-e2e/jest.config.ts create mode 100644 e2e/shadcn-ui-e2e/project.json create mode 100644 e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts create mode 100644 e2e/shadcn-ui-e2e/tsconfig.json create mode 100644 e2e/shadcn-ui-e2e/tsconfig.spec.json create mode 100644 packages/shadcn-ui/.eslintrc.json create mode 100644 packages/shadcn-ui/README.md create mode 100644 packages/shadcn-ui/executors.json create mode 100644 packages/shadcn-ui/generators.json create mode 100644 packages/shadcn-ui/jest.config.ts create mode 100644 packages/shadcn-ui/package.json create mode 100644 packages/shadcn-ui/project.json create mode 100644 packages/shadcn-ui/src/generators/init/files-utils/cn.ts.template create mode 100644 packages/shadcn-ui/src/generators/init/files-utils/global.css.template create mode 100644 packages/shadcn-ui/src/generators/init/files-utils/tailwind.config.js.template create mode 100644 packages/shadcn-ui/src/generators/init/init.impl.ts create mode 100644 packages/shadcn-ui/src/generators/init/schema.d.ts create mode 100644 packages/shadcn-ui/src/generators/init/schema.json create mode 100644 packages/shadcn-ui/src/index.ts create mode 100644 packages/shadcn-ui/tsconfig.json create mode 100644 packages/shadcn-ui/tsconfig.lib.json create mode 100644 packages/shadcn-ui/tsconfig.spec.json diff --git a/e2e/shadcn-ui-e2e/jest.config.ts b/e2e/shadcn-ui-e2e/jest.config.ts new file mode 100644 index 00000000..17ca9666 --- /dev/null +++ b/e2e/shadcn-ui-e2e/jest.config.ts @@ -0,0 +1,15 @@ +export default { + displayName: 'shadcn-ui-e2e', + preset: '../../jest.preset.js', + globals: {}, + transform: { + '^.+\\.[tj]s$': [ + 'ts-jest', + { + tsconfig: '/tsconfig.spec.json' + } + ] + }, + moduleFileExtensions: ['ts', 'js', 'html'], + coverageDirectory: '../../coverage/e2e/shadcn-ui-e2e' +} diff --git a/e2e/shadcn-ui-e2e/project.json b/e2e/shadcn-ui-e2e/project.json new file mode 100644 index 00000000..3791a249 --- /dev/null +++ b/e2e/shadcn-ui-e2e/project.json @@ -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"] +} diff --git a/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts b/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts new file mode 100644 index 00000000..aaefb142 --- /dev/null +++ b/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts @@ -0,0 +1,26 @@ +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`, + 'components.json' + )).not.toThrow() + }) + +}) diff --git a/e2e/shadcn-ui-e2e/tsconfig.json b/e2e/shadcn-ui-e2e/tsconfig.json new file mode 100644 index 00000000..879cca47 --- /dev/null +++ b/e2e/shadcn-ui-e2e/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.base.json", + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.e2e.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/e2e/shadcn-ui-e2e/tsconfig.spec.json b/e2e/shadcn-ui-e2e/tsconfig.spec.json new file mode 100644 index 00000000..29efa430 --- /dev/null +++ b/e2e/shadcn-ui-e2e/tsconfig.spec.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": ["**/*.spec.ts", "**/*.d.ts"] +} diff --git a/packages/shadcn-ui/.eslintrc.json b/packages/shadcn-ui/.eslintrc.json new file mode 100644 index 00000000..9e4a7b76 --- /dev/null +++ b/packages/shadcn-ui/.eslintrc.json @@ -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": {} + } + ] +} diff --git a/packages/shadcn-ui/README.md b/packages/shadcn-ui/README.md new file mode 100644 index 00000000..9eb4fedc --- /dev/null +++ b/packages/shadcn-ui/README.md @@ -0,0 +1,24 @@ +# @nx-extend/shadcn-ui + + + @nx-extend/shadcn-ui NPM package + + +**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 +``` diff --git a/packages/shadcn-ui/executors.json b/packages/shadcn-ui/executors.json new file mode 100644 index 00000000..7f6d9dd8 --- /dev/null +++ b/packages/shadcn-ui/executors.json @@ -0,0 +1,6 @@ +{ + "executors": { + }, + "builders": { + } +} diff --git a/packages/shadcn-ui/generators.json b/packages/shadcn-ui/generators.json new file mode 100644 index 00000000..6a6c51e0 --- /dev/null +++ b/packages/shadcn-ui/generators.json @@ -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" + } + } +} diff --git a/packages/shadcn-ui/jest.config.ts b/packages/shadcn-ui/jest.config.ts new file mode 100644 index 00000000..fdbfcf96 --- /dev/null +++ b/packages/shadcn-ui/jest.config.ts @@ -0,0 +1,12 @@ +/* eslint-disable */ +export default { + displayName: 'shadcn-ui', + preset: '../../jest.preset.js', + globals: {}, + transform: { + '^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }] + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], + coverageDirectory: '../../coverage/packages/shadcn-ui', + testEnvironment: 'node' +} diff --git a/packages/shadcn-ui/package.json b/packages/shadcn-ui/package.json new file mode 100644 index 00000000..5634ad43 --- /dev/null +++ b/packages/shadcn-ui/package.json @@ -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" +} diff --git a/packages/shadcn-ui/project.json b/packages/shadcn-ui/project.json new file mode 100644 index 00000000..a6c80915 --- /dev/null +++ b/packages/shadcn-ui/project.json @@ -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": [] +} diff --git a/packages/shadcn-ui/src/generators/init/files-utils/cn.ts.template b/packages/shadcn-ui/src/generators/init/files-utils/cn.ts.template new file mode 100644 index 00000000..68efbe05 --- /dev/null +++ b/packages/shadcn-ui/src/generators/init/files-utils/cn.ts.template @@ -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)); +}; diff --git a/packages/shadcn-ui/src/generators/init/files-utils/global.css.template b/packages/shadcn-ui/src/generators/init/files-utils/global.css.template new file mode 100644 index 00000000..173f5cc5 --- /dev/null +++ b/packages/shadcn-ui/src/generators/init/files-utils/global.css.template @@ -0,0 +1,60 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +@layer base { + :root { + --background: 0 0% 100%; + --foreground: 240 10% 3.9%; + --card: 0 0% 100%; + --card-foreground: 240 10% 3.9%; + --popover: 0 0% 100%; + --popover-foreground: 240 10% 3.9%; + --primary: 240 5.9% 10%; + --primary-foreground: 0 0% 98%; + --secondary: 240 4.8% 95.9%; + --secondary-foreground: 240 5.9% 10%; + --muted: 240 4.8% 95.9%; + --muted-foreground: 240 3.8% 46.1%; + --accent: 240 4.8% 95.9%; + --accent-foreground: 240 5.9% 10%; + --destructive: 0 84.2% 60.2%; + --destructive-foreground: 0 0% 98%; + --border: 240 5.9% 90%; + --input: 240 5.9% 90%; + --ring: 240 5.9% 10%; + --radius: 0.5rem; + } + + .dark { + --background: 240 10% 3.9%; + --foreground: 0 0% 98%; + --card: 240 10% 3.9%; + --card-foreground: 0 0% 98%; + --popover: 240 10% 3.9%; + --popover-foreground: 0 0% 98%; + --primary: 0 0% 98%; + --primary-foreground: 240 5.9% 10%; + --secondary: 240 3.7% 15.9%; + --secondary-foreground: 0 0% 98%; + --muted: 240 3.7% 15.9%; + --muted-foreground: 240 5% 64.9%; + --accent: 240 3.7% 15.9%; + --accent-foreground: 0 0% 98%; + --destructive: 0 62.8% 30.6%; + --destructive-foreground: 0 0% 98%; + --border: 240 3.7% 15.9%; + --input: 240 3.7% 15.9%; + --ring: 240 4.9% 83.9%; + } +} + +@layer base { + * { + @apply border-border; + } + body { + @apply bg-background text-foreground; + font-feature-settings: "rlig" 1, "calt" 1; + } +} diff --git a/packages/shadcn-ui/src/generators/init/files-utils/tailwind.config.js.template b/packages/shadcn-ui/src/generators/init/files-utils/tailwind.config.js.template new file mode 100644 index 00000000..62635cba --- /dev/null +++ b/packages/shadcn-ui/src/generators/init/files-utils/tailwind.config.js.template @@ -0,0 +1,74 @@ +const { join } = require('path'); + +const defaultTheme = require('tailwindcss/defaultTheme'); +const TailwindAnimate = require('tailwindcss-animate'); + +module.exports = { + content: [ + join( + __dirname, + '{src,pages,components,app}/**/*!(*.stories|*.spec).{ts,tsx,html}' + ), + ...createGlobPatternsForDependencies(__dirname), + ], + theme: { + extend: { + colors: { + border: 'hsl(var(--border))', + input: 'hsl(var(--input))', + ring: 'hsl(var(--ring))', + background: 'hsl(var(--background))', + foreground: 'hsl(var(--foreground))', + primary: { + DEFAULT: 'hsl(var(--primary))', + foreground: 'hsl(var(--primary-foreground))', + }, + secondary: { + DEFAULT: 'hsl(var(--secondary))', + foreground: 'hsl(var(--secondary-foreground))', + }, + destructive: { + DEFAULT: 'hsl(var(--destructive))', + foreground: 'hsl(var(--destructive-foreground))', + }, + muted: { + DEFAULT: 'hsl(var(--muted))', + foreground: 'hsl(var(--muted-foreground))', + }, + accent: { + DEFAULT: 'hsl(var(--accent))', + foreground: 'hsl(var(--accent-foreground))', + }, + popover: { + DEFAULT: 'hsl(var(--popover))', + foreground: 'hsl(var(--popover-foreground))', + }, + card: { + DEFAULT: 'hsl(var(--card))', + foreground: 'hsl(var(--card-foreground))', + }, + }, + borderRadius: { + lg: `var(--radius)`, + md: `calc(var(--radius) - 2px)`, + sm: 'calc(var(--radius) - 4px)', + }, + keyframes: { + 'accordion-down': { + from: { height: 0 }, + to: { height: 'var(--radix-accordion-content-height)' }, + }, + 'accordion-up': { + from: { height: 'var(--radix-accordion-content-height)' }, + to: { height: 0 }, + }, + }, + animation: { + 'accordion-down': 'accordion-down 0.2s ease-out', + 'accordion-up': 'accordion-up 0.2s ease-out', + }, + }, + }, + plugins: [TailwindAnimate], + darkMode: ['class'], +}; diff --git a/packages/shadcn-ui/src/generators/init/init.impl.ts b/packages/shadcn-ui/src/generators/init/init.impl.ts new file mode 100644 index 00000000..9e840cf9 --- /dev/null +++ b/packages/shadcn-ui/src/generators/init/init.impl.ts @@ -0,0 +1,102 @@ +import { + addDependenciesToPackageJson, + generateFiles, + getWorkspaceLayout, + joinPathFragments, + runTasksInSerial, + Tree, writeJson +} from '@nx/devkit' +import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils' +import { addTsConfigPath, libraryGenerator } from '@nx/js' +import { join } from 'path' + +import type { ShadecnUiSchema } from './schema' + +import { devDependencies } from '../../../package.json' + +function cleanupLib(tree: Tree, libDirectory: string) { + // Remove the unneeded files + tree.delete(`${libDirectory}/src/index.ts`) + const libFiles = tree.children(`${libDirectory}/src/lib`) + + for (const file of libFiles) { + tree.delete(`${libDirectory}/src/lib/${file}`) + } +} + +function addFilesToUtilsLib(host: Tree, libDirectory: string) { + generateFiles(host, join(__dirname, 'files-utils'), libDirectory, { + template: '' + }) +} + +function getLibRoot(host: Tree, fileName: string) { + return joinPathFragments( + getWorkspaceLayout(host).libsDir, + fileName + ) +} + +export default async function (tree: Tree, options: ShadecnUiSchema) { + await libraryGenerator(tree, { + name: options.uiName, + skipFormat: true + }) + + const uiLibOptions = await determineProjectNameAndRootOptions(tree, { + callingGenerator: '@nx-extend/shadcn-ui:init', + name: options.uiName, + projectType: 'library' + }) + + const uiRoot = getLibRoot(tree, uiLibOptions.projectRoot) + addTsConfigPath(tree, `${uiLibOptions.importPath}/*`, [`${uiRoot}/src/*`]) + cleanupLib(tree, uiRoot) + + await libraryGenerator(tree, { + name: options.utilsName, + skipFormat: true + }) + + const utilsLibOptions = await determineProjectNameAndRootOptions(tree, { + callingGenerator: '@nx-extend/shadcn-ui:init', + name: options.utilsName, + projectType: 'library' + }) + + const utilRoot = getLibRoot(tree, utilsLibOptions.projectRoot) + addTsConfigPath(tree, `${utilsLibOptions.importPath}/*`, [`${utilRoot}/src/*`]) + cleanupLib(tree, utilRoot) + + addFilesToUtilsLib(tree, `${getLibRoot(tree, options.utilsName)}/src`) + + writeJson(tree, 'components.json', { + '$schema': 'https://ui.shadcn.com/schema.json', + 'style': 'default', + 'rsc': false, + 'tailwind': { + 'config': join(utilRoot, 'tailwind.config.js'), + 'css': join(utilRoot, 'global.css'), + 'baseColor': 'neutral', + 'cssVariables': true + }, + 'aliases': { + 'components': uiLibOptions.importPath, + 'utils': utilsLibOptions.importPath + } + }) + + return runTasksInSerial( + addDependenciesToPackageJson( + tree, + { + 'class-variance-authority': devDependencies['class-variance-authority'], + 'clsx': devDependencies['clsx'], + 'lucide-react': devDependencies['lucide-react'], + 'tailwind-merge': devDependencies['tailwind-merge'], + 'tailwindcss-animate': devDependencies['tailwindcss-animate'] + }, + {} + ) + ) +} diff --git a/packages/shadcn-ui/src/generators/init/schema.d.ts b/packages/shadcn-ui/src/generators/init/schema.d.ts new file mode 100644 index 00000000..2bfdcbe7 --- /dev/null +++ b/packages/shadcn-ui/src/generators/init/schema.d.ts @@ -0,0 +1,4 @@ +export interface ShadecnUiSchema { + uiName: string + utilsName: string +} diff --git a/packages/shadcn-ui/src/generators/init/schema.json b/packages/shadcn-ui/src/generators/init/schema.json new file mode 100644 index 00000000..f39faa14 --- /dev/null +++ b/packages/shadcn-ui/src/generators/init/schema.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json-schema.org/schema", + "type": "object", + "id": "Strapi", + "title": "", + "properties": { + "uiName": { + "type": "string", + "description": "", + "$default": { + "$source": "argv", + "index": 0 + }, + "x-prompt": "What name would you like to use for the ui lib?" + }, + "utilsName": { + "type": "string", + "description": "", + "$default": { + "$source": "argv", + "index": 1 + }, + "x-prompt": "What name would you like to use for the utils lib?" + } + }, + "required": [ + "uiName", + "utilsName" + ] +} diff --git a/packages/shadcn-ui/src/index.ts b/packages/shadcn-ui/src/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/shadcn-ui/tsconfig.json b/packages/shadcn-ui/tsconfig.json new file mode 100644 index 00000000..62ebbd94 --- /dev/null +++ b/packages/shadcn-ui/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.base.json", + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/packages/shadcn-ui/tsconfig.lib.json b/packages/shadcn-ui/tsconfig.lib.json new file mode 100644 index 00000000..4cc95e88 --- /dev/null +++ b/packages/shadcn-ui/tsconfig.lib.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../../dist/out-tsc", + "declaration": true, + "types": ["node"], + "resolveJsonModule": true + }, + "exclude": ["**/*.spec.ts", "jest.config.ts"], + "include": ["**/*.ts"] +} diff --git a/packages/shadcn-ui/tsconfig.spec.json b/packages/shadcn-ui/tsconfig.spec.json new file mode 100644 index 00000000..831ab648 --- /dev/null +++ b/packages/shadcn-ui/tsconfig.spec.json @@ -0,0 +1,16 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "**/*.spec.ts", + "**/*.spec.tsx", + "**/*.spec.js", + "**/*.spec.jsx", + "**/*.d.ts", + "jest.config.ts" + ] +} diff --git a/yarn.lock b/yarn.lock index 2f6e895c..0906f96e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2302,6 +2302,15 @@ __metadata: languageName: node linkType: hard +"@babel/runtime@npm:^7.23.5": + version: 7.23.8 + resolution: "@babel/runtime@npm:7.23.8" + dependencies: + regenerator-runtime: "npm:^0.14.0" + checksum: ec8f1967a36164da6cac868533ffdff97badd76d23d7d820cc84f0818864accef972f22f9c6a710185db1e3810e353fc18c3da721e5bb3ee8bc61bdbabce03ff + languageName: node + linkType: hard + "@babel/template@npm:^7.22.15": version: 7.22.15 resolution: "@babel/template@npm:7.22.15" @@ -4798,6 +4807,18 @@ __metadata: languageName: unknown linkType: soft +"@nx-extend/shadcn-ui@workspace:packages/shadcn-ui": + version: 0.0.0-use.local + resolution: "@nx-extend/shadcn-ui@workspace:packages/shadcn-ui" + dependencies: + class-variance-authority: "npm:^0.7.0" + clsx: "npm:^2.1.0" + lucide-react: "npm:^0.312.0" + tailwind-merge: "npm:^2.2.0" + tailwindcss-animate: "npm:^1.0.7" + languageName: unknown + linkType: soft + "@nx-extend/strapi@workspace:packages/strapi": version: 0.0.0-use.local resolution: "@nx-extend/strapi@workspace:packages/strapi" @@ -10753,6 +10774,15 @@ __metadata: languageName: node linkType: hard +"class-variance-authority@npm:^0.7.0": + version: 0.7.0 + resolution: "class-variance-authority@npm:0.7.0" + dependencies: + clsx: "npm:2.0.0" + checksum: 06646e82953e577fb8834100d763f1e5ecb808b8a1fba6244e94b20603865b134ff2296e30432449793baaeb02282cce617afba6981afe18b6846f1f8e9485ca + languageName: node + linkType: hard + "clean-css@npm:^5.2.2": version: 5.3.2 resolution: "clean-css@npm:5.3.2" @@ -10909,6 +10939,20 @@ __metadata: languageName: node linkType: hard +"clsx@npm:2.0.0": + version: 2.0.0 + resolution: "clsx@npm:2.0.0" + checksum: 943766d1b02fee3538c871e56638d87f973fbc2d6291ce221215ea436fdecb9be97ad323f411839c2d52c45640c449b1a53fbfe7e8b3d529b4e263308b630c9a + languageName: node + linkType: hard + +"clsx@npm:^2.1.0": + version: 2.1.0 + resolution: "clsx@npm:2.1.0" + checksum: 2e0ce7c3b6803d74fc8147c408f88e79245583202ac14abd9691e2aebb9f312de44270b79154320d10bb7804a9197869635d1291741084826cff20820f31542b + languageName: node + linkType: hard + "co-body@npm:^5.1.1": version: 5.2.0 resolution: "co-body@npm:5.2.0" @@ -19017,6 +19061,15 @@ __metadata: languageName: node linkType: hard +"lucide-react@npm:^0.312.0": + version: 0.312.0 + resolution: "lucide-react@npm:0.312.0" + peerDependencies: + react: ^16.5.1 || ^17.0.0 || ^18.0.0 + checksum: 39f6d6c7460064ed8cac503018c1f8410cd55666b4cb56928456c99c80b39cf54c0cac3c1a5abe02dd7e9b32c9e7473351d1f138ba6e80204956b51a28f5f0f0 + languageName: node + linkType: hard + "luxon@npm:^1.26.0": version: 1.28.1 resolution: "luxon@npm:1.28.1" @@ -24713,6 +24766,24 @@ __metadata: languageName: node linkType: hard +"tailwind-merge@npm:^2.2.0": + version: 2.2.0 + resolution: "tailwind-merge@npm:2.2.0" + dependencies: + "@babel/runtime": "npm:^7.23.5" + checksum: ec2a249da3c7afc2df935f93dd896843c719a701bd692cf051eafb2b2350989da158e7af9cc976227e49c833501a91b06c42b80aa6721457eec2187a999c9be7 + languageName: node + linkType: hard + +"tailwindcss-animate@npm:^1.0.7": + version: 1.0.7 + resolution: "tailwindcss-animate@npm:1.0.7" + peerDependencies: + tailwindcss: "*" + checksum: ef176fbb0bf9dca84178b35b6a9615cd756358ea80be9c575456d12ecd7f3c431e9e571915c7df72959dc798a730959e9a4739d59eab55d8cc6db390870ff0d2 + languageName: node + linkType: hard + "tapable@npm:^2.0.0, tapable@npm:^2.1.1, tapable@npm:^2.2.0, tapable@npm:^2.2.1": version: 2.2.1 resolution: "tapable@npm:2.2.1" From 387ac6561a72934bf2dfadcaf1feceab60bd1544 Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Thu, 18 Jan 2024 14:58:24 +0100 Subject: [PATCH 3/4] refactor(shadcn-ui): Added notes --- .../src/generators/init/files-utils/global.css.template | 4 ++++ .../generators/init/files-utils/tailwind.config.js.template | 3 +++ 2 files changed, 7 insertions(+) diff --git a/packages/shadcn-ui/src/generators/init/files-utils/global.css.template b/packages/shadcn-ui/src/generators/init/files-utils/global.css.template index 173f5cc5..d7c2aad9 100644 --- a/packages/shadcn-ui/src/generators/init/files-utils/global.css.template +++ b/packages/shadcn-ui/src/generators/init/files-utils/global.css.template @@ -1,3 +1,7 @@ +/** + * Don't forget to update your APPs global.css to include this file! + */ + @tailwind base; @tailwind components; @tailwind utilities; diff --git a/packages/shadcn-ui/src/generators/init/files-utils/tailwind.config.js.template b/packages/shadcn-ui/src/generators/init/files-utils/tailwind.config.js.template index 62635cba..a0d2e70a 100644 --- a/packages/shadcn-ui/src/generators/init/files-utils/tailwind.config.js.template +++ b/packages/shadcn-ui/src/generators/init/files-utils/tailwind.config.js.template @@ -1,3 +1,6 @@ +/** + * Don't forget to update your APPs tailwind.config.js to include this file! + */ const { join } = require('path'); const defaultTheme = require('tailwindcss/defaultTheme'); From eac038e97a673493a249a6c2a5d639f54d816453 Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Thu, 18 Jan 2024 15:49:29 +0100 Subject: [PATCH 4/4] feat(shadcn-ui): Added `add` executor to add new components --- e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts | 9 +++++++ packages/shadcn-ui/executors.json | 10 +++++++ .../shadcn-ui/src/executors/add/add.impl.ts | 26 +++++++++++++++++++ .../shadcn-ui/src/executors/add/compat.ts | 5 ++++ .../shadcn-ui/src/executors/add/schema.json | 22 ++++++++++++++++ .../init/files-utils/index.ts.template | 1 + .../src/generators/init/init.impl.ts | 14 ++++++++-- 7 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 packages/shadcn-ui/src/executors/add/add.impl.ts create mode 100644 packages/shadcn-ui/src/executors/add/compat.ts create mode 100644 packages/shadcn-ui/src/executors/add/schema.json create mode 100644 packages/shadcn-ui/src/generators/init/files-utils/index.ts.template diff --git a/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts b/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts index aaefb142..bc1eb45c 100644 --- a/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts +++ b/e2e/shadcn-ui-e2e/tests/shadcn-ui.spec.ts @@ -19,8 +19,17 @@ describe('shadcn/ui e2e', () => { `${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() + // }) + }) diff --git a/packages/shadcn-ui/executors.json b/packages/shadcn-ui/executors.json index 7f6d9dd8..09fa8459 100644 --- a/packages/shadcn-ui/executors.json +++ b/packages/shadcn-ui/executors.json @@ -1,6 +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" + } } } diff --git a/packages/shadcn-ui/src/executors/add/add.impl.ts b/packages/shadcn-ui/src/executors/add/add.impl.ts new file mode 100644 index 00000000..97fb1619 --- /dev/null +++ b/packages/shadcn-ui/src/executors/add/add.impl.ts @@ -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 diff --git a/packages/shadcn-ui/src/executors/add/compat.ts b/packages/shadcn-ui/src/executors/add/compat.ts new file mode 100644 index 00000000..4e773afa --- /dev/null +++ b/packages/shadcn-ui/src/executors/add/compat.ts @@ -0,0 +1,5 @@ +import { convertNxExecutor } from '@nx/devkit' + +import { addExecutor } from './add.impl' + +export default convertNxExecutor(addExecutor) diff --git a/packages/shadcn-ui/src/executors/add/schema.json b/packages/shadcn-ui/src/executors/add/schema.json new file mode 100644 index 00000000..7d0f93ca --- /dev/null +++ b/packages/shadcn-ui/src/executors/add/schema.json @@ -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" + ] +} diff --git a/packages/shadcn-ui/src/generators/init/files-utils/index.ts.template b/packages/shadcn-ui/src/generators/init/files-utils/index.ts.template new file mode 100644 index 00000000..c5c1882c --- /dev/null +++ b/packages/shadcn-ui/src/generators/init/files-utils/index.ts.template @@ -0,0 +1 @@ +export * from './cn' diff --git a/packages/shadcn-ui/src/generators/init/init.impl.ts b/packages/shadcn-ui/src/generators/init/init.impl.ts index 9e840cf9..e48c518e 100644 --- a/packages/shadcn-ui/src/generators/init/init.impl.ts +++ b/packages/shadcn-ui/src/generators/init/init.impl.ts @@ -2,9 +2,9 @@ import { addDependenciesToPackageJson, generateFiles, getWorkspaceLayout, - joinPathFragments, + joinPathFragments, readProjectConfiguration, runTasksInSerial, - Tree, writeJson + Tree, updateProjectConfiguration, writeJson } from '@nx/devkit' import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils' import { addTsConfigPath, libraryGenerator } from '@nx/js' @@ -16,6 +16,7 @@ import { devDependencies } from '../../../package.json' function cleanupLib(tree: Tree, libDirectory: string) { // Remove the unneeded files + tree.delete(`${libDirectory}/package.json`) tree.delete(`${libDirectory}/src/index.ts`) const libFiles = tree.children(`${libDirectory}/src/lib`) @@ -86,6 +87,15 @@ export default async function (tree: Tree, options: ShadecnUiSchema) { } }) + updateProjectConfiguration(tree, uiLibOptions.projectName, { + ...readProjectConfiguration(tree, uiLibOptions.projectName), + targets: { + add: { + executor: '@nx-extend/shadcn-ui:add' + } + } + }) + return runTasksInSerial( addDependenciesToPackageJson( tree,