trix-ui 0.2.8 → 0.2.9
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/dist/__tests__/contracts/registry.test.d.ts +1 -0
- package/dist/__tests__/contracts/registry.test.js +42 -0
- package/dist/__tests__/contracts/registry.test.js.map +1 -0
- package/dist/__tests__/e2e/cli.test.d.ts +1 -0
- package/dist/__tests__/e2e/cli.test.js +67 -0
- package/dist/__tests__/e2e/cli.test.js.map +1 -0
- package/dist/__tests__/helpers/fs.d.ts +5 -0
- package/dist/__tests__/helpers/fs.js +26 -0
- package/dist/__tests__/helpers/fs.js.map +1 -0
- package/dist/__tests__/integration/commands.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/commands.integration.test.js +184 -0
- package/dist/__tests__/integration/commands.integration.test.js.map +1 -0
- package/dist/commands/__tests__/add-composite.test.d.ts +2 -0
- package/dist/commands/__tests__/add-composite.test.js +171 -0
- package/dist/commands/__tests__/add-composite.test.js.map +1 -0
- package/dist/commands/__tests__/add-entry.mocks.d.ts +23 -0
- package/dist/commands/__tests__/add-entry.mocks.js +64 -0
- package/dist/commands/__tests__/add-entry.mocks.js.map +1 -0
- package/dist/commands/__tests__/add-section.test.d.ts +2 -0
- package/dist/commands/__tests__/add-section.test.js +191 -0
- package/dist/commands/__tests__/add-section.test.js.map +1 -0
- package/dist/commands/__tests__/add-wrapper.test.d.ts +2 -0
- package/dist/commands/__tests__/add-wrapper.test.js +171 -0
- package/dist/commands/__tests__/add-wrapper.test.js.map +1 -0
- package/dist/commands/__tests__/cli-mocks.d.ts +1 -0
- package/dist/commands/__tests__/cli-mocks.js +24 -0
- package/dist/commands/__tests__/cli-mocks.js.map +1 -0
- package/dist/commands/__tests__/doctor.mocks.d.ts +6 -0
- package/dist/commands/__tests__/doctor.mocks.js +20 -0
- package/dist/commands/__tests__/doctor.mocks.js.map +1 -0
- package/dist/commands/__tests__/doctor.test.d.ts +2 -0
- package/dist/commands/__tests__/doctor.test.js +80 -0
- package/dist/commands/__tests__/doctor.test.js.map +1 -0
- package/dist/commands/__tests__/list.mocks.d.ts +8 -0
- package/dist/commands/__tests__/list.mocks.js +20 -0
- package/dist/commands/__tests__/list.mocks.js.map +1 -0
- package/dist/commands/__tests__/list.test.d.ts +2 -0
- package/dist/commands/__tests__/list.test.js +60 -0
- package/dist/commands/__tests__/list.test.js.map +1 -0
- package/dist/commands/__tests__/remove.mocks.d.ts +9 -0
- package/dist/commands/__tests__/remove.mocks.js +26 -0
- package/dist/commands/__tests__/remove.mocks.js.map +1 -0
- package/dist/commands/__tests__/remove.test.d.ts +2 -0
- package/dist/commands/__tests__/remove.test.js +116 -0
- package/dist/commands/__tests__/remove.test.js.map +1 -0
- package/dist/commands/add/__tests__/add.mocks.d.ts +19 -19
- package/dist/commands/add/__tests__/add.mocks.js +59 -59
- package/dist/commands/add/__tests__/add.test.d.ts +2 -2
- package/dist/commands/add/__tests__/add.test.js +140 -140
- package/dist/commands/add/analysis.d.ts +4 -4
- package/dist/commands/add/analysis.js +56 -56
- package/dist/commands/add/command.d.ts +2 -2
- package/dist/commands/add/command.js +202 -202
- package/dist/commands/add/config.d.ts +2 -2
- package/dist/commands/add/config.js +11 -11
- package/dist/commands/add/install.d.ts +27 -27
- package/dist/commands/add/install.js +80 -80
- package/dist/commands/add/package-manager.d.ts +1 -1
- package/dist/commands/add/package-manager.js +4 -4
- package/dist/commands/add/project-files.d.ts +2 -2
- package/dist/commands/add/project-files.js +17 -17
- package/dist/commands/add/prompts.d.ts +3 -3
- package/dist/commands/add/prompts.js +28 -28
- package/dist/commands/add/registry.d.ts +4 -4
- package/dist/commands/add/registry.js +6 -6
- package/dist/commands/add/types.d.ts +33 -33
- package/dist/commands/add/types.js +1 -1
- package/dist/commands/add/ui.d.ts +4 -4
- package/dist/commands/add/ui.js +55 -55
- package/dist/commands/add/validation.d.ts +3 -3
- package/dist/commands/add/validation.js +30 -30
- package/dist/commands/add-collection.d.ts +1 -1
- package/dist/commands/add-collection.js +1 -1
- package/dist/commands/add-composite.d.ts +2 -2
- package/dist/commands/add-composite.js +201 -201
- package/dist/commands/add-section.d.ts +2 -2
- package/dist/commands/add-section.js +201 -201
- package/dist/commands/add-wrapper.d.ts +2 -2
- package/dist/commands/add-wrapper.js +201 -201
- package/dist/commands/add.d.ts +1 -1
- package/dist/commands/add.js +1 -1
- package/dist/commands/build.d.ts +2 -2
- package/dist/commands/doctor.d.ts +2 -2
- package/dist/commands/doctor.js +67 -67
- package/dist/commands/init/__tests__/init.mocks.d.ts +24 -0
- package/dist/commands/init/__tests__/init.mocks.js +84 -0
- package/dist/commands/init/__tests__/init.mocks.js.map +1 -0
- package/dist/commands/init/__tests__/init.test.d.ts +2 -0
- package/dist/commands/init/__tests__/init.test.js +283 -0
- package/dist/commands/init/__tests__/init.test.js.map +1 -0
- package/dist/commands/init/__tests__/tailwind.test.d.ts +1 -0
- package/dist/commands/init/__tests__/tailwind.test.js +56 -0
- package/dist/commands/init/__tests__/tailwind.test.js.map +1 -0
- package/dist/commands/init/__tests__/tsconfig.test.d.ts +1 -0
- package/dist/commands/init/__tests__/tsconfig.test.js +108 -0
- package/dist/commands/init/__tests__/tsconfig.test.js.map +1 -0
- package/dist/commands/init/__tests__/vite.test.d.ts +1 -0
- package/dist/commands/init/__tests__/vite.test.js +66 -0
- package/dist/commands/init/__tests__/vite.test.js.map +1 -0
- package/dist/commands/init/command.d.ts +2 -2
- package/dist/commands/init/command.js +114 -114
- package/dist/commands/init/config.d.ts +2 -2
- package/dist/commands/init/config.js +25 -25
- package/dist/commands/init/constants.d.ts +3 -3
- package/dist/commands/init/constants.js +105 -105
- package/dist/commands/init/dependencies.d.ts +5 -5
- package/dist/commands/init/dependencies.js +52 -52
- package/dist/commands/init/filesystem.d.ts +1 -1
- package/dist/commands/init/filesystem.js +10 -10
- package/dist/commands/init/lockfile.d.ts +1 -1
- package/dist/commands/init/lockfile.js +1 -1
- package/dist/commands/init/package-json.d.ts +6 -6
- package/dist/commands/init/package-json.js +18 -18
- package/dist/commands/init/project-files.d.ts +8 -0
- package/dist/commands/init/project-files.js +37 -0
- package/dist/commands/init/project-files.js.map +1 -0
- package/dist/commands/init/project.d.ts +3 -3
- package/dist/commands/init/project.js +97 -97
- package/dist/commands/init/style-imports.d.ts +9 -0
- package/dist/commands/init/style-imports.js +218 -0
- package/dist/commands/init/style-imports.js.map +1 -0
- package/dist/commands/init/tailwind.d.ts +3 -3
- package/dist/commands/init/tailwind.js +34 -34
- package/dist/commands/init/templates.d.ts +3 -3
- package/dist/commands/init/templates.js +15 -15
- package/dist/commands/init/tsconfig.d.ts +2 -2
- package/dist/commands/init/tsconfig.js +273 -273
- package/dist/commands/init/types.d.ts +33 -33
- package/dist/commands/init/types.js +1 -1
- package/dist/commands/init/ui.d.ts +3 -3
- package/dist/commands/init/ui.js +33 -33
- package/dist/commands/init/vite.d.ts +23 -0
- package/dist/commands/init/vite.js +347 -0
- package/dist/commands/init/vite.js.map +1 -0
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.js +1 -1
- package/dist/commands/list.d.ts +2 -2
- package/dist/commands/list.js +62 -62
- package/dist/commands/remove.d.ts +2 -2
- package/dist/commands/remove.js +93 -93
- package/dist/commands/shared/add-collection.d.ts +50 -50
- package/dist/commands/shared/add-collection.js +206 -206
- package/dist/commands/shared/list-entries.d.ts +6 -6
- package/dist/commands/shared/list-entries.js +12 -12
- package/dist/commands/shared/name-utils.d.ts +1 -1
- package/dist/commands/shared/name-utils.js +13 -13
- package/dist/commands/shared/remove-entries.d.ts +16 -16
- package/dist/commands/shared/remove-entries.js +41 -41
- package/dist/icons/index.d.ts +1 -1
- package/dist/icons/index.js +1 -1
- package/dist/icons/libraries.d.ts +37 -37
- package/dist/icons/libraries.js +34 -34
- package/dist/index.d.ts +2 -2
- package/dist/index.js +30 -30
- package/dist/lib/__tests__/config.test.d.ts +1 -0
- package/dist/lib/__tests__/config.test.js +49 -0
- package/dist/lib/__tests__/config.test.js.map +1 -0
- package/dist/lib/__tests__/install.test.d.ts +1 -0
- package/dist/lib/__tests__/install.test.js +149 -0
- package/dist/lib/__tests__/install.test.js.map +1 -0
- package/dist/lib/__tests__/lockfile.test.d.ts +1 -0
- package/dist/lib/__tests__/lockfile.test.js +89 -0
- package/dist/lib/__tests__/lockfile.test.js.map +1 -0
- package/dist/lib/__tests__/paths.test.d.ts +1 -0
- package/dist/lib/__tests__/paths.test.js +39 -0
- package/dist/lib/__tests__/paths.test.js.map +1 -0
- package/dist/lib/__tests__/registry.test.d.ts +1 -0
- package/dist/lib/__tests__/registry.test.js +76 -0
- package/dist/lib/__tests__/registry.test.js.map +1 -0
- package/dist/lib/config.d.ts +45 -45
- package/dist/lib/config.js +97 -97
- package/dist/lib/fs.d.ts +76 -76
- package/dist/lib/fs.js +302 -302
- package/dist/lib/highlighter.d.ts +6 -6
- package/dist/lib/highlighter.js +7 -7
- package/dist/lib/install.d.ts +19 -19
- package/dist/lib/install.js +55 -55
- package/dist/lib/lockfile.d.ts +63 -63
- package/dist/lib/lockfile.js +173 -173
- package/dist/lib/logger.d.ts +8 -8
- package/dist/lib/logger.js +41 -41
- package/dist/lib/paths.d.ts +14 -14
- package/dist/lib/paths.js +31 -31
- package/dist/lib/registry.d.ts +35 -35
- package/dist/lib/registry.js +180 -180
- package/dist/schema/index.d.ts +1128 -1128
- package/dist/schema/index.js +238 -238
- package/dist/styles/create-style-map.d.ts +4 -4
- package/dist/styles/create-style-map.js +68 -68
- package/dist/styles/transform-style-map.d.ts +3 -3
- package/dist/styles/transform-style-map.js +428 -428
- package/dist/styles/transform.d.ts +10 -10
- package/dist/styles/transform.js +15 -15
- package/dist/utils/index.d.ts +6 -6
- package/dist/utils/index.js +5 -5
- package/dist/utils/transformers/transform-icons.d.ts +2 -2
- package/dist/utils/transformers/transform-icons.js +164 -164
- package/dist/utils/transformers/transform-menu.d.ts +2 -2
- package/dist/utils/transformers/transform-menu.js +39 -39
- package/dist/utils/transformers/transform-render.d.ts +2 -2
- package/dist/utils/transformers/transform-render.js +97 -97
- package/dist/utils/transformers/types.d.ts +14 -14
- package/dist/utils/transformers/types.js +1 -1
- package/package.json +1 -1
|
@@ -1,203 +1,203 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import { Command } from "commander";
|
|
4
|
-
import ora from "ora";
|
|
5
|
-
import { loadConfig } from "../../lib/config.js";
|
|
6
|
-
import { directoryExists } from "../../lib/fs.js";
|
|
7
|
-
import { loadLockfile, saveLockfile } from "../../lib/lockfile.js";
|
|
8
|
-
import { logger } from "../../lib/logger.js";
|
|
9
|
-
import { loadRegistry } from "../../lib/registry.js";
|
|
10
|
-
import { analyzeDependencies } from "./analysis.js";
|
|
11
|
-
import { installComponents, installNpmDependencies, updateBarrelFile, } from "./install.js";
|
|
12
|
-
import { ensureProjectFiles } from "./project-files.js";
|
|
13
|
-
import { confirmDependencyInstallation, confirmInstallation, confirmOverwrite, } from "./prompts.js";
|
|
14
|
-
import { getComponentNames } from "./registry.js";
|
|
15
|
-
import { displayInstallationPlan, displayManualInstallInstructions, displayResults, } from "./ui.js";
|
|
16
|
-
import { validateComponents } from "./validation.js";
|
|
17
|
-
function normalizeComponents(components) {
|
|
18
|
-
const unique = new Set();
|
|
19
|
-
const normalized = [];
|
|
20
|
-
for (const component of components) {
|
|
21
|
-
const trimmed = component.trim();
|
|
22
|
-
if (!trimmed || unique.has(trimmed)) {
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
unique.add(trimmed);
|
|
26
|
-
normalized.push(trimmed);
|
|
27
|
-
}
|
|
28
|
-
return normalized;
|
|
29
|
-
}
|
|
30
|
-
function toAddConfig(config) {
|
|
31
|
-
return config;
|
|
32
|
-
}
|
|
33
|
-
export const addCommand = new Command("add")
|
|
34
|
-
.description("Add components to your project")
|
|
35
|
-
.argument("<components...>", "component names (or 'all' to install everything)")
|
|
36
|
-
.option("-f, --force", "overwrite existing files", false)
|
|
37
|
-
.option("-y, --yes", "skip confirmation prompts", false)
|
|
38
|
-
.option("-s, --silent", "suppress output messages", false)
|
|
39
|
-
.option("-c, --cwd <path>", "working directory to add components")
|
|
40
|
-
.option("--skip-deps", "skip dependency installation", false)
|
|
41
|
-
.action(async (components, options) => {
|
|
42
|
-
const spinner = options.silent ? null : ora({ color: "blue" });
|
|
43
|
-
const shouldLog = !options.silent;
|
|
44
|
-
const shouldPrompt = !options.yes && !options.silent;
|
|
45
|
-
try {
|
|
46
|
-
const cwd = path.resolve(options.cwd || process.cwd());
|
|
47
|
-
if (shouldLog) {
|
|
48
|
-
logger.info({ cwd }, "Adding components");
|
|
49
|
-
}
|
|
50
|
-
if (!(await directoryExists(cwd))) {
|
|
51
|
-
logger.error(`Directory does not exist: ${cwd}`);
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
spinner?.start("Loading configuration...");
|
|
55
|
-
const config = toAddConfig(await loadConfig(cwd));
|
|
56
|
-
spinner?.succeed("Configuration loaded");
|
|
57
|
-
spinner?.start("Loading registry and lockfile...");
|
|
58
|
-
const registry = await loadRegistry(config, cwd);
|
|
59
|
-
const lockfile = await loadLockfile(cwd);
|
|
60
|
-
spinner?.succeed("Registry and lockfile loaded");
|
|
61
|
-
let requestedComponents = normalizeComponents(components);
|
|
62
|
-
if (requestedComponents.length === 0) {
|
|
63
|
-
logger.error("No component names provided.");
|
|
64
|
-
process.exit(1);
|
|
65
|
-
}
|
|
66
|
-
if (requestedComponents.includes("all")) {
|
|
67
|
-
const allComponents = getComponentNames(registry);
|
|
68
|
-
if (shouldLog) {
|
|
69
|
-
console.log(chalk.yellow(`\nThis will install ${allComponents.length} components:`));
|
|
70
|
-
console.log(chalk.gray(allComponents.join(", ")));
|
|
71
|
-
}
|
|
72
|
-
const shouldContinue = shouldPrompt
|
|
73
|
-
? await confirmInstallation(`all ${allComponents.length} components`)
|
|
74
|
-
: true;
|
|
75
|
-
if (!shouldContinue) {
|
|
76
|
-
logger.info("Installation cancelled");
|
|
77
|
-
process.exit(0);
|
|
78
|
-
}
|
|
79
|
-
requestedComponents = allComponents;
|
|
80
|
-
}
|
|
81
|
-
spinner?.start("Validating components...");
|
|
82
|
-
const validation = validateComponents(requestedComponents, registry);
|
|
83
|
-
spinner?.stop();
|
|
84
|
-
if (validation.invalid.length > 0) {
|
|
85
|
-
logger.error("The following components were not found:");
|
|
86
|
-
validation.invalid.forEach((name) => logger.error(` \u0007 ${name}`));
|
|
87
|
-
if (validation.suggestions.length > 0 && shouldLog) {
|
|
88
|
-
console.log(chalk.yellow("\nDid you mean:"));
|
|
89
|
-
validation.suggestions.forEach((suggestion) => console.log(chalk.gray(` \u0007 ${suggestion}`)));
|
|
90
|
-
}
|
|
91
|
-
process.exit(1);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
spinner?.start("Analyzing dependencies...");
|
|
95
|
-
const analysis = analyzeDependencies(validation.valid, registry, lockfile);
|
|
96
|
-
spinner?.stop();
|
|
97
|
-
if (analysis.missingDependencies.length > 0) {
|
|
98
|
-
logger.error("Registry is missing required component dependencies:");
|
|
99
|
-
analysis.missingDependencies.forEach((name) => logger.error(` \u0007 ${name}`));
|
|
100
|
-
process.exit(1);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
if (shouldLog) {
|
|
104
|
-
displayInstallationPlan(analysis, options);
|
|
105
|
-
}
|
|
106
|
-
let forceInstall = Boolean(options.force);
|
|
107
|
-
if (analysis.conflicts.length > 0 && !forceInstall) {
|
|
108
|
-
if (shouldLog) {
|
|
109
|
-
logger.warn("The following components already exist:");
|
|
110
|
-
analysis.conflicts.forEach((name) => logger.warn(` \u0007 ${name}`));
|
|
111
|
-
}
|
|
112
|
-
if (options.yes) {
|
|
113
|
-
forceInstall = true;
|
|
114
|
-
}
|
|
115
|
-
else if (shouldPrompt) {
|
|
116
|
-
const shouldOverwrite = await confirmOverwrite();
|
|
117
|
-
if (!shouldOverwrite) {
|
|
118
|
-
logger.info("Installation cancelled");
|
|
119
|
-
process.exit(0);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
forceInstall = true;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const installCount = forceInstall
|
|
126
|
-
? analysis.components.length
|
|
127
|
-
: analysis.totalToInstall;
|
|
128
|
-
if (shouldPrompt && installCount > 0) {
|
|
129
|
-
const shouldInstall = await confirmInstallation(`${installCount} component${installCount > 1 ? "s" : ""}`);
|
|
130
|
-
if (!shouldInstall) {
|
|
131
|
-
logger.info("Installation cancelled");
|
|
132
|
-
process.exit(0);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
spinner?.start("Verifying project setup...");
|
|
137
|
-
await ensureProjectFiles(cwd, config);
|
|
138
|
-
spinner?.succeed("Project setup verified");
|
|
139
|
-
spinner?.start("Installing components...");
|
|
140
|
-
const result = await installComponents({
|
|
141
|
-
cwd,
|
|
142
|
-
config,
|
|
143
|
-
registry,
|
|
144
|
-
lockfile,
|
|
145
|
-
components: analysis.components,
|
|
146
|
-
conflicts: analysis.conflicts,
|
|
147
|
-
force: forceInstall,
|
|
148
|
-
spinner,
|
|
149
|
-
});
|
|
150
|
-
const installedMessage = `Installed ${result.installed.length} component${result.installed.length !== 1 ? "s" : ""}`;
|
|
151
|
-
if (result.failed.length > 0) {
|
|
152
|
-
spinner?.fail(`${installedMessage} (${result.failed.length} failed)`);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
spinner?.succeed(installedMessage);
|
|
156
|
-
}
|
|
157
|
-
spinner?.start("Updating lockfile...");
|
|
158
|
-
await saveLockfile(cwd, lockfile);
|
|
159
|
-
spinner?.succeed("Lockfile updated");
|
|
160
|
-
if (config.barrel && result.installed.length > 0) {
|
|
161
|
-
spinner?.start("Updating barrel file...");
|
|
162
|
-
await updateBarrelFile({ cwd, config, lockfile });
|
|
163
|
-
spinner?.succeed("Barrel file updated");
|
|
164
|
-
}
|
|
165
|
-
if (result.npmDependencies.size > 0 && !options.skipDeps) {
|
|
166
|
-
const shouldInstallDeps = shouldPrompt
|
|
167
|
-
? await confirmDependencyInstallation(result.npmDependencies)
|
|
168
|
-
: true;
|
|
169
|
-
if (shouldInstallDeps) {
|
|
170
|
-
await installNpmDependencies({
|
|
171
|
-
cwd,
|
|
172
|
-
dependencies: result.npmDependencies,
|
|
173
|
-
spinner,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
if (shouldLog) {
|
|
178
|
-
await displayManualInstallInstructions(result.npmDependencies, cwd);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
else if (result.npmDependencies.size > 0 && shouldLog) {
|
|
183
|
-
await displayManualInstallInstructions(result.npmDependencies, cwd);
|
|
184
|
-
}
|
|
185
|
-
if (shouldLog) {
|
|
186
|
-
displayResults(result, { ...options, force: forceInstall });
|
|
187
|
-
}
|
|
188
|
-
if (result.failed.length > 0) {
|
|
189
|
-
process.exit(1);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
catch (error) {
|
|
194
|
-
spinner?.fail("Installation failed");
|
|
195
|
-
logger.error(error.message);
|
|
196
|
-
if (process.env.DEBUG) {
|
|
197
|
-
console.error(error);
|
|
198
|
-
}
|
|
199
|
-
process.exit(1);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
});
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import ora from "ora";
|
|
5
|
+
import { loadConfig } from "../../lib/config.js";
|
|
6
|
+
import { directoryExists } from "../../lib/fs.js";
|
|
7
|
+
import { loadLockfile, saveLockfile } from "../../lib/lockfile.js";
|
|
8
|
+
import { logger } from "../../lib/logger.js";
|
|
9
|
+
import { loadRegistry } from "../../lib/registry.js";
|
|
10
|
+
import { analyzeDependencies } from "./analysis.js";
|
|
11
|
+
import { installComponents, installNpmDependencies, updateBarrelFile, } from "./install.js";
|
|
12
|
+
import { ensureProjectFiles } from "./project-files.js";
|
|
13
|
+
import { confirmDependencyInstallation, confirmInstallation, confirmOverwrite, } from "./prompts.js";
|
|
14
|
+
import { getComponentNames } from "./registry.js";
|
|
15
|
+
import { displayInstallationPlan, displayManualInstallInstructions, displayResults, } from "./ui.js";
|
|
16
|
+
import { validateComponents } from "./validation.js";
|
|
17
|
+
function normalizeComponents(components) {
|
|
18
|
+
const unique = new Set();
|
|
19
|
+
const normalized = [];
|
|
20
|
+
for (const component of components) {
|
|
21
|
+
const trimmed = component.trim();
|
|
22
|
+
if (!trimmed || unique.has(trimmed)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
unique.add(trimmed);
|
|
26
|
+
normalized.push(trimmed);
|
|
27
|
+
}
|
|
28
|
+
return normalized;
|
|
29
|
+
}
|
|
30
|
+
function toAddConfig(config) {
|
|
31
|
+
return config;
|
|
32
|
+
}
|
|
33
|
+
export const addCommand = new Command("add")
|
|
34
|
+
.description("Add components to your project")
|
|
35
|
+
.argument("<components...>", "component names (or 'all' to install everything)")
|
|
36
|
+
.option("-f, --force", "overwrite existing files", false)
|
|
37
|
+
.option("-y, --yes", "skip confirmation prompts", false)
|
|
38
|
+
.option("-s, --silent", "suppress output messages", false)
|
|
39
|
+
.option("-c, --cwd <path>", "working directory to add components")
|
|
40
|
+
.option("--skip-deps", "skip dependency installation", false)
|
|
41
|
+
.action(async (components, options) => {
|
|
42
|
+
const spinner = options.silent ? null : ora({ color: "blue" });
|
|
43
|
+
const shouldLog = !options.silent;
|
|
44
|
+
const shouldPrompt = !options.yes && !options.silent;
|
|
45
|
+
try {
|
|
46
|
+
const cwd = path.resolve(options.cwd || process.cwd());
|
|
47
|
+
if (shouldLog) {
|
|
48
|
+
logger.info({ cwd }, "Adding components");
|
|
49
|
+
}
|
|
50
|
+
if (!(await directoryExists(cwd))) {
|
|
51
|
+
logger.error(`Directory does not exist: ${cwd}`);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
spinner?.start("Loading configuration...");
|
|
55
|
+
const config = toAddConfig(await loadConfig(cwd));
|
|
56
|
+
spinner?.succeed("Configuration loaded");
|
|
57
|
+
spinner?.start("Loading registry and lockfile...");
|
|
58
|
+
const registry = await loadRegistry(config, cwd);
|
|
59
|
+
const lockfile = await loadLockfile(cwd);
|
|
60
|
+
spinner?.succeed("Registry and lockfile loaded");
|
|
61
|
+
let requestedComponents = normalizeComponents(components);
|
|
62
|
+
if (requestedComponents.length === 0) {
|
|
63
|
+
logger.error("No component names provided.");
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
if (requestedComponents.includes("all")) {
|
|
67
|
+
const allComponents = getComponentNames(registry);
|
|
68
|
+
if (shouldLog) {
|
|
69
|
+
console.log(chalk.yellow(`\nThis will install ${allComponents.length} components:`));
|
|
70
|
+
console.log(chalk.gray(allComponents.join(", ")));
|
|
71
|
+
}
|
|
72
|
+
const shouldContinue = shouldPrompt
|
|
73
|
+
? await confirmInstallation(`all ${allComponents.length} components`)
|
|
74
|
+
: true;
|
|
75
|
+
if (!shouldContinue) {
|
|
76
|
+
logger.info("Installation cancelled");
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
requestedComponents = allComponents;
|
|
80
|
+
}
|
|
81
|
+
spinner?.start("Validating components...");
|
|
82
|
+
const validation = validateComponents(requestedComponents, registry);
|
|
83
|
+
spinner?.stop();
|
|
84
|
+
if (validation.invalid.length > 0) {
|
|
85
|
+
logger.error("The following components were not found:");
|
|
86
|
+
validation.invalid.forEach((name) => logger.error(` \u0007 ${name}`));
|
|
87
|
+
if (validation.suggestions.length > 0 && shouldLog) {
|
|
88
|
+
console.log(chalk.yellow("\nDid you mean:"));
|
|
89
|
+
validation.suggestions.forEach((suggestion) => console.log(chalk.gray(` \u0007 ${suggestion}`)));
|
|
90
|
+
}
|
|
91
|
+
process.exit(1);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
spinner?.start("Analyzing dependencies...");
|
|
95
|
+
const analysis = analyzeDependencies(validation.valid, registry, lockfile);
|
|
96
|
+
spinner?.stop();
|
|
97
|
+
if (analysis.missingDependencies.length > 0) {
|
|
98
|
+
logger.error("Registry is missing required component dependencies:");
|
|
99
|
+
analysis.missingDependencies.forEach((name) => logger.error(` \u0007 ${name}`));
|
|
100
|
+
process.exit(1);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (shouldLog) {
|
|
104
|
+
displayInstallationPlan(analysis, options);
|
|
105
|
+
}
|
|
106
|
+
let forceInstall = Boolean(options.force);
|
|
107
|
+
if (analysis.conflicts.length > 0 && !forceInstall) {
|
|
108
|
+
if (shouldLog) {
|
|
109
|
+
logger.warn("The following components already exist:");
|
|
110
|
+
analysis.conflicts.forEach((name) => logger.warn(` \u0007 ${name}`));
|
|
111
|
+
}
|
|
112
|
+
if (options.yes) {
|
|
113
|
+
forceInstall = true;
|
|
114
|
+
}
|
|
115
|
+
else if (shouldPrompt) {
|
|
116
|
+
const shouldOverwrite = await confirmOverwrite();
|
|
117
|
+
if (!shouldOverwrite) {
|
|
118
|
+
logger.info("Installation cancelled");
|
|
119
|
+
process.exit(0);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
forceInstall = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const installCount = forceInstall
|
|
126
|
+
? analysis.components.length
|
|
127
|
+
: analysis.totalToInstall;
|
|
128
|
+
if (shouldPrompt && installCount > 0) {
|
|
129
|
+
const shouldInstall = await confirmInstallation(`${installCount} component${installCount > 1 ? "s" : ""}`);
|
|
130
|
+
if (!shouldInstall) {
|
|
131
|
+
logger.info("Installation cancelled");
|
|
132
|
+
process.exit(0);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
spinner?.start("Verifying project setup...");
|
|
137
|
+
await ensureProjectFiles(cwd, config);
|
|
138
|
+
spinner?.succeed("Project setup verified");
|
|
139
|
+
spinner?.start("Installing components...");
|
|
140
|
+
const result = await installComponents({
|
|
141
|
+
cwd,
|
|
142
|
+
config,
|
|
143
|
+
registry,
|
|
144
|
+
lockfile,
|
|
145
|
+
components: analysis.components,
|
|
146
|
+
conflicts: analysis.conflicts,
|
|
147
|
+
force: forceInstall,
|
|
148
|
+
spinner,
|
|
149
|
+
});
|
|
150
|
+
const installedMessage = `Installed ${result.installed.length} component${result.installed.length !== 1 ? "s" : ""}`;
|
|
151
|
+
if (result.failed.length > 0) {
|
|
152
|
+
spinner?.fail(`${installedMessage} (${result.failed.length} failed)`);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
spinner?.succeed(installedMessage);
|
|
156
|
+
}
|
|
157
|
+
spinner?.start("Updating lockfile...");
|
|
158
|
+
await saveLockfile(cwd, lockfile);
|
|
159
|
+
spinner?.succeed("Lockfile updated");
|
|
160
|
+
if (config.barrel && result.installed.length > 0) {
|
|
161
|
+
spinner?.start("Updating barrel file...");
|
|
162
|
+
await updateBarrelFile({ cwd, config, lockfile });
|
|
163
|
+
spinner?.succeed("Barrel file updated");
|
|
164
|
+
}
|
|
165
|
+
if (result.npmDependencies.size > 0 && !options.skipDeps) {
|
|
166
|
+
const shouldInstallDeps = shouldPrompt
|
|
167
|
+
? await confirmDependencyInstallation(result.npmDependencies)
|
|
168
|
+
: true;
|
|
169
|
+
if (shouldInstallDeps) {
|
|
170
|
+
await installNpmDependencies({
|
|
171
|
+
cwd,
|
|
172
|
+
dependencies: result.npmDependencies,
|
|
173
|
+
spinner,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
if (shouldLog) {
|
|
178
|
+
await displayManualInstallInstructions(result.npmDependencies, cwd);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else if (result.npmDependencies.size > 0 && shouldLog) {
|
|
183
|
+
await displayManualInstallInstructions(result.npmDependencies, cwd);
|
|
184
|
+
}
|
|
185
|
+
if (shouldLog) {
|
|
186
|
+
displayResults(result, { ...options, force: forceInstall });
|
|
187
|
+
}
|
|
188
|
+
if (result.failed.length > 0) {
|
|
189
|
+
process.exit(1);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
spinner?.fail("Installation failed");
|
|
195
|
+
logger.error(error.message);
|
|
196
|
+
if (process.env.DEBUG) {
|
|
197
|
+
console.error(error);
|
|
198
|
+
}
|
|
199
|
+
process.exit(1);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
203
|
//# sourceMappingURL=command.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { AddConfig } from "./types.js";
|
|
2
|
-
export declare function inferScriptExtension(config: AddConfig): "ts" | "js";
|
|
1
|
+
import type { AddConfig } from "./types.js";
|
|
2
|
+
export declare function inferScriptExtension(config: AddConfig): "ts" | "js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
export function inferScriptExtension(config) {
|
|
3
|
-
if (config.typescript) {
|
|
4
|
-
return "ts";
|
|
5
|
-
}
|
|
6
|
-
const ext = path.extname(config.paths.utils).toLowerCase();
|
|
7
|
-
if (ext === ".ts" || ext === ".tsx") {
|
|
8
|
-
return "ts";
|
|
9
|
-
}
|
|
10
|
-
return "js";
|
|
11
|
-
}
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
export function inferScriptExtension(config) {
|
|
3
|
+
if (config.typescript) {
|
|
4
|
+
return "ts";
|
|
5
|
+
}
|
|
6
|
+
const ext = path.extname(config.paths.utils).toLowerCase();
|
|
7
|
+
if (ext === ".ts" || ext === ".tsx") {
|
|
8
|
+
return "ts";
|
|
9
|
+
}
|
|
10
|
+
return "js";
|
|
11
|
+
}
|
|
12
12
|
//# sourceMappingURL=config.js.map
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import type { Ora } from "ora";
|
|
2
|
-
import type { Lockfile } from "../../lib/lockfile.js";
|
|
3
|
-
import type { RegistryIndex } from "../../lib/registry.js";
|
|
4
|
-
import type { AddConfig, InstallationResult } from "./types.js";
|
|
5
|
-
export interface InstallComponentsOptions {
|
|
6
|
-
cwd: string;
|
|
7
|
-
config: AddConfig;
|
|
8
|
-
registry: RegistryIndex;
|
|
9
|
-
lockfile: Lockfile;
|
|
10
|
-
components: string[];
|
|
11
|
-
conflicts: string[];
|
|
12
|
-
force: boolean;
|
|
13
|
-
spinner: Ora | null;
|
|
14
|
-
}
|
|
15
|
-
export declare function installComponents(options: InstallComponentsOptions): Promise<InstallationResult>;
|
|
16
|
-
export interface UpdateBarrelFileOptions {
|
|
17
|
-
cwd: string;
|
|
18
|
-
config: AddConfig;
|
|
19
|
-
lockfile: Lockfile;
|
|
20
|
-
}
|
|
21
|
-
export declare function updateBarrelFile(options: UpdateBarrelFileOptions): Promise<void>;
|
|
22
|
-
export interface InstallNpmDependenciesOptions {
|
|
23
|
-
cwd: string;
|
|
24
|
-
dependencies: Set<string>;
|
|
25
|
-
spinner: Ora | null;
|
|
26
|
-
}
|
|
27
|
-
export declare function installNpmDependencies(options: InstallNpmDependenciesOptions): Promise<void>;
|
|
1
|
+
import type { Ora } from "ora";
|
|
2
|
+
import type { Lockfile } from "../../lib/lockfile.js";
|
|
3
|
+
import type { RegistryIndex } from "../../lib/registry.js";
|
|
4
|
+
import type { AddConfig, InstallationResult } from "./types.js";
|
|
5
|
+
export interface InstallComponentsOptions {
|
|
6
|
+
cwd: string;
|
|
7
|
+
config: AddConfig;
|
|
8
|
+
registry: RegistryIndex;
|
|
9
|
+
lockfile: Lockfile;
|
|
10
|
+
components: string[];
|
|
11
|
+
conflicts: string[];
|
|
12
|
+
force: boolean;
|
|
13
|
+
spinner: Ora | null;
|
|
14
|
+
}
|
|
15
|
+
export declare function installComponents(options: InstallComponentsOptions): Promise<InstallationResult>;
|
|
16
|
+
export interface UpdateBarrelFileOptions {
|
|
17
|
+
cwd: string;
|
|
18
|
+
config: AddConfig;
|
|
19
|
+
lockfile: Lockfile;
|
|
20
|
+
}
|
|
21
|
+
export declare function updateBarrelFile(options: UpdateBarrelFileOptions): Promise<void>;
|
|
22
|
+
export interface InstallNpmDependenciesOptions {
|
|
23
|
+
cwd: string;
|
|
24
|
+
dependencies: Set<string>;
|
|
25
|
+
spinner: Ora | null;
|
|
26
|
+
}
|
|
27
|
+
export declare function installNpmDependencies(options: InstallNpmDependenciesOptions): Promise<void>;
|
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { execa } from "execa";
|
|
3
|
-
import { installRegistryEntries } from "../../lib/install.js";
|
|
4
|
-
import { writeFileSafe } from "../../lib/fs.js";
|
|
5
|
-
import { logger } from "../../lib/logger.js";
|
|
6
|
-
import { inferScriptExtension } from "./config.js";
|
|
7
|
-
import { detectPackageManager } from "./package-manager.js";
|
|
8
|
-
export async function installComponents(options) {
|
|
9
|
-
const { cwd, config, registry, lockfile, components, conflicts, force, spinner } = options;
|
|
10
|
-
const installed = [];
|
|
11
|
-
const skipped = [];
|
|
12
|
-
const failed = [];
|
|
13
|
-
const npmDependencies = new Set();
|
|
14
|
-
let currentIndex = 0;
|
|
15
|
-
const total = components.length;
|
|
16
|
-
for (const componentName of components) {
|
|
17
|
-
currentIndex += 1;
|
|
18
|
-
try {
|
|
19
|
-
if (spinner) {
|
|
20
|
-
spinner.text = `Installing ${componentName} (${currentIndex}/${total})...`;
|
|
21
|
-
}
|
|
22
|
-
const result = await installRegistryEntries({
|
|
23
|
-
cwd,
|
|
24
|
-
config,
|
|
25
|
-
entries: registry.components,
|
|
26
|
-
names: [componentName],
|
|
27
|
-
lockEntries: lockfile.components,
|
|
28
|
-
force,
|
|
29
|
-
itemLabel: "component"
|
|
30
|
-
});
|
|
31
|
-
if (result.installed.length > 0) {
|
|
32
|
-
installed.push(...result.installed);
|
|
33
|
-
}
|
|
34
|
-
if (result.skipped.length > 0) {
|
|
35
|
-
skipped.push(...result.skipped);
|
|
36
|
-
}
|
|
37
|
-
result.npmDependencies.forEach((dep) => npmDependencies.add(dep));
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
failed.push(componentName);
|
|
41
|
-
logger.error(`Failed to install ${componentName}: ${error.message}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
installed,
|
|
46
|
-
skipped,
|
|
47
|
-
failed,
|
|
48
|
-
npmDependencies,
|
|
49
|
-
conflicts
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
export async function updateBarrelFile(options) {
|
|
53
|
-
const { cwd, config, lockfile } = options;
|
|
54
|
-
const ext = inferScriptExtension(config);
|
|
55
|
-
const barrelPath = path.resolve(cwd, config.paths.components, `index.${ext}`);
|
|
56
|
-
const components = Object.keys(lockfile.components).sort();
|
|
57
|
-
const exports = components
|
|
58
|
-
.map((name) => `export { ${name} } from "./${name}"`)
|
|
59
|
-
.join("\n");
|
|
60
|
-
const content = `// Auto-generated barrel file
|
|
61
|
-
// This file exports all components from this directory
|
|
62
|
-
|
|
63
|
-
${exports}
|
|
64
|
-
`;
|
|
65
|
-
await writeFileSafe(barrelPath, content, true);
|
|
66
|
-
}
|
|
67
|
-
export async function installNpmDependencies(options) {
|
|
68
|
-
const { cwd, dependencies, spinner } = options;
|
|
69
|
-
const packageManager = await detectPackageManager(cwd);
|
|
70
|
-
const installCmd = packageManager === "npm" ? "install" : "add";
|
|
71
|
-
try {
|
|
72
|
-
spinner?.start(`Installing ${dependencies.size} npm package${dependencies.size > 1 ? "s" : ""}...`);
|
|
73
|
-
await execa(packageManager, [installCmd, ...Array.from(dependencies)], { cwd });
|
|
74
|
-
spinner?.succeed("NPM packages installed");
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
spinner?.fail("Failed to install npm packages");
|
|
78
|
-
throw new Error(`Failed to install dependencies: ${error.message}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { execa } from "execa";
|
|
3
|
+
import { installRegistryEntries } from "../../lib/install.js";
|
|
4
|
+
import { writeFileSafe } from "../../lib/fs.js";
|
|
5
|
+
import { logger } from "../../lib/logger.js";
|
|
6
|
+
import { inferScriptExtension } from "./config.js";
|
|
7
|
+
import { detectPackageManager } from "./package-manager.js";
|
|
8
|
+
export async function installComponents(options) {
|
|
9
|
+
const { cwd, config, registry, lockfile, components, conflicts, force, spinner } = options;
|
|
10
|
+
const installed = [];
|
|
11
|
+
const skipped = [];
|
|
12
|
+
const failed = [];
|
|
13
|
+
const npmDependencies = new Set();
|
|
14
|
+
let currentIndex = 0;
|
|
15
|
+
const total = components.length;
|
|
16
|
+
for (const componentName of components) {
|
|
17
|
+
currentIndex += 1;
|
|
18
|
+
try {
|
|
19
|
+
if (spinner) {
|
|
20
|
+
spinner.text = `Installing ${componentName} (${currentIndex}/${total})...`;
|
|
21
|
+
}
|
|
22
|
+
const result = await installRegistryEntries({
|
|
23
|
+
cwd,
|
|
24
|
+
config,
|
|
25
|
+
entries: registry.components,
|
|
26
|
+
names: [componentName],
|
|
27
|
+
lockEntries: lockfile.components,
|
|
28
|
+
force,
|
|
29
|
+
itemLabel: "component"
|
|
30
|
+
});
|
|
31
|
+
if (result.installed.length > 0) {
|
|
32
|
+
installed.push(...result.installed);
|
|
33
|
+
}
|
|
34
|
+
if (result.skipped.length > 0) {
|
|
35
|
+
skipped.push(...result.skipped);
|
|
36
|
+
}
|
|
37
|
+
result.npmDependencies.forEach((dep) => npmDependencies.add(dep));
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
failed.push(componentName);
|
|
41
|
+
logger.error(`Failed to install ${componentName}: ${error.message}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
installed,
|
|
46
|
+
skipped,
|
|
47
|
+
failed,
|
|
48
|
+
npmDependencies,
|
|
49
|
+
conflicts
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export async function updateBarrelFile(options) {
|
|
53
|
+
const { cwd, config, lockfile } = options;
|
|
54
|
+
const ext = inferScriptExtension(config);
|
|
55
|
+
const barrelPath = path.resolve(cwd, config.paths.components, `index.${ext}`);
|
|
56
|
+
const components = Object.keys(lockfile.components).sort();
|
|
57
|
+
const exports = components
|
|
58
|
+
.map((name) => `export { ${name} } from "./${name}"`)
|
|
59
|
+
.join("\n");
|
|
60
|
+
const content = `// Auto-generated barrel file
|
|
61
|
+
// This file exports all components from this directory
|
|
62
|
+
|
|
63
|
+
${exports}
|
|
64
|
+
`;
|
|
65
|
+
await writeFileSafe(barrelPath, content, true);
|
|
66
|
+
}
|
|
67
|
+
export async function installNpmDependencies(options) {
|
|
68
|
+
const { cwd, dependencies, spinner } = options;
|
|
69
|
+
const packageManager = await detectPackageManager(cwd);
|
|
70
|
+
const installCmd = packageManager === "npm" ? "install" : "add";
|
|
71
|
+
try {
|
|
72
|
+
spinner?.start(`Installing ${dependencies.size} npm package${dependencies.size > 1 ? "s" : ""}...`);
|
|
73
|
+
await execa(packageManager, [installCmd, ...Array.from(dependencies)], { cwd });
|
|
74
|
+
spinner?.succeed("NPM packages installed");
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
spinner?.fail("Failed to install npm packages");
|
|
78
|
+
throw new Error(`Failed to install dependencies: ${error.message}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
81
|
//# sourceMappingURL=install.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function detectPackageManager(cwd: string): Promise<string>;
|
|
1
|
+
export declare function detectPackageManager(cwd: string): Promise<string>;
|