Skip to content
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
12 changes: 6 additions & 6 deletions packages/sdk/src/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Interlinkv1beta1 } from '@scaleway/sdk-interlink'
import { Iotv1 } from '@scaleway/sdk-iot'
import { Ipamv1 } from '@scaleway/sdk-ipam'
import { Jobsv1alpha1 } from '@scaleway/sdk-jobs'
import { K8sv1 } from '@scaleway/sdk-k8s'
import { K8Sv1 } from '@scaleway/sdk-k8s'
import { KeyManagerv1alpha1 } from '@scaleway/sdk-key-manager'
import { Lbv1 } from '@scaleway/sdk-lb'
import { Marketplacev2 } from '@scaleway/sdk-marketplace'
Expand All @@ -37,7 +37,7 @@ import { Qaasv1alpha1 } from '@scaleway/sdk-qaas'
import { Rdbv1 } from '@scaleway/sdk-rdb'
import { Redisv1 } from '@scaleway/sdk-redis'
import { Registryv1 } from '@scaleway/sdk-registry'
import { S2sVpnv1alpha1 } from '@scaleway/sdk-s2s-vpn'
import { S2SVpnv1alpha1 } from '@scaleway/sdk-s2s-vpn'
import { Secretv1beta1 } from '@scaleway/sdk-secret'
import { ServerlessSqldbv1alpha1 } from '@scaleway/sdk-serverless-sqldb'
import { Temv1alpha1 } from '@scaleway/sdk-tem'
Expand Down Expand Up @@ -246,9 +246,9 @@ export const Jobs = {
/**
* @deprecated Direct version exports are deprecated. Use the 'K8s' namespace instead (e.g., K8s.v1).
*/
export { K8sv1 }
export { K8Sv1 }
export const K8s = {
v1: K8sv1,
v1: K8Sv1,
}

/**
Expand Down Expand Up @@ -335,9 +335,9 @@ export const Registry = {
/**
* @deprecated Direct version exports are deprecated. Use the 'S2sVpn' namespace instead (e.g., S2sVpn.v1).
*/
export { S2sVpnv1alpha1 }
export { S2SVpnv1alpha1 }
export const S2sVpn = {
v1alpha1: S2sVpnv1alpha1,
v1alpha1: S2SVpnv1alpha1,
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages_generated/k8s/src/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* PLEASE DO NOT EDIT HERE
*/

export * as K8sv1 from './v1/index'
export * as K8Sv1 from './v1/index'
2 changes: 1 addition & 1 deletion packages_generated/s2s_vpn/src/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* PLEASE DO NOT EDIT HERE
*/

export * as S2sVpnv1alpha1 from './v1alpha1/index.gen'
export * as S2SVpnv1alpha1 from './v1alpha1/index.gen'
1 change: 1 addition & 0 deletions packages_generated/webhosting/src/v1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ const unmarshalOffer = (data: unknown): Offer => {
options: unmarshalArrayOfObject(data.options, unmarshalOfferOption),
price: data.price ? unmarshalMoney(data.price) : undefined,
quotaWarning: data.quota_warning,
region: data.region,
} as Offer
}

Expand Down
4 changes: 4 additions & 0 deletions packages_generated/webhosting/src/v1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ export interface Offer {
* Defines a warning if the maximum value for an option in the offer is exceeded.
*/
quotaWarning: OfferOptionWarning
/**
* Region where the offer is hosted.
*/
region: ScwRegion
}

export interface Platform {
Expand Down
62 changes: 47 additions & 15 deletions scripts/generateAlias.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { appendFileSync, readdirSync, statSync, writeFileSync } from 'node:fs'
import {
appendFileSync,
readdirSync,
readFileSync,
statSync,
writeFileSync,
} from 'node:fs'
import { join } from 'node:path'

const GENERATED_PATH = 'packages_generated'
Expand All @@ -12,6 +18,28 @@ const toPascal = (s: string) =>

const toSlug = (s: string) => s.replace(/_/g, '-')

/**
* Extract real export names from package's index.gen.ts
* This ensures we use the exact same names as exported by the package
*/
const getExportsFromPackage = (packagePath: string): string[] => {
const indexPath = join(packagePath, 'src', 'index.gen.ts')
try {
const content = readFileSync(indexPath, 'utf8')
const exportPattern = /export \* as (\w+) from/g
const exports: string[] = []
let match

while ((match = exportPattern.exec(content)) !== null) {
exports.push(match[1])
}

return exports
} catch (err: unknown) {
throw new Error(`Error reading exports from ${indexPath}: ${err.message}`)
}
}

const services = readdirSync(GENERATED_PATH).filter(folder => {
const fullPath = join(GENERATED_PATH, folder)

Expand All @@ -29,34 +57,38 @@ let importsOutput = ''
for (const service of services) {
const slug = toSlug(service)
const pascal = toPascal(service)
const srcPath = join(GENERATED_PATH, service, 'src')
const packagePath = join(GENERATED_PATH, service)

let versions: string[] = []
// Get real exports from the package
let exportedNames: string[] = []
try {
versions = readdirSync(srcPath).filter(vFolder => {
const vPath = join(srcPath, vFolder)

return statSync(vPath).isDirectory() && /^v[0-9a-z]+$/i.test(vFolder)
})
exportedNames = getExportsFromPackage(packagePath)
} catch (err: unknown) {
throw new Error(
`Error: missing or unreadable 'src' folder for package '${service}': ${err.message}`,
`Error getting exports for package '${service}': ${err.message}`,
)
}

writeFileSync(OUTPUT_PATH, AUTO_GENERATE_MESSAGE)

if (versions.length > 0) {
if (exportedNames.length > 0) {
const imports: string[] = []
const versionsImport: string[] = []
const mappings: string[] = []

for (const version of versions) {
const importName = `${pascal}${version}`
versionsImport.push(`${importName}`)
mappings.push(` ${version}: ${importName},`)
for (const exportName of exportedNames) {
// Extract version from export name (e.g., K8Sv1 -> v1, S2SVpnv1alpha1 -> v1alpha1)
// Version must start with lowercase 'v' followed by digits
const versionMatch = exportName.match(/(v\d+[a-z]*\d*)$/)
if (versionMatch) {
const version = versionMatch[1]
versionsImport.push(exportName)
mappings.push(` ${version}: ${exportName},`)
}
}
imports.push(`import { ${versionsImport} } from '@scaleway/sdk-${slug}'`)
imports.push(
`import { ${versionsImport.join(', ')} } from '@scaleway/sdk-${slug}'`,
)

importsOutput += `${imports.join('\n')}\n`
const importedNames = imports
Expand Down
Loading