generated from hlxsites/aem-boilerplate-commerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postinstall.js
68 lines (61 loc) · 2.21 KB
/
postinstall.js
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
const fs = require('fs');
const path = require('path');
// Define the dropins folder
const dropinsDir = path.join('scripts', '__dropins__');
// Remove existing dropins folder
if (fs.existsSync(dropinsDir)) {
fs.rmSync(dropinsDir, { recursive: true });
}
// Create scripts/__dropins__ directory if not exists
fs.mkdirSync(dropinsDir, { recursive: true });
// Copy specified files from node_modules/@dropins to scripts/__dropins__
fs.readdirSync('node_modules/@dropins', { withFileTypes: true }).forEach((file) => {
// Skip if is not folder
if (!file.isDirectory()) {
return;
}
fs.cpSync(path.join('node_modules', '@dropins', file.name), path.join(dropinsDir, file.name), {
recursive: true,
filter: (src) => (!src.endsWith('package.json')),
});
});
fs.copyFileSync(path.resolve(__dirname, './node_modules/@adobe/magento-storefront-event-collector/dist/index.js'), path.resolve(__dirname, './scripts/commerce-events-collector.js'));
fs.copyFileSync(path.resolve(__dirname, './node_modules/@adobe/magento-storefront-events-sdk/dist/index.js'), path.resolve(__dirname, './scripts/commerce-events-sdk.js'));
function checkPackageLockForArtifactory() {
return new Promise((resolve, reject) => {
fs.readFile('package-lock.json', 'utf8', (err, data) => {
if (err) {
reject(err);
return;
}
try {
const packageLock = JSON.parse(data);
let found = false;
Object.keys(packageLock.packages).forEach((packageName) => {
const packageInfo = packageLock.packages[packageName];
if (packageInfo.resolved && packageInfo.resolved.includes('artifactory')) {
console.warn(`Warning: artifactory found in resolved property for package ${packageName}`);
found = true;
}
});
resolve(found);
} catch (error) {
reject(error);
}
});
});
}
checkPackageLockForArtifactory()
.then((found) => {
if (!found) {
console.log('🫡 Dropins installed successfully!');
process.exit(0);
} else {
console.error('🚨 Fix artifactory references before committing! 🚨');
process.exit(1);
}
})
.catch((error) => {
console.error('Error:', error);
process.exit(1);
});