TECHNOLOGY-8

Добавить в имя пакета дату при сборке
dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 10 years ago
parent eb632e2c29
commit 367bd9cb69
  1. 2
      BuildServer/lib/builder.js
  2. 65
      BuildServer/routes/release.js

@ -62,7 +62,7 @@ var build = function (options, callback) {
warnMessage = result && result.warns ? ((result.warns.$allMessages || [])[0] || {}).message : err,
infoMessage = result && result.infos ? ((result.infos.$allMessages || []).slice(-1)[0] || {}).message : err;
fs.writeFile(release + "/report.json", JSON.stringify({err: err, result: result}), function (writeErr) {
fs.writeFile(release + "/report.json", JSON.stringify({date: Date.now(), err: err, result: result}), function (writeErr) {
statusQueue.push(function (callback) {
async.parallel([
function (callback) {

@ -1,7 +1,48 @@
"use strict";
var path = require('path');
var Zip = require('adm-zip');
var path = require('path'),
fs = require('fs'),
Zip = require('adm-zip');
var getReport = function(releasePath, callback) {
var reportFile = releasePath + "/report.json";
fs.exists(reportFile, function (exists) {
if (!exists) {
return callback("ReportFileNotFound");
}
return fs.readFile(reportFile, function (err, dataBuffer) {
if (err) {
return callback(err, options);
}
var data = dataBuffer.toString();
if (!data) {
return callback("ReportFileNotFound", options);
}
var report = JSON.parse(data);
return callback(null, report);
});
});
};
var getDatePart = function (report) {
if (!report.date) {
return "unknowndate";
}
var date = new Date(report.date),
paddingLeft = function (str, paddingValue) {
return String(paddingValue + str).slice(-paddingValue.length);
};
return date.getFullYear() + "." +
paddingLeft(date.getMonth() + 1, "00") + "." +
paddingLeft(date.getDate(), "00") + "." +
paddingLeft(date.getHours(), "00") + "." +
paddingLeft(date.getMinutes(), "00") + "." +
paddingLeft(date.getSeconds(), "00");
};
module.exports = function(req, res, next) {
var options = {
@ -15,11 +56,17 @@ module.exports = function(req, res, next) {
var zip = new Zip(),
releasePath = path.normalize(req.app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/" + options.branch + "/" + options.rev + "/");
zip.addLocalFolder(releasePath);
zip.toBuffer(function (buffer) {
res.attachment(options.reponame + '.' + options.rev + '.zip', '.');
res.send(buffer);
}, function (error) {
next(error);
}, function () { }, function () { });
getReport(releasePath, function (err, report) {
if (err) {
return next(err);
}
zip.addLocalFolder(releasePath);
zip.toBuffer(function (buffer) {
res.attachment(options.reponame + '.' + getDatePart(report) + '.' + options.rev + '.zip', '.');
res.send(buffer);
}, function (error) {
next(error);
}, function () { }, function () { });
});
};

Loading…
Cancel
Save