Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: export more helper utilities, including import statement genera…
…tion
- Loading branch information
1 parent
7b35e50
commit 54a061b
Showing
4 changed files
with
185 additions
and
135 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
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,61 @@ | ||
import Path from "path"; | ||
|
||
const DEFAULT_ALONGSIDE_SUFFIX = "codegen"; | ||
|
||
export type GenLocationOptions = | ||
| { type: "alongside"; dependencyGenPath: string; suffix?: string } | ||
| { type: "folder"; genPath: string } | ||
| { type: "node_modules"; genPath: string }; | ||
|
||
export interface GenOptions { | ||
genLocation: GenLocationOptions; | ||
/** | ||
* the project root (where package.json resides) from which generation | ||
* paths are resolved | ||
*/ | ||
rootPath: string; | ||
} | ||
|
||
// produced via the _ | ||
export interface GenerationConfig { | ||
basePath: string; | ||
baseDependenciesPath: string; | ||
rootPath: string; | ||
suffix?: string; | ||
} | ||
|
||
export function createGenerationConfig(options: GenOptions): GenerationConfig { | ||
let basePath: string; | ||
let baseDependenciesPath: string; | ||
let suffix: string | undefined; | ||
|
||
switch (options.genLocation.type) { | ||
case "alongside": | ||
basePath = options.rootPath; | ||
baseDependenciesPath = Path.join( | ||
basePath, | ||
options.genLocation.dependencyGenPath | ||
); | ||
suffix = options.genLocation.suffix || DEFAULT_ALONGSIDE_SUFFIX; | ||
break; | ||
case "folder": | ||
basePath = Path.join(options.rootPath, options.genLocation.genPath); | ||
baseDependenciesPath = Path.join(basePath, "zod_schema_node_modules"); | ||
break; | ||
case "node_modules": | ||
basePath = Path.join( | ||
options.rootPath, | ||
"node_modules", | ||
options.genLocation.genPath | ||
); | ||
baseDependenciesPath = Path.join(basePath, "zod_schema_node_modules"); | ||
break; | ||
} | ||
|
||
return { | ||
basePath, | ||
baseDependenciesPath, | ||
suffix, | ||
rootPath: options.rootPath | ||
} | ||
} |
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.