import { execSync } from 'node:child_process' import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { basename, extname, join } from 'node:path' // Vendors shadcn-vue's own component examples into playground/examples, so the // playground demos every variant without us writing (or maintaining) them. // Like src/ui, playground/examples is generated: never edit it by hand. const REPO = 'https://github.com/unovue/shadcn-vue.git' const BASE = 'apps/v4/registry/bases/reka' const root = join(import.meta.dirname, '..') const out = join(root, 'playground', 'examples') const checkout = join(tmpdir(), 'chassis-ui-upstream') const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) const installed = new Set([ ...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.peerDependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {}), ]) function fetchUpstream(): string { rmSync(checkout, { recursive: true, force: true }) execSync(`git clone -q --depth 1 --filter=blob:none --sparse ${REPO} "${checkout}"`, { stdio: 'inherit' }) execSync(`git -C "${checkout}" sparse-checkout set ${BASE}/examples ${BASE}/components/example`, { stdio: 'inherit' }) return execSync(`git -C "${checkout}" rev-parse --short HEAD`).toString().trim() } function rewrite(source: string): string { return source .replace(/(['"])@\/registry\/bases\/reka\/ui\/([\w-]+)\1/g, '$1chassis-ui/$2$1') .replace(/(['"])@\/components\/ui\/([\w-]+)\1/g, '$1chassis-ui/$2$1') .replace(/(['"])[~@]\/registry\/bases\/reka\/components\/example\1/g, '$1@playground/examples/_shared/example$1') .replace(/(['"])@\/components\/IconPlaceholder\.vue\1/g, '$1@playground/components/IconPlaceholder.vue$1') .replace(/(['"])[~@]\/registry\/bases\/reka\/examples\//g, '$1@playground/examples/') } function importsOf(source: string): string[] { // Real import statements only: skip the template and code samples held in template strings const code = source.replace(/