/* eslint-env node */
const fs = require('promise-fs');
const filesAndReplacements = [
{
input: 'editor/svg-editor-es.html',
output: 'editor/xdomain-svg-editor-es.html',
replacements: [
[
'',
``
]
]
},
{
input: 'editor/xdomain-svg-editor-es.html',
output: 'editor/xdomain-svg-editor.html',
replacements: [
[
'',
`
`
],
[
'',
''
],
[
'',
''
],
[
'',
''
]
]
},
{
input: 'editor/svg-editor-es.html',
output: 'editor/svg-editor.html',
replacements: [
[
'',
`
`
],
[
'',
''
],
[
'',
''
],
[
'',
''
]
]
},
{
input: 'editor/extensions/imagelib/index-es.html',
output: 'editor/extensions/imagelib/index.html',
replacements: [
[
'',
`
`
],
[
'',
''
]
]
}
];
filesAndReplacements.reduce((p, {input, output, replacements}) => {
return p.then(async () => {
let data;
try {
data = await fs.readFile(input, 'utf8');
} catch (err) {
console.log(`Error reading ${input} file`, err);
}
data = replacements.reduce((s, [find, replacement]) => {
return s.replace(find, replacement);
}, data);
try {
await fs.writeFile(output, data);
} catch (err) {
console.log(`Error writing file: ${err}`, err);
return;
}
console.log(`Completed file ${input} rewriting!`);
});
}, Promise.resolve()).then(() => {
console.log('Finished!');
});