Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose a file with just the latest #71

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading