Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fis-auto-packager

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fis-auto-packager - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

lib/log.js

13

core/codeAnalyzer.js
var File = require("./file.js"),
util = require("../lib/util.js"),
gzip = require('gzip-js'),
fs = require("fs");

@@ -123,3 +124,13 @@

var stat = fs.statSync(filepath),
var content = util.read(filepath),
options = {
level: 6,
timestamp: parseInt(Date.now() / 1000, 10)
},
out = gzip.zip(content, options),
bakFile = filepath + ".bak";
util.write(bakFile, new Buffer(out));
var stat = fs.statSync(bakFile),
filesize = stat["size"],

@@ -126,0 +137,0 @@ deps = [];

@@ -0,1 +1,2 @@

var util = require("./../lib/util.js");

@@ -53,3 +54,8 @@

File.prototype.addPage = function(hash, pv){
this.pages[hash] = pv;
//会出现hash相同的情况,所以pv需要累加
if(this.pages[hash]){
this.pages[hash] += pv;
}else{
this.pages[hash] = pv;
}
}

@@ -56,0 +62,0 @@

@@ -1,2 +0,2 @@

//todo : 后续升级为每天定义下载分析数据
//todo : 后续升级为每天定时下载分析数据

@@ -26,2 +26,37 @@ var Record = require("./record.js"),

/**
* 切分log日志,并进行容错处理,容错方案
* 第一项 : 通过log平台切分脚本保证永远是fid并且绝对存在 logId
* 第二项 ; 十位hash值 pageHash
* 第三项 : 静态资源集合 逗号分割的七位hash值 data
* 第四项 : 数字pv值 pv
* 第五项 : 斜杠分割的路径tpl结尾 page
* 第六项 : http开头的url路径 url
* @param urlLogLine : map_batman 1ab500ad37 524d8e8,e2f65bd,2a3f5c5,4c580b1 95 taxi/page/vip.tpl http://taxi.map.baidu.com/vip
*/
function logSplite(urlLogLine){
var urlTokens = urlLogLine.split(/\s+|\t+/),
logToken = {},
logMatchReg = /(\w{10})|(\w{7}(?:,\w{7})+)|(\d+)|(\w+(?:\/\w+)+\.(?:tpl|html|xhtml))|(https?:\/\/.*)/;
logToken["fid"] = urlTokens.shift();
for(var i=0; i<urlTokens.length; i++){
var matchResult = urlTokens[i].match(logMatchReg);
if(matchResult){
if(matchResult[1]){
logToken["pageHash"] = matchResult[1];
}else if(matchResult[2]){
logToken["data"] = matchResult[2];
}else if(matchResult[3]){
logToken["pv"] = matchResult[3];
}else if(matchResult[4]){
logToken["page"] = matchResult[4];
}else if(matchResult[5]){
logToken["url"] = matchResult[5];
}
}
}
return logToken;
}
function processLogData(data, hashTable){

@@ -32,6 +67,8 @@ var lines = data.split(/\n|\r\n/),

if(util.trim(lines[i]) != ""){
var urlTokens = lines[i].split(/\s+|\t/),
statics = urlTokens[2].split(/,/),
var lineTokens = logSplite(lines[i]);
var statics = lineTokens["data"].split(/,/),
syncDepsRes = [],
asyncDepsRes = [];
for(var j=0; j<statics.length; j++){

@@ -49,6 +86,3 @@ var resource = hashTable[statics[j]];

}
//todo : 新版数据结构需要重新整理
urlTokens[5] = urlTokens[4];
urlTokens[4] = "index/page/index.tpl";
records.push(new Record(urlTokens[1], util.array_unique(syncDepsRes), util.array_unique(asyncDepsRes), urlTokens[3], urlTokens[4], urlTokens[5]));
records.push(new Record(lineTokens["pageHash"], util.array_unique(syncDepsRes), util.array_unique(asyncDepsRes), lineTokens["pv"], lineTokens["page"], lineTokens["url"]));
}

@@ -55,0 +89,0 @@ }

@@ -14,2 +14,4 @@ var util = require("./../lib/util.js");

this.packages = {};
//记录静态资源的请求个数
this.requestNum = 0;
}

@@ -16,0 +18,0 @@

32

fis-auto-packager.js

@@ -25,3 +25,3 @@

