-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐞add some logs to creating declaration of schema
- Loading branch information
1 parent
da1c155
commit c95df5c
Showing
8 changed files
with
141 additions
and
82 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,10 @@ | ||
import { getSchemaDeclarations } from "./schema/mod.ts"; | ||
import { getRequestDeclarations } from "./request/mod.ts"; | ||
|
||
export const generateDeclarations = async ( | ||
generateSchema: boolean, | ||
generateRequest: boolean | ||
) => { | ||
//generateRequest && (await getRequestDeclarations()); | ||
generateSchema && (await getSchemaDeclarations()); | ||
}; |
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 |
---|---|---|
@@ -1,62 +1,69 @@ | ||
import { Project, log } from "../../deps.ts"; | ||
import { ensureDir } from "../../deps.ts"; | ||
import { Project, log, emptyDir } from "../../deps.ts"; | ||
import { rgb24 } from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import { denoResolutionHost } from "../utils/mod.ts"; | ||
import { addFunQLInterfaceToSourceFile } from "./utils/addInterfaceToSrcFile.ts"; | ||
|
||
export const getSchemaDeclarations = async (dirPath?: string) => { | ||
log.info("Generating of declarations of schema is started"); | ||
const project = new Project({ | ||
resolutionHost: denoResolutionHost, | ||
}); | ||
|
||
const __dirname = dirPath || Deno.cwd(); | ||
await ensureDir("declarations/schema"); | ||
project.addSourceFilesAtPaths(`${__dirname}/**/*.ts`); | ||
//handle differentiate between schema and schemas | ||
const dir = | ||
project.getDirectory(`${__dirname}/schema`) || | ||
project.getDirectory(`${__dirname}/schemas`); | ||
|
||
const createdSourceFile = project.createSourceFile( | ||
`${__dirname}/declarations/schema/schema.ts`, | ||
undefined, | ||
{ | ||
overwrite: true, | ||
} | ||
); | ||
|
||
const sourceFiles = dir?.getSourceFiles(); | ||
|
||
//get all of interfaces | ||
sourceFiles?.map((sourceFile) => { | ||
const selectedInterfaces = sourceFile | ||
.getInterfaces() | ||
.filter( | ||
(inter) => | ||
inter.getName().startsWith("Pu") || | ||
inter.getName().startsWith("Em") || | ||
inter.getName().startsWith("In") || | ||
inter.getName().startsWith("OutRel") || | ||
inter.getName().startsWith("I") | ||
); | ||
try { | ||
log.info("Generating of declarations of schema is started"); | ||
const project = new Project({ | ||
resolutionHost: denoResolutionHost, | ||
}); | ||
|
||
const __dirname = dirPath || Deno.cwd(); | ||
await emptyDir("declarations/schema"); | ||
project.addSourceFilesAtPaths(`${__dirname}/**/*.ts`); | ||
//handle differentiate between schema and schemas | ||
const dir = | ||
project.getDirectory(`${__dirname}/schema`) || | ||
project.getDirectory(`${__dirname}/schemas`); | ||
|
||
selectedInterfaces.map((inter) => | ||
addFunQLInterfaceToSourceFile(inter, createdSourceFile) | ||
const createdSourceFile = project.createSourceFile( | ||
`${__dirname}/declarations/schema/schema.ts`, | ||
undefined, | ||
{ | ||
overwrite: true, | ||
} | ||
); | ||
}); | ||
|
||
//console.log(newSourceFile.getText()); | ||
await createdSourceFile.save(); | ||
const sourceFiles = dir!.getSourceFiles(); | ||
|
||
//get all of interfaces | ||
sourceFiles?.map((sourceFile) => { | ||
const selectedInterfaces = sourceFile | ||
.getInterfaces() | ||
.filter( | ||
(inter) => | ||
inter.getName().startsWith("Pu") || | ||
inter.getName().startsWith("Em") || | ||
inter.getName().startsWith("In") || | ||
inter.getName().startsWith("OutRel") || | ||
inter.getName().startsWith("I") | ||
); | ||
|
||
selectedInterfaces.map((inter) => | ||
addFunQLInterfaceToSourceFile(inter, createdSourceFile) | ||
); | ||
}); | ||
|
||
//console.log(newSourceFile.getText()); | ||
await createdSourceFile.save(); | ||
|
||
log.info(`creating of declaration files for schema was successful | ||
log.info(`creating of declaration files for schema was successful | ||
${rgb24( | ||
` | ||
------------------------------------------------------------- | ||
| schema: file://${__dirname}/declarations/schema/schema.ts | ||
------------------------------------------------------------- | ||
`, | ||
------------------------------------------------------------- | ||
| schema: file://${__dirname}/declarations/schema/schema.ts | ||
------------------------------------------------------------- | ||
`, | ||
0xadfc03 | ||
)} | ||
`); | ||
} catch (error) { | ||
log.error( | ||
`creating of schema was unsuccessful please review your project | ||
${error} | ||
` | ||
); | ||
} | ||
}; |
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