Skip to content

Commit 21a1ad7

Browse files
committed
feat: add npm global package support to dashboard and config API
1 parent 9dec185 commit 21a1ad7

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

src/lib/presets.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface PresetPackages {
22
cli: string[];
33
cask: string[];
4+
npm?: string[];
45
}
56

67
export const PRESET_PACKAGES: Record<string, PresetPackages> = {
@@ -68,7 +69,8 @@ export const PRESET_PACKAGES: Record<string, PresetPackages> = {
6869
'arc',
6970
'postman',
7071
'notion'
71-
]
72+
],
73+
npm: ['typescript', 'tsx', 'eslint', 'prettier', 'nodemon']
7274
},
7375
full: {
7476
cli: [
@@ -136,13 +138,14 @@ export const PRESET_PACKAGES: Record<string, PresetPackages> = {
136138
'keka',
137139
'aldente',
138140
'rectangle'
139-
]
141+
],
142+
npm: ['typescript', 'tsx', 'eslint', 'prettier', 'nodemon', 'pm2', 'serve', 'vercel', 'wrangler']
140143
}
141144
};
142145

143146
export function getPresetPackages(preset: string): string[] {
144147
const p = PRESET_PACKAGES[preset];
145-
return p ? [...p.cli, ...p.cask] : [];
148+
return p ? [...p.cli, ...p.cask, ...(p.npm || [])] : [];
146149
}
147150

148151
export const PRESET_NAMES = ['minimal', 'developer', 'full'] as const;

src/routes/[username]/[slug]/config/+server.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const GET: RequestHandler = async ({ platform, params }) => {
4848
const rawPackages: any[] = JSON.parse(config.packages || '[]');
4949
const packageNames: string[] = [];
5050
const caskNames: string[] = [];
51+
const npmNames: string[] = [];
5152

5253
for (const pkg of rawPackages) {
5354
if (typeof pkg === 'string') {
@@ -56,9 +57,13 @@ export const GET: RequestHandler = async ({ platform, params }) => {
5657
caskNames.push(pkg);
5758
}
5859
} else {
59-
packageNames.push(pkg.name);
60-
if (pkg.type === 'cask') {
61-
caskNames.push(pkg.name);
60+
if (pkg.type === 'npm') {
61+
npmNames.push(pkg.name);
62+
} else {
63+
packageNames.push(pkg.name);
64+
if (pkg.type === 'cask') {
65+
caskNames.push(pkg.name);
66+
}
6267
}
6368
}
6469
}
@@ -80,6 +85,7 @@ export const GET: RequestHandler = async ({ platform, params }) => {
8085
packages: packageNames,
8186
casks: caskNames,
8287
taps: taps,
88+
npm: npmNames,
8389
dotfiles_repo: config.dotfiles_repo || ''
8490
});
8591
};

src/routes/dashboard/+page.svelte

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
interface SearchResult {
4545
name: string;
4646
desc: string;
47-
type: 'formula' | 'cask' | 'tap';
47+
type: 'formula' | 'cask' | 'tap' | 'npm';
4848
}
4949
5050
let selectedPackages = $state(new Map<string, string>());
@@ -116,24 +116,35 @@
116116
return Array.from(selectedPackages.keys()).filter((pkg) => !presetPkgs.has(pkg));
117117
}
118118
119-
function getGroupedPackages(): { cli: string[]; apps: string[] } {
119+
function getGroupedPackages(): { cli: string[]; apps: string[]; npm: string[] } {
120120
const cli: string[] = [];
121121
const apps: string[] = [];
122+
const npm: string[] = [];
122123
for (const [pkg, t] of selectedPackages) {
123124
if (t === 'cask') apps.push(pkg);
125+
else if (t === 'npm') npm.push(pkg);
124126
else cli.push(pkg);
125127
}
126-
return { cli, apps };
128+
return { cli, apps, npm };
127129
}
128130
129131
130132
131133
function initPackagesForPreset(preset: string) {
132-
const presetPkgs = getPresetPackages(preset);
134+
const p = PRESET_PACKAGES[preset];
135+
if (!p) return;
133136
const newMap = new Map<string, string>();
134-
for (const pkg of presetPkgs) {
137+
for (const pkg of p.cli) {
135138
newMap.set(pkg, 'formula');
136139
}
140+
for (const pkg of p.cask) {
141+
newMap.set(pkg, 'cask');
142+
}
143+
if (p.npm) {
144+
for (const pkg of p.npm) {
145+
newMap.set(pkg, 'npm');
146+
}
147+
}
137148
selectedPackages = newMap;
138149
}
139150
@@ -574,6 +585,23 @@
574585
{/if}
575586
</div>
576587
</div>
588+
589+
<div class="packages-group">
590+
<div class="group-header">
591+
<span class="group-label">NPM</span>
592+
<span class="group-count">{grouped.npm.length}</span>
593+
</div>
594+
<div class="group-tags">
595+
{#each grouped.npm as pkg}
596+
<button type="button" class="pkg-tag" onclick={() => togglePackage(pkg, 'npm')}>
597+
{pkg}<span class="remove-icon">×</span>
598+
</button>
599+
{/each}
600+
{#if grouped.npm.length === 0}
601+
<span class="group-empty">No npm packages</span>
602+
{/if}
603+
</div>
604+
</div>
577605
<div class="packages-search">
578606
<input
579607
type="text"

0 commit comments

Comments
 (0)