-
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: using cjs files for generator button and input styles scripts * refactor: updated @atls-ui-generators/icons package destructured svgr logic to utils updated @svgr/core version to 8.1.0 updated icon template for esm syntax * chore: install dependencies
- Loading branch information
Showing
22 changed files
with
741 additions
and
177 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
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 was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
generators/icons/src/get-color-replacement/get-color-replacement.interfaces.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface GetColorReplacementOptions { | ||
themePaths?: Array<string> | ||
color: string | ||
} | ||
|
||
export type GetColorReplacement = (options: GetColorReplacementOptions) => Record<string, string> |
8 changes: 8 additions & 0 deletions
8
generators/icons/src/get-color-replacement/get-color-replacement.util.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { GetColorReplacement } from './get-color-replacement.interfaces' | ||
|
||
export const getColorReplacement: GetColorReplacement = (options) => ({ | ||
[options.color]: `{(props.color && vars.colors${(options.themePaths || []).reduce( | ||
(str, prop) => `${str}.${prop}`, | ||
'' | ||
)}[props.color]) || props.color || "${options.color}"}`, | ||
}) |
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 @@ | ||
export * from './get-color-replacement.util' |
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,17 @@ | ||
import type { Config } from '@svgr/core' | ||
|
||
export interface Icon { | ||
name: string | ||
source: string | ||
fileName: string | ||
} | ||
|
||
export interface Source { | ||
name: string | ||
code: string | ||
withReplacement: boolean | ||
} | ||
|
||
export type Replacements = Record<string, Record<string, string>> | ||
|
||
export type CreateSvgrTemplate = (withReplacement: boolean) => Config['template'] |
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,2 +1,2 @@ | ||
export * from './get-color-replacement.util' | ||
export * from './svgr' | ||
export * from './get-color-replacement' | ||
export * from './utils' |
This file was deleted.
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,42 @@ | ||
import type { Icon } from '../icons.interfaces' | ||
import type { Replacements } from '../icons.interfaces' | ||
import type { Source } from '../icons.interfaces' | ||
import type { CreateSvgrTemplate } from '../icons.interfaces' | ||
|
||
import { transform } from '@svgr/core' | ||
|
||
const createSvgrTemplate: CreateSvgrTemplate = (withReplacement) => | ||
({ jsx, componentName }, { tpl }) => tpl` | ||
import type { IconProps } from '../icons.interfaces.js' | ||
import React from 'react' | ||
import { memo } from 'react' | ||
${withReplacement ? `import { vars } from '@atls-ui-admin/theme'` : ''} | ||
export const ${componentName} = memo((props: IconProps) => ( | ||
${jsx} | ||
)) | ||
` | ||
|
||
export const compileIcons = async ( | ||
icons: Array<Icon>, | ||
replacements: Replacements | ||
): Promise<Array<Source>> => | ||
Promise.all( | ||
icons.map(async (icon) => ({ | ||
name: icon.fileName, | ||
code: await transform( | ||
icon.source.replace(/mask0/g, icon.name), | ||
{ | ||
icon: true, | ||
typescript: true, | ||
template: createSvgrTemplate(Boolean(replacements[icon.name])), | ||
plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx', '@svgr/plugin-prettier'], | ||
replaceAttrValues: replacements[icon.name] || {}, | ||
}, | ||
{ componentName: icon.name.replace('50+', 'FiftyPlus') } | ||
), | ||
withReplacement: Boolean(replacements[icon.name]), | ||
})) | ||
) |
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,39 @@ | ||
import type { Options } from 'prettier' | ||
|
||
import type { Source } from '../icons.interfaces' | ||
|
||
import * as prettierPlugin from '@atls/prettier-plugin' | ||
import prettierConfig from '@atls/config-prettier' | ||
import fs from 'fs-extra-promise' | ||
import path from 'path' | ||
import parserBabel from 'prettier/parser-babel' | ||
import parserTypescript from 'prettier/parser-typescript' | ||
import prettier from 'prettier/standalone' | ||
|
||
const writeSourceFile = async (source: Source, targetDir: string): Promise<void> => { | ||
const filename = path.join(targetDir, `${source.name}.tsx`) | ||
const config = prettierConfig as Options | ||
|
||
const data = prettier.format(source.code, { | ||
...config, | ||
filepath: path.join(targetDir, `${source.name}.tsx`), | ||
plugins: [parserTypescript, parserBabel, prettierPlugin], | ||
}) | ||
|
||
await fs.writeFileAsync(filename, data) | ||
} | ||
|
||
const writeIndexFile = async (sources: Array<Source>, targetDir: string): Promise<void> => { | ||
const filename = path.join(targetDir, 'index.ts') | ||
const data = `${sources.map((source) => `export * from './${source.name}.js'`).join('\n')}\n` | ||
|
||
await fs.writeFileAsync(filename, data) | ||
} | ||
|
||
export const createFiles = async (sources: Array<Source>, targetDir: string): Promise<void> => { | ||
await fs.ensureDir(targetDir) | ||
|
||
await Promise.all(sources.map(async (source) => writeSourceFile(source, targetDir))) | ||
|
||
await writeIndexFile(sources, targetDir) | ||
} |
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 @@ | ||
export * from './svgr-build.util' |
Oops, something went wrong.