2024-03-23 00:02:09 -07:00
#!/usr/bin/env zx
let definitions , softwarePackages
async function getSoftwareDefinitions ( ) {
try {
return YAML . parse ( fs . readFileSync ( ` ${ os . homedir ( ) } /.local/share/chezmoi/software.yml ` , 'utf8' ) )
} catch ( e ) {
throw Error ( 'Failed to load software definitions' , e )
}
}
async function writeSoftwareDefinitions ( ) {
try {
2024-03-23 00:49:17 -07:00
fs . writeFileSync ( ` ${ os . homedir ( ) } /.local/share/chezmoi/software.yml ` , YAML . stringify ( definitions ) )
2024-03-23 03:29:45 -07:00
console . log ( 'Wrote additional data to software.yml' )
2024-03-23 00:02:09 -07:00
} catch ( e ) {
throw Error ( 'Failed to write new software definitions file' , e )
}
}
async function populateMissing ( ) {
definitions = await getSoftwareDefinitions ( )
softwarePackages = definitions . softwarePackages
for ( const pkg in softwarePackages ) {
if ( softwarePackages [ pkg ] . _github ) {
2024-03-23 03:29:45 -07:00
if ( ! softwarePackages [ pkg ] . _short ) {
const sgptResponse = await $ ` sgpt "Describe ${ softwarePackages [ pkg ] . _github } . Make the description extremely short." `
console . log ( '--- START - SGPT Response for _short Acquired ---' )
console . log ( sgptResponse . stdout )
console . log ( '--- END - SGPT Response for _short Acquired ---' )
softwarePackages [ pkg ] . _short = sgptResponse . stdout
}
2024-03-23 00:02:09 -07:00
if ( ! softwarePackages [ pkg ] . _desc ) {
2024-03-23 03:29:45 -07:00
const sgptResponse = await $ ` sgpt "Describe ${ softwarePackages [ pkg ] . _github } ." `
2024-03-23 00:49:17 -07:00
console . log ( '--- START - SGPT Response for _desc Acquired ---' )
2024-03-23 00:02:09 -07:00
console . log ( sgptResponse . stdout )
2024-03-23 00:49:17 -07:00
console . log ( '--- END - SGPT Response for _desc Acquired ---' )
2024-03-23 00:02:09 -07:00
softwarePackages [ pkg ] . _desc = sgptResponse . stdout
}
if ( ! softwarePackages [ pkg ] . _name ) {
const sgptResponse = await $ ` sgpt "What is the project name of ${ softwarePackages [ pkg ] . _github } ? Only print the project name without any additional text." `
2024-03-23 00:49:17 -07:00
console . log ( '--- START - SGPT Response for _name Acquired ---' )
2024-03-23 00:02:09 -07:00
console . log ( sgptResponse . stdout )
2024-03-23 00:49:17 -07:00
console . log ( '--- END - SGPT Response for _name Acquired ---' )
2024-03-23 00:02:09 -07:00
softwarePackages [ pkg ] . _name = sgptResponse . stdout
}
2024-03-23 00:49:17 -07:00
//if (!softwarePackages[pkg]._home) {
// const sgptResponse = await $`sgpt "What is the project name of ${softwarePackages[pkg]._github}? Only print the project name without any additional text."`
// console.log('--- START - SGPT Response for _home Acquired ---')
// console.log(sgptResponse.stdout)
// console.log('--- END - SGPT Response for _home Acquired ---')
// softwarePackages[pkg]._home = sgptResponse.stdout
//}
//if (!softwarePackages[pkg]._docs) {
// const sgptResponse = await $`sgpt "Print the documentation URL for ${softwarePackages[pkg]._github}. Print only the URL without 'The documentation URL for' text."`
// console.log('--- START - SGPT Response for _docs Acquired ---')
// console.log(sgptResponse.stdout)
// console.log('--- END - SGPT Response for _docs Acquired ---')
// softwarePackages[pkg]._docs = sgptResponse.stdout
//}
2024-03-23 00:02:09 -07:00
} else if ( softwarePackages [ pkg ] . _github === false ) {
console . log ( 'No GitHub repository for ' + pkg )
} else {
2024-03-23 00:49:17 -07:00
console . log ( '***** MISSING GITHUB REPOSITORY INFORMATION FOR ' + pkg + ' *****' )
2024-03-23 00:02:09 -07:00
}
}
definitions . softwarePackages = softwarePackages
}
async function main ( ) {
await populateMissing ( )
2024-03-23 00:49:17 -07:00
await writeSoftwareDefinitions ( )
2024-03-23 00:02:09 -07:00
}
console . log ( 'Running script..' )
main ( )