-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: import event's parameters types of the same spec version
affects: @joystream/hydra-typegen
- Loading branch information
1 parent
c114562
commit b9319e6
Showing
6 changed files
with
80 additions
and
10 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,53 @@ | ||
import { execFile } from 'child_process' | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { promisify } from 'util' | ||
import { GeneratorConfig } from '.' | ||
import { IConfig } from '../commands/typegen' | ||
import { formatWithPrettier, writeFile } from '../util' | ||
|
||
const debug = require('debug')('hydra-typegen:gen-typesLookup') | ||
|
||
export async function generateTypesLookup( | ||
{ outDir, metadata: { source }, typegenBinPath }: IConfig, | ||
{ dest, specVersion }: GeneratorConfig | ||
) { | ||
const TYPES_LOOKUP_FILE_NAME = 'types-lookup.ts' | ||
const TYPES_OUT_DIR_NAME = 'types' | ||
|
||
// create the temporary types-lookup directory | ||
const typesLookupOutDir = path.join(dest, TYPES_OUT_DIR_NAME) | ||
fs.mkdirSync(typesLookupOutDir, { recursive: true }) | ||
|
||
// generate types-lookup.ts using polkadot typegen | ||
const pExecFile = promisify(execFile) | ||
await pExecFile(path.join(process.cwd(), typegenBinPath), [ | ||
'--endpoint', | ||
source, | ||
'--input', | ||
path.join(outDir, specVersion.toString(), TYPES_OUT_DIR_NAME), | ||
'--package', | ||
dest, | ||
]) | ||
|
||
// read types-lookup.ts | ||
const file = fs.readFileSync( | ||
path.join(typesLookupOutDir, TYPES_LOOKUP_FILE_NAME), | ||
'utf8' | ||
) | ||
|
||
// remove module augmentation from the file | ||
const outFile = file | ||
.replace(`declare module '@polkadot/types/lookup' {`, '') | ||
.replace('} // declare module', '') | ||
|
||
// save the file | ||
writeFile(path.join(dest, TYPES_LOOKUP_FILE_NAME), () => | ||
formatWithPrettier(outFile) | ||
) | ||
|
||
// remove the temporary types-lookup directory | ||
fs.rmSync(typesLookupOutDir, { recursive: true, force: true }) | ||
|
||
debug('Done writing types-lookup') | ||
} |
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