Skip to content

Commit 347ad7d

Browse files
author
kacper-paczos
committed
refactor(utils): extract formatUrls helper for setup wizard codegen
Share URL formatting between Axe and Lighthouse setup bindings.
1 parent 4cd53fb commit 347ad7d

4 files changed

Lines changed: 10 additions & 14 deletions

File tree

packages/plugin-axe/src/lib/binding.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
answerBoolean,
1010
answerNonEmptyArray,
1111
answerString,
12+
formatUrls,
1213
resolveDevServerUrlPrompt,
1314
singleQuote,
1415
} from '@code-pushup/utils';
@@ -140,10 +141,3 @@ function formatPluginCall({ urls, preset, setupScript }: AxeOptions): string {
140141
}
141142
return `axePlugin(${formattedUrls}, { ${options.join(', ')} })`;
142143
}
143-
144-
function formatUrls([first, ...rest]: [string, ...string[]]): string {
145-
if (rest.length === 0) {
146-
return singleQuote(first);
147-
}
148-
return `[${[first, ...rest].map(singleQuote).join(', ')}]`;
149-
}

packages/plugin-lighthouse/src/lib/binding.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
FALLBACK_DEV_SERVER_URL,
99
answerArray,
1010
answerNonEmptyArray,
11+
formatUrls,
1112
resolveDevServerUrlPrompt,
1213
singleQuote,
1314
} from '@code-pushup/utils';
@@ -150,10 +151,3 @@ function createCategories({
150151
}),
151152
);
152153
}
153-
154-
function formatUrls([first, ...rest]: [string, ...string[]]): string {
155-
if (rest.length === 0) {
156-
return singleQuote(first);
157-
}
158-
return `[${[first, ...rest].map(singleQuote).join(', ')}]`;
159-
}

packages/utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export {
6767
pluralizeToken,
6868
roundDecimals,
6969
serializeCommandWithArgs,
70+
formatUrls,
7071
singleQuote,
7172
slugify,
7273
transformLines,

packages/utils/src/lib/formatting.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,10 @@ export function singleQuote(value: string): string {
205205
.replace(/'/g, String.raw`\'`);
206206
return `'${inner}'`;
207207
}
208+
209+
export function formatUrls([first, ...rest]: [string, ...string[]]): string {
210+
if (rest.length === 0) {
211+
return singleQuote(first);
212+
}
213+
return `[${[first, ...rest].map(singleQuote).join(', ')}]`;
214+
}

0 commit comments

Comments
 (0)