Skip to content
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

feat: add create and add commands #16

Merged
merged 51 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d59d340
use `none` instead of `null`
AdrianGonz97 Aug 26, 2024
116cccd
change `default` to `demo`
AdrianGonz97 Aug 26, 2024
77920b0
initial `create` command
AdrianGonz97 Aug 26, 2024
1505c33
not needed
AdrianGonz97 Aug 29, 2024
e570384
move config directly into `adders`
AdrianGonz97 Aug 29, 2024
9de4bd8
missed a spot
AdrianGonz97 Aug 29, 2024
48d6173
run adder wizard after `create`
AdrianGonz97 Aug 29, 2024
9c316d1
initial `add` cmd implementation
AdrianGonz97 Aug 29, 2024
f47ce63
add global preconditions
AdrianGonz97 Aug 30, 2024
6d5678b
tweak types
AdrianGonz97 Aug 30, 2024
bd546da
tweak
AdrianGonz97 Aug 30, 2024
3380842
validate workspace
AdrianGonz97 Aug 30, 2024
6b5b33d
update entry
AdrianGonz97 Aug 30, 2024
767af1b
no longer necessary
AdrianGonz97 Aug 30, 2024
13a8f88
try to reduce core to its essentials
AdrianGonz97 Aug 30, 2024
4e8acbb
tweaks
AdrianGonz97 Aug 30, 2024
efa766a
log errors
AdrianGonz97 Aug 30, 2024
37b1912
word
AdrianGonz97 Aug 30, 2024
f15ba41
add community adders
AdrianGonz97 Aug 30, 2024
25786e6
lint
AdrianGonz97 Aug 30, 2024
9336428
todo
AdrianGonz97 Aug 30, 2024
1b3eb61
types
AdrianGonz97 Aug 30, 2024
876b5dc
am i going insane?
AdrianGonz97 Aug 30, 2024
8217d5c
Merge branch 'main' into feat/add-subcommands
AdrianGonz97 Aug 30, 2024
2cf6fe1
yea ok. no idea why this is only failing in CI. disabling you for now
AdrianGonz97 Aug 30, 2024
962c85a
tweaks and expose findUp
AdrianGonz97 Aug 31, 2024
bae2396
infer workspace if we're in a child directory of one
AdrianGonz97 Aug 31, 2024
2e89184
only format if there are files to format
AdrianGonz97 Aug 31, 2024
79469a0
apply code review suggestions
AdrianGonz97 Sep 2, 2024
5fc5a3d
re-enable linting rule and fix errors
manuel3108 Sep 2, 2024
e64a46b
fix type
AdrianGonz97 Sep 2, 2024
fbe1cfb
derive adder details from categories
AdrianGonz97 Sep 2, 2024
be078ad
dont prompt if a directory is specified
AdrianGonz97 Sep 2, 2024
3dd2d0a
wording
AdrianGonz97 Sep 2, 2024
a4ae9f5
prompt to install deps when `--no-adders` is set
AdrianGonz97 Sep 2, 2024
21d892f
skip install if specified
AdrianGonz97 Sep 2, 2024
bfe8153
add `sv` to the root workspace
AdrianGonz97 Sep 2, 2024
d7064cc
Merge branch 'main' into feat/add-subcommands
AdrianGonz97 Sep 3, 2024
13c0409
initial adder option flags implementation
AdrianGonz97 Sep 4, 2024
93c84b2
tweak error
AdrianGonz97 Sep 4, 2024
5c21342
fix order
AdrianGonz97 Sep 4, 2024
ec6828d
validate workspace when `--cwd` is specified
AdrianGonz97 Sep 4, 2024
ebb4f8c
adjust create template order
AdrianGonz97 Sep 4, 2024
38a62ea
add basic choices to help cmd
AdrianGonz97 Sep 4, 2024
b26c388
set initial value of the install prompt to the current pm
AdrianGonz97 Sep 4, 2024
0df1af7
tweak
AdrianGonz97 Sep 4, 2024
bc4dfdb
unnecessary
AdrianGonz97 Sep 4, 2024
ccc8cc9
print next steps for `create`
AdrianGonz97 Sep 4, 2024
31aff01
i borked it - fixed
AdrianGonz97 Sep 4, 2024
7ef6540
ugh
AdrianGonz97 Sep 4, 2024
e3950c5
silly
AdrianGonz97 Sep 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"rollup": "^4.20.0",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-preserve-shebangs": "^0.2.0",
"typescript": "^5.3.3",
"sv": "workspace:*",
"typescript": "^5.5.4",
"typescript-eslint": "^8.0.0",
"unplugin-isolated-decl": "^0.4.7"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export type CategoryKeys = 'codeQuality' | 'css' | 'db' | 'testing' | 'additional';

