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

feat(tokens): compile ts files into js map on generate tokens script #162

Merged
merged 15 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ packages/react/src/components
packages/vue/src/components
packages/**/coverage
packages/**/components.d.ts
packages/tokens/src/tokens
packages/core/react
packages/core/vue
packages/core/core.css
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions packages/tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Tokens and variables for Atomium",
"access": "public",
"type": "module",
"main": "dist/index.d.ts",
RodrigoRVSN marked this conversation as resolved.
Show resolved Hide resolved
"main": "dist/src/tokens/index.js",
RodrigoRVSN marked this conversation as resolved.
Show resolved Hide resolved
"repository": {
"type": "git",
"url": "https://github.com/juntossomosmais/atomium.git",
Expand All @@ -16,11 +16,11 @@
},
"exports": {
"./*": "./dist/*",
".": "./dist/index.d.ts"
".": "./dist/src/tokens/index.js"
},
"scripts": {
"start": "rollup -c -w",
"build": "rollup -c && tsc && node dist/scripts/generate-tokens.js",
"build": "rollup -c && tsc && node dist/scripts/generate-tokens.js && tsc --outDir dist",
"publish-library": "npm publish --access public"
},
"files": [
Expand Down
13 changes: 9 additions & 4 deletions packages/tokens/scripts/generate-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { fileURLToPath } from 'url'

const CURRENT_DIR = path.dirname(fileURLToPath(import.meta.url))
tassioFront marked this conversation as resolved.
Show resolved Hide resolved
const TOKENS_DIR = path.resolve(CURRENT_DIR, '../tokens.css')
const OUTPUT_DIR = path.resolve(CURRENT_DIR, '../')
const OUTPUT_DIR = path.resolve(CURRENT_DIR, '../../src')
tassioFront marked this conversation as resolved.
Show resolved Hide resolved
const OUTPUT_TOKENS_DIR = `${OUTPUT_DIR}/tokens`

const prefixes = ['color', 'spacing', 'screen']
const exportStatements: Array<string> = []
Expand Down Expand Up @@ -47,18 +48,22 @@ function processCssFileByTokenPrefix(cssFilePath: string, prefix: string) {
const tokens = extractTokensFromCss(cssContent, prefix)

const outputFileName = `${prefix}.ts`
const outputFilePath = path.join(OUTPUT_DIR, outputFileName)
const outputFilePath = path.join(OUTPUT_TOKENS_DIR, outputFileName)

generateJavaScriptFile(tokens, outputFilePath)
exportStatements.push(`export * from './${prefix}';`)
}

function generateIndexFile() {
const outputFileName = 'index.d.ts'
const outputFilePath = path.join(OUTPUT_DIR, outputFileName)
const outputFileName = 'index.ts'
const outputFilePath = path.join(OUTPUT_TOKENS_DIR, outputFileName)
fs.writeFileSync(outputFilePath, exportStatements.join('\n'), 'utf8')
}

if (!fs.existsSync(OUTPUT_TOKENS_DIR)) {
fs.mkdirSync(OUTPUT_TOKENS_DIR)
}

prefixes.forEach((prefix) => {
processCssFileByTokenPrefix(TOKENS_DIR, prefix)
})
Expand Down