Skip to content

Commit

Permalink
enhancement: [arco-cli] add log report
Browse files Browse the repository at this point in the history
  • Loading branch information
Helium-Z committed Dec 9, 2021
1 parent b5c1d5d commit c03002c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/arco-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arco-design/arco-cli",
"version": "1.22.1",
"version": "1.22.2",
"description": "Init an Arco material project quickly",
"keywords": [
"arco",
Expand Down
4 changes: 4 additions & 0 deletions packages/arco-cli/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import subCommands from './subCommands';
import { printLogo, fetchLatestVersion } from './utils';
import { listAllGroups, queryGroup, addGroupMember, deleteGroupMember } from './group';
import { checkEnv, switchEnv, printEnv } from './env';
import teaLog from './teaLog';

const VALID_SUBCOMMANDS = [
'init',
Expand Down Expand Up @@ -178,6 +179,9 @@ function registerCommand() {

printLogo();
registerCommand();
teaLog({
args: process.argv.slice(2).join(' '),
});

if (process.argv[2] !== 'env' && checkEnv() === false) {
switchEnv()
Expand Down
37 changes: 37 additions & 0 deletions packages/arco-cli/src/teaLog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import axios from 'axios';
import os from 'os';
import { getGlobalInfo } from '@arco-design/arco-dev-utils';

interface LogParameters {
user: {
username: string;
};
event: {
event: string;
time: number;
params: Record<string, any>;
};
}

export default function teaLog(params: LogParameters['event']['params']) {
try {
const globalInfo = getGlobalInfo();
if (globalInfo && globalInfo.host?.arco) {
const message: LogParameters = {
user: {
username: globalInfo.userInfo?.username || '',
},
event: {
event: 'arco_cli',
time: +Date.now(),
params: {
...params,
os: os.type(),
node: process.version,
},
},
};
axios.post(`${globalInfo.host.arco}/material/api/log`, message).catch(() => {});
}
} catch (err) {}
}

0 comments on commit c03002c

Please sign in to comment.