@programinglive/dev-workflow-mcp-server 1.5.1 → 1.5.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/.agent/workflows/dev-workflow-bugfix.md +250 -250
- package/.agent/workflows/dev-workflow-feature.md +201 -201
- package/.agent/workflows/dev-workflow-full-cycle.md +400 -400
- package/.agent/workflows/dev-workflow-refactor.md +238 -238
- package/.github/ISSUE_TEMPLATE/bug_report.md +34 -34
- package/.github/ISSUE_TEMPLATE/feature_request.md +25 -25
- package/.github/pull_request_template.md +22 -22
- package/.github/workflows/npm-publish.yml +50 -50
- package/.husky/commit-msg +0 -0
- package/CHANGELOG.md +749 -739
- package/CODE_OF_CONDUCT.md +79 -79
- package/CONTRIBUTING.md +60 -60
- package/LICENSE +21 -21
- package/README.md +632 -632
- package/SECURITY.md +20 -20
- package/db/index.js +204 -204
- package/docs/NETLIFY_DEPLOYMENT.md +125 -125
- package/docs/PLESK_DEPLOYMENT.md +170 -170
- package/docs/WORKFLOW-BEST-PRACTICES.md +58 -58
- package/docs/antigravity/EXAMPLES.md +535 -535
- package/docs/antigravity/GETTING-STARTED.md +292 -292
- package/docs/antigravity/TROUBLESHOOTING.md +742 -742
- package/docs/antigravity/WALKTHROUGH.md +25 -25
- package/docs/antigravity/WORKFLOW-TEMPLATES.md +670 -670
- package/docs/product/PRD.md +67 -67
- package/docs/release-notes/RELEASE_NOTES.md +226 -226
- package/docs/web-dashboard.md +175 -175
- package/exec.js +49 -49
- package/index.js +279 -279
- package/install.js +73 -73
- package/package.json +4 -4
- package/release-wrapper.js +192 -192
- package/scripts/build-docs.js +63 -63
- package/scripts/hello-world.js +1 -1
- package/scripts/release.cjs +252 -252
- package/scripts/update-release-notes.cjs +178 -178
- package/server.json +23 -23
- package/tailwind.config.js +8 -8
- package/tests/build.test.js +83 -91
- package/tests/exec.test.js +35 -35
- package/tests/handlers.test.js +1058 -1058
- package/tests/hello-world.test.js +13 -13
- package/tests/mcpRegistry.test.js +65 -65
- package/tests/release-wrapper.test.js +107 -107
- package/tests/workflowState.test.js +505 -505
- package/tools/definitions.js +332 -332
- package/tools/handlers.js +1019 -1019
- package/vite.config.js +43 -43
- package/vite.web.config.js +23 -23
- package/web/README.md +36 -36
- package/web/app/docs/page.tsx +202 -202
- package/web/app/globals.css +90 -90
- package/web/app/layout.tsx +36 -36
- package/web/app/page.tsx +15 -15
- package/web/components/ApiReference.tsx +20 -20
- package/web/components/Features.tsx +61 -61
- package/web/components/Footer.tsx +9 -9
- package/web/components/Hero.tsx +96 -97
- package/web/components/History.tsx +143 -143
- package/web/components/Navbar.tsx +64 -64
- package/web/components/Terminal.tsx +114 -114
- package/web/eslint.config.mjs +18 -18
- package/web/lib/db.js +131 -131
- package/web/lib/docs.js +73 -73
- package/web/netlify.toml +3 -6
- package/web/next.config.ts +12 -7
- package/web/package-lock.json +6560 -6560
- package/web/package.json +28 -28
- package/web/postcss.config.mjs +9 -9
- package/web/server.js +31 -31
- package/web/tailwind.config.ts +19 -19
- package/web/tsconfig.json +42 -42
- package/workflow-state.js +612 -612
- package/web/app/api/docs/route.ts +0 -32
- package/web/app/api/history/route.ts +0 -12
- package/web/app/api/npm-downloads/route.ts +0 -21
- package/web/app/api/summary/route.ts +0 -13
- package/web/app/api/version/route.ts +0 -8
package/docs/web-dashboard.md
CHANGED
|
@@ -1,175 +1,175 @@
|
|
|
1
|
-
# Dev Workflow Web Dashboard
|
|
2
|
-
|
|
3
|
-
Learn how to start and use the Dev Workflow dashboard included with the MCP server. The dashboard exposes project history, summaries, and aggregates through a small Node.js service.
|
|
4
|
-
|
|
5
|
-
## Prerequisites
|
|
6
|
-
|
|
7
|
-
Before launching the dashboard, confirm the following:
|
|
8
|
-
|
|
9
|
-
- Node.js 18+ installed (same requirement as the MCP server)
|
|
10
|
-
- Project dependencies installed with `npm install`
|
|
11
|
-
- Workflow history stored under `.state/` (created automatically when using the MCP server)
|
|
12
|
-
|
|
13
|
-
> **Plesk users:** follow the [Plesk installation guide](../README.md#option-3-install-on-plesk-hosting) first and ensure SSH access is enabled.
|
|
14
|
-
|
|
15
|
-
## Features
|
|
16
|
-
|
|
17
|
-
- **Task history browser** – Paginated list of completed workflow entries.
|
|
18
|
-
- **Summary stats** – Counts of tasks by type and recent activity timeline.
|
|
19
|
-
- **Aggregated trends** – Daily, monthly, or yearly breakdowns of workflow activity.
|
|
20
|
-
- **Multi-user support** – Switch between user identifiers recorded in the `.state` directory.
|
|
21
|
-
|
|
22
|
-
## Getting Started
|
|
23
|
-
|
|
24
|
-
Launch the dashboard from your project directory:
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
npm run web
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
When the server is ready you will see:
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
🌐 Dev Workflow Dashboard running at http://localhost:3111
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Open the URL in your browser. If port 3111 is in use, the script automatically selects a nearby free port.
|
|
37
|
-
|
|
38
|
-
### Choosing a Port
|
|
39
|
-
|
|
40
|
-
Set `DEV_WORKFLOW_WEB_PORT` to force a specific port:
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
DEV_WORKFLOW_WEB_PORT=5000 npm run web
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### Selecting a User
|
|
47
|
-
|
|
48
|
-
The dashboard defaults to the `default` user. Append `?user=<USER_ID>` to view another user’s data. User IDs map to the subdirectories under `.state/users/`.
|
|
49
|
-
|
|
50
|
-
```
|
|
51
|
-
http://localhost:3111/?user=my-teammate
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Navigation
|
|
55
|
-
|
|
56
|
-
The HTML frontend lives in `web/index.html`. The default UI includes:
|
|
57
|
-
|
|
58
|
-
- **Summary cards** – Total tasks completed and last active date.
|
|
59
|
-
- **Recent tasks table** – Paginated entries with task descriptions and timestamps.
|
|
60
|
-
- **Charts** (if script extensions are enabled) – Visual trends per frequency selection.
|
|
61
|
-
|
|
62
|
-
## API Reference
|
|
63
|
-
|
|
64
|
-
Interact with the dashboard programmatically using the JSON endpoints served by `web/server.js`.
|
|
65
|
-
|
|
66
|
-
### `GET /api/summary`
|
|
67
|
-
|
|
68
|
-
Returns aggregate statistics for a user.
|
|
69
|
-
|
|
70
|
-
**Query parameters**
|
|
71
|
-
|
|
72
|
-
- `user` *(optional, string)* – User identifier (default `default`).
|
|
73
|
-
|
|
74
|
-
**Response**
|
|
75
|
-
|
|
76
|
-
```json
|
|
77
|
-
{
|
|
78
|
-
"summary": {
|
|
79
|
-
"totalTasks": 12,
|
|
80
|
-
"taskTypes": { "feature": 8, "bugfix": 3, "refactor": 1 },
|
|
81
|
-
"lastActive": "2025-10-01T09:25:41.123Z",
|
|
82
|
-
"recentTasks": [
|
|
83
|
-
{ "description": "feat: add billing webhooks", "type": "feature", "timestamp": "2025-10-01T09:25:41.123Z" }
|
|
84
|
-
],
|
|
85
|
-
"updatedAt": "2025-10-01T09:30:00.000Z"
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### `GET /api/history`
|
|
91
|
-
|
|
92
|
-
Returns paginated task history.
|
|
93
|
-
|
|
94
|
-
**Query parameters**
|
|
95
|
-
|
|
96
|
-
- `user` *(optional, string)* – User identifier (default `default`).
|
|
97
|
-
- `page` *(optional, number)* – Page number (default `1`).
|
|
98
|
-
- `pageSize` *(optional, number)* – Items per page (default `20`, max `100`).
|
|
99
|
-
- `startDate` *(optional, string)* – Filter by ISO date (inclusive).
|
|
100
|
-
- `endDate` *(optional, string)* – Filter by ISO date (inclusive).
|
|
101
|
-
|
|
102
|
-
**Response**
|
|
103
|
-
|
|
104
|
-
```json
|
|
105
|
-
{
|
|
106
|
-
"entries": [
|
|
107
|
-
{
|
|
108
|
-
"id": 42,
|
|
109
|
-
"user_id": "default",
|
|
110
|
-
"task_description": "feat: add reporting endpoint",
|
|
111
|
-
"task_type": "feature",
|
|
112
|
-
"commit_message": "feat: add reporting endpoint",
|
|
113
|
-
"timestamp": "2025-09-30T09:18:00.000Z"
|
|
114
|
-
}
|
|
115
|
-
],
|
|
116
|
-
"total": 42,
|
|
117
|
-
"page": 1,
|
|
118
|
-
"pageSize": 20
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### `GET /api/history-summary`
|
|
123
|
-
|
|
124
|
-
Returns an array of task counts grouped by period.
|
|
125
|
-
|
|
126
|
-
**Query parameters**
|
|
127
|
-
|
|
128
|
-
- `user` *(optional, string)* – User identifier (default `default`).
|
|
129
|
-
- `frequency` *(optional, string)* – `daily`, `monthly`, or `yearly` (default `daily`).
|
|
130
|
-
- `startDate`, `endDate` *(optional, string)* – Limit range by ISO dates.
|
|
131
|
-
|
|
132
|
-
**Response**
|
|
133
|
-
|
|
134
|
-
```json
|
|
135
|
-
{
|
|
136
|
-
"summary": [
|
|
137
|
-
{ "period": "2025-09-30", "count": 3 },
|
|
138
|
-
{ "period": "2025-09-29", "count": 1 }
|
|
139
|
-
]
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Configuration
|
|
144
|
-
|
|
145
|
-
| Variable | Description | Default |
|
|
146
|
-
| --- | --- | --- |
|
|
147
|
-
| `DEV_WORKFLOW_WEB_PORT` | Port for the dashboard | `3111` or next available |
|
|
148
|
-
| `DEV_WORKFLOW_USER_ID` | User identifier when launching via MCP | auto-generated |
|
|
149
|
-
| `DEV_WORKFLOW_STATE_FILE` | Overrides path to workflow state JSON | auto-detected |
|
|
150
|
-
|
|
151
|
-
## Troubleshooting
|
|
152
|
-
|
|
153
|
-
| Symptom | Fix |
|
|
154
|
-
| --- | --- |
|
|
155
|
-
| Server fails with `better-sqlite3` build error | Install Python 3 and build tools (Windows) or ensure SQLite build dependencies exist (Linux/macOS). |
|
|
156
|
-
| Dashboard shows empty data | Confirm the MCP server has generated `.state/users/<user>/workflow-state.json` and that the chosen `user` matches. |
|
|
157
|
-
| Port already in use | Set `DEV_WORKFLOW_WEB_PORT` to a free port before running `npm run web`. |
|
|
158
|
-
|
|
159
|
-
## Deployment Options
|
|
160
|
-
|
|
161
|
-
The web dashboard can be deployed in multiple ways:
|
|
162
|
-
|
|
163
|
-
| Platform | Database Support | Best For |
|
|
164
|
-
| --- | --- | --- |
|
|
165
|
-
| Local (`npm run web`) | Full SQLite | Development and personal use |
|
|
166
|
-
| [Netlify](./NETLIFY_DEPLOYMENT.md) | Static only | Public documentation site |
|
|
167
|
-
| [Plesk](./PLESK_DEPLOYMENT.md) | Full SQLite | Self-hosted production |
|
|
168
|
-
|
|
169
|
-
## Related Topics
|
|
170
|
-
|
|
171
|
-
- [Main README](../README.md)
|
|
172
|
-
- [Netlify Deployment](./NETLIFY_DEPLOYMENT.md)
|
|
173
|
-
- [Plesk Deployment](./PLESK_DEPLOYMENT.md)
|
|
174
|
-
- [Workflow State Internals](./state.md) *(coming soon)*
|
|
175
|
-
- [CLI Tools](../README.md#🛠️-available-tools)
|
|
1
|
+
# Dev Workflow Web Dashboard
|
|
2
|
+
|
|
3
|
+
Learn how to start and use the Dev Workflow dashboard included with the MCP server. The dashboard exposes project history, summaries, and aggregates through a small Node.js service.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Before launching the dashboard, confirm the following:
|
|
8
|
+
|
|
9
|
+
- Node.js 18+ installed (same requirement as the MCP server)
|
|
10
|
+
- Project dependencies installed with `npm install`
|
|
11
|
+
- Workflow history stored under `.state/` (created automatically when using the MCP server)
|
|
12
|
+
|
|
13
|
+
> **Plesk users:** follow the [Plesk installation guide](../README.md#option-3-install-on-plesk-hosting) first and ensure SSH access is enabled.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- **Task history browser** – Paginated list of completed workflow entries.
|
|
18
|
+
- **Summary stats** – Counts of tasks by type and recent activity timeline.
|
|
19
|
+
- **Aggregated trends** – Daily, monthly, or yearly breakdowns of workflow activity.
|
|
20
|
+
- **Multi-user support** – Switch between user identifiers recorded in the `.state` directory.
|
|
21
|
+
|
|
22
|
+
## Getting Started
|
|
23
|
+
|
|
24
|
+
Launch the dashboard from your project directory:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm run web
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
When the server is ready you will see:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
🌐 Dev Workflow Dashboard running at http://localhost:3111
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Open the URL in your browser. If port 3111 is in use, the script automatically selects a nearby free port.
|
|
37
|
+
|
|
38
|
+
### Choosing a Port
|
|
39
|
+
|
|
40
|
+
Set `DEV_WORKFLOW_WEB_PORT` to force a specific port:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
DEV_WORKFLOW_WEB_PORT=5000 npm run web
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Selecting a User
|
|
47
|
+
|
|
48
|
+
The dashboard defaults to the `default` user. Append `?user=<USER_ID>` to view another user’s data. User IDs map to the subdirectories under `.state/users/`.
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
http://localhost:3111/?user=my-teammate
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Navigation
|
|
55
|
+
|
|
56
|
+
The HTML frontend lives in `web/index.html`. The default UI includes:
|
|
57
|
+
|
|
58
|
+
- **Summary cards** – Total tasks completed and last active date.
|
|
59
|
+
- **Recent tasks table** – Paginated entries with task descriptions and timestamps.
|
|
60
|
+
- **Charts** (if script extensions are enabled) – Visual trends per frequency selection.
|
|
61
|
+
|
|
62
|
+
## API Reference
|
|
63
|
+
|
|
64
|
+
Interact with the dashboard programmatically using the JSON endpoints served by `web/server.js`.
|
|
65
|
+
|
|
66
|
+
### `GET /api/summary`
|
|
67
|
+
|
|
68
|
+
Returns aggregate statistics for a user.
|
|
69
|
+
|
|
70
|
+
**Query parameters**
|
|
71
|
+
|
|
72
|
+
- `user` *(optional, string)* – User identifier (default `default`).
|
|
73
|
+
|
|
74
|
+
**Response**
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"summary": {
|
|
79
|
+
"totalTasks": 12,
|
|
80
|
+
"taskTypes": { "feature": 8, "bugfix": 3, "refactor": 1 },
|
|
81
|
+
"lastActive": "2025-10-01T09:25:41.123Z",
|
|
82
|
+
"recentTasks": [
|
|
83
|
+
{ "description": "feat: add billing webhooks", "type": "feature", "timestamp": "2025-10-01T09:25:41.123Z" }
|
|
84
|
+
],
|
|
85
|
+
"updatedAt": "2025-10-01T09:30:00.000Z"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### `GET /api/history`
|
|
91
|
+
|
|
92
|
+
Returns paginated task history.
|
|
93
|
+
|
|
94
|
+
**Query parameters**
|
|
95
|
+
|
|
96
|
+
- `user` *(optional, string)* – User identifier (default `default`).
|
|
97
|
+
- `page` *(optional, number)* – Page number (default `1`).
|
|
98
|
+
- `pageSize` *(optional, number)* – Items per page (default `20`, max `100`).
|
|
99
|
+
- `startDate` *(optional, string)* – Filter by ISO date (inclusive).
|
|
100
|
+
- `endDate` *(optional, string)* – Filter by ISO date (inclusive).
|
|
101
|
+
|
|
102
|
+
**Response**
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"entries": [
|
|
107
|
+
{
|
|
108
|
+
"id": 42,
|
|
109
|
+
"user_id": "default",
|
|
110
|
+
"task_description": "feat: add reporting endpoint",
|
|
111
|
+
"task_type": "feature",
|
|
112
|
+
"commit_message": "feat: add reporting endpoint",
|
|
113
|
+
"timestamp": "2025-09-30T09:18:00.000Z"
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"total": 42,
|
|
117
|
+
"page": 1,
|
|
118
|
+
"pageSize": 20
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### `GET /api/history-summary`
|
|
123
|
+
|
|
124
|
+
Returns an array of task counts grouped by period.
|
|
125
|
+
|
|
126
|
+
**Query parameters**
|
|
127
|
+
|
|
128
|
+
- `user` *(optional, string)* – User identifier (default `default`).
|
|
129
|
+
- `frequency` *(optional, string)* – `daily`, `monthly`, or `yearly` (default `daily`).
|
|
130
|
+
- `startDate`, `endDate` *(optional, string)* – Limit range by ISO dates.
|
|
131
|
+
|
|
132
|
+
**Response**
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"summary": [
|
|
137
|
+
{ "period": "2025-09-30", "count": 3 },
|
|
138
|
+
{ "period": "2025-09-29", "count": 1 }
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Configuration
|
|
144
|
+
|
|
145
|
+
| Variable | Description | Default |
|
|
146
|
+
| --- | --- | --- |
|
|
147
|
+
| `DEV_WORKFLOW_WEB_PORT` | Port for the dashboard | `3111` or next available |
|
|
148
|
+
| `DEV_WORKFLOW_USER_ID` | User identifier when launching via MCP | auto-generated |
|
|
149
|
+
| `DEV_WORKFLOW_STATE_FILE` | Overrides path to workflow state JSON | auto-detected |
|
|
150
|
+
|
|
151
|
+
## Troubleshooting
|
|
152
|
+
|
|
153
|
+
| Symptom | Fix |
|
|
154
|
+
| --- | --- |
|
|
155
|
+
| Server fails with `better-sqlite3` build error | Install Python 3 and build tools (Windows) or ensure SQLite build dependencies exist (Linux/macOS). |
|
|
156
|
+
| Dashboard shows empty data | Confirm the MCP server has generated `.state/users/<user>/workflow-state.json` and that the chosen `user` matches. |
|
|
157
|
+
| Port already in use | Set `DEV_WORKFLOW_WEB_PORT` to a free port before running `npm run web`. |
|
|
158
|
+
|
|
159
|
+
## Deployment Options
|
|
160
|
+
|
|
161
|
+
The web dashboard can be deployed in multiple ways:
|
|
162
|
+
|
|
163
|
+
| Platform | Database Support | Best For |
|
|
164
|
+
| --- | --- | --- |
|
|
165
|
+
| Local (`npm run web`) | Full SQLite | Development and personal use |
|
|
166
|
+
| [Netlify](./NETLIFY_DEPLOYMENT.md) | Static only | Public documentation site |
|
|
167
|
+
| [Plesk](./PLESK_DEPLOYMENT.md) | Full SQLite | Self-hosted production |
|
|
168
|
+
|
|
169
|
+
## Related Topics
|
|
170
|
+
|
|
171
|
+
- [Main README](../README.md)
|
|
172
|
+
- [Netlify Deployment](./NETLIFY_DEPLOYMENT.md)
|
|
173
|
+
- [Plesk Deployment](./PLESK_DEPLOYMENT.md)
|
|
174
|
+
- [Workflow State Internals](./state.md) *(coming soon)*
|
|
175
|
+
- [CLI Tools](../README.md#🛠️-available-tools)
|
package/exec.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { exec as execCallback } from "child_process";
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { fileURLToPath } from "url";
|
|
5
|
-
import { promisify } from "util";
|
|
6
|
-
|
|
7
|
-
const execPromise = promisify(execCallback);
|
|
8
|
-
|
|
9
|
-
function findRepoRoot(startDir) {
|
|
10
|
-
if (!startDir) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let current = path.resolve(startDir);
|
|
15
|
-
const { root } = path.parse(current);
|
|
16
|
-
|
|
17
|
-
while (true) {
|
|
18
|
-
if (existsSync(path.join(current, ".git"))) {
|
|
19
|
-
return current;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (current === root) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const parent = path.dirname(current);
|
|
27
|
-
if (parent === current) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
current = parent;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function getDefaultCwd() {
|
|
36
|
-
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
37
|
-
const candidateDirs = [process.cwd(), process.env.INIT_CWD, moduleDir];
|
|
38
|
-
return candidateDirs.reduce((resolved, candidate) => {
|
|
39
|
-
if (resolved) {
|
|
40
|
-
return resolved;
|
|
41
|
-
}
|
|
42
|
-
return findRepoRoot(candidate) || null;
|
|
43
|
-
}, null) || process.cwd();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function exec(command, options = {}) {
|
|
47
|
-
const execOptions = options.cwd ? options : { ...options, cwd: getDefaultCwd() };
|
|
48
|
-
return execPromise(command, execOptions);
|
|
49
|
-
}
|
|
1
|
+
import { exec as execCallback } from "child_process";
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { promisify } from "util";
|
|
6
|
+
|
|
7
|
+
const execPromise = promisify(execCallback);
|
|
8
|
+
|
|
9
|
+
function findRepoRoot(startDir) {
|
|
10
|
+
if (!startDir) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let current = path.resolve(startDir);
|
|
15
|
+
const { root } = path.parse(current);
|
|
16
|
+
|
|
17
|
+
while (true) {
|
|
18
|
+
if (existsSync(path.join(current, ".git"))) {
|
|
19
|
+
return current;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (current === root) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const parent = path.dirname(current);
|
|
27
|
+
if (parent === current) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
current = parent;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getDefaultCwd() {
|
|
36
|
+
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
37
|
+
const candidateDirs = [process.cwd(), process.env.INIT_CWD, moduleDir];
|
|
38
|
+
return candidateDirs.reduce((resolved, candidate) => {
|
|
39
|
+
if (resolved) {
|
|
40
|
+
return resolved;
|
|
41
|
+
}
|
|
42
|
+
return findRepoRoot(candidate) || null;
|
|
43
|
+
}, null) || process.cwd();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function exec(command, options = {}) {
|
|
47
|
+
const execOptions = options.cwd ? options : { ...options, cwd: getDefaultCwd() };
|
|
48
|
+
return execPromise(command, execOptions);
|
|
49
|
+
}
|