Skip to content

Commit

Permalink
feat: migrate the installation method to asdf, close #16
Browse files Browse the repository at this point in the history
  • Loading branch information
leoli0605 committed May 9, 2024
1 parent 88371a0 commit e8ad820
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 41 deletions.
91 changes: 59 additions & 32 deletions packageData.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
},
"type": "enable"
},
"CMake": {
"description": "跨平台的建構系統產生工具",
"install": {
"linux": "asdf plugin add cmake && asdf install cmake latest && asdf global cmake latest",
"mac": "asdf plugin add cmake && asdf install cmake latest && asdf global cmake latest",
"windows": "choco install cmake -y"
},
"type": "disable"
},
"Cuda": {
"description": "控制 NVIDIA GPU 的 CLI 工具",
"install": {
Expand Down Expand Up @@ -75,11 +84,11 @@
"Golang": {
"description": "",
"install": {
"linux": "asdf plugin add golang && asdf install golang 1.20 && asdf global golang 1.20",
"mac": "brew install coreutils && asdf plugin add golang && asdf install golang 1.20 && asdf global golang 1.20",
"linux": "asdf plugin add golang && asdf install golang latest && asdf global golang latest",
"mac": "brew install coreutils && asdf plugin add golang && asdf install golang latest && asdf global golang latest",
"windows": "choco install golang -y"
},
"type": "disable"
"type": "enable"
},
"ImageJ": {
"description": "基於 Java 的圖像處理軟體",
Expand Down Expand Up @@ -108,15 +117,6 @@
},
"type": "enable"
},
"LazyDocker": {
"description": "一個簡單的終端機使用者介面,適用於 docker 與 docker-compose",
"install": {
"linux": "asdf install lazydocker latest && asdf global lazydocker latest",
"mac": "asdf install lazydocker latest && asdf global lazydocker latest",
"windows": "choco install lazydocker -y"
},
"type": "enable"
},
"Miniconda 3": {
"description": "",
"install": {
Expand Down Expand Up @@ -156,9 +156,9 @@
"Pandoc": {
"description": "文件轉換工具",
"install": {
"linux": "sudo apt install -y pandoc texlive-full",
"mac": "brew install pandoc && brew install --cask mactex-no-gui",
"windows": "choco install pandoc miktex -y"
"linux": "asdf plugin add pandoc && asdf install pandoc latest && asdf global pandoc latest && asdf plugin add tinytex && asdf install tinytex latest && asdf global tinytex latest",
"mac": "asdf plugin add pandoc && asdf install pandoc latest && asdf global pandoc latest && asdf plugin add tinytex && asdf install tinytex latest && asdf global tinytex latest",
"windows": "choco install pandoc tinytex -y"
},
"type": "enable"
},
Expand Down Expand Up @@ -250,7 +250,7 @@
"mac": "npm install -g yo generator-code vsce esbuild",
"windows": "npm install -g yo generator-code vsce esbuild"
},
"type": "disable"
"type": "enable"
},
"Virtual Box": {
"description": "自由及開放原始碼的虛擬機器軟體",
Expand Down Expand Up @@ -280,10 +280,10 @@
"type": "enable"
},
"act-cli": {
"description": "GitHub Actions 的 CLI 工具",
"description": "GitHub Actions 的本地模擬工具",
"install": {
"linux": "",
"mac": "brew install act",
"linux": "asdf plugin add act && asdf install act latest && asdf global act latest",
"mac": "asdf plugin add act && asdf install act latest && asdf global act latest",
"windows": "choco install act-cli -y"
},
"type": "disable"
Expand Down Expand Up @@ -316,13 +316,13 @@
"type": "enable"
},
"gcc-arm-none-eabi": {
"description": "ARM 編譯器 (推薦使用 Docker 以避免環境問題)",
"description": "ARM 編譯器",
"install": {
"linux": "sudo apt install gcc-arm-none-eabi -y",
"mac": "brew install --cask gcc-arm-embedded",
"linux": "asdf plugin add gcc-arm-none-eabi && asdf install gcc-arm-none-eabi latest && asdf global gcc-arm-none-eabi latest",
"mac": "asdf plugin add gcc-arm-none-eabi && asdf install gcc-arm-none-eabi latest && asdf global gcc-arm-none-eabi latest",
"windows": "choco install gcc-arm-embedded -y"
},
"type": "disable"
"type": "enable"
},
"ilspy": {
"description": "C# 反編譯工具",
Expand All @@ -333,11 +333,29 @@
},
"type": "enable"
},
"lazydocker": {
"description": "一個簡單的終端機使用者介面,適用於 docker 與 docker-compose",
"install": {
"linux": "asdf install lazydocker latest && asdf global lazydocker latest",
"mac": "asdf install lazydocker latest && asdf global lazydocker latest",
"windows": "choco install lazydocker -y"
},
"type": "enable"
},
"lazygit": {
"description": "一個簡單的終端機使用者介面,適用於 git",
"install": {
"linux": "asdf plugin add lazygit && asdf install lazygit latest && asdf global lazygit latest",
"mac": "asdf plugin add lazygit && asdf install lazygit latest && asdf global lazygit latest",
"windows": ""
},
"type": "enable"
},
"make": {
"description": "",
"install": {
"linux": "sudo apt install make -y",
"mac": "brew install make",
"linux": "asdf plugin add make && asdf install make latest && asdf global make latest",
"mac": "asdf plugin add make && asdf install make latest && asdf global make latest",
"windows": "choco install make -y"
},
"type": "enable"
Expand All @@ -358,7 +376,7 @@
"mac": "pip install --upgrade pyocd --user",
"windows": "pip install --upgrade pyocd --user"
},
"type": "disable"
"type": "enable"
},
"usbipd-win": {
"description": "USB over IP 的 Windows 版本",
Expand All @@ -367,7 +385,7 @@
"mac": "",
"windows": "winget install --interactive --exact dorssel.usbipd-win"
},
"type": "disable"
"type": "enable"
}
},
"MISC": {
Expand Down Expand Up @@ -488,6 +506,15 @@
},
"type": "enable"
},
"ImageMagick": {
"description": "圖像處理工具",
"install": {
"linux": "asdf plugin add imagemagick && asdf install imagemagick latest && asdf global imagemagick latest",
"mac": "asdf plugin add imagemagick && asdf install imagemagick latest && asdf global imagemagick latest",
"windows": "choco install imagemagick -y"
},
"type": "enable"
},
"Inkscape": {
"description": "免費向量繪圖軟體,類似 Adobe Illustrator",
"install": {
Expand Down Expand Up @@ -591,7 +618,7 @@
"description": "",
"install": {
"linux": "",
"mac": "brew install --cask vlc",
"mac": "",
"windows": "choco install potplayer -y"
},
"type": "enable"
Expand Down Expand Up @@ -662,8 +689,8 @@
"ffmepg": {
"description": "影片處理 CLI 工具",
"install": {
"linux": "sudo apt install ffmpeg -y",
"mac": "brew install ffmpeg",
"linux": "asdf plugin add ffmpeg && asdf install ffmpeg latest && asdf global ffmpeg latest",
"mac": "asdf plugin add ffmpeg && asdf install ffmpeg latest && asdf global ffmpeg latest",
"windows": "choco install ffmpeg -y"
},
"type": "enable"
Expand All @@ -680,8 +707,8 @@
"yt-dlp": {
"description": "YouTube 影片下載 CLI 工具",
"install": {
"linux": "sudo apt install yt-dlp -y",
"mac": "brew install yt-dlp",
"linux": "asdf plugin add yt-dlp && asdf install yt-dlp latest && asdf global yt-dlp latest",
"mac": "asdf plugin add yt-dlp && asdf install yt-dlp latest && asdf global yt-dlp latest",
"windows": "choco install yt-dlp -y"
},
"type": "enable"
Expand Down
32 changes: 23 additions & 9 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ class SetupManager {

selectedPackages.forEach((p) => p && this.shell.addCommand(p.installCommand));

if (os.platform() === 'win32') {
this.shell.addCommand('refreshenv\n');
}
refreshEnvironment();

if (selectedPackages.some((p) => p && p.packageName.startsWith('Python'))) {
if (os.platform() === 'win32') {
this.shell.addEnvironment('$HOME\\AppData\\Roaming\\Python\\Scripts');
} else {
this.shell.addEnvironment('\'export PATH="$HOME/.local/bin:$PATH"\'');
}
const poetryInstallCommand = os.platform() === 'win32' ? '(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -' : 'curl -sSL https://install.python-poetry.org | python3';
this.shell.addCommand(poetryInstallCommand);
this.shell.addCommand('python --version');
this.shell.addCommand('pip --version');
/* Install Poetry */
const poetryInstallCommand = os.platform() === 'win32' ? '(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -' : 'asdf plugin add poetry && asdf install poetry latest && asdf global poetry latest';
this.shell.addCommand(poetryInstallCommand);
refreshEnvironment();
this.shell.addCommand('poetry --version');
this.shell.addCommand('poetry config virtualenvs.in-project true');
this.shell.addCommand(fs.readFileSync(path.join(__dirname, 'scripts/pip.setup'), 'utf8').trim());
Expand All @@ -80,12 +80,11 @@ class SetupManager {
console.log('Ubuntu 20.04 not detected');
}
}
refreshEnvironment();
this.shell.addCommand('node --version');
this.shell.addCommand('npm --version');
this.shell.addCommand(fs.readFileSync(path.join(__dirname, 'scripts/npm.setup'), 'utf8').trim());
if (os.platform() === 'win32') {
this.shell.addCommand('refreshenv\n');
}
refreshEnvironment();
}

if (os.platform() === 'win32' && selectedPackages.some((p) => p && p.packageName.startsWith('Sublime Text'))) {
Expand All @@ -98,7 +97,7 @@ class SetupManager {
this.shell.addCommand(fs.readFileSync(path.join(__dirname, 'scripts/macos/macsetup.sh'), 'utf8').trim());
}

this.shell.addCommand('npx @leoli0605/git-setup');
if (!isLinuxRunAsRoot()) this.shell.addCommand('npx @leoli0605/git-setup');
}

setupNonWindowsEnvironment() {
Expand All @@ -116,6 +115,21 @@ class SetupManager {
}
}

refreshEnvironment() {
if (os.platform() === 'win32') {
this.shell.addCommand('refreshenv\n');
} else {
this.shell.addCommand('source ~/.bashrc\n');
if (fs.existsSync(path.join(os.homedir(), '.zshrc'))) {
this.shell.addCommand('source ~/.zshrc\n');
}
}
}

isLinuxRunAsRoot() {
return os.platform() === 'linux' && process.getuid() === 0;
}

finalizeScript() {
const script = this.shell.script();
this.args = os.platform() === 'win32' ? ['-NoProfile', '-EncodedCommand', Buffer.from(script, 'utf16le').toString('base64')] : ['-c', script];
Expand Down

0 comments on commit e8ad820

Please sign in to comment.