Skip to content

Commit

Permalink
feat: expose a file with just the latest
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin committed Jan 2, 2025
1 parent ccbd140 commit 1489a0f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/generatedTypes/latest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// generated file, do not edit manually

export * as latest from './v1.3.0'
23 changes: 19 additions & 4 deletions src/scripts/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ async function compile(): Promise<void> {
const typesIndexPath = path.join(TYPES_DEST_PATH, 'index.ts')
console.info(`Creating ${typesIndexPath} file`)
const typesIndexFile = await fs.promises.open(typesIndexPath, 'w')
await typesIndexFile.write(`// generated file, do not edit manually\n\n`)

// Generates out file for types/latest.ts
const latestIndexPath = path.join(TYPES_DEST_PATH, 'latest.ts')
const latestIndexFile = await fs.promises.open(latestIndexPath, 'w')

const generatedFiles = [typesIndexFile, latestIndexFile]
await generatedFiles.forEach(async (file) => {
file.write(`// generated file, do not edit manually\n\n`)
})

// Lists all schemas
const schemas = await fs.promises.readdir(SCHEMAS_SRC_PATH, { withFileTypes: true })
Expand Down Expand Up @@ -67,9 +75,9 @@ async function compile(): Promise<void> {
const latestPartnerFeeVersion = await getLatestMetadataDocVersion('partnerFee')
const latestReplacedOrderVersion = await getLatestMetadataDocVersion('replacedOrder')

const exportLatest = `export * as latest from './${latest}'\n`
const additionalTypesExport = `
export * as latest from './${latest}'
${exportLatest}
export const LATEST_APP_DATA_VERSION = '${extractSemver(latest)}'
export const LATEST_QUOTE_METADATA_VERSION = '${extractSemver(latestQuoteVersion)}'
export const LATEST_REFERRER_METADATA_VERSION = '${extractSemver(latestReferrerVersion)}'
Expand All @@ -87,10 +95,17 @@ export type AnyAppDataDocVersion = ${allVersions}
export {${versions.map((version) => `\n ${versionNameToExport(version)}`)}
}
`
// Writes exports to types/index.ts
await typesIndexFile.write(additionalTypesExport)

// Writes exports to types/latest.ts
await latestIndexFile.write(exportLatest)
}

await typesIndexFile.close()
// Closes all files
for (const file of generatedFiles) {
await file.close()
}
}

compile().then(() => console.log('Done'))
Expand Down

0 comments on commit 1489a0f

Please sign in to comment.