-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(npm): add types and sass variables
- Loading branch information
Julius Osokinas
committed
May 18, 2021
1 parent
01f2a4b
commit 62bb8f4
Showing
19 changed files
with
130 additions
and
10 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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
@forward './theme'; | ||
|
||
// generated by Theo | ||
@forward './definitions/border-radius.scss'; | ||
@forward './definitions/color-palette.scss'; | ||
@forward './definitions/theme-colors.scss'; | ||
@forward './tokens'; | ||
@forward './theme-day'; | ||
@forward './theme-night'; |
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 |
---|---|---|
@@ -1 +1,10 @@ | ||
export * from './utils'; | ||
|
||
// generated by Theo | ||
export * from './definitions/borderRadius'; | ||
export * from './definitions/colorPalette'; | ||
export * from './definitions/themeColors'; | ||
|
||
import type { ColorPalette } from './definitions/colorPalette'; | ||
import type { ThemeColors } from './definitions/themeColors'; | ||
export type Color = ColorPalette | ThemeColors; |
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,9 @@ | ||
// generated by Theo (https://github.com/salesforce-ux/theo) | ||
|
||
${{DEFINITIONS_NAME}}: ( | ||
{{#each props as |prop|}} | ||
{{#is prop.category '{{FILTER_CATEGORY}}'}} | ||
'{{prop.name}}', | ||
{{/is}} | ||
{{/each}} | ||
); |
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
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,8 @@ | ||
// generated by Theo (https://github.com/salesforce-ux/theo) | ||
|
||
export type {{DEFINITIONS_NAME}} = | ||
{{#each props as |prop|}} | ||
{{#is prop.category '{{FILTER_CATEGORY}}'}} | ||
| '{{prop.name}}' | ||
{{/is}} | ||
{{/each}}; |
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,48 @@ | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
import { camelCase, kebabCase } from 'lodash'; | ||
import { join } from 'path'; | ||
import { convert, Format, registerFormat } from 'theo'; | ||
|
||
const definitionsName = process.env.DEFINITIONS_NAME; | ||
if (!definitionsName) throw new Error('No definitions name provided'); | ||
|
||
const srcPath = join(__dirname, `src/definitions/${definitionsName}.json`); | ||
|
||
const { meta } = JSON.parse(readFileSync(srcPath, 'utf8')); | ||
|
||
( | ||
[ | ||
{ | ||
type: 'scss', | ||
formatFile: 'sass-variables.scss.hbs', | ||
destFile: `${kebabCase(definitionsName)}.scss`, | ||
definitionsName: meta.sassVariableName, | ||
}, | ||
{ | ||
type: 'ts' as Format, | ||
formatFile: 'types.ts.hbs', | ||
destFile: `${camelCase(definitionsName)}.ts`, | ||
definitionsName: meta.typeName, | ||
}, | ||
] as const | ||
).forEach(({ type, formatFile, destFile, definitionsName }) => { | ||
const formatPath = join(__dirname, `packages/npm/src/${formatFile}`); | ||
const destPath = join(__dirname, `packages/npm/src/definitions/${destFile}`); | ||
|
||
registerFormat( | ||
type, | ||
readFileSync(formatPath, 'utf8') | ||
.replace(/{{DEFINITIONS_NAME}}/g, definitionsName) | ||
.replace(/{{FILTER_CATEGORY}}/g, meta.filterCategory) | ||
); | ||
|
||
convert({ | ||
transform: { | ||
type: 'raw', | ||
file: srcPath, | ||
}, | ||
format: { type }, | ||
}) | ||
.then((data) => writeFileSync(destPath, data)) | ||
.catch(console.error); | ||
}); |
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
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,8 @@ | ||
{ | ||
"imports": ["../tokens.json"], | ||
"meta": { | ||
"filterCategory": "border-radius", | ||
"sassVariableName": "border-radius", | ||
"typeName": "BorderRadius" | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"imports": ["../tokens.json"], | ||
"meta": { | ||
"filterCategory": "color", | ||
"sassVariableName": "color-palette", | ||
"typeName": "ColorPalette" | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"imports": ["../themes/day.json", "../themes/night.json"], | ||
"meta": { | ||
"filterCategory": "color", | ||
"sassVariableName": "theme-colors", | ||
"typeName": "ThemeColors" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"imports": ["../aliases.json"], | ||
"imports": ["./aliases.json"], | ||
"props": [ | ||
{ | ||
"type": "duration", | ||
|