Skip to content

Commit

Permalink
chore: simpler / more flexible api (#181)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
manuel3108 and AdrianGonz97 authored Nov 14, 2024
1 parent 674cb58 commit 9da497f
Show file tree
Hide file tree
Showing 31 changed files with 1,434 additions and 1,576 deletions.
38 changes: 17 additions & 21 deletions community-adder-template/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,23 @@ export const options = defineAdderOptions({

export default defineAdder({
id: 'community-addon',
environments: { kit: true, svelte: true },
options,
packages: [],
files: [
{
name: () => 'adder-template-demo.txt',
content: ({ content, options }) => {
if (options.demo) {
return 'This is a text file made by the Community Adder Template demo!';
}
return content;
setup: ({ kit, unsupported }) => {
if (!kit) unsupported('Requires SvelteKit');
},
run: ({ sv, options, typescript }) => {
sv.file('adder-template-demo.txt', (content) => {
if (options.demo) {
return 'This is a text file made by the Community Adder Template demo!';
}
},
{
name: () => 'src/DemoComponent.svelte',
content: ({ content, options, typescript }) => {
if (!options.demo) return content;
const { script, generateCode } = parseSvelte(content, { typescript });
imports.addDefault(script.ast, '../adder-template-demo.txt?raw', 'demo');
return generateCode({ script: script.generateCode(), template: '{demo}' });
}
}
]
return content;
});

sv.file('src/DemoComponent.svelte', (content) => {
if (!options.demo) return content;
const { script, generateCode } = parseSvelte(content, { typescript });
imports.addDefault(script.ast, '../adder-template-demo.txt?raw', 'demo');
return generateCode({ script: script.generateCode(), template: '{demo}' });
});
}
});
2 changes: 1 addition & 1 deletion packages/adders/_config/official.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const officialAdders = [
mdsvex,
paraglide,
storybook
];
] as AdderWithoutExplicitArgs[];

export function getAdderDetails(id: string): AdderWithoutExplicitArgs {
const details = officialAdders.find((a) => a.id === id);
Expand Down
30 changes: 30 additions & 0 deletions packages/adders/_tests/all-addons/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import process from 'node:process';
import { expect } from '@playwright/test';
import { setupTest } from '../_setup/suite.ts';
import { officialAdders } from '../../index.ts';
import type { AddonMap, OptionMap } from 'sv';

const windowsCI = process.env.CI && process.platform === 'win32';
const addons = officialAdders.reduce<AddonMap>((addonMap, addon) => {
if (addon.id === 'storybook' && windowsCI) return addonMap;
addonMap[addon.id] = addon;
return addonMap;
}, {});

const defaultOptions = officialAdders.reduce<OptionMap<typeof addons>>((options, addon) => {
options[addon.id] = {};
return options;
}, {});

const { test, variants, prepareServer } = setupTest(addons);

const kitOnly = variants.filter((v) => v.startsWith('kit'));
test.concurrent.for(kitOnly)('run all addons - %s', async (variant, { page, ...ctx }) => {
const cwd = await ctx.run(variant, defaultOptions);

const { close } = await prepareServer({ cwd, page });
// kill server process when we're done
ctx.onTestFinished(async () => await close());

expect(true).toBe(true);
});
12 changes: 11 additions & 1 deletion packages/adders/_tests/eslint/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import fs from 'node:fs';
import path from 'node:path';
import { execSync } from 'node:child_process';
import { expect } from '@playwright/test';
import { setupTest } from '../_setup/suite.ts';
import eslint from '../../eslint/index.ts';
Expand All @@ -11,5 +14,12 @@ test.concurrent.for(variants)('core - %s', async (variant, { page, ...ctx }) =>
// kill server process when we're done
ctx.onTestFinished(async () => await close());

expect(true).toBe(true);
const unlintedFile = 'let foo = "";\nif (Boolean(foo)) {\n//\n}';
fs.writeFileSync(path.resolve(cwd, 'foo.js'), unlintedFile, 'utf8');

expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).toThrowError();

expect(() => execSync('pnpm eslint --fix .', { cwd, stdio: 'pipe' })).not.toThrowError();

expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).not.toThrowError();
});
12 changes: 11 additions & 1 deletion packages/adders/_tests/prettier/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import fs from 'node:fs';
import path from 'node:path';
import { execSync } from 'node:child_process';
import { expect } from '@playwright/test';
import { setupTest } from '../_setup/suite.ts';
import prettier from '../../prettier/index.ts';
Expand All @@ -11,5 +14,12 @@ test.concurrent.for(variants)('core - %s', async (variant, { page, ...ctx }) =>
// kill server process when we're done
ctx.onTestFinished(async () => await close());

expect(true).toBe(true);
const unformattedFile = 'const foo = "bar"';
fs.writeFileSync(path.resolve(cwd, 'foo.js'), unformattedFile, 'utf8');

expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).toThrowError();

expect(() => execSync('pnpm format', { cwd, stdio: 'pipe' })).not.toThrowError();

expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).not.toThrowError();
});
5 changes: 3 additions & 2 deletions packages/adders/_tests/storybook/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const { test, variants, prepareServer } = setupTest({ storybook });

let port = 6006;

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

Expand Down
8 changes: 2 additions & 6 deletions packages/adders/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { imports, exports, common } from '@sveltejs/cli-core/js';
import { type Question, type FileEditor } from '@sveltejs/cli-core';
import { parseScript, parseSvelte } from '@sveltejs/cli-core/parsers';

export function addEslintConfigPrettier({ content }: FileEditor<Record<string, Question>>): string {
export function addEslintConfigPrettier(content: string): string {
const { ast, generateCode } = parseScript(content);

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

export function addToDemoPage(
{ content }: FileEditor<Record<string, Question>>,
path: string
): string {
export function addToDemoPage(content: string, path: string): string {
const { template, generateCode } = parseSvelte(content);

for (const node of template.ast.childNodes) {
Expand Down
Loading

0 comments on commit 9da497f

Please sign in to comment.