Skip to content

Commit

Permalink
chore: [wip] diffing types
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderblue committed Jun 4, 2024
1 parent 0124062 commit 7ef216d
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions scripts/diff-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// module.exports = async ({
// core
// }) => {

const fs = require('fs');
const yaml = require('yaml');

let tutoneConfig = null
let schema = null

try {
const tutoneConfigFile = fs.readFileSync('.tutone.yml', 'utf8')
tutoneConfig = yaml.parse(tutoneConfigFile)

const schemaFileLatest = fs.readFileSync('schema.json', 'utf8');
schema = JSON.parse(schemaFileLatest);
} catch(err) {
console.error(err);
}

const package = tutoneConfig.packages.find(x => x.name === 'entities');
const packageTypesByName = package.types.filter(t => !t.skip_type_create && t.name.includes("Entity")).map(t => t.name);

const schemaTypes = schema.types.filter(t => t.name.endsWith("Entity") || t.name.endsWith("EntityOutline")).map(t => t.name)

const typesDiff = schemaTypes.filter(x => {
console.log("schema type:", x);
console.log("pkg type: ", packageTypesByName.includes(x));

return !packageTypesByName.includes(x)
});

// console.log('packageTypes:', JSON.stringify(packageTypesByName, null, 2));
// console.log('schemaTypes: ', JSON.stringify(schemaTypes, null, 2));
// console.log('typesDiff: ', typesDiff);
// console.log('typesDiff: ', typesDiff.length);

function getPackageTypesFromTypesFile() {
fs.readFile('/Users/sblue/dev/newrelic-client-go/pkg/entities/types.go', 'utf8', (err, text) => {
if (err) {
console.error(err);
return;
}

// console.log(data);

// Define the regex pattern
// const pattern = /func\s+(\*?\w+)\s+\(\w+\s+\*\w+\)\s+\w+\s+\{\}/g;
// const regex = /func\s+(\*?\w+)\s+\(\w+\s+\*\w+\)\s+\w+\s+\{\}/g;
// const regex = /func\s+([\s\S]*?)\s*struct\s*\{/g;

// Find all matches
const regex = /type\s+(\S+)\s+struct\s*{/g;

// Find all matches
let match;
while ((match = regex.exec(text)) !== null) {
console.log(match[1]);
}
// Print the matches
// console.log(matches);
});
}

getPackageTypesFromTypesFile()

0 comments on commit 7ef216d

Please sign in to comment.