Skip to content

Commit d5ba75e

Browse files
authored
Merge pull request #34 from sairus2k/fix-clipped-output
Fix clipped output
2 parents 11d97c9 + c84b8b1 commit d5ba75e

File tree

2 files changed

+18
-39
lines changed

2 files changed

+18
-39
lines changed

package-lock.json

Lines changed: 4 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ interface PluginProps {
4545
* @default no formatter
4646
* @example "biome"
4747
*/
48-
formatter?: Formatter;
48+
formatter?: Formatter;
4949
/**
5050
* The cwd, defaults to process.cwd()
5151
* @default process.cwd()
@@ -115,6 +115,7 @@ function fileNameToCamelCase(fileName: string): string {
115115
const capitalizedWords = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1));
116116
return capitalizedWords.join("");
117117
}
118+
118119
/**
119120
* Creates a single SVG file that contains all the icons
120121
*/
@@ -158,7 +159,7 @@ async function generateSvgSprite({
158159
svg.removeAttribute("width");
159160
svg.removeAttribute("height");
160161
return svg.toString().trim();
161-
}),
162+
})
162163
);
163164
const output = [
164165
'<?xml version="1.0" encoding="UTF-8"?>',
@@ -173,7 +174,7 @@ async function generateSvgSprite({
173174
return writeIfChanged(
174175
outputPath,
175176
formattedOutput,
176-
`🖼️ Generated SVG spritesheet in ${chalk.green(outputDirRelative)}`,
177+
`🖼️ Generated SVG spritesheet in ${chalk.green(outputDirRelative)}`
177178
);
178179
}
179180

@@ -194,21 +195,18 @@ async function lintFileContent(fileContent: string, formatter: Formatter | undef
194195
stdinStream.push(null);
195196

196197
const { process } = exec(formatter, options, {});
197-
if (!process?.stdin) {
198+
if (!process?.stdin) {
198199
return fileContent;
199200
}
200201
stdinStream.pipe(process.stdin);
201202
process.stderr?.pipe(stderr);
202-
process.on("error", ( ) => {
203-
return fileContent
203+
process.on("error", (err) => {
204+
console.error(`Error running formatter process: ${err.message}`);
204205
});
205-
const formattedContent = await new Promise<string>((resolve) => {
206-
process.stdout?.on("data", (data) => {
207-
resolve(data.toString());
208-
});
209-
process.stderr?.on("data", (data) => {
210-
resolve(data.toString());
211-
});
206+
207+
let formattedContent = "";
208+
process.stdout?.on("data", (data) => {
209+
formattedContent = formattedContent + data.toString();
212210
});
213211
return new Promise<string>((resolve) => {
214212
process.on("exit", (code) => {
@@ -242,7 +240,7 @@ async function generateTypes({
242240
const file = await writeIfChanged(
243241
outputPath,
244242
formattedOutput,
245-
`${chalk.blueBright("TS")} Generated icon types in ${chalk.green(outputPath)}`,
243+
`${chalk.blueBright("TS")} Generated icon types in ${chalk.green(outputPath)}`
246244
);
247245
return file;
248246
}
@@ -270,16 +268,7 @@ export const iconsSpritesheet: (args: PluginProps | PluginProps[]) => any = (may
270268
const configs = Array.isArray(maybeConfigs) ? maybeConfigs : [maybeConfigs];
271269
const allSpriteSheetNames = configs.map((config) => config.fileName ?? "sprite.svg");
272270
return configs.map((config, i) => {
273-
const {
274-
withTypes,
275-
inputDir,
276-
outputDir,
277-
typesOutputFile,
278-
fileName,
279-
cwd,
280-
iconNameTransformer,
281-
formatter,
282-
} = config;
271+
const { withTypes, inputDir, outputDir, typesOutputFile, fileName, cwd, iconNameTransformer, formatter } = config;
283272
const iconGenerator = async () =>
284273
generateIcons({
285274
withTypes,
@@ -290,7 +279,7 @@ export const iconsSpritesheet: (args: PluginProps | PluginProps[]) => any = (may
290279
iconNameTransformer,
291280
formatter,
292281
});
293-
282+
294283
const workDir = cwd ?? process.cwd();
295284
return {
296285
name: `icon-spritesheet-generator${i > 0 ? i.toString() : ""}`,

0 commit comments

Comments
 (0)