-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow inlining standalone clients with
- Loading branch information
Showing
76 changed files
with
6,268 additions
and
5,713 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 @@ | ||
--- | ||
'@hey-api/openapi-ts': minor | ||
--- | ||
|
||
feat: allow inlining standalone clients with `client.inline = true` |
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 |
---|---|---|
@@ -1 +1 @@ | ||
20.9.0 | ||
20.10.0 |
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
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,49 @@ | ||
import { copyFileSync, readFileSync, writeFileSync } from 'node:fs'; | ||
import { createRequire } from 'node:module'; | ||
import path from 'node:path'; | ||
|
||
import { getConfig, isStandaloneClient } from '../utils/config'; | ||
import { ensureDirSync } from './utils'; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
||
/** | ||
* (optional) Creates a `client.ts` file containing the same exports as a | ||
* standalone client package. Creates a `core` directory containing the modules | ||
* from standalone client. These files are generated only when `client.inline` | ||
* is set to true. | ||
*/ | ||
export const generateClient = async ( | ||
outputPath: string, | ||
moduleName: string, | ||
) => { | ||
const config = getConfig(); | ||
|
||
if (!isStandaloneClient(config) || !config.client.inline) { | ||
return; | ||
} | ||
|
||
// create directory for client modules | ||
const dirPath = path.resolve(outputPath, 'core'); | ||
ensureDirSync(dirPath); | ||
|
||
const clientModulePath = require.resolve(moduleName); | ||
const clientSrcPath = `${clientModulePath.slice(0, clientModulePath.indexOf('/dist/'))}/src`; | ||
|
||
// copy client modules | ||
const files = ['index.ts', 'types.ts', 'utils.ts']; | ||
files.forEach((file) => { | ||
copyFileSync( | ||
path.resolve(clientSrcPath, file), | ||
path.resolve(dirPath, file), | ||
); | ||
}); | ||
|
||
// copy index file with cherry-picked exports | ||
const nodeIndexFile = readFileSync( | ||
path.resolve(clientSrcPath, 'node', 'index.ts'), | ||
'utf-8', | ||
); | ||
const indexFile = nodeIndexFile.replaceAll('../', './core/'); | ||
writeFileSync(path.resolve(outputPath, 'client.ts'), indexFile, 'utf-8'); | ||
}; |
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
Oops, something went wrong.