Skip to content

Commit

Permalink
fix: repair PowerShell commands and command execution errors
Browse files Browse the repository at this point in the history
  • Loading branch information
leoli0605 committed Mar 6, 2024
1 parent 4d129fe commit 8d464f2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packageData.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"install": {
"linux": "sudo apt install docker.io -y && sudo apt install docker-compose -y",
"mac": "brew install --cask docker && brew install docker-compose",
"windows": "choco install docker-desktop -y && choco install docker-compose -y"
"windows": "choco install docker-desktop -y ; choco install docker-compose -y"
},
"type": "enable"
},
Expand Down Expand Up @@ -275,7 +275,7 @@
"install": {
"linux": "npm install -g commitizen cz-conventional-changelog conventional-changelog-cli && echo '{\"path\": \"cz-conventional-changelog\"}' > ~/.czrc",
"mac": "npm install -g commitizen cz-conventional-changelog conventional-changelog-cli && echo '{\"path\": \"cz-conventional-changelog\"}' > ~/.czrc",
"windows": "npm install -g commitizen cz-conventional-changelog conventional-changelog-cli && echo '{\"path\": \"cz-conventional-changelog\"}' | Out-File -Encoding utf8 $HOME\\.czrc"
"windows": "npm install -g commitizen cz-conventional-changelog conventional-changelog-cli ; echo '{\"path\": \"cz-conventional-changelog\"}' | Out-File -Encoding utf8 $HOME\\.czrc"
},
"type": "enable"
},
Expand Down
6 changes: 2 additions & 4 deletions src/cmd_process.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { spawn } from "child_process";

function cmd(command, args) {
export function cmd(command, args) {
return new Promise((resolve, reject) => {
const process = spawn(command, args, { shell: true });
const process = spawn(command, args);

process.stdout.on("data", (data) => {
console.log(data.toString());
Expand All @@ -21,5 +21,3 @@ function cmd(command, args) {
});
});
}

export default { cmd };
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'fs';
import os from 'os';
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
import cmd from './cmd_process.js';
import { cmd } from './cmd_process.js';
import { selectPackages } from './package_selector.js';
import PowerShell from './powershell.js';

Expand Down Expand Up @@ -46,9 +46,9 @@ selectPackages()
ps.addCommand('refreshenv\n'); // for powershell to refresh environment variables

const psScript = ps.getScripts();
fs.writeFileSync(path.join(__dirname, 'scripts.ps1.log'), psScript);
// fs.writeFileSync(path.join(__dirname, 'scripts.ps1.log'), psScript);

const encodedPsScript = Buffer.from(psScript).toString('base64');
const encodedPsScript = Buffer.from(psScript, 'utf16le').toString('base64');
command = 'powershell.exe';
args = ['-NoProfile', '-EncodedCommand', encodedPsScript];
} else if (os.platform() === 'darwin') {
Expand All @@ -69,10 +69,10 @@ selectPackages()
console.log(`args: ${args}`);
cmd(command, args)
.then(() => {
console.log("Success executing scripts");
console.log('Success executing scripts');
})
.catch((error) => {
console.error("Error executing scripts:", error);
console.error('Error executing scripts:', error);
});
})
.catch((error) => {
Expand Down

0 comments on commit 8d464f2

Please sign in to comment.