Skip to content

Commit

Permalink
iceworks/3.4.2 (#2928)
Browse files Browse the repository at this point in the history
* feat: dau

* refactor: start and stop record

* chore: lint

* chore: browser compatible

* refactor: goldlog

* refactor: clear data for project && page record

* chore: lint

* refactor: rebase

* refactor: rebase

* fix: glodlog create-project

* feat: update version and changelog

* refactor: new field for 3.0 dau and record version

* chore: lint

* fix: typo

* fix: send dau after render
  • Loading branch information
alvinhui authored Nov 18, 2019
1 parent 31493a6 commit c65d18b
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 57 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# CHANGELOG for iceworks

## 3.4.2

- [refactor] Better user data collection methods

## 3.4.1

- [fix] Loss pacakge-json dependency


## 3.4.0

- [fix] Error in request sending parameters for data statistics
Expand Down
12 changes: 9 additions & 3 deletions packages/iceworks-client/src/hooks/useProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function useProject({ panelStores } = {}) {
const [deleteProjectPath, setDeleteProjectPath] = useState('');
const [scaffold, setScaffold] = useState({});

const { currentMaterial } = materialStore.dataSource;

const {
on: onCreateProjectModal,
setModal: setCreateProjectModal,
Expand Down Expand Up @@ -101,14 +103,18 @@ function useProject({ panelStores } = {}) {
}

async function createProject(data) {
await projectsStore.create(data);
await refreshProjects();
goldlog({
namespace: 'home',
module: 'project',
action: 'create-project',
data,
data: {
materialIsOfficial: currentMaterial.official,
scaffoldSourceNpm: scaffold.source.npm,
},
});

await projectsStore.create(data);
await refreshProjects();
setCreateProjectModal(false);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/iceworks-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useTheme from '@hooks/useTheme';
import '@alifd/next/reset.scss';

import logger from '@utils/logger';
import dau from '@utils/dau';
import socket from '@src/socket';
import MainLayout from '@layouts/MainLayout/index';
import { LocaleProvider } from '@components/Locale';
Expand Down Expand Up @@ -62,4 +63,4 @@ const App = () => {
);
};

ReactDOM.render(<App />, document.getElementById('iceworks'));
ReactDOM.render(<App />, document.getElementById('iceworks'), dau);
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const BuildPageModal = ({
} catch (error) {
showMessage(error);
}

setSaveModal(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ const PagePanel = ({ intl, title, description }) => {
async function createPage(data) {
const { menuName, routePath, routeGroup } = data;
logger.info('create page data:', data);
goldlog({
namespace: 'home',
module: 'project',
action: 'create-page',
data: {
blocks: data.blocks.length,
},
});

await pagesStore.create(data);

Expand Down Expand Up @@ -121,13 +129,6 @@ const PagePanel = ({ intl, title, description }) => {
pagesStore.refresh();
menuStore.refresh();
routerStore.refresh();

goldlog({
namespace: 'home',
module: 'project',
action: 'create-page',
data,
});
}

async function addBlocks(newBlocks) {
Expand Down
52 changes: 52 additions & 0 deletions packages/iceworks-client/src/utils/dau.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import axios from 'axios';
import dateTime from 'date-time';
import browser from 'browser-detect';
import logger from '@utils/logger';
import appConfig from '../appConfig';

const UA = browser();

function dau(data = {}) {
logger.info('log dau');

// eslint-disable-next-line @typescript-eslint/camelcase
data.visit_time = dateTime();
data.UA = UA;

return axios({
method: 'post',
url: `${appConfig.apiUrl}goldlog/dau`,
data,
});
}

let hidden;
let visibilityChange;
if (typeof document.hidden !== 'undefined') { // Opera 12.10 and Firefox 18 and later support
hidden = 'hidden';
visibilityChange = 'visibilitychange';
} else if (typeof document.msHidden !== 'undefined') {
hidden = 'msHidden';
visibilityChange = 'msvisibilitychange';
} else if (typeof document.webkitHidden !== 'undefined') {
hidden = 'webkitHidden';
visibilityChange = 'webkitvisibilitychange';
}

function handleVisibilityChange() {
if (!document[hidden]) {
dau();
}
}

export default function() {
dau();

if (typeof document.addEventListener !== 'undefined') {
document.addEventListener(visibilityChange, handleVisibilityChange, false);
}

if (typeof window.addEventListener !== 'undefined') {
window.addEventListener('focus', handleVisibilityChange);
}
};
2 changes: 1 addition & 1 deletion packages/iceworks-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iceworks-server",
"version": "3.4.1",
"version": "3.4.2",
"description": "iceworks server",
"files": [
"dist/",
Expand Down
61 changes: 34 additions & 27 deletions packages/iceworks-server/src/app/controller/goldlog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { controller, provide, post } from 'midway-mirror';
import * as request from 'request-promise-native';
import storage from '../../lib/storage';
import goldlog from '../../lib/goldlog';

const { checkAliInternal } = require('ice-npm-utils');
const packageJSON = require('../../../package.json');

@provide()
@controller('/api/goldlog')
Expand All @@ -9,33 +13,36 @@ export class GoldlogController {
public async record(ctx) {
if (ctx.request.body) {
const data = ctx.request.body;
const dataKeyArray = Object.keys(data);
const gokey = dataKeyArray.reduce((finnalStr, currentKey, index) => {
const currentData =
typeof data[currentKey] === 'string'
? data[currentKey]
: JSON.stringify(data[currentKey]);
return `${finnalStr}${currentKey}=${currentData}${
dataKeyArray.length - 1 === index ? '' : '&'
}`;
}, '');
await goldlog(data);
}

ctx.body = {
success: true,
};
}

@post('/dau')
public async dau(ctx) {
const isAlibaba = await checkAliInternal();
const nowtDate = new Date().toDateString();

try {
await request({
method: 'post',
url: 'http://gm.mmstat.com/iceteam.iceworks.log3',
json: true,
body: {
cache: Math.random(),
gmkey: 'CLK',
gokey: encodeURIComponent(gokey),
logtype: '2',
},
});
} catch (error) {
error.name = 'goldlog-error';
ctx.logger.error(error);
}
const dauKey = 'lastDate3';
const lastDate = storage.get(dauKey);
const locale = storage.get('locale');
const theme = storage.get('theme');
if(nowtDate !== lastDate) {
storage.set(dauKey, nowtDate);
await goldlog({
namespace: 'home',
module: 'log',
action: 'dau',
data: {
group: isAlibaba ? 'alibaba' : 'outer',
locale,
theme,
version: packageJSON.version,
},
});
}

ctx.body = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default (app) => {
storage.set('material', newMaterials);
}

return {...formatMaterialData(data), name: currentItem.name };
return {...formatMaterialData(data), name: currentItem.name, official: currentItem.official };
}

public async getRecommendScaffolds() {
Expand Down Expand Up @@ -120,7 +120,7 @@ export default (app) => {

const materialData = formatMaterialData(data);

return { resource: storage.get('material'), current: { ...materialData, name } };
return { resource: storage.get('material'), current: { ...materialData, name, official: currentItem.official } };
}

public async delete(ctx) {
Expand Down
12 changes: 11 additions & 1 deletion packages/iceworks-server/src/lib/adapter/modules/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as uniqBy from 'lodash.uniqby';
import { getAndExtractTarball } from 'ice-npm-utils';
import scanDirectory from '../../../scanDirectory';
import getNpmClient from '../../../getNpmClient';
import goldlog from '../../../goldlog';
import getIceVersion from '../../utils/getIceVersion';
import getTarballURLByMaterielSource from '../../../getTarballURLByMaterielSource';
import { install as installDependency } from '../dependency';
Expand Down Expand Up @@ -116,6 +117,7 @@ export default class Page implements IPageModule {
}

private async downloadBlockToPage(block: IMaterialBlock, pageName: string, ctx: IContext): Promise<void> {
const blockSourceNpm = block.source.npm;
const { i18n, logger } = ctx;
const projectPackageJSON = this.project.getPackageJSON();
const componentsDir = path.join(
Expand All @@ -124,6 +126,14 @@ export default class Page implements IPageModule {
this.componentDirName
);
await mkdirpAsync(componentsDir);
await goldlog({
namespace: 'adapter',
module: 'page',
action: 'downloadBlock',
data: {
block: blockSourceNpm,
},
});

const iceVersion: string = getIceVersion(projectPackageJSON);
const blockName: string = this.generateBlockName(block);
Expand All @@ -133,7 +143,7 @@ export default class Page implements IPageModule {
tarballURL = await getTarballURLByMaterielSource(block.source, iceVersion);
} catch (error) {
logger.error(error);
error.message = `${i18n.format('baseAdapter.page.download.requestError', { blockSourceNpm: block.source.npm })},可手动克隆 ${block.repository}`;
error.message = `${i18n.format('baseAdapter.page.download.requestError', { blockSourceNpm })},可手动克隆 ${block.repository}`;
throw error;
}

Expand Down
33 changes: 33 additions & 0 deletions packages/iceworks-server/src/lib/goldlog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as request from 'request-promise-native';

export default async function(data) {
try {
const dataKeyArray = Object.keys(data);
const gokey = dataKeyArray.reduce((finalStr, currentKey, index) => {
const currentData =
typeof data[currentKey] === 'string'
? data[currentKey]
: JSON.stringify(data[currentKey]);
return `${finalStr}${currentKey}=${currentData}${
dataKeyArray.length - 1 === index ? '' : '&'
}`;
}, '');

console.log('glodlog:', gokey);

await request({
method: 'post',
url: 'http://gm.mmstat.com/iceteam.iceworks.log3',
json: true,
body: {
cache: Math.random(),
gmkey: 'CLK',
gokey: encodeURIComponent(gokey),
logtype: '2',
},
});
} catch (error) {
error.name = 'goldlog-error';
console.error(error);
}
}
4 changes: 4 additions & 0 deletions packages/iceworks-server/src/lib/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ if (!fs.existsSync(confPath)) {
}

const schema = {
lastDate3: {
type: 'string',
default: '',
},
workFolder: {
type: 'string',
default: userHome,
Expand Down
20 changes: 7 additions & 13 deletions tools/iceworks-cli/command/start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ async function startIceworks(options) {
console.log();
process.exit(1);
});

process.on('SIGINT', () => {
goldlog('stop');
});
}

/**
Expand All @@ -169,19 +173,9 @@ async function checkServerVersion(packageName, packageVersion) {

async function dauStat() {
const isAlibaba = await checkAliInternal();
const nowtDate = new Date().toDateString();
const iceworksConfigPath = path.join(userHome, '.iceworks', 'db.json');
// eslint-disable-next-line
const iceworksConfigContent = require(`${iceworksConfigPath}`);
const lastDate = iceworksConfigContent.lastDate;
if(nowtDate !== lastDate) {
iceworksConfigContent.lastDate = nowtDate;
fs.writeFileSync(iceworksConfigPath, JSON.stringify(iceworksConfigContent, null, 2));

goldlog('dau', {
group: isAlibaba ? 'alibaba' : 'outer',
});
}
goldlog('start', {
group: isAlibaba ? 'alibaba' : 'outer',
});
}

module.exports = (...args) => {
Expand Down

0 comments on commit c65d18b

Please sign in to comment.