Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add src to dist #1064

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 27 additions & 0 deletions build.tsconfig.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"jsx": "react",
"target": "ES2016",
"module": "preserve",
"lib": ["ESNext", "dom"],
"moduleResolution": "Bundler",
"esModuleInterop": true,
"strict": true,
"noImplicitAny": true,
"skipLibCheck": false,
"typeRoots": ["./src/@types", "./node_modules/", "./node_modules/@types", "types"],
"types": ["vitest/globals"],
"rootDir": "./src",
"outDir": "./dist/build",
"declaration": true,
"resolveJsonModule": true,
"baseUrl": ".",
"paths": {
"~/*": ["*"],
// workaround for: https://github.com/vitest-dev/vitest/issues/4567
"rollup/parseAst": ["./node_modules/rollup/dist/parseAst"],
},
},
"include": ["src/**/*.ts"],
"exclude": ["**/*.test.ts", "src/test-utilities/*.ts", "vitest.config.ts"],
}
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +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 && 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
5 changes: 2 additions & 3 deletions 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 Expand Up @@ -34,6 +34,5 @@ export const fontFamilyToCss: Transform = {
type: 'value',
transitive: true,
filter: isFontFamily,
transform: (token: TransformedToken, config: PlatformConfig): string =>
parseFontFamily(getTokenValue(token, undefined, config)),
transform: (token: TransformedToken): string => parseFontFamily(getTokenValue(token)),
}
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
}