@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.
Files changed (117) hide show
  1. package/README.md +246 -2
  2. package/dist/cli/cli.options.d.ts +5 -0
  3. package/dist/cli/cli.options.js +73 -0
  4. package/dist/cli/cli.registry.d.ts +6 -0
  5. package/dist/cli/cli.registry.js +37 -0
  6. package/dist/cli/cli.types.d.ts +33 -0
  7. package/dist/cli/cli.types.js +1 -0
  8. package/dist/cli/index.d.ts +3 -0
  9. package/dist/cli/index.js +3 -0
  10. package/dist/cli.d.ts +2 -0
  11. package/dist/cli.js +48 -0
  12. package/dist/commands/add.command.d.ts +4 -0
  13. package/dist/commands/add.command.js +49 -0
  14. package/dist/commands/dev.command.d.ts +3 -0
  15. package/dist/commands/dev.command.js +76 -0
  16. package/dist/commands/doctor.command.d.ts +3 -0
  17. package/dist/commands/doctor.command.js +103 -0
  18. package/dist/commands/index.d.ts +9 -0
  19. package/dist/commands/index.js +9 -0
  20. package/dist/commands/init.command.d.ts +2 -0
  21. package/dist/commands/init.command.js +43 -0
  22. package/dist/commands/install.command.d.ts +2 -0
  23. package/dist/commands/install.command.js +36 -0
  24. package/dist/commands/list.command.d.ts +2 -0
  25. package/dist/commands/list.command.js +59 -0
  26. package/dist/commands/meta.command.d.ts +1 -0
  27. package/dist/commands/meta.command.js +19 -0
  28. package/dist/commands/registry.command.d.ts +2 -0
  29. package/dist/commands/registry.command.js +69 -0
  30. package/dist/commands/styles.command.d.ts +5 -0
  31. package/dist/commands/styles.command.js +44 -0
  32. package/dist/config/config.helpers.d.ts +10 -0
  33. package/dist/config/config.helpers.js +116 -0
  34. package/dist/config/framework.helpers.d.ts +3 -0
  35. package/dist/config/framework.helpers.js +14 -0
  36. package/dist/config/index.d.ts +2 -0
  37. package/dist/config/index.js +2 -0
  38. package/dist/constants/cli.constants.d.ts +20 -0
  39. package/dist/constants/cli.constants.js +20 -0
  40. package/dist/constants/framework.constants.d.ts +3 -0
  41. package/dist/constants/framework.constants.js +2 -0
  42. package/dist/constants/index.d.ts +2 -0
  43. package/dist/constants/index.js +2 -0
  44. package/dist/doctor/checks/barrels.check.d.ts +1 -0
  45. package/dist/doctor/checks/barrels.check.js +60 -0
  46. package/dist/doctor/checks/contracts.check.d.ts +1 -0
  47. package/dist/doctor/checks/contracts.check.js +45 -0
  48. package/dist/doctor/checks/entries.check.d.ts +1 -0
  49. package/dist/doctor/checks/entries.check.js +21 -0
  50. package/dist/doctor/checks/icons.check.d.ts +1 -0
  51. package/dist/doctor/checks/icons.check.js +60 -0
  52. package/dist/doctor/checks/imports.check.d.ts +1 -0
  53. package/dist/doctor/checks/imports.check.js +45 -0
  54. package/dist/doctor/checks/index.d.ts +10 -0
  55. package/dist/doctor/checks/index.js +10 -0
  56. package/dist/doctor/checks/motion.check.d.ts +1 -0
  57. package/dist/doctor/checks/motion.check.js +66 -0
  58. package/dist/doctor/checks/namespaces.check.d.ts +1 -0
  59. package/dist/doctor/checks/namespaces.check.js +76 -0
  60. package/dist/doctor/checks/peers.check.d.ts +1 -0
  61. package/dist/doctor/checks/peers.check.js +55 -0
  62. package/dist/doctor/checks/styles.check.d.ts +1 -0
  63. package/dist/doctor/checks/styles.check.js +45 -0
  64. package/dist/doctor/checks/themes.check.d.ts +1 -0
  65. package/dist/doctor/checks/themes.check.js +42 -0
  66. package/dist/doctor/doctor.helpers.d.ts +6 -0
  67. package/dist/doctor/doctor.helpers.js +43 -0
  68. package/dist/doctor/doctor.registry.d.ts +10 -0
  69. package/dist/doctor/doctor.registry.js +24 -0
  70. package/dist/doctor/doctor.types.d.ts +31 -0
  71. package/dist/doctor/doctor.types.js +1 -0
  72. package/dist/doctor/index.d.ts +3 -0
  73. package/dist/doctor/index.js +3 -0
  74. package/dist/errors/cli-error.d.ts +3 -0
  75. package/dist/errors/cli-error.js +6 -0
  76. package/dist/errors/index.d.ts +1 -0
  77. package/dist/errors/index.js +1 -0
  78. package/dist/helpers/args.helpers.d.ts +6 -0
  79. package/dist/helpers/args.helpers.js +84 -0
  80. package/dist/helpers/barrels.helpers.d.ts +15 -0
  81. package/dist/helpers/barrels.helpers.js +157 -0
  82. package/dist/helpers/help.helpers.d.ts +1 -0
  83. package/dist/helpers/help.helpers.js +30 -0
  84. package/dist/helpers/index.d.ts +5 -0
  85. package/dist/helpers/index.js +5 -0
  86. package/dist/helpers/package.helpers.d.ts +2 -0
  87. package/dist/helpers/package.helpers.js +12 -0
  88. package/dist/helpers/path.helpers.d.ts +3 -0
  89. package/dist/helpers/path.helpers.js +15 -0
  90. package/dist/helpers/styles.helpers.d.ts +21 -0
  91. package/dist/helpers/styles.helpers.js +164 -0
  92. package/dist/index.d.ts +12 -0
  93. package/dist/index.js +11 -0
  94. package/dist/registry/index.d.ts +3 -0
  95. package/dist/registry/index.js +3 -0
  96. package/dist/registry/lockfile.d.ts +18 -0
  97. package/dist/registry/lockfile.js +32 -0
  98. package/dist/registry/registry.helpers.d.ts +12 -0
  99. package/dist/registry/registry.helpers.js +242 -0
  100. package/dist/registry/registry.providers.d.ts +13 -0
  101. package/dist/registry/registry.providers.js +159 -0
  102. package/dist/registry/registry.service.d.ts +14 -0
  103. package/dist/registry/registry.service.js +126 -0
  104. package/dist/types/cli.types.d.ts +6 -0
  105. package/dist/types/cli.types.js +1 -0
  106. package/dist/types/config.types.d.ts +70 -0
  107. package/dist/types/config.types.js +1 -0
  108. package/dist/types/index.d.ts +3 -0
  109. package/dist/types/index.js +3 -0
  110. package/dist/types/registry.types.d.ts +68 -0
  111. package/dist/types/registry.types.js +3 -0
  112. package/dist/ui-api/index.d.ts +16 -0
  113. package/dist/ui-api/index.js +30 -0
  114. package/dist/ui-api/ui-api.d.ts +18 -0
  115. package/dist/ui-api/ui-api.js +194 -0
  116. package/package.json +37 -3
  117. package/styles.css +16 -0
