Skip to content

Instantly share code, notes, and snippets.

@ranyitz
Last active June 25, 2020 15:15
Show Gist options
  • Save ranyitz/fdd9e4df1decb3f4090c95e06a697fa4 to your computer and use it in GitHub Desktop.
Save ranyitz/fdd9e4df1decb3f4090c95e06a697fa4 to your computer and use it in GitHub Desktop.
Update owner in all specs
#!/usr/bin/env node
const fs = require('fs');
const os = require('os');
const path = require('path');
function writeJson(fileName, object) {
fs.writeFileSync(
fileName,
JSON.stringify(object, null, 2).replace(/\n/g, os.EOL) + os.EOL,
);
}
const specsDir = path.resolve('petri-specs');
const specs = fs.readdirSync(specsDir);
const ownershipTag = process.argv[2];
if(!ownershipTag) {
throw new Error('please insert an ownership tag as the a cli argument');
}
console.log(`Changing all of the owners to this ownership tag: "${ownershipTag}"`);
specs.forEach(specName => {
const scopePath = path.join(specsDir, specName);
const scopeContent = JSON.parse(fs.readFileSync(scopePath, 'utf-8'));
Object.keys(scopeContent).forEach(key => {
scopeContent[key].owner = ownershipTag;
});
writeJson(scopePath, scopeContent);
});
console.log();
console.log('The following specs was modified succesfully:');
specs.forEach(spec => console.log(spec));
{
"name": "update-specs-owner",
"version": "1.0.0",
"bin": "./add-owner-to-specs.js"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment