@bagelink/sdk 0.0.503 → 0.0.511
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.ts +30 -8
- package/package.json +1 -1
package/bin/index.ts
CHANGED
|
@@ -7,26 +7,48 @@ import { loadEnv } from 'vite'
|
|
|
7
7
|
import { openAPI } from '@bagelink/sdk'
|
|
8
8
|
|
|
9
9
|
const _require = createRequire(import.meta.url)
|
|
10
|
-
|
|
11
|
-
const cwd =
|
|
10
|
+
const proc = _require('process')
|
|
11
|
+
const cwd = proc.cwd()
|
|
12
12
|
const env = loadEnv('', cwd)
|
|
13
13
|
|
|
14
|
+
if (!env.VITE_BAGEL_BASE_URL) {
|
|
15
|
+
throw new Error('VITE_BAGEL_BASE_URL is not defined')
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
const baseURL = `${env.VITE_BAGEL_BASE_URL}/openapi.json`
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
const { types, code } = await openAPI(baseURL || '', 'import.meta.env.VITE_BAGEL_BASE_URL')
|
|
20
|
+
const dirFlag = proc.argv[2]
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
const withAuth = proc.argv[3] === '--auth'
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
if (dirFlag) {
|
|
25
|
+
console.log(`using passed in dir to generate sdk client: ${dirFlag}`)
|
|
26
|
+
} else {
|
|
27
|
+
console.log(`using default dir to generate sdk client: .bagelink`)
|
|
28
|
+
console.log(`to use a different dir, pass it as an argument to the command`)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const bagelinkDir = join(cwd, dirFlag || '.bagelink')
|
|
32
|
+
|
|
33
|
+
export async function loadTypes() {
|
|
34
|
+
const { types, code } = await openAPI(
|
|
35
|
+
baseURL || '',
|
|
36
|
+
'import.meta.env.VITE_BAGEL_BASE_URL'
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
if (!fs.existsSync(bagelinkDir)) fs.mkdirSync(bagelinkDir)
|
|
24
40
|
|
|
25
41
|
const typesPath = join(bagelinkDir, 'types.d.ts')
|
|
26
42
|
fs.writeFileSync(typesPath, types)
|
|
27
43
|
|
|
28
44
|
const apiPath = join(bagelinkDir, 'api.ts')
|
|
29
45
|
fs.writeFileSync(apiPath, code)
|
|
46
|
+
|
|
47
|
+
if (withAuth) {
|
|
48
|
+
const authCode = fs.readFileSync(join(cwd, 'auth.txt'), 'utf-8')
|
|
49
|
+
const authPath = join(bagelinkDir, 'auth.ts')
|
|
50
|
+
fs.writeFileSync(authPath, authCode)
|
|
51
|
+
}
|
|
30
52
|
}
|
|
31
53
|
|
|
32
54
|
loadTypes().catch(console.error)
|