Skip to content

feat(chore): export alias for bc #2048

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

Merged
merged 4 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 8 additions & 8 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
"type": "module",
"exports": {
".": {
"types": "./dist/index.gen.d.ts",
"import": "./dist/index.gen.js",
"require": "./dist/index.gen.cjs",
"default": "./dist/index.gen.js"
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
},
"./*": {
"types": "./dist/*/index.gen.d.ts",
"import": "./dist/*/index.gen.js",
"require": "./dist/*/index.gen.cjs",
"default": "./dist/*/index.gen.js"
"types": "./dist/*/index.d.ts",
"import": "./dist/*/index.js",
"require": "./dist/*/index.cjs",
"default": "./dist/*/index.js"
}
},
"repository": {
Expand Down
240 changes: 240 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
/* Auto-generated. Do not edit manually. */

import { Accountv3 } from '@scaleway/sdk-account'
import { Applesiliconv1alpha1 } from '@scaleway/sdk-applesilicon'
import { AuditTrailv1alpha1 } from '@scaleway/sdk-audit-trail'
import { Baremetalv1 , Baremetalv3 } from '@scaleway/sdk-baremetal'
import { Billingv2beta1 } from '@scaleway/sdk-billing'
import { Blockv1 , Blockv1alpha1 } from '@scaleway/sdk-block'
import { Cockpitv1 } from '@scaleway/sdk-cockpit'
import { Containerv1beta1 } from '@scaleway/sdk-container'
import { Dediboxv1 } from '@scaleway/sdk-dedibox'
import { Domainv2beta1 } from '@scaleway/sdk-domain'
import { EdgeServicesv1beta1 } from '@scaleway/sdk-edge-services'
import { Filev1alpha1 } from '@scaleway/sdk-file'
import { Flexibleipv1alpha1 } from '@scaleway/sdk-flexibleip'
import { Functionv1beta1 } from '@scaleway/sdk-function'
import { Iamv1alpha1 } from '@scaleway/sdk-iam'
import { Inferencev1 , Inferencev1beta1 } from '@scaleway/sdk-inference'
import { Instancev1 } from '@scaleway/sdk-instance'
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 { KeyManagerv1alpha1 } from '@scaleway/sdk-key-manager'
import { Lbv1 } from '@scaleway/sdk-lb'
import { Marketplacev2 } from '@scaleway/sdk-marketplace'
import { Mnqv1beta1 } from '@scaleway/sdk-mnq'
import { Mongodbv1alpha1 } from '@scaleway/sdk-mongodb'
import { ProductCatalogv2alpha1 } from '@scaleway/sdk-product-catalog'
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 { Secretv1beta1 } from '@scaleway/sdk-secret'
import { ServerlessSqldbv1alpha1 } from '@scaleway/sdk-serverless-sqldb'
import { Temv1alpha1 } from '@scaleway/sdk-tem'
import { Testv1 } from '@scaleway/sdk-test'
import { Vpcv2 } from '@scaleway/sdk-vpc'
import { Vpcgwv1 , Vpcgwv2 } from '@scaleway/sdk-vpcgw'
import { Webhostingv1 } from '@scaleway/sdk-webhosting'

export { Accountv3 }
export const Account = {
v3: Accountv3,
}

export { Applesiliconv1alpha1 }
export const Applesilicon = {
v1alpha1: Applesiliconv1alpha1,
}

export { AuditTrailv1alpha1 }
export const AuditTrail = {
v1alpha1: AuditTrailv1alpha1,
}

export { Baremetalv1, Baremetalv3 }
export const Baremetal = {
v1: Baremetalv1,
v3: Baremetalv3,
}

export { Billingv2beta1 }
export const Billing = {
v2beta1: Billingv2beta1,
}

export { Blockv1, Blockv1alpha1 }
export const Block = {
v1: Blockv1,
v1alpha1: Blockv1alpha1,
}

export { Cockpitv1 }
export const Cockpit = {
v1: Cockpitv1,
}

export { Containerv1beta1 }
export const Container = {
v1beta1: Containerv1beta1,
}

export { Dediboxv1 }
export const Dedibox = {
v1: Dediboxv1,
}

export { Domainv2beta1 }
export const Domain = {
v2beta1: Domainv2beta1,
}

export { EdgeServicesv1beta1 }
export const EdgeServices = {
v1beta1: EdgeServicesv1beta1,
}

export { Filev1alpha1 }
export const File = {
v1alpha1: Filev1alpha1,
}

export { Flexibleipv1alpha1 }
export const Flexibleip = {
v1alpha1: Flexibleipv1alpha1,
}

export { Functionv1beta1 }
export const Function = {
v1beta1: Functionv1beta1,
}

export { Iamv1alpha1 }
export const Iam = {
v1alpha1: Iamv1alpha1,
}

export { Inferencev1, Inferencev1beta1 }
export const Inference = {
v1: Inferencev1,
v1beta1: Inferencev1beta1,
}

export { Instancev1 }
export const Instance = {
v1: Instancev1,
}

export { Interlinkv1beta1 }
export const Interlink = {
v1beta1: Interlinkv1beta1,
}

export { Iotv1 }
export const Iot = {
v1: Iotv1,
}

export { Ipamv1 }
export const Ipam = {
v1: Ipamv1,
}

export { Jobsv1alpha1 }
export const Jobs = {
v1alpha1: Jobsv1alpha1,
}

export { K8sv1 }
export const K8s = {
v1: K8sv1,
}

export { KeyManagerv1alpha1 }
export const KeyManager = {
v1alpha1: KeyManagerv1alpha1,
}

export { Lbv1 }
export const Lb = {
v1: Lbv1,
}

export { Marketplacev2 }
export const Marketplace = {
v2: Marketplacev2,
}

export { Mnqv1beta1 }
export const Mnq = {
v1beta1: Mnqv1beta1,
}

export { Mongodbv1alpha1 }
export const Mongodb = {
v1alpha1: Mongodbv1alpha1,
}

export { ProductCatalogv2alpha1 }
export const ProductCatalog = {
v2alpha1: ProductCatalogv2alpha1,
}

export { Qaasv1alpha1 }
export const Qaas = {
v1alpha1: Qaasv1alpha1,
}

export { Rdbv1 }
export const Rdb = {
v1: Rdbv1,
}

export { Redisv1 }
export const Redis = {
v1: Redisv1,
}

export { Registryv1 }
export const Registry = {
v1: Registryv1,
}

export { Secretv1beta1 }
export const Secret = {
v1beta1: Secretv1beta1,
}

export { ServerlessSqldbv1alpha1 }
export const ServerlessSqldb = {
v1alpha1: ServerlessSqldbv1alpha1,
}

export { Temv1alpha1 }
export const Tem = {
v1alpha1: Temv1alpha1,
}

export { Testv1 }
export const Test = {
v1: Testv1,
}

export { Vpcv2 }
export const Vpc = {
v2: Vpcv2,
}

export { Vpcgwv1, Vpcgwv2 }
export const Vpcgw = {
v1: Vpcgwv1,
v2: Vpcgwv2,
}

export { Webhostingv1 }
export const Webhosting = {
v1: Webhostingv1,
}
2 changes: 1 addition & 1 deletion packages/sdk/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { defaultConfig } from '../../vite.config'
export default mergeConfig(defineConfig(defaultConfig), {
build: {
lib: {
entry: 'src/index.gen.ts',
entry: 'src/index.ts',
},
},
})
61 changes: 61 additions & 0 deletions scripts/generateAlias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { readdirSync, statSync, writeFileSync } from 'fs'
import { join } from 'path'

const GENERATED_PATH = 'packages_generated'
const OUTPUT_PATH = 'packages/sdk/src/index.ts'

const toPascal = (s: string) =>
s
.split(/[_-]/)
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
.join('')

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

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

return statSync(fullPath).isDirectory()
})

