-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: glob imports are not transformed
- Loading branch information
1 parent
01ce6f8
commit 2c29eb4
Showing
8 changed files
with
208 additions
and
24 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { globIterate } from 'glob' | ||
import { writeFile } from 'fs/promises' | ||
import { format, resolveConfig } from 'prettier' | ||
|
||
const prettierConfig = await resolveConfig() | ||
|
||
const generateIcons = async () => { | ||
const outputPath = 'src/lib/assets/icons/index.ts' | ||
const prefix = 'src/lib/assets/icons/' | ||
|
||
const lines = [] | ||
const names = [] | ||
|
||
for await (const i of globIterate('src/lib/assets/icons/*.svg')) { | ||
const name = i.slice(prefix.length, i.length - 4) | ||
lines.push(`import ${name} from './${name}.svg?url'`) | ||
names.push(name) | ||
} | ||
|
||
lines.push('') | ||
lines.push( | ||
`export const iconUrls: Record<string, string> = {\n${names.map((x) => `\t${x}`).join(',\n')}\n}` | ||
) | ||
lines.push('') | ||
lines.push(`export const iconNames: string[] = ${JSON.stringify(names)}`) | ||
|
||
await writeFile( | ||
outputPath, | ||
await format(lines.join('\n'), { ...prettierConfig, parser: 'typescript' }) | ||
) | ||
} | ||
|
||
const generateTranslations = async () => { | ||
const outputPath = 'src/lib/localization/translations/index.ts' | ||
const prefix = 'src/lib/localization/translations/' | ||
|
||
const lines = [] | ||
const translationData = [] | ||
|
||
for await (const i of globIterate('src/lib/localization/translations/*/*.ftl')) { | ||
const name = i.slice(prefix.length, i.length - 4) | ||
const importName = name.replace(/\//g, '_') | ||
|
||
lines.push(`import ${importName} from './${name}.ftl?raw'`) | ||
|
||
translationData.push(`${JSON.stringify(name)}: ${importName}`) | ||
} | ||
|
||
lines.push('') | ||
|
||
lines.push( | ||
`export const translationData: Record<string, string> = {\n${translationData.map((x) => `\t${x}`).join(',\n')}\n}` | ||
) | ||
|
||
await writeFile( | ||
outputPath, | ||
await format(lines.join('\n'), { ...prettierConfig, parser: 'typescript' }) | ||
) | ||
} | ||
|
||
await Promise.all([generateIcons(), generateTranslations()]) |
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,114 @@ | ||
import topLeft from './topLeft.svg?url' | ||
import tag from './tag.svg?url' | ||
import steam from './steam.svg?url' | ||
import speed from './speed.svg?url' | ||
import sort from './sort.svg?url' | ||
import shuffle from './shuffle.svg?url' | ||
import show from './show.svg?url' | ||
import sheet from './sheet.svg?url' | ||
import share from './share.svg?url' | ||
import search from './search.svg?url' | ||
import scale from './scale.svg?url' | ||
import refresh from './refresh.svg?url' | ||
import question from './question.svg?url' | ||
import plusFilled from './plusFilled.svg?url' | ||
import playOutlined from './playOutlined.svg?url' | ||
import playFilled from './playFilled.svg?url' | ||
import minusFilled from './minusFilled.svg?url' | ||
import list from './list.svg?url' | ||
import hide from './hide.svg?url' | ||
import help from './help.svg?url' | ||
import heartOutlined from './heartOutlined.svg?url' | ||
import heart from './heart.svg?url' | ||
import fire from './fire.svg?url' | ||
import filter from './filter.svg?url' | ||
import expand from './expand.svg?url' | ||
import downloadFile from './downloadFile.svg?url' | ||
import download from './download.svg?url' | ||
import copy from './copy.svg?url' | ||
import cogs from './cogs.svg?url' | ||
import close from './close.svg?url' | ||
import chevronLeft from './chevronLeft.svg?url' | ||
import check from './check.svg?url' | ||
import calendar from './calendar.svg?url' | ||
import bottomRight from './bottomRight.svg?url' | ||
import bottomArrowCircleOutlined from './bottomArrowCircleOutlined.svg?url' | ||
import accuracy from './accuracy.svg?url' | ||
|
||
export const iconUrls: Record<string, string> = { | ||
topLeft, | ||
tag, | ||
steam, | ||
speed, | ||
sort, | ||
shuffle, | ||
show, | ||
sheet, | ||
share, | ||
search, | ||
scale, | ||
refresh, | ||
question, | ||
plusFilled, | ||
playOutlined, | ||
playFilled, | ||
minusFilled, | ||
list, | ||
hide, | ||
help, | ||
heartOutlined, | ||
heart, | ||
fire, | ||
filter, | ||
expand, | ||
downloadFile, | ||
download, | ||
copy, | ||
cogs, | ||
close, | ||
chevronLeft, | ||
check, | ||
calendar, | ||
bottomRight, | ||
bottomArrowCircleOutlined, | ||
accuracy | ||
} | ||
|
||
export const iconNames: string[] = [ | ||
'topLeft', | ||
'tag', | ||
'steam', | ||
'speed', | ||
'sort', | ||
'shuffle', | ||
'show', | ||
'sheet', | ||
'share', | ||
'search', | ||
'scale', | ||
'refresh', | ||
'question', | ||
'plusFilled', | ||
'playOutlined', | ||
'playFilled', | ||
'minusFilled', | ||
'list', | ||
'hide', | ||
'help', | ||
'heartOutlined', | ||
'heart', | ||
'fire', | ||
'filter', | ||
'expand', | ||
'downloadFile', | ||
'download', | ||
'copy', | ||
'cogs', | ||
'close', | ||
'chevronLeft', | ||
'check', | ||
'calendar', | ||
'bottomRight', | ||
'bottomArrowCircleOutlined', | ||
'accuracy' | ||
] |
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,23 +1,17 @@ | ||
export const getIconClass = (name: string) => `icon__${name}` | ||
|
||
const icons = import.meta.glob('./icons/*.svg', { | ||
eager: true, | ||
query: '?url', | ||
import: 'default' | ||
}) | ||
import { iconUrls, iconNames } from './icons/index.js' | ||
|
||
const iconPrefix = './icons/' | ||
export const iconNames = Object.keys(icons).map((x) => x.slice(iconPrefix.length, x.length - 4)) | ||
export const getIconClass = (name: string) => `icon__${name}` | ||
|
||
export const generateIconStyles = () => { | ||
const css: string[] = [] | ||
for (const key in icons) { | ||
const name = key.slice(iconPrefix.length, key.length - 4) | ||
const url = icons[key] | ||
const element = `.${getIconClass(name)} { --icon-url: url('${(url as string).replace(/'/g, '%27')}') }` | ||
for (const iconName of iconNames) { | ||
const url = iconUrls[iconName] | ||
const element = `.${getIconClass(iconName)} { --icon-url: url('${url.replace(/'/g, '%27')}') }` | ||
|
||
css.push(element) | ||
} | ||
|
||
return `<style>\n${css.join('\n')}\n</style>` | ||
} | ||
|
||
export { iconNames } |
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,15 @@ | ||
import ko_nav from './ko/nav.ftl?raw' | ||
import ko_footer from './ko/footer.ftl?raw' | ||
import ko_common from './ko/common.ftl?raw' | ||
import en_nav from './en/nav.ftl?raw' | ||
import en_footer from './en/footer.ftl?raw' | ||
import en_common from './en/common.ftl?raw' | ||
|
||
export const translationData: Record<string, string> = { | ||
'ko/nav': ko_nav, | ||
'ko/footer': ko_footer, | ||
'ko/common': ko_common, | ||
'en/nav': en_nav, | ||
'en/footer': en_footer, | ||
'en/common': en_common | ||
} |
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