Skip to content

Commit 9da497f

Browse files
chore: simpler / more flexible api (#181)
* mock api * mock paraglide adder * improve? api * small tweaks * more tweaks * more * start implementing new api (no clue if it works, requires cleanup) * rename * rename some stuff * migrate eslint * migrate mdsvex * migrate playwright * migrate prettier * delete routify * update storybook * update tailwindcss * migrate vitest * migrate drizzle * migrate lucia * exract `dependsOn` into seperate function * cleanup * migrate community adder * try out `setup` api, without actually implementing it * skip writing empty files * make `setup` function work * rename dir because vitest hates us * dont expose `options` * simplify * pm * remove old tests * initial install helper impl * ignores * add initial tests * ..pin storybook * fix scripts * add storybook test * simplify * deps * add retries * not needed * tweak community template * add fixtures * community template tests * naming * tweaks * unneeded * clean * lockfile trickery * fix eslint test * fix paraglide * tweak workflow * ... * fix lint * fix check * simplify * simplify * upgrade vitest * fix nit * fix lint * simplify * cleanup * rename `vi` to `vitest` * windows fixes * more windows annoyances * tweaks * add `test:ui` script * `tinyexec` `throwOnError: true` * revert * properly terminate child processes * dont skip storybook * cleanup on failure to load the page * unused * newline * use vitest workspaces * add `try-catch` while killing processes * increase navigation timeout * apply merge changes * fix timeout * add retries * remove storybook log * cleanup cli package * simplify * fix lucia tests * dont print external command output while testing * fix storybook * fixes * format before evaluating test * fix dir path * setup matrix * skip running docker containers outside of linux runners * print console output? * fix lint? * force `npm` for storybook? * Revert "force `npm` for storybook?" This reverts commit ef2df6e. * try latest * Revert "try latest" This reverts commit 1c095d6. * Revert "print console output?" This reverts commit 9d5b6b2. * skip runnung storybook tests in ci on windows * improve * missing filename * enhance tests * pipe stdio during tests * skip storybook * fixes * fix test * fix: apply defaults to unspecified options * unpin storybook and remove skipping windows ci * use `defineProject` instead for better type safety in a workspace * remove silent flag * use latest * temp log * unwrap * clear cache and log cause * move it along * run sequentially * revert * test * exclude windows from running concurrently * tweaks * dont return string from `file` function * improve `unsupported` * log `stderr` on failed dep installs * tweak error * simplify * fixes and tweaks * fix --------- Co-authored-by: AdrianGonz97 <[email protected]>
1 parent 674cb58 commit 9da497f

File tree

31 files changed

+1434
-1576
lines changed

31 files changed

+1434
-1576
lines changed

community-adder-template/src/index.js

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,23 @@ export const options = defineAdderOptions({
1212

1313
export default defineAdder({
1414
id: 'community-addon',
15-
environments: { kit: true, svelte: true },
1615
options,
17-
packages: [],
18-
files: [
19-
{
20-
name: () => 'adder-template-demo.txt',
21-
content: ({ content, options }) => {
22-
if (options.demo) {
23-
return 'This is a text file made by the Community Adder Template demo!';
24-
}
25-
return content;
16+
setup: ({ kit, unsupported }) => {
17+
if (!kit) unsupported('Requires SvelteKit');
18+
},
19+
run: ({ sv, options, typescript }) => {
20+
sv.file('adder-template-demo.txt', (content) => {
21+
if (options.demo) {
22+
return 'This is a text file made by the Community Adder Template demo!';
2623
}
27-
},
28-
{
29-
name: () => 'src/DemoComponent.svelte',
30-
content: ({ content, options, typescript }) => {
31-
if (!options.demo) return content;
32-
const { script, generateCode } = parseSvelte(content, { typescript });
33-
imports.addDefault(script.ast, '../adder-template-demo.txt?raw', 'demo');
34-
return generateCode({ script: script.generateCode(), template: '{demo}' });
35-
}
36-
}
37-
]
24+
return content;
25+
});
26+
27+
sv.file('src/DemoComponent.svelte', (content) => {
28+
if (!options.demo) return content;
29+
const { script, generateCode } = parseSvelte(content, { typescript });
30+
imports.addDefault(script.ast, '../adder-template-demo.txt?raw', 'demo');
31+
return generateCode({ script: script.generateCode(), template: '{demo}' });
32+
});
33+
}
3834
});

packages/adders/_config/official.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const officialAdders = [
2424
mdsvex,
2525
paraglide,
2626
storybook
27-
];
27+
] as AdderWithoutExplicitArgs[];
2828

2929
export function getAdderDetails(id: string): AdderWithoutExplicitArgs {
3030
const details = officialAdders.find((a) => a.id === id);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import process from 'node:process';
2+
import { expect } from '@playwright/test';
3+
import { setupTest } from '../_setup/suite.ts';
4+
import { officialAdders } from '../../index.ts';
5+
import type { AddonMap, OptionMap } from 'sv';
6+
7+
const windowsCI = process.env.CI && process.platform === 'win32';
8+
const addons = officialAdders.reduce<AddonMap>((addonMap, addon) => {
9+
if (addon.id === 'storybook' && windowsCI) return addonMap;
10+
addonMap[addon.id] = addon;
11+
return addonMap;
12+
}, {});
13+
14+
const defaultOptions = officialAdders.reduce<OptionMap<typeof addons>>((options, addon) => {
15+
options[addon.id] = {};
16+
return options;
17+
}, {});
18+
19+
const { test, variants, prepareServer } = setupTest(addons);
20+
21+
const kitOnly = variants.filter((v) => v.startsWith('kit'));
22+
test.concurrent.for(kitOnly)('run all addons - %s', async (variant, { page, ...ctx }) => {
23+
const cwd = await ctx.run(variant, defaultOptions);
24+
25+
const { close } = await prepareServer({ cwd, page });
26+
// kill server process when we're done
27+
ctx.onTestFinished(async () => await close());
28+
29+
expect(true).toBe(true);
30+
});

packages/adders/_tests/eslint/test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { execSync } from 'node:child_process';
14
import { expect } from '@playwright/test';
25
import { setupTest } from '../_setup/suite.ts';
36
import eslint from '../../eslint/index.ts';
@@ -11,5 +14,12 @@ test.concurrent.for(variants)('core - %s', async (variant, { page, ...ctx }) =>
1114
// kill server process when we're done
1215
ctx.onTestFinished(async () => await close());
1316

14-
expect(true).toBe(true);
17+
const unlintedFile = 'let foo = "";\nif (Boolean(foo)) {\n//\n}';
18+
fs.writeFileSync(path.resolve(cwd, 'foo.js'), unlintedFile, 'utf8');
19+
20+
expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).toThrowError();
21+
22+
expect(() => execSync('pnpm eslint --fix .', { cwd, stdio: 'pipe' })).not.toThrowError();
23+
24+
expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).not.toThrowError();
1525
});

packages/adders/_tests/prettier/test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { execSync } from 'node:child_process';
14
import { expect } from '@playwright/test';
25
import { setupTest } from '../_setup/suite.ts';
36
import prettier from '../../prettier/index.ts';
@@ -11,5 +14,12 @@ test.concurrent.for(variants)('core - %s', async (variant, { page, ...ctx }) =>
1114
// kill server process when we're done
1215
ctx.onTestFinished(async () => await close());
1316

14-
expect(true).toBe(true);
17+
const unformattedFile = 'const foo = "bar"';
18+
fs.writeFileSync(path.resolve(cwd, 'foo.js'), unformattedFile, 'utf8');
19+
20+
expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).toThrowError();
21+
22+
expect(() => execSync('pnpm format', { cwd, stdio: 'pipe' })).not.toThrowError();
23+
24+
expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).not.toThrowError();
1525
});

