Comparing version 0.0.0-beta.7d85013 to 0.0.0-beta.9a5085d
#!/usr/bin/env node | ||
// src/index.ts | ||
import { existsSync, promises as fs3 } from "fs"; | ||
import { existsSync as existsSync2, promises as fs3 } from "fs"; | ||
import path3 from "path"; | ||
@@ -64,6 +64,28 @@ import { Command } from "commander"; | ||
// src/utils/get-project-info.ts | ||
import { existsSync } from "fs"; | ||
import path2 from "path"; | ||
import fs2 from "fs-extra"; | ||
async function getProjectInfo() { | ||
const info = { | ||
tsconfig: null, | ||
alias: null, | ||
srcDir: false, | ||
appDir: false | ||
}; | ||
try { | ||
const tsconfig = await getTsConfig(); | ||
const paths = tsconfig?.compilerOptions?.paths; | ||
const alias = paths ? Object.keys(paths)[0].replace("*", "") : null; | ||
return { | ||
tsconfig, | ||
alias, | ||
srcDir: existsSync(path2.resolve("./src")), | ||
appDir: existsSync(path2.resolve("./app")) || existsSync(path2.resolve("./src/app")) | ||
}; | ||
} catch (error) { | ||
return info; | ||
} | ||
} | ||
async function getTsConfig() { | ||
try { | ||
const tsconfigPath = path2.join("tsconfig.json"); | ||
@@ -74,10 +96,3 @@ const tsconfig = await fs2.readJSON(tsconfigPath); | ||
} | ||
const paths = tsconfig.compilerOptions?.paths; | ||
if (!paths) { | ||
throw new Error("tsconfig.json is missing paths"); | ||
} | ||
const alias = Object.keys(paths)[0].replace("*", ""); | ||
return { | ||
alias | ||
}; | ||
return tsconfig; | ||
} catch (error) { | ||
@@ -105,8 +120,181 @@ return null; | ||
// src/utils/templates.ts | ||
var STYLES = `@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
@layer base { | ||
:root { | ||
--background: 0 0% 100%; | ||
--foreground: 222.2 47.4% 11.2%; | ||
--muted: 210 40% 96.1%; | ||
--muted-foreground: 215.4 16.3% 46.9%; | ||
--popover: 0 0% 100%; | ||
--popover-foreground: 222.2 47.4% 11.2%; | ||
--card: 0 0% 100%; | ||
--card-foreground: 222.2 47.4% 11.2%; | ||
--border: 214.3 31.8% 91.4%; | ||
--input: 214.3 31.8% 91.4%; | ||
--primary: 222.2 47.4% 11.2%; | ||
--primary-foreground: 210 40% 98%; | ||
--secondary: 210 40% 96.1%; | ||
--secondary-foreground: 222.2 47.4% 11.2%; | ||
--accent: 210 40% 96.1%; | ||
--accent-foreground: 222.2 47.4% 11.2%; | ||
--destructive: 0 100% 50%; | ||
--destructive-foreground: 210 40% 98%; | ||
--ring: 215 20.2% 65.1%; | ||
--radius: 0.5rem; | ||
} | ||
.dark { | ||
--background: 224 71% 4%; | ||
--foreground: 213 31% 91%; | ||
--muted: 223 47% 11%; | ||
--muted-foreground: 215.4 16.3% 56.9%; | ||
--popover: 224 71% 4%; | ||
--popover-foreground: 215 20.2% 65.1%; | ||
--card: 0 0% 100%; | ||
--card-foreground: 222.2 47.4% 11.2%; | ||
--border: 216 34% 17%; | ||
--input: 216 34% 17%; | ||
--primary: 210 40% 98%; | ||
--primary-foreground: 222.2 47.4% 1.2%; | ||
--secondary: 222.2 47.4% 11.2%; | ||
--secondary-foreground: 210 40% 98%; | ||
--accent: 216 34% 17%; | ||
--accent-foreground: 210 40% 98%; | ||
--destructive: 0 63% 31%; | ||
--destructive-foreground: 210 40% 98%; | ||
--ring: 216 34% 17%; | ||
--radius: 0.5rem; | ||
} | ||
} | ||
@layer base { | ||
* { | ||
@apply border-border; | ||
} | ||
body { | ||
@apply bg-background text-foreground; | ||
font-feature-settings: "rlig" 1, "calt" 1; | ||
} | ||
}`; | ||
var UTILS = `import { ClassValue, clsx } from "clsx" | ||
import { twMerge } from "tailwind-merge" | ||
export function cn(...inputs: ClassValue[]) { | ||
return twMerge(clsx(inputs)) | ||
} | ||
`; | ||
var TAILWIND_CONFIG = `/** @type {import('tailwindcss').Config} */ | ||
module.exports = { | ||
darkMode: ["class"], | ||
content: [ | ||
'./pages/**/*.{ts,tsx}', | ||
'./components/**/*.{ts,tsx}', | ||
'./app/**/*.{ts,tsx}', | ||
], | ||
theme: { | ||
container: { | ||
center: true, | ||
padding: "2rem", | ||
screens: { | ||
"2xl": "1400px", | ||
}, | ||
}, | ||
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: [require("tailwindcss-animate")], | ||
}`; | ||
// src/index.ts | ||
process.on("SIGINT", () => process.exit(0)); | ||
process.on("SIGTERM", () => process.exit(0)); | ||
var PROJECT_DEPENDENCIES = [ | ||
"tailwindcss-animate", | ||
"class-variance-authority", | ||
"clsx", | ||
"tailwind-merge", | ||
"lucide-react" | ||
]; | ||
async function main() { | ||
const packageInfo = await getPackageInfo(); | ||
const projectInfo = await getProjectInfo(); | ||
const packageManager = getPackageManager(); | ||
const program = new Command().name("shadcn-ui").description("Add shadcn-ui components to your project").version( | ||
@@ -117,2 +305,60 @@ packageInfo.version || "1.0.0", | ||
); | ||
program.command("init").description("Configure your Next.js project.").option("-y, --yes", "Skip confirmation prompt.").action(async (options) => { | ||
logger.warn( | ||
"Running the following command will overwrite existing files." | ||
); | ||
logger.warn( | ||
"Make sure you have committed your changes before proceeding." | ||
); | ||
logger.warn(""); | ||
logger.warn( | ||
"This command assumes a Next.js project with TypeScript and Tailwind CSS." | ||
); | ||
logger.warn( | ||
"If you don't have these, follow the manual steps at https://ui.shadcn.com/docs/installation." | ||
); | ||
logger.warn(""); | ||
if (!options.yes) { | ||
const { proceed } = await prompts({ | ||
type: "confirm", | ||
name: "proceed", | ||
message: "Running this command will install dependencies and overwrite files. Proceed?", | ||
initial: true | ||
}); | ||
if (!proceed) { | ||
process.exit(0); | ||
} | ||
} | ||
const dependenciesSpinner = ora(`Installing dependencies...`).start(); | ||
await execa(packageManager, [ | ||
packageManager === "npm" ? "install" : "add", | ||
...PROJECT_DEPENDENCIES | ||
]); | ||
dependenciesSpinner.succeed(); | ||
if (!projectInfo?.appDir) { | ||
const stylesDir = projectInfo?.srcDir ? "./src/styles" : "./styles"; | ||
if (!existsSync2(path3.resolve(stylesDir))) { | ||
await fs3.mkdir(path3.resolve(stylesDir), { recursive: true }); | ||
} | ||
} | ||
let stylesDestination = projectInfo?.srcDir ? "./src/styles/globals.css" : "./styles/globals.css"; | ||
if (projectInfo?.appDir) { | ||
stylesDestination = projectInfo?.srcDir ? "./src/app/globals.css" : "./app/globals.css"; | ||
} | ||
const stylesSpinner = ora(`Adding styles with CSS variables...`).start(); | ||
await fs3.writeFile(stylesDestination, STYLES, "utf8"); | ||
stylesSpinner.succeed(); | ||
const libDir = projectInfo?.srcDir ? "./src/lib" : "./lib"; | ||
if (!existsSync2(path3.resolve(libDir))) { | ||
await fs3.mkdir(path3.resolve(libDir), { recursive: true }); | ||
} | ||
const utilsDestination = projectInfo?.srcDir ? "./src/lib/utils.ts" : "./lib/utils.ts"; | ||
const utilsSpinner = ora(`Adding utils...`).start(); | ||
await fs3.writeFile(utilsDestination, UTILS, "utf8"); | ||
utilsSpinner.succeed(); | ||
const tailwindDestination = "./tailwind.config.js"; | ||
const tailwindSpinner = ora(`Updating tailwind.config.js...`).start(); | ||
await fs3.writeFile(tailwindDestination, TAILWIND_CONFIG, "utf8"); | ||
tailwindSpinner.succeed(); | ||
}); | ||
program.command("add").description("add components to your project").argument("[components...]", "name of components").action(async (components) => { | ||
@@ -145,3 +391,3 @@ logger.warn( | ||
const destinationDir = path3.resolve(dir); | ||
if (!existsSync(destinationDir)) { | ||
if (!existsSync2(destinationDir)) { | ||
const spinner = ora(`Creating ${dir}...`).start(); | ||
@@ -151,3 +397,2 @@ await fs3.mkdir(destinationDir, { recursive: true }); | ||
} | ||
const packageManager = getPackageManager(); | ||
logger.success( | ||
@@ -154,0 +399,0 @@ `Installing ${selectedComponents.length} component(s) and dependencies...` |
{ | ||
"name": "shadcn-ui", | ||
"version": "0.0.0-beta.7d85013", | ||
"version": "0.0.0-beta.9a5085d", | ||
"description": "Add components to your apps.", | ||
@@ -18,2 +18,5 @@ "publishConfig": { | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
@@ -37,3 +40,2 @@ "components", | ||
"prompts": "^2.4.2", | ||
"react-day-picker": "^8.6.0", | ||
"zod": "^3.20.2" | ||
@@ -40,0 +42,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36693
8
6
410
6
2
2
- Removedreact-day-picker@^8.6.0
- Removeddate-fns@3.6.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)
- Removedreact@18.3.1(transitive)
- Removedreact-day-picker@8.10.1(transitive)