Skip to content

Commit

Permalink
Merge branch 'dev' into releases/v1
Browse files Browse the repository at this point in the history
  • Loading branch information
leoli0605 committed May 9, 2024
2 parents 03b9614 + 61d353d commit bd6fe0d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 45 deletions.
33 changes: 12 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packageData.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion scripts/linux/basesetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion scripts/npm.setup
Original file line number Diff line number Diff line change
@@ -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
45 changes: 26 additions & 19 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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')));
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit bd6fe0d

Please sign in to comment.