Apply non-derive typesBundle statically (#7957)
This commit is contained in:
parent
3d72c9760b
commit
addf54d4bd
@ -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",
|
||||
|
||||
28
packages/apps-config/src/api/derives.ts
Normal file
28
packages/apps-config/src/api/derives.ts
Normal 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;
|
||||
}
|
||||
24
packages/apps-config/src/api/index.spec.ts
Normal file
24
packages/apps-config/src/api/index.spec.ts
Normal 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 || {})
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -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);
|
||||
|
||||
35
packages/apps-config/src/api/typesBundle.spec.ts
Normal file
35
packages/apps-config/src/api/typesBundle.spec.ts
Normal 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;
|
||||
`);
|
||||
});
|
||||
68306
packages/apps-config/src/api/typesBundle.ts
Normal file
68306
packages/apps-config/src/api/typesBundle.ts
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user