-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restructure commands and update docs
- Loading branch information
Showing
15 changed files
with
213 additions
and
71 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
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,13 @@ | ||
import { cli, runCli } from 'clifer' | ||
import create from './create/create-command' | ||
import generate from './generate/generate-command' | ||
|
||
const command = cli('gql-assist') | ||
.description( | ||
'GQL Assist is a powerful tool designed to streamline the development of GraphQL APIs in a NestJS environment. By automatically converting TypeScript classes, resolvers, and enums into their corresponding GraphQL definitions, GQL Assist significantly reduces the amount of boilerplate code you need to write.', | ||
) | ||
.version('1.0') | ||
.command(generate) | ||
.command(create) | ||
|
||
runCli(command) |
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,39 +1,8 @@ | ||
import { command, input } from 'clifer' | ||
import { writeFile } from 'fs-extra' | ||
import { reduceAsync } from 'tsds-tools' | ||
import ts from 'typescript' | ||
import { GQLAssistConfig, config } from '../config' | ||
import { generateEnum } from '../generator/enum/enum-generator' | ||
import { generateInput } from '../generator/input/input-generator' | ||
import { generateModel } from '../generator/model/model-generator' | ||
import { generateResolver } from '../generator/resolver/resolver-generator' | ||
import { readTSFile } from '../ts/parse-ts' | ||
import { prettify } from '../ts/prettify' | ||
import { printTS } from '../ts/print-ts' | ||
|
||
interface GenerateProps { | ||
file: string | ||
} | ||
|
||
const plugins = [generateModel, generateInput, generateResolver, generateEnum] | ||
|
||
export async function generate(sourceFile: ts.SourceFile, config: GQLAssistConfig) { | ||
return await reduceAsync( | ||
plugins, | ||
(sourceFile, runPlugin) => runPlugin(sourceFile, config), | ||
sourceFile, | ||
) | ||
} | ||
|
||
async function run({ file }: GenerateProps) { | ||
const sourceFile = readTSFile(file) | ||
const output = await prettify(printTS(await generate(sourceFile, config), undefined)) | ||
await writeFile(file, output) | ||
} | ||
|
||
export default command<GenerateProps>('generate') | ||
.description('Generate models and resolvers') | ||
.argument( | ||
input('file').description('The source file to inspect and generate').string().required(), | ||
) | ||
.handle(run) | ||
import { command } from 'clifer' | ||
import generateDecoratorCommand from './generate-decorator-command' | ||
import generateHookCommand from './generate-hook-command' | ||
|
||
export default command('generate') | ||
.description('GraphQL Assist converts GraphQL queries, mutations or subscriptions') | ||
.command(generateHookCommand) | ||
.command(generateDecoratorCommand) |
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,39 @@ | ||
import { command, input } from 'clifer' | ||
import { writeFile } from 'fs-extra' | ||
import { reduceAsync } from 'tsds-tools' | ||
import ts from 'typescript' | ||
import { GQLAssistConfig, config } from '../config' | ||
import { generateEnum } from '../generator/enum/enum-generator' | ||
import { generateInput } from '../generator/input/input-generator' | ||
import { generateModel } from '../generator/model/model-generator' | ||
import { generateResolver } from '../generator/resolver/resolver-generator' | ||
import { readTSFile } from '../ts/parse-ts' | ||
import { prettify } from '../ts/prettify' | ||
import { printTS } from '../ts/print-ts' | ||
|
||
interface GenerateProps { | ||
file: string | ||
} | ||
|
||
const plugins = [generateModel, generateInput, generateResolver, generateEnum] | ||
|
||
export async function generate(sourceFile: ts.SourceFile, config: GQLAssistConfig) { | ||
return await reduceAsync( | ||
plugins, | ||
(sourceFile, runPlugin) => runPlugin(sourceFile, config), | ||
sourceFile, | ||
) | ||
} | ||
|
||
async function run({ file }: GenerateProps) { | ||
const sourceFile = readTSFile(file) | ||
const output = await prettify(printTS(await generate(sourceFile, config), undefined)) | ||
await writeFile(file, output) | ||
} | ||
|
||
export default command<GenerateProps>('decorator') | ||
.description( | ||
'Automatically converts TypeScript classes, resolvers, methods, and enums to their respective NestJS GraphQL or Type GraphQL counterparts with appropriate decorators.', | ||
) | ||
.option(input('file').description('The source file to inspect and generate').string().required()) | ||
.handle(run) |
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,26 @@ | ||
import { command, input } from 'clifer' | ||
import { writeFile } from 'fs-extra' | ||
import { config } from '../config' | ||
import { generateHook } from '../generator' | ||
import { loadSchema } from '../generator/hook/graphql-util' | ||
import { prettify, printTS, readTSFile } from '../ts' | ||
|
||
interface Props { | ||
file: string | ||
schema: string | ||
} | ||
|
||
async function run(props: Props) { | ||
const schema = loadSchema(props.schema) | ||
const sourceFile = readTSFile(props.file) | ||
const output = await prettify(printTS(await generateHook(sourceFile, schema, config), undefined)) | ||
await writeFile(props.file, output) | ||
} | ||
|
||
export default command<Props>('hook') | ||
.description( | ||
'GraphQL Assist converts GraphQL queries into TypeScript code compatible with @apollo/client or similar library, making query writing for Apollo Client easier and less error-prone.', | ||
) | ||
.option(input('schema').description('Schema file').string().required()) | ||
.option(input('file').description('The source file to inspect and generate').string().required()) | ||
.handle(run) |
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,2 @@ | ||
export * from './generate-decorator-command' | ||
export * from './generate-hook-command' |
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,3 +1,4 @@ | ||
export * from './context' | ||
export * from './enum' | ||
export * from './hook' | ||
export * from './input' | ||
|
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,16 +1,5 @@ | ||
export * from './diff' | ||
export * from './generate' | ||
export * from './generator' | ||
|
||
import { cli, runCli } from 'clifer' | ||
import generate from './generate/generate-command' | ||
import create from './create/create-command' | ||
|
||
const command = cli('gql-assist') | ||
.description( | ||
'Assists in generating models, resolvers, field resolvers, and GraphQL types efficiently.', | ||
) | ||
.version('1.0') | ||
.command(generate) | ||
.command(create) | ||
|
||
runCli(command) | ||
export * from './ts' | ||
export * from './util' |
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,45 @@ | ||
export * from './add-decorator' | ||
export * from './add-export' | ||
export * from './add-imports' | ||
export * from './add-new-line' | ||
export * from './add-nullability' | ||
export * from './conditional' | ||
export * from './convert-to-method' | ||
export * from './create-args-decorator' | ||
export * from './create-class-decorator' | ||
export * from './create-context-decorator' | ||
export * from './create-enum' | ||
export * from './create-graphql-query' | ||
export * from './create-import' | ||
export * from './create-interface' | ||
export * from './create-parent-decorator' | ||
export * from './create-property-or-method-decorator' | ||
export * from './create-resolver-decorator' | ||
export * from './create-scalar-decorator' | ||
export * from './create-type' | ||
export * from './create-union' | ||
export * from './find-node' | ||
export * from './get-all-types' | ||
export * from './get-comment' | ||
export * from './get-comment-from-decorator' | ||
export * from './get-decorator' | ||
export * from './get-implementation-by-name' | ||
export * from './get-method-declaration' | ||
export * from './get-name' | ||
export * from './get-parameter' | ||
export * from './get-parameter-by-type' | ||
export * from './get-property-declaration' | ||
export * from './get-type' | ||
export * from './is-async' | ||
export * from './is-nullable' | ||
export * from './is-nullable-from-decorator' | ||
export * from './is-private' | ||
export * from './organize-imports' | ||
export * from './parse-ts' | ||
export * from './prettify' | ||
export * from './print-ts' | ||
export * from './remove-nullability' | ||
export * from './transform-name' | ||
export * from './traverse-syntax-tree' | ||
export * from './update-statements' | ||
export * from './with-default-type' |
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,3 @@ | ||
export * from './common' | ||
export * from './run-command' | ||
export * from './test-util' |
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