packages/adders/_tests/storybook/test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ const { test, variants, prepareServer } = setupTest({ storybook });
77

88
let port = 6006;
99

10-
const skip = process.env.CI && process.platform === 'win32';
11-
test.skipIf(skip).concurrent.for(variants)(
10+
const windowsCI = process.env.CI && process.platform === 'win32';
11+
test.for(variants)(
1212
'storybook loaded - %s',
13+
{ concurrent: !windowsCI },
1314
async (variant, { page, ...ctx }) => {
1415
const cwd = await ctx.run(variant, { storybook: {} });
1516

packages/adders/common.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { imports, exports, common } from '@sveltejs/cli-core/js';
2-
import { type Question, type FileEditor } from '@sveltejs/cli-core';
32
import { parseScript, parseSvelte } from '@sveltejs/cli-core/parsers';
43

5-
export function addEslintConfigPrettier({ content }: FileEditor<Record<string, Question>>): string {
4+
export function addEslintConfigPrettier(content: string): string {
65
const { ast, generateCode } = parseScript(content);
76

87
// if a default import for `eslint-plugin-svelte` already exists, then we'll use their specifier's name instead
@@ -65,10 +64,7 @@ export function addEslintConfigPrettier({ content }: FileEditor<Record<string, Q
6564
return generateCode();
6665
}
6766

68-
export function addToDemoPage(
69-
{ content }: FileEditor<Record<string, Question>>,
70-
path: string
71-
): string {
67+
export function addToDemoPage(content: string, path: string): string {
7268
const { template, generateCode } = parseSvelte(content);
7369

7470
for (const node of template.ast.childNodes) {

0 commit comments

Comments
 (0)