mirror of
https://github.com/frappe/books.git
synced 2025-02-10 07:59:03 +00:00
Merge pull request #157 from 18alantom/update-patchrun
refactor: update patch run for patches.json
This commit is contained in:
commit
187446e3aa
@ -1,40 +1,26 @@
|
|||||||
const frappe = require('frappejs');
|
const frappe = require('frappejs');
|
||||||
|
|
||||||
module.exports = async function runPatches(allPatches, patchOrder) {
|
module.exports = async function runPatches(patchList) {
|
||||||
let executedPatchRuns = [];
|
const patchesAlreadyRun = (
|
||||||
try {
|
await frappe.db.knex('PatchRun').select('name')
|
||||||
executedPatchRuns = (
|
).map(({ name }) => name);
|
||||||
await frappe.db.getAll({ doctype: 'PatchRun', fields: ['name'] })
|
|
||||||
).map((d) => d.name);
|
|
||||||
} catch (error) {}
|
|
||||||
|
|
||||||
let patchRunOrder = patchOrder
|
for (let patch of patchList) {
|
||||||
.map((text) => {
|
if (patchesAlreadyRun.includes(patch.patchName)) {
|
||||||
let [patch] = text.split(' ');
|
continue;
|
||||||
if (text && patch) {
|
|
||||||
return {
|
|
||||||
fileName: text,
|
|
||||||
method: allPatches[patch],
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.filter(Boolean);
|
|
||||||
|
|
||||||
for (let patch of patchRunOrder) {
|
|
||||||
if (!executedPatchRuns.includes(patch.fileName)) {
|
|
||||||
await runPatch(patch);
|
await runPatch(patch);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async function runPatch(patch) {
|
async function runPatch({ patchName, patchFunction }) {
|
||||||
try {
|
try {
|
||||||
await patch.method();
|
await patchFunction();
|
||||||
let patchRun = frappe.getNewDoc('PatchRun');
|
const patchRun = frappe.getNewDoc('PatchRun');
|
||||||
patchRun.name = patch.fileName;
|
patchRun.name = patchName;
|
||||||
await patchRun.insert();
|
await patchRun.insert();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(`could not run ${patchName}`, error);
|
||||||
console.log('Could not run patch', patch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user