Skip to content

Commit 4aa9de6

Browse files
committed
Initial commit
Initial commit
0 parents  commit 4aa9de6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+3606
-0
lines changed

.github/workflows/release.yml

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: release
2+
# on:
3+
# push:
4+
# branches: ["main"]
5+
# pull_request:
6+
# branches: ["main"]
7+
8+
on:
9+
push:
10+
# Sequence of patterns matched against refs/tags
11+
tags:
12+
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
13+
14+
# env: # 全局环境变量
15+
# linux_x86_archive_name: "n-linux-x86.tar.gz"
16+
# macos-x86-archive-name: "n-macos-x86.tar.gz"
17+
# macos-arm-archive-name: "n-macos-arm.tar.gz"
18+
# windows-archive-name: "n-windows.7z"
19+
20+
jobs:
21+
build:
22+
name: build
23+
runs-on: ${{ matrix.os }}
24+
strategy:
25+
matrix:
26+
build: [linux, macos-x86_64, macos-arm, windows]
27+
include:
28+
- build: linux
29+
os: ubuntu-latest
30+
rust: nightly
31+
target: x86_64-unknown-linux-musl
32+
archive-name: n-linux-x86.tar.gz
33+
- build: macos-x86_64
34+
os: macos-latest
35+
rust: nightly
36+
target: x86_64-apple-darwin
37+
archive-name: n-macos-x86.tar.gz
38+
- build: macos-arm
39+
os: macos-latest
40+
rust: nightly
41+
target: aarch64-apple-darwin
42+
archive-name: n-macos-arm.tar.gz
43+
- build: windows
44+
os: windows-2019
45+
rust: nightly-x86_64-msvc
46+
target: x86_64-pc-windows-msvc
47+
archive-name: n-windows.7z
48+
fail-fast: false
49+
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v3
53+
54+
- name: Install Rust
55+
uses: actions-rs/toolchain@v1
56+
with:
57+
toolchain: ${{ matrix.rust }}
58+
profile: minimal
59+
override: true
60+
target: ${{ matrix.target }}
61+
62+
- name: Build binary
63+
run: cargo build --verbose --release --target ${{ matrix.target }}
64+
env:
65+
RUST_BACKTRACE: 1
66+
67+
- name: Strip binary (linux and macos)
68+
if: matrix.build == 'linux' || matrix.build == 'macos'
69+
run: strip "target/${{ matrix.target }}/release/n"
70+
71+
- name: Build archive
72+
shell: bash
73+
run: |
74+
mkdir archive
75+
cp LICENSE README.md archive/
76+
cd archive
77+
if [ "${{ matrix.build }}" = "windows" ]; then
78+
cp "../target/${{ matrix.target }}/release/n.exe" ./
79+
7z a "${{ matrix.archive-name }}" LICENSE README.md n.exe
80+
else
81+
cp "../target/${{ matrix.target }}/release/n" ./
82+
tar -czf "${{ matrix.archive-name }}" LICENSE README.md n
83+
fi
84+
- name: Upload archive
85+
uses: actions/upload-artifact@v3
86+
with:
87+
name: ${{ matrix.archive-name }}
88+
path: archive/${{ matrix.archive-name }}
89+
# - name: Create Release And Upload Release Asset
90+
# uses: softprops/action-gh-release@v1
91+
# if: startsWith(github.ref, 'refs/tags/')
92+
# with:
93+
# tag_name: ${{ github.ref }}
94+
# name: Release ${{ github.ref }}
95+
# body: TODO New Release.
96+
# draft: false
97+
# prerelease: false
98+
# files: |
99+
# archive/${{ matrix.archive-name }}
100+
release:
101+
name: release
102+
needs: build
103+
runs-on: ubuntu-latest
104+
steps:
105+
- name: Download linux-x86 archive
106+
uses: actions/download-artifact@v2
107+
with:
108+
name: n-linux-x86.tar.gz
109+
path: archive
110+
- name: Download macos-x86 archive
111+
uses: actions/download-artifact@v2
112+
with:
113+
name: n-macos-x86.tar.gz
114+
path: archive
115+
- name: Download macos-arm archive
116+
uses: actions/download-artifact@v2
117+
with:
118+
name: n-macos-arm.tar.gz
119+
path: archive
120+
- name: Download windows archive
121+
uses: actions/download-artifact@v2
122+
with:
123+
name: n-windows.7z
124+
path: archive
125+
126+
- name: Create Release And Upload Release Asset
127+
uses: softprops/action-gh-release@v1
128+
if: startsWith(github.ref, 'refs/tags/')
129+
with:
130+
tag_name: ${{ github.ref }}
131+
name: ${{ github.ref_name }}
132+
body: TODO New Release.
133+
draft: false
134+
prerelease: false
135+
files: |
136+
archive/n-linux-x86.tar.gz
137+
archive/n-macos-x86.tar.gz
138+
archive/n-macos-arm.tar.gz
139+
archive/n-windows.7z

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
debug/
4+
target/
5+
6+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8+
Cargo.lock
9+
10+
# These are backup files generated by rustfmt
11+
**/*.rs.bk
12+
13+
# MSVC Windows builds of rustc generate these, which store debugging information
14+
*.pdb
15+
.DS_Store
16+
.idea
17+
.idea

.vscode/settings.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"rust-analyzer.linkedProjects": [
3+
"./crates/cli/Cargo.toml",
4+
"./crates/snm_core/Cargo.toml",
5+
"./crates/snm_pm/Cargo.toml",
6+
"./crates/snm_node/Cargo.toml",
7+
],
8+
"cSpell.words": [
9+
"canonicalize",
10+
"chrono",
11+
"consts",
12+
"crossterm",
13+
"dialoguer",
14+
"flate",
15+
"hasher",
16+
"reqwest",
17+
"SHASUMS",
18+
"thiserror",
19+
"Unalias",
20+
"yarnpkg"
21+
]
22+
}

Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[workspace]
2+
members = [
3+
"crates/cli",
4+
"crates/snm_pm",
5+
"crates/snm_node",
6+
"crates/snm_core",
7+
]

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 SHEIN
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.

README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# snm
2+
3+
4+
RUST_BACKTRACE=1 cargo run -p cli --bin main -- node default 21.4.0
5+
6+
RUST_BACKTRACE=1 cargo run -p cli --bin main -- node list
7+
8+
RUST_BACKTRACE=1 cargo run -p cli --bin main -- node install 20.11.1
9+
10+
export PATH=$HOME/GitRepository/snm/target/debug:$PATH
11+
12+
13+
- [x] snm node list
14+
- [x] snm node list-remote
15+
- [x] snm node install 20.11.1
16+
- [x] snm node uninstall 20.11.1
17+
- [x] snm node default 20.11.1
18+
- [x] snm node env
19+
20+
21+
- [x] corepack auto download
22+
- [x] check valid package manager
23+
- [x] execute package manager command
24+
25+
26+
- [ ] snm install
27+
- [ ] snm clean-install
28+
- [ ] snm uninstall
29+
- [ ] snm update
30+
- [ ] snm dedupe
31+
- [ ] snm pack
32+
- [ ] snm publish
33+
- [ ] snm run
34+
- [ ] snm exec [name]
35+
36+
37+
SNM_NODE_BIN_DIR = '~/.snm/bin'
38+
SNM_DOWNLOAD_DIR = '~/.snm/download'
39+
SNM_NODE_MODULES_DIR = '~/.snm/node_modules'
40+
41+
42+
43+
44+
45+
snm add [package-spec] (-O --save-optional) (-D --save-dev) (-P --save-prod) (-E --save-exact)
46+
npm add [package-spec] (-O --save-optional) (-D --save-dev) (-P --save-prod) (-E --save-exact)
47+
pnpm add [package-spec] (-O --save-optional) (-D --save-dev) (-P --save-prod) (-E --save-exact)
48+
yarn1 add [package-spec] (-O --optional) (-D --dev) (-P --peer) (-E --exact)
49+
yarn2 add [package-spec] (-O --optional) (-D --dev) (-P --peer) (-E --exact)
50+
51+
52+
snm install
53+
npm install (rename npm ci if v > 7 has npm clean-install)
54+
pnpm install (--frozen-lockfile)
55+
yarn1 install (--frozen-lockfile)
56+
yarn2 install (--immutable)
57+
58+
snm run
59+
60+
snx
61+
npm npx
62+
pnpm pnpm dlx
63+
yarn1 😭
64+
yarn2 yarn dlx
65+
66+
67+
68+
69+
snm query -i 自研
70+
71+
72+
snm update(up) -i 自研

crates/cli/Cargo.toml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[package]
2+
name = "cli"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
9+
[[bin]]
10+
name = "snm"
11+
path = "src/main.rs"
12+
13+
[[bin]]
14+
name = "npm"
15+
path = "src/shim/npm.rs"
16+
17+
[[bin]]
18+
name = "pnpm"
19+
path = "src/shim/pnpm.rs"
20+
21+
[[bin]]
22+
name = "yarn"
23+
path = "src/shim/yarn.rs"
24+
25+
[[bin]]
26+
name = "node"
27+
path = "src/shim/node.rs"
28+
29+
[dependencies]
30+
log = "0.4.20"
31+
anyhow = "1.0"
32+
colored = "2.1.0"
33+
semver = "1.0.21"
34+
serde_json = "1.0"
35+
dialoguer = "0.11.0"
36+
env_logger = "0.11.2"
37+
crossterm = "0.27.0"
38+
snm_pm = { path = "../snm_pm"}
39+
snm_core ={ path = "../snm_core"}
40+
snm_node = { path = "../snm_node" }
41+
serde = { version = "1.0", features = ["derive"] }
42+
tokio = { version = "1.0.0", features = ["full"] }
43+
clap = { version = "4.5.1" , features = ["derive"] }
44+
ansi_term = "0.12.1"
45+
regex = "1.10.4"
46+
glob = "0.3.1"

0 commit comments

Comments
 (0)