/* eslint-env node */
import fs from 'promise-fs';
const filesAndReplacements = [
{
input: 'src/editor/svg-editor-es.html',
output: 'src/editor/xdomain-svg-editor-es.html',
replacements: [
[
'',
''
]
]
},
{
input: 'src/editor/xdomain-svg-editor-es.html',
output: 'src/editor/xdomain-svg-editor.html',
replacements: [
[
'',
`
`
],
[
'',
''
],
[
'',
''
],
[
'',
''
],
[
'',
''
]
]
},
// Now that file has copied, we can replace the DOCTYPE in xdomain
{
input: 'src/editor/xdomain-svg-editor-es.html',
output: 'src/editor/xdomain-svg-editor-es.html',
replacements: [
[
'',
`
`
]
]
},
{
input: 'src/editor/svg-editor-es.html',
output: 'src/editor/svg-editor.html',
replacements: [
[
'',
`
`
],
[
'',
''
],
[
'',
''
],
[
'',
''
],
[
'',
''
]
]
},
{
input: 'src/editor/extensions/imagelib/openclipart-es.html',
output: 'src/editor/extensions/imagelib/openclipart.html',
replacements: [
[
'',
`
`
],
[
'',
''
],
[
'',
''
],
[
'',
''
]
]
},
{
input: 'src/editor/extensions/imagelib/index-es.html',
output: 'src/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
})();