Skip to content

Commit

Permalink
give write perms
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshay committed Aug 2, 2023
1 parent 34cf1a8 commit 6ecd6fa
Show file tree
Hide file tree
Showing 6 changed files with 3,141 additions and 5,938 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
name: Release
url: ${{ steps.deployment.outputs.page_url }}
permissions:
contents: read
contents: write
pages: write
id-token: write
steps:
Expand Down
23 changes: 11 additions & 12 deletions packages/ui/.scripts/bump-version.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
#!/usr/bin/env node

import { execSync } from "node:child_process"
import { writeFile } from "node:fs/promises"
import { argv } from "node:process"
import { inc, parse } from "semver"

import packageJson from "../package.json" assert { type: "json" }

const run = async () => {
const oldVersion = packageJson.version
const version = parse(packageJson.version)
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const newVersion = inc(version, argv[2] ?? "patch")
const oldVersion = packageJson.version
const version = parse(packageJson.version)
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const newVersion = inc(version, argv[2] ?? "patch")

packageJson.version = newVersion
packageJson.version = newVersion

// eslint-disable-next-line no-console
console.log(`Bumping version from ${oldVersion} to ${newVersion}`)
// eslint-disable-next-line no-console
console.log(`Bumping version from ${oldVersion} to ${newVersion}`)

// eslint-disable-next-line @typescript-eslint/no-magic-numbers
await writeFile("./package.json", JSON.stringify(packageJson, undefined, 2))
}
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
await writeFile("./package.json", JSON.stringify(packageJson, undefined, 2))

void run()
execSync(`git tag v${newVersion}`)
37 changes: 16 additions & 21 deletions packages/ui/.scripts/clear-package-json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@ import { env } from "node:process"

import packageJson from "../package.json" assert { type: "json" }

// eslint-disable-next-line max-statements
const run = async () => {
if (!env.SKIP_UPDATE) {
packageJson.dependencies = undefined
packageJson.typesVersions = undefined
packageJson.exports = undefined
}

packageJson.peerDependencies = undefined
packageJson.peerDependenciesMeta = undefined
packageJson.devDependencies.tailwindcss = undefined
packageJson.devDependencies["@radix-ui/react-icons"] = undefined
packageJson.devDependencies["lucide-react"] = undefined
packageJson.devDependencies.react = undefined
packageJson.devDependencies["react-dom"] = undefined
packageJson.devDependencies["@types/react"] = undefined
packageJson.devDependencies["@types/react-dom"] = undefined

// eslint-disable-next-line @typescript-eslint/no-magic-numbers
await writeFile("./package.json", JSON.stringify(packageJson, undefined, 2))
if (!env.SKIP_UPDATE) {
packageJson.dependencies = undefined
packageJson.typesVersions = undefined
packageJson.exports = undefined
}

void run()
packageJson.peerDependencies = undefined
packageJson.peerDependenciesMeta = undefined
packageJson.devDependencies.tailwindcss = undefined
packageJson.devDependencies["@radix-ui/react-icons"] = undefined
packageJson.devDependencies["lucide-react"] = undefined
packageJson.devDependencies.react = undefined
packageJson.devDependencies["react-dom"] = undefined
packageJson.devDependencies["@types/react"] = undefined
packageJson.devDependencies["@types/react-dom"] = undefined

// eslint-disable-next-line @typescript-eslint/no-magic-numbers
await writeFile("./package.json", JSON.stringify(packageJson, undefined, 2))
103 changes: 49 additions & 54 deletions packages/ui/.scripts/update-components.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
/* eslint-disable max-statements */
import { globby } from "globby"
import { mkdir, readFile, rm, writeFile } from "node:fs/promises"
import { resolve } from "node:path"
Expand All @@ -10,64 +9,63 @@ import { createComponentsConfig } from "./lib/utils.mjs"

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

const main = async () => {
// Remove the old components
await rm(INSTALL_DIR, {
force: true,
recursive: true,
})
// Remove the old components
await rm(INSTALL_DIR, {
force: true,
recursive: true,
})

await mkdir("./src-gen/lib", {
force: true,
recursive: true,
})
await mkdir("./src-gen/lib", {
force: true,
recursive: true,
})

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

await writeFile(
"./src-gen/lib/styles.ts",
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
`export const styles = ${JSON.stringify(styles, undefined, 2)};`,
)
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) {
// eslint-disable-next-line no-await-in-loop
await createComponentsConfig(name)
// eslint-disable-next-line fp/no-loops
for (const { name } of styles) {
// eslint-disable-next-line no-await-in-loop
await createComponentsConfig(name)

// 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(" ")}`,
)
}
// 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(" ")}`,
)
}

