Skip to content

Commit c6a8dc5

Browse files
Add src to dist (#1064)
* copy src to dist for primer/brand ot use * use tsc and copy type files
1 parent 0bd6f45 commit c6a8dc5

File tree

10 files changed

+58
-15
lines changed

10 files changed

+58
-15
lines changed

.changeset/sweet-apes-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/primitives': minor
3+
---
4+
5+
Adds src to dist as "build" so that primer/brand can use it

build.tsconfig.jsonc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"compilerOptions": {
3+
"jsx": "react",
4+
"target": "ES2016",
5+
"module": "preserve",
6+
"lib": ["ESNext", "dom"],
7+
"moduleResolution": "Bundler",
8+
"esModuleInterop": true,
9+
"strict": true,
10+
"noImplicitAny": true,
11+
"skipLibCheck": false,
12+
"typeRoots": ["./src/@types", "./node_modules/", "./node_modules/@types", "types"],
13+
"types": ["vitest/globals"],
14+
"rootDir": "./src",
15+
"outDir": "./dist/build",
16+
"declaration": true,
17+
"resolveJsonModule": true,
18+
"baseUrl": ".",
19+
"paths": {
20+
"~/*": ["*"],
21+
// workaround for: https://github.com/vitest-dev/vitest/issues/4567
22+
"rollup/parseAst": ["./node_modules/rollup/dist/parseAst"],
23+
},
24+
},
25+
"include": ["src/**/*.ts"],
26+
"exclude": ["**/*.test.ts", "src/test-utilities/*.ts", "vitest.config.ts"],
27+
}

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
},
2424
"homepage": "https://github.com/primer/primitives#readme",
2525
"scripts": {
26-
"build": "npm run clean && npm run build:tokens && npm run build:fallbacks && npm run build:figma",
26+
"build": "npm run clean && npm run build:tokens && npm run build:fallbacks && npm run build:figma && npm run build:config",
2727
"build:tokens": "tsx ./scripts/buildTokens.ts",
2828
"build:fallbacks": "tsx ./scripts/buildFallbacks.ts",
2929
"build:figma": "tsx scripts/buildFigma.ts",
30+
"build:config": "tsc -p build.tsconfig.jsonc && tsx ./scripts/copyDir.ts src/types dist/build/types",
3031
"clean": "rm -rf dist",
3132
"tokenJson:check": "tsx scripts/diffThemes.ts && tsx scripts/diffTokenProps.ts",
3233
"contrast:check": "tsx scripts/color-contrast.ts",

scripts/copyDir.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {copyFromDir} from '~/src/utilities/copyFromDir.js'
2+
3+
const copyDir = async () => {
4+
const [from, to] = process.argv.slice(2, 4)
5+
const files = await copyFromDir(from, to)
6+
// eslint-disable-next-line no-console
7+
console.log(`\u001b[36;1m\u001b[1m${files.length} files copied from ${from} to ${to}\u001b[0m`)
8+
}
9+
10+
await copyDir()

src/formats/typescriptExportDefinition.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('Format: TypeScript definitions', () => {
104104
* @description a css border string
105105
* @format color | style | width
106106
*/
107-
type Border = \`\${ColorHex} \${string} \${string}\`;
107+
type Border = \`\${string} \${string} \${string}\`;
108108
109109
export type tokens = {
110110
test: {
@@ -129,15 +129,15 @@ describe('Format: TypeScript definitions', () => {
129129
const input = getMockFormatterArguments({dictionary})
130130
const expectedOutput = await format(
131131
`/**
132-
* @description hex string (6 or 8-digit)
133-
*/
132+
* @description hex string (6 or 8-digit)
133+
*/
134134
type ColorHex = string;
135135
136136
/**
137137
* @description a css border string
138138
* @format color | style | width
139139
*/
140-
type Border = \`\${ColorHex} \${string} \${string}\`;
140+
type Border = \`\${string} \${string} \${string}\`;
141141
142142
export type tokens = {
143143
tokens: {

src/formats/typescriptExportDefinition.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ const getTokenObjectWithTypes = (tokens: DesignTokens, options: Config & LocalOp
137137
const getTypeDefinition = (tokens: DesignTokens, options: Config & LocalOptions): string => {
138138
// extract options
139139
const {moduleName = `tokens`, tokenTypesPath = `./src/types/`} = options
140-
141-
const usedTypes = getUsedTokenTypes(tokens, ['ColorHex', 'Shadow', 'Border', 'SizeEm', 'SizeRem', 'SizePx'], options)
140+
const usedTypes = getUsedTokenTypes(tokens, ['Shadow', 'ColorHex', 'Border', 'SizeEm', 'SizeRem', 'SizePx'], options)
142141
const tokenObjectWithTypes = getTokenObjectWithTypes(tokens, options)
143142
// get token type declaration from file
144143
const designTokenTypes: string[] = []

src/transformers/fontFamilyToCss.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {PlatformConfig, Transform, TransformedToken} from 'style-dictionary/types'
1+
import type {Transform, TransformedToken} from 'style-dictionary/types'
22
import {isFontFamily} from '../filters/index.js'
33
import {getTokenValue} from './utilities/getTokenValue.js'
44
import {hasSpaceInString} from './utilities/hasSpaceInString.js'
@@ -34,6 +34,5 @@ export const fontFamilyToCss: Transform = {
3434
type: 'value',
3535
transitive: true,
3636
filter: isFontFamily,
37-
transform: (token: TransformedToken, config: PlatformConfig): string =>
38-
parseFontFamily(getTokenValue(token, undefined, config)),
37+
transform: (token: TransformedToken): string => parseFontFamily(getTokenValue(token)),
3938
}

src/types/Border.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
* @description a css border string
33
* @format color | style | width
44
*/
5-
type Border = `${ColorHex} ${string} ${string}`
5+
type Border = `${string} ${string} ${string}`

src/utilities/copyFromDir.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ import {copyFile, readdir, mkdir} from 'fs/promises'
55
* @description Copies all files from source folder to destination
66
* @param source path
77
* @param destination path
8-
* @returns promise
8+
* @returns promise of file name array
99
*/
10-
export const copyFromDir = async (source: string, destination: string) => {
10+
export const copyFromDir = async (source: string, destination: string): Promise<string[]> => {
1111
// adjust trailing slash
1212
const src = `${source.replace(/\/$/, '')}`
1313
const dest = `${destination.replace(/\/$/, '')}`
1414
// create dest if it does not exists
1515
await mkdir(dest, {recursive: true})
16+
1617
// read files from source
1718
const files = await readdir(src)
1819
for (const file of files) {
1920
copyFile(`${src}/${file}`, `${dest}/${file}`)
2021
}
22+
23+
return files
2124
}

0 commit comments

Comments
 (0)