Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cli #8

Merged
merged 10 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ Note: If you have [nvm](https://github.com/nvm-sh/nvm), you can run `nvm i` to i
1. Fork the [oku-ui](https://github.com/oku-ui/pergel) repository
2. Install the project dependencies
`pnpm install`
3. Run the project in dev mode
`pnpm dev`

### Scripts

```shell
pnpm build # Build the project
pnpm dev # Run the project in dev mode
pnpm stub # Dev mode and watch mode change dist folder

pnpm lint # Run ESLint
pnpm lint:fix # Run ESLint and fix errors

Expand Down
3 changes: 3 additions & 0 deletions bin/pergel.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
'use strict'
import '../dist/index.mjs'
13 changes: 13 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
entries: [
'src/index.ts',
],
clean: true,
declaration: true,
rollup: {
emitCJS: true,
inlineDependencies: true,
},
})
117 changes: 117 additions & 0 deletions install/ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash

#!/bin/bash

# Function to compare two version numbers
version_compare() {
local version1=$1
local version2=$2
if dpkg --compare-versions "$version1" gt "$version2"; then
echo "1"
else
echo "0"
fi
}

# Check if Wget is already installed
if command -v wget &>/dev/null; then
installed_version=$(wget --version | awk 'NR==1{print $3}')
echo "Wget is already installed (Version $installed_version)."
else
echo "Wget is not installed, starting the installation..."

# Use the appropriate package manager to install Wget
if command -v apt-get &>/dev/null; then
sudo apt-get update
sudo apt-get install wget -y
elif command -v yum &>/dev/null; then
sudo yum install wget -y
elif command -v dnf &>/dev/null; then
sudo dnf install wget -y
else
echo "Unsupported package manager, please install Wget manually."
exit 1
fi

# Display a message if the installation was successful
if [ $? -eq 0 ]; then
installed_version=$(wget --version | awk 'NR==1{print $3}')
echo "Wget has been installed successfully (Version $installed_version)."
else
echo "An error occurred while installing Wget."
exit 1
fi
fi

# Get the latest version of Wget
latest_version=$(wget -qO- https://ftp.gnu.org/gnu/wget/ | grep -oE 'wget-[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n 1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')

# Check if Wget is outdated
if [ "$(version_compare "$installed_version" "$latest_version")" -eq "1" ]; then
echo "Wget is outdated (Installed Version: $installed_version, Latest Version: $latest_version)."

# Ask the user if they want to update Wget
read -p "Do you want to update Wget? (yes/no): " update_choice
if [ "$update_choice" == "yes" ]; then
# Use the appropriate package manager to update Wget
if command -v apt-get &>/dev/null; then
sudo apt-get update
sudo apt-get install wget -y
elif command -v yum &>/dev/null; then
sudo yum install wget -y
elif command -v dnf &>/dev/null; then
sudo dnf install wget -y
else
echo "Unsupported package manager, please update Wget manually."
fi

# Display a message if the update was successful
if [ $? -eq 0 ]; then
updated_version=$(wget --version | awk 'NR==1{print $3}')
echo "Wget has been updated to Version $updated_version."
else
echo "An error occurred while updating Wget."
fi
else
echo "Wget will not be updated."
fi
else
echo "Wget is up to date (Version $installed_version)."
fi


# Check if nvm is not installed
if command -v nvm &>/dev/null; then
echo "nvm is already installed."
npm install -g pergel
npm list -g pergel
else
echo "nvm is not installed, starting the installation..."
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
# Display a message if the installation was successful
if [ $? -eq 0 ]; then

# Install the latest LTS version of Node.js using nvm
echo "Installing the latest LTS version of Node.js..."
nvm install --lts

# Set the LTS version as the default
nvm alias default $(nvm ls --lts | tail -n 1)

# Verify the installation and default version
echo "Default Node.js version: $(node --version)"
echo "Default npm version: $(npm --version)"


echo "nvm has been installed successfully."

# Install the latest version of Pergel
echo "Installing the latest version of Pergel..."
npm install -g pergel
npm list -g pergel
else
echo "An error occurred while installing nvm."
exit 1
fi
fi

37 changes: 36 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,57 @@
"packageManager": "[email protected]",
"description": "",
"author": "",
"license": "ISC",
"license": "MIT",
"keywords": [],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"bin": {
"pergel": "bin/pergel.mjs"
},
"files": [
"bin",
"dist"
],
"engines": {
"node": ">=18"
},
"scripts": {
"dev": "esno src/index.ts",
"build": "unbuild",
"stub": "unbuild --stub",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "vitest",
"test:watch": "vitest --watch",
"test:coverage": "vitest --coverage"
},
"dependencies": {
"@clack/prompts": "^0.7.0",
"citty": "^0.1.4",
"globby": "^13.2.2",
"picocolors": "^1.0.0",
"shelljs": "^0.8.5"
},
"devDependencies": {
"@antfu/eslint-config": "1.0.0-beta.18",
"@types/node": "^20.8.2",
"@types/shelljs": "^0.8.13",
"@vitest/coverage-v8": "^0.34.6",
"eslint": "^8.50.0",
"esno": "^0.17.0",
"lint-staged": "^14.0.1",
"simple-git-hooks": "^2.9.0",
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"unbuild": "^2.0.0",
"vitest": "^0.34.6"
},
"simple-git-hooks": {
Expand Down
15 changes: 15 additions & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "playground",
"version": "1.0.0",
"description": "",
"author": "",
"license": "ISC",
"keywords": [],
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"pergel": "workspace:^"
}
}
Loading