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

next: Sidebars #1337

Merged
merged 35 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
da1df5a
init sidebar work
huntabyte Oct 20, 2024
39d1f4f
some more
huntabyte Oct 20, 2024
1827fe2
sidebar-01 ✅
huntabyte Oct 20, 2024
6778e3e
more sidebars done
huntabyte Oct 20, 2024
49ae356
9/15 😅
huntabyte Oct 20, 2024
534c350
10/15 😅
huntabyte Oct 20, 2024
369147e
11/15 😅
huntabyte Oct 20, 2024
1945a2d
12/15 💪
huntabyte Oct 20, 2024
a3e29ba
13/15 💪
huntabyte Oct 21, 2024
af501ce
14/15 💪
huntabyte Oct 21, 2024
06d8df6
15/15 💪
huntabyte Oct 21, 2024
aaab7df
add registry blocks
huntabyte Oct 21, 2024
d6a5ac0
update settings
huntabyte Oct 21, 2024
90d9b6d
next: update registry to support pages/hooks/components (#1340)
huntabyte Oct 23, 2024
ae8336e
change theme
huntabyte Oct 23, 2024
1538f48
sheeesh docs
huntabyte Oct 23, 2024
b6571e9
improve doc install steps
huntabyte Oct 23, 2024
0dc94c3
doc block things
huntabyte Oct 24, 2024
d6e2df3
fix registry script
huntabyte Oct 24, 2024
bdaca98
formatting
huntabyte Oct 24, 2024
81d0c0c
block screenshots
huntabyte Oct 24, 2024
096d6d8
update testys
huntabyte Oct 24, 2024
ec9454f
wow
huntabyte Oct 24, 2024
6e672a7
ok
huntabyte Oct 24, 2024
f202781
update templates
huntabyte Oct 24, 2024
ba2ff7f
more template things
huntabyte Oct 24, 2024
d1feaa1
more stuff
huntabyte Oct 24, 2024
df7860c
more stuff
huntabyte Oct 24, 2024
1aa7a8d
update lockfile
huntabyte Oct 24, 2024
dc866f4
style tweaks
huntabyte Oct 24, 2024
f13f38d
fix tests
huntabyte Oct 24, 2024
fc54bf3
ignore playgrounds
huntabyte Oct 24, 2024
25b929a
update bits
huntabyte Oct 24, 2024
d1c8691
update bits again
huntabyte Oct 24, 2024
9524e0b
update bits
huntabyte Oct 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ sites/docs/other/themes/dark.json
sites/docs/other/themes/light.json
sites/docs/static
sites/docs/.velite
sites/docs/src/__registry__
packages/cli/test/fixtures
playgrounds
.svelte-kit
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
"source.organizeImports": "never",
"source.removeUnusedImports": "never",
"source.removeUnused.ts": "never"
},

// Enable eslint for all supported languages
Expand Down
2 changes: 2 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export default tseslint.config(
"dist/",
".svelte-kit/**/*",
"sites/docs/.svelte-kit/**/*",
".svelte-kit",
"playgrounds/**/*",
],
}
);
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.44.1",
"globals": "^15.11.0",
"prettier": "^3.2.5",
"prettier": "^3.3.3",
"prettier-plugin-svelte": "^3.2.7",
"prettier-plugin-tailwindcss": "^0.5.12",
"prettier-plugin-tailwindcss": "^0.6.8",
"pretty-quick": "^4.0.0",
"svelte": "^5.0.0-next.264",
"svelte-eslint-parser": "^0.41.1",
"svelte-eslint-parser": "^0.42.0",
"typescript": "^5.6.3",
"typescript-eslint": "^8.10.0"
}
Expand Down
89 changes: 60 additions & 29 deletions packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import { existsSync, promises as fs } from "node:fs";
import path from "node:path";
import process from "node:process";
import color from "chalk";
import { Command } from "commander";
import { execa } from "execa";
import { existsSync, promises as fs } from "node:fs";
import path from "node:path";
import process from "node:process";
import * as v from "valibot";
import { type Config, getConfig } from "../utils/get-config.js";
import { getEnvProxy } from "../utils/get-env-proxy.js";
import { detectPM } from "../utils/auto-detect.js";
import { ConfigError, error, handleError } from "../utils/errors.js";
import {
fetchTree,
getItemTargetPath,
// getRegistryBaseColor,
getRegistryIndex,
resolveTree,
} from "../utils/registry/index.js";
import { transformImports } from "../utils/transformers.js";
import * as p from "../utils/prompts.js";
import * as cliConfig from "../utils/get-config.js";
import { getEnvProxy } from "../utils/get-env-proxy.js";
import { intro, prettifyList } from "../utils/prompt-helpers.js";
import { detectPM } from "../utils/auto-detect.js";
import * as p from "../utils/prompts.js";
import * as registry from "../utils/registry/index.js";
import { transformImports } from "../utils/transformers.js";

const highlight = (...args: unknown[]) => color.bold.cyan(...args);