let output = `/* Auto-generated. Do not edit manually. */\n\n`

for (const service of services) {
const slug = toSlug(service) // ex. "audit-trail"
const pascal = toPascal(service) // ex. "AuditTrail"
const srcPath = join(GENERATED_PATH, service, 'src')

let versions: string[] = []
try {
versions = readdirSync(srcPath).filter(vFolder => {
const vPath = join(srcPath, vFolder)

return statSync(vPath).isDirectory() && /^v[0-9a-z]+$/i.test(vFolder)
})
} catch {
console.warn(`⚠️ Pas de dossier 'src' pour ${service}, ignoré.`)
// eslint-disable-next-line no-continue
continue
Copy link
Contributor

@philibea philibea Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should throw an error instead

}
// eslint-disable-next-line no-continue
if (versions.length === 0) continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not usefull ?


const imports: string[] = []
const mappings: string[] = []

for (const version of versions) {
const importName = `${pascal}${version}` // ex. AuditTrailv1alpha1
imports.push(`import { ${importName} } from '@scaleway/sdk-${slug}'`)
mappings.push(` ${version}: ${importName},`)
}

output += `${imports.join('\n')}\n\n`
const importedNames = imports
.map(line => /{ (.*?) }/.exec(line)![1])
.join(', ')
output += `export { ${importedNames} }\n`
output += `export const ${pascal} = {\n${mappings.join('\n')}\n}\n\n`
}

writeFileSync(OUTPUT_PATH, output)
console.log(`✅ Fichier généré : ${OUTPUT_PATH}`)
Loading