@@ -0,0 +1,103 @@
1
+ import { readdir } from 'node:fs/promises';
2
+ import { join, resolve } from 'node:path';
3
+ import { registerCliCommand } from '../cli/cli.registry.js';
4
+ import { readConfig, resolveComponentsDir } from '../config/index.js';
5
+ import { CLI_NAME } from '../constants/index.js';
6
+ import { CliError } from '../errors/index.js';
7
+ import { toDisplayPath } from '../helpers/path.helpers.js';
8
+ import '../doctor/index.js';
9
+ import { getDoctorChecks } from '../doctor/doctor.registry.js';
10
+ import { readLockfile } from '../registry/lockfile.js';
11
+ import { loadRegistryProviders } from '../registry/registry.providers.js';
12
+ async function walkFiles(directory) {
13
+ const files = [];
14
+ let entries;
15
+ try {
16
+ entries = await readdir(directory, { withFileTypes: true });
17
+ }
18
+ catch {
19
+ return files;
20
+ }
21
+ for (const entry of entries) {
22
+ const fullPath = join(directory, entry.name);
23
+ if (entry.isDirectory()) {
24
+ files.push(...(await walkFiles(fullPath)));
25
+ }
26
+ else if (entry.isFile()) {
27
+ files.push(fullPath);
28
+ }
29
+ }
30
+ return files;
31
+ }
32
+ function status(level) {
33
+ if (level === 'error')
34
+ return 'ERROR';
35
+ return level === 'warn' ? 'WARN ' : 'OK ';
36
+ }
37
+ function reportLevel(problems) {
38
+ if (!problems || problems.length === 0)
39
+ return 'ok';
40
+ return problems.some(problem => problem.level === 'error') ? 'error' : 'warn';
41
+ }
42
+ export async function doctorCommand(options = {}) {
43
+ const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
44
+ const config = await readConfig(cwd);
45
+ if (!config) {
46
+ throw new CliError(`components.json not found. Run "${CLI_NAME} init" first.`);
47
+ }
48
+ const componentsDir = resolveComponentsDir(cwd, config, options.componentsDir);
49
+ const files = await walkFiles(componentsDir);
50
+ const registries = options.registries ?? config.registries;
51
+ const providers = await loadRegistryProviders(cwd, registries, config.framework);
52
+ const items = providers.flatMap(provider => provider.items);
53
+ const lock = await readLockfile(cwd);
54
+ const reports = [];
55
+ for (const check of getDoctorChecks()) {
56
+ const result = await check.run({
57
+ cwd,
58
+ componentsDir,
59
+ displayDir: toDisplayPath(cwd, componentsDir),
60
+ files,
61
+ sourceFiles: files.filter(file => /\.tsx?$/.test(file)),
62
+ framework: config.framework,
63
+ registries,
64
+ globalCss: options.globalCss,
65
+ items,
66
+ providers,
67
+ lock
68
+ });
69
+ if (result)
70
+ reports.push({ id: check.id, result });
71
+ }
72
+ console.log(`${CLI_NAME} doctor\n`);
73
+ for (const report of reports) {
74
+ if (!report.result.summary)
75
+ continue;
76
+ console.log(`${status(reportLevel(report.result.problems))} ${report.id}: ${report.result.summary}`);
77
+ }
78
+ const problems = reports.flatMap(report => (report.result.problems ?? []).map(problem => ({ area: report.id, problem })));
79
+ if (problems.length === 0) {
80
+ console.log('\nEverything looks good.');
81
+ return;
82
+ }
83
+ console.log('');
84
+ for (const { area, problem } of problems) {
85
+ console.log(`${status(problem.level)} ${area}: ${problem.message}`);
86
+ }
87
+ if (problems.some(({ problem }) => problem.level === 'error')) {
88
+ process.exitCode = 1;
89
+ }
90
+ }
91
+ registerCliCommand({
92
+ name: 'doctor',
93
+ description: 'Check imports, icons, themes, styles and peer packages',
94
+ usage: 'doctor [options]',
95
+ order: 40,
96
+ examples: [`${CLI_NAME} doctor`],
97
+ run: context => doctorCommand({
98
+ cwd: context.cwd,
99
+ componentsDir: context.componentsDir,
100
+ registries: context.registries,
101
+ globalCss: context.globalCss
102
+ })
103
+ });
@@ -0,0 +1,9 @@
1
+ export * from './add.command.js';
2
+ export * from './dev.command.js';
3
+ export * from './doctor.command.js';
4
+ export * from './init.command.js';
5
+ export * from './install.command.js';
6
+ export * from './list.command.js';
7
+ export * from './meta.command.js';
8
+ export * from './registry.command.js';
9
+ export * from './styles.command.js';
@@ -0,0 +1,9 @@
1
+ export * from './add.command.js';
2
+ export * from './dev.command.js';
3
+ export * from './doctor.command.js';
4
+ export * from './init.command.js';
5
+ export * from './install.command.js';
6
+ export * from './list.command.js';
7
+ export * from './meta.command.js';
8
+ export * from './registry.command.js';
9
+ export * from './styles.command.js';
@@ -0,0 +1,2 @@
1
+ import type { InitOptions } from '../types/config.types.js';
2
+ export declare function initCommand(options?: InitOptions): Promise<void>;
@@ -0,0 +1,43 @@
1
+ import { mkdir } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+ import { registerCliCommand } from '../cli/cli.registry.js';
4
+ import { assertFramework, createDefaultConfig, resolveComponentsDir, writeConfig } from '../config/index.js';
5
+ import { CLI_NAME, DEFAULT_COMPONENTS_DIR } from '../constants/index.js';
6
+ import { toDisplayPath } from '../helpers/path.helpers.js';
7
+ import { install } from '../ui-api/index.js';
8
+ import { printInstallResult } from './add.command.js';
9
+ export async function initCommand(options = {}) {
10
+ const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
11
+ const framework = assertFramework(options.framework ?? options.variant);
12
+ const registries = Array.from(new Set(options.registries ?? []));
13
+ const config = createDefaultConfig(options.componentsDir ?? DEFAULT_COMPONENTS_DIR, framework, registries);
14
+ const componentsDir = resolveComponentsDir(cwd, config);
15
+ await writeConfig(cwd, config, Boolean(options.force));
16
+ await mkdir(componentsDir, { recursive: true });
17
+ console.log('Created components.json');
18
+ console.log(`Framework: ${framework}`);
19
+ console.log(`Exposure: ${config.exposure}`);
20
+ console.log(`Created ${toDisplayPath(cwd, componentsDir)}/`);
21
+ if (registries.length === 0) {
22
+ console.log(`No registries configured. Add one with "${CLI_NAME} registry add <package>".`);
23
+ return;
24
+ }
25
+ const result = await install({ cwd, exposure: 'full', force: Boolean(options.force) });
26
+ printInstallResult(result, false);
27
+ console.log(`\nLockfile: ${toDisplayPath(cwd, resolve(cwd, 'ui.lock.json'))}`);
28
+ }
29
+ registerCliCommand({
30
+ name: 'init',
31
+ description: 'Create components.json and install the full composition of every registry',
32
+ usage: 'init [options]',
33
+ order: 10,
34
+ examples: [`${CLI_NAME} init --framework react`],
35
+ run: context => initCommand({
36
+ cwd: context.cwd,
37
+ componentsDir: context.componentsDir,
38
+ framework: context.framework,
39
+ variant: context.variant,
40
+ registries: context.registries,
41
+ force: context.force
42
+ })
43
+ });
@@ -0,0 +1,2 @@
1
+ import type { CliContext } from '../cli/cli.types.js';
2
+ export declare function installCommand(context: CliContext): Promise<void>;
@@ -0,0 +1,36 @@
1
+ import { registerCliCommand } from '../cli/cli.registry.js';
2
+ import { CLI_NAME } from '../constants/index.js';
3
+ import { toDisplayPath } from '../helpers/path.helpers.js';
4
+ import { install } from '../ui-api/index.js';
5
+ import { printInstallResult } from './add.command.js';
6
+ export async function installCommand(context) {
7
+ const result = await install({
8
+ cwd: context.cwd,
9
+ componentsDir: context.componentsDir,
10
+ registries: context.registries,
11
+ exposure: context.flags.exposure === 'full' || context.flags.exposure === 'incremental'
12
+ ? context.flags.exposure
13
+ : undefined,
14
+ force: context.force,
15
+ dryRun: context.dryRun,
16
+ frozen: context.flags.frozen === true,
17
+ installPeers: context.flags.installPeers === true,
18
+ globalCss: context.globalCss
19
+ });
20
+ printInstallResult(result, context.dryRun);
21
+ console.log(`\nLocked entries: ${result.entries.length}`);
22
+ if (context.cwd)
23
+ console.log(`Project: ${toDisplayPath(process.cwd(), context.cwd)}`);
24
+ }
25
+ registerCliCommand({
26
+ name: 'install',
27
+ description: 'Materialize the configured registries and refresh generated barrels',
28
+ usage: 'install [options]',
29
+ order: 15,
30
+ examples: [
31
+ `${CLI_NAME} install`,
32
+ `${CLI_NAME} install --frozen`,
33
+ `${CLI_NAME} install --dry-run`
34
+ ],
35
+ run: context => installCommand(context)
36
+ });
@@ -0,0 +1,2 @@
1
+ import type { ListOptions } from '../types/config.types.js';
2
+ export declare function listCommand(options?: ListOptions): Promise<void>;
@@ -0,0 +1,59 @@
1
+ import { resolve } from 'node:path';
2
+ import { registerCliCommand } from '../cli/cli.registry.js';
3
+ import { readConfig } from '../config/index.js';
4
+ import { CLI_NAME, DEFAULT_FRAMEWORK } from '../constants/index.js';
5
+ import { assertValidRegistryKind, listRegistryItems } from '../registry/index.js';
6
+ const KIND_LABELS = {
7
+ component: 'components',
8
+ icon: 'icons',
9
+ theme: 'themes',
10
+ style: 'styles',
11
+ utility: 'utilities'
12
+ };
13
+ const KIND_ORDER = ['component', 'icon', 'theme', 'style', 'utility'];
14
+ export async function listCommand(options = {}) {
15
+ const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
16
+ const config = await readConfig(cwd);
17
+ const framework = options.framework ?? config?.framework ?? DEFAULT_FRAMEWORK;
18
+ const kind = assertValidRegistryKind(options.kind);
19
+ const registries = options.registries ?? config?.registries ?? [];
20
+ const items = await listRegistryItems({ cwd, framework, registries });
21
+ const visible = items.filter(item => !item.hidden && (kind === undefined || item.kind === kind));
22
+ if (visible.length === 0) {
23
+ console.log(registries.length === 0
24
+ ? `No registries configured. Add one with "${CLI_NAME} registry add <package>".`
25
+ : kind
26
+ ? `No "${kind}" entries available for ${framework} yet.`
27
+ : `No entries available for ${framework} yet.`);
28
+ return;
29
+ }
30
+ console.log(`Available ${framework} registry entries (${visible.length}):`);
31
+ for (const group of KIND_ORDER) {
32
+ const groupItems = visible.filter(item => item.kind === group);
33
+ if (groupItems.length === 0)
34
+ continue;
35
+ console.log(`\n${KIND_LABELS[group]} (${groupItems.length}):`);
36
+ for (const item of groupItems)
37
+ printItem(item);
38
+ }
39
+ }
40
+ function printItem(item) {
41
+ console.log(` ${item.name.padEnd(18)} ${item.description}`);
42
+ console.log(`${' '.repeat(21)}registry: ${item.registry}`);
43
+ if (item.dependencies.length > 0) {
44
+ console.log(`${' '.repeat(21)}deps: ${item.dependencies.join(', ')}`);
45
+ }
46
+ }
47
+ registerCliCommand({
48
+ name: 'list',
49
+ aliases: ['ls'],
50
+ description: 'List entries grouped by kind',
51
+ usage: 'list [options]',
52
+ order: 50,
53
+ examples: [`${CLI_NAME} list --kind icon`],
54
+ run: context => listCommand({
55
+ cwd: context.cwd,
56
+ kind: context.kind,
57
+ registries: context.registries
58
+ })
59
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import { registerCliCommand } from '../cli/cli.registry.js';
2
+ import { getPackageVersion } from '../helpers/package.helpers.js';
3
+ import { printHelp } from '../helpers/help.helpers.js';
4
+ registerCliCommand({
5
+ name: 'help',
6
+ description: 'Show this help',
7
+ usage: 'help',
8
+ hidden: true,
9
+ run: () => printHelp()
10
+ });
11
+ registerCliCommand({
12
+ name: 'version',
13
+ description: 'Show the CLI version',
14
+ usage: 'version',
15
+ hidden: true,
16
+ run: async () => {
17
+ console.log(await getPackageVersion());
18
+ }
19
+ });
@@ -0,0 +1,2 @@
1
+ import type { RegistryOptions } from '../types/config.types.js';
2
+ export declare function registryCommand(options?: RegistryOptions): Promise<void>;
@@ -0,0 +1,69 @@
1
+ import { resolve } from 'node:path';
2
+ import { registerCliCommand } from '../cli/cli.registry.js';
3
+ import { readConfig, updateConfig } from '../config/index.js';
4
+ import { CLI_NAME } from '../constants/index.js';
5
+ import { CliError } from '../errors/index.js';
6
+ import { loadRegistryProvider } from '../registry/index.js';
7
+ export async function registryCommand(options = {}) {
8
+ const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
9
+ const config = await readConfig(cwd);
10
+ if (!config) {
11
+ throw new CliError(`components.json not found. Run "${CLI_NAME} init" first.`);
12
+ }
13
+ const names = options.names ?? [];
14
+ const subcommand = names[0] ?? 'list';
15
+ const values = names.slice(1);
16
+ if (subcommand === 'add') {
17
+ if (values.length === 0) {
18
+ throw new CliError('Usage: ui registry add <package...>');
19
+ }
20
+ const next = Array.from(new Set([...config.registries, ...values]));
21
+ const providers = [];
22
+ const ids = new Map();
23
+ for (const specifier of next) {
24
+ const provider = await loadRegistryProvider(cwd, specifier, config.framework);
25
+ const owner = ids.get(provider.id);
26
+ if (owner) {
27
+ throw new CliError(`Duplicate registry id "${provider.id}" declared by "${owner}" and "${specifier}".`);
28
+ }
29
+ ids.set(provider.id, specifier);
30
+ providers.push(provider);
31
+ }
32
+ config.registries = next;
33
+ await updateConfig(cwd, config);
34
+ console.log(`Registries: ${providers.map(provider => `${provider.specifier} (${provider.id})`).join(', ') || 'none'}`);
35
+ return;
36
+ }
37
+ if (subcommand === 'remove') {
38
+ if (values.length === 0) {
39
+ throw new CliError('Usage: ui registry remove <package...>');
40
+ }
41
+ const remove = new Set(values);
42
+ config.registries = config.registries.filter(specifier => !remove.has(specifier));
43
+ await updateConfig(cwd, config);
44
+ console.log(`Registries: ${config.registries.join(', ') || 'none'}`);
45
+ return;
46
+ }
47
+ if (subcommand === 'list') {
48
+ if (config.registries.length === 0) {
49
+ console.log(`No registries configured. Add one with "${CLI_NAME} registry add <package>".`);
50
+ return;
51
+ }
52
+ console.log('Configured registries:');
53
+ for (const specifier of config.registries)
54
+ console.log(` ${specifier}`);
55
+ return;
56
+ }
57
+ throw new CliError(`Unknown registry command "${subcommand}". Use add, remove or list.`);
58
+ }
59
+ registerCliCommand({
60
+ name: 'registry',
61
+ description: 'Manage the external registry packages used by this project',
62
+ usage: 'registry <add|remove|list> [package...]',
63
+ order: 60,
64
+ examples: [
65
+ `${CLI_NAME} registry add @blankways/react-registry`,
66
+ `${CLI_NAME} registry list`
67
+ ],
68
+ run: context => registryCommand({ cwd: context.cwd, names: context.names })
69
+ });
@@ -0,0 +1,5 @@
1
+ import type { CliContext } from '../cli/cli.types.js';
2
+ import type { StylesOptions } from '../types/config.types.js';
3
+ /** Kept as a compatibility alias; barrels are regenerated by every install. */
4
+ export declare function stylesLinkCommand(options?: StylesOptions): Promise<void>;
5
+ export declare function stylesCommand(context: CliContext): Promise<void>;
@@ -0,0 +1,44 @@
1
+ import { resolve } from 'node:path';
2
+ import { registerCliCommand } from '../cli/cli.registry.js';
3
+ import { CLI_NAME } from '../constants/index.js';
4
+ import { toDisplayPath } from '../helpers/path.helpers.js';
5
+ import { sync } from '../ui-api/index.js';
6
+ /** Kept as a compatibility alias; barrels are regenerated by every install. */
7
+ export async function stylesLinkCommand(options = {}) {
8
+ const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
9
+ const result = await sync({
10
+ cwd,
11
+ dryRun: options.dryRun,
12
+ globalCss: options.globalCss
13
+ });
14
+ console.log(`${CLI_NAME} styles link is deprecated: install and sync now happen together.`);
15
+ if (result.barrels.length === 0) {
16
+ console.log('No themes or runtimes installed yet.');
17
+ return;
18
+ }
19
+ for (const barrel of result.barrels) {
20
+ console.log(`Barrel: ${toDisplayPath(cwd, barrel)}`);
21
+ }
22
+ if (result.css)
23
+ console.log(`Global CSS: ${toDisplayPath(cwd, result.css)}`);
24
+ }
25
+ export async function stylesCommand(context) {
26
+ const subcommand = context.names[0] ?? 'link';
27
+ if (subcommand !== 'link') {
28
+ throw new Error(`Unknown styles command "${subcommand}". Run "${CLI_NAME} --help".`);
29
+ }
30
+ await stylesLinkCommand({
31
+ cwd: context.cwd,
32
+ componentsDir: context.componentsDir,
33
+ globalCss: context.globalCss,
34
+ dryRun: context.dryRun
35
+ });
36
+ }
37
+ registerCliCommand({
38
+ name: 'styles',
39
+ description: '[deprecated] Regenerate barrels; use install instead',
40
+ usage: 'styles link [options]',
41
+ order: 30,
42
+ examples: [`${CLI_NAME} styles link`],
43
+ run: context => stylesCommand(context)
44
+ });
@@ -0,0 +1,10 @@
1
+ import { type SupportedFramework } from '../constants/index.js';
2
+ import type { ComponentsConfig } from '../types/config.types.js';
3
+ import type { ExposureMode } from '../types/registry.types.js';
4
+ export declare function getConfigPath(cwd: string): string;
5
+ export declare function createDefaultConfig(componentsDir?: string, framework?: SupportedFramework, registries?: string[], exposure?: ExposureMode): ComponentsConfig;
6
+ export declare function readConfig(cwd: string): Promise<ComponentsConfig | null>;
7
+ export declare function writeConfig(cwd: string, config: ComponentsConfig, force?: boolean): Promise<void>;
8
+ /** Persists changes to an existing components.json without requiring --force. */
9
+ export declare function updateConfig(cwd: string, config: ComponentsConfig): Promise<void>;
10
+ export declare function resolveComponentsDir(cwd: string, config: ComponentsConfig, override?: string): string;
@@ -0,0 +1,116 @@
1
+ import { mkdir, readFile, stat, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { CLI_NAME, CONFIG_FILE_NAME, DEFAULT_COMPONENTS_DIR, DEFAULT_EXPOSURE, DEFAULT_FRAMEWORK } from '../constants/index.js';
4
+ import { CliError } from '../errors/index.js';
5
+ import { resolveProjectPath } from '../helpers/path.helpers.js';
6
+ import { assertFramework } from './framework.helpers.js';
7
+ async function pathExists(path) {
8
+ try {
9
+ await stat(path);
10
+ return true;
11
+ }
12
+ catch {
13
+ return false;
14
+ }
15
+ }
16
+ export function getConfigPath(cwd) {
17
+ return join(cwd, CONFIG_FILE_NAME);
18
+ }
19
+ export function createDefaultConfig(componentsDir = DEFAULT_COMPONENTS_DIR, framework = DEFAULT_FRAMEWORK, registries = [], exposure = DEFAULT_EXPOSURE) {
20
+ return {
21
+ componentsDir,
22
+ framework,
23
+ overwrite: false,
24
+ registries: [...registries],
25
+ exposure
26
+ };
27
+ }
28
+ function parseRegistries(value) {
29
+ if (value === undefined)
30
+ return [];
31
+ if (!Array.isArray(value) || value.some(entry => typeof entry !== 'string' || entry.trim() === '')) {
32
+ throw new CliError(`${CONFIG_FILE_NAME}: "registries" must be an array of non-empty strings.`);
33
+ }
34
+ return Array.from(new Set(value.map(entry => entry.trim())));
35
+ }
36
+ function parseExposure(value) {
37
+ if (value === undefined)
38
+ return DEFAULT_EXPOSURE;
39
+ if (value !== 'full' && value !== 'incremental') {
40
+ throw new CliError(`${CONFIG_FILE_NAME}: "exposure" must be "full" or "incremental".`);
41
+ }
42
+ return value;
43
+ }
44
+ function parseThemeOrder(value) {
45
+ if (value === undefined)
46
+ return undefined;
47
+ if (!Array.isArray(value) || value.some(entry => typeof entry !== 'string' || entry.trim() === '')) {
48
+ throw new CliError(`${CONFIG_FILE_NAME}: "themeOrder" must be an array of non-empty strings.`);
49
+ }
50
+ return value.map(entry => entry.trim());
51
+ }
52
+ function parseEntries(value) {
53
+ if (value === undefined)
54
+ return undefined;
55
+ if (!Array.isArray(value) || value.some(entry => typeof entry !== 'string' || entry.trim() === '')) {
56
+ throw new CliError(`${CONFIG_FILE_NAME}: "entries" must be an array of non-empty strings.`);
57
+ }
58
+ return Array.from(new Set(value.map(entry => entry.trim())));
59
+ }
60
+ export async function readConfig(cwd) {
61
+ const configPath = getConfigPath(cwd);
62
+ if (!(await pathExists(configPath)))
63
+ return null;
64
+ let parsed;
65
+ try {
66
+ parsed = JSON.parse((await readFile(configPath, 'utf8')).replace(/^\uFEFF/, ''));
67
+ }
68
+ catch (error) {
69
+ const message = error instanceof Error ? error.message : String(error);
70
+ throw new CliError(`Invalid JSON in ${CONFIG_FILE_NAME}: ${message}`);
71
+ }
72
+ if (typeof parsed !== 'object' || parsed === null) {
73
+ throw new CliError(`${CONFIG_FILE_NAME} must contain a JSON object.`);
74
+ }
75
+ const record = parsed;
76
+ const componentsDir = record.componentsDir ?? DEFAULT_COMPONENTS_DIR;
77
+ const framework = assertFramework(record.framework ?? record.variant ?? DEFAULT_FRAMEWORK);
78
+ const overwrite = record.overwrite ?? false;
79
+ if (typeof componentsDir !== 'string' || componentsDir.trim() === '') {
80
+ throw new CliError(`${CONFIG_FILE_NAME}: "componentsDir" must be a non-empty string.`);
81
+ }
82
+ if (typeof overwrite !== 'boolean') {
83
+ throw new CliError(`${CONFIG_FILE_NAME}: "overwrite" must be a boolean.`);
84
+ }
85
+ const entries = parseEntries(record.entries);
86
+ const themeOrder = parseThemeOrder(record.themeOrder);
87
+ return {
88
+ componentsDir,
89
+ framework,
90
+ overwrite,
91
+ registries: parseRegistries(record.registries),
92
+ exposure: parseExposure(record.exposure),
93
+ ...(entries ? { entries } : {}),
94
+ ...(themeOrder ? { themeOrder } : {})
95
+ };
96
+ }
97
+ async function saveConfig(cwd, config) {
98
+ await mkdir(cwd, { recursive: true });
99
+ await writeFile(getConfigPath(cwd), `${JSON.stringify(config, null, 2)}\n`, 'utf8');
100
+ }
101
+ export async function writeConfig(cwd, config, force = false) {
102
+ if ((await pathExists(getConfigPath(cwd))) && !force) {
103
+ throw new CliError(`${CONFIG_FILE_NAME} already exists. Use --force to overwrite.`);
104
+ }
105
+ await saveConfig(cwd, config);
106
+ }
107
+ /** Persists changes to an existing components.json without requiring --force. */
108
+ export async function updateConfig(cwd, config) {
109
+ if (!(await pathExists(getConfigPath(cwd)))) {
110
+ throw new CliError(`${CONFIG_FILE_NAME} not found. Run "${CLI_NAME} init" first.`);
111
+ }
112
+ await saveConfig(cwd, config);
113
+ }
114
+ export function resolveComponentsDir(cwd, config, override) {
115
+ return resolveProjectPath(cwd, override ?? config.componentsDir);
116
+ }
@@ -0,0 +1,3 @@
1
+ import { type SupportedFramework } from '../constants/index.js';
2
+ export declare function isSupportedFramework(value: unknown): value is SupportedFramework;
3
+ export declare function assertFramework(value: unknown): SupportedFramework;
@@ -0,0 +1,14 @@
1
+ import { DEFAULT_FRAMEWORK, SUPPORTED_FRAMEWORKS } from '../constants/index.js';
2
+ import { CliError } from '../errors/index.js';
3
+ export function isSupportedFramework(value) {
4
+ return (typeof value === 'string' &&
5
+ SUPPORTED_FRAMEWORKS.includes(value));
6
+ }
7
+ export function assertFramework(value) {
8
+ if (value === undefined || value === null || value === '')
9
+ return DEFAULT_FRAMEWORK;
10
+ if (!isSupportedFramework(value)) {
11
+ throw new CliError(`Unsupported framework "${String(value)}". Available: ${SUPPORTED_FRAMEWORKS.join(', ')}.`);
12
+ }
13
+ return value;
14
+ }
@@ -0,0 +1,2 @@
1
+ export * from './config.helpers.js';
2
+ export * from './framework.helpers.js';
@@ -0,0 +1,2 @@
1
+ export * from './config.helpers.js';
2
+ export * from './framework.helpers.js';
@@ -0,0 +1,20 @@
1
+ export declare const CLI_NAME = "ui";
2
+ export declare const CONFIG_FILE_NAME = "components.json";
3
+ export declare const DEFAULT_COMPONENTS_DIR = "ui";
4
+ export declare const DEFAULT_EXPOSURE: 'full';
5
+ export declare const LOCK_FILE_NAME = "ui.lock.json";
6
+ export declare const COMPONENTS_SUBDIR = "components";
7
+ export declare const THEMES_SUBDIR = "themes";
8
+ export declare const RUNTIMES_SUBDIR = "runtimes";
9
+ export declare const MANIFEST_FILE_NAME = "component.json";
10
+ export declare const COMPONENT_NAME_PATTERN: RegExp;
11
+ /** Namespace slug used to scope every target of a registry package. */
12
+ export declare const UI_REGISTRY_ID_FIELD = "uiRegistryId";
13
+ /** Minimum @blankways/ui version required by a registry package. */
14
+ export declare const UI_REQUIRES_FIELD = "uiRequires";
15
+ /** Dev-only registry packages used while authoring this registry. */
16
+ export declare const UI_DEV_REGISTRIES_FIELD = "uiDevRegistries";
17
+ /** Base stylesheet owned by @blankways/ui; imported, never copied. */
18
+ export declare const BASE_STYLE_IMPORT = "@blankways/ui/styles.css";
19
+ /** package.json field that points to a registry directory inside a package. */
20
+ export declare const UI_REGISTRY_FIELD = "uiRegistry";
@@ -0,0 +1,20 @@
1
+ export const CLI_NAME = 'ui';
2
+ export const CONFIG_FILE_NAME = 'components.json';
3
+ export const DEFAULT_COMPONENTS_DIR = 'ui';
4
+ export const DEFAULT_EXPOSURE = 'full';
5
+ export const LOCK_FILE_NAME = 'ui.lock.json';
6
+ export const COMPONENTS_SUBDIR = 'components';
7
+ export const THEMES_SUBDIR = 'themes';
8
+ export const RUNTIMES_SUBDIR = 'runtimes';
9
+ export const MANIFEST_FILE_NAME = 'component.json';
10
+ export const COMPONENT_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
11
+ /** Namespace slug used to scope every target of a registry package. */
12
+ export const UI_REGISTRY_ID_FIELD = 'uiRegistryId';
13
+ /** Minimum @blankways/ui version required by a registry package. */
14
+ export const UI_REQUIRES_FIELD = 'uiRequires';
15
+ /** Dev-only registry packages used while authoring this registry. */
16
+ export const UI_DEV_REGISTRIES_FIELD = 'uiDevRegistries';
17
+ /** Base stylesheet owned by @blankways/ui; imported, never copied. */
18
+ export const BASE_STYLE_IMPORT = '@blankways/ui/styles.css';
19
+ /** package.json field that points to a registry directory inside a package. */
20
+ export const UI_REGISTRY_FIELD = 'uiRegistry';
@@ -0,0 +1,3 @@
1
+ export declare const SUPPORTED_FRAMEWORKS: readonly ['react'];
2
+ export type SupportedFramework = (typeof SUPPORTED_FRAMEWORKS)[number];
3
+ export declare const DEFAULT_FRAMEWORK: SupportedFramework;
@@ -0,0 +1,2 @@
1
+ export const SUPPORTED_FRAMEWORKS = ['react'];
2
+ export const DEFAULT_FRAMEWORK = 'react';
@@ -0,0 +1,2 @@
1
+ export * from './cli.constants.js';
2
+ export * from './framework.constants.js';
@@ -0,0 +1,2 @@
1
+ export * from './cli.constants.js';
2
+ export * from './framework.constants.js';
@@ -0,0 +1 @@
1
+ export {};