Skip to content

Commit

Permalink
fix: record log (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
luhc228 authored Aug 4, 2021
1 parent efd1f33 commit 4643b69
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 30 deletions.
7 changes: 7 additions & 0 deletions main/ipc/handleNpmDependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getGlobalDependenciesInfo,
} from '../npm/dependency';
import killChannelChildProcess from '../utils/killChannelChildProcess';
import { record } from '../recorder';

const childProcessMap = new Map();

Expand Down Expand Up @@ -54,6 +55,12 @@ export default () => {
childProcessMap.set(channel, childProcess);

childProcess.on('message', ({ data }: any) => {
if (data.status === 'done') {
record({
module: 'node',
action: 'createCustomGlobalDependenciesDir',
});
}
sendMainWindow(channel, data);
});
});
Expand Down
9 changes: 4 additions & 5 deletions main/ipc/installBasePackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export default () => {
if (channel === processChannel) {
if (data.status === 'done') {
killChannelChildProcess(childProcessMap, installChannel);
record({
module: 'base',
action: 'installPackages',
});
}
// save process data to cache
const processCaches = nodeCache.get(channel) || [];
Expand All @@ -48,11 +52,6 @@ export default () => {
nodeCache.set(channel, processCaches);
}

record({
module: 'base',
action: 'installPackages',
});

sendMainWindow(channel, data);
});
});
Expand Down
16 changes: 8 additions & 8 deletions main/ipc/installNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export default () => {
const { status, result } = data;
if (status === 'done') {
killChannelChildProcess(childProcessMap, installChannel);
record({
module: 'node',
action: 'installNode',
data: {
version: nodeVersion,
nodeManager: managerName,
},
});
} else if (status === 'success' && result && result.nodePath) {
// nodeEnvPath e.g: /Users/xxx/.nvm/versions/node/v14.15.0/bin/node -> Users/xxx/.nvm/versions/node/v14.15.0/bin
const nodeEnvPath = result.nodePath.replace('/bin/node', '/bin');
Expand All @@ -65,14 +73,6 @@ export default () => {
nodeCache.set(channel, processCaches);
}

record({
module: 'node',
action: 'installNode',
data: {
nodeVersion,
},
});

sendMainWindow(channel, data);
});
});
Expand Down
9 changes: 0 additions & 9 deletions main/node/NvmManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { INodeManager } from '../types';
import log from '../utils/log';
import formatNodeVersion from '../utils/formatNodeVersion';
import getShellName from '../utils/getShellName';
import { record } from '../recorder';

class NvmManager implements INodeManager {
channel: string;
Expand Down Expand Up @@ -42,14 +41,6 @@ class NvmManager implements INodeManager {
const npmVersion = this.getCurrentNpmVersion(this.std);
this.nodePath = nodePath;
resolve({ nodeVersion: formattedVersion, npmVersion, nodePath });
record({
module: 'node',
action: 'installNode',
data: {
version,
nodeManager: 'nvm',
},
});
});
});
};
Expand Down
6 changes: 0 additions & 6 deletions main/npm/dependency/createCustomGlobalDepsDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as AdmZip from 'adm-zip';
import { getNpmInfo, setNpmInfo } from '../npmInfo';
import log from '../../utils/log';
import { GLOBAL_DEPENDENCIES_PATH } from './globalDependenciesPath';
import { record } from '../../recorder';

async function createCustomGlobalDependenciesDir(channel: string, currentGlobalDepsPath: string) {
if (!path.relative(GLOBAL_DEPENDENCIES_PATH, currentGlobalDepsPath)) {
Expand All @@ -23,11 +22,6 @@ async function createCustomGlobalDependenciesDir(channel: string, currentGlobalD
await writePathToProfile(profilePath, channel);

process.send({ channel, data: { percent: 100, status: 'done' } });

record({
module: 'node',
action: 'createCustomGlobalDependenciesDir',
});
} catch (error) {
log.error(error);
process.send({ channel, data: { status: 'error', message: error.message } });
Expand Down
2 changes: 0 additions & 2 deletions main/utils/log.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as util from 'util';
import { app } from 'electron';
import * as log from 'electron-log';
import fetch from 'node-fetch';

Expand Down Expand Up @@ -29,7 +28,6 @@ log.transports.sls = ({ data, level }) => {
__topic__: level, // log level
APIVersion: '0.6.0', // sls param
platform: `${process.platform}_${process.arch}`,
electron_version: app.getVersion(),
toolkit_version: version,
};

Expand Down

0 comments on commit 4643b69

Please sign in to comment.