@inspecto-dev/cli 0.2.0-alpha.0
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/.turbo/turbo-build.log +19 -0
- package/.turbo/turbo-test.log +15 -0
- package/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +78 -0
- package/TESTING.md +109 -0
- package/bin/inspecto.js +3 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +83 -0
- package/dist/chunk-4RR7PTRN.js +1306 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +10 -0
- package/package.json +38 -0
- package/src/bin.ts +89 -0
- package/src/commands/doctor.ts +185 -0
- package/src/commands/init.ts +447 -0
- package/src/commands/teardown.ts +124 -0
- package/src/detect/ai-tool.ts +127 -0
- package/src/detect/build-tool.ts +123 -0
- package/src/detect/framework.ts +65 -0
- package/src/detect/ide.ts +78 -0
- package/src/detect/package-manager.ts +56 -0
- package/src/index.ts +5 -0
- package/src/inject/ast-injector.ts +300 -0
- package/src/inject/extension.ts +140 -0
- package/src/inject/gitignore.ts +76 -0
- package/src/types.ts +48 -0
- package/src/utils/exec.ts +44 -0
- package/src/utils/fs.ts +69 -0
- package/src/utils/logger.ts +64 -0
- package/tests/framework.test.ts +65 -0
- package/tests/ide.test.ts +94 -0
- package/tsconfig.json +13 -0
- package/tsup.config.ts +10 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
> @inspecto-dev/cli@0.2.0-alpha.0 build /Users/bytedance/Works/hugo.felix/inspecto/packages/cli
|
|
3
|
+
> tsup
|
|
4
|
+
|
|
5
|
+
CLI Building entry: src/bin.ts, src/index.ts
|
|
6
|
+
CLI Using tsconfig: tsconfig.json
|
|
7
|
+
CLI tsup v8.5.1
|
|
8
|
+
CLI Using tsup config: /Users/bytedance/Works/hugo.felix/inspecto/packages/cli/tsup.config.ts
|
|
9
|
+
CLI Target: node18
|
|
10
|
+
CLI Cleaning output folder
|
|
11
|
+
ESM Build start
|
|
12
|
+
ESM dist/index.js 109.00 B
|
|
13
|
+
ESM dist/chunk-4RR7PTRN.js 44.32 KB
|
|
14
|
+
ESM dist/bin.js 2.47 KB
|
|
15
|
+
ESM ⚡️ Build success in 25ms
|
|
16
|
+
DTS Build start
|
|
17
|
+
DTS ⚡️ Build success in 1355ms
|
|
18
|
+
DTS dist/bin.d.ts 13.00 B
|
|
19
|
+
DTS dist/index.d.ts 1.16 KB
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
> @inspecto/cli@0.1.0 test /Users/bytedance/Works/hugo.felix/inspecto/packages/cli
|
|
3
|
+
> vitest run --passWithNoTests
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
RUN v1.6.1 /Users/bytedance/Works/hugo.felix/inspecto/packages/cli
|
|
7
|
+
|
|
8
|
+
✓ tests/framework.test.ts (5 tests) 3ms
|
|
9
|
+
✓ tests/ide.test.ts (6 tests) 3ms
|
|
10
|
+
|
|
11
|
+
Test Files 2 passed (2)
|
|
12
|
+
Tests 11 passed (11)
|
|
13
|
+
Start at 11:28:38
|
|
14
|
+
Duration 783ms (transform 117ms, setup 0ms, collect 167ms, tests 6ms, environment 0ms, prepare 810ms)
|
|
15
|
+
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @inspecto-dev/cli
|
|
2
|
+
|
|
3
|
+
## 0.2.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b3cd76b: Initial release of Inspecto
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- release first internal alpha version
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- Updated dependencies [b3cd76b]
|
|
14
|
+
- @inspecto-dev/types@0.2.0-alpha.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Inspecto Contributors
|
|
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
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @inspecto-dev/cli
|
|
2
|
+
|
|
3
|
+
The official command-line interface for Inspecto. This tool automates the process of scaffolding, configuring, and maintaining the Inspecto setup within your project.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can use the CLI without installing it globally by using `npx`:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx inspecto <command>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Alternatively, you can install it as a dev dependency in your project:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -D @inspecto-dev/cli
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Commands
|
|
20
|
+
|
|
21
|
+
### `inspecto init`
|
|
22
|
+
|
|
23
|
+
The primary command to scaffold Inspecto into a project. It performs a comprehensive environmental analysis and automatically configures Inspecto.
|
|
24
|
+
|
|
25
|
+
**Features:**
|
|
26
|
+
|
|
27
|
+
- **Package Manager Detection:** Auto-detects `npm`, `pnpm`, `yarn`, or `bun`.
|
|
28
|
+
- **Build Tool / Framework Detection:** Detects Vite, Webpack, Rspack, Rsbuild, and Next.js. Supports legacy versions (e.g., `@rspack/cli < 0.4.0`).
|
|
29
|
+
- **IDE Detection:** Prioritizes environment variables, then falls back to directory structures to accurately detect VS Code, Cursor, Trae, Windsurf, or WebStorm.
|
|
30
|
+
- **AI Tool Detection:** Scans for both CLI-based tools (Claude, Coco, CodeX, Gemini) and IDE Plugins (GitHub Copilot, Claude Code, Gemini, CodeX).
|
|
31
|
+
- **Interactive Prompts:** If multiple build configurations or AI tools are detected, it presents an interactive prompt for you to select your preferred configuration.
|
|
32
|
+
- **AST Injection:** Safely injects the `@inspecto-dev/plugin` into your build configuration file (`vite.config.ts`, `rspack.config.js`, etc.) using AST transformation, preventing duplicate injections.
|
|
33
|
+
- **IDE Extension Installation:** Uses a robust 4-level waterfall strategy to install the necessary IDE extension.
|
|
34
|
+
- **Configuration Scaffolding:** Generates the `.inspecto/settings.json` file tailored to your detected or selected AI tools, and updates `.gitignore` to prevent committing local settings.
|
|
35
|
+
|
|
36
|
+
### `inspecto doctor`
|
|
37
|
+
|
|
38
|
+
A diagnostic command to verify your current environment.
|
|
39
|
+
|
|
40
|
+
**Features:**
|
|
41
|
+
|
|
42
|
+
- Checks if the current project is a recognized framework/build tool.
|
|
43
|
+
- Verifies if the IDE is supported.
|
|
44
|
+
- Scans for available AI tools (both CLI and Plugin modes).
|
|
45
|
+
- Validates the current Inspecto installation and configuration.
|
|
46
|
+
|
|
47
|
+
### `inspecto teardown`
|
|
48
|
+
|
|
49
|
+
A clean-up command to remove Inspecto from your project.
|
|
50
|
+
|
|
51
|
+
**Features:**
|
|
52
|
+
|
|
53
|
+
- Uninstalls `@inspecto-dev/plugin` and `@inspecto-dev/cli`.
|
|
54
|
+
- Uses AST transformation to carefully remove the plugin injection from your build configuration file.
|
|
55
|
+
- Deletes the `.inspecto` directory and its contents.
|
|
56
|
+
- Restores `.gitignore` by removing Inspecto-specific rules.
|
|
57
|
+
|
|
58
|
+
## Technical Details
|
|
59
|
+
|
|
60
|
+
### Waterfall Degradation Strategy
|
|
61
|
+
|
|
62
|
+
The CLI employs a resilient fallback strategy for certain operations, such as installing IDE extensions.
|
|
63
|
+
|
|
64
|
+
**IDE Extension Installation Levels:**
|
|
65
|
+
|
|
66
|
+
1. **PATH Command:** Attempts to use the IDE's CLI command (e.g., `code --install-extension`).
|
|
67
|
+
2. **Binary Path:** Searches known default installation paths for the IDE binary across different operating systems (macOS, Linux, Windows).
|
|
68
|
+
3. **URI Scheme:** Uses the IDE's deep-link URI scheme (e.g., `vscode:extension/inspecto...`).
|
|
69
|
+
4. **Manual:** If all else fails, provides explicit instructions for the user to install the extension manually.
|
|
70
|
+
|
|
71
|
+
### AI Tool Detection
|
|
72
|
+
|
|
73
|
+
The CLI intelligently detects AI tools across two modes:
|
|
74
|
+
|
|
75
|
+
- **CLI Mode:** Checks the system `PATH` for known executables (e.g., `claude`, `coco`).
|
|
76
|
+
- **Plugin Mode:** Checks the IDE's extension directories (e.g., `~/.vscode/extensions`) for known plugin IDs.
|
|
77
|
+
|
|
78
|
+
When a tool supports both modes, the CLI merges the detections and presents a unified option to the user, configuring the `settings.json` accordingly.
|
package/TESTING.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Inspecto CLI Manual Testing Checklist
|
|
2
|
+
|
|
3
|
+
The Inspecto CLI relies on detecting various project states (package managers, frameworks, build tools, and IDEs) and safely mutating user files via AST parsing. While we have automated tests, the complexity of real-world project configurations means manual end-to-end (E2E) testing is critical before a release.
|
|
4
|
+
|
|
5
|
+
Use this checklist to perform a comprehensive regression test of the CLI.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Preparation
|
|
10
|
+
|
|
11
|
+
Create a fresh testing environment using a supported toolchain (e.g., Rsbuild + React) in the `playground/` directory:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
cd playground
|
|
15
|
+
npx create-rsbuild@latest test-cli-rspack --template react-ts
|
|
16
|
+
cd test-cli-rspack
|
|
17
|
+
npm install
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
All the following tests assume you are running the commands from inside `playground/test-cli-rspack`.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Core Scenarios
|
|
25
|
+
|
|
26
|
+
### Case 1: Initial Setup (The Happy Path)
|
|
27
|
+
|
|
28
|
+
1. **Action:** Run `node ../../packages/cli/bin/inspecto.js init`
|
|
29
|
+
2. **Expectations:**
|
|
30
|
+
- Detects `npm`, `react`, and `Rsbuild (rsbuild.config.ts)`.
|
|
31
|
+
- Detects the current IDE accurately (e.g., VS Code or Trae). If it's not VS Code, it should warn about lack of support.
|
|
32
|
+
- If `@inspecto-dev/plugin` cannot be installed (e.g., registry not ready), it logs the failure but does not crash.
|
|
33
|
+
- Backs up `rsbuild.config.ts` to `rsbuild.config.ts.bak`.
|
|
34
|
+
- Injects the `inspecto()` plugin code safely into `rsbuild.config.ts` without ruining the formatting.
|
|
35
|
+
- Creates a valid `.inspecto/settings.json`.
|
|
36
|
+
- Updates `.gitignore` with fine-grained rules (`install.lock`, `cache.json`, `*.local.json`).
|
|
37
|
+
- If an error occurred during dependency installation or AST injection, the final message should be a yellow warning `⚠ Setup completed with some manual steps required`, **not** the green success `⚡ Ready!`.
|
|
38
|
+
|
|
39
|
+
### Case 2: Idempotency (Running Init Again)
|
|
40
|
+
|
|
41
|
+
1. **Action:** Run `node ../../packages/cli/bin/inspecto.js init` again in the exact same directory.
|
|
42
|
+
2. **Expectations:**
|
|
43
|
+
- Logs `Plugin already injected in rsbuild.config.ts (skipped)`.
|
|
44
|
+
- Logs `.inspecto/settings.json already exists (skipped)`.
|
|
45
|
+
- The `.gitignore` file is not duplicated.
|
|
46
|
+
- The `.inspecto/install.lock` remains valid and tracks the fact that the file was modified previously.
|
|
47
|
+
|
|
48
|
+
### Case 3: Doctor Diagnostics
|
|
49
|
+
|
|
50
|
+
1. **Action:** Run `node ../../packages/cli/bin/inspecto.js doctor`
|
|
51
|
+
2. **Expectations:**
|
|
52
|
+
- Prints a clean checklist of the environment.
|
|
53
|
+
- Successfully finds `rsbuild.config.ts` with the plugin injected.
|
|
54
|
+
- Accurately reports whether the VS Code extension is installed (if applicable).
|
|
55
|
+
- Accurately reports missing npm dependencies (if the install failed in Case 1).
|
|
56
|
+
|
|
57
|
+
### Case 4: Fault Tolerance Diagnostics
|
|
58
|
+
|
|
59
|
+
1. **Action:**
|
|
60
|
+
- Open `.inspecto/settings.json` and purposely ruin the JSON syntax (e.g., delete a curly brace or add random text).
|
|
61
|
+
- Run `node ../../packages/cli/bin/inspecto.js doctor` again.
|
|
62
|
+
2. **Expectations:**
|
|
63
|
+
- Does not crash.
|
|
64
|
+
- Safely catches the JSON parse error and logs `✘ .inspecto/settings.json has invalid JSON`.
|
|
65
|
+
|
|
66
|
+
### Case 5: Precise Teardown (Rollback)
|
|
67
|
+
|
|
68
|
+
1. **Action:** Fix the JSON file from Case 4, then run `node ../../packages/cli/bin/inspecto.js teardown`
|
|
69
|
+
2. **Expectations:**
|
|
70
|
+
- Reads `.inspecto/install.lock`.
|
|
71
|
+
- Completely restores `rsbuild.config.ts` back to its original state using the `.bak` file, and deletes the `.bak` file.
|
|
72
|
+
- Removes `@inspecto-dev/plugin` from `package.json` `devDependencies` (if it was installed).
|
|
73
|
+
- Cleans up the `# Inspecto` block from `.gitignore`.
|
|
74
|
+
- Deletes the entire `.inspecto/` directory.
|
|
75
|
+
- Leaves no trace behind.
|
|
76
|
+
|
|
77
|
+
### Case 6: Best-Effort Teardown (Missing Lock File)
|
|
78
|
+
|
|
79
|
+
1. **Action:**
|
|
80
|
+
- Run `init` again to generate the files.
|
|
81
|
+
- Manually delete the `.inspecto/` folder (which contains `install.lock`).
|
|
82
|
+
- Run `node ../../packages/cli/bin/inspecto.js teardown`
|
|
83
|
+
2. **Expectations:**
|
|
84
|
+
- Logs `⚠ No .inspecto/install.lock found. Running in best-effort mode.`
|
|
85
|
+
- Still manages to uninstall the npm dependency.
|
|
86
|
+
- Still manages to clean the `.gitignore` entries.
|
|
87
|
+
- Instructs the user to manually remove the AST injection since there is no backup to restore from.
|
|
88
|
+
|
|
89
|
+
### Case 7: Ambiguous Config Resolution
|
|
90
|
+
|
|
91
|
+
1. **Action:**
|
|
92
|
+
- Create an empty dummy file named `vite.config.ts` in the project root to simulate a mixed/conflicting configuration.
|
|
93
|
+
- Run `node ../../packages/cli/bin/inspecto.js init`
|
|
94
|
+
2. **Expectations:**
|
|
95
|
+
- The CLI stops and presents an interactive prompt `? Detected multiple build tool configs:`.
|
|
96
|
+
- Allows the user to select either Rsbuild or Vite via arrow keys, or choose "Skip".
|
|
97
|
+
- If the user selects one, it attempts injection on the selected file only.
|
|
98
|
+
|
|
99
|
+
### Case 8: Interactive IDE Prompt
|
|
100
|
+
|
|
101
|
+
1. **Action:**
|
|
102
|
+
- Simulate opening the project in multiple IDEs by creating empty directories: `mkdir .vscode && mkdir .idea`.
|
|
103
|
+
- Open your terminal in a different IDE (e.g., Trae or Cursor).
|
|
104
|
+
- Run `node ../../packages/cli/bin/inspecto.js init`
|
|
105
|
+
2. **Expectations:**
|
|
106
|
+
- Detects the current terminal IDE **and** the directory artifacts.
|
|
107
|
+
- Pauses and asks `? Detected multiple IDEs:`.
|
|
108
|
+
- Shows which ones are `(supported)` vs `(unsupported)`.
|
|
109
|
+
- Updates `settings.json` with the chosen IDE if it is supported.
|
package/bin/inspecto.js
ADDED
package/dist/bin.d.ts
ADDED
package/dist/bin.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
doctor,
|
|
3
|
+
init,
|
|
4
|
+
log,
|
|
5
|
+
teardown
|
|
6
|
+
} from "./chunk-4RR7PTRN.js";
|
|
7
|
+
|
|
8
|
+
// src/bin.ts
|
|
9
|
+
import { parseArgs } from "util";
|
|
10
|
+
var HELP = `
|
|
11
|
+
\u2726 Inspecto CLI (v1)
|
|
12
|
+
|
|
13
|
+
Supported: VS Code | React + Vue | Vite + Webpack + Rspack + esbuild + Rollup
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
inspecto init Set up Inspecto in your project
|
|
17
|
+
inspecto doctor Diagnose your Inspecto installation
|
|
18
|
+
inspecto teardown Remove Inspecto from your project
|
|
19
|
+
|
|
20
|
+
Init Options:
|
|
21
|
+
--shared Share .inspecto/settings.json with your team via Git
|
|
22
|
+
--skip-install Skip npm dependency installation
|
|
23
|
+
--dry-run Preview changes without modifying files
|
|
24
|
+
--prefer <tool> Set default AI tool (e.g. github-copilot, claude-code)
|
|
25
|
+
--no-extension Skip VS Code extension installation
|
|
26
|
+
--packages <names> (Monorepo) Comma-separated list of packages to inject
|
|
27
|
+
|
|
28
|
+
Examples:
|
|
29
|
+
npx inspecto init
|
|
30
|
+
npx inspecto init --shared --prefer github-copilot
|
|
31
|
+
npx inspecto init --dry-run
|
|
32
|
+
npx inspecto doctor
|
|
33
|
+
npx inspecto teardown
|
|
34
|
+
`;
|
|
35
|
+
async function main() {
|
|
36
|
+
const args = process.argv.slice(2);
|
|
37
|
+
const command = args[0];
|
|
38
|
+
if (!command || command === "--help" || command === "-h") {
|
|
39
|
+
console.log(HELP);
|
|
40
|
+
process.exit(0);
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
switch (command) {
|
|
44
|
+
case "init": {
|
|
45
|
+
const { values } = parseArgs({
|
|
46
|
+
args: args.slice(1),
|
|
47
|
+
options: {
|
|
48
|
+
shared: { type: "boolean", default: false },
|
|
49
|
+
"skip-install": { type: "boolean", default: false },
|
|
50
|
+
"dry-run": { type: "boolean", default: false },
|
|
51
|
+
prefer: { type: "string" },
|
|
52
|
+
"no-extension": { type: "boolean", default: false },
|
|
53
|
+
packages: { type: "string" }
|
|
54
|
+
},
|
|
55
|
+
strict: true
|
|
56
|
+
});
|
|
57
|
+
await init({
|
|
58
|
+
shared: values.shared ?? false,
|
|
59
|
+
skipInstall: values["skip-install"] ?? false,
|
|
60
|
+
dryRun: values["dry-run"] ?? false,
|
|
61
|
+
...values.prefer && { prefer: values.prefer },
|
|
62
|
+
noExtension: values["no-extension"] ?? false,
|
|
63
|
+
...values.packages && { packages: values.packages.split(",").map((s) => s.trim()) }
|
|
64
|
+
});
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case "doctor":
|
|
68
|
+
await doctor();
|
|
69
|
+
break;
|
|
70
|
+
case "teardown":
|
|
71
|
+
await teardown();
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
log.error(`Unknown command: ${command}`);
|
|
75
|
+
console.log(HELP);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
log.error(err instanceof Error ? err.message : String(err));
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
main();
|