@bagelink/sdk 0.0.633 → 0.0.635

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.
Files changed (2) hide show
  1. package/bin/index.ts +54 -32
  2. package/package.json +1 -1
package/bin/index.ts CHANGED
@@ -9,9 +9,9 @@ import { loadEnv } from 'vite'
9
9
  import { openAPI } from '@bagelink/sdk'
10
10
 
11
11
  const _require = createRequire(import.meta.url)
12
- const proc = _require('process')
12
+ const proc = _require('process') as typeof import('process')
13
13
 
14
- const cwd: string = proc.cwd()
14
+ const cwd = proc.cwd()
15
15
  const env = loadEnv('', cwd)
16
16
 
17
17
  if (!env.VITE_BAGEL_BASE_URL) {
@@ -33,43 +33,65 @@ if (dirFlag !== undefined) {
33
33
 
34
34
  const bagelinkDir = join(cwd, dirFlag ?? '.bagelink')
35
35
 
36
- async function formatCode(code: string) {
36
+ async function formatAndWriteCode(outPath: string, code: string) {
37
37
  const prettyCode = await prettier.format(code, { parser: 'typescript' })
38
+ fs.writeFileSync(outPath, prettyCode)
39
+ }
40
+
41
+ async function runEsLintOnDir(dir: string) {
42
+ // ! only run if eslint.config.js exists
43
+ if (!fs.existsSync(join(cwd, 'eslint.config.js'))) {
44
+ console.log('no eslint.config.js found, skipping eslint')
45
+ return
46
+ }
38
47
 
39
- const eslint = new ESLint({ fix: true, overrideConfigFile: join(cwd, 'eslint.config.js') })
40
- const results = await eslint.lintText(prettyCode)
41
- const formatter = await eslint.loadFormatter('stylish')
42
- const rulesMeta = eslint.getRulesMetaForResults(results)
43
- const resultText = await formatter.format(results, { cwd, rulesMeta })
48
+ const eslint = new ESLint({ fix: true, overrideConfigFile: join(cwd, 'eslint.config.js'), cwd })
49
+ const results = await eslint.lintFiles(`${dir}/**/*.ts`)
44
50
 
45
- return resultText
51
+ await ESLint.outputFixes(results)
52
+
53
+ // const formatter = await eslint.loadFormatter('stylish')
54
+ // const rulesMeta = eslint.getRulesMetaForResults(results)
55
+ // await formatter.format(results, { cwd, rulesMeta })
56
+ // const resultText =
57
+ // console.log(resultText)
46
58
  }
47
59
 
48
60
  export async function loadTypes() {
49
- const { types, code } = await openAPI(
50
- baseURL || '',
51
- 'import.meta.env.VITE_BAGEL_BASE_URL'
52
- )
53
-
54
- if (!fs.existsSync(bagelinkDir)) fs.mkdirSync(bagelinkDir)
55
-
56
- const typesPath = join(bagelinkDir, 'types.d.ts')
57
- fs.writeFileSync(typesPath, await formatCode(types))
58
-
59
- const apiPath = join(bagelinkDir, 'api.ts')
60
- fs.writeFileSync(apiPath, await formatCode(code))
61
-
62
- if (withAuth) {
63
- const authCode = fs.readFileSync(
64
- join(cwd, 'auth.ts'),
65
- 'utf-8'
66
- ).replace(
67
- '// @ts-expect-error - required for axios to work',
68
- ''
61
+ try {
62
+ const { types, code } = await openAPI(
63
+ baseURL || '',
64
+ 'import.meta.env.VITE_BAGEL_BASE_URL'
69
65
  )
70
- const authPath = join(bagelinkDir, 'auth.ts')
71
- fs.writeFileSync(authPath, await formatCode(authCode))
66
+
67
+ if (!fs.existsSync(bagelinkDir)) fs.mkdirSync(bagelinkDir)
68
+
69
+ const typesPath = join(bagelinkDir, 'types.d.ts')
70
+ await formatAndWriteCode(typesPath, types)
71
+
72
+ const apiPath = join(bagelinkDir, 'api.ts')
73
+ await formatAndWriteCode(apiPath, code)
74
+
75
+ if (withAuth) {
76
+ const authCode = fs.readFileSync(
77
+ join(cwd, 'auth.ts'),
78
+ 'utf-8'
79
+ ).replace(
80
+ '',
81
+ ''
82
+ )
83
+ const authPath = join(bagelinkDir, 'auth.ts')
84
+ await formatAndWriteCode(authPath, authCode)
85
+ }
86
+
87
+ await runEsLintOnDir(bagelinkDir)
88
+ } catch (error) {
89
+ proc.exitCode = 1
90
+ console.error(error)
72
91
  }
73
92
  }
74
93
 
75
- loadTypes().catch(console.error)
94
+ loadTypes().catch((error: unknown) => {
95
+ proc.exitCode = 1
96
+ console.error(error)
97
+ })
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "0.0.633",
4
+ "version": "0.0.635",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",