@snowdreamtech/unistack 0.0.1
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/LICENSE +21 -0
- package/README.md +124 -0
- package/README_zh-CN.md +124 -0
- package/install.js +160 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present SnowdreamTech Inc.
|
|
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,124 @@
|
|
|
1
|
+
# UniStack
|
|
2
|
+
|
|
3
|
+
[](https://github.com/snowdreamtech/UniStack/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/snowdreamtech/UniStack/actions/workflows/cd.yml)
|
|
5
|
+
[](https://github.com/snowdreamtech/UniStack/actions/workflows/pages.yml)
|
|
6
|
+
[](https://github.com/snowdreamtech/UniStack/actions/workflows/codeql.yml)
|
|
7
|
+
[](https://github.com/snowdreamtech/UniStack/actions/workflows/ci.yml)
|
|
8
|
+
[](https://github.com/snowdreamtech/UniStack/actions/workflows/ci.yml)
|
|
9
|
+
[](https://github.com/snowdreamtech/UniStack/releases/latest)
|
|
10
|
+
[](https://opensource.org/license/MIT)
|
|
11
|
+
[](https://github.com/snowdreamtech/UniStack/releases/latest)
|
|
12
|
+
[](https://github.com/snowdreamtech/UniStack/blob/main/.github/dependabot.yml)
|
|
13
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
14
|
+
[](https://github.com/snowdreamtech/UniStack)
|
|
15
|
+
[](https://github.com/snowdreamtech/UniStack/issues)
|
|
16
|
+
[](https://github.com/snowdreamtech/UniStack)
|
|
17
|
+
|
|
18
|
+
[English](README.md) | [įŽäŊ䏿](README_zh-CN.md)
|
|
19
|
+
|
|
20
|
+
UniStack is a fast, flexible, and enterprise-grade Golang CLI template inspired by UniRTM and helloworld. It provides a robust foundation for building modern command-line applications in Go, featuring beautiful terminal output, structured logging, built-in caching, and a comprehensive CI/CD pipeline.
|
|
21
|
+
|
|
22
|
+
## đ Features
|
|
23
|
+
|
|
24
|
+
- **Modern CLI Architecture**: Built with Go 1.24+ and Cobra, providing a structured and extensible command-line application framework.
|
|
25
|
+
- **Beautiful Output**: Utilizes `pterm` for rich, colorful, and interactive terminal output.
|
|
26
|
+
- **Structured Logging**: Built-in support for Go's standard `slog` package for high-performance structured logging.
|
|
27
|
+
- **Robust Tooling**: Includes built-in commands like `doctor`, `self-update`, `cache`, `config`, and `license`.
|
|
28
|
+
- **Triple Guarantee Quality**: 100% code purity enforced through IDE checks, Pre-commit hooks, and GitHub Actions integrated quality gates.
|
|
29
|
+
- **Cross-Platform Ready**: Runs seamlessly on macOS, Linux, and Windows.
|
|
30
|
+
|
|
31
|
+
## đī¸ Architecture & Design
|
|
32
|
+
|
|
33
|
+
### Overview
|
|
34
|
+
|
|
35
|
+
UniStack is engineered to solve the boilerplate problem when starting new Go CLI projects. It standardizes the development environment, architectural patterns, and automation pipelines out of the box.
|
|
36
|
+
|
|
37
|
+
### Core Components
|
|
38
|
+
|
|
39
|
+
- **CLI Framework**: Utilizes `spf13/cobra` and `spf13/viper` for powerful command parsing and configuration management.
|
|
40
|
+
- **UI & Logging**: Integrated `pterm` for UI components and `slog` for structured event logging.
|
|
41
|
+
- **Database & Caching**: SQLite-backed (via `modernc.org/sqlite`) local caching and transactional data storage.
|
|
42
|
+
- **Task Orchestration**: Configured with `UniRTM` for managing local development workflows (lint, test, verify).
|
|
43
|
+
|
|
44
|
+
## đ Usage Guide
|
|
45
|
+
|
|
46
|
+
### Prerequisites
|
|
47
|
+
|
|
48
|
+
- **Runtime**: Go (>= 1.24).
|
|
49
|
+
- **Git**: Global git installation required.
|
|
50
|
+
- **UniRTM**: Required for task execution and orchestration.
|
|
51
|
+
|
|
52
|
+
### Quick Start
|
|
53
|
+
|
|
54
|
+
1. **Install UniRTM**: Ensure `unirtm` is installed on your system.
|
|
55
|
+
2. **Initialize**: `unirtm run setup` (bootstraps core dependencies and hooks).
|
|
56
|
+
3. **Install**: `unirtm run install` (installs project dependencies).
|
|
57
|
+
4. **Verify**: `unirtm run verify` (ensures everything is green).
|
|
58
|
+
5. **Build**: `go build -o unistack main.go`
|
|
59
|
+
|
|
60
|
+
### Available Commands
|
|
61
|
+
|
|
62
|
+
- `unistack version`: Print the version number
|
|
63
|
+
- `unistack doctor`: Check system health and diagnose issues
|
|
64
|
+
- `unistack self-update`: Update to the latest version
|
|
65
|
+
- `unistack cache`: Manage local cache
|
|
66
|
+
- `unistack config`: Manage configuration
|
|
67
|
+
- `unistack license`: Manage copyright license headers
|
|
68
|
+
|
|
69
|
+
## đ ī¸ Operations Guide
|
|
70
|
+
|
|
71
|
+
### Pre-deployment Checklist
|
|
72
|
+
|
|
73
|
+
1. Run `unirtm run verify` to ensure all quality gates are green (runs formatters, linters, tests, and security audits).
|
|
74
|
+
2. Ensure `CHANGELOG.md` is updated.
|
|
75
|
+
|
|
76
|
+
### Troubleshooting
|
|
77
|
+
|
|
78
|
+
- **Problem**: `unirtm run verify` fails with test errors.
|
|
79
|
+
- **Solution**: Ensure your code passes all Go unit tests. UniStack enforces strict coverage and race condition checks.
|
|
80
|
+
- **Problem**: Pre-commit hooks fail.
|
|
81
|
+
- **Solution**: The hooks often auto-fix issues (like formatting). Stage the modified files and commit again.
|
|
82
|
+
|
|
83
|
+
## đ Security Considerations
|
|
84
|
+
|
|
85
|
+
### Security Model
|
|
86
|
+
|
|
87
|
+
- **Audit Logging**: All critical operations and security scans are executed during the `verify` task using tools like `trivy`, `gitleaks`, and `govulncheck`.
|
|
88
|
+
- **Dependency Management**: Powered by Dependabot to ensure all dependencies are kept up-to-date and secure.
|
|
89
|
+
|
|
90
|
+
## đ§âđģ Development Guide
|
|
91
|
+
|
|
92
|
+
### Local Development Setup
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
git clone https://github.com/snowdreamtech/UniStack.git
|
|
96
|
+
cd UniStack
|
|
97
|
+
unirtm run setup
|
|
98
|
+
unirtm run install
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### đ Proxy Usage Scenarios
|
|
102
|
+
|
|
103
|
+
The `GITHUB_PROXY` (default: `https://gh-proxy.sn0wdr1am.com/`) is optimized for specific network acceleration scenarios. Misusing it for unsupported protocols (like Git) will result in errors.
|
|
104
|
+
|
|
105
|
+
| Scenario | Supported? | Example / Note |
|
|
106
|
+
| :-------------------- | :--------- | :----------------------------------------------------- |
|
|
107
|
+
| **Release Files** | â
Yes | `.../releases/download/v1.0/tool.zip` |
|
|
108
|
+
| **Source Archives** | â
Yes | `.../archive/master.zip` or `.tar.gz` |
|
|
109
|
+
| **Direct File Links** | â
Yes | `.../blob/master/filename` |
|
|
110
|
+
| **Git Clone** | â **No** | Do **not** use for `git clone` or `insteadOf` configs. |
|
|
111
|
+
| **Project Folders** | â **No** | Browsing/cloning via proxy is not supported. |
|
|
112
|
+
|
|
113
|
+
> [!IMPORTANT]
|
|
114
|
+
> To prevent breaking toolchains (like `unirtm`), this template explicitly disables Git redirection via this proxy. Use it only for direct HTTP downloads in scripts.
|
|
115
|
+
|
|
116
|
+
## đ License
|
|
117
|
+
|
|
118
|
+
This project is licensed under the **MIT License**.
|
|
119
|
+
Copyright (c) 2026-present [SnowdreamTech Inc.](https://github.com/snowdreamtech)
|
|
120
|
+
See the [LICENSE](./LICENSE) file for the full license text.
|
|
121
|
+
|
|
122
|
+
## Star History
|
|
123
|
+
|
|
124
|
+
[](https://www.star-history.com/?repos=snowdreamtech%2FUniStack&type=date&legend=top-left)
|
package/README_zh-CN.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# UniStack
|
|
2
|
+
|
|
3
|
+
[](https://github.com/snowdreamtech/UniStack/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/snowdreamtech/UniStack/actions/workflows/cd.yml)
|
|
5
|
+
[](https://github.com/snowdreamtech/UniStack/actions/workflows/pages.yml)
|
|
6
|
+
[](https://github.com/snowdreamtech/UniStack/actions/workflows/codeql.yml)
|
|
7
|
+
[](https://github.com/snowdreamtech/UniStack/actions/workflows/ci.yml)
|
|
8
|
+
[](https://github.com/snowdreamtech/UniStack/actions/workflows/ci.yml)
|
|
9
|
+
[](https://github.com/snowdreamtech/UniStack/releases/latest)
|
|
10
|
+
[](https://opensource.org/license/MIT)
|
|
11
|
+
[](https://github.com/snowdreamtech/UniStack/releases/latest)
|
|
12
|
+
[](https://github.com/snowdreamtech/UniStack/blob/main/.github/dependabot.yml)
|
|
13
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
14
|
+
[](https://github.com/snowdreamtech/UniStack)
|
|
15
|
+
[](https://github.com/snowdreamtech/UniStack/issues)
|
|
16
|
+
[](https://github.com/snowdreamtech/UniStack)
|
|
17
|
+
|
|
18
|
+
[English](README.md) | [įŽäŊ䏿](README_zh-CN.md)
|
|
19
|
+
|
|
20
|
+
UniStack æ¯ä¸ä¸ĒåŋĢéãįĩæ´ģä¸äŧä¸įē§į Golang CLI æ¨Ąæŋīŧæˇąå UniRTM å helloworld įå¯åãåŽä¸ēæåģēį°äģŖ Go åŊäģ¤čĄåēį¨į¨åēæäžäēä¸ä¸ĒååŽįåēįĄīŧå
įŊŽäēį˛žįžįįģį̝čžåēãįģæåæĨåŋãįŧåįŽĄįæēåļäģĨåå
¨åĨį CI/CD æĩæ°´įēŋã
|
|
21
|
+
|
|
22
|
+
## đ įšæ§
|
|
23
|
+
|
|
24
|
+
- **į°äģŖ CLI æļæ**īŧåēäē Go 1.24+ å Cobra æåģēīŧæäžįģæå䏿äēæŠåąįåŊäģ¤čĄæĄæļã
|
|
25
|
+
- **į˛žįžčžåē**īŧäŊŋ፠`pterm` åŽį°ä¸°å¯ãå¤åŊŠä¸äē¤äēååĨŊįįģį̝čžåēææã
|
|
26
|
+
- **įģæåæĨåŋ**īŧå
įŊŽå¯š Go æ ååē `slog` ῝æīŧæäžéĢæ§čŊįįģæåæĨåŋ莰åŊã
|
|
27
|
+
- **丰å¯įå
įŊŽåˇĨå
ˇ**īŧčĒå¸Ļ `doctor`ã`self-update`ã`cache`ã`config` å `license` įåŽį¨åŊäģ¤ã
|
|
28
|
+
- **ä¸éäŋč¯č´¨é**īŧéčŋ IDE åŽæļæŖæĨãPre-commit æŦ尿ϿĒå GitHub Actions čŋį̝å
¨éåŽĄčŽĄīŧæåģē 100% äģŖį įē¯ååēĻé˛įēŋã
|
|
29
|
+
- **čˇ¨åšŗå°å°ąįģĒ**īŧå¨ macOSãLinux å Windows ä¸å坿 įŧčŋčĄã
|
|
30
|
+
|
|
31
|
+
## đī¸ æļæä¸čŽžčŽĄ
|
|
32
|
+
|
|
33
|
+
### æĻč§
|
|
34
|
+
|
|
35
|
+
UniStack æ¨å¨č§Ŗåŗæ¯æŦĄå¯å¨æ°į Go CLI éĄšįŽæļéå°įæ¨Ąæŋååéå¤é
įŊŽéŽéĸãåŽæäžäēåŧįŽąåŗį¨įæ ååŧåį¯åĸãæļææ¨ĄåŧåčĒå¨åæĩæ°´įēŋã
|
|
36
|
+
|
|
37
|
+
### æ ¸åŋįģäģļ
|
|
38
|
+
|
|
39
|
+
- **CLI æĄæļ**īŧäŊŋ፠`spf13/cobra` å `spf13/viper` čŋčĄåŧē大įåŊäģ¤č§Ŗæåé
įŊŽįŽĄįã
|
|
40
|
+
- **UI ä¸ æĨåŋ**īŧéæäē `pterm` äŊä¸ē UI įģäģļīŧåšļäŊŋ፠`slog` čŋčĄįģæåįäēäģļ莰åŊã
|
|
41
|
+
- **æ°æŽåēä¸įŧå**īŧįą SQLite éŠąå¨ (éčŋ `modernc.org/sqlite`)īŧæ¯ææŦå°įŧååäēåĄæ§æ°æŽåå¨ã
|
|
42
|
+
- **äģģåĄįŧæ**īŧå
įŊŽäē `UniRTM` é
įŊŽīŧį¨äēįŽĄįæŦå°åŧååˇĨäŊæĩīŧlintãtestãverifyīŧã
|
|
43
|
+
|
|
44
|
+
## đ äŊŋ፿å
|
|
45
|
+
|
|
46
|
+
### åįŊŽæĄäģļ
|
|
47
|
+
|
|
48
|
+
- **čŋčĄæļ**: Go (>= 1.24)ã
|
|
49
|
+
- **Git**: éčĻå
¨åąåŽčŖ
gitã
|
|
50
|
+
- **UniRTM**: åŋ
éĄģåŽčŖ
äģĨæ§čĄäģģåĄįŧæã
|
|
51
|
+
|
|
52
|
+
### åŋĢéåŧå§
|
|
53
|
+
|
|
54
|
+
1. **åŽčŖ
UniRTM**īŧč¯ˇįĄŽäŋįŗģįģ厞åŽčŖ
`unirtm`ã
|
|
55
|
+
2. **åå§å**īŧ`unirtm run setup`īŧåŧå¯ŧåŽčŖ
æ ¸åŋåˇĨå
ˇä¸éŠåīŧã
|
|
56
|
+
3. **åŽčŖ
äžčĩ**īŧ`unirtm run install`īŧåŽčŖ
饚įŽäžčĩīŧã
|
|
57
|
+
4. **éĒč¯**īŧ`unirtm run verify`īŧįĄŽäŋææäģŖį æŖæĨéčŋīŧã
|
|
58
|
+
5. **æåģē**īŧ`go build -o unistack main.go`
|
|
59
|
+
|
|
60
|
+
### å¯į¨åŊäģ¤
|
|
61
|
+
|
|
62
|
+
- `unistack version`: æå°įæŦåˇ
|
|
63
|
+
- `unistack doctor`: æŖæĨįŗģįģåĨåēˇįļåĩåšļ蝿éŽéĸ
|
|
64
|
+
- `unistack self-update`: æ´æ°å°ææ°įæŦ
|
|
65
|
+
- `unistack cache`: įŽĄįæŦå°įŧå
|
|
66
|
+
- `unistack config`: įŽĄįé
įŊŽ
|
|
67
|
+
- `unistack license`: įŽĄįæēäģŖį æäģļä¸įįæčޏå¯å¤´
|
|
68
|
+
|
|
69
|
+
## đ ī¸ čŋįģ´æå
|
|
70
|
+
|
|
71
|
+
### é¨įŊ˛åæŖæĨæ¸
å
|
|
72
|
+
|
|
73
|
+
1. čŋčĄ `unirtm run verify` įĄŽäŋææč´¨éé¨įĻåä¸ēįģŋč˛īŧæ§čĄæ ŧåŧåãLintãæĩč¯ååŽå
¨åŽĄčŽĄīŧã
|
|
74
|
+
2. įĄŽäŋ `CHANGELOG.md` åˇ˛æ´æ°ã
|
|
75
|
+
|
|
76
|
+
### æ
éæé¤
|
|
77
|
+
|
|
78
|
+
- **éŽéĸ**: `unirtm run verify` æĨæĩč¯å¤ąč´Ĩã
|
|
79
|
+
- **č§ŖåŗæšæĄ**: įĄŽäŋäģŖį éčŋææ Go åå
æĩč¯ãUniStack äŧæ§čĄä¸Ĩæ ŧįäģŖį čĻįįåįĢææĄäģļ (race) æŖæĨã
|
|
80
|
+
- **éŽéĸ**: Pre-commit éŠåæĨéã
|
|
81
|
+
- **č§ŖåŗæšæĄ**: 莸å¤éŠåīŧåĻäģŖį æ ŧåŧåīŧäŧčĒå¨äŋŽå¤éŽéĸãå°äŋŽæšåįæäģļéæ° `git add` åšļåæŦĄæäē¤åŗå¯ã
|
|
82
|
+
|
|
83
|
+
## đ åŽå
¨æŗ¨æäē饚
|
|
84
|
+
|
|
85
|
+
### åŽå
¨æ¨Ąå
|
|
86
|
+
|
|
87
|
+
- **åŽĄčŽĄæĨåŋ**: ææįå
ŗéŽæäŊä¸åŽå
¨æĢæīŧåå¨äŊŋ፠`unirtm run verify` æļīŧįą `trivy`ã`gitleaks` å `govulncheck` įåˇĨå
ˇčĒ卿§čĄã
|
|
88
|
+
- **äžčĩįŽĄį**: įą Dependabot æ¯æīŧäģĨįĄŽäŋææéĄšįŽäžčĩ饚å§įģäŋæææ°ä¸åŽå
¨įįļæã
|
|
89
|
+
|
|
90
|
+
## đ§âđģ åŧåč
æå
|
|
91
|
+
|
|
92
|
+
### æŦå°åŧå莞įŊŽ
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
git clone https://github.com/snowdreamtech/UniStack.git
|
|
96
|
+
cd UniStack
|
|
97
|
+
unirtm run setup
|
|
98
|
+
unirtm run install
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### đ äģŖįäŊŋį¨å翝
|
|
102
|
+
|
|
103
|
+
`GITHUB_PROXY` (éģ莤: `https://gh-proxy.sn0wdr1am.com/`) é寚įšåŽįįŊįģå éå翝čŋčĄäēäŧåãå¨ä¸æ¯æįå莎īŧåĻ Gitīŧä¸č¯¯į¨åŽäŧå¯ŧč´é蝝ã
|
|
104
|
+
|
|
105
|
+
| å翝 | æ¯åĻæ¯æ | į¤ēäž / 蝴æ |
|
|
106
|
+
| :--------------------- | :------------ | :--------------------------------------------- |
|
|
107
|
+
| **Release æäģļ** | â
æ¯æ | `.../releases/download/v1.0/tool.zip` |
|
|
108
|
+
| **æēį åŊæĄŖ (Archive)** | â
æ¯æ | `.../archive/master.zip` æ `.tar.gz` |
|
|
109
|
+
| **æäģļį´æĨéžæĨ** | â
æ¯æ | `.../blob/master/filename` |
|
|
110
|
+
| **Git Clone** | â **䏿¯æ** | **蝎åŋ**į¨äē `git clone` æ `insteadOf` é
įŊŽã |
|
|
111
|
+
| **éĄšįŽæäģļ多** | â **䏿¯æ** | 䏿¯æéčŋäģŖįčŋčĄéĄšįŽæäģļ多įæĩč§æå
éã |
|
|
112
|
+
|
|
113
|
+
> [!IMPORTANT]
|
|
114
|
+
> ä¸ēäē鞿ĸį ´ååˇĨå
ˇéžīŧåĻ `unirtm`īŧīŧæŦæ¨ĄæŋæžåŧįĻį¨äēéčŋæ¤äģŖįčŋčĄį Git éåŽåã蝎äģ
å¨čæŦä¸čŋčĄį´æĨ HTTP ä¸čŊŊæļäŊŋį¨åŽã
|
|
115
|
+
|
|
116
|
+
## đ 莸å¯č¯
|
|
117
|
+
|
|
118
|
+
æŦ饚įŽé፠**MIT 莸å¯č¯** ææã
|
|
119
|
+
įæææ (c) 2026-į°å¨ [SnowdreamTech Inc.](https://github.com/snowdreamtech)
|
|
120
|
+
č¯Ļč§ [LICENSE](./LICENSE) æäģļã
|
|
121
|
+
|
|
122
|
+
## Star History
|
|
123
|
+
|
|
124
|
+
[](https://www.star-history.com/?repos=snowdreamtech%2FUniStack&type=date&legend=top-left)
|
package/install.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026 SnowdreamTech. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// install.js - Root package entry point for @snowdreamtech/unistack
|
|
8
|
+
//
|
|
9
|
+
// This script is both the `bin` entry and the `postinstall` hook.
|
|
10
|
+
// It locates the correct platform-specific binary and either:
|
|
11
|
+
// - Runs it (when invoked as CLI)
|
|
12
|
+
// - Validates the installation (when invoked via postinstall)
|
|
13
|
+
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
const { execFileSync, spawnSync } = require("child_process");
|
|
17
|
+
const path = require("path");
|
|
18
|
+
const fs = require("fs");
|
|
19
|
+
const os = require("os");
|
|
20
|
+
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Platform detection
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Map Node.js process.platform + process.arch to npm package suffix.
|
|
27
|
+
* @returns {string} package suffix e.g. "linux-x64"
|
|
28
|
+
*/
|
|
29
|
+
function getPlatformPackageSuffix() {
|
|
30
|
+
const platform = process.platform; // 'darwin' | 'linux' | 'win32'
|
|
31
|
+
const arch = process.arch; // 'x64' | 'arm64' | 'arm' | 'ia32'
|
|
32
|
+
|
|
33
|
+
if (platform === "darwin") {
|
|
34
|
+
if (arch === "arm64") return "darwin-arm64";
|
|
35
|
+
if (arch === "x64") return "darwin-x64";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (platform === "linux") {
|
|
39
|
+
if (arch === "x64") return "linux-x64";
|
|
40
|
+
if (arch === "arm64") return "linux-arm64";
|
|
41
|
+
if (arch === "ia32") return "linux-ia32";
|
|
42
|
+
if (arch === "arm") {
|
|
43
|
+
return "linux-arm"; // armv7
|
|
44
|
+
}
|
|
45
|
+
if (arch === "loong64") return "linux-loong64";
|
|
46
|
+
if (arch === "ppc64") return "linux-ppc64le";
|
|
47
|
+
if (arch === "riscv64") return "linux-riscv64";
|
|
48
|
+
if (arch === "s390x") return "linux-s390x";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (platform === "win32") {
|
|
52
|
+
if (arch === "x64") return "windows-x64";
|
|
53
|
+
if (arch === "arm64") return "windows-arm64";
|
|
54
|
+
if (arch === "ia32") return "windows-ia32";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (platform === "freebsd") {
|
|
58
|
+
if (arch === "x64") return "freebsd-x64";
|
|
59
|
+
if (arch === "arm64") return "freebsd-arm64";
|
|
60
|
+
if (arch === "ia32") return "freebsd-ia32";
|
|
61
|
+
if (arch === "arm") return "freebsd-arm";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (platform === "openbsd") {
|
|
65
|
+
if (arch === "x64") return "openbsd-x64";
|
|
66
|
+
if (arch === "arm64") return "openbsd-arm64";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (platform === "netbsd") {
|
|
70
|
+
if (arch === "x64") return "netbsd-x64";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Unsupported platform: ${platform}-${arch}\n` +
|
|
75
|
+
"Please open an issue at https://github.com/snowdreamtech/unistack/issues"
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// Binary resolution
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Locate the platform binary from the optional dependency package.
|
|
85
|
+
* @param {string} suffix e.g. "linux-x64"
|
|
86
|
+
* @returns {string} absolute path to the binary
|
|
87
|
+
*/
|
|
88
|
+
function resolveBinary(suffix) {
|
|
89
|
+
const pkgName = `@snowdreamtech/unistack-${suffix}`;
|
|
90
|
+
const binaryName = process.platform === "win32" ? "unistack.exe" : "unistack";
|
|
91
|
+
|
|
92
|
+
// Strategy 1: resolve via require.resolve (works when package is installed)
|
|
93
|
+
try {
|
|
94
|
+
const pkgJsonPath = require.resolve(`${pkgName}/package.json`);
|
|
95
|
+
const pkgDir = path.dirname(pkgJsonPath);
|
|
96
|
+
const binPath = path.join(pkgDir, "bin", binaryName);
|
|
97
|
+
if (fs.existsSync(binPath)) {
|
|
98
|
+
return binPath;
|
|
99
|
+
}
|
|
100
|
+
} catch (_) {
|
|
101
|
+
// package not found via require.resolve, try manual search
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Strategy 2: walk up node_modules hierarchy
|
|
105
|
+
let dir = __dirname;
|
|
106
|
+
for (let i = 0; i < 10; i++) {
|
|
107
|
+
const candidate = path.join(dir, "node_modules", pkgName, "bin", binaryName);
|
|
108
|
+
if (fs.existsSync(candidate)) {
|
|
109
|
+
return candidate;
|
|
110
|
+
}
|
|
111
|
+
const parent = path.dirname(dir);
|
|
112
|
+
if (parent === dir) break;
|
|
113
|
+
dir = parent;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
throw new Error(
|
|
117
|
+
`Could not find binary for ${pkgName}.\n` +
|
|
118
|
+
"Try reinstalling @snowdreamtech/unistack:\n" +
|
|
119
|
+
" npm install @snowdreamtech/unistack\n\n" +
|
|
120
|
+
`Platform: ${process.platform}-${process.arch}`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// Entry point
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
const isPostInstall = process.env.npm_lifecycle_event === "postinstall";
|
|
129
|
+
|
|
130
|
+
if (isPostInstall) {
|
|
131
|
+
// Postinstall: just validate that the binary can be found
|
|
132
|
+
try {
|
|
133
|
+
const suffix = getPlatformPackageSuffix();
|
|
134
|
+
const binPath = resolveBinary(suffix);
|
|
135
|
+
const result = spawnSync(binPath, ["--version"], { encoding: "utf8" });
|
|
136
|
+
if (result.status === 0) {
|
|
137
|
+
process.stdout.write(`â
unistack installed successfully (${binPath})\n`);
|
|
138
|
+
}
|
|
139
|
+
} catch (err) {
|
|
140
|
+
// Non-fatal: postinstall failure should not break npm install
|
|
141
|
+
process.stderr.write(`â ī¸ unistack: ${err.message}\n`);
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
// CLI invocation: forward all arguments to the native binary
|
|
145
|
+
try {
|
|
146
|
+
const suffix = getPlatformPackageSuffix();
|
|
147
|
+
const binPath = resolveBinary(suffix);
|
|
148
|
+
const args = process.argv.slice(2);
|
|
149
|
+
|
|
150
|
+
const result = spawnSync(binPath, args, {
|
|
151
|
+
stdio: "inherit",
|
|
152
|
+
windowsHide: false,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
process.exit(result.status !== null ? result.status : 1);
|
|
156
|
+
} catch (err) {
|
|
157
|
+
process.stderr.write(`Error: ${err.message}\n`);
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
160
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@snowdreamtech/unistack",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "UniStack - Universal Runtime Manager: enterprise-grade foundational toolchain for multi-AI IDE collaboration",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/snowdreamtech/unistack",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/snowdreamtech/unistack.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/snowdreamtech/unistack/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"unistack",
|
|
16
|
+
"runtime",
|
|
17
|
+
"manager",
|
|
18
|
+
"toolchain",
|
|
19
|
+
"ai",
|
|
20
|
+
"ide"
|
|
21
|
+
],
|
|
22
|
+
"bin": {
|
|
23
|
+
"unistack": "install.js"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"postinstall": "node install.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"install.js",
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"README.md",
|
|
32
|
+
"README_zh-CN.md"
|
|
33
|
+
],
|
|
34
|
+
"optionalDependencies": {
|
|
35
|
+
"@snowdreamtech/unistack-darwin-arm64": "0.0.1",
|
|
36
|
+
"@snowdreamtech/unistack-darwin-x64": "0.0.1",
|
|
37
|
+
"@snowdreamtech/unistack-linux-x64": "0.0.1",
|
|
38
|
+
"@snowdreamtech/unistack-linux-arm64": "0.0.1",
|
|
39
|
+
"@snowdreamtech/unistack-linux-ia32": "0.0.1",
|
|
40
|
+
"@snowdreamtech/unistack-linux-arm": "0.0.1",
|
|
41
|
+
"@snowdreamtech/unistack-linux-loong64": "0.0.1",
|
|
42
|
+
"@snowdreamtech/unistack-linux-ppc64le": "0.0.1",
|
|
43
|
+
"@snowdreamtech/unistack-linux-riscv64": "0.0.1",
|
|
44
|
+
"@snowdreamtech/unistack-linux-s390x": "0.0.1",
|
|
45
|
+
"@snowdreamtech/unistack-windows-x64": "0.0.1",
|
|
46
|
+
"@snowdreamtech/unistack-windows-arm64": "0.0.1",
|
|
47
|
+
"@snowdreamtech/unistack-windows-ia32": "0.0.1",
|
|
48
|
+
"@snowdreamtech/unistack-freebsd-x64": "0.0.1",
|
|
49
|
+
"@snowdreamtech/unistack-freebsd-arm64": "0.0.1",
|
|
50
|
+
"@snowdreamtech/unistack-freebsd-ia32": "0.0.1",
|
|
51
|
+
"@snowdreamtech/unistack-freebsd-arm": "0.0.1",
|
|
52
|
+
"@snowdreamtech/unistack-openbsd-x64": "0.0.1",
|
|
53
|
+
"@snowdreamtech/unistack-openbsd-arm64": "0.0.1",
|
|
54
|
+
"@snowdreamtech/unistack-netbsd-x64": "0.0.1"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=18"
|
|
58
|
+
}
|
|
59
|
+
}
|