Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
remove no longer used code
  • Loading branch information
xlc committed May 4, 2020
commit caa5425ee9e80d6fcd4e8b72d8d8ffe1810d2c29
19 changes: 0 additions & 19 deletions packages/typegen/src/util/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,8 @@

import Handlebars from 'handlebars';

import { Text } from '@polkadot/types';

import { indent } from './formatting';
import { readTemplate } from './file';

type AnyString = Text | string;
type Arg = [AnyString, AnyString];

Handlebars.registerPartial({
docs: Handlebars.compile(readTemplate('docs'))
});

export function createDocComments (spaces: number, docs: AnyString[], args: Arg[] = []): string {
const contents = [
...docs.map((doc): string => doc.toString().trim()).filter((doc): boolean => !!doc),
...args.map(([name, type]): string => `@param ${name} ${type}`)
].map((d): string => ` * ${d}`);

return contents.length
? ['/**', ...contents, ' **/\n']
.map((s): string => indent(spaces)(s))
.join('\n')
: '';
}
11 changes: 0 additions & 11 deletions packages/typegen/src/util/formatting.spec.ts

This file was deleted.

53 changes: 0 additions & 53 deletions packages/typegen/src/util/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { readTemplate } from './file';
const TYPES_NON_PRIMITIVE = ['Metadata'];

export const HEADER = (type: 'chain' | 'defs'): string => `// Auto-generated via \`yarn polkadot-types-from-${type}\`, do not edit\n/* eslint-disable */\n\n`;
export const FOOTER = '\n';

Handlebars.registerPartial({
footer: Handlebars.compile(readTemplate('footer')),
Expand Down Expand Up @@ -72,48 +71,6 @@ Handlebars.registerHelper({
}
});

// creates the import lines
/** @internal */
export function createImportCode (header: string, imports: TypeImports, checks: { file: string; types: string[] }[]): string {
return [
{
file: '@polkadot/types/types',
types: Object.keys(imports.typesTypes)
},
{
file: '@polkadot/types/codec',
types: Object
.keys(imports.codecTypes)
.filter((name): boolean => name !== 'Tuple')
},
{
file: '@polkadot/types/extrinsic',
types: Object.keys(imports.extrinsicTypes)
},
{
file: '@polkadot/types/generic',
types: Object.keys(imports.genericTypes)
},
{
file: '@polkadot/types/primitive',
types: Object
.keys(imports.primitiveTypes)
.filter((name): boolean => !TYPES_NON_PRIMITIVE.includes(name))
},
{
file: '@polkadot/types',
types: Object
.keys(imports.primitiveTypes)
.filter((name): boolean => TYPES_NON_PRIMITIVE.includes(name))
},
...checks
].reduce((result, { file, types }): string => {
return types.length
? `${result}import { ${types.sort().join(', ')} } from '${file}';\n`
: result;
}, header) + '\n';
}

// helper to generate a `export interface <Name> extends <Base> {<Body>}
/** @internal */
export function exportInterface (name = '', base: string, body = ''): string {
Expand Down Expand Up @@ -331,13 +288,3 @@ export function formatType (definitions: object, type: string | TypeDef, imports
}
}
}

/**
* Indent a string with `n` spaces before.
*/
/** @internal */
export function indent (n: number, char = ' '): (str: string) => string {
return function (str: string): string {
return `${char.repeat(n)}${str}`;
};
}