-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tokens): compile ts files into js map on generate tokens script (#…
…162) Co-authored-by: Felipe Fialho <hi@felipefialho.com>
- Loading branch information
1 parent
60bb4a0
commit d5fd754
Showing
10 changed files
with
1,458 additions
and
1,071 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-env", "@babel/preset-typescript"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest', | ||
}, | ||
testMatch: ['**/*.spec.ts'], | ||
moduleFileExtensions: ['ts', 'js'], | ||
collectCoverage: true, | ||
coverageReporters: ['lcov'], | ||
collectCoverageFrom: ['scripts/*.ts', '!scripts/*.spec.ts'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import typescript from '@rollup/plugin-typescript' | ||
|
||
export default [ | ||
{ | ||
input: './index.ts', | ||
output: [ | ||
{ | ||
file: 'dist/index.js', | ||
format: 'cjs', | ||
sourcemap: true, | ||
}, | ||
{ | ||
file: 'dist/index.mjs', | ||
format: 'esm', | ||
sourcemap: true, | ||
}, | ||
], | ||
plugins: [typescript()], | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import fs from 'fs' | ||
import { OUTPUT_DIR, TOKENS_DIR, extractTokensFromCss } from './generate-tokens' | ||
|
||
jest.mock('fs', () => ({ | ||
readFileSync: jest.fn().mockReturnValue(` | ||
--color-primary: #ff0000; | ||
--spacing-small: 4px; | ||
--screen-mobile: 480px; | ||
`), | ||
writeFileSync: jest.fn(), | ||
})) | ||
|
||
describe('Generate Tokens', () => { | ||
it('should extract tokens from CSS content', () => { | ||
expect(fs.readFileSync).toHaveBeenCalledWith(TOKENS_DIR, 'utf8') | ||
expect(fs.writeFileSync).toHaveBeenCalledWith( | ||
`${OUTPUT_DIR}/index.ts`, | ||
`export const colorPrimary = '#ff0000';\nexport const spacingSmall = '4px';\nexport const screenMobile = '480px';`, | ||
'utf8' | ||
) | ||
}) | ||
|
||
it('should ignore CSS content without prefix tokens', () => { | ||
const cssContent = ` | ||
--any-variable: any_value; | ||
` | ||
const tokens: Record<string, string> = {} | ||
extractTokensFromCss(cssContent, 'color') | ||
expect(tokens).toEqual({}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters