Skip to content

Commit

Permalink
refactor: refactor windows package installation in index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
leoli0605 committed Mar 7, 2024
1 parent adad422 commit 7536047
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,31 @@ selectPackages()
let args = [];
if (os.platform() === 'win32') {
const ps = new PowerShell();
ps.addEnvironment('$HOME\\AppData\\Roaming\\Python\\Scripts'); // for python
ps.addEnvironment('$HOME\\leoli\\.cargo\\bin'); // for rust

for (const p of selectedPackages) {
if (p) {
ps.addCommand(p.installCommand);
}
}
ps.addCommand('refreshenv\n'); // for powershell to refresh environment variables

ps.addCommand('python.exe -m pip install --upgrade pip'); // for pip
ps.addCommand('(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -'); // for poetry
ps.addCommand('poetry config virtualenvs.in-project true'); // for poetry
const pipSetup = fs.readFileSync(path.join(__dirname, '../scripts/pip.setup'), 'utf8').trim();
ps.addCommand(pipSetup);
if (selectedPackages.some((p) => p && p.packageName.startsWith('Python'))) {
ps.addEnvironment('$HOME\\AppData\\Roaming\\Python\\Scripts');
ps.addCommand('python.exe -m pip install --upgrade pip'); // for pip
ps.addCommand('(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -'); // for poetry
ps.addCommand('poetry config virtualenvs.in-project true'); // for poetry
const pipSetup = fs.readFileSync(path.join(__dirname, '../scripts/pip.setup'), 'utf8').trim();
ps.addCommand(pipSetup);
}
if (selectedPackages.some((p) => p && p.packageName.startsWith('Rust'))) {
ps.addEnvironment('$HOME\\leoli\\.cargo\\bin');
}
ps.addCommand('refreshenv\n'); // for powershell to refresh environment variables

const npmSetup = fs.readFileSync(path.join(__dirname, '../scripts/npm.setup'), 'utf8').trim();
ps.addCommand(npmSetup);
ps.addCommand('npx @leoli0605/git-setup'); // for git
if (selectPackages.some((p) => p && p.packageName.startsWith('Node.js'))) {
const npmSetup = fs.readFileSync(path.join(__dirname, '../scripts/npm.setup'), 'utf8').trim();
ps.addCommand(npmSetup);
ps.addCommand('npx @leoli0605/git-setup'); // for git
}
ps.addCommand('refreshenv\n'); // for powershell to refresh environment variables

if (selectedPackages.some((p) => p && p.packageName.startsWith('Sublime Text'))) {
Expand Down

0 comments on commit 7536047

Please sign in to comment.