Apply non-derive typesBundle statically (#7957)

This commit is contained in:
Jaco 2022-08-03 11:47:57 +02:00 committed by GitHub
parent 3d72c9760b
commit addf54d4bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 68397 additions and 4 deletions

View File

@ -33,6 +33,7 @@
"build:electron": "yarn clean:electronBuild && yarn build:electronMain && yarn build:electronRenderer",
"build:electronMain": "cd packages/apps-electron && NODE_ENV=production yarn webpack --config webpack.main.cjs",
"build:electronRenderer": "cd packages/apps-electron && NODE_ENV=production yarn webpack --config webpack.renderer.cjs",
"build:extra": "yarn run test:one packages/apps-config/src/api/typesBundle.spec.ts",
"build:i18n": "i18next-scanner --config i18next-scanner.config.cjs && node ./scripts/i18nSort.cjs",
"build:release:electron": "yarn build && yarn build:electron && yarn postinstall:electron",
"build:release:ghpages": "yarn polkadot-ci-ghact-docs",

View File

@ -0,0 +1,28 @@
// Copyright 2017-2022 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { OverrideBundleDefinition, OverrideBundleType } from '@polkadot/types/types';
import equilibrium from './spec/equilibrium';
import genshiro from './spec/genshiro';
import interbtc from './spec/interbtc';
import subspace from './spec/subspace';
const mapping: [OverrideBundleDefinition, string[]][] = [
[equilibrium, ['Equilibrium']],
[genshiro, ['Genshiro', 'Genshiro Rococo Testnet']],
[interbtc, ['interbtc-parachain', 'interbtc-standalone', 'interlay-parachain', 'kintsugi-parachain']],
[subspace, ['subspace']]
];
export function applyDerives (typesBundle: OverrideBundleType): OverrideBundleType {
mapping.forEach(([{ derives }, chains]): void => {
chains.forEach((chain): void => {
if (typesBundle.spec && typesBundle.spec[chain]) {
typesBundle.spec[chain].derives = derives;
}
});
});
return typesBundle;
}

View File

@ -0,0 +1,24 @@
// Copyright 2017-2022 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { OverrideBundleDefinition } from '@polkadot/types/types';
import spec from './spec';
import { typesBundle } from '.';
function getDerives (spec: Record<string, OverrideBundleDefinition>): string[] {
return Object
.entries(spec)
.filter(([, v]) => !!v.derives)
.map(([k]) => k);
}
describe('typesBundle', (): void => {
it('all derives are re-exported', (): void => {
expect(
getDerives(spec)
).toEqual(
getDerives(typesBundle.spec || {})
);
});
});

View File

@ -1,11 +1,10 @@
// Copyright 2017-2022 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { OverrideBundleType } from '@polkadot/types/types';
import spec from './spec';
import { applyDerives } from './derives';
import { typesBundle as typesOnlyBundle } from './typesBundle';
export * from './constants';
export * from './params';
export const typesBundle: OverrideBundleType = { spec };
export const typesBundle = applyDerives(typesOnlyBundle);

View File

@ -0,0 +1,35 @@
// Copyright 2017-2022 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
import fs from 'fs';
import { objectSpread } from '@polkadot/util';
import spec from './spec';
it('generates the typesBundle', (): void => {
const specEntries = Object.entries(spec);
const typesBundle: { spec: Record<string, unknown> } = { spec: {} };
specEntries.forEach(([k, v]): void => {
const value = objectSpread<{ derives: unknown }>({}, v);
delete value.derives;
typesBundle.spec[k] = value;
});
fs.writeFileSync('packages/apps-config/src/api/typesBundle.ts', `// Copyright 2017-2022 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Do not edit, auto-generated by @polkadot/apps-config
import type { OverrideBundleType } from '@polkadot/types/types';
/* eslint-disable quotes */
/* eslint-disable quote-props */
/* eslint-disable sort-keys */
export const typesBundle = ${JSON.stringify(typesBundle, null, 2)} as unknown as OverrideBundleType;
`);
});

File diff suppressed because it is too large Load Diff