bigbrother-webpack-plugin
Advanced tools
Comparing version 1.1.1 to 1.1.2
1.1.2 / 2018-11-29 | ||
================== | ||
* fix: online report | ||
* fix: 数据格式修改 | ||
* feat: merge satori | ||
1.1.1 / 2018-11-16 | ||
@@ -3,0 +10,0 @@ ================== |
import { ISatoriCreateBuild, IAdapter } from '../typings'; | ||
export default class SatoriAdapter implements IAdapter { | ||
private prefixHost; | ||
private satoriClient; | ||
constructor(); | ||
postBuild(args: ISatoriCreateBuild): Promise<void>; | ||
postDev(args: ISatoriCreateBuild): Promise<void>; | ||
uploadShameimaru(shameimaru: object): Promise<string>; | ||
private ifSkipBuildReport; | ||
private ifDevReport; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var urllib_1 = require("urllib"); | ||
var enum_1 = require("../enum"); | ||
var SatoriAdapter = /** @class */ (function () { | ||
// private satoriClient; | ||
function SatoriAdapter() { | ||
this.prefixHost = 'http://bigbrother.dockerlab.alipay.net'; | ||
// this.satoriClient = new Satori('bigbrother'); | ||
var SatoriClient = require('@alipay/satori-client'); | ||
this.satoriClient = new SatoriClient('bigfish-build'); | ||
} | ||
@@ -14,12 +13,12 @@ SatoriAdapter.prototype.postBuild = function (args) { | ||
return tslib_1.__generator(this, function (_a) { | ||
// TODO: 调用 satori sdk | ||
console.log(args); | ||
urllib_1.request(this.prefixHost + "/api/postBuild", { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
data: args, | ||
}); | ||
return [2 /*return*/]; | ||
switch (_a.label) { | ||
case 0: | ||
if (this.ifSkipBuildReport(args)) { | ||
return [2 /*return*/]; | ||
} | ||
return [4 /*yield*/, this.satoriClient.postFrontendBuildInfo(args)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
@@ -31,11 +30,5 @@ }); | ||
return tslib_1.__generator(this, function (_a) { | ||
// TODO: 调用 satori sdk | ||
console.log(args); | ||
urllib_1.request(this.prefixHost + "/api/postDev", { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
data: args, | ||
}); | ||
if (this.ifDevReport(args)) { | ||
return [2 /*return*/]; | ||
} | ||
return [2 /*return*/]; | ||
@@ -45,4 +38,51 @@ }); | ||
}; | ||
SatoriAdapter.prototype.uploadShameimaru = function (shameimaru) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var url; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.satoriClient.uploadShameimaru(JSON.stringify(shameimaru))]; | ||
case 1: | ||
url = _a.sent(); | ||
return [2 /*return*/, url]; | ||
} | ||
}); | ||
}); | ||
}; | ||
SatoriAdapter.prototype.ifSkipBuildReport = function (data) { | ||
// 环境变量跳过上报: 设置环境变量 NO_BIGBROTHER=true 可以关闭内网环境验证和数据上报 | ||
if (process.env.NO_BIGBROTHER === 'true') { | ||
return true; | ||
} | ||
var platform = data.platform; | ||
// 只收集 LinkE 平台的构建与 Basement 平台的构建。本地构建不上传 | ||
if (!platform.type) { | ||
return true; | ||
} | ||
// Basement 和 LinkE 都需要传入 appName | ||
if (!platform.appName) { | ||
return true; | ||
} | ||
// Basement 平台需要传入 appType | ||
if (platform.type === enum_1.PLATFORM_TYPE.BASEMENT) { | ||
if (!platform.appType) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
SatoriAdapter.prototype.ifDevReport = function (data) { | ||
// 环境变量跳过上报: 设置环境变量 NO_BIGBROTHER=true 可以关闭内网环境验证和数据上报 | ||
if (process.env.NO_BIGBROTHER === 'true') { | ||
return true; | ||
} | ||
var git = data.git; | ||
// 本地若无 git 信息,跳过上报 | ||
if (!git.repository) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
return SatoriAdapter; | ||
}()); | ||
exports.default = SatoriAdapter; |
@@ -1,2 +0,2 @@ | ||
import MonitorClient from './MonitorClient'; | ||
import SatoriAdapter from './adapter/satori'; | ||
import { IOptions, ITYPETOOL } from './typings'; | ||
@@ -8,6 +8,6 @@ declare class BigBrotherWebpackPlugin implements IOptions { | ||
buildConfig?: object; | ||
monitorClient: MonitorClient; | ||
satori: SatoriAdapter; | ||
constructor(options: any); | ||
apply(compiler: any): void; | ||
report(stats: any): void; | ||
report(stats: any): Promise<void>; | ||
private getReportData; | ||
@@ -14,0 +14,0 @@ private getStages; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var path_1 = require("path"); | ||
var assert = require("assert"); | ||
var uuid_1 = require("uuid"); | ||
var MonitorClient_1 = require("./MonitorClient"); | ||
var satori_1 = require("./adapter/satori"); | ||
var utils_1 = require("./utils"); | ||
@@ -18,3 +19,3 @@ var BigBrotherWebpackPlugin = /** @class */ (function () { | ||
try { | ||
this.monitorClient = new MonitorClient_1.default(); | ||
this.satori = new satori_1.default(); | ||
} | ||
@@ -37,39 +38,72 @@ catch (_) { } | ||
BigBrotherWebpackPlugin.prototype.report = function (stats) { | ||
var data = this.getReportData(stats); | ||
var fun = process.env.NODE_ENV === 'production' ? 'postBuild' : 'postDev'; | ||
try { | ||
this.monitorClient[fun](data); | ||
} | ||
catch (_) { | ||
} | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var data, fun; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.getReportData(stats)]; | ||
case 1: | ||
data = _a.sent(); | ||
fun = process.env.NODE_ENV === 'production' ? 'postBuild' : 'postDev'; | ||
try { | ||
this.satori[fun](data); | ||
} | ||
catch (_) { | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
BigBrotherWebpackPlugin.prototype.getReportData = function (stats) { | ||
var _a = process.versions, node = _a.node, _b = _a.alinode, alinode = _b === void 0 ? '' : _b; | ||
return { | ||
buildTimeRef: uuid_1.v4(), | ||
cwd: this.cwd, | ||
success: !stats.hasErrors(), | ||
startAt: stats.startTime, | ||
endedAt: stats.endTime, | ||
tool: this.tool, | ||
pkg: utils_1.getPkg(this.cwd), | ||
buildConfig: this.buildConfig, | ||
artifact: utils_1.getArtifactInfo(stats), | ||
errors: stats.compilation.errors.slice(0, 2).map(function (_a) { | ||
var name = _a.name, message = _a.message; | ||
return ({ | ||
name: name, | ||
message: message ? message(0, 200) : '', | ||
}); | ||
}), | ||
stages: this.getStages(stats), | ||
node: { | ||
node: node, | ||
alinode: alinode, | ||
}, | ||
git: utils_1.getGitInfo(this.cwd), | ||
platform: utils_1.getPlatformInfo(), | ||
envs: process.env, | ||
hardware: utils_1.getHardware(), | ||
}; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _a, node, _b, alinode, depTreeOssUrl, depTree, _1; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_a = process.versions, node = _a.node, _b = _a.alinode, alinode = _b === void 0 ? '' : _b; | ||
_c.label = 1; | ||
case 1: | ||
_c.trys.push([1, 4, , 5]); | ||
return [4 /*yield*/, utils_1.getDepTree(this.cwd)]; | ||
case 2: | ||
depTree = _c.sent(); | ||
return [4 /*yield*/, this.satori.uploadShameimaru(depTree)]; | ||
case 3: | ||
depTreeOssUrl = _c.sent(); | ||
return [3 /*break*/, 5]; | ||
case 4: | ||
_1 = _c.sent(); | ||
depTreeOssUrl = ''; | ||
return [3 /*break*/, 5]; | ||
case 5: return [2 /*return*/, { | ||
buildTimeRef: uuid_1.v4(), | ||
cwd: this.cwd, | ||
success: !stats.hasErrors(), | ||
startedAt: stats.startTime, | ||
endedAt: stats.endTime, | ||
tool: this.tool, | ||
pkg: utils_1.getPkg(this.cwd), | ||
buildConfig: this.buildConfig, | ||
artifact: utils_1.getArtifactInfo(stats), | ||
errors: stats.compilation.errors.slice(0, 2).map(function (_a) { | ||
var name = _a.name, message = _a.message; | ||
return ({ | ||
name: name, | ||
message: message ? message(0, 200) : '', | ||
}); | ||
}), | ||
stages: this.getStages(stats), | ||
node: { | ||
node: node, | ||
alinode: alinode, | ||
}, | ||
git: utils_1.getGitInfo(this.cwd), | ||
platform: utils_1.getPlatformInfo(), | ||
envs: process.env, | ||
hardware: utils_1.getHardware(), | ||
shameimaruUrl: depTreeOssUrl, | ||
}]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -76,0 +110,0 @@ // 取 stages |
@@ -11,2 +11,3 @@ import * as webpack from 'webpack'; | ||
cloudBuildLog?: string; | ||
appType?: string; | ||
appName?: string; | ||
@@ -25,3 +26,3 @@ } | ||
memory?: number; | ||
hostName?: string; | ||
hostname?: string; | ||
platform?: string; | ||
@@ -46,3 +47,3 @@ } | ||
success: boolean; | ||
startAt: Date; | ||
startedAt: Date; | ||
endedAt: Date; | ||
@@ -69,2 +70,3 @@ cwd: string; | ||
hardware: IHardware; | ||
shameimaruUrl: string; | ||
} | ||
@@ -71,0 +73,0 @@ export interface ICreateRuntime extends ICommonArgs { |
@@ -1,4 +0,3 @@ | ||
import getHardware from './getHardware'; | ||
import { IPkg, IBuildGitInfo, IPlatformInfo, IHardware } from '../typings'; | ||
import GitInfo from './GitInfo'; | ||
import { IPkg, IBuildGitInfo, IPlatformInfo } from '../typings'; | ||
declare function getPkg(cwd: any): IPkg; | ||
@@ -12,2 +11,4 @@ declare function getArtifactInfo(stats: any): { | ||
declare function getPlatformInfo(): IPlatformInfo; | ||
export { GitInfo, getHardware, getPkg, getArtifactInfo, getGitInfo, getPlatformInfo, }; | ||
declare function getHardware(): IHardware; | ||
declare function getDepTree(cwd: string): Promise<any>; | ||
export { GitInfo, getHardware, getPkg, getArtifactInfo, getGitInfo, getPlatformInfo, getDepTree, }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var getHardware_1 = require("./getHardware"); | ||
exports.getHardware = getHardware_1.default; | ||
var tslib_1 = require("tslib"); | ||
var os = require("os"); | ||
var path_1 = require("path"); | ||
var fs_1 = require("fs"); | ||
var enum_1 = require("../enum"); | ||
var GitInfo_1 = require("./GitInfo"); | ||
exports.GitInfo = GitInfo_1.default; | ||
var enum_1 = require("../enum"); | ||
var path_1 = require("path"); | ||
var fs_1 = require("fs"); | ||
function getPkg(cwd) { | ||
@@ -48,7 +48,3 @@ var pkg = {}; | ||
function getPlatformInfo() { | ||
var _a = process.env, PLATFORM_TYPE = _a.PLATFORM_TYPE, | ||
// basement | ||
CLOUD_BUILD_ID = _a.CLOUD_BUILD_ID, CLOUD_BUILD_LOG = _a.CLOUD_BUILD_LOG, | ||
// linke | ||
APP_NAME = _a.APP_NAME; | ||
var _a = process.env, PLATFORM_TYPE = _a.PLATFORM_TYPE, CLOUD_BUILD_ID = _a.CLOUD_BUILD_ID, CLOUD_BUILD_LOG = _a.CLOUD_BUILD_LOG, APP_NAME = _a.APP_NAME, APP_TYPE = _a.APP_TYPE; | ||
var type = [enum_1.PLATFORM_TYPE.BASEMENT, enum_1.PLATFORM_TYPE.LINKE].indexOf(PLATFORM_TYPE) > -1 | ||
@@ -60,8 +56,30 @@ ? PLATFORM_TYPE | ||
// basement | ||
cloudBuildId: (CLOUD_BUILD_ID || ''), | ||
cloudBuildLog: CLOUD_BUILD_LOG || '', | ||
cloudBuildId: (CLOUD_BUILD_ID || null), | ||
cloudBuildLog: CLOUD_BUILD_LOG || null, | ||
// appname | ||
appName: APP_NAME, | ||
appType: APP_TYPE, | ||
}; | ||
} | ||
exports.getPlatformInfo = getPlatformInfo; | ||
function getHardware() { | ||
return { | ||
cpuLength: os.cpus().length, | ||
arch: os.arch(), | ||
memory: os.totalmem() / 1024 / 1024 / 1024, | ||
hostname: os.hostname(), | ||
platform: os.platform(), | ||
}; | ||
} | ||
exports.getHardware = getHardware; | ||
function getDepTree(cwd) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var Shameimaru, shameimaru; | ||
return tslib_1.__generator(this, function (_a) { | ||
Shameimaru = require('shameimaru'); | ||
shameimaru = new Shameimaru(cwd); | ||
return [2 /*return*/, shameimaru.traverse()]; | ||
}); | ||
}); | ||
} | ||
exports.getDepTree = getDepTree; |
{ | ||
"name": "bigbrother-webpack-plugin", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "bigbrother client", | ||
@@ -13,3 +13,3 @@ "main": "lib/index.js", | ||
"build": "npm run clean && tsc", | ||
"test": "npm run build && TEST=1 mocha -r ts-node/register test/**/*.test.ts", | ||
"test": "npm run build && TEST=1 mocha -r ts-node/register test/*.test.ts test/**/*.test.ts", | ||
"ci": "npm run lint && npm run test", | ||
@@ -63,6 +63,6 @@ "lint": "tslint --project ./tsconfig.json", | ||
"is-ali-env": "^0.1.4", | ||
"shameimaru": "^1.0.1", | ||
"tslib": "^1.9.3", | ||
"urllib": "^2.31.2", | ||
"uuid": "^3.3.2" | ||
} | ||
} |
23967
601
18
12
+ Addedshameimaru@^1.0.1
+ Addedalgorithmjs@1.0.0(transitive)
+ Addedbuiltins@1.0.3(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addednpm-package-arg@6.1.1(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedosenv@0.1.5(transitive)
+ Addedshameimaru@1.0.6(transitive)
+ Addedvalidate-npm-package-name@3.0.0(transitive)
- Removedurllib@^2.31.2
- Removedcontent-type@1.0.5(transitive)
- Removedcopy-to@2.0.1(transitive)
- Removeddefault-user-agent@1.0.0(transitive)
- Removeddestroy@1.2.0(transitive)
- Removeddigest-header@1.1.0(transitive)
- Removedee-first@1.1.1(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedescape-html@1.0.3(transitive)
- Removedextend-shallow@2.0.1(transitive)
- Removedformstream@1.5.1(transitive)
- Removedhumanize-ms@1.2.1(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedis-extendable@0.1.1(transitive)
- Removedmime@2.6.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednode-hex@1.0.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedos-name@1.0.3(transitive)
- Removedosx-release@1.1.0(transitive)
- Removedpause-stream@0.0.11(transitive)
- Removedpump@3.0.2(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedstatuses@1.5.0(transitive)
- Removedthrough@2.3.8(transitive)
- Removedunescape@1.0.1(transitive)
- Removedurllib@2.44.0(transitive)
- Removedutility@1.18.0(transitive)
- Removedwin-release@1.1.1(transitive)
- Removedwrappy@1.0.2(transitive)