export type CategoryInfo = {
id: string;
id: CategoryKeys;
name: string;
description: string;
};

export type CategoryKeys = 'codeQuality' | 'css' | 'db' | 'testing' | 'additional';
export type CategoryDetails = Record<CategoryKeys, CategoryInfo>;

export type AdderCategories = Record<CategoryKeys, string[]>;
Expand All @@ -25,14 +26,14 @@ export const categories: CategoryDetails = {
name: 'CSS',
description: 'Can be used to style your components'
},
additional: {
id: 'additional',
name: 'Additional functionality',
description: ''
},
db: {
id: 'db',
name: 'Database',
description: ''
},
additional: {
id: 'additional',
name: 'Additional functionality',
description: ''
}
};
3 changes: 3 additions & 0 deletions packages/adders/_config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { adderIds, adderCategories, getAdderDetails } from './official';
export { categories, type CategoryKeys, type CategoryInfo } from './categories';
export { communityAdders } from './community';
44 changes: 44 additions & 0 deletions packages/adders/_config/official.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { AdderCategories } from './categories';
import type { AdderWithoutExplicitArgs } from '@svelte-cli/core';

// adders
import drizzle from '../drizzle';
import eslint from '../eslint';
import mdsvex from '../mdsvex';
import playwright from '../playwright';
import prettier from '../prettier';
import routify from '../routify';
import storybook from '../storybook';
import tailwindcss from '../tailwindcss';
import vitest from '../vitest';
manuel3108 marked this conversation as resolved.
Show resolved Hide resolved

const categories = {
codeQuality: [prettier, eslint],
testing: [vitest, playwright],
css: [tailwindcss],
db: [drizzle],
additional: [storybook, mdsvex, routify]
};

export const adderCategories: AdderCategories = getCategoriesById();

function getCategoriesById(): AdderCategories {
const adderCategories: any = {};
for (const [key, adders] of Object.entries(categories)) {
adderCategories[key] = adders.map((a) => a.config.metadata.id);
}
return adderCategories;
}

export const adderIds: string[] = Object.values(adderCategories).flatMap((x) => x);

const adderDetails = Object.values(categories).flat();

export function getAdderDetails(name: string): AdderWithoutExplicitArgs {
const details = adderDetails.find((a) => a.config.metadata.id === name);
if (!details) {
throw new Error(`invalid adder name: ${name}`);
}

return details as AdderWithoutExplicitArgs;
}
4 changes: 2 additions & 2 deletions packages/adders/common.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ScriptFileEditorArgs } from '@svelte-cli/core';
import type { ScriptFileEditor } from '@svelte-cli/core';
import type { Question } from '../core/internal';