Expand Down Expand Up @@ -60,13 +54,15 @@ export const add = new Command()
throw error(`The path ${color.cyan(cwd)} does not exist. Please try again.`);
}

const config = await getConfig(cwd);
const config = await cliConfig.getConfig(cwd);
if (!config) {
throw new ConfigError(
`Configuration file is missing. Please run ${color.green("init")} to create a ${highlight("components.json")} file.`
);
}

registry.setRegistry(config.registry);

await runAdd(cwd, config, options);

p.outro(`${color.green("Success!")} Component installation completed.`);
Expand All @@ -75,13 +71,13 @@ export const add = new Command()
}
});

async function runAdd(cwd: string, config: Config, options: AddOptions) {
async function runAdd(cwd: string, config: cliConfig.Config, options: AddOptions) {
if (options.proxy !== undefined) {
process.env.HTTP_PROXY = options.proxy;
p.log.info(`You are using the provided proxy: ${color.green(options.proxy)}`);
}

const registryIndex = await getRegistryIndex();
const registryIndex = await registry.getRegistryIndex();

let selectedComponents = new Set(
options.all ? registryIndex.map(({ name }) => name) : options.components
Expand Down Expand Up @@ -118,12 +114,34 @@ async function runAdd(cwd: string, config: Config, options: AddOptions) {

// adds `registryDependency` to `selectedComponents` so that they can be individually overwritten
for (const name of selectedComponents) {
const regDeps = registryDepMap.get(name);
regDeps?.forEach((dep) => selectedComponents.add(dep));
if (registryDepMap.has(name)) {
const regDeps = registryDepMap.get(name);
regDeps?.forEach((dep) => selectedComponents.add(dep));
} else {
const tree = await registry.resolveTree({
index: registryIndex,
names: [name],
includeRegDeps: true,
config,
});
for (const item of tree) {
for (const regDep of item.registryDependencies) {
selectedComponents.add(regDep);
const regDeps = registryDepMap.get(regDep);
regDeps?.forEach((dep) => selectedComponents.add(dep));
}
}
}
}

const tree = await resolveTree(registryIndex, Array.from(selectedComponents), false);
const payload = await fetchTree(config, tree);
const tree = await registry.resolveTree({
index: registryIndex,
names: Array.from(selectedComponents),
includeRegDeps: false,
config,
});

const payload = await registry.fetchTree(config, tree);
// const baseColor = await getRegistryBaseColor(config.tailwind.baseColor);

if (payload.length === 0) {
Expand All @@ -136,8 +154,11 @@ async function runAdd(cwd: string, config: Config, options: AddOptions) {
const targetPath = options.path ? path.resolve(cwd, options.path) : undefined;
for (const item of payload) {
if (selectedComponents.has(item.name) === false) continue;
for (const regDep of item.registryDependencies) {
selectedComponents.add(regDep);
}

const targetDir = getItemTargetPath(config, item, targetPath);
const targetDir = registry.getRegistryItemTargetPath(config, item.type, targetPath);
if (targetDir === null) continue;

const componentExists = item.files.some((file) => {
Expand Down Expand Up @@ -187,7 +208,7 @@ async function runAdd(cwd: string, config: Config, options: AddOptions) {
const dependencies = new Set<string>();
const tasks: p.Task[] = [];
for (const item of payload) {
const targetDir = getItemTargetPath(config, item, targetPath);
const targetDir = registry.getRegistryItemTargetPath(config, item.type, targetPath);
if (targetDir === null) continue;

if (!existsSync(targetDir)) {
Expand Down Expand Up @@ -225,14 +246,15 @@ async function runAdd(cwd: string, config: Config, options: AddOptions) {
title: `Installing ${highlight(item.name)}`,
async task() {
for (const file of item.files) {
const componentDir = path.resolve(targetDir, item.name);
const filePath = path.resolve(targetDir, item.name, file.name);
const targetDir = registry.getRegistryItemTargetPath(config, file.type);
const filePath = path.resolve(targetDir, file.target);

// Run transformers.
const content = transformImports(file.content, config);

if (!existsSync(componentDir)) {
await fs.mkdir(componentDir, { recursive: true });
const dir = path.parse(filePath).dir;
if (!existsSync(dir)) {
await fs.mkdir(dir, { recursive: true });
}

await fs.writeFile(filePath, content);
Expand All @@ -251,14 +273,23 @@ async function runAdd(cwd: string, config: Config, options: AddOptions) {
title: `${highlight(pm)}: Installing dependencies`,
enabled: dependencies.size > 0,
async task() {
await execa(pm, [add, ...dependencies], {
await execa(pm, [add, "-D", ...dependencies], {
cwd,
});
return `Dependencies installed with ${highlight(pm)}`;
},
});
}

// Update the config
tasks.push({
title: "Updating config file",
async task() {
cliConfig.writeConfig(cwd, config);
return `Config file ${highlight("components.json")} updated`;
},
});

await p.tasks(tasks);

if (!options.deps) {
Expand Down
Loading