const initialPaths = await globby("./src-gen/**/*.{tsx,ts}")
const initialPaths = await globby("./src-gen/**/*.{tsx,ts}")

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")
await Promise.all(
initialPaths
.filter((path) => path.includes("components") && path.includes("ui"))
.map(async (path) => {

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

View workflow job for this annotation

GitHub Actions / verify

Prefer an early return to a conditionally-wrapped function body

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

View workflow job for this annotation

GitHub Actions / verify / verify

Prefer an early return to a conditionally-wrapped function body
if (path.includes("components") && path.includes("ui")) {
const contentsBuffer = await readFile(path)

Check warning on line 52 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 52 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / verify / verify

Found readFile from package "node:fs/promises" with non literal argument at index 0
const contents = contentsBuffer.toString("utf8")

// 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 56 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 56 in packages/ui/.scripts/update-components.mjs

View workflow job for this annotation

GitHub Actions / verify / verify

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}`,
)
}
}),
)

await writeFile(
`./src-gen/lib/utils.ts`,
`import { ClassValue, clsx } from "clsx";
await writeFile(
`./src-gen/lib/utils.ts`,
`import { ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
Expand All @@ -76,7 +74,4 @@ export function cn(...inputs: ClassValue[]) {
export const CONTENT = "./node_modules/@lshay/ui/dist/cjs/components/**/*.js" as const;
`,
)
}

void main()
)
124 changes: 60 additions & 64 deletions packages/ui/.scripts/update-package-json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,70 @@ import { writeFile } from "node:fs/promises"

import packageJson from "../package.json" assert { type: "json" }

const run = async () => {
const paths = await globby("./dist/cjs/**/*.js")
const paths = await globby("./dist/cjs/**/*.js")

packageJson.exports = Object.fromEntries(
paths
.filter((path) => !path.includes("chunk-"))
.map((path) => {
const withoutDistribution = path.replace("./dist/cjs/", "")
const withoutDistributionAndExtension = withoutDistribution.replace(
/\.js$/u,
"",
)
const cjsPath = path
const esmPath = `./dist/esm/${withoutDistributionAndExtension}.mjs`
const typesPath = `./dist/types/${withoutDistributionAndExtension}.d.ts`
packageJson.exports = Object.fromEntries(
paths
.filter((path) => !path.includes("chunk-"))
.map((path) => {
const withoutDistribution = path.replace("./dist/cjs/", "")
const withoutDistributionAndExtension = withoutDistribution.replace(
/\.js$/u,
"",
)
const cjsPath = path
const esmPath = `./dist/esm/${withoutDistributionAndExtension}.mjs`
const typesPath = `./dist/types/${withoutDistributionAndExtension}.d.ts`

return [
`./${withoutDistributionAndExtension.replace("/ui/", "/")}`.replace(
"./index",
".",
),
{
import: esmPath,
require: cjsPath,
types: typesPath,
},
]
}),
)
return [
`./${withoutDistributionAndExtension.replace("/ui/", "/")}`.replace(
"./index",
".",
),
{
import: esmPath,
require: cjsPath,
types: typesPath,
},
]
}),
)

packageJson.typesVersions = {
"*": Object.fromEntries(
Object.entries(packageJson.exports).map(([key, value]) => [
key.replace("./", ""),
[value.types.replace("./", "")],
]),
),
}

packageJson.peerDependenciesMeta = {
"@radix-ui/react-icons": {
optional: true,
},
"lucide-react": {
optional: true,
},
react: {
optional: false,
},
"react-dom": {
optional: false,
},
tailwindcss: {
optional: false,
},
}
packageJson.typesVersions = {
"*": Object.fromEntries(
Object.entries(packageJson.exports).map(([key, value]) => [
key.replace("./", ""),
[value.types.replace("./", "")],
]),
),
}

/*
* PackageJson.main = "./dist/index.js";
* packageJson.types = "./dist/index.d.ts";
*/
packageJson.peerDependenciesMeta = {
"@radix-ui/react-icons": {
optional: true,
},
"lucide-react": {
optional: true,
},
react: {
optional: false,
},
"react-dom": {
optional: false,
},
tailwindcss: {
optional: false,
},
}

packageJson.main = undefined
packageJson.module = undefined
packageJson.types = undefined
/*
* PackageJson.main = "./dist/index.js";
* packageJson.types = "./dist/index.d.ts";
*/

// eslint-disable-next-line @typescript-eslint/no-magic-numbers
await writeFile("./package.json", JSON.stringify(packageJson, undefined, 2))
}
packageJson.main = undefined
packageJson.module = undefined
packageJson.types = undefined

void run()
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
await writeFile("./package.json", JSON.stringify(packageJson, undefined, 2))
Loading

0 comments on commit 6ecd6fa

Please sign in to comment.