@dofu-lab/simui-cli 0.1.1 → 0.1.2

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 (2) hide show
  1. package/dist/index.js +19 -5
  2. package/package.json +1 -1
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
@@ -70,6 +70,19 @@ function detectPackageManager(cwd) {
70
70
  // src/commands/add.ts
71
71
  async function addComponent(componentName, options) {
72
72
  const cwd = process.cwd();
73
+ function findProjectRoot(startPath) {
74
+ let dir = resolve(startPath);
75
+ const root = dirname(dir);
76
+ while (true) {
77
+ const pkgPath = join2(dir, "package.json");
78
+ const ngPath = join2(dir, "angular.json");
79
+ if (existsSync2(pkgPath) || existsSync2(ngPath)) return dir;
80
+ const parent = dirname(dir);
81
+ if (parent === dir) break;
82
+ dir = parent;
83
+ }
84
+ return null;
85
+ }
73
86
  p.intro(chalk.bold.cyan(`SimUI`) + chalk.dim(` \u2014 adding ${componentName}`));
74
87
  const spinner2 = p.spinner();
75
88
  spinner2.start("Fetching component from registry\u2026");
@@ -84,6 +97,7 @@ async function addComponent(componentName, options) {
84
97
  }
85
98
  const outputDir = options.path ? resolve(cwd, options.path) : join2(cwd, "src", "app", "components");
86
99
  const outputFile = join2(outputDir, `${componentName}.component.ts`);
100
+ const installCwd = findProjectRoot(outputDir) || cwd;
87
101
  if (existsSync2(outputFile)) {
88
102
  const overwrite = await p.confirm({
89
103
  message: `${chalk.yellow(outputFile.replace(cwd + "/", ""))} already exists. Overwrite?`,
@@ -125,14 +139,14 @@ async function addComponent(componentName, options) {
125
139
  p.outro(chalk.dim("Done."));
126
140
  return;
127
141
  }
128
- const pm = detectPackageManager(cwd);
129
- p.log.info(`Using ${chalk.bold(pm)}`);
142
+ const pm = detectPackageManager(installCwd);
143
+ p.log.info(`Installing dependencies in ${chalk.bold(installCwd)} using ${chalk.bold(pm)}`);
130
144
  for (const helmPkg of spartanHelm) {
131
145
  const installSpinner = p.spinner();
132
146
  installSpinner.start(`Installing @spartan-ng/helm/${helmPkg}\u2026`);
133
147
  try {
134
148
  execSync(`npx ng generate @spartan-ng/cli:ui ${helmPkg}`, {
135
- cwd,
149
+ cwd: installCwd,
136
150
  stdio: "pipe"
137
151
  });
138
152
  installSpinner.stop(chalk.green(`@spartan-ng/helm/${helmPkg} installed via generator`));
@@ -149,7 +163,7 @@ async function addComponent(componentName, options) {
149
163
  const installSpinner = p.spinner();
150
164
  installSpinner.start(`Installing ${ngIconsStr}\u2026`);
151
165
  try {
152
- execSync(installCmd, { cwd, stdio: "pipe" });
166
+ execSync(installCmd, { cwd: installCwd, stdio: "pipe" });
153
167
  installSpinner.stop(chalk.green(`${ngIconsStr} installed`));
154
168
  } catch (err) {
155
169
  installSpinner.stop(chalk.red(`Failed to install ${ngIconsStr}`));
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.2",
4
4
  "description": "CLI to add SimUI components to your Angular project",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",