1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
const fs = require("fs");
const path = require("path");
const targetPath = path.join(
__dirname,
"..",
"node_modules",
"@medusajs",
"medusa",
"dist",
"services",
"payment-provider.js"
);
const notificationPath = path.join(
__dirname,
"..",
"node_modules",
"@medusajs",
"medusa",
"dist",
"services",
"notification.js"
);
const fulfillmentPath = path.join(
__dirname,
"..",
"node_modules",
"@medusajs",
"medusa",
"dist",
"services",
"fulfillment-provider.js"
);
const targets = [
{
label: "payment-provider",
filePath: targetPath,
},
{
label: "notification",
filePath: notificationPath,
},
{
label: "fulfillment-provider",
filePath: fulfillmentPath,
},
];
const replacements = [
{
before: "model.update({}, { is_installed: false })",
after:
"model.createQueryBuilder().update().set({ is_installed: false }).where('1=1').execute()",
},
];
let totalApplied = 0;
for (const target of targets) {
if (!fs.existsSync(target.filePath)) {
console.error("patch-medusa: cible introuvable:", target.filePath);
process.exit(1);
}
const original = fs.readFileSync(target.filePath, "utf8");
let patched = original;
let appliedCount = 0;
for (const { before, after } of replacements) {
if (patched.includes(before)) {
patched = patched.replace(before, after);
appliedCount += 1;
}
}
if (appliedCount === 0) {
console.error(
"patch-medusa: motif introuvable pour " + target.label + "."
);
process.exit(1);
}
fs.writeFileSync(target.filePath, patched, "utf8");
totalApplied += appliedCount;
}
console.log(
"patch-medusa: update vide remplace avec succes (count=" +
totalApplied +
")."
);
|