Skip to content

Instantly share code, notes, and snippets.

@ahonn
Last active August 9, 2022 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahonn/c97c870b58a52b2802c48201f3284747 to your computer and use it in GitHub Desktop.
Save ahonn/c97c870b58a52b2802c48201f3284747 to your computer and use it in GitHub Desktop.
const { Project, ts } = require('ts-morph');
const path = require('path');
const filePath = path.join(process.cwd(), './simple_types.ts');
const project = new Project();
project.addExistingSourceFile(filePath);
const sourceFile = project.getSourceFile(filePath);
const enums = sourceFile.getEnums();
enums.forEach((e) => {
const members = e.getMembers();
members.forEach((member, index) => {
console.log(e.getName(), member.getName(), index);
member.setValue(index + 1);
});
});
sourceFile.saveSync();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment