@blankways/ui 0.0.0-stage → 0.2.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 +246 -2
- package/dist/cli/cli.options.d.ts +5 -0
- package/dist/cli/cli.options.js +73 -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 +33 -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 +48 -0
- package/dist/commands/add.command.d.ts +4 -0
- package/dist/commands/add.command.js +49 -0
- package/dist/commands/dev.command.d.ts +3 -0
- package/dist/commands/dev.command.js +76 -0
- package/dist/commands/doctor.command.d.ts +3 -0
- package/dist/commands/doctor.command.js +103 -0
- package/dist/commands/index.d.ts +9 -0
- package/dist/commands/index.js +9 -0
- package/dist/commands/init.command.d.ts +2 -0
- package/dist/commands/init.command.js +43 -0
- package/dist/commands/install.command.d.ts +2 -0
- package/dist/commands/install.command.js +36 -0
- package/dist/commands/list.command.d.ts +2 -0
- package/dist/commands/list.command.js +59 -0
- package/dist/commands/meta.command.d.ts +1 -0
- package/dist/commands/meta.command.js +19 -0
- package/dist/commands/registry.command.d.ts +2 -0
- package/dist/commands/registry.command.js +69 -0
- package/dist/commands/styles.command.d.ts +5 -0
- package/dist/commands/styles.command.js +44 -0
- package/dist/config/config.helpers.d.ts +10 -0
- package/dist/config/config.helpers.js +116 -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 +20 -0
- package/dist/constants/cli.constants.js +20 -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/barrels.check.d.ts +1 -0
- package/dist/doctor/checks/barrels.check.js +60 -0
- package/dist/doctor/checks/contracts.check.d.ts +1 -0
- package/dist/doctor/checks/contracts.check.js +45 -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 +60 -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 +10 -0
- package/dist/doctor/checks/index.js +10 -0
- package/dist/doctor/checks/motion.check.d.ts +1 -0
- package/dist/doctor/checks/motion.check.js +66 -0
- package/dist/doctor/checks/namespaces.check.d.ts +1 -0
- package/dist/doctor/checks/namespaces.check.js +76 -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 +42 -0
- package/dist/doctor/doctor.helpers.d.ts +6 -0
- package/dist/doctor/doctor.helpers.js +43 -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 +31 -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 +6 -0
- package/dist/helpers/args.helpers.js +84 -0
- package/dist/helpers/barrels.helpers.d.ts +15 -0
- package/dist/helpers/barrels.helpers.js +157 -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 +12 -0
- package/dist/index.js +11 -0
- package/dist/registry/index.d.ts +3 -0
- package/dist/registry/index.js +3 -0
- package/dist/registry/lockfile.d.ts +18 -0
- package/dist/registry/lockfile.js +32 -0
- package/dist/registry/registry.helpers.d.ts +12 -0
- package/dist/registry/registry.helpers.js +242 -0
- package/dist/registry/registry.providers.d.ts +13 -0
- package/dist/registry/registry.providers.js +159 -0
- package/dist/registry/registry.service.d.ts +14 -0
- package/dist/registry/registry.service.js +126 -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 +70 -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 +68 -0
- package/dist/types/registry.types.js +3 -0
- package/dist/ui-api/index.d.ts +16 -0
- package/dist/ui-api/index.js +30 -0
- package/dist/ui-api/ui-api.d.ts +18 -0
- package/dist/ui-api/ui-api.js +194 -0
- package/package.json +37 -3
- package/styles.css +16 -0
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
registries?: readonly string[];
|
|
15
|
+
globalCss?: string;
|
|
16
|
+
items?: import('../types/registry.types.js').RegistryItem[];
|
|
17
|
+
providers?: import('../types/registry.types.js').RegistryProvider[];
|
|
18
|
+
lock?: import('../registry/lockfile.js').Lockfile;
|
|
19
|
+
};
|
|
20
|
+
export type DoctorCheckResult = {
|
|
21
|
+
summary?: string;
|
|
22
|
+
problems?: DoctorProblem[];
|
|
23
|
+
};
|
|
24
|
+
export type DoctorCheck = {
|
|
25
|
+
id: string;
|
|
26
|
+
run(context: DoctorContext): Promise<DoctorCheckResult | null> | DoctorCheckResult | null;
|
|
27
|
+
};
|
|
28
|
+
export type DoctorReport = {
|
|
29
|
+
id: string;
|
|
30
|
+
result: DoctorCheckResult;
|
|
31
|
+
};
|
|
@@ -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,6 @@
|
|
|
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;
|
|
5
|
+
/** Reads a comma-separated string flag as a deduplicated list. */
|
|
6
|
+
export declare function getStringListFlag(flags: Record<string, FlagValue>, key: string): string[] | undefined;
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
'frozen',
|
|
15
|
+
'installPeers',
|
|
16
|
+
'yes'
|
|
17
|
+
]);
|
|
18
|
+
function normalizeFlag(raw) {
|
|
19
|
+
const withoutDashes = raw.startsWith('--') ? raw.slice(2) : raw.replace(/^-/, '');
|
|
20
|
+
return withoutDashes.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
21
|
+
}
|
|
22
|
+
function splitFlag(token) {
|
|
23
|
+
const equalsIndex = token.indexOf('=');
|
|
24
|
+
if (equalsIndex === -1)
|
|
25
|
+
return [token, undefined];
|
|
26
|
+
return [token.slice(0, equalsIndex), token.slice(equalsIndex + 1)];
|
|
27
|
+
}
|
|
28
|
+
export function parseArgs(argv) {
|
|
29
|
+
const flags = {};
|
|
30
|
+
const positionals = [];
|
|
31
|
+
let index = 0;
|
|
32
|
+
while (index < argv.length) {
|
|
33
|
+
const token = argv[index];
|
|
34
|
+
if (token === '--') {
|
|
35
|
+
positionals.push(...argv.slice(index + 1));
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
if (token.startsWith('-')) {
|
|
39
|
+
const [rawKey, inlineValue] = splitFlag(token);
|
|
40
|
+
const key = SHORT_FLAGS[rawKey] ?? normalizeFlag(rawKey);
|
|
41
|
+
if (inlineValue !== undefined) {
|
|
42
|
+
flags[key] = inlineValue;
|
|
43
|
+
index += 1;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (BOOLEAN_FLAGS.has(key)) {
|
|
47
|
+
flags[key] = true;
|
|
48
|
+
index += 1;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const next = argv[index + 1];
|
|
52
|
+
if (next !== undefined && !next.startsWith('-')) {
|
|
53
|
+
flags[key] = next;
|
|
54
|
+
index += 2;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
flags[key] = true;
|
|
58
|
+
index += 1;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
positionals.push(token);
|
|
62
|
+
index += 1;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
command: positionals[0],
|
|
66
|
+
names: positionals.slice(1),
|
|
67
|
+
flags
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function getStringFlag(flags, key) {
|
|
71
|
+
const value = flags[key];
|
|
72
|
+
return typeof value === 'string' ? value : undefined;
|
|
73
|
+
}
|
|
74
|
+
export function isFlagEnabled(flags, key) {
|
|
75
|
+
const value = flags[key];
|
|
76
|
+
return value === true || value === 'true';
|
|
77
|
+
}
|
|
78
|
+
/** Reads a comma-separated string flag as a deduplicated list. */
|
|
79
|
+
export function getStringListFlag(flags, key) {
|
|
80
|
+
const value = getStringFlag(flags, key);
|
|
81
|
+
if (value === undefined)
|
|
82
|
+
return undefined;
|
|
83
|
+
return Array.from(new Set(value.split(',').map(entry => entry.trim()).filter(Boolean)));
|
|
84
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type BarrelsSyncOptions = {
|
|
2
|
+
cwd: string;
|
|
3
|
+
componentsDir: string;
|
|
4
|
+
globalCss?: string;
|
|
5
|
+
themeOrder?: readonly string[];
|
|
6
|
+
dryRun?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type BarrelsSyncResult = {
|
|
9
|
+
barrels: string[];
|
|
10
|
+
css?: string;
|
|
11
|
+
importLine?: string;
|
|
12
|
+
changed: boolean;
|
|
13
|
+
};
|
|
14
|
+
/** Regenerates the generated entry points of the namespaced layout. */
|
|
15
|
+
export declare function syncBarrels(options: BarrelsSyncOptions): Promise<BarrelsSyncResult>;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { mkdir, readFile, readdir, stat, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
3
|
+
import { BASE_STYLE_IMPORT, RUNTIMES_SUBDIR, THEMES_SUBDIR } from '../constants/index.js';
|
|
4
|
+
import { findGlobalStylesheet, toCssImport } from './styles.helpers.js';
|
|
5
|
+
async function isFile(path) {
|
|
6
|
+
try {
|
|
7
|
+
return (await stat(path)).isFile();
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function walk(directory, prefix = '') {
|
|
14
|
+
const output = [];
|
|
15
|
+
let entries;
|
|
16
|
+
try {
|
|
17
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return output;
|
|
21
|
+
}
|
|
22
|
+
for (const entry of entries) {
|
|
23
|
+
const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
24
|
+
const fullPath = join(directory, entry.name);
|
|
25
|
+
if (entry.isDirectory()) {
|
|
26
|
+
output.push(...(await walk(fullPath, relativePath)));
|
|
27
|
+
}
|
|
28
|
+
else if (entry.isFile()) {
|
|
29
|
+
output.push(relativePath);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return output;
|
|
33
|
+
}
|
|
34
|
+
function peerOf(relativePath) {
|
|
35
|
+
return relativePath.split('/')[0] ?? '';
|
|
36
|
+
}
|
|
37
|
+
function orderedPeers(peers, themeOrder) {
|
|
38
|
+
const rank = (peer) => {
|
|
39
|
+
const index = themeOrder.indexOf(peer);
|
|
40
|
+
return index === -1 ? themeOrder.length : index;
|
|
41
|
+
};
|
|
42
|
+
return [...peers].sort((a, b) => rank(a) - rank(b) || a.localeCompare(b));
|
|
43
|
+
}
|
|
44
|
+
const CSS_ORDER = ['tokens', 'base', 'components', 'utilities', 'motion'];
|
|
45
|
+
function compareCss(left, right) {
|
|
46
|
+
const rank = (file) => {
|
|
47
|
+
const name = basename(file).replace(/\.css$/, '');
|
|
48
|
+
const index = CSS_ORDER.indexOf(name);
|
|
49
|
+
return index === -1 ? CSS_ORDER.length : index;
|
|
50
|
+
};
|
|
51
|
+
return rank(left) - rank(right) || left.localeCompare(right);
|
|
52
|
+
}
|
|
53
|
+
function buildThemesBarrel(files, themeOrder) {
|
|
54
|
+
const css = files.filter(file => file.endsWith('.css') && !file.endsWith('/index.css'));
|
|
55
|
+
const peers = orderedPeers(Array.from(new Set(css.map(peerOf))), themeOrder);
|
|
56
|
+
const lines = [`@import '${BASE_STYLE_IMPORT}';`];
|
|
57
|
+
for (const peer of peers) {
|
|
58
|
+
for (const file of css.filter(item => peerOf(item) === peer).sort(compareCss)) {
|
|
59
|
+
lines.push(`@import './${file}';`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return `${lines.join('\n')}\n`;
|
|
63
|
+
}
|
|
64
|
+
function buildPeerRuntimeBarrel(files) {
|
|
65
|
+
const names = files
|
|
66
|
+
.filter(file => /\.tsx?$/.test(file) && !file.endsWith('/index.ts'))
|
|
67
|
+
.map(file => basename(file).replace(/\.tsx?$/, ''))
|
|
68
|
+
.sort();
|
|
69
|
+
if (names.length === 0)
|
|
70
|
+
return null;
|
|
71
|
+
return `${names.map(name => `export * from './${name}.js'`).join('\n')}\n`;
|
|
72
|
+
}
|
|
73
|
+
function buildRuntimeBarrel(peers) {
|
|
74
|
+
if (peers.length === 0)
|
|
75
|
+
return null;
|
|
76
|
+
return `${peers.map(peer => `export * from './${peer}/index.js'`).join('\n')}\n`;
|
|
77
|
+
}
|
|
78
|
+
function withBarrelImport(content, importLine) {
|
|
79
|
+
const withoutLegacy = content
|
|
80
|
+
.split(/\r?\n/)
|
|
81
|
+
.filter(line => !/styles\/index\.css/.test(line))
|
|
82
|
+
.join('\n');
|
|
83
|
+
if (withoutLegacy.includes(importLine))
|
|
84
|
+
return withoutLegacy;
|
|
85
|
+
const tailwind = withoutLegacy.match(/@import\s+['"]tailwindcss['"]\s*;?\s*\r?\n?/);
|
|
86
|
+
if (tailwind?.index !== undefined) {
|
|
87
|
+
const index = tailwind.index + tailwind[0].length;
|
|
88
|
+
return `${withoutLegacy.slice(0, index)}${importLine}\n${withoutLegacy.slice(index)}`;
|
|
89
|
+
}
|
|
90
|
+
return `${importLine}\n${withoutLegacy.replace(/^\r?\n/, '')}`;
|
|
91
|
+
}
|
|
92
|
+
async function writeIfChanged(path, next, dryRun) {
|
|
93
|
+
let changed = true;
|
|
94
|
+
try {
|
|
95
|
+
changed = (await readFile(path, 'utf8')) !== next;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
changed = true;
|
|
99
|
+
}
|
|
100
|
+
if (changed && !dryRun) {
|
|
101
|
+
await mkdir(dirname(path), { recursive: true });
|
|
102
|
+
await writeFile(path, next, 'utf8');
|
|
103
|
+
}
|
|
104
|
+
return changed;
|
|
105
|
+
}
|
|
106
|
+
/** Regenerates the generated entry points of the namespaced layout. */
|
|
107
|
+
export async function syncBarrels(options) {
|
|
108
|
+
const root = resolve(options.cwd, options.componentsDir);
|
|
109
|
+
const themeDir = join(root, THEMES_SUBDIR);
|
|
110
|
+
const runtimeDir = join(root, RUNTIMES_SUBDIR);
|
|
111
|
+
const themeOrder = options.themeOrder ?? [];
|
|
112
|
+
const themeFiles = (await walk(themeDir)).filter(file => file !== 'index.css');
|
|
113
|
+
const runtimeFiles = (await walk(runtimeDir)).filter(file => file !== 'index.ts' && !file.endsWith('/index.ts'));
|
|
114
|
+
const result = { barrels: [], changed: false };
|
|
115
|
+
if (themeFiles.length > 0) {
|
|
116
|
+
const barrelPath = join(themeDir, 'index.css');
|
|
117
|
+
if (await writeIfChanged(barrelPath, buildThemesBarrel(themeFiles, themeOrder), Boolean(options.dryRun))) {
|
|
118
|
+
result.changed = true;
|
|
119
|
+
result.barrels.push(barrelPath);
|
|
120
|
+
}
|
|
121
|
+
const globalCss = await findGlobalStylesheet(options.cwd, barrelPath, options.globalCss);
|
|
122
|
+
if (globalCss) {
|
|
123
|
+
const importLine = toCssImport(globalCss, barrelPath);
|
|
124
|
+
const content = await readFile(globalCss, 'utf8');
|
|
125
|
+
const next = withBarrelImport(content, importLine);
|
|
126
|
+
const cssChanged = next !== content;
|
|
127
|
+
if (cssChanged && !options.dryRun)
|
|
128
|
+
await writeFile(globalCss, next, 'utf8');
|
|
129
|
+
result.css = globalCss;
|
|
130
|
+
result.importLine = importLine;
|
|
131
|
+
result.changed = result.changed || cssChanged;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (runtimeFiles.length > 0) {
|
|
135
|
+
const peers = orderedPeers(Array.from(new Set(runtimeFiles.map(peerOf))), themeOrder);
|
|
136
|
+
for (const peer of peers) {
|
|
137
|
+
const files = runtimeFiles.filter(file => peerOf(file) === peer);
|
|
138
|
+
const content = buildPeerRuntimeBarrel(files);
|
|
139
|
+
if (!content)
|
|
140
|
+
continue;
|
|
141
|
+
const path = join(runtimeDir, peer, 'index.ts');
|
|
142
|
+
if (await writeIfChanged(path, content, Boolean(options.dryRun))) {
|
|
143
|
+
result.changed = true;
|
|
144
|
+
result.barrels.push(path);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const rootBarrel = buildRuntimeBarrel(peers);
|
|
148
|
+
if (rootBarrel) {
|
|
149
|
+
const path = join(runtimeDir, 'index.ts');
|
|
150
|
+
if (await writeIfChanged(path, rootBarrel, Boolean(options.dryRun))) {
|
|
151
|
+
result.changed = true;
|
|
152
|
+
result.barrels.push(path);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
@@ -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,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public, curated build-time API of @blankways/ui.
|
|
3
|
+
*
|
|
4
|
+
* Nothing here starts a runtime in the browser: every export performs work at
|
|
5
|
+
* build time against a project root and is safe to call from a script/CI job.
|
|
6
|
+
*/
|
|
7
|
+
export { ensure, ensureAll, install, status, sync, validate } from './ui-api/index.js';
|
|
8
|
+
/** Extension points. Importing the package root never registers built-in commands. */
|
|
9
|
+
export { registerCliCommand } from './cli/cli.registry.js';
|
|
10
|
+
export { registerDoctorCheck } from './doctor/doctor.registry.js';
|
|
11
|
+
export { listRegistryItems } from './registry/registry.service.js';
|
|
12
|
+
export type { ExposureMode, InstallOptions, InstallResult, LockEntry, Lockfile } from './ui-api/index.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public, curated build-time API of @blankways/ui.
|
|
3
|
+
*
|
|
4
|
+
* Nothing here starts a runtime in the browser: every export performs work at
|
|
5
|
+
* build time against a project root and is safe to call from a script/CI job.
|
|
6
|
+
*/
|
|
7
|
+
export { ensure, ensureAll, install, status, sync, validate } from './ui-api/index.js';
|
|
8
|
+
/** Extension points. Importing the package root never registers built-in commands. */
|
|
9
|
+
export { registerCliCommand } from './cli/cli.registry.js';
|
|
10
|
+
export { registerDoctorCheck } from './doctor/doctor.registry.js';
|
|
11
|
+
export { listRegistryItems } from './registry/registry.service.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type LockEntry = {
|
|
2
|
+
revision: number;
|
|
3
|
+
files: Record<string, string>;
|
|
4
|
+
};
|
|
5
|
+
export type Lockfile = {
|
|
6
|
+
version: 1;
|
|
7
|
+
exposure: string;
|
|
8
|
+
registries: Record<string, {
|
|
9
|
+
id: string;
|
|
10
|
+
version: string;
|
|
11
|
+
}>;
|
|
12
|
+
entries: Record<string, LockEntry>;
|
|
13
|
+
};
|
|
14
|
+
export declare function createEmptyLock(exposure?: string): Lockfile;
|
|
15
|
+
export declare function readLockfile(cwd: string): Promise<Lockfile>;
|
|
16
|
+
export declare function writeLockfile(cwd: string, lock: Lockfile): Promise<void>;
|
|
17
|
+
export declare function hashContent(content: string): string;
|
|
18
|
+
export declare function hashFile(path: string): Promise<string>;
|