Посредством node-minify (npm пакет) и его библиотеки делаю минификацию файла
сам файл весит 6кб
var CADESCOM_CADES_X_LONG_TYPE_1 = 0x5d;
var CADESCOM_CADES_BES = 1;
var CAPICOM_CURRENT_USER_STORE = 2;
var CAPICOM_MY_STORE = "My";
var CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED = 2;
var CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME = 1;
function GetErrorMessage(e) {
var err = e.message;
if (!err) {
err = e;
} else if (e.number) {
err += " (" + e.number + ")";
}
return err;
}
function SignCreate(certSubjectName, dataToSign, $rootScope, storageService) {
return new Promise(function(resolve, reject){
cadesplugin.async_spawn(function *(args) {
try {
var oStore = yield cadesplugin.CreateObjectAsync("CAPICOM.Store");
yield oStore.Open(CAPICOM_CURRENT_USER_STORE, CAPICOM_MY_STORE,CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);
var CertificatesObj = yield oStore.Certificates;
var oCertificates = yield CertificatesObj.Find(
CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME, certSubjectName);
var Count = yield oCertificates.Count;
if (Count == 0) {
throw("Certificate not found: " + args[0]);
}
var oCertificate = yield oCertificates.Item(1);
var oSigner = yield cadesplugin.CreateObjectAsync("CAdESCOM.CPSigner");
yield oSigner.propset_Certificate(oCertificate);
var oSignedData = yield cadesplugin.CreateObjectAsync("CAdESCOM.CadesSignedData");
var tspService = "http://testca.cryptopro.ru/tsp/";
yield oSignedData.propset_Content(dataToSign);
yield oSigner.propset_TSAAddress(tspService);
var sSignedMessage = yield oSignedData.SignCades(oSigner, CADESCOM_CADES_X_LONG_TYPE_1);
//var sSignedMessage = yield oSignedData.SignCades(oSigner, CADESCOM_CADES_BES);
yield oStore.Close();
args[2](sSignedMessage);
}
catch (err)
{
if ($rootScope) {
$rootScope.crypto = true;
$rootScope.$digest();
}
if (storageService) {
storageService.freezeMode = false;
}
throw GetErrorMessage(err);
}
}, certSubjectName, dataToSign, resolve, reject);
});
}
/**
* Формирование строчки сертификата
*/
function CertificateAdjuster() {
this.extract = function(from, what) {
certName = "";
var begin = from.indexOf(what);
if(begin>=0)
{
var end = from.indexOf(', ', begin);
certName = (end<0) ? from.substr(begin) : from.substr(begin, end - begin);
}
return certName;
};
this.Print2Digit = function(digit){
return (digit<10) ? "0"+digit : digit;
};
this.GetCertDate = function(paramDate) {
var certDate = new Date(paramDate);
return this.Print2Digit(certDate.getUTCDate())+"."+this.Print2Digit(certDate.getMonth()+1)+"."+certDate.getFullYear() + " " +
this.Print2Digit(certDate.getUTCHours()) + ":" + this.Print2Digit(certDate.getUTCMinutes()) + ":" + this.Print2Digit(certDate.getUTCSeconds());
};
this.GetCertName = function(certSubjectName){
return this.extract(certSubjectName, 'CN=');
};
this.GetIssuer = function(certIssuerName){
return this.extract(certIssuerName, 'CN=');
};
this.GetCertInfoString = function(certSubjectName, certFromDate, issuedBy){
return this.extract(certSubjectName,'CN=') + "; Выдан: " + this.GetCertDate(certFromDate) + " " + issuedBy;
};
}
function FillCertList_NPAPI($rootScope) {
return new Promise(function(resolve, reject){
cadesplugin.async_spawn(function *(args) {
try {
var oStore = yield cadesplugin.CreateObjectAsync("CAPICOM.Store");
yield oStore.Open(CAPICOM_CURRENT_USER_STORE, CAPICOM_MY_STORE,CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);
var CertificatesObj = yield oStore.Certificates;
var Count = yield CertificatesObj.Count;
if (Count == 0) {
// не установлены сертификаты
$rootScope.globalCountCertificate = 0;
$rootScope.error = true;
throw("Нет сертификатов");
}
if (!Array.isArray($rootScope.globalOptionList)) {
$rootScope.globalOptionList = [];
}
var text;
var dateObj = new Date();
var count = 0;
for (var i = 1; i <= Count; i++) {
var cert = yield CertificatesObj.Item(i);
var ValidToDate = new Date((yield cert.ValidToDate));
var ValidFromDate = new Date((yield cert.ValidFromDate));
var HasPrivateKey = yield cert.HasPrivateKey();
var Validator = yield cert.IsValid();
var IsValid = yield Validator.Result;
if( dateObj < new Date(ValidToDate) && IsValid && HasPrivateKey) {
var issuedBy = yield cert.GetInfo(1);
issuedBy = issuedBy || "";
text = new CertificateAdjuster().GetCertInfoString(yield cert.SubjectName, ValidFromDate, issuedBy);
$rootScope.globalOptionList.push({'value': text.replace(/^cn=([^;]+);.+/i, '$1'), 'text' : text.replace("CN=", "") });
count++;
}
}
$rootScope.globalCountCertificate = count;
console.log($rootScope)
} catch (err) {
console.log($rootScope)
$rootScope.error = true;
}
});
});
}
Но в итоге получается файл на 23кб, после минификации и такой:
var $jscomp={};$jscomp.scope={};$jscomp.defineProperty=typeof Object.defineProperties=="function"?Object.defineProperty:function(target,property,descriptor){descriptor=(descriptor);if(descriptor.get||descriptor.set)throw new TypeError("ES3 does not support getters and setters.");if(target==Array.prototype||target==Object.prototype)return;target[property]=descriptor.value};
$jscomp.getGlobal=function(maybeGlobal){return typeof window!="undefined"&&window===maybeGlobal?maybeGlobal:typeof global!="undefined"&&global!=null?global:maybeGlobal};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_";$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};if(!$jscomp.global.Symbol)$jscomp.global.Symbol=$jscomp.Symbol};$jscomp.symbolCounter_=0;$jscomp.Symbol=function(opt_description){return($jscomp.SYMBOL_PREFIX+(opt_description||"")+$jscomp.symbolCounter_++)};
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var
...
Минифицирую таким способом:
var filepath = "/home/splincode/Develop/blackbox/ui-util/src/shared/js/crypto/webkitcrypto.js";
var filename = filepath.split(/[/ ]+/).pop();
var promise = compressor.minify({
compressor: 'gcc',
input: filepath,
output: `./src/public/js/${filename}`,
});
promise.then(function(min) {
console.log("to minified: ", `./src/public/js/${filename}`);
});
Uglify я так понял не поддерживает ES6
Я хотел просто минифицировать файл!