refactor code insertion to avoid duplication

This commit is contained in:
David Bailey 2020-12-07 19:58:55 +00:00
parent 07b1726ac1
commit 7082899f86

View File

@ -128,7 +128,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
if (err) throw err; if (err) throw err;
fs.writeFile( fs.writeFile(
insertion_file, insertion_file,
`${data data
.replace( .replace(
/process.platform === "win32"/g, /process.platform === "win32"/g,
'process.platform === "win32" || process.platform === "linux"' 'process.platform === "win32" || process.platform === "linux"'
@ -136,22 +136,19 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
.replace( .replace(
/else \{[\s\n]+const win = createWindow_1\.createWindow\(relativeUrl\);/g, /else \{[\s\n]+const win = createWindow_1\.createWindow\(relativeUrl\);/g,
'else if (relativeUrl) { const win = createWindow_1.createWindow(relativeUrl);' 'else if (relativeUrl) { const win = createWindow_1.createWindow(relativeUrl);'
)}\n\n//notion-enhancer\nrequire('${realpath( ),
__dirname
)}/loader.js')(__filename, exports);`,
'utf8', 'utf8',
(err) => { (err) => {
if (err) throw err; if (err) throw err;
} }
); );
}); });
} else { }
fs.appendFile( fs.appendFile(
insertion_file, insertion_file,
`\n\n//notion-enhancer\nrequire('notion-enhancer/pkg/loader.js')(__filename, exports);` `\n\n//notion-enhancer\nrequire('notion-enhancer/pkg/loader.js')(__filename, exports);`
); );
} }
}
// not resolved, nothing else in apply process depends on it // not resolved, nothing else in apply process depends on it
// so it's just a "let it do its thing" // so it's just a "let it do its thing"