trackfw 1.0.2 → 1.0.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/bin/README.md +301 -0
- package/bin/trackfw-darwin-amd64 +0 -0
- package/bin/trackfw-darwin-arm64 +0 -0
- package/bin/trackfw-linux-amd64 +0 -0
- package/bin/trackfw-linux-arm64 +0 -0
- package/bin/trackfw-windows-amd64.exe +0 -0
- package/package.json +2 -6
- package/bin/trackfw +0 -22
- package/scripts/.gitkeep +0 -0
- package/scripts/postinstall.js +0 -221
package/bin/README.md
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# trackfw
|
|
2
|
+
|
|
3
|
+
> Governed software delivery — ADR → REQ → ROADMAP → backlog / wip / done
|
|
4
|
+
|
|
5
|
+
[](https://github.com/kgsaran/trackfw/releases/latest)
|
|
6
|
+
[](go.mod)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
**trackfw** is an open-source CLI that enforces a traceable chain from architectural decision to shipped code — without SaaS, accounts, or databases. Markdown files are state.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
ADR → REQ → ROADMAP → backlog / wip / blocked / done / abandoned
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Every piece of work traces back to a decision. Every decision links to a requirement. Every requirement lands in a roadmap. No orphan work, no undocumented choices.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## The problem
|
|
20
|
+
|
|
21
|
+
Most teams accumulate technical debt not because they lack tools, but because they lack **governance traceability**. Decisions are made in Slack. Requirements live in someone's head. Roadmaps drift from what was actually shipped.
|
|
22
|
+
|
|
23
|
+
- **ADR tools** manage decision records, but don't connect them to delivery.
|
|
24
|
+
- **Kanban tools** track tasks, but don't enforce that tasks are backed by a decision.
|
|
25
|
+
- **CI tools** validate code, but don't validate governance.
|
|
26
|
+
|
|
27
|
+
trackfw closes the loop — connective tissue between *why*, *what*, and *when*.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Demo
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
$ trackfw req new "Login screen"
|
|
37
|
+
|
|
38
|
+
? Describe what you want to build Login screen for the application
|
|
39
|
+
? Motivation Users need to authenticate to access the system
|
|
40
|
+
|
|
41
|
+
Detected domains: authentication, ui
|
|
42
|
+
|
|
43
|
+
? How will users authenticate?
|
|
44
|
+
> Local login (email + password)
|
|
45
|
+
SSO (Google, Azure AD, Okta...)
|
|
46
|
+
Not decided yet ← generates ADR draft
|
|
47
|
+
|
|
48
|
+
? Is there an existing UI framework or design system?
|
|
49
|
+
Yes, already chosen
|
|
50
|
+
> No, need to choose a UI framework ← generates ADR draft
|
|
51
|
+
|
|
52
|
+
ADR drafts created:
|
|
53
|
+
→ ADR-2026-06-12-authentication-strategy.md
|
|
54
|
+
→ ADR-2026-06-12-ui-framework.md
|
|
55
|
+
|
|
56
|
+
Resolve these ADRs (set Status: Accepted) before creating a roadmap.
|
|
57
|
+
created docs/req/REQ-2026-06-12-login-screen.md
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
### macOS / Linux — curl
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
curl -sSfL https://github.com/kgsaran/trackfw/releases/latest/download/install.sh | sh
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Homebrew
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
brew install kgsaran/tap/trackfw
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Go
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
go install github.com/kgsaran/trackfw/cmd/trackfw@latest
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### npm
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm install -g trackfw
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### pip
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install trackfw
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Quick start
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# 1. Set up governance in your project (interactive wizard)
|
|
100
|
+
trackfw init
|
|
101
|
+
|
|
102
|
+
# 2. Document an architectural decision
|
|
103
|
+
trackfw adr new "Use PostgreSQL as primary database"
|
|
104
|
+
|
|
105
|
+
# 3. Create a requirement — wizard detects domains and proposes ADR drafts
|
|
106
|
+
trackfw req new "User authentication"
|
|
107
|
+
|
|
108
|
+
# 4. Once ADRs are accepted, plan the work
|
|
109
|
+
trackfw roadmap new "Auth service"
|
|
110
|
+
|
|
111
|
+
# 5. Check governance health
|
|
112
|
+
trackfw validate
|
|
113
|
+
|
|
114
|
+
# 6. See what is in flight
|
|
115
|
+
trackfw status
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Commands
|
|
121
|
+
|
|
122
|
+
| Command | Description |
|
|
123
|
+
|---|---|
|
|
124
|
+
| `trackfw init` | Interactive wizard — scaffolds governance + AI integrations |
|
|
125
|
+
| `trackfw adr new "title"` | Create a new Architecture Decision Record |
|
|
126
|
+
| `trackfw adr list` | List all ADRs with status |
|
|
127
|
+
| `trackfw req new "title"` | Create a REQ with guided ADR discovery |
|
|
128
|
+
| `trackfw req list` | List all REQs with status |
|
|
129
|
+
| `trackfw roadmap new "title"` | Create a roadmap in `backlog/` |
|
|
130
|
+
| `trackfw roadmap move <name> <state>` | Move roadmap between states |
|
|
131
|
+
| `trackfw roadmap list` | List all roadmaps grouped by state |
|
|
132
|
+
| `trackfw validate` | Check governance consistency (use as CI gate) |
|
|
133
|
+
| `trackfw status` | Show wip, blocked, REQs waiting on ADRs |
|
|
134
|
+
| `trackfw agents` | Install Claude Code subagents |
|
|
135
|
+
| `trackfw gemini` | Install Gemini CLI skills and commands |
|
|
136
|
+
| `trackfw cursor` | Install Cursor rules |
|
|
137
|
+
| `trackfw copilot` | Install GitHub Copilot instructions |
|
|
138
|
+
| `trackfw windsurf` | Install Windsurf rules and workflows |
|
|
139
|
+
| `trackfw amazonq` | Install Amazon Q Developer rules |
|
|
140
|
+
| `trackfw version` | Print version |
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Governance chain
|
|
145
|
+
|
|
146
|
+
| Layer | Artifact | Purpose |
|
|
147
|
+
|---|---|---|
|
|
148
|
+
| Decide | `ADR` | Document the *why* behind a technical decision |
|
|
149
|
+
| Specify | `REQ` | Define *what* needs to be delivered, linked to an ADR |
|
|
150
|
+
| Plan | `ROADMAP` | Break the requirement into microbatches with acceptance criteria |
|
|
151
|
+
| Execute | `backlog → wip → done` | Folder position is the source of truth |
|
|
152
|
+
|
|
153
|
+
### Roadmap states
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
docs/roadmaps/
|
|
157
|
+
├── backlog/ queued, not started
|
|
158
|
+
├── wip/ actively being worked on (one at a time)
|
|
159
|
+
├── blocked/ waiting on a dependency or decision
|
|
160
|
+
├── done/ completed and validated
|
|
161
|
+
└── abandoned/ discontinued — reason required in file
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Moving a file between folders **is** the state transition. No database, no API.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## REQ-driven ADR discovery
|
|
169
|
+
|
|
170
|
+
When you run `trackfw req new`, the wizard analyzes your intent and asks targeted questions for each detected domain — authentication, UI, persistence, API, deploy, events. Unanswered architectural decisions become ADR drafts automatically.
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
trackfw req new "checkout flow with payment integration"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Detected domains: **persistence**, **api**, **events**
|
|
177
|
+
|
|
178
|
+
Questions asked:
|
|
179
|
+
- Which database engine will be used? → *Not decided yet* → `ADR: database-engine (Draft)`
|
|
180
|
+
- Which API protocol will be used? → *REST (already decided)* → no ADR
|
|
181
|
+
- Which event broker will be used? → *Not decided yet* → `ADR: event-broker (Draft)`
|
|
182
|
+
|
|
183
|
+
The REQ is linked to its blocking ADRs. `trackfw validate` enforces that no roadmap is created until every linked ADR reaches `Accepted` status.
|
|
184
|
+
|
|
185
|
+
This is the difference between experienced architects (who know which decisions to make) and everyone else — trackfw brings the architectural checklist to the requirement.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## `trackfw validate` — governance gate
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
$ trackfw validate
|
|
193
|
+
|
|
194
|
+
✗ REQ-2026-06-12-login-screen.md is blocked by Draft ADR: ADR-authentication-strategy.md
|
|
195
|
+
✗ roadmap/wip/auth-service.md has no linked REQ
|
|
196
|
+
⚠ 2 roadmaps in wip/ (recommended: 1)
|
|
197
|
+
|
|
198
|
+
2 violation(s) found
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Designed to run as a **pre-commit hook** and a **CI quality gate**. `trackfw init` wires both automatically for your stack.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## `trackfw status` — current state at a glance
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
$ trackfw status
|
|
209
|
+
|
|
210
|
+
── trackfw status ──────────────────────
|
|
211
|
+
|
|
212
|
+
🔄 WIP (1)
|
|
213
|
+
roadmap-auth-service.md
|
|
214
|
+
|
|
215
|
+
❌ Blocked (0)
|
|
216
|
+
|
|
217
|
+
⏳ REQs blocked by Draft ADRs (1)
|
|
218
|
+
REQ-2026-06-12-login-screen.md
|
|
219
|
+
→ ADR-2026-06-12-authentication-strategy.md (Draft)
|
|
220
|
+
|
|
221
|
+
✅ Done (last 5)
|
|
222
|
+
roadmap-user-profile.md
|
|
223
|
+
roadmap-db-setup.md
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## AI assistant integration
|
|
229
|
+
|
|
230
|
+
`trackfw init` asks which AI tools your team uses and installs native governance context for each. Commands can also be run independently.
|
|
231
|
+
|
|
232
|
+
| Command | Installs | Format |
|
|
233
|
+
|---|---|---|
|
|
234
|
+
| `trackfw agents` | 10 subagents in `~/.claude/agents/` | Claude Code `.md` with frontmatter |
|
|
235
|
+
| `trackfw gemini` | GEMINI.md + 10 skills + 3 commands | `~/.gemini/` + project root |
|
|
236
|
+
| `trackfw cursor` | 10 rules in `.cursor/rules/` | `.mdc` with YAML frontmatter |
|
|
237
|
+
| `trackfw copilot` | `copilot-instructions.md` + 10 instructions + 10 prompts | `.github/` |
|
|
238
|
+
| `trackfw windsurf` | 10 rules + workflows in `.windsurf/` + global rules | Appends to `~/.codeium/windsurf/memories/` |
|
|
239
|
+
| `trackfw amazonq` | 10 rules in `.amazonq/rules/` | Plain Markdown |
|
|
240
|
+
|
|
241
|
+
Each installer is idempotent — running it twice never overwrites your customizations.
|
|
242
|
+
|
|
243
|
+
The 10 roles installed for each tool: **architect · backend · frontend · qa · infra · security · code-quality · dba · ux · data**
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## `trackfw init` — stack-aware scaffolding
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
? Project type? Full-stack / Frontend / Backend / Governance only
|
|
251
|
+
? Frontend stack? React / Vue / Angular
|
|
252
|
+
? Backend stack? Go / Java / Node / Python
|
|
253
|
+
? Package manager? npm / pnpm / yarn / bun
|
|
254
|
+
? Git hooks? husky / lefthook / none
|
|
255
|
+
? CI system? GitHub Actions / GitLab CI / none
|
|
256
|
+
? Which AI assistants? Claude Code / Gemini CLI / Cursor / Copilot / Windsurf / Amazon Q
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
The governance structure (`docs/adr/`, `docs/req/`, `docs/roadmaps/`) is always identical — stack-agnostic. The generated hooks, workflows, and AI integrations adapt to your answers.
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Design principles
|
|
264
|
+
|
|
265
|
+
1. **Files are state** — folder position is the source of truth. No database, no lock-in.
|
|
266
|
+
2. **Traceability is mandatory** — `validate` is a gate, not a suggestion.
|
|
267
|
+
3. **Framework-agnostic, integration-aware** — governance never changes; generated artifacts adapt to your stack.
|
|
268
|
+
4. **One active roadmap at a time** — parallel work without traceability is the root of most delivery chaos.
|
|
269
|
+
5. **Human-readable, machine-parseable** — every artifact is a Markdown file with a predictable structure.
|
|
270
|
+
6. **Guided, not prescriptive** — the wizard surfaces decisions you might not know to ask; it never blocks work unnecessarily.
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## What trackfw is not
|
|
275
|
+
|
|
276
|
+
- Not a project management SaaS — no UI, no accounts, no cloud sync
|
|
277
|
+
- Not a replacement for Git history — it complements, not duplicates
|
|
278
|
+
- Not a task tracker — use GitHub Issues, Linear, or Jira for tasks; trackfw governs the *why*
|
|
279
|
+
- Not opinionated about how you write code — only about how you document decisions
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Contributing
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
git clone https://github.com/kgsaran/trackfw
|
|
287
|
+
cd trackfw
|
|
288
|
+
make build # compiles to bin/trackfw
|
|
289
|
+
make test # go test ./...
|
|
290
|
+
make lint # go vet ./...
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Generators are the stack-specific components — you can add support for a new stack without touching core logic. See `internal/generators/` for examples.
|
|
294
|
+
|
|
295
|
+
Issues and pull requests welcome at [github.com/kgsaran/trackfw](https://github.com/kgsaran/trackfw).
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## License
|
|
300
|
+
|
|
301
|
+
MIT — see [LICENSE](LICENSE)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trackfw",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Governed software delivery framework: ADR → REQ → ROADMAP → kanban",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -18,12 +18,8 @@
|
|
|
18
18
|
"bin": {
|
|
19
19
|
"trackfw": "./bin/trackfw"
|
|
20
20
|
},
|
|
21
|
-
"scripts": {
|
|
22
|
-
"postinstall": "node scripts/postinstall.js"
|
|
23
|
-
},
|
|
24
21
|
"files": [
|
|
25
|
-
"bin/"
|
|
26
|
-
"scripts/"
|
|
22
|
+
"bin/"
|
|
27
23
|
],
|
|
28
24
|
"engines": {
|
|
29
25
|
"node": ">=14"
|
package/bin/trackfw
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
'use strict'
|
|
4
|
-
|
|
5
|
-
const { spawnSync } = require('child_process')
|
|
6
|
-
const path = require('path')
|
|
7
|
-
const fs = require('fs')
|
|
8
|
-
|
|
9
|
-
const isWindows = process.platform === 'win32'
|
|
10
|
-
const binaryName = isWindows ? 'trackfw-bin.exe' : 'trackfw-bin'
|
|
11
|
-
const binaryPath = path.join(__dirname, binaryName)
|
|
12
|
-
|
|
13
|
-
if (!fs.existsSync(binaryPath)) {
|
|
14
|
-
console.error(
|
|
15
|
-
'trackfw: binário não encontrado em ' + binaryPath + '\n' +
|
|
16
|
-
'Tente reinstalar: npm install -g trackfw'
|
|
17
|
-
)
|
|
18
|
-
process.exit(1)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const result = spawnSync(binaryPath, process.argv.slice(2), { stdio: 'inherit' })
|
|
22
|
-
process.exit(result.status ?? 1)
|
package/scripts/.gitkeep
DELETED
|
File without changes
|
package/scripts/postinstall.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const https = require('https');
|
|
6
|
-
const fs = require('fs');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const os = require('os');
|
|
9
|
-
const child_process = require('child_process');
|
|
10
|
-
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
// Mapeamento de plataforma e arquitetura
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
|
|
15
|
-
const PLATFORM_MAP = {
|
|
16
|
-
linux: 'linux',
|
|
17
|
-
darwin: 'darwin',
|
|
18
|
-
win32: 'windows',
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const ARCH_MAP = {
|
|
22
|
-
x64: 'amd64',
|
|
23
|
-
arm64: 'arm64',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const platform = PLATFORM_MAP[process.platform];
|
|
27
|
-
const arch = ARCH_MAP[process.arch];
|
|
28
|
-
|
|
29
|
-
if (!platform || !arch) {
|
|
30
|
-
console.warn('trackfw: plataforma não suportada, pulando instalação do binário');
|
|
31
|
-
process.exit(0);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// ---------------------------------------------------------------------------
|
|
35
|
-
// Versão — lida do package.json do wrapper npm
|
|
36
|
-
// ---------------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
const pkgPath = path.join(__dirname, '..', 'package.json');
|
|
39
|
-
const { version } = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
40
|
-
|
|
41
|
-
// ---------------------------------------------------------------------------
|
|
42
|
-
// URL de download
|
|
43
|
-
// ---------------------------------------------------------------------------
|
|
44
|
-
|
|
45
|
-
const isWindows = platform === 'windows';
|
|
46
|
-
const ext = isWindows ? '.zip' : '.tar.gz';
|
|
47
|
-
const archiveName = `trackfw_${version}_${platform}_${arch}${ext}`;
|
|
48
|
-
const downloadUrl = `https://github.com/kgsaran/trackfw/releases/download/v${version}/${archiveName}`;
|
|
49
|
-
|
|
50
|
-
// ---------------------------------------------------------------------------
|
|
51
|
-
// Destino final do binário
|
|
52
|
-
// ---------------------------------------------------------------------------
|
|
53
|
-
|
|
54
|
-
const binDir = path.join(__dirname, '..', 'bin');
|
|
55
|
-
const binName = isWindows ? 'trackfw-bin.exe' : 'trackfw-bin';
|
|
56
|
-
const binDest = path.join(binDir, binName);
|
|
57
|
-
|
|
58
|
-
if (!fs.existsSync(binDir)) {
|
|
59
|
-
fs.mkdirSync(binDir, { recursive: true });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// ---------------------------------------------------------------------------
|
|
63
|
-
// Helpers
|
|
64
|
-
// ---------------------------------------------------------------------------
|
|
65
|
-
|
|
66
|
-
function download(url, destFile) {
|
|
67
|
-
return new Promise((resolve, reject) => {
|
|
68
|
-
const file = fs.createWriteStream(destFile);
|
|
69
|
-
|
|
70
|
-
function get(currentUrl) {
|
|
71
|
-
https
|
|
72
|
-
.get(currentUrl, (res) => {
|
|
73
|
-
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
74
|
-
const location = res.headers['location'];
|
|
75
|
-
if (!location) {
|
|
76
|
-
reject(new Error('Redirect sem Location header'));
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
res.resume();
|
|
80
|
-
// reabrir o arquivo para a requisição seguinte não acumular lixo
|
|
81
|
-
file.close(() => {
|
|
82
|
-
const file2 = fs.createWriteStream(destFile);
|
|
83
|
-
file2.on('finish', () => file2.close(resolve));
|
|
84
|
-
file2.on('error', (err) => { fs.unlink(destFile, () => {}); reject(err); });
|
|
85
|
-
https.get(location, (res2) => {
|
|
86
|
-
if (res2.statusCode !== 200) {
|
|
87
|
-
reject(new Error(`Falha ao baixar ${location}: HTTP ${res2.statusCode}`));
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
res2.pipe(file2);
|
|
91
|
-
}).on('error', (err) => { fs.unlink(destFile, () => {}); reject(err); });
|
|
92
|
-
});
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (res.statusCode !== 200) {
|
|
97
|
-
reject(new Error(`Falha ao baixar ${currentUrl}: HTTP ${res.statusCode}`));
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
res.pipe(file);
|
|
102
|
-
file.on('finish', () => file.close(resolve));
|
|
103
|
-
file.on('error', (err) => {
|
|
104
|
-
fs.unlink(destFile, () => {});
|
|
105
|
-
reject(err);
|
|
106
|
-
});
|
|
107
|
-
})
|
|
108
|
-
.on('error', (err) => {
|
|
109
|
-
fs.unlink(destFile, () => {});
|
|
110
|
-
reject(err);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
get(url);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function extract(archiveFile, destDir) {
|
|
119
|
-
if (isWindows) {
|
|
120
|
-
child_process.execSync(
|
|
121
|
-
`powershell -NoProfile -Command "Expand-Archive -LiteralPath '${archiveFile}' -DestinationPath '${destDir}' -Force"`,
|
|
122
|
-
{ stdio: 'pipe' }
|
|
123
|
-
);
|
|
124
|
-
} else {
|
|
125
|
-
child_process.execSync(
|
|
126
|
-
`tar -xzf "${archiveFile}" -C "${destDir}"`,
|
|
127
|
-
{ stdio: 'pipe' }
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Busca recursiva pelo binário em qualquer subdiretório após extração
|
|
133
|
-
function findBinary(dir, name) {
|
|
134
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
135
|
-
for (const entry of entries) {
|
|
136
|
-
const full = path.join(dir, entry.name);
|
|
137
|
-
if (entry.isDirectory()) {
|
|
138
|
-
const found = findBinary(full, name);
|
|
139
|
-
if (found) return found;
|
|
140
|
-
} else if (entry.name === name) {
|
|
141
|
-
return full;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function cleanup(target) {
|
|
148
|
-
try {
|
|
149
|
-
if (!fs.existsSync(target)) return;
|
|
150
|
-
const stat = fs.statSync(target);
|
|
151
|
-
if (stat.isDirectory()) {
|
|
152
|
-
fs.rmSync(target, { recursive: true, force: true });
|
|
153
|
-
} else {
|
|
154
|
-
fs.unlinkSync(target);
|
|
155
|
-
}
|
|
156
|
-
} catch (_) {}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// ---------------------------------------------------------------------------
|
|
160
|
-
// Função principal
|
|
161
|
-
// ---------------------------------------------------------------------------
|
|
162
|
-
|
|
163
|
-
async function main() {
|
|
164
|
-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'trackfw-'));
|
|
165
|
-
const tmpFile = path.join(tmpDir, archiveName);
|
|
166
|
-
|
|
167
|
-
try {
|
|
168
|
-
console.log(`trackfw: baixando binário para ${platform}/${arch} v${version}...`);
|
|
169
|
-
console.log(` ${downloadUrl}`);
|
|
170
|
-
|
|
171
|
-
await download(downloadUrl, tmpFile);
|
|
172
|
-
|
|
173
|
-
const fileSize = fs.statSync(tmpFile).size;
|
|
174
|
-
if (fileSize < 1000) {
|
|
175
|
-
throw new Error(`Arquivo baixado suspeito (${fileSize} bytes) — verifique a conexão ou se a versão v${version} foi publicada no GitHub`);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
console.log('trackfw: extraindo arquivo...');
|
|
179
|
-
extract(tmpFile, tmpDir);
|
|
180
|
-
|
|
181
|
-
const extractedBinName = isWindows ? 'trackfw.exe' : 'trackfw';
|
|
182
|
-
const extractedBin = findBinary(tmpDir, extractedBinName);
|
|
183
|
-
|
|
184
|
-
if (!extractedBin) {
|
|
185
|
-
const files = [];
|
|
186
|
-
function listAll(d) {
|
|
187
|
-
for (const e of fs.readdirSync(d, { withFileTypes: true })) {
|
|
188
|
-
const p = path.join(d, e.name);
|
|
189
|
-
files.push(p);
|
|
190
|
-
if (e.isDirectory()) listAll(p);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
listAll(tmpDir);
|
|
194
|
-
throw new Error(
|
|
195
|
-
`Binário "${extractedBinName}" não encontrado após extração.\nArquivos encontrados:\n${files.join('\n')}`
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
fs.renameSync(extractedBin, binDest);
|
|
200
|
-
|
|
201
|
-
if (!isWindows) {
|
|
202
|
-
fs.chmodSync(binDest, 0o755);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
console.log('trackfw: binário instalado com sucesso em ' + binDest);
|
|
206
|
-
} finally {
|
|
207
|
-
cleanup(tmpFile);
|
|
208
|
-
cleanup(tmpDir);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
main().catch((err) => {
|
|
213
|
-
console.error('\ntrackfw: ERRO ao instalar binário:');
|
|
214
|
-
console.error(' ' + err.message);
|
|
215
|
-
console.error('\nAlternativas de instalação:');
|
|
216
|
-
console.error(' curl -sSfL https://github.com/kgsaran/trackfw/releases/latest/download/install.sh | sh');
|
|
217
|
-
console.error(' brew install kgsaran/tap/trackfw (macOS/Linux)');
|
|
218
|
-
console.error(' go install github.com/kgsaran/trackfw/cmd/trackfw@latest\n');
|
|
219
|
-
// Sair com 0 para não bloquear npm install em CIs sem acesso ao GitHub
|
|
220
|
-
process.exit(0);
|
|
221
|
-
});
|