Skip to content

Commit

Permalink
Merge pull request #9 from machour/8-configurable-ts-types-output-loc…
Browse files Browse the repository at this point in the history
…ation

Configurable TS types output location
  • Loading branch information
AlemTuzlak authored May 28, 2024
2 parents a823a2b + f20884f commit ead61d7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default {
inputDir: "icons",
// Output path for the generated spritesheet and types
outputDir: "public/icons",
// Output path for the generated type file, defaults to types.ts in outputDir
typesOutputFile: "app/icons.ts",
// The name of the generated spritesheet, defaults to sprite.svg
fileName: "icon.svg",
// The cwd, defaults to process.cwd()
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.

12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface PluginProps {
withTypes?: boolean;
inputDir: string;
outputDir: string;
typesOutputFile?: string;
fileName?: string;
cwd?: string;
iconNameTransformer?: (fileName: string) => string;
Expand All @@ -21,6 +22,7 @@ const generateIcons = async ({
withTypes = false,
inputDir,
outputDir,
typesOutputFile = `${outputDir}/types.ts`,
cwd,
fileName = "sprite.svg",
iconNameTransformer,
Expand All @@ -45,10 +47,16 @@ const generateIcons = async ({
outputDirRelative,
iconNameTransformer,
});

if (withTypes) {
const typesOutputDir = path.dirname(typesOutputFile);
const typesFile = path.basename(typesOutputFile);
const typesOutputDirRelative = path.relative(cwdToUse, typesOutputDir);

await mkdir(typesOutputDirRelative, { recursive: true });
await generateTypes({
names: files.map((file: string) => transformIconName(file, iconNameTransformer ?? fileNameToCamelCase)),
outputPath: path.join(outputDir, "types.ts"),
outputPath: path.join(typesOutputDir, typesFile),
});
}
};
Expand Down Expand Up @@ -156,6 +164,7 @@ export const iconsSpritesheet: (args: PluginProps) => Plugin = ({
withTypes,
inputDir,
outputDir,
typesOutputFile,
fileName,
cwd,
iconNameTransformer,
Expand All @@ -165,6 +174,7 @@ export const iconsSpritesheet: (args: PluginProps) => Plugin = ({
withTypes,
inputDir,
outputDir,
typesOutputFile,
fileName,
iconNameTransformer,
});
Expand Down

0 comments on commit ead61d7

Please sign in to comment.