const cp = require('child_process');
const path = require('path');
const {promisify} = require('util');
const exec = promisify(cp.exec);
function mkdirp(dirPath) {
return (process.platform === 'win32'
? exec(`mkdir ${path.win32.resolve(dirPath)}`) // win версия рекурсивна по умолчанию
: exec(`mkdir -p ${path.posix.resolve(dirPath)}`)
);
}
copyObj = (obj, name, id) => {
const trees = obj.trees;
const names = obj.names;
obj[name].forEach(item => {
const newId = uuid();
trees.forEach(tree => {
if (tree.tree_type !== 'obj_tree' || tree.tree_type !== 'obj_feature_tree' || tree.tree_type !== 'regexp_tree') { return; }
if (item.id === tree[tree.tree_type].parrent_element) {
tree[tree.tree_type].parrent_element = newId;
}
});
names.forEach(name => {
if (name.name_type !== 'unmark_name' || name.name_type !== 'shift_name' || name.name_type !== 'fill_name') { return; }
if (item.id === name[name.name_type].parrent_element) {
name[name.name_type].parrent_element = newId;
}
switch (name.name_type) {
case 'shift_name':
['parrent_element_from', 'parrent_element_to'].forEach(parrent_element => {
if (item.id === name.shift_name[parrent_element]) {
name.shift_name[parrent_element] = newId;
}
});
break;
case 'fill_name':
name.fill_name.feature_values.forEach(val => {
if (val.value_type === 'dynamic' && item.id === val.dvalue.parrent_element) {
val.dvalue.parrent_element = newId;
}
});
break;
}
});
});
return {
trees: trees,
names: names,
};
};
var a = document.querySelectorAll('.link');
Array.prototype.forEach.call(a, function(el) {
el.addEventListener('click', function() {
// что-нибудь делаем
});
});
function globalError(e) {
e.preventDefault();
window.ga('send', 'event', 'logs', 'error', JSON.stringify({
reason: e.reason,
message: e.message,
filename: e.filename,
pos: `${e.lineno}:${e.colno}`,
href: location.href
}), {
nonInteraction: true
});
}
window.addEventListener('unhandledrejection', globalError);
window.addEventListener('error', globalError);
Гугл аналитику можно заменить на любой другой сбор логовelement.onerror = function(e) {
// обрабатываем ошибку
};