Skip to content

Commit 896ace1

Browse files
committed
ligher limbo of import / exports
1 parent 4bea408 commit 896ace1

File tree

11 files changed

+70
-81
lines changed

11 files changed

+70
-81
lines changed

packages/sv/lib/addons/drizzle/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
js,
1111
parseJson,
1212
parseScript,
13-
resolveCommand
13+
resolveCommand,
14+
style
1415
} from '../../core.ts';
1516

1617
type Database = 'mysql' | 'postgresql' | 'sqlite';
@@ -428,23 +429,23 @@ export default defineAddon({
428429
return generateCode();
429430
});
430431
},
431-
nextSteps: ({ options, highlighter, packageManager }) => {
432+
nextSteps: ({ options, packageManager }) => {
432433
const steps = [
433-
`You will need to set ${highlighter.env('DATABASE_URL')} in your production environment`
434+
`You will need to set ${style.env('DATABASE_URL')} in your production environment`
434435
];
435436
if (options.docker) {
436437
const { command, args } = resolveCommand(packageManager, 'run', ['db:start'])!;
437438
steps.push(
438-
`Run ${highlighter.command(`${command} ${args.join(' ')}`)} to start the docker container`
439+
`Run ${style.command(`${command} ${args.join(' ')}`)} to start the docker container`
439440
);
440441
} else {
441442
steps.push(
442-
`Check ${highlighter.env('DATABASE_URL')} in ${highlighter.path('.env')} and adjust it to your needs`
443+
`Check ${style.env('DATABASE_URL')} in ${style.path('.env')} and adjust it to your needs`
443444
);
444445
}
445446
const { command, args } = resolveCommand(packageManager, 'run', ['db:push'])!;
446447
steps.push(
447-
`Run ${highlighter.command(`${command} ${args.join(' ')}`)} to update your database schema`
448+
`Run ${style.command(`${command} ${args.join(' ')}`)} to update your database schema`
448449
);
449450

450451
return steps;

packages/sv/lib/addons/lucia/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import {
44
type AstTypes,
55
Walker,
66
addToDemoPage,
7-
colors,
87
dedent,
98
defineAddon,
109
defineAddonOptions,
1110
js,
1211
log,
1312
parseScript,
1413
resolveCommand,
14+
style,
1515
utils
1616
} from '../../core.ts';
1717

@@ -31,7 +31,7 @@ const options = defineAddonOptions()
3131
.add('demo', {
3232
type: 'boolean',
3333
default: true,
34-
question: `Do you want to include a demo? ${colors.dim('(includes a login/register page)')}`
34+
question: `Do you want to include a demo? ${style.optional('(includes a login/register page)')}`
3535
})
3636
.build();
3737

@@ -403,7 +403,7 @@ export default defineAddon({
403403
sv.file(`${kit!.routesDirectory}/demo/lucia/login/+page.server.${ext}`, (content) => {
404404
if (content) {
405405
const filePath = `${kit!.routesDirectory}/demo/lucia/login/+page.server.${typescript ? 'ts' : 'js'}`;
406-
log.warn(`Existing ${colors.yellow(filePath)} file. Could not update.`);
406+
log.warn(`Existing ${style.warning(filePath)} file. Could not update.`);
407407
return content;
408408
}
409409

@@ -526,7 +526,7 @@ export default defineAddon({
526526
sv.file(`${kit!.routesDirectory}/demo/lucia/login/+page.svelte`, (content) => {
527527
if (content) {
528528
const filePath = `${kit!.routesDirectory}/demo/lucia/login/+page.svelte`;
529-
log.warn(`Existing ${colors.yellow(filePath)} file. Could not update.`);
529+
log.warn(`Existing ${style.warning(filePath)} file. Could not update.`);
530530
return content;
531531
}
532532

@@ -576,7 +576,7 @@ export default defineAddon({
576576
sv.file(`${kit!.routesDirectory}/demo/lucia/+page.server.${ext}`, (content) => {
577577
if (content) {
578578
const filePath = `${kit!.routesDirectory}/demo/lucia/+page.server.${typescript ? 'ts' : 'js'}`;
579-
log.warn(`Existing ${colors.yellow(filePath)} file. Could not update.`);
579+
log.warn(`Existing ${style.warning(filePath)} file. Could not update.`);
580580
return content;
581581
}
582582

@@ -618,7 +618,7 @@ export default defineAddon({
618618
sv.file(`${kit!.routesDirectory}/demo/lucia/+page.svelte`, (content) => {
619619
if (content) {
620620
const filePath = `${kit!.routesDirectory}/demo/lucia/+page.svelte`;
621-
log.warn(`Existing ${colors.yellow(filePath)} file. Could not update.`);
621+
log.warn(`Existing ${style.warning(filePath)} file. Could not update.`);
622622
return content;
623623
}
624624

@@ -640,13 +640,13 @@ export default defineAddon({
640640
});
641641
}
642642
},
643-
nextSteps: ({ highlighter, options, packageManager }) => {
643+
nextSteps: ({ options, packageManager }) => {
644644
const { command, args } = resolveCommand(packageManager, 'run', ['db:push'])!;
645645
const steps = [
646-
`Run ${highlighter.command(`${command} ${args.join(' ')}`)} to update your database schema`
646+
`Run ${style.command(`${command} ${args.join(' ')}`)} to update your database schema`
647647
];
648648
if (options.demo) {
649-
steps.push(`Visit ${highlighter.route('/demo/lucia')} route to view the demo`);
649+
steps.push(`Visit ${style.route('/demo/lucia')} route to view the demo`);
650650
}
651651

652652
return steps;

packages/sv/lib/addons/mcp/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
defineAddon,
33
defineAddonOptions,
4-
getHighlighter,
54
getSharedFiles,
65
log,
7-
parseJson
6+
parseJson,
7+
style
88
} from '../../core.ts';
99

1010
const options = defineAddonOptions()
@@ -165,19 +165,18 @@ export default defineAddon({
165165
}
166166

167167
if (filesExistingAlready.length > 0) {
168-
const highlighter = getHighlighter();
169168
log.warn(
170-
`${filesExistingAlready.map((path) => highlighter.path(path)).join(', ')} already exists, we didn't touch ${filesExistingAlready.length > 1 ? 'them' : 'it'}. ` +
171-
`See ${highlighter.website('https://svelte.dev/docs/mcp/overview#Usage')} for manual setup.`
169+
`${filesExistingAlready.map((path) => style.path(path)).join(', ')} already exists, we didn't touch ${filesExistingAlready.length > 1 ? 'them' : 'it'}. ` +
170+
`See ${style.website('https://svelte.dev/docs/mcp/overview#Usage')} for manual setup.`
172171
);
173172
}
174173
},
175-
nextSteps({ highlighter, options }) {
174+
nextSteps({ options }) {
176175
const steps = [];
177176

178177
if (options.ide.includes('other')) {
179178
steps.push(
180-
`For other clients: ${highlighter.website(`https://svelte.dev/docs/mcp/${options.setup}-setup#Other-clients`)}`
179+
`For other clients: ${style.website(`https://svelte.dev/docs/mcp/${options.setup}-setup#Other-clients`)}`
181180
);
182181
}
183182

packages/sv/lib/addons/paraglide/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
addToDemoPage,
3-
colors,
43
defineAddon,
54
defineAddonOptions,
65
html,
@@ -10,6 +9,7 @@ import {
109
parseJson,
1110
parseScript,
1211
parseSvelte,
12+
style,
1313
svelte
1414
} from '../../core.ts';
1515

@@ -26,7 +26,7 @@ const DEFAULT_INLANG_PROJECT = {
2626

2727
const options = defineAddonOptions()
2828
.add('languageTags', {
29-
question: `Which languages would you like to support? ${colors.gray('(e.g. en,de-ch)')}`,
29+
question: `Which languages would you like to support? ${style.optional('(e.g. en,de-ch)')}`,
3030
type: 'string',
3131
default: 'en, es',
3232
validate(input) {
@@ -250,10 +250,10 @@ export default defineAddon({
250250
}
251251
},
252252

253-
nextSteps: ({ highlighter }) => {
254-
const steps = [`Edit your messages in ${highlighter.path('messages/en.json')}`];
253+
nextSteps: () => {
254+
const steps = [`Edit your messages in ${style.path('messages/en.json')}`];
255255
if (options.demo) {
256-
steps.push(`Visit ${highlighter.route('/demo/paraglide')} route to view the demo`);
256+
steps.push(`Visit ${style.route('/demo/paraglide')} route to view the demo`);
257257
}
258258

259259
return steps;

packages/sv/lib/addons/prettier/index.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
addEslintConfigPrettier,
3-
colors,
4-
dedent,
5-
defineAddon,
6-
log,
7-
parseJson
8-
} from '../../core.ts';
1+
import { addEslintConfigPrettier, dedent, defineAddon, log, parseJson, style } from '../../core.ts';
92

103
export default defineAddon({
114
id: 'prettier',
@@ -40,7 +33,7 @@ export default defineAddon({
4033
({ data, generateCode } = parseJson(content));
4134
} catch {
4235
log.warn(
43-
`A ${colors.yellow('.prettierrc')} config already exists and cannot be parsed as JSON. Skipping initialization.`
36+
`A ${style.warning('.prettierrc')} config already exists and cannot be parsed as JSON. Skipping initialization.`
4437
);
4538
return content;
4639
}
@@ -96,9 +89,9 @@ export default defineAddon({
9689

9790
if (eslintVersion?.startsWith(SUPPORTED_ESLINT_VERSION) === false) {
9891
log.warn(
99-
`An older major version of ${colors.yellow(
92+
`An older major version of ${style.warning(
10093
'eslint'
101-
)} was detected. Skipping ${colors.yellow('eslint-config-prettier')} installation.`
94+
)} was detected. Skipping ${style.warning('eslint-config-prettier')} installation.`
10295
);
10396
}
10497

packages/sv/lib/addons/vitest-addon/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { dedent, defineAddon, defineAddonOptions, js, parseJson, parseScript } from '../../core.ts';
1+
import {
2+
dedent,
3+
defineAddon,
4+
defineAddonOptions,
5+
js,
6+
parseJson,
7+
parseScript,
8+
style
9+
} from '../../core.ts';
210

311
const options = defineAddonOptions()
412
.add('usages', {
@@ -158,22 +166,22 @@ export default defineAddon({
158166
});
159167
},
160168

161-
nextSteps: ({ highlighter, typescript, options }) => {
169+
nextSteps: ({ typescript, options }) => {
162170
const toReturn: string[] = [];
163171

164172
if (vitestV3Installed) {
165173
const componentTesting = options.usages.includes('component');
166174
if (componentTesting) {
167-
toReturn.push(`Uninstall ${highlighter.command('@vitest/browser')} package`);
175+
toReturn.push(`Uninstall ${style.command('@vitest/browser')} package`);
168176
toReturn.push(
169-
`Update usage from ${highlighter.command("'@vitest/browser...'")} to ${highlighter.command("'vitest/browser'")}`
177+
`Update usage from ${style.command("'@vitest/browser...'")} to ${style.command("'vitest/browser'")}`
170178
);
171179
}
172180
toReturn.push(
173-
`${highlighter.optional('Optional')} Check ${highlighter.path('./vite.config.ts')} and remove duplicate project definitions`
181+
`${style.optional('Optional')} Check ${style.path('./vite.config.ts')} and remove duplicate project definitions`
174182
);
175183
toReturn.push(
176-
`${highlighter.optional('Optional')} Remove ${highlighter.path('./vitest-setup-client' + (typescript ? '.ts' : '.js'))} file`
184+
`${style.optional('Optional')} Remove ${style.path('./vitest-setup-client' + (typescript ? '.ts' : '.js'))} file`
177185
);
178186
}
179187

packages/sv/lib/cli/add/index.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
packageManagerPrompt
2424
} from '../utils/package-manager.ts';
2525
import { downloadPackage, getPackageJSON } from './fetch-packages.ts';
26-
import { formatFiles, getHighlighter } from './utils.ts';
26+
import { formatFiles, style } from './utils.ts';
2727
import { verifyCleanWorkingDirectory, verifyUnsupportedAddons } from './verifiers.ts';
2828
import { createWorkspace } from './workspace.ts';
2929

@@ -660,9 +660,8 @@ export async function runAddonsApply({
660660
p.cancel('All selected add-ons were canceled.');
661661
process.exit(1);
662662
} else {
663-
const highlighter = getHighlighter();
664663
p.log.success(
665-
`Successfully setup add-ons: ${addonSuccess.map((c) => highlighter.addon(c)).join(', ')}`
664+
`Successfully setup add-ons: ${addonSuccess.map((c) => style.addon(c)).join(', ')}`
666665
);
667666
}
668667

@@ -735,14 +734,12 @@ export async function runAddonsApply({
735734
await formatFiles({ packageManager, cwd: options.cwd, filesToFormat });
736735
}
737736

738-
const highlighter = getHighlighter();
739-
740737
// print next steps
741738
const nextSteps = selectedAddons
742739
.map((addon) => {
743740
if (!addon.nextSteps) return;
744741
const addonOptions = answers[addon.id];
745-
const addonNextSteps = addon.nextSteps({ ...workspace, options: addonOptions, highlighter });
742+
const addonNextSteps = addon.nextSteps({ ...workspace, options: addonOptions });
746743
if (addonNextSteps.length === 0) return;
747744

748745
let addonMessage = `${pc.green(addon.id)}:\n`;
@@ -793,10 +790,9 @@ export function sanitizeAddons(addonArgs: AddonArgsIn[]): AddonArgsOut[] {
793790
}
794791
}
795792
if (invalidAddons.length > 0) {
796-
const highlighter = getHighlighter();
797793
common.errorAndExit(
798-
`Invalid add-ons specified: ${invalidAddons.map((id) => highlighter.command(id)).join(', ')}\n` +
799-
`${highlighter.optional('Check the documentation for valid add-on specifiers:')} ${highlighter.website('https://svelte.dev/docs/cli/sv-add')}`
794+
`Invalid add-ons specified: ${invalidAddons.map((id) => style.command(id)).join(', ')}\n` +
795+
`${style.optional('Check the documentation for valid add-on specifiers:')} ${style.website('https://svelte.dev/docs/cli/sv-add')}`
800796
);
801797
}
802798

@@ -898,11 +894,10 @@ export async function resolveNonOfficialAddons(
898894
downloadCheck: boolean
899895
) {
900896
const selectedAddons: ResolvedAddon[] = [];
901-
const highlighter = getHighlighter();
902897
const { start, stop } = p.spinner();
903898

904899
try {
905-
start(`Resolving ${addons.map((a) => highlighter.addon(a.id)).join(', ')} packages`);
900+
start(`Resolving ${addons.map((a) => style.addon(a.id)).join(', ')} packages`);
906901

907902
// Do this only for npm addons
908903
// const npmAddons = addons.filter((a) => a.kind !== 'file' && a.kind !== 'official');
@@ -918,9 +913,8 @@ export async function resolveNonOfficialAddons(
918913
// }
919914
// const blockedNpmAddons = npmAddons.filter((a) => blocklist.npm_names.includes(a.resolvedId));
920915
// if (blockedNpmAddons.length > 0) {
921-
// const h = getHighlighter();
922916
// common.errorAndExit(
923-
// `${blockedNpmAddons.map((a) => h.env(a.id)).join(', ')} blocked from being installed.`
917+
// `${blockedNpmAddons.map((a) => style.env(a.id)).join(', ')} blocked from being installed.`
924918
// );
925919
// }
926920
// }
@@ -964,7 +958,7 @@ export async function resolveNonOfficialAddons(
964958
} catch (err) {
965959
const msg = err instanceof Error ? err.message : 'Unknown error';
966960
common.errorAndExit(
967-
`Failed to resolve ${addons.map((a) => highlighter.addon(a.id)).join(', ')}\n${highlighter.optional(msg)}`
961+
`Failed to resolve ${addons.map((a) => style.addon(a.id)).join(', ')}\n${style.optional(msg)}`
968962
);
969963
}
970964
return selectedAddons;

packages/sv/lib/cli/add/utils.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ export const commonFilePaths = {
136136
viteConfigTS: 'vite.config.ts'
137137
} as const;
138138

139-
export function getHighlighter(): Highlighter {
140-
return {
141-
addon: (str) => pc.green(str),
142-
command: (str) => pc.bold(pc.cyanBright(str)),
143-
env: (str) => pc.yellow(str),
144-
path: (str) => pc.green(str),
145-
route: (str) => pc.bold(str),
146-
website: (str) => pc.whiteBright(str),
147-
optional: (str) => pc.gray(str)
148-
};
149-
}
139+
export const style = {
140+
addon: (str: string): string => pc.green(str),
141+
command: (str: string): string => pc.bold(pc.cyanBright(str)),
142+
env: (str: string): string => pc.yellow(str),
143+
path: (str: string): string => pc.green(str),
144+
route: (str: string): string => pc.bold(str),
145+
website: (str: string): string => pc.whiteBright(str),
146+
optional: (str: string): string => pc.gray(str),
147+
issue: (str: string): string => pc.red(str),
148+
warning: (str: string): string => pc.yellow(str)
149+
};

0 commit comments

Comments
 (0)