From 7ef216d90748a667e824e5a2552037053842bd48 Mon Sep 17 00:00:00 2001 From: Sander Blue Date: Tue, 4 Jun 2024 16:17:32 -0500 Subject: [PATCH] chore: [wip] diffing types --- scripts/diff-types.js | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 scripts/diff-types.js diff --git a/scripts/diff-types.js b/scripts/diff-types.js new file mode 100755 index 00000000..93b3a50c --- /dev/null +++ b/scripts/diff-types.js @@ -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()