@dofu-lab/simui-cli 0.1.1 → 0.1.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dofu Lab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -8,11 +8,13 @@ A small, focused CLI to fetch and inject SimUI Angular components into an existi
8
8
  This tool fetches component source from the SimUI registry (https://simui.dev/registry), writes the component file into your project, and offers to install any detected dependencies (Spartan UI generators and ng-icons).
9
9
 
10
10
  Features
11
+
11
12
  - Fetch a component by name and inject it into your project
12
13
  - Detects `@spartan-ng/helm/*` and `@ng-icons/*` imports and offers to install them
13
14
  - Default output path: `src/app/components` (configurable with `--path`)
14
15
 
15
16
  Prerequisites
17
+
16
18
  - Node.js >= 18
17
19
  - An Angular project (CLI available via `ng`)
18
20
 
@@ -110,4 +112,3 @@ This project is licensed under the MIT License — see the `LICENSE` file for de
110
112
  Support
111
113
 
112
114
  If you encounter issues, open an issue on the repository with logs and reproduction steps.
113
-
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { Command } from "commander";
7
7
  import * as p from "@clack/prompts";
8
8
  import chalk from "chalk";
9
9
  import { existsSync as existsSync2, mkdirSync, writeFileSync } from "fs";
10
- import { join as join2, resolve } from "path";
10
+ import { dirname, join as join2, resolve } from "path";
11
11
  import { execSync } from "child_process";
12
12
 
13
13
  // src/utils/registry.ts
@@ -36,7 +36,9 @@ Browse available components at https://simui.dev`
36
36
  throw new Error(`Invalid response from registry for "${name}"`);
37
37
  }
38
38
  if (typeof data !== "object" || data === null || !("content" in data) || typeof data.content !== "string") {
39
- throw new Error(`Unexpected registry format for "${name}" \u2014 expected { content: string }`);
39
+ throw new Error(
40
+ `Unexpected registry format for "${name}" \u2014 expected { content: string }`
41
+ );
40
42
  }
41
43
  return data.content;
42
44
  }
