This repository has been archived on 2021-12-11. You can view files and clone it, but cannot push or open issues or pull requests.
magento-ts-client/tools/clean_magento.js
2021-07-24 13:30:56 +02:00

43 lines
1.2 KiB
JavaScript

const read = require('@plastichub/fs/read').sync;
const path = require('path');
const write = require('@plastichub/fs/write').sync;
const content = read('./shop_errors.txt').split('\n');
let api = read('./src/shop/api.ts');
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream('shop_errors.txt')
});
var types = {};
lineReader.on('line', function (line) {
// create a map of the unresolved types
if (line.indexOf('src/shop/api.ts')) {
const type = line.split("'")[1];
if (type) {
if (!types[type]) {
types[type] = false;
}
}
}
});
String.prototype.replaceAll = function (search, replacement) {
var target = this;
return target.split(search).join(replacement);
};
lineReader.on('close', function (e) {
for (var t in types) {
t = t.replace(/[^\x00-\x7F]/g, ""); // non ascii
t = t.replace(/[\u0000-\u001F\u007F-\u009F]/g, "");//typescript term characters
t = t.replace(/[\u{0080}-\u{FFFF}]/gu,"");//terminal plugin special characters
api = api.replaceAll(t, 'any');
}
write('./src/shop/api.ts', api);
});