@dofu-lab/simui-cli 0.1.0 → 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.
- package/README.md +62 -97
- package/dist/index.js +22 -7
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,148 +1,113 @@
|
|
|
1
|
-
# @simui
|
|
1
|
+
# @dofu-lab/simui-cli
|
|
2
2
|
|
|
3
|
-
A CLI to
|
|
3
|
+
A small, focused CLI to fetch and inject SimUI Angular components into an existing Angular project.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@dofu-lab/simui-cli)
|
|
6
|
+
[](#license)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
# Using npx (no install required)
|
|
9
|
-
npx @simui/cli add accordion-01
|
|
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).
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
Features
|
|
11
|
+
- Fetch a component by name and inject it into your project
|
|
12
|
+
- Detects `@spartan-ng/helm/*` and `@ng-icons/*` imports and offers to install them
|
|
13
|
+
- Default output path: `src/app/components` (configurable with `--path`)
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
Prerequisites
|
|
16
|
+
- Node.js >= 18
|
|
17
|
+
- An Angular project (CLI available via `ng`)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
Installation (local use)
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
You can run the CLI directly from the built artifact in this repository without publishing to npm:
|
|
21
22
|
|
|
22
23
|
```bash
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
cd packages/cli
|
|
25
|
+
npm install
|
|
26
|
+
npm run build
|
|
27
|
+
node dist/index.js add accordion-01
|
|
26
28
|
```
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
| Flag | Default | Description |
|
|
31
|
-
|------|---------|-------------|
|
|
32
|
-
| `-p, --path <dir>` | `src/app/components` | Output directory (relative to cwd) |
|
|
33
|
-
|
|
34
|
-
**Examples:**
|
|
30
|
+
Usage
|
|
35
31
|
|
|
36
32
|
```bash
|
|
37
|
-
#
|
|
38
|
-
|
|
33
|
+
# Fetch and add a component to the default location
|
|
34
|
+
node dist/index.js add accordion-01
|
|
39
35
|
|
|
40
|
-
#
|
|
41
|
-
simui add
|
|
36
|
+
# Use the published package (once available)
|
|
37
|
+
npx @dofu-lab/simui-cli add accordion-01
|
|
42
38
|
|
|
43
|
-
#
|
|
44
|
-
|
|
39
|
+
# Override output directory
|
|
40
|
+
node dist/index.js add badge-01 --path src/shared/ui
|
|
45
41
|
```
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
1. **Fetches** the component TypeScript source from `https://simui.dev/registry/<name>.json`
|
|
50
|
-
2. **Writes** the file to the resolved output path
|
|
51
|
-
3. **Detects** required `@spartan-ng/helm/*` and `@ng-icons/*` imports
|
|
52
|
-
4. **Prompts** you to install them:
|
|
53
|
-
- Spartan UI packages — installed via `npx @spartan-ng/cli@latest add <package>`
|
|
54
|
-
- `@ng-icons/*` packages — installed via your detected package manager (pnpm / yarn / npm)
|
|
55
|
-
|
|
56
|
-
## Requirements
|
|
57
|
-
|
|
58
|
-
- Node.js ≥ 18
|
|
59
|
-
- An Angular project with [Spartan UI](https://spartan.ng) configured
|
|
43
|
+
Commands
|
|
60
44
|
|
|
61
|
-
|
|
45
|
+
- `add <component>` — fetches `<component>` from the registry and writes `<component>.component.ts` to the output directory.
|
|
62
46
|
|
|
63
|
-
|
|
47
|
+
Options
|
|
64
48
|
|
|
65
|
-
|
|
49
|
+
- `-p, --path <dir>` — Output directory relative to the current working directory (default: `src/app/components`).
|
|
66
50
|
|
|
67
|
-
|
|
51
|
+
What the command does
|
|
68
52
|
|
|
69
|
-
1.
|
|
53
|
+
1. Fetches `https://simui.dev/registry/<name>.json` and reads the `content` field.
|
|
54
|
+
2. Writes the TypeScript component file to the chosen output path.
|
|
55
|
+
3. Parses the source for `@spartan-ng/helm/*` and `@ng-icons/*` imports.
|
|
56
|
+
4. Prompts to install dependencies. Spartan packages are invoked via the Angular generator:
|
|
70
57
|
|
|
71
58
|
```bash
|
|
72
|
-
|
|
73
|
-
npm test # if you have tests
|
|
74
|
-
npm run lint # if you have a lint script
|
|
59
|
+
ng generate @spartan-ng/cli:ui <package>
|
|
75
60
|
```
|
|
76
61
|
|
|
77
|
-
|
|
62
|
+
And `@ng-icons/*` packages are installed via your detected package manager (`pnpm`, `yarn`, or `npm`).
|
|
63
|
+
|
|
64
|
+
Development
|
|
78
65
|
|
|
79
66
|
```bash
|
|
80
67
|
cd packages/cli
|
|
81
|
-
npm
|
|
82
|
-
|
|
68
|
+
npm install
|
|
69
|
+
npm run build
|
|
70
|
+
# Run the CLI locally
|
|
71
|
+
node dist/index.js add select-01
|
|
83
72
|
```
|
|
84
73
|
|
|
85
|
-
|
|
74
|
+
Publishing
|
|
86
75
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
4. Build the package
|
|
76
|
+
Follow these steps to publish a new version of this package under the `@dofu-lab` scope.
|
|
90
77
|
|
|
91
78
|
```bash
|
|
92
79
|
cd packages/cli
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
5. Dry-run publish / pack
|
|
80
|
+
# bump version (creates a commit + tag)
|
|
81
|
+
npm version patch
|
|
97
82
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
npm pack
|
|
83
|
+
# build
|
|
84
|
+
npm run build
|
|
101
85
|
|
|
102
|
-
#
|
|
86
|
+
# dry-run
|
|
103
87
|
npm publish --dry-run
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
6. Login to npm (if needed)
|
|
107
|
-
|
|
108
|
-
```bash
|
|
109
|
-
npm whoami || npm login
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
7. Publish to npm
|
|
113
88
|
|
|
114
|
-
|
|
115
|
-
cd packages/cli
|
|
89
|
+
# publish (scoped public requires --access public)
|
|
116
90
|
npm publish --access public
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
8. Push changes and tags to the remote repo
|
|
120
91
|
|
|
121
|
-
|
|
122
|
-
# from repo root
|
|
92
|
+
# push commits and tags
|
|
123
93
|
git push origin main
|
|
124
94
|
git push --tags
|
|
125
95
|
```
|
|
126
96
|
|
|
127
|
-
|
|
97
|
+
Contributing
|
|
128
98
|
|
|
129
|
-
|
|
130
|
-
gh release create vX.Y.Z --title "vX.Y.Z" --notes "Short changelog"
|
|
131
|
-
```
|
|
99
|
+
Contributions are welcome. Open issues or pull requests against this repository. For code changes:
|
|
132
100
|
|
|
133
|
-
|
|
101
|
+
1. Fork the repo
|
|
102
|
+
2. Create a feature branch
|
|
103
|
+
3. Run tests and build locally
|
|
104
|
+
4. Submit a pull request
|
|
134
105
|
|
|
135
|
-
|
|
136
|
-
# try via npx
|
|
137
|
-
npx @simui/cli@latest add accordion-01
|
|
106
|
+
License
|
|
138
107
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
```
|
|
108
|
+
This project is licensed under the MIT License — see the `LICENSE` file for details.
|
|
109
|
+
|
|
110
|
+
Support
|
|
143
111
|
|
|
144
|
-
|
|
145
|
-
- If your package is scoped (e.g. `@simui/cli`) publishing publicly requires `--access public`.
|
|
146
|
-
- If your npm account has 2FA enabled, you'll be prompted for an OTP when publishing.
|
|
147
|
-
- For CI-based publishing, use an `NPM_TOKEN` and run `npm publish` from the pipeline.
|
|
112
|
+
If you encounter issues, open an issue on the repository with logs and reproduction steps.
|
|
148
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
|
|
@@ -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,21 +139,22 @@ async function addComponent(componentName, options) {
|
|
|
125
139
|
p.outro(chalk.dim("Done."));
|
|
126
140
|
return;
|
|
127
141
|
}
|
|
128
|
-
const pm = detectPackageManager(
|
|
129
|
-
p.log.info(`
|
|
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
|
-
execSync(`npx @spartan-ng/cli
|
|
135
|
-
cwd,
|
|
148
|
+
execSync(`npx ng generate @spartan-ng/cli:ui ${helmPkg}`, {
|
|
149
|
+
cwd: installCwd,
|
|
136
150
|
stdio: "pipe"
|
|
137
151
|
});
|
|
138
|
-
installSpinner.stop(chalk.green(`@spartan-ng/helm/${helmPkg} installed`));
|
|
152
|
+
installSpinner.stop(chalk.green(`@spartan-ng/helm/${helmPkg} installed via generator`));
|
|
139
153
|
} catch (err) {
|
|
140
154
|
installSpinner.stop(chalk.red(`Failed to install @spartan-ng/helm/${helmPkg}`));
|
|
141
155
|
const stderr = err instanceof Error && "stderr" in err ? String(err.stderr) : "";
|
|
142
156
|
p.log.warn(chalk.dim(stderr.trim() || String(err)));
|
|
157
|
+
p.log.warn(`If this fails, try running: ${chalk.bold(`ng generate @spartan-ng/cli:ui ${helmPkg}`)}`);
|
|
143
158
|
}
|
|
144
159
|
}
|
|
145
160
|
if (ngIcons.length > 0) {
|
|
@@ -148,7 +163,7 @@ async function addComponent(componentName, options) {
|
|
|
148
163
|
const installSpinner = p.spinner();
|
|
149
164
|
installSpinner.start(`Installing ${ngIconsStr}\u2026`);
|
|
150
165
|
try {
|
|
151
|
-
execSync(installCmd, { cwd, stdio: "pipe" });
|
|
166
|
+
execSync(installCmd, { cwd: installCwd, stdio: "pipe" });
|
|
152
167
|
installSpinner.stop(chalk.green(`${ngIconsStr} installed`));
|
|
153
168
|
} catch (err) {
|
|
154
169
|
installSpinner.stop(chalk.red(`Failed to install ${ngIconsStr}`));
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dofu-lab/simui-cli",
|
|
3
|
-
"version": "0.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",
|
|
7
7
|
"bin": {
|
|
8
8
|
"simui": "./dist/index.js"
|
|
9
9
|
},
|
|
10
|
-
"files": [
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
11
13
|
"scripts": {
|
|
12
14
|
"build": "tsup",
|
|
13
15
|
"dev": "tsup --watch",
|