diff --git a/CHANGELOG.md b/CHANGELOG.md index b461fc8..4d0b581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## [1.2.4](https://github.com/leoli0605/npm-env-setup/compare/v1.2.3...v1.2.4) (2024-05-09) + + +### Bug Fixes + +* fix some critical bugs ([61d353d](https://github.com/leoli0605/npm-env-setup/commit/61d353d8fed6682e59df7c54011c9d082015684d)) +* update lazydocker installation commands ([961d71d](https://github.com/leoli0605/npm-env-setup/commit/961d71de8777465a34b37b119daf950f0d117a4e)) + + + ## [1.2.3](https://github.com/leoli0605/npm-env-setup/compare/v1.2.2...v1.2.3) (2024-05-09) diff --git a/Dockerfile b/Dockerfile index 1c82314..6808c31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,18 @@ -FROM ubuntu:20.04 +ARG UBUNTU_VERSION=latest + +FROM node:18 as builder +WORKDIR /app +COPY . . +RUN npm install -g pnpm && \ + pnpm install --force +RUN npm run build + +FROM ubuntu:${UBUNTU_VERSION} RUN apt-get update && apt-get install -y tzdata ENV TZ=Asia/Taipei RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - ARG USERNAME=user -RUN apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y curl gnupg2 git - RUN DEBIAN_FRONTEND=noninteractive apt-get install -y sudo \ -o Dpkg::Options::="--force-confold" @@ -19,18 +23,5 @@ RUN useradd -ms /bin/bash ${USERNAME} && \ USER ${USERNAME} WORKDIR /home/${USERNAME} -RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0 -ENV PATH="/home/${USERNAME}/.asdf/bin:/home/${USERNAME}/.asdf/shims:$PATH" -RUN echo ". $HOME/.asdf/asdf.sh" >> ~/.bashrc && \ - echo ". $HOME/.asdf/completions/asdf.bash" >> ~/.bashrc -RUN /bin/bash -c ". $HOME/.asdf/asdf.sh && \ - asdf plugin-add nodejs && \ - asdf install nodejs 18.18.0 && \ - asdf global nodejs 18.18.0" - -COPY . . - -RUN npm install -g pnpm && \ - pnpm install --force - -CMD ["npm", "test"] +COPY --from=builder /app/dist /home/${USERNAME}/dist +RUN sudo chmod +x /home/${USERNAME}/dist/env-setup-linux-x64 diff --git a/README.md b/README.md index 67b20f7..c51b2b2 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Open `powershell` and run the following command. This will start setting up your ```shell -powershell.exe -Command "Invoke-WebRequest -Uri https://github.com/leoli0605/npm-env-setup/releases/download/v1.2.3/env-setup-win-x64.exe -OutFile env-setup-win-x64.exe; Start-Process env-setup-win-x64.exe -Wait; Remove-Item env-setup-win-x64.exe -Force" +powershell.exe -Command "Invoke-WebRequest -Uri https://github.com/leoli0605/npm-env-setup/releases/download/v1.2.4/env-setup-win-x64.exe -OutFile env-setup-win-x64.exe; Start-Process env-setup-win-x64.exe -Wait; Remove-Item env-setup-win-x64.exe -Force" ``` @@ -47,7 +47,7 @@ For Mac users, the process is just as simple. Depending on the type of chip your ```shell -curl -L https://github.com/leoli0605/npm-env-setup/releases/download/v1.2.3/env-setup-macos-x64 -o env-setup-macos-x64 && chmod +x env-setup-macos-x64 && ./env-setup-macos-x64 && rm -f env-setup-macos-x64 +curl -L https://github.com/leoli0605/npm-env-setup/releases/download/v1.2.4/env-setup-macos-x64 -o env-setup-macos-x64 && chmod +x env-setup-macos-x64 && ./env-setup-macos-x64 && rm -f env-setup-macos-x64 ``` @@ -55,7 +55,7 @@ curl -L https://github.com/leoli0605/npm-env-setup/releases/download/v1.2.3/env- ```shell -curl -L https://github.com/leoli0605/npm-env-setup/releases/download/v1.2.3/env-setup-macos-arm64 -o env-setup-macos-arm64 && chmod +x env-setup-macos-arm64 && ./env-setup-macos-arm64 && rm -f env-setup-macos-arm64 +curl -L https://github.com/leoli0605/npm-env-setup/releases/download/v1.2.4/env-setup-macos-arm64 -o env-setup-macos-arm64 && chmod +x env-setup-macos-arm64 && ./env-setup-macos-arm64 && rm -f env-setup-macos-arm64 ``` @@ -65,7 +65,7 @@ For Linux users running Ubuntu 18.04 LTS or newer versions, execute the followin ```shell -curl -L https://github.com/leoli0605/npm-env-setup/releases/download/v1.2.3/env-setup-linux-x64 -o env-setup-linux-x64 && chmod +x env-setup-linux-x64 && ./env-setup-linux-x64 && rm -f env-setup-linux-x64 +curl -L https://github.com/leoli0605/npm-env-setup/releases/download/v1.2.4/env-setup-linux-x64 -o env-setup-linux-x64 && chmod +x env-setup-linux-x64 && ./env-setup-linux-x64 && rm -f env-setup-linux-x64 ``` diff --git a/package.json b/package.json index 182807b..5236134 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@leoli0605/env-setup", - "version": "1.2.3", + "version": "1.2.4", "description": "\"\"", "main": "./src/index.mjs", "files": [ @@ -26,6 +26,9 @@ "scripts": { "start": "node ./src/index.mjs", "test": "node ./test/test.mjs", + "test:docker": "docker build -t env-setup . && docker run --rm -it env-setup /bin/bash", + "test:docker-20": "docker build --build-arg UBUNTU_VERSION=20.04 -t env-setup . && docker run --rm -it env-setup /bin/bash", + "test:docker-18": "docker build --build-arg UBUNTU_VERSION=18.04 -t env-setup . && docker run --rm -it env-setup /bin/bash", "build": "webpack && npm run build:pkg", "production": "webpack --mode production && npm run build:pkg", "build:pkg": "pkg dist/env-setup.js --config pkg.config.json", diff --git a/packageData.json b/packageData.json index 64192d3..2f5c5eb 100644 --- a/packageData.json +++ b/packageData.json @@ -138,7 +138,7 @@ "Node.js": { "description": "", "install": { - "linux": "asdf plugin add nodejs && asdf install nodejs 18.18.0 && asdf global nodejs 18.18.0", + "linux": "echo 'This line will be replaced by the code to meet different versions of Ubuntu'", "mac": "asdf plugin add nodejs && asdf install nodejs 18.18.0 && asdf global nodejs 18.18.0", "windows": "choco install nodejs --version=18.18.0 -y ; choco pin add -n=nodejs" }, @@ -336,8 +336,8 @@ "lazydocker": { "description": "一個簡單的終端機使用者介面,適用於 docker 與 docker-compose", "install": { - "linux": "asdf install lazydocker latest && asdf global lazydocker latest", - "mac": "asdf install lazydocker latest && asdf global lazydocker latest", + "linux": "asdf plugin add lazydocker https://github.com/comdotlinux/asdf-lazydocker.git && asdf install lazydocker latest && asdf global lazydocker latest", + "mac": "asdf plugin add lazydocker https://github.com/comdotlinux/asdf-lazydocker.git && asdf install lazydocker latest && asdf global lazydocker latest", "windows": "choco install lazydocker -y" }, "type": "enable" diff --git a/scripts/linux/basesetup.sh b/scripts/linux/basesetup.sh index a8a62d8..7b174ab 100644 --- a/scripts/linux/basesetup.sh +++ b/scripts/linux/basesetup.sh @@ -19,4 +19,5 @@ sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install -y \ tk-dev \ wget \ xz-utils \ - zlib1g-dev + zlib1g-dev \ + git diff --git a/scripts/npm.setup b/scripts/npm.setup index 7246bab..4b04777 100644 --- a/scripts/npm.setup +++ b/scripts/npm.setup @@ -1,4 +1,3 @@ -npm install -g pnpm@latest npm install -g npm-check-updates@latest npm install -g @leoli0605/git-setup@latest npm list -g diff --git a/src/index.mjs b/src/index.mjs index 75ec602..2bec11d 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -42,6 +42,26 @@ class SetupManager { this.setupNonWindowsEnvironment(); } + selectedPackages.forEach((p) => { + if (p) { + if (p.packageName.startsWith('Node.js')) { + if (os.platform() === 'linux' && fs.existsSync('/etc/os-release')) { + const data = fs.readFileSync('/etc/os-release', 'utf8'); + const isUbuntuVersion2X = /VERSION_ID="20\.\d+"|VERSION_ID="2[1-9]\.\d+"/.test(data) || /PRETTY_NAME="Ubuntu 20\.\d+.*"|PRETTY_NAME="Ubuntu 2[1-9]\.\d+.*"/.test(data); + if (isUbuntuVersion2X) { + console.log('Ubuntu 2x.xx is detected'); + p.installCommand = 'asdf plugin add nodejs && asdf install nodejs 18.18.0 && asdf global nodejs 18.18.0 && npm install -g pnpm@latest'; + } else { + console.log('Ubuntu 1x.xx is detected'); + p.installCommand = 'asdf plugin add nodejs && asdf install nodejs 16.20.2 && asdf global nodejs 16.20.2'; + } + } + } + this.shell.addCommand(p.installCommand); + this.refreshEnvironment(); + } + }); + if (selectedPackages.some((p) => p && p.packageName.startsWith('Python'))) { if (os.platform() === 'win32') { this.shell.addEnvironment('$HOME\\AppData\\Roaming\\Python\\Scripts'); @@ -59,32 +79,18 @@ class SetupManager { this.shell.addCommand(fs.readFileSync(path.join(__dirname, 'scripts/pip.setup'), 'utf8').trim()); } - if (os.platform() === 'win32' && selectedPackages.some((p) => p && p.packageName.startsWith('Rust'))) { - this.shell.addEnvironment('$HOME\\.cargo\\bin'); - this.shell.addCommand('refreshenv\n'); - this.shell.addCommand('rust --version'); - } - if (selectedPackages.some((p) => p && p.packageName.startsWith('Node.js'))) { - if (os.platform() === 'linux' && fs.existsSync('/etc/os-release')) { - const data = fs.readFileSync('/etc/os-release', 'utf8'); - const isUbuntuVersion2X = /VERSION_ID="20\.\d+"|VERSION_ID="2[1-9]\.\d+"/.test(data) || /PRETTY_NAME="Ubuntu 20\.\d+.*"|PRETTY_NAME="Ubuntu 2[1-9]\.\d+.*"/.test(data); - if (!isUbuntuVersion2X) { - console.log('Ubuntu 2x.xx not detected'); - this.shell.addCommand('asdf install nodejs 16.20.2'); - this.shell.addCommand('asdf global nodejs 16.20.2'); - } - } - this.refreshEnvironment(); this.shell.addCommand('node --version'); this.shell.addCommand('npm --version'); this.shell.addCommand(fs.readFileSync(path.join(__dirname, 'scripts/npm.setup'), 'utf8').trim()); this.refreshEnvironment(); } - selectedPackages.forEach((p) => p && this.shell.addCommand(p.installCommand)); - - this.refreshEnvironment(); + if (os.platform() === 'win32' && selectedPackages.some((p) => p && p.packageName.startsWith('Rust'))) { + this.shell.addEnvironment('$HOME\\.cargo\\bin'); + this.shell.addCommand('refreshenv\n'); + this.shell.addCommand('rust --version'); + } if (os.platform() === 'win32' && selectedPackages.some((p) => p && p.packageName.startsWith('Sublime Text'))) { this.shell.addCommand(fs.readFileSync(path.join(__dirname, 'scripts/windows/SublimeSetup.ps1'), 'utf8').trim().replace('${PATH}', path.join(__dirname, 'scripts/windows/Preferences.sublime-settings'))); @@ -112,6 +118,7 @@ class SetupManager { this.shell.addEnvironment('\'. "$HOME/.asdf/completions/asdf.bash"\''); this.shell.addCommand('export PATH="$HOME/.asdf/bin:$HOME/.asdf/shims:$PATH"'); } + this.refreshEnvironment(); } refreshEnvironment() {