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 23, 2024
1 parent c64ca36 commit 333dff1
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 13 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"],
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
},
"homepage": "https://github.com/primer/primitives#readme",
"scripts": {
"build": "npm run clean && npm run build:tokens && npm run build:fallbacks && npm run build:figma",
"build": "npm run clean && npm run build:tokens && npm run build:fallbacks && npm run build:figma && npm run build:config",
"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()
8 changes: 4 additions & 4 deletions src/formats/typescriptExportDefinition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('Format: TypeScript definitions', () => {
* @description a css border string
* @format color | style | width
*/
type Border = \`\${ColorHex} \${string} \${string}\`;
type Border = \`\${string} \${string} \${string}\`;
export type tokens = {
test: {
Expand All @@ -129,15 +129,15 @@ describe('Format: TypeScript definitions', () => {
const input = getMockFormatterArguments({dictionary})
const expectedOutput = await format(
`/**
* @description hex string (6 or 8-digit)
*/
* @description hex string (6 or 8-digit)
*/
type ColorHex = string;
/**
* @description a css border string
* @format color | style | width
*/
type Border = \`\${ColorHex} \${string} \${string}\`;
type Border = \`\${string} \${string} \${string}\`;
export type tokens = {
tokens: {
Expand Down
3 changes: 1 addition & 2 deletions src/formats/typescriptExportDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ const getTokenObjectWithTypes = (tokens: DesignTokens, options: Config & LocalOp
const getTypeDefinition = (tokens: DesignTokens, options: Config & LocalOptions): string => {
// extract options
const {moduleName = `tokens`, tokenTypesPath = `./src/types/`} = options

const usedTypes = getUsedTokenTypes(tokens, ['ColorHex', 'Shadow', 'Border', 'SizeEm', 'SizeRem', 'SizePx'], options)
const usedTypes = getUsedTokenTypes(tokens, ['Shadow', 'ColorHex', 'Border', 'SizeEm', 'SizeRem', 'SizePx'], options)
const tokenObjectWithTypes = getTokenObjectWithTypes(tokens, options)
// get token type declaration from file
const designTokenTypes: string[] = []
Expand Down
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: 1 addition & 1 deletion src/types/Border.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
* @description a css border string
* @format color | style | width
*/
type Border = `${ColorHex} ${string} ${string}`
type Border = `${string} ${string} ${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 333dff1

Please sign in to comment.