/* eslint-env node */
import fs from '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: [
[
'',
`
`
],
[
'',
''
],
[
'',
''
],
[
'',
''
],
[
'',
''
]
]
},
// Now that file has copied, we can replace the DOCTYPE in xdomain
{
input: 'editor/xdomain-svg-editor-es.html',
output: 'editor/xdomain-svg-editor-es.html',
replacements: [
[
'',
`
`
]
]
},
{
input: 'editor/svg-editor-es.html',
output: 'editor/svg-editor.html',
replacements: [
[
'',
`
`
],
[
'',
''
],
[
'',
''
],
[
'',
''
],
[
'',
''
]
]
},
{
input: 'editor/extensions/imagelib/openclipart-es.html',
output: 'editor/extensions/imagelib/openclipart.html',
replacements: [
[
'',
`
`
],
[
'',
''
],
[
'',
''
],
[
'',
''
]
]
},
{
input: 'editor/extensions/imagelib/index-es.html',
output: 'editor/extensions/imagelib/index.html',
replacements: [
[
'',
`
`
],
[
'',
''
],
[
'',
''
]
]
}
];
(async () => {
await filesAndReplacements.reduce(async (p, {input, output, replacements}) => {
await p;
let data;
try {
data = await fs.readFile(input, 'utf8');
} catch (err) {
console.log(`Error reading ${input} file`, err); // eslint-disable-line no-console
}
data = replacements.reduce((s, [fnd, replacement]) => {
return s.replace(fnd, replacement);
}, data);
try {
await fs.writeFile(output, data);
} catch (err) {
console.log(`Error writing file: ${err}`, err); // eslint-disable-line no-console
return;
}
console.log(`Completed file ${input} rewriting!`); // eslint-disable-line no-console
}, Promise.resolve());
console.log('Finished!'); // eslint-disable-line no-console
})();