8000 chore: improve paraglide by AdrianGonz97 · Pull Request #104 · sveltejs/cli · GitHub
[go: up one dir, main page]

Skip to content

chore: improve paraglide #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Convers 8000 ations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify createPrinter
  • Loading branch information
AdrianGonz97 committed Oct 13, 2024
commit 55b4cd42f4585093973bc76bfa52ad8d29936b22
8 changes: 4 additions & 4 deletions packages/adders/lucia/index.ts
10000
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export default defineAdder({
return content;
}

const { ts } = utils.createPrinter({ ts: typescript });
const [ts] = utils.createPrinter(typescript);
return dedent`
import { fail, redirect } from '@sveltejs/kit';
import { hash, verify } from '@node-rs/argon2';
Expand Down Expand Up @@ -434,7 +434,7 @@ export default defineAdder({
return content;
}

const { ts } = utils.createPrinter({ ts: typescript });
const [ts] = utils.createPrinter(typescript);
return dedent`
<script ${ts(`lang='ts'`)}>
import { enhance } from '$app/forms';
Expand Down Expand Up @@ -473,7 +473,7 @@ export default defineAdder({
return content;
}

const { ts } = utils.createPrinter({ ts: typescript });
const [ts] = utils.createPrinter(typescript);
return dedent`
import { lucia } from '$lib/server/auth';
import { fail, redirect } from '@sveltejs/kit';
Expand Down Expand Up @@ -514,7 +514,7 @@ export default defineAdder({
return content;
}

const { ts } = utils.createPrinter({ ts: typescript });
const [ts] = utils.createPrinter(typescript);
return dedent`
<script ${ts(`lang='ts'`)}>
import { enhance } from '$app/forms';
Expand Down
2 changes: 1 addition & 1 deletion packages/adders/paraglide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export default defineAdder({
);
}

const { ts } = utils.createPrinter({ ts: typescript });
const [ts] = utils.createPrinter(typescript);

const scriptCode = new MagicString(script.generateCode());
if (!scriptCode.original.includes('function switchToLanguage')) {
Expand Down
16 changes: 5 additions & 11 deletions packages/core/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
type Printers<Condition extends Record<string, boolean>> = {
[K in keyof Condition]: (content: string, alt?: string) => string;
};
export function createPrinter<Condition extends Record<string, boolean>>(
conditions: Condition
): Printers<Condition> {
const printers = Object.entries(conditions).reduce((acc, [key, condition]) => {
acc[key as keyof Condition] = (content: string, alt = '') => (condition ? content : alt);
return acc;
}, {} as Printers<Condition>);

type Printer = (content: string, alt?: string) => string;
export function createPrinter(...conditions: boolean[]): Printer[] {
const printers = conditions.map((condition) => {
return (content: string, alt = '') => (condition ? content : alt);
});
return printers;
}
0