flexi-bot/tasks/utils.js

66 lines
1.5 KiB
JavaScript

var path = require('path');
const fg = require('fast-glob');
const read = require('@plastichub/fs/read').sync;
const write = require('@plastichub/fs/write').sync;
const exists = require('@plastichub/fs/exists').sync;
const forward_slash = (path) => {
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
const hasNonAscii = /[^\u0000-\u0080]+/.test(path); // eslint-disable-line no-control-regex
if (isExtendedLengthPath || hasNonAscii) {
return path;
}
return path.replace(/\\/g, '/');
};
const files = (dir, glob) => fg.sync(glob, {
dot: true,
cwd: dir,
absolute: true
});
const MainAssembly = (dir) => {
const mains = files(dir, '**/cad/**/Global*.+(SLDASM)');
return mains[0];
}
const file_path_with_ext = (file, ext) => {
const parts = path.parse(file);
return path.join(parts.dir, parts.name + '.' + ext);
}
function unique_by(arr, key) {
return [...new Map(arr.map(item => [item[key], item])).values()]
}
const onProduct = (src, dst, content) => {
debugger;
const $ = cheerio.load(content, {
xmlMode: true
});
$('a').each(function () {
$(this).attr("style", "color:#4C74B9");
})
$('table').each(function () {
$(this).attr("style", "display:table;width:auto;margin-left:auto;margin-right:auto");
})
return $.html();
}
module.exports = {
MainAssembly,
file_path_with_ext,
unique_by,
files,
forward_slash,
read,
write,
exists,
onProduct
}