Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e27aa595d2 | ||
|
|
049a6904b0 | ||
|
|
ad91d6205e |
@@ -1,2 +0,0 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
+5
-8
@@ -1,8 +1,5 @@
|
||||
# MacOS
|
||||
.DS_Store
|
||||
|
||||
# VSCode
|
||||
.vscode
|
||||
|
||||
# Output
|
||||
/bin
|
||||
dist/
|
||||
build/
|
||||
lib/
|
||||
package.json
|
||||
main.spec
|
||||
@@ -1,32 +0,0 @@
|
||||
# Project variables
|
||||
BINARY_NAME = wpm
|
||||
SOURCE_DIR = src
|
||||
OUTPUT_DIR = bin
|
||||
|
||||
# Go commands
|
||||
BUILD_CMD = go build -o $(OUTPUT_DIR)/$(BINARY_NAME) $(SOURCE_DIR)/*.go
|
||||
RUN_CMD = go run $(SOURCE_DIR)/*.go
|
||||
|
||||
# Targets
|
||||
.PHONY: all build run clean
|
||||
|
||||
# Default target
|
||||
all: build
|
||||
|
||||
# Build the project
|
||||
build:
|
||||
@echo "Building the project..."
|
||||
@mkdir -p $(OUTPUT_DIR)
|
||||
@$(BUILD_CMD)
|
||||
@echo "Build complete!"
|
||||
|
||||
# Run the project using `go run`
|
||||
run:
|
||||
@echo "Running the project..."
|
||||
@$(RUN_CMD)
|
||||
|
||||
# Clean the output directory
|
||||
clean:
|
||||
@echo "Cleaning up..."
|
||||
@rm -rf $(OUTPUT_DIR)
|
||||
@echo "Clean complete!"
|
||||
@@ -0,0 +1,75 @@
|
||||
import urllib
|
||||
import urllib.parse
|
||||
import requests
|
||||
import os
|
||||
from json import dump
|
||||
import shutil
|
||||
import zipfile
|
||||
from sys import argv
|
||||
from urllib.parse import urlparse
|
||||
import re
|
||||
|
||||
def extract(zip_file, pkgName):
|
||||
os.makedirs("tmp", exist_ok=True)
|
||||
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
|
||||
zip_ref.extractall(path="tmp")
|
||||
old_folder_name = os.listdir("tmp")[0]
|
||||
final_destination = 'lib/'+pkgName
|
||||
try:shutil.rmtree(final_destination)
|
||||
except:pass
|
||||
shutil.move(os.path.join("tmp", old_folder_name), final_destination)
|
||||
shutil.rmtree('tmp')
|
||||
|
||||
def downloadRelease(pkgName, repo, tag):
|
||||
if tag=='latest':
|
||||
tag = requests.get(os.path.join('https://api.github.com/repos',
|
||||
str(urlparse(repo).path).removeprefix('/'),
|
||||
'releases/latest'),
|
||||
headers={"Accept": "application/vnd.github+json"}).json()['tag_name']
|
||||
url = os.path.join(repo, f'archive/refs/tags/{tag}.zip')
|
||||
urllib.request.urlretrieve(url, "temp.zip")
|
||||
extract('temp.zip', pkgName)
|
||||
os.remove('temp.zip')
|
||||
|
||||
def installPackage(packageName, packageVersion='latest'):
|
||||
print(f"Indexing package {packageName}")
|
||||
req = requests.get("http://localhost:3000", json={'name': packageName})
|
||||
data = req.json()
|
||||
if req.status_code==200:
|
||||
print(f"Downloading package {packageName}")
|
||||
downloadRelease(packageName, data['repo'], packageVersion)
|
||||
print(f"Done")
|
||||
else:
|
||||
print(f'Error ({packageName}): {data["message"]}')
|
||||
quit(1)
|
||||
|
||||
def verify_repo(n) -> str:
|
||||
re_match = re.match(r'^https://(github.com)/[a-zA-Z0-9\-]+/[a-zA-Z0-9\-]+', n)
|
||||
if re_match:
|
||||
return str(re_match.group())
|
||||
else:
|
||||
print(f'Error: invalid repo')
|
||||
quit(1)
|
||||
|
||||
if __name__=="__main__":
|
||||
argl = len(argv)
|
||||
if argl > 1:
|
||||
match argv[1]:
|
||||
case "install":
|
||||
if argl > 2:
|
||||
for pkg in argv[2::]:
|
||||
package = pkg.split('@')
|
||||
if len(package) == 2:
|
||||
installPackage(package[0], package[1])
|
||||
else:
|
||||
installPackage(pkg)
|
||||
case "init":
|
||||
pkg_json = {
|
||||
'name': str(os.getcwd().split('/')[-1].split('\\')[-1]),
|
||||
'repo': verify_repo(input("link to the repository (required) "))
|
||||
}
|
||||
if not os.path.exists:
|
||||
os.mkdir("lib")
|
||||
with open('package.json', 'w')as f:
|
||||
dump(pkg_json, f)
|
||||
case _:...
|
||||
@@ -1,23 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func showHelp() {
|
||||
fmt.Println("wpm - Wyst Package Manager")
|
||||
fmt.Println("Commands:")
|
||||
fmt.Println(" install <package>[:version] - Install a package (version is optional)")
|
||||
fmt.Println(" version - Show the wpm version")
|
||||
fmt.Println(" help - Show this help message")
|
||||
fmt.Println(" info <package> - Show package information (author, description, versions)")
|
||||
}
|
||||
|
||||
func parsePackageArg(arg string) (string, string) {
|
||||
parts := strings.Split(arg, ":")
|
||||
if len(parts) == 2 {
|
||||
return parts[0], parts[1]
|
||||
}
|
||||
return parts[0], ""
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func showPackageInfo(packageName string) {
|
||||
url := fmt.Sprintf("https://raw.githubusercontent.com/wyst-lang/index/master/%s/index.json", packageName)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
fmt.Printf("Error fetching package info: %v\n", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
fmt.Printf("Error: %s\n", resp.Status)
|
||||
return
|
||||
}
|
||||
|
||||
var pkgIndex PackageIndex
|
||||
if err := json.NewDecoder(resp.Body).Decode(&pkgIndex); err != nil {
|
||||
fmt.Printf("Error decoding package info: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Package: %s\n", packageName)
|
||||
for version, info := range pkgIndex.Versions {
|
||||
fmt.Printf("Version: %s\n", version)
|
||||
fmt.Printf(" Author: %s\n", info.Author)
|
||||
fmt.Printf(" Description: %s\n", info.Description)
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type PackageVersion struct {
|
||||
Author string `json:"author"`
|
||||
Description string `json:"description"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
type PackageIndex struct {
|
||||
Versions map[string]PackageVersion `json:"versions"`
|
||||
}
|
||||
|
||||
func installPackage(packageName, packageVersion string) {
|
||||
url := fmt.Sprintf("https://raw.githubusercontent.com/wyst-lang/index/master/%s/index.json", packageName)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
fmt.Printf("Error fetching package info: %v\n", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
fmt.Printf("Error: %s\n", resp.Status)
|
||||
return
|
||||
}
|
||||
|
||||
var pkgIndex PackageIndex
|
||||
if err := json.NewDecoder(resp.Body).Decode(&pkgIndex); err != nil {
|
||||
fmt.Printf("Error decoding package info: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if packageVersion == "" {
|
||||
packageVersion = getLatestVersion(pkgIndex)
|
||||
}
|
||||
|
||||
pkgVersion, exists := pkgIndex.Versions[packageVersion]
|
||||
if !exists {
|
||||
fmt.Printf("Version %s not found for package %s\n", packageVersion, packageName)
|
||||
return
|
||||
}
|
||||
|
||||
downloadAndSavePackage(pkgVersion.URL, packageName, packageVersion)
|
||||
}
|
||||
|
||||
func getLatestVersion(pkgIndex PackageIndex) string {
|
||||
var latest string
|
||||
for version := range pkgIndex.Versions {
|
||||
if version > latest {
|
||||
latest = version
|
||||
}
|
||||
}
|
||||
return latest
|
||||
}
|
||||
|
||||
func downloadAndSavePackage(url, packageName, packageVersion string) {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
fmt.Printf("Error downloading package: %v\n", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
fmt.Printf("Error: %s\n", resp.Status)
|
||||
return
|
||||
}
|
||||
|
||||
libDir := "lib"
|
||||
if err := os.MkdirAll(libDir, 0755); err != nil {
|
||||
fmt.Printf("Error creating lib directory: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
filename := filepath.Base(url)
|
||||
packageFile := filepath.Join(libDir, filename)
|
||||
out, err := os.Create(packageFile)
|
||||
if err != nil {
|
||||
fmt.Printf("Error creating package file: %v\n", err)
|
||||
return
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
if _, err := io.Copy(out, resp.Body); err != nil {
|
||||
fmt.Printf("Error saving package: %v\n", err)
|
||||
} else {
|
||||
fmt.Printf("Package %s version %s downloaded and saved successfully as %s\n", packageName, packageVersion, filename)
|
||||
}
|
||||
}
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
const wpmVersion = "1.0.0"
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
showHelp()
|
||||
return
|
||||
}
|
||||
|
||||
command := os.Args[1]
|
||||
switch command {
|
||||
case "install":
|
||||
if len(os.Args) < 3 {
|
||||
fmt.Println("Usage: wpm install <package>[:version]")
|
||||
return
|
||||
}
|
||||
packageName, packageVersion := parsePackageArg(os.Args[2])
|
||||
installPackage(packageName, packageVersion)
|
||||
case "version":
|
||||
fmt.Println("wpm version", wpmVersion)
|
||||
case "help":
|
||||
showHelp()
|
||||
case "info":
|
||||
if len(os.Args) < 3 {
|
||||
fmt.Println("Usage: wpm info <package>")
|
||||
return
|
||||
}
|
||||
showPackageInfo(os.Args[2])
|
||||
default:
|
||||
fmt.Println("Unknown command:", command)
|
||||
showHelp()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user