Skip to content

Commit

Permalink
updated scripts to use submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshay committed Jan 17, 2024
1 parent 88fe751 commit 96e249c
Show file tree
Hide file tree
Showing 10 changed files with 7,039 additions and 3,799 deletions.
5 changes: 2 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[submodule "apps/www/ui"]
path = apps/www/ui
[submodule "ui"]
path = ui
url = [email protected]:shadcn-ui/ui.git
shallow = true
4 changes: 3 additions & 1 deletion apps/www/.scripts/gen-default-demos.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { format } from "prettier"

import prettierConfig from "../.prettierrc.cjs"

const demoFiles = await globby("./ui/apps/www/content/docs/components/*.mdx")
const demoFiles = await globby(
"../../ui/apps/www/content/docs/components/*.mdx",
)

const demosContent = await Promise.all(
demoFiles.map(async (demoFile) => {
Expand Down
1 change: 0 additions & 1 deletion apps/www/ui
Submodule ui deleted from 6b523b
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@lshay/ui-root",
"scripts": {
"format": "prettier --write --check . '!packages/**' '!apps/**' && turbo run format",
"format": "prettier --write --check . '!packages/**' '!apps/**' '!ui/**' && turbo run format",
"lint": "turbo run lint",
"lint:fix": "turbo run lint:fix",
"build": "turbo run build",
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/.scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ pnpm add --save-peer @radix-ui/react-icons@latest lucide-react@latest react@^18.
pnpm add --save-dev @types/react @types/react-dom

if [[ -z "${SKIP_UPDATE}" ]]; then
rm -rf src-gen
./.scripts/update-components.mjs
rm -rf src-gen
./.scripts/update-components.mjs
else
echo "__SCRIPTS__: Skipping update"
echo "__SCRIPTS__: Skipping update"
fi

pnpm tsup-node ./src-gen/**/* --target es2020 --format esm --clean --tsconfig tsconfig.json --out-dir ./dist/esm --minify --treeshake recommended
Expand Down
56 changes: 33 additions & 23 deletions packages/ui/.scripts/update-components.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env node
import { globby } from "globby"
import { mkdir, readFile, rm, writeFile } from "node:fs/promises"
import { execSync } from "node:child_process"
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises"
import { resolve } from "node:path"

import { execAsync } from "./lib/node.mjs"
import shadcnPackageJson from "../../../ui/apps/www/package.json" assert { type: "json" }
import { fetchComponents, fetchStyles } from "./lib/registry.mjs"
import { createComponentsConfig } from "./lib/utils.mjs"

const INSTALL_DIR = resolve("src-gen", "components")

Expand All @@ -20,25 +20,34 @@ await mkdir("./src-gen/lib", {
recursive: true,
})

const components = await fetchComponents()
const styles = await fetchStyles()
const components = await fetchComponents()

execSync(
`pnpm i ${components
.flatMap((comp) => comp.dependencies)
.map((dep) => `${dep}@${shadcnPackageJson.dependencies[dep] ?? "latest"}`)

Check warning on line 29 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / verify

Generic Object Injection Sink

Check warning on line 29 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / release

Generic Object Injection Sink
.join(" ")}`,
)

await writeFile(
"./src-gen/lib/styles.ts",
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
`export const styles = ${JSON.stringify(styles, undefined, 2)};`,
)

// eslint-disable-next-line fp/no-loops
for (const { name } of styles) {

Check failure on line 39 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / verify

Unallowed use of `for` loop

Check failure on line 39 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / release

Unallowed use of `for` loop
// eslint-disable-next-line no-await-in-loop
await createComponentsConfig(name)
await mkdir(`src-gen/components/${name}/ui`, {

Check failure on line 40 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / verify

Unexpected `await` inside a loop

Check warning on line 40 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / verify

Found mkdir from package "node:fs/promises" with non literal argument at index 0

Check failure on line 40 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / release

Unexpected `await` inside a loop

Check warning on line 40 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / release

Found mkdir from package "node:fs/promises" with non literal argument at index 0
force: true,
recursive: true,
})

// eslint-disable-next-line no-await-in-loop
await execAsync(
`npx shadcn-ui@latest add --yes --overwrite --path ./src-gen/components/${name} ${components
.map((component) => component.name)
.join(" ")}`,
await cp(

Check failure on line 45 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / verify

Unexpected `await` inside a loop

Check failure on line 45 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / release

Unexpected `await` inside a loop
`../../ui/apps/www/registry/${name}/ui`,
`src-gen/components/${name}/ui`,
{
recursive: true,
},
)
}

Expand All @@ -48,18 +57,19 @@ await Promise.all(
initialPaths
.filter((path) => path.includes("components") && path.includes("ui"))
.map(async (path) => {
if (path.includes("components") && path.includes("ui")) {
const contentsBuffer = await readFile(path)
const contents = contentsBuffer.toString("utf8")
const contentsBuffer = await readFile(path)

Check warning on line 60 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / verify

Found readFile from package "node:fs/promises" with non literal argument at index 0

Check warning on line 60 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / release

Found readFile from package "node:fs/promises" with non literal argument at index 0
const contents = contentsBuffer
.toString("utf8")
// eslint-disable-next-line unicorn/prefer-string-replace-all
.replace(/@\/registry\/(default|new-york)\/ui/gu, ".")

Check failure on line 64 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / verify

Capture group '(default|new-york)' should be converted to a named or non-capturing group

Check failure on line 64 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / verify

Capturing group number 1 is defined but never used

Check failure on line 64 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / release

Capture group '(default|new-york)' should be converted to a named or non-capturing group

Check failure on line 64 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / release

Capturing group number 1 is defined but never used

// BUG: Add the React import if it's missing. This is a bug in ui.shadcn.com.
await writeFile(
path,
contents.includes('import * as React from "react"')
? contents
: `import * as React from "react";\n${contents}`,
)
}
// BUG: Add the React import if it's missing. This is a bug in ui.shadcn.com.
await writeFile(

Check warning on line 67 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / verify

Found writeFile from package "node:fs/promises" with non literal argument at index 0

Check warning on line 67 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / release

Found writeFile from package "node:fs/promises" with non literal argument at index 0
path,
contents.includes('import * as React from "react"')
? contents
: `import * as React from "react";\n${contents}`,
)
}),
)

Expand Down
Loading

0 comments on commit 96e249c

Please sign in to comment.