*/
function createPackConf(resources, outputDir, projectName){
function createPackConf(resources, outputDir, moduels, projectName){
var packResults = {};

@@ -34,16 +34,19 @@

type = tokens[tokens.length-1];
if(!packResults[module]){
packResults[module] = {};
}
util.map(packages, function(index, pkgFile){
var files = pkgFile.get("mergedStatic"),
packageKey = "pkg/" + packageKeyPrefix + "_" + index + "." + type;
//只产出指定的模块
if(util.in_array(module, moduels)){
if(!packResults[module]){
packResults[module] = {};
}
util.map(packages, function(index, pkgFile){
var files = pkgFile.get("mergedStatic"),
packageKey = "pkg/" + packageKeyPrefix + "_" + index + "." + type;
packResults[module][packageKey] = [];
packResults[module][packageKey] = [];
util.map(files, function(index, file){
packResults[module][packageKey].push(file.replace(/\w+:/, "/"));
util.map(files, function(index, file){
packResults[module][packageKey].push(file.replace(/\w+:/, "/"));
});
});
})
}
});

@@ -66,6 +69,7 @@

* @param projectName : 项目名称
* @param modules : 所有需要计算打包的模块名
* @param logUrl : 获取log日志的url
* @param callback : callback(error, result)
*/
module.exports.package = function(dir, outputDir, projectName, logUrl, callback){
module.exports.package = function(dir, outputDir, projectName, modules, logUrl, callback){
resources = codeAnalyzer.getResource(dir, hashTable, defaultPackages);

@@ -102,3 +106,3 @@ logAnalyzer.analyzeLog(function(error, records){

var predictPackageResultFile = packageReport.predictPackageResult(records, packageResults, outputDir, projectName);
var resultFile = createPackConf(packageResults, outputDir, projectName);
var resultFile = createPackConf(packageResults, outputDir, modules, projectName);
var resultFiles = {

@@ -105,0 +109,0 @@ "urlPv" : urlPvFile,

@@ -32,4 +32,4 @@ //todo : 是否需要产出收益分析文档报表

if(resource.get("type") == "js"){
csvAllBody += resource.get("id");
csvMainBody += resource.get("id");
csvAllBody += resource.get("id") + "_" + resource.get("pv");
csvMainBody += resource.get("id") + "_" + resource.get("pv");
for(var j=0; j<records.length; j++ ){

@@ -143,8 +143,22 @@ if(records[j].get("pv") > 0){

});
record.set("requestNum", num);
recordStr += num + "," + totalSize + "," + packageStr + "," + record.get("url") + "\n";
resultStr += recordStr;
});
util.write(file, resultStr);
var totalPv = 0,
requestCount = {},
requestStr = "";
util.map(records, function(index, record){
if(!requestCount[record.get("requestNum")]){
requestCount[record.get("requestNum")] = 0;
}
totalPv += parseInt(record.get("pv"));
requestCount[record.get("requestNum")] += parseInt(record.get("pv"));
});
util.map(requestCount, function(num, pv){
requestStr += "\nrequest num = " + num + " pv = " + pv + " percentage = " + Math.round((pv/totalPv) * 100) / 100;
});
util.write(file, resultStr + requestStr);
return file;
}
{
"name": "fis-auto-packager",
"version": "0.0.4",
"version": "0.0.5",
"description": "fis-auto-packager",

@@ -8,3 +8,4 @@ "main": "fis-auto-packager.js",

"request" : "*",
"adm-zip" : "*"
"adm-zip" : "*",
"gzip-js" : "*"
},

@@ -11,0 +12,0 @@ "scripts": {

@@ -7,3 +7,2 @@ /**

//todo : modjs需要做特殊处理
var benefitMap = {},

@@ -24,2 +23,3 @@ File = require("../core/file.js"),

newResources = sortByPv(newResources);
fixModjs(newResources);

@@ -38,2 +38,17 @@ util.map(newResources, function(packageKey, partResource){

function fixModjs(newResources){
util.map(newResources, function(key, resources){
for(var i=0; i<resources.length; i++){
var subpath = resources[i].get("subpath");
if(subpath.match(/mod\.js$/)){
resources[i].set("pv", resources[0].get("pv"));
resources[i].set("pages", resources[0].get("pages"));
var results = resources.splice(i, 1); //删除mod.js独享
resources.unshift(results[0]);
break;
}
}
});
}
function hit(resource, defaultPackages){

@@ -199,2 +214,6 @@ var type = resource.get("type"),

});
//todo : 记录打包的过程
if(staticA.get("module") == "common" && staticA.get("type") == "js" && largestResource != null){
console.log(staticA.get("id") + " and " + largestResource.get("id") + " merged benefit is = " + largestBenefit);
}
return {

@@ -235,2 +254,4 @@ "benefit" : largestBenefit,

if(newMergeBenefit > oldMergeBenefit){

@@ -246,3 +267,3 @@ //首先移除后面item,否则会导致误删除其他的item

oldMergeStatic.mergeStatic(newMergeStatic, newMergeBenefit);
resources.unshift(oldMergeStatic);
resources.push(oldMergeStatic);
mergePackage(originStatic, resources, mergedStatics);

@@ -249,0 +270,0 @@ }else{

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc