Skip to content

Commit

Permalink
use tsc and copy type files
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Sep 20, 2024
1 parent 79a5ea3 commit fd07194
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-apes-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/primitives': minor
---

Adds src to dist as "build" so that primer/brand can use it
2 changes: 1 addition & 1 deletion build.tsconfig.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
},
},
"include": ["src/**/*.ts"],
"exclude": ["./src/@types", "**/*.test.ts", "src/test-utilities/*.ts", "vitest.config.ts"],
"exclude": ["**/*.test.ts", "src/test-utilities/*.ts", "vitest.config.ts"],
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"build:tokens": "tsx ./scripts/buildTokens.ts",
"build:fallbacks": "tsx ./scripts/buildFallbacks.ts",
"build:figma": "tsx scripts/buildFigma.ts",
"build:config": "tsc -p build.tsconfig.jsonc",
"build:config": "tsc -p build.tsconfig.jsonc && tsx ./scripts/copyDir.ts src/types dist/build/types",
"clean": "rm -rf dist",
"tokenJson:check": "tsx scripts/diffThemes.ts && tsx scripts/diffTokenProps.ts",
"contrast:check": "tsx scripts/color-contrast.ts",
Expand Down
10 changes: 10 additions & 0 deletions scripts/copyDir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {copyFromDir} from '~/src/utilities/copyFromDir.js'

const copyDir = async () => {
const [from, to] = process.argv.slice(2, 4)
const files = await copyFromDir(from, to)
// eslint-disable-next-line no-console
console.log(`\u001b[36;1m\u001b[1m${files.length} files copied from ${from} to ${to}\u001b[0m`)
}

await copyDir()
2 changes: 1 addition & 1 deletion src/transformers/fontFamilyToCss.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {PlatformConfig, Transform, TransformedToken} from 'style-dictionary/types'
import type {Transform, TransformedToken} from 'style-dictionary/types'
import {isFontFamily} from '../filters/index.js'
import {getTokenValue} from './utilities/getTokenValue.js'
import {hasSpaceInString} from './utilities/hasSpaceInString.js'
Expand Down
2 changes: 2 additions & 0 deletions src/types/Border.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line import/extensions
import type {ColorHex} from './ColorHex.d.ts'
/**
* @description a css border string
* @format color | style | width
Expand Down
2 changes: 1 addition & 1 deletion src/types/ColorHex.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* @description hex string (6 or 8-digit)
*/
type ColorHex = string
export type ColorHex = string
7 changes: 5 additions & 2 deletions src/utilities/copyFromDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ import {copyFile, readdir, mkdir} from 'fs/promises'
* @description Copies all files from source folder to destination
* @param source path
* @param destination path
* @returns promise
* @returns promise of file name array
*/
export const copyFromDir = async (source: string, destination: string) => {
export const copyFromDir = async (source: string, destination: string): Promise<string[]> => {
// adjust trailing slash
const src = `${source.replace(/\/$/, '')}`
const dest = `${destination.replace(/\/$/, '')}`
// create dest if it does not exists
await mkdir(dest, {recursive: true})

// read files from source
const files = await readdir(src)
for (const file of files) {
copyFile(`${src}/${file}`, `${dest}/${file}`)
}

return files
}

0 comments on commit fd07194

Please sign in to comment.