Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions main/ipc/installNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ export default () => {
});

childProcess.on('message', ({ channel, data }: any) => {
if (channel === processChannel && (data.status === 'done')) {
killChannelChildProcess(childProcessMap, installChannel);
if (channel === processChannel) {
const { status, result } = data;
if (status === 'done') {
killChannelChildProcess(childProcessMap, installChannel);
} else if (status === 'success' && result && result.nodePath) {
// nodeEnvPath e.g: /Users/xxx/.nvm/versions/node/v14.15.0/bin/path -> Users/xxx/.nvm/versions/node/v14.15.0/bin
const nodeEnvPath = result.nodePath.replace('/bin/node', '/bin');
// process.env.PATH: /usr/local/bin -> /Users/xxx/.nvm/versions/node/v14.15.0/bin:/usr/local/bin
process.env.PATH = `${nodeEnvPath}${path.delimiter}${process.env.PATH}`;
}
}
sendMainWindow(channel, data);
});
Expand Down
6 changes: 3 additions & 3 deletions main/node/NvmManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class NvmManager implements INodeManager {
});

cp.on('exit', () => {
this.nodePath = this.getCurrentNodePath(this.std);
const nodePath = this.getCurrentNodePath(this.std);
const npmVersion = this.getCurrentNpmVersion(this.std);

resolve({ nodeVersion: formattedVersion, npmVersion });
this.nodePath = nodePath;
resolve({ nodeVersion: formattedVersion, npmVersion, nodePath });
});
});
};
Expand Down
27 changes: 14 additions & 13 deletions main/packageInfo/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,36 @@ import { DEFAULT_LOCAL_PACKAGE_INFO } from '../../constants';
import getVersionStatus from '../../utils/getVersionStatus';
import log from '../../utils/log';

function getLocalToolInfo(name: string, latestVersion: string | null) {
const localToolInfo = { ...DEFAULT_LOCAL_PACKAGE_INFO };
function getLocalCliInfo(name: string, latestVersion: string | null) {
const localCliInfo = { ...DEFAULT_LOCAL_PACKAGE_INFO };
// get the local path of cli
try {
const toolPath = shell.which(name);
if (!toolPath) {
throw new Error(`Tool ${name} is not found.`);
const { stdout: cliPath } = shell.which(name);

if (!cliPath) {
throw new Error(`Command ${name} is not found.`);
}
localToolInfo.localPath = toolPath.stdout;
localCliInfo.localPath = cliPath;
} catch (error) {
log.error(error.message);
return localToolInfo;
return localCliInfo;
}
// get cli version
try {
const { stdout: cliVersion } = execa.sync(
localToolInfo.localPath,
localCliInfo.localPath,
['--version'],
{ shell: true, extendEnv: false },
{ shell: true },
);
const cliVersionMatch = cliVersion.match(/(\d+(\.\d+)*)/);
localToolInfo.localVersion = cliVersionMatch ? cliVersionMatch[1] : cliVersion;
localCliInfo.localVersion = cliVersionMatch ? cliVersionMatch[1] : cliVersion;
} catch (error) {
log.error(`Tool ${name} version is not found. Error: ${error.message}`);
}
// get cli version status
localToolInfo.versionStatus = getVersionStatus(localToolInfo.localVersion, latestVersion);
localCliInfo.versionStatus = getVersionStatus(localCliInfo.localVersion, latestVersion);

return localToolInfo;
return localCliInfo;
}

export default getLocalToolInfo;
export default getLocalCliInfo;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build": "rm -rf ./dist && npm run build:renderer && npm run build:main",
"build:renderer": "cd ./renderer && npm run build",
"build:main": "tsc --build ./main/tsconfig.json",
"package": "npm run build && npm run copy:static && NPM_CONFIG_ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ electron-builder build --mac",
"package": "rm -rf release && npm run build && npm run copy:static && NPM_CONFIG_ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ electron-builder build --mac",
"lint": "npm run eslint && npm run stylelint",
"eslint": "eslint --ext .ts,.tsx,.js,.jsx ./",
"eslint:fix": "npm run eslint -- --fix",
Expand Down Expand Up @@ -97,4 +97,4 @@
"typescript": "^4.0.0",
"wait-on": "^5.3.0"
}
}
}