This repository was archived by the owner on Feb 27, 2026. It is now read-only.
forked from hlxsites/aem-boilerplate-commerce
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpostinstall.js
More file actions
97 lines (86 loc) · 2.98 KB
/
postinstall.js
File metadata and controls
97 lines (86 loc) · 2.98 KB
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
93
94
95
96
97
/* eslint-disable import/extensions */
const fs = require('fs');
const path = require('path');
const { dependencies } = require('./package.json');
// Create a temporary storefront-search folder
const tempDir = path.join('scripts', 'temp');
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir);
}
// Copy the entire directory, excluding no files this time
fs.cpSync(path.join('scripts/__dropins__/storefront-search'), tempDir, {
recursive: true,
});
// 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 package is not in package.json dependencies / skip devDependencies
if (!dependencies[`@dropins/${file.name}`]) {
return;
}
// 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')),
});
});
// Move storefront-search back to its original location and delete the temp dir
fs.cpSync(tempDir, path.join('scripts/__dropins__/storefront-search'), {
recursive: true,
});
fs.rmdirSync(tempDir, { recursive: true });
// Other files to copy
[
{ from: '@adobe/magento-storefront-event-collector/dist/index.js', to: 'commerce-events-collector.js' },
{ from: '@adobe/magento-storefront-events-sdk/dist/index.js', to: 'commerce-events-sdk.js' },
].forEach((file) => {
fs.copyFileSync(path.resolve(__dirname, 'node_modules', file.from), path.resolve(__dirname, 'scripts', file.to));
});
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.info('✅ Drop-ins installed successfully!', '\n');
process.exit(0);
} else {
console.error('🚨 Fix artifactory references before committing! 🚨');
process.exit(1);
}
})
.catch((error) => {
console.error('Error:', error);
process.exit(1);
});