Skip to content

Commit

Permalink
[Update] code style
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinmp committed Oct 23, 2018
1 parent 341347f commit 3d0e59c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/api/typeDefs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface IgqlTsOpts {
outFile?: string;
}

const defaults: IgqlTsOpts = {
const defaults: IgqlTsOpts = {
globPattern: '**/*.gql',
outFile: ''
};
Expand All @@ -24,14 +24,16 @@ const readFile: (fileName: string) => Promise<string> =
(fileName) => fs.readFile(fileName, 'utf8');

const getGlobbedFilesLoad: (globPattern: string) => Promise<string[]> = async (globPattern) => {
const files: string[] = await glob(globPattern);
const files: string[] = await glob(globPattern);
const load: string[] = await Promise.all(R.map(readFile, files));

return load;
};

export const getTypeDefs: (globPattern?: string) => Promise<string> = async (globPattern = '**/*.gql') => {
export const getTypeDefs: (globPattern?: string) => Promise<any> = async (globPattern = '**/*.gql') => {
try {
const typesLoad: string[] = await getGlobbedFilesLoad(globPattern);

return mergeTypes(typesLoad);
} catch (error) {
console.error(error);
Expand All @@ -40,18 +42,19 @@ export const getTypeDefs: (globPattern?: string) => Promise<string> = async (glo

const addAutoGeneratedWarning = (tsTypes: string): string => {
return `// This file is auto generated by the gqlToTs.ts module\n${tsTypes}`;
};
};

export const generateTsFromGql: (options?: IgqlTsOpts) => Promise <string | any> = async (options = {}) => {
export const generateTsFromGql: (options?: IgqlTsOpts) => Promise <string | any> = async (options = {}) => {
// check whether we have args
const namespace = process.argv[2] || 'DH';
const namespace = process.argv[2] || 'DH';
console.log('created type definitions with: ', namespace, ' namespace');
const opts = Object.assign(defaults, options);
const opts = { ...defaults, ...options };
try {
const typeDefs: string = await getTypeDefs(opts.globPattern);
const namespaceOpts = { ignoreTypeNameDeclaration: true};
const namespaceOpts = { ignoreTypeNameDeclaration: true };
const tsNameSpace: string = generateNamespace(namespace, typeDefs, namespaceOpts, {});
if (opts.outFile && opts.outFile.length) fs.writeFile(opts.outFile, addAutoGeneratedWarning(tsNameSpace));
if (opts.outFile && opts.outFile.length) { fs.writeFile(opts.outFile, addAutoGeneratedWarning(tsNameSpace)); }

return tsNameSpace;
} catch (error) {
console.error(error);
Expand All @@ -60,5 +63,5 @@ export const generateTsFromGql: (options?: IgqlTsOpts) => Promise <string | any

if (require.main === module && process.env.NODE_ENV !== 'test') {
// this module was run directly from the command line as in node xxx.js
generateTsFromGql({outFile: 'index.d.ts'});
generateTsFromGql({ outFile: 'index.d.ts' });
}

0 comments on commit 3d0e59c

Please sign in to comment.