Skip to content

Instantly share code, notes, and snippets.

@kieranja
Created November 15, 2019 00:07
Show Gist options
  • Save kieranja/0be668988e565bc30bc189bad26402b0 to your computer and use it in GitHub Desktop.
Save kieranja/0be668988e565bc30bc189bad26402b0 to your computer and use it in GitHub Desktop.
i hate git conflicts
--- old.js 2019-11-15 00:02:06.000000000 +0000
+++ new.js 2019-11-15 00:05:49.000000000 +0000
@@ -225,6 +225,43 @@
}
/**
+ * It's likely ids should be kept in this scenario,
+ * as they're used further down
+ * @param obj
+ */
+function removeIds(obj) {
+ if (Array.isArray(obj)) {
+ for (let i=0;i<obj.length;i++) {
+ removeIds(obj[i]);
+ }
+ return;
+ }
+ for(let prop in obj) {
+ if (prop === 'id') {
+ delete obj[prop];
+ } else if (typeof obj[prop] === 'object') {
+ removeIds(obj[prop]);
+ }
+ }
+}
+
+async function cleanupFile(localFsPath, node) {
+ let isFileToProcess = ['meta.json', 'fields.json'].includes(node.name);
+ if (!isFileToProcess) {
+ return true;
+ }
+ await fs.readFile(localFsPath, 'utf8', (err, contents) => {
+ if (isFileToProcess) {
+ let fileContents = JSON.parse(contents);
+ delete fileContents['module_id'];
+ // why not just map this to filename+fieldname
+ removeIds(fileContents);
+ fs.writeFile(localFsPath, JSON.stringify(fileContents, null, 2));
+ }
+ });
+}
+
+/**
* @private
* @async
* @param {FileMapperInputArguments} input
@@ -281,6 +318,7 @@
});
writeStream.on('close', async () => {
await writeUtimes(input, filepath, node);
+ await cleanupFile(filepath, node);
logger.log('Wrote file "%s"', filepath);
resolve(node);
});
@kieranja
Copy link
Author

depends if hubspot-cli is install locally/globally - but for locally it's stored node_modules/@hubspot/cms-lib/fileMapper.js, remotely on osx i think it's /usr/local/lib/node_modules/@hubspot/cms-lib/fileMapper.js

@dennisedson
Copy link

Well played ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment