-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli-utils): Add separate support packages for Vue & Svelte (#361)
- Loading branch information
Showing
19 changed files
with
604 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@gql.tada/cli-utils": minor | ||
--- | ||
|
||
Split `.vue` and `.svelte` SFC file support out into support packages. If you need Vue support, you must now install `@gql.tada/vue-support` alongside `gql.tada`, and if you need Svelte support, you must now install `@gql.tada/svelte-support` alongside `gql.tada`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import type ts from 'typescript'; | ||
import * as path from 'node:path'; | ||
|
||
import { TadaError, TadaErrorCode } from '../utils/error'; | ||
|
||
let _svelte: typeof import('@gql.tada/svelte-support'); | ||
let _vue: typeof import('@gql.tada/vue-support'); | ||
|
||
const transformSvelte = async ( | ||
...args: Parameters<typeof _svelte.transform> | ||
): Promise<ReturnType<typeof _svelte.transform>> => { | ||
if (!_svelte) { | ||
try { | ||
_svelte = await import('@gql.tada/svelte-support'); | ||
} catch (_error) { | ||
throw new TadaError( | ||
TadaErrorCode.SVELTE_SUPPORT, | ||
'For Svelte support the `@gql.tada/svelte-support` package must be installed.\n' + | ||
'Install the package and try again.' | ||
); | ||
} | ||
} | ||
return _svelte.transform(...args); | ||
}; | ||
|
||
const transformVue = async ( | ||
...args: Parameters<typeof _vue.transform> | ||
): Promise<ReturnType<typeof _vue.transform>> => { | ||
if (!_vue) { | ||
try { | ||
_vue = await import('@gql.tada/vue-support'); | ||
} catch (_error) { | ||
throw new TadaError( | ||
TadaErrorCode.VUE_SUPPORT, | ||
'For Vue support the `@gql.tada/vue-support` package must be installed.\n' + | ||
'Install the package and try again.' | ||
); | ||
} | ||
} | ||
return _vue.transform(...args); | ||
}; | ||
|
||
const checkVue = async (): Promise<void> => { | ||
if (!_vue) { | ||
try { | ||
_vue = await import('@gql.tada/vue-support'); | ||
} catch (_error) { | ||
throw new TadaError( | ||
TadaErrorCode.VUE_SUPPORT, | ||
'For Vue support the `@gql.tada/vue-support` package must be installed.\n' + | ||
'Install the package and try again.' | ||
); | ||
} | ||
} | ||
return _vue.check(); | ||
}; | ||
|
||
export const transformExtensions = ['.svelte', '.vue'] as const; | ||
|
||
export const transform = async (sourceFile: ts.SourceFile) => { | ||
const extname = path.extname(sourceFile.fileName); | ||
if (extname === '.svelte') { | ||
return transformSvelte(sourceFile); | ||
} else if (extname === '.vue') { | ||
await checkVue(); | ||
return transformVue(sourceFile); | ||
} else { | ||
throw new TadaError( | ||
TadaErrorCode.UNKNOWN_EXTERNAL_FILE, | ||
`Tried transforming unknown file type "${extname}". Supported: ${transformExtensions.join( | ||
', ' | ||
)}` | ||
); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export const enum TadaErrorCode { | ||
VUE_SUPPORT, | ||
SVELTE_SUPPORT, | ||
UNKNOWN_EXTERNAL_FILE, | ||
} | ||
|
||
export class TadaError extends Error { | ||
static isTadaError(error: unknown): error is TadaError { | ||
return !!(typeof error === 'object' && error && 'name' in error && error.name === 'TadaError'); | ||
} | ||
|
||
readonly code: TadaErrorCode; | ||
constructor(code: TadaErrorCode, message: string) { | ||
super(message); | ||
this.code = code; | ||
this.name = 'TadaError'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 0no.co | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.