export function addEslintConfigPrettier({
ast,
imports,
exports,
common
}: ScriptFileEditorArgs<Record<string, Question>>) {
}: ScriptFileEditor<Record<string, Question>>) {
// if a default import for `eslint-plugin-svelte` already exists, then we'll use their specifier's name instead
const importNodes = ast.body.filter((n) => n.type === 'ImportDeclaration');
const sveltePluginImport = importNodes.find(
Expand Down
14 changes: 6 additions & 8 deletions packages/adders/drizzle/config/adder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineAdderConfig, dedent, type TextFileEditorArgs } from '@svelte-cli/core';
import { defineAdderConfig, dedent, type TextFileEditor } from '@svelte-cli/core';
import { options as availableOptions } from './options';

const PORTS = {
Expand Down Expand Up @@ -151,7 +151,7 @@ export const adder = defineAdderConfig({
}
},
{
name: ({ typescript }) => `drizzle.config.${typescript.installed ? 'ts' : 'js'}`,
name: ({ typescript }) => `drizzle.config.${typescript ? 'ts' : 'js'}`,
contentType: 'script',
content: ({ options, ast, common, exports, typescript, imports, object }) => {
imports.addNamed(ast, 'drizzle-kit', { defineConfig: 'defineConfig' });
Expand All @@ -175,9 +175,7 @@ export const adder = defineAdderConfig({
: undefined;

object.properties(objExpression, {
schema: common.createLiteral(
`./src/lib/server/db/schema.${typescript.installed ? 'ts' : 'js'}`
),
schema: common.createLiteral(`./src/lib/server/db/schema.${typescript ? 'ts' : 'js'}`),
dbCredentials: object.create({
url: common.expressionFromString('process.env.DATABASE_URL'),
authToken
Expand All @@ -198,7 +196,7 @@ export const adder = defineAdderConfig({
},
{
name: ({ kit, typescript }) =>
`${kit.libDirectory}/server/db/schema.${typescript.installed ? 'ts' : 'js'}`,
`${kit?.libDirectory}/server/db/schema.${typescript ? 'ts' : 'js'}`,
contentType: 'script',
content: ({ ast, exports, imports, options, common, variables }) => {
let userSchemaExpression;
Expand Down Expand Up @@ -251,7 +249,7 @@ export const adder = defineAdderConfig({
},
{
name: ({ kit, typescript }) =>
`${kit.libDirectory}/server/db/index.${typescript.installed ? 'ts' : 'js'}`,
`${kit?.libDirectory}/server/db/index.${typescript ? 'ts' : 'js'}`,
contentType: 'script',
content: ({ ast, exports, imports, options, common, functions, variables }) => {
imports.addNamed(ast, '$env/dynamic/private', { env: 'env' });
Expand Down Expand Up @@ -337,7 +335,7 @@ export const adder = defineAdderConfig({
}
});

function generateEnvFileContent({ content, options }: TextFileEditorArgs<typeof availableOptions>) {
function generateEnvFileContent({ content, options }: TextFileEditor<typeof availableOptions>) {
const DB_URL_KEY = 'DATABASE_URL';
if (options.docker) {
// we'll prefill with the default docker db credentials
Expand Down
16 changes: 7 additions & 9 deletions packages/adders/drizzle/config/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export const tests = defineAdderTests({
],
files: [
{
name: ({ kit }) => `${kit.routesDirectory}/+page.svelte`,
name: ({ kit }) => `${kit?.routesDirectory}/+page.svelte`,
contentType: 'svelte',
condition: ({ kit }) => kit.installed,
condition: ({ kit }) => Boolean(kit),
manuel3108 marked this conversation as resolved.
Show resolved Hide resolved
content: ({ html, js }) => {
js.common.addFromString(js.ast, 'export let data;');
html.addFromRawHtml(
Expand All @@ -35,9 +35,9 @@ export const tests = defineAdderTests({
},
{
name: ({ kit, typescript }) =>
`${kit.routesDirectory}/+page.server.${typescript.installed ? 'ts' : 'js'}`,
`${kit?.routesDirectory}/+page.server.${typescript ? 'ts' : 'js'}`,
contentType: 'script',
condition: ({ kit }) => kit.installed,
condition: ({ kit }) => Boolean(kit),
content: ({ ast, common, typescript }) => {
common.addFromString(
ast,
Expand All @@ -53,9 +53,7 @@ export const tests = defineAdderTests({
return { users };
};

function insertUser(${
typescript.installed ? 'value: typeof user.$inferInsert' : 'value'
}) {
function insertUser(${typescript ? 'value: typeof user.$inferInsert' : 'value'}) {
return db.insert(user).values(value);
}
`
Expand All @@ -64,9 +62,9 @@ export const tests = defineAdderTests({
},
{
// override the config so we can remove strict mode
name: ({ typescript }) => `drizzle.config.${typescript.installed ? 'ts' : 'js'}`,
name: ({ typescript }) => `drizzle.config.${typescript ? 'ts' : 'js'}`,
contentType: 'text',
condition: ({ kit }) => kit.installed,
condition: ({ kit }) => Boolean(kit),
content: ({ content }) => {
return content.replace('strict: true,', '');
}
Expand Down
2 changes: 0 additions & 2 deletions packages/adders/drizzle/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

import { defineAdder } from '@svelte-cli/core';
import { adder } from './config/adder.js';
import { checks } from './config/checks.js';
Expand Down
12 changes: 6 additions & 6 deletions packages/adders/eslint/config/adder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export const adder = defineAdderConfig({
name: 'typescript-eslint',
version: '^8.0.0',
dev: true,
condition: ({ typescript }) => typescript.installed
condition: ({ typescript }) => typescript
},
{ name: 'eslint-plugin-svelte', version: '^2.36.0', dev: true },
{
name: 'eslint-config-prettier',
version: '^9.1.0',
dev: true,
condition: ({ prettier }) => prettier.installed
condition: ({ prettier }) => prettier
}
],
files: [
Expand Down Expand Up @@ -69,7 +69,7 @@ export const adder = defineAdderConfig({
const jsConfig = common.expressionFromString('js.configs.recommended');
array.push(eslintConfigs, jsConfig);

if (typescript.installed) {
if (typescript) {
const tsConfig = common.expressionFromString('ts.configs.recommended');
array.push(eslintConfigs, common.createSpreadElement(tsConfig));
}
Expand All @@ -90,7 +90,7 @@ export const adder = defineAdderConfig({
});
array.push(eslintConfigs, globalsConfig);

if (typescript.installed) {
if (typescript) {
const svelteTSParserConfig = object.create({
files: common.expressionFromString('["**/*.svelte"]'),
languageOptions: object.create({
Expand Down Expand Up @@ -118,7 +118,7 @@ export const adder = defineAdderConfig({
common.addJsDocTypeComment(defaultExport.astNode, "import('eslint').Linter.Config[]");

// imports
if (typescript.installed) imports.addDefault(ast, 'typescript-eslint', 'ts');
if (typescript) imports.addDefault(ast, 'typescript-eslint', 'ts');
imports.addDefault(ast, 'globals', 'globals');
imports.addDefault(ast, 'eslint-plugin-svelte', 'svelte');
imports.addDefault(ast, '@eslint/js', 'js');
Expand All @@ -127,7 +127,7 @@ export const adder = defineAdderConfig({
{
name: () => 'eslint.config.js',
contentType: 'script',
condition: ({ prettier }) => prettier.installed,
condition: ({ prettier }) => prettier,
content: addEslintConfigPrettier
}
]
Expand Down
2 changes: 0 additions & 2 deletions packages/adders/eslint/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

import { defineAdder } from '@svelte-cli/core';
import { adder } from './config/adder.js';
import { checks } from './config/checks.js';
Expand Down
22 changes: 1 addition & 21 deletions packages/adders/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
import type { AdderConfig, AdderWithoutExplicitArgs, Question } from '@svelte-cli/core';

export async function getAdderDetails(name: string) {
const adder: { default: AdderWithoutExplicitArgs } = await import(`./${name}/index.ts`);

return adder.default;
}

export async function getAdderConfig(name: string) {
// Mainly used by the website
// Either vite / rollup or esbuild are not able to process the shebangs
// present on the `index.js` file. That's why we directly import the configuration
// for the website here, as this is the only important part.

const adder: Promise<{ adder: AdderConfig<Record<string, Question>> }> = await import(
`./${name}/config/adder.ts`
);
const { adder: adderConfig } = await adder;

return adderConfig;
}
export * from './_config/index';
20 changes: 10 additions & 10 deletions packages/adders/mdsvex/config/tests.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import {
defineAdderTests,
type SvelteFileEditorArgs,
type TextFileEditorArgs,
type SvelteFileEditor,
type TextFileEditor,
type OptionDefinition
} from '@svelte-cli/core';
import { options } from './options';

export const tests = defineAdderTests({
files: [
{
name: ({ kit }) => `${kit.routesDirectory}/+page.svelte`,
name: ({ kit }) => `${kit?.routesDirectory}/+page.svelte`,
contentType: 'svelte',
content: useMarkdownFile,
condition: ({ kit }) => kit.installed
condition: ({ kit }) => Boolean(kit)
},
{
name: () => 'src/App.svelte',
contentType: 'svelte',
content: useMarkdownFile,
condition: ({ kit }) => !kit.installed
condition: ({ kit }) => !kit
},
{
name: ({ kit }) => `${kit.routesDirectory}/Demo.svx`,
name: ({ kit }) => `${kit?.routesDirectory}/Demo.svx`,
contentType: 'text',
content: addMarkdownFile,
condition: ({ kit }) => kit.installed
condition: ({ kit }) => Boolean(kit)
},
{
name: () => 'src/Demo.svx',
contentType: 'text',
content: addMarkdownFile,
condition: ({ kit }) => !kit.installed
condition: ({ kit }) => !kit
}
],
options,
Expand All @@ -47,7 +47,7 @@ export const tests = defineAdderTests({
]
});

function addMarkdownFile<Args extends OptionDefinition>(editor: TextFileEditorArgs<Args>) {
function addMarkdownFile<Args extends OptionDefinition>(editor: TextFileEditor<Args>) {
// example taken from website: https://mdsvex.pngwn.io
return (
editor.content +
Expand All @@ -65,7 +65,7 @@ Markdown is pretty good but sometimes you just need more.
);
}

function useMarkdownFile<Args extends OptionDefinition>({ js, html }: SvelteFileEditorArgs<Args>) {
function useMarkdownFile<Args extends OptionDefinition>({ js, html }: SvelteFileEditor<Args>) {
js.imports.addDefault(js.ast, './Demo.svx', 'Demo');

const div = html.div({ class: 'mdsvex' });
Expand Down
2 changes: 0 additions & 2 deletions packages/adders/mdsvex/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

import { defineAdder } from '@svelte-cli/core';
import { adder } from './config/adder.js';
import { tests } from './config/tests.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/adders/playwright/config/adder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const adder = defineAdderConfig({
}
},
{
name: ({ typescript }) => `e2e/demo.test.${typescript.installed ? 'ts' : 'js'}`,
name: ({ typescript }) => `e2e/demo.test.${typescript ? 'ts' : 'js'}`,
contentType: 'text',
content: ({ content }) => {
if (content) return content;
Expand All @@ -58,7 +58,7 @@ export const adder = defineAdderConfig({
}
},
{
name: ({ typescript }) => `playwright.config.${typescript.installed ? 'ts' : 'js'}`,
name: ({ typescript }) => `playwright.config.${typescript ? 'ts' : 'js'}`,
contentType: 'script',
content: ({ ast, imports, exports, common, object }) => {
const defineConfig = common.expressionFromString('defineConfig({})');
Expand Down
2 changes: 0 additions & 2 deletions packages/adders/playwright/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

import { defineAdder } from '@svelte-cli/core';
import { adder } from './config/adder.js';
import { checks } from './config/checks.js';
Expand Down
2 changes: 0 additions & 2 deletions packages/adders/prettier/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

import { defineAdder } from '@svelte-cli/core';
import { adder } from './config/adder.js';
import { checks } from './config/checks.js';
Expand Down
Loading