2021-12-27 20:46:28 +02:00
|
|
|
const { copy, mkdirp, remove } = require('fs-extra');
|
2020-02-08 02:15:56 +02:00
|
|
|
|
2022-01-02 19:36:58 +02:00
|
|
|
const msleep = async (ms) => {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
resolve();
|
|
|
|
}, ms);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Same as copyApplicationAssets - probably both scripts should be merged in
|
|
|
|
// one.
|
|
|
|
const withRetry = async (fn) => {
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
try {
|
|
|
|
await fn();
|
|
|
|
return;
|
|
|
|
} catch (error) {
|
|
|
|
console.warn(`withRetry: Failed calling function - will retry (${i})`, error);
|
|
|
|
await msleep(1000 + i * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error('withRetry: Could not run function after multiple attempts');
|
|
|
|
};
|
|
|
|
|
2020-02-08 02:15:56 +02:00
|
|
|
async function main() {
|
2020-03-10 01:24:57 +02:00
|
|
|
const rootDir = `${__dirname}/..`;
|
2021-12-20 17:08:43 +02:00
|
|
|
|
2020-11-05 18:58:23 +02:00
|
|
|
const sourceDir = `${rootDir}/../../packages/renderer/assets`;
|
2020-03-10 01:24:57 +02:00
|
|
|
const destDirs = [
|
|
|
|
`${rootDir}/gui/note-viewer/pluginAssets`,
|
|
|
|
`${rootDir}/pluginAssets`,
|
|
|
|
];
|
|
|
|
|
2021-12-27 20:46:28 +02:00
|
|
|
for (const action of ['delete', 'copy']) {
|
|
|
|
for (const destDir of destDirs) {
|
|
|
|
if (action === 'delete') {
|
2022-01-02 19:36:58 +02:00
|
|
|
await withRetry(() => remove(destDir));
|
2021-12-27 20:46:28 +02:00
|
|
|
} else {
|
|
|
|
console.info(`Copying to ${destDir}`);
|
2022-01-02 19:36:58 +02:00
|
|
|
await withRetry(() => mkdirp(destDir));
|
|
|
|
await withRetry(() => copy(sourceDir, destDir, { overwrite: true }));
|
2021-12-27 20:46:28 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-10 01:24:57 +02:00
|
|
|
}
|
2020-02-08 02:15:56 +02:00
|
|
|
}
|
|
|
|
|
2020-02-21 00:59:18 +02:00
|
|
|
module.exports = main;
|