Skip to content

Commit 1ce77d4

Browse files
committed
fix: reduce size to 4mb
1 parent 67b68ee commit 1ce77d4

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

tools/postman/scripts/transform-postman.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,35 @@ const transform = () => {
6767
console.log(`Adding baseUrl property ${BASE_URL}`);
6868
collection.collection.variable.push({ key: 'baseUrl', value: BASE_URL });
6969

70+
console.log('Removing redundant fields to reduce size');
71+
_.forEach(collection.collection.item, (item) => {
72+
if (item.request) {
73+
delete item.request.description; // Remove request descriptions
74+
delete item.request.auth; // Remove unused auth fields
75+
76+
if (item.request.body && item.request.body.mode === 'raw') {
77+
delete item.request.body.raw; // Remove raw fields from body
78+
}
79+
}
80+
if (item.response) {
81+
item.response.forEach((response) => {
82+
delete response.originalRequest; // Remove original request from responses
83+
delete response._postman_previewlanguage; // Remove preview language metadata
84+
delete response.header; // Remove headers from responses
85+
response.body = ''; // Clear response body
86+
});
87+
}
88+
});
89+
90+
console.log('Removing empty arrays and objects');
91+
collection = JSON.parse(
92+
JSON.stringify(collection, (key, value) => {
93+
if (Array.isArray(value) && value.length === 0) return undefined;
94+
if (value && typeof value === 'object' && Object.keys(value).length === 0) return undefined;
95+
return value;
96+
})
97+
);
98+
7099
if (TOGGLE_ADD_DOCS_LINKS) {
71100
console.log('Adding links to docs for each request');
72101

@@ -119,7 +148,7 @@ function loadJsonFile(filePath) {
119148
}
120149

121150
function saveJsonFile(filePath, json) {
122-
fs.writeFileSync(filePath, JSON.stringify(json, null, 2), 'utf8');
151+
fs.writeFileSync(filePath, JSON.stringify(json, null, 0), 'utf8');
123152
}
124153

125154
// hack

0 commit comments

Comments
 (0)