@@ -70,6 +72,19 @@ function detectPackageManager(cwd) {
70
72
  // src/commands/add.ts
71
73
  async function addComponent(componentName, options) {
72
74
  const cwd = process.cwd();
75
+ function findProjectRoot(startPath) {
76
+ let dir = resolve(startPath);
77
+ const root = dirname(dir);
78
+ while (true) {
79
+ const pkgPath = join2(dir, "package.json");
80
+ const ngPath = join2(dir, "angular.json");
81
+ if (existsSync2(pkgPath) || existsSync2(ngPath)) return dir;
82
+ const parent = dirname(dir);
83
+ if (parent === dir) break;
84
+ dir = parent;
85
+ }
86
+ return null;
87
+ }
73
88
  p.intro(chalk.bold.cyan(`SimUI`) + chalk.dim(` \u2014 adding ${componentName}`));
74
89
  const spinner2 = p.spinner();
75
90
  spinner2.start("Fetching component from registry\u2026");
@@ -84,6 +99,7 @@ async function addComponent(componentName, options) {
84
99
  }
85
100
  const outputDir = options.path ? resolve(cwd, options.path) : join2(cwd, "src", "app", "components");
86
101
  const outputFile = join2(outputDir, `${componentName}.component.ts`);
102
+ const installCwd = findProjectRoot(outputDir) || cwd;
87
103
  if (existsSync2(outputFile)) {
88
104
  const overwrite = await p.confirm({
89
105
  message: `${chalk.yellow(outputFile.replace(cwd + "/", ""))} already exists. Overwrite?`,
@@ -98,7 +114,11 @@ async function addComponent(componentName, options) {
98
114
  mkdirSync(outputDir, { recursive: true });
99
115
  writeFileSync(outputFile, content, "utf-8");
100
116
  } catch (err) {
101
- p.outro(chalk.red(`Could not write file: ${err instanceof Error ? err.message : err}`));
117
+ p.outro(
118
+ chalk.red(
119
+ `Could not write file: ${err instanceof Error ? err.message : err}`
120
+ )
121
+ );
102
122
  process.exit(1);
103
123
  }
104
124
  const relativePath = outputFile.replace(cwd + "/", "");
@@ -111,7 +131,9 @@ async function addComponent(componentName, options) {
111
131
  }
112
132
  p.log.info(chalk.bold("Dependencies detected in this component:"));
113
133
  for (const d of spartanHelm) {
114
- p.log.message(` ${chalk.cyan("@spartan-ng/helm/")}${d} ${chalk.dim("(via Spartan CLI)")}`);
134
+ p.log.message(
135
+ ` ${chalk.cyan("@spartan-ng/helm/")}${d} ${chalk.dim("(via Spartan CLI)")}`
136
+ );
115
137
  }
116
138
  for (const d of ngIcons) {
117
139
  p.log.message(` ${chalk.cyan(d)}`);
@@ -121,26 +143,36 @@ async function addComponent(componentName, options) {
121
143
  initialValue: true
122
144
  });
123
145
  if (p.isCancel(shouldInstall) || !shouldInstall) {
124
- p.log.warn("Skipped dependency installation. Install them manually before using the component.");
146
+ p.log.warn(
147
+ "Skipped dependency installation. Install them manually before using the component."
148
+ );
125
149
  p.outro(chalk.dim("Done."));
126
150
  return;
127
151
  }
128
- const pm = detectPackageManager(cwd);
129
- p.log.info(`Using ${chalk.bold(pm)}`);
152
+ const pm = detectPackageManager(installCwd);
153
+ p.log.info(
154
+ `Installing dependencies in ${chalk.bold(installCwd)} using ${chalk.bold(pm)}`
155
+ );
130
156
  for (const helmPkg of spartanHelm) {
131
157
  const installSpinner = p.spinner();
132
158
  installSpinner.start(`Installing @spartan-ng/helm/${helmPkg}\u2026`);
133
159
  try {
134
160
  execSync(`npx ng generate @spartan-ng/cli:ui ${helmPkg}`, {
135
- cwd,
161
+ cwd: installCwd,
136
162
  stdio: "pipe"
137
163
  });
138
- installSpinner.stop(chalk.green(`@spartan-ng/helm/${helmPkg} installed via generator`));
164
+ installSpinner.stop(
165
+ chalk.green(`@spartan-ng/helm/${helmPkg} installed via generator`)
166
+ );
139
167
  } catch (err) {
140
- installSpinner.stop(chalk.red(`Failed to install @spartan-ng/helm/${helmPkg}`));
168
+ installSpinner.stop(
169
+ chalk.red(`Failed to install @spartan-ng/helm/${helmPkg}`)
170
+ );
141
171
  const stderr = err instanceof Error && "stderr" in err ? String(err.stderr) : "";
142
172
  p.log.warn(chalk.dim(stderr.trim() || String(err)));
143
- p.log.warn(`If this fails, try running: ${chalk.bold(`ng generate @spartan-ng/cli:ui ${helmPkg}`)}`);
173
+ p.log.warn(
174
+ `If this fails, try running: ${chalk.bold(`ng generate @spartan-ng/cli:ui ${helmPkg}`)}`
175
+ );
144
176
  }
145
177
  }
146
178
  if (ngIcons.length > 0) {
@@ -149,7 +181,7 @@ async function addComponent(componentName, options) {
149
181
  const installSpinner = p.spinner();
150
182
  installSpinner.start(`Installing ${ngIconsStr}\u2026`);
151
183
  try {
152
- execSync(installCmd, { cwd, stdio: "pipe" });
184
+ execSync(installCmd, { cwd: installCwd, stdio: "pipe" });
153
185
  installSpinner.stop(chalk.green(`${ngIconsStr} installed`));
154
186
  } catch (err) {
155
187
  installSpinner.stop(chalk.red(`Failed to install ${ngIconsStr}`));
@@ -169,7 +201,9 @@ var __dirname = dirname2(__filename);
169
201
  var pkg = require2(join3(__dirname, "..", "package.json"));
170
202
  var program = new Command();
171
203
  program.name("simui").description("Add SimUI Angular components to your project").version(pkg.version);
172
- program.command("add <component>").description("Fetch a SimUI component from the registry and add it to your project").option(
204
+ program.command("add <component>").description(
205
+ "Fetch a SimUI component from the registry and add it to your project"
206
+ ).option(
173
207
  "-p, --path <path>",
174
208
  "Output directory relative to cwd (default: src/app/components)"
175
209
  ).action(async (component, opts) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dofu-lab/simui-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "CLI to add SimUI components to your Angular project",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",