Skip to content

Instantly share code, notes, and snippets.

@bantic
Created September 28, 2021 10:08
Show Gist options
  • Save bantic/66f6c77bf878abb2e3a50f70848b539e to your computer and use it in GitHub Desktop.
Save bantic/66f6c77bf878abb2e3a50f70848b539e to your computer and use it in GitHub Desktop.
zx: go back through tags to look for a specific string in a file
#!/usr/bin/env zx
$.verbose = false;
const MAX_v2_MINOR = 18;
let version = { major: 3, minor: 28, patch: 0 };
version.toString = function () {
return `v${this.major}.${this.minor}.${this.patch}`;
};
version.decrementMinor = function () {
if (this.minor > 0) {
this.minor -= 1;
} else {
if (this.major === 3) {
this.major = 2;
this.minor = MAX_v2_MINOR;
} else {
throw new Error(`Cannot decrement: ${version}`);
}
}
};
async function tagExists(version) {
try {
let result = await $`git tag -l ${version}`;
return true;
} catch (p) {
return p.exitCode === 0;
}
}
async function checkForString(string, filepath, tag) {
await $`git checkout ${tag}`;
if (!fs.existsSync(filepath)) {
throw new Error(`path ${filepath} doesn't exist`);
}
try {
await $`cat ${filepath} | grep ${string}`;
return true;
} catch (p) {
return p.exitCode === 0;
}
}
while (true) {
console.log(`Checking Version: ${version}`);
let exists = await tagExists(version);
if (!exists) {
console.log(`Skipping version ${version}`);
} else {
let str = "index(";
let filepath = "lib/broccoli/ember-app.js";
let isFound = await checkForString(str, filepath, version.toString());
if (isFound) {
console.log(`FOUND! "${str}" at ${filepath} for version ${version}`);
}
}
version.decrementMinor();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment