Skip to content

Commit

Permalink
feat: expose a file with just the latest (#71)
Browse files Browse the repository at this point in the history
* feat: expose a file with just the latest

* chore: remove duplication

* chore: regenerate
  • Loading branch information
anxolin authored Jan 2, 2025
1 parent ccbd140 commit c6e63b5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/generatedTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as v1_1_0 from './v1.1.0'
import * as v1_2_0 from './v1.2.0'
import * as v1_3_0 from './v1.3.0'

export * as latest from './v1.3.0'
export * from './latest'

export const LATEST_APP_DATA_VERSION = '1.3.0'
export const LATEST_QUOTE_METADATA_VERSION = '1.1.0'
Expand Down
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'
32 changes: 28 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 @@ -68,7 +76,7 @@ async function compile(): Promise<void> {
const latestReplacedOrderVersion = await getLatestMetadataDocVersion('replacedOrder')

const additionalTypesExport = `
export * as latest from './${latest}'
export * from './latest'
export const LATEST_APP_DATA_VERSION = '${extractSemver(latest)}'
export const LATEST_QUOTE_METADATA_VERSION = '${extractSemver(latestQuoteVersion)}'
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(`export * as latest from './${latest}'\n`)
}

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

compile().then(() => console.log('Done'))
Expand All @@ -104,7 +119,16 @@ function extractSemver(name: string): string {
}

async function getLatestMetadataDocVersion(
metadataDocName: 'quote' | 'referrer' | 'orderClass' | 'utm' | 'hooks' | 'signer' | 'widget' | 'partnerFee' | 'replacedOrder'
metadataDocName:
| 'quote'
| 'referrer'
| 'orderClass'
| 'utm'
| 'hooks'
| 'signer'
| 'widget'
| 'partnerFee'
| 'replacedOrder'
): Promise<string> {
const metadataPath = path.join(SCHEMAS_SRC_PATH, metadataDocName)
const versions = await fs.promises.readdir(metadataPath)
Expand Down

0 comments on commit c6e63b5

Please sign in to comment.