@blankways/ui 0.0.0-stage → 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +228 -2
- package/dist/cli/cli.options.d.ts +5 -0
- package/dist/cli/cli.options.js +53 -0
- package/dist/cli/cli.registry.d.ts +6 -0
- package/dist/cli/cli.registry.js +37 -0
- package/dist/cli/cli.types.d.ts +32 -0
- package/dist/cli/cli.types.js +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +47 -0
- package/dist/commands/add.command.d.ts +2 -0
- package/dist/commands/add.command.js +101 -0
- package/dist/commands/doctor.command.d.ts +3 -0
- package/dist/commands/doctor.command.js +92 -0
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/index.js +6 -0
- package/dist/commands/init.command.d.ts +2 -0
- package/dist/commands/init.command.js +38 -0
- package/dist/commands/list.command.d.ts +2 -0
- package/dist/commands/list.command.js +54 -0
- package/dist/commands/meta.command.d.ts +1 -0
- package/dist/commands/meta.command.js +19 -0
- package/dist/commands/styles.command.d.ts +6 -0
- package/dist/commands/styles.command.js +68 -0
- package/dist/config/config.helpers.d.ts +7 -0
- package/dist/config/config.helpers.js +63 -0
- package/dist/config/framework.helpers.d.ts +3 -0
- package/dist/config/framework.helpers.js +14 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/constants/cli.constants.d.ts +9 -0
- package/dist/constants/cli.constants.js +15 -0
- package/dist/constants/framework.constants.d.ts +3 -0
- package/dist/constants/framework.constants.js +2 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +2 -0
- package/dist/doctor/checks/entries.check.d.ts +1 -0
- package/dist/doctor/checks/entries.check.js +21 -0
- package/dist/doctor/checks/icons.check.d.ts +1 -0
- package/dist/doctor/checks/icons.check.js +55 -0
- package/dist/doctor/checks/imports.check.d.ts +1 -0
- package/dist/doctor/checks/imports.check.js +45 -0
- package/dist/doctor/checks/index.d.ts +7 -0
- package/dist/doctor/checks/index.js +7 -0
- package/dist/doctor/checks/motion.check.d.ts +1 -0
- package/dist/doctor/checks/motion.check.js +66 -0
- package/dist/doctor/checks/peers.check.d.ts +1 -0
- package/dist/doctor/checks/peers.check.js +55 -0
- package/dist/doctor/checks/styles.check.d.ts +1 -0
- package/dist/doctor/checks/styles.check.js +45 -0
- package/dist/doctor/checks/themes.check.d.ts +1 -0
- package/dist/doctor/checks/themes.check.js +64 -0
- package/dist/doctor/doctor.helpers.d.ts +6 -0
- package/dist/doctor/doctor.helpers.js +39 -0
- package/dist/doctor/doctor.registry.d.ts +10 -0
- package/dist/doctor/doctor.registry.js +24 -0
- package/dist/doctor/doctor.types.d.ts +27 -0
- package/dist/doctor/doctor.types.js +1 -0
- package/dist/doctor/index.d.ts +3 -0
- package/dist/doctor/index.js +3 -0
- package/dist/errors/cli-error.d.ts +3 -0
- package/dist/errors/cli-error.js +6 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/helpers/args.helpers.d.ts +4 -0
- package/dist/helpers/args.helpers.js +75 -0
- package/dist/helpers/help.helpers.d.ts +1 -0
- package/dist/helpers/help.helpers.js +30 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +5 -0
- package/dist/helpers/package.helpers.d.ts +2 -0
- package/dist/helpers/package.helpers.js +12 -0
- package/dist/helpers/path.helpers.d.ts +3 -0
- package/dist/helpers/path.helpers.js +15 -0
- package/dist/helpers/styles.helpers.d.ts +21 -0
- package/dist/helpers/styles.helpers.js +164 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/registry/index.d.ts +1 -0
- package/dist/registry/index.js +1 -0
- package/dist/registry/registry.helpers.d.ts +22 -0
- package/dist/registry/registry.helpers.js +328 -0
- package/dist/registry-data/README.md +71 -0
- package/dist/registry-data/avatar/Avatar.tsx +64 -0
- package/dist/registry-data/avatar/component.json +30 -0
- package/dist/registry-data/avatar/index.ts +1 -0
- package/dist/registry-data/badge/Badge.tsx +76 -0
- package/dist/registry-data/badge/component.json +30 -0
- package/dist/registry-data/badge/index.ts +1 -0
- package/dist/registry-data/brand-logo/BrandLogo.tsx +24 -0
- package/dist/registry-data/brand-logo/component.json +26 -0
- package/dist/registry-data/brand-logo/index.ts +1 -0
- package/dist/registry-data/button/Button.tsx +76 -0
- package/dist/registry-data/button/component.json +33 -0
- package/dist/registry-data/button/index.ts +1 -0
- package/dist/registry-data/button-link/ButtonLink.tsx +83 -0
- package/dist/registry-data/button-link/component.json +33 -0
- package/dist/registry-data/button-link/index.ts +5 -0
- package/dist/registry-data/button-styles/component.json +19 -0
- package/dist/registry-data/button-styles/index.ts +45 -0
- package/dist/registry-data/cn/cn.ts +6 -0
- package/dist/registry-data/cn/component.json +16 -0
- package/dist/registry-data/confirm-dialog/ConfirmDialog.tsx +134 -0
- package/dist/registry-data/confirm-dialog/component.json +34 -0
- package/dist/registry-data/confirm-dialog/index.ts +1 -0
- package/dist/registry-data/container/Container.tsx +22 -0
- package/dist/registry-data/container/component.json +28 -0
- package/dist/registry-data/container/index.ts +1 -0
- package/dist/registry-data/cursor-glow/CursorGlow.tsx +29 -0
- package/dist/registry-data/cursor-glow/component.json +28 -0
- package/dist/registry-data/cursor-glow/index.ts +1 -0
- package/dist/registry-data/dropdown-menu/DropdownMenu.tsx +157 -0
- package/dist/registry-data/dropdown-menu/component.json +34 -0
- package/dist/registry-data/dropdown-menu/index.ts +5 -0
- package/dist/registry-data/empty-state/EmptyState.tsx +92 -0
- package/dist/registry-data/empty-state/component.json +30 -0
- package/dist/registry-data/empty-state/index.ts +5 -0
- package/dist/registry-data/eyebrow/Eyebrow.tsx +68 -0
- package/dist/registry-data/eyebrow/component.json +30 -0
- package/dist/registry-data/eyebrow/index.ts +1 -0
- package/dist/registry-data/field-styles/component.json +19 -0
- package/dist/registry-data/field-styles/index.ts +42 -0
- package/dist/registry-data/form-dialog/FormDialog.tsx +128 -0
- package/dist/registry-data/form-dialog/component.json +34 -0
- package/dist/registry-data/form-dialog/index.ts +1 -0
- package/dist/registry-data/icons/component.json +22 -0
- package/dist/registry-data/icons/index.ts +21 -0
- package/dist/registry-data/icons-form/component.json +17 -0
- package/dist/registry-data/icons-form/index.ts +1 -0
- package/dist/registry-data/icons-sidebar/component.json +17 -0
- package/dist/registry-data/icons-sidebar/index.ts +1 -0
- package/dist/registry-data/icons-theme/component.json +17 -0
- package/dist/registry-data/icons-theme/index.ts +1 -0
- package/dist/registry-data/icons-toast/component.json +17 -0
- package/dist/registry-data/icons-toast/index.ts +1 -0
- package/dist/registry-data/info-dialog/InfoDialog.tsx +119 -0
- package/dist/registry-data/info-dialog/component.json +36 -0
- package/dist/registry-data/info-dialog/index.ts +1 -0
- package/dist/registry-data/input/Input.tsx +96 -0
- package/dist/registry-data/input/component.json +33 -0
- package/dist/registry-data/input/index.ts +1 -0
- package/dist/registry-data/multi-combobox/MultiCombobox.tsx +205 -0
- package/dist/registry-data/multi-combobox/component.json +35 -0
- package/dist/registry-data/multi-combobox/index.ts +5 -0
- package/dist/registry-data/remote-provider/RemoteProvider.tsx +8 -0
- package/dist/registry-data/remote-provider/component.json +25 -0
- package/dist/registry-data/remote-provider/index.ts +3 -0
- package/dist/registry-data/reveal/Reveal.tsx +22 -0
- package/dist/registry-data/reveal/component.json +30 -0
- package/dist/registry-data/reveal/index.ts +1 -0
- package/dist/registry-data/section/Section.tsx +80 -0
- package/dist/registry-data/section/component.json +30 -0
- package/dist/registry-data/section/index.ts +1 -0
- package/dist/registry-data/section-heading/SectionHeading.tsx +105 -0
- package/dist/registry-data/section-heading/component.json +32 -0
- package/dist/registry-data/section-heading/index.ts +1 -0
- package/dist/registry-data/select/Select.tsx +197 -0
- package/dist/registry-data/select/component.json +34 -0
- package/dist/registry-data/select/index.ts +1 -0
- package/dist/registry-data/sidebar/Sidebar.tsx +432 -0
- package/dist/registry-data/sidebar/SidebarCollapsible.tsx +77 -0
- package/dist/registry-data/sidebar/SidebarParts.tsx +373 -0
- package/dist/registry-data/sidebar/component.json +47 -0
- package/dist/registry-data/sidebar/index.ts +4 -0
- package/dist/registry-data/sidebar/useSidebar.ts +29 -0
- package/dist/registry-data/styles-base/component.json +19 -0
- package/dist/registry-data/styles-base/index.css +67 -0
- package/dist/registry-data/styles-components/component.json +19 -0
- package/dist/registry-data/styles-components/index.css +30 -0
- package/dist/registry-data/styles-motion/component.json +20 -0
- package/dist/registry-data/styles-motion/index.css +381 -0
- package/dist/registry-data/styles-tokens/component.json +17 -0
- package/dist/registry-data/styles-tokens/index.css +77 -0
- package/dist/registry-data/styles-utilities/component.json +19 -0
- package/dist/registry-data/styles-utilities/index.css +29 -0
- package/dist/registry-data/switch/Switch.tsx +91 -0
- package/dist/registry-data/switch/component.json +34 -0
- package/dist/registry-data/switch/index.ts +1 -0
- package/dist/registry-data/tabs/Tabs.tsx +226 -0
- package/dist/registry-data/tabs/component.json +32 -0
- package/dist/registry-data/tabs/index.ts +1 -0
- package/dist/registry-data/textarea/Textarea.tsx +94 -0
- package/dist/registry-data/textarea/component.json +33 -0
- package/dist/registry-data/textarea/index.ts +1 -0
- package/dist/registry-data/theme-core/component.json +17 -0
- package/dist/registry-data/theme-core/theme.ts +84 -0
- package/dist/registry-data/theme-dark/component.json +19 -0
- package/dist/registry-data/theme-dark/index.ts +7 -0
- package/dist/registry-data/theme-light/component.json +19 -0
- package/dist/registry-data/theme-light/index.ts +7 -0
- package/dist/registry-data/theme-provider/ThemeContext.tsx +177 -0
- package/dist/registry-data/theme-provider/component.json +30 -0
- package/dist/registry-data/theme-provider/index.ts +2 -0
- package/dist/registry-data/theme-selector/ThemeSelector.tsx +269 -0
- package/dist/registry-data/theme-selector/component.json +35 -0
- package/dist/registry-data/theme-selector/selector.ts +1 -0
- package/dist/registry-data/theme-system/component.json +19 -0
- package/dist/registry-data/theme-system/index.ts +7 -0
- package/dist/registry-data/theme-toggle/ThemeToggle.tsx +71 -0
- package/dist/registry-data/theme-toggle/component.json +31 -0
- package/dist/registry-data/theme-toggle/toggle.ts +1 -0
- package/dist/registry-data/toast/Toast.tsx +260 -0
- package/dist/registry-data/toast/ToastTypeIcon.tsx +83 -0
- package/dist/registry-data/toast/component.json +43 -0
- package/dist/registry-data/toast/index.ts +3 -0
- package/dist/registry-data/toast/useToast.ts +47 -0
- package/dist/types/cli.types.d.ts +6 -0
- package/dist/types/cli.types.js +1 -0
- package/dist/types/config.types.d.ts +41 -0
- package/dist/types/config.types.js +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +3 -0
- package/dist/types/registry.types.d.ts +37 -0
- package/dist/types/registry.types.js +1 -0
- package/package.json +35 -3
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { CLI_NAME } from '../../constants/index.js';
|
|
4
|
+
import { toDisplayPath } from '../../helpers/path.helpers.js';
|
|
5
|
+
import { findGlobalStylesheet } from '../../helpers/styles.helpers.js';
|
|
6
|
+
import { isFile } from '../doctor.helpers.js';
|
|
7
|
+
import { registerDoctorCheck } from '../doctor.registry.js';
|
|
8
|
+
registerDoctorCheck({
|
|
9
|
+
id: 'styles',
|
|
10
|
+
async run(context) {
|
|
11
|
+
const styleFiles = context.files.filter(file => /[\\/]styles[\\/].*\.css$/.test(file));
|
|
12
|
+
if (styleFiles.length === 0)
|
|
13
|
+
return null;
|
|
14
|
+
const barrelPath = join(context.componentsDir, 'styles', 'index.css');
|
|
15
|
+
const problems = [];
|
|
16
|
+
if (!(await isFile(barrelPath))) {
|
|
17
|
+
problems.push({
|
|
18
|
+
level: 'warn',
|
|
19
|
+
message: `${context.displayDir}/styles/index.css is missing. Run "${CLI_NAME} styles link".`
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const globalCss = await findGlobalStylesheet(context.cwd, barrelPath, context.globalCss);
|
|
24
|
+
if (!globalCss) {
|
|
25
|
+
problems.push({
|
|
26
|
+
level: 'warn',
|
|
27
|
+
message: `No global stylesheet found. Use --global-css with "${CLI_NAME} styles link".`
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const content = await readFile(globalCss, 'utf8');
|
|
32
|
+
if (!/@import\s+['"][^'"]*styles\/index\.css['"]/.test(content)) {
|
|
33
|
+
problems.push({
|
|
34
|
+
level: 'warn',
|
|
35
|
+
message: `${toDisplayPath(context.cwd, globalCss)} does not import ${context.displayDir}/styles/index.css.`
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
summary: `${styleFiles.length} css files${problems.length > 0 ? `, ${problems.length} issues` : ''}`,
|
|
42
|
+
problems
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { isFile } from '../doctor.helpers.js';
|
|
4
|
+
import { registerDoctorCheck } from '../doctor.registry.js';
|
|
5
|
+
function parseThemeConstants(content) {
|
|
6
|
+
const names = new Set();
|
|
7
|
+
const pattern = /export\s+const\s+\w+\s*:\s*(?:Theme|ThemePreference)\s*=\s*['"]([^'"]+)['"]/g;
|
|
8
|
+
for (const match of content.matchAll(pattern)) {
|
|
9
|
+
if (match[1] !== 'system')
|
|
10
|
+
names.add(match[1]);
|
|
11
|
+
}
|
|
12
|
+
return names;
|
|
13
|
+
}
|
|
14
|
+
function parseCssThemes(content) {
|
|
15
|
+
const names = new Set();
|
|
16
|
+
for (const match of content.matchAll(/\[data-theme\s*=\s*['"]([^'"]+)['"]\]/g)) {
|
|
17
|
+
names.add(match[1]);
|
|
18
|
+
}
|
|
19
|
+
// `:root` is the default theme, so it covers `light` without an explicit block.
|
|
20
|
+
if (/\B:root\s*\{/.test(content))
|
|
21
|
+
names.add('light');
|
|
22
|
+
return names;
|
|
23
|
+
}
|
|
24
|
+
registerDoctorCheck({
|
|
25
|
+
id: 'themes',
|
|
26
|
+
async run(context) {
|
|
27
|
+
const themeFiles = context.files.filter(file => /[\\/]themes[\\/].*\.tsx?$/.test(file));
|
|
28
|
+
const constants = new Set();
|
|
29
|
+
for (const file of themeFiles) {
|
|
30
|
+
const content = await readFile(file, 'utf8');
|
|
31
|
+
for (const name of parseThemeConstants(content))
|
|
32
|
+
constants.add(name);
|
|
33
|
+
}
|
|
34
|
+
const tokensPath = join(context.componentsDir, 'styles', 'tokens.css');
|
|
35
|
+
const cssThemes = new Set();
|
|
36
|
+
if (await isFile(tokensPath)) {
|
|
37
|
+
const content = await readFile(tokensPath, 'utf8');
|
|
38
|
+
for (const name of parseCssThemes(content))
|
|
39
|
+
cssThemes.add(name);
|
|
40
|
+
}
|
|
41
|
+
const problems = [];
|
|
42
|
+
for (const name of constants) {
|
|
43
|
+
if (!cssThemes.has(name)) {
|
|
44
|
+
problems.push({
|
|
45
|
+
level: 'warn',
|
|
46
|
+
message: `"${name}" is registered but has no :root[data-theme='${name}'] block.`
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const name of cssThemes) {
|
|
51
|
+
if (!constants.has(name)) {
|
|
52
|
+
problems.push({
|
|
53
|
+
level: 'warn',
|
|
54
|
+
message: `CSS theme "${name}" has no matching constant in ${context.displayDir}/themes.`
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const names = Array.from(new Set([...constants, ...cssThemes]));
|
|
59
|
+
return {
|
|
60
|
+
summary: `${names.length} found (${names.join(', ') || 'none'})${problems.length > 0 ? `, ${problems.length} mismatches` : ''}`,
|
|
61
|
+
problems
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RegistryItem } from '../types/registry.types.js';
|
|
2
|
+
import type { DoctorContext } from './doctor.types.js';
|
|
3
|
+
export declare function isFile(path: string): Promise<boolean>;
|
|
4
|
+
export declare function readJsonFile(path: string): Promise<Record<string, unknown>>;
|
|
5
|
+
export declare function localNames(block: string): string[];
|
|
6
|
+
export declare function getInstalledItems(context: DoctorContext): Promise<RegistryItem[]>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { listRegistryItems } from '../registry/index.js';
|
|
4
|
+
export async function isFile(path) {
|
|
5
|
+
try {
|
|
6
|
+
return (await stat(path)).isFile();
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export async function readJsonFile(path) {
|
|
13
|
+
const content = (await readFile(path, 'utf8')).replace(/^\uFEFF/, '');
|
|
14
|
+
return JSON.parse(content);
|
|
15
|
+
}
|
|
16
|
+
export function localNames(block) {
|
|
17
|
+
return block
|
|
18
|
+
.split(',')
|
|
19
|
+
.map(part => part.trim())
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
.map(part => part.split(/\s+as\s+/).pop().trim());
|
|
22
|
+
}
|
|
23
|
+
export async function getInstalledItems(context) {
|
|
24
|
+
const installed = [];
|
|
25
|
+
for (const item of await listRegistryItems({ framework: context.framework })) {
|
|
26
|
+
if (item.hidden || item.files.length === 0)
|
|
27
|
+
continue;
|
|
28
|
+
let present = true;
|
|
29
|
+
for (const file of item.files) {
|
|
30
|
+
if (!(await isFile(resolve(context.componentsDir, file.target)))) {
|
|
31
|
+
present = false;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (present)
|
|
36
|
+
installed.push(item);
|
|
37
|
+
}
|
|
38
|
+
return installed;
|
|
39
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DoctorCheck } from './doctor.types.js';
|
|
2
|
+
export type DoctorRegistry = {
|
|
3
|
+
register(check: DoctorCheck): void;
|
|
4
|
+
list(): readonly DoctorCheck[];
|
|
5
|
+
clear(): void;
|
|
6
|
+
};
|
|
7
|
+
export declare function createDoctorRegistry(): DoctorRegistry;
|
|
8
|
+
export declare const doctorRegistry: DoctorRegistry;
|
|
9
|
+
export declare function registerDoctorCheck(check: DoctorCheck): void;
|
|
10
|
+
export declare function getDoctorChecks(): readonly DoctorCheck[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function createDoctorRegistry() {
|
|
2
|
+
const checks = [];
|
|
3
|
+
return {
|
|
4
|
+
register(check) {
|
|
5
|
+
if (checks.some(item => item.id === check.id)) {
|
|
6
|
+
throw new Error(`Doctor check "${check.id}" is already registered.`);
|
|
7
|
+
}
|
|
8
|
+
checks.push(check);
|
|
9
|
+
},
|
|
10
|
+
list() {
|
|
11
|
+
return [...checks];
|
|
12
|
+
},
|
|
13
|
+
clear() {
|
|
14
|
+
checks.length = 0;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export const doctorRegistry = createDoctorRegistry();
|
|
19
|
+
export function registerDoctorCheck(check) {
|
|
20
|
+
doctorRegistry.register(check);
|
|
21
|
+
}
|
|
22
|
+
export function getDoctorChecks() {
|
|
23
|
+
return doctorRegistry.list();
|
|
24
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SupportedFramework } from '../constants/index.js';
|
|
2
|
+
export type DoctorLevel = 'error' | 'warn';
|
|
3
|
+
export type DoctorProblem = {
|
|
4
|
+
level: DoctorLevel;
|
|
5
|
+
message: string;
|
|
6
|
+
};
|
|
7
|
+
export type DoctorContext = {
|
|
8
|
+
cwd: string;
|
|
9
|
+
componentsDir: string;
|
|
10
|
+
displayDir: string;
|
|
11
|
+
files: string[];
|
|
12
|
+
sourceFiles: string[];
|
|
13
|
+
framework?: SupportedFramework;
|
|
14
|
+
globalCss?: string;
|
|
15
|
+
};
|
|
16
|
+
export type DoctorCheckResult = {
|
|
17
|
+
summary?: string;
|
|
18
|
+
problems?: DoctorProblem[];
|
|
19
|
+
};
|
|
20
|
+
export type DoctorCheck = {
|
|
21
|
+
id: string;
|
|
22
|
+
run(context: DoctorContext): Promise<DoctorCheckResult | null> | DoctorCheckResult | null;
|
|
23
|
+
};
|
|
24
|
+
export type DoctorReport = {
|
|
25
|
+
id: string;
|
|
26
|
+
result: DoctorCheckResult;
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cli-error.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cli-error.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CliArgs, FlagValue } from '../types/cli.types.js';
|
|
2
|
+
export declare function parseArgs(argv: readonly string[]): CliArgs;
|
|
3
|
+
export declare function getStringFlag(flags: Record<string, FlagValue>, key: string): string | undefined;
|
|
4
|
+
export declare function isFlagEnabled(flags: Record<string, FlagValue>, key: string): boolean;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const SHORT_FLAGS = {
|
|
2
|
+
'-h': 'help',
|
|
3
|
+
'-v': 'version',
|
|
4
|
+
'-f': 'force'
|
|
5
|
+
};
|
|
6
|
+
const BOOLEAN_FLAGS = new Set([
|
|
7
|
+
'help',
|
|
8
|
+
'version',
|
|
9
|
+
'force',
|
|
10
|
+
'dryRun',
|
|
11
|
+
'all',
|
|
12
|
+
'noDeps',
|
|
13
|
+
'noImport',
|
|
14
|
+
'yes'
|
|
15
|
+
]);
|
|
16
|
+
function normalizeFlag(raw) {
|
|
17
|
+
const withoutDashes = raw.startsWith('--') ? raw.slice(2) : raw.replace(/^-/, '');
|
|
18
|
+
return withoutDashes.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
19
|
+
}
|
|
20
|
+
function splitFlag(token) {
|
|
21
|
+
const equalsIndex = token.indexOf('=');
|
|
22
|
+
if (equalsIndex === -1)
|
|
23
|
+
return [token, undefined];
|
|
24
|
+
return [token.slice(0, equalsIndex), token.slice(equalsIndex + 1)];
|
|
25
|
+
}
|
|
26
|
+
export function parseArgs(argv) {
|
|
27
|
+
const flags = {};
|
|
28
|
+
const positionals = [];
|
|
29
|
+
let index = 0;
|
|
30
|
+
while (index < argv.length) {
|
|
31
|
+
const token = argv[index];
|
|
32
|
+
if (token === '--') {
|
|
33
|
+
positionals.push(...argv.slice(index + 1));
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
if (token.startsWith('-')) {
|
|
37
|
+
const [rawKey, inlineValue] = splitFlag(token);
|
|
38
|
+
const key = SHORT_FLAGS[rawKey] ?? normalizeFlag(rawKey);
|
|
39
|
+
if (inlineValue !== undefined) {
|
|
40
|
+
flags[key] = inlineValue;
|
|
41
|
+
index += 1;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (BOOLEAN_FLAGS.has(key)) {
|
|
45
|
+
flags[key] = true;
|
|
46
|
+
index += 1;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const next = argv[index + 1];
|
|
50
|
+
if (next !== undefined && !next.startsWith('-')) {
|
|
51
|
+
flags[key] = next;
|
|
52
|
+
index += 2;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
flags[key] = true;
|
|
56
|
+
index += 1;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
positionals.push(token);
|
|
60
|
+
index += 1;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
command: positionals[0],
|
|
64
|
+
names: positionals.slice(1),
|
|
65
|
+
flags
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function getStringFlag(flags, key) {
|
|
69
|
+
const value = flags[key];
|
|
70
|
+
return typeof value === 'string' ? value : undefined;
|
|
71
|
+
}
|
|
72
|
+
export function isFlagEnabled(flags, key) {
|
|
73
|
+
const value = flags[key];
|
|
74
|
+
return value === true || value === 'true';
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function printHelp(): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getCliCommands } from '../cli/cli.registry.js';
|
|
2
|
+
import { getCliOptions } from '../cli/cli.options.js';
|
|
3
|
+
import { CLI_NAME, SUPPORTED_FRAMEWORKS } from '../constants/index.js';
|
|
4
|
+
export function printHelp() {
|
|
5
|
+
const commands = getCliCommands()
|
|
6
|
+
.filter(command => !command.hidden)
|
|
7
|
+
.sort((a, b) => (a.order ?? Number.MAX_SAFE_INTEGER) - (b.order ?? Number.MAX_SAFE_INTEGER));
|
|
8
|
+
console.log(`${CLI_NAME} — copy open UI components into your project`);
|
|
9
|
+
console.log(`Frameworks: ${SUPPORTED_FRAMEWORKS.join(', ')} (set with "${CLI_NAME} init --framework <name>")\n`);
|
|
10
|
+
console.log('Usage:');
|
|
11
|
+
for (const command of commands) {
|
|
12
|
+
console.log(` ${CLI_NAME} ${command.usage ?? command.name}`);
|
|
13
|
+
}
|
|
14
|
+
console.log('\nCommands:');
|
|
15
|
+
for (const command of commands) {
|
|
16
|
+
const aliases = command.aliases?.length ? ` (${command.aliases.join(', ')})` : '';
|
|
17
|
+
console.log(` ${(command.name + aliases).padEnd(16)} ${command.description}`);
|
|
18
|
+
}
|
|
19
|
+
console.log('\nOptions:');
|
|
20
|
+
for (const option of getCliOptions()) {
|
|
21
|
+
console.log(` ${option.flag.padEnd(24)} ${option.description}`);
|
|
22
|
+
}
|
|
23
|
+
const examples = commands.flatMap(command => command.examples ?? []);
|
|
24
|
+
if (examples.length > 0) {
|
|
25
|
+
console.log('\nExamples:');
|
|
26
|
+
for (const example of examples)
|
|
27
|
+
console.log(` ${example}`);
|
|
28
|
+
}
|
|
29
|
+
console.log('');
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
export function getPackageRoot() {
|
|
5
|
+
return resolve(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
6
|
+
}
|
|
7
|
+
export async function getPackageVersion() {
|
|
8
|
+
const packageJsonPath = resolve(getPackageRoot(), 'package.json');
|
|
9
|
+
const contents = await readFile(packageJsonPath, 'utf8');
|
|
10
|
+
const parsed = JSON.parse(contents);
|
|
11
|
+
return parsed.version ?? '0.0.0';
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
2
|
+
import { CliError } from '../errors/index.js';
|
|
3
|
+
export function resolveProjectPath(cwd, value) {
|
|
4
|
+
return isAbsolute(value) ? resolve(value) : resolve(cwd, value);
|
|
5
|
+
}
|
|
6
|
+
export function toDisplayPath(cwd, target) {
|
|
7
|
+
const value = relative(cwd, target);
|
|
8
|
+
return (value || '.').split(sep).join('/');
|
|
9
|
+
}
|
|
10
|
+
export function assertSafeRelativePath(value) {
|
|
11
|
+
const segments = value.split(/[\\/]/);
|
|
12
|
+
if (isAbsolute(value) || segments.includes('..') || segments.includes('')) {
|
|
13
|
+
throw new CliError(`Unsafe component path "${value}".`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const STYLES_BARREL_FILE = "index.css";
|
|
2
|
+
export type StylesSyncOptions = {
|
|
3
|
+
cwd: string;
|
|
4
|
+
componentsDir: string;
|
|
5
|
+
globalCss?: string;
|
|
6
|
+
dryRun?: boolean;
|
|
7
|
+
plannedStyles?: string[];
|
|
8
|
+
};
|
|
9
|
+
export type StylesSyncResult = {
|
|
10
|
+
barrel?: string;
|
|
11
|
+
css?: string;
|
|
12
|
+
importLine?: string;
|
|
13
|
+
barrelChanged: boolean;
|
|
14
|
+
cssChanged: boolean;
|
|
15
|
+
skippedReason?: 'no-styles' | 'no-global-css';
|
|
16
|
+
};
|
|
17
|
+
export declare function getStylesBarrelPath(cwd: string, componentsDir: string): string;
|
|
18
|
+
export declare function toCssImport(fromFile: string, targetFile: string): string;
|
|
19
|
+
export declare function withStyleImport(content: string, importLine: string): string;
|
|
20
|
+
export declare function findGlobalStylesheet(cwd: string, barrelPath: string, override?: string): Promise<string | null>;
|
|
21
|
+
export declare function syncStyles(options: StylesSyncOptions): Promise<StylesSyncResult>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { mkdir, readFile, readdir, stat, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import { CliError } from '../errors/index.js';
|
|
4
|
+
import { resolveProjectPath } from './path.helpers.js';
|
|
5
|
+
export const STYLES_BARREL_FILE = 'index.css';
|
|
6
|
+
const STYLE_FILE_ORDER = [
|
|
7
|
+
'tokens.css',
|
|
8
|
+
'base.css',
|
|
9
|
+
'components.css',
|
|
10
|
+
'utilities.css',
|
|
11
|
+
'motion.css'
|
|
12
|
+
];
|
|
13
|
+
const GLOBAL_CSS_CANDIDATES = [
|
|
14
|
+
'app/globals.css',
|
|
15
|
+
'src/app/globals.css',
|
|
16
|
+
'src/styles/globals.css',
|
|
17
|
+
'src/styles/index.css',
|
|
18
|
+
'styles/globals.css',
|
|
19
|
+
'styles/index.css',
|
|
20
|
+
'app/global.css',
|
|
21
|
+
'src/global.css',
|
|
22
|
+
'src/index.css',
|
|
23
|
+
'src/main.css',
|
|
24
|
+
'src/globals.css',
|
|
25
|
+
'index.css',
|
|
26
|
+
'global.css'
|
|
27
|
+
];
|
|
28
|
+
async function pathExists(path) {
|
|
29
|
+
try {
|
|
30
|
+
await stat(path);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function isFile(path) {
|
|
38
|
+
try {
|
|
39
|
+
return (await stat(path)).isFile();
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function readDirectoryNames(path) {
|
|
46
|
+
try {
|
|
47
|
+
return (await readdir(path)).map(entry => basename(entry));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function getStylesBarrelPath(cwd, componentsDir) {
|
|
54
|
+
return resolve(cwd, componentsDir, 'styles', STYLES_BARREL_FILE);
|
|
55
|
+
}
|
|
56
|
+
export function toCssImport(fromFile, targetFile) {
|
|
57
|
+
let value = relative(dirname(fromFile), targetFile)
|
|
58
|
+
.split(sep)
|
|
59
|
+
.join('/');
|
|
60
|
+
if (!value.startsWith('.'))
|
|
61
|
+
value = `./${value}`;
|
|
62
|
+
return `@import '${value}';`;
|
|
63
|
+
}
|
|
64
|
+
export function withStyleImport(content, importLine) {
|
|
65
|
+
if (content.includes(importLine))
|
|
66
|
+
return content;
|
|
67
|
+
const existing = /@import\s+['"][^'"]*styles\/index\.css['"]\s*;?/.test(content);
|
|
68
|
+
if (existing)
|
|
69
|
+
return content;
|
|
70
|
+
const tailwind = content.match(/@import\s+['"]tailwindcss['"]\s*;?\s*\r?\n?/);
|
|
71
|
+
if (tailwind && tailwind.index !== undefined) {
|
|
72
|
+
const index = tailwind.index + tailwind[0].length;
|
|
73
|
+
return `${content.slice(0, index)}${importLine}\n${content.slice(index)}`;
|
|
74
|
+
}
|
|
75
|
+
return `${importLine}\n${content}`;
|
|
76
|
+
}
|
|
77
|
+
export async function findGlobalStylesheet(cwd, barrelPath, override) {
|
|
78
|
+
if (override) {
|
|
79
|
+
const path = resolveProjectPath(cwd, override);
|
|
80
|
+
if (!(await isFile(path))) {
|
|
81
|
+
throw new CliError(`Global stylesheet not found: ${override}`);
|
|
82
|
+
}
|
|
83
|
+
return path;
|
|
84
|
+
}
|
|
85
|
+
const candidates = GLOBAL_CSS_CANDIDATES.map(name => resolve(cwd, name)).filter(path => path !== barrelPath);
|
|
86
|
+
for (const path of candidates) {
|
|
87
|
+
if (!(await isFile(path)))
|
|
88
|
+
continue;
|
|
89
|
+
const content = await readFile(path, 'utf8');
|
|
90
|
+
if (/@import\s+['"]tailwindcss['"]/.test(content))
|
|
91
|
+
return path;
|
|
92
|
+
}
|
|
93
|
+
for (const path of candidates) {
|
|
94
|
+
if (await isFile(path))
|
|
95
|
+
return path;
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
async function buildStylesBarrel(stylesDir, plannedStyles) {
|
|
100
|
+
const existing = await readDirectoryNames(stylesDir);
|
|
101
|
+
const names = new Set([
|
|
102
|
+
...existing.filter(name => name.endsWith('.css') && name !== STYLES_BARREL_FILE),
|
|
103
|
+
...plannedStyles.filter(name => name.endsWith('.css') && name !== STYLES_BARREL_FILE)
|
|
104
|
+
]);
|
|
105
|
+
if (names.size === 0)
|
|
106
|
+
return null;
|
|
107
|
+
const ordered = [
|
|
108
|
+
...STYLE_FILE_ORDER.filter(name => names.has(name)),
|
|
109
|
+
...Array.from(names)
|
|
110
|
+
.filter(name => !STYLE_FILE_ORDER.includes(name))
|
|
111
|
+
.sort()
|
|
112
|
+
];
|
|
113
|
+
const lines = ordered.map(name => `@import './${name}';`);
|
|
114
|
+
const barrelPath = join(stylesDir, STYLES_BARREL_FILE);
|
|
115
|
+
if (await pathExists(barrelPath)) {
|
|
116
|
+
const current = await readFile(barrelPath, 'utf8');
|
|
117
|
+
const missing = lines.filter(line => !current.includes(line));
|
|
118
|
+
if (missing.length === 0)
|
|
119
|
+
return null;
|
|
120
|
+
return `${missing.join('\n')}\n${current.endsWith('\n') ? '' : '\n'}${current}`;
|
|
121
|
+
}
|
|
122
|
+
return `${lines.join('\n')}\n`;
|
|
123
|
+
}
|
|
124
|
+
export async function syncStyles(options) {
|
|
125
|
+
const stylesDir = resolve(options.cwd, options.componentsDir, 'styles');
|
|
126
|
+
const plannedStyles = options.plannedStyles ?? [];
|
|
127
|
+
const hasStyles = (await readDirectoryNames(stylesDir)).length > 0 || plannedStyles.length > 0;
|
|
128
|
+
if (!hasStyles) {
|
|
129
|
+
return { barrelChanged: false, cssChanged: false, skippedReason: 'no-styles' };
|
|
130
|
+
}
|
|
131
|
+
const barrelPath = join(stylesDir, STYLES_BARREL_FILE);
|
|
132
|
+
const barrel = await buildStylesBarrel(stylesDir, plannedStyles);
|
|
133
|
+
let barrelChanged = false;
|
|
134
|
+
if (barrel !== null) {
|
|
135
|
+
barrelChanged = true;
|
|
136
|
+
if (!options.dryRun) {
|
|
137
|
+
await mkdir(stylesDir, { recursive: true });
|
|
138
|
+
await writeFile(barrelPath, barrel, 'utf8');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const cssPath = await findGlobalStylesheet(options.cwd, barrelPath, options.globalCss);
|
|
142
|
+
if (!cssPath) {
|
|
143
|
+
return {
|
|
144
|
+
barrel: barrelPath,
|
|
145
|
+
barrelChanged,
|
|
146
|
+
cssChanged: false,
|
|
147
|
+
skippedReason: 'no-global-css'
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const css = await readFile(cssPath, 'utf8');
|
|
151
|
+
const importLine = toCssImport(cssPath, barrelPath);
|
|
152
|
+
const next = withStyleImport(css, importLine);
|
|
153
|
+
const cssChanged = next !== css;
|
|
154
|
+
if (cssChanged && !options.dryRun) {
|
|
155
|
+
await writeFile(cssPath, next, 'utf8');
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
barrel: barrelPath,
|
|
159
|
+
css: cssPath,
|
|
160
|
+
importLine,
|
|
161
|
+
barrelChanged,
|
|
162
|
+
cssChanged
|
|
163
|
+
};
|
|
164
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './cli/index.js';
|
|
2
|
+
export * from './commands/index.js';
|
|
3
|
+
export * from './config/index.js';
|
|
4
|
+
export * from './constants/index.js';
|
|
5
|
+
export * from './doctor/index.js';
|
|
6
|
+
export * from './errors/index.js';
|
|
7
|
+
export * from './helpers/index.js';
|
|
8
|
+
export * from './registry/index.js';
|
|
9
|
+
export * from './types/index.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './cli/index.js';
|
|
2
|
+
export * from './commands/index.js';
|
|
3
|
+
export * from './config/index.js';
|
|
4
|
+
export * from './constants/index.js';
|
|
5
|
+
export * from './doctor/index.js';
|
|
6
|
+
export * from './errors/index.js';
|
|
7
|
+
export * from './helpers/index.js';
|
|
8
|
+
export * from './registry/index.js';
|
|
9
|
+
export * from './types/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './registry.helpers.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './registry.helpers.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type SupportedFramework } from '../constants/index.js';
|
|
2
|
+
import { type CopyResult, type RegistryItem, type RegistryKind, type ResolvedRegistryItem } from '../types/registry.types.js';
|
|
3
|
+
export declare function getRegistryRoot(): string;
|
|
4
|
+
export declare function isValidComponentName(name: string): boolean;
|
|
5
|
+
export declare function assertValidComponentName(name: string): void;
|
|
6
|
+
export declare function assertValidRegistryKind(value: string | undefined): RegistryKind | undefined;
|
|
7
|
+
export type ListRegistryOptions = {
|
|
8
|
+
framework?: SupportedFramework;
|
|
9
|
+
};
|
|
10
|
+
export declare function listRegistryItems(options?: ListRegistryOptions): Promise<RegistryItem[]>;
|
|
11
|
+
export declare function resolveRegistryItem(name: string, frameworkOption?: SupportedFramework): Promise<RegistryItem | null>;
|
|
12
|
+
export type ResolveOptions = {
|
|
13
|
+
kind?: string;
|
|
14
|
+
framework?: SupportedFramework;
|
|
15
|
+
noDeps?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare function resolveSelectedComponents(names: readonly string[], all: boolean, options?: ResolveOptions): Promise<ResolvedRegistryItem[]>;
|
|
18
|
+
export declare function copyRegistryItem(item: RegistryItem, componentsDir: string, options: {
|
|
19
|
+
cwd: string;
|
|
20
|
+
force?: boolean;
|
|
21
|
+
dryRun?: boolean;
|
|
22
|
+
}): Promise<CopyResult>;
|