diff --git a/package.json b/package.json index ebeb3c3d0c..fd6240e70d 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "build": "polkadot-dev-build-ts && yarn run build:methodsdoc && polkadot-dev-build-docs", "build:htmldoc": "yarn clean && typedoc --theme default --out docs/html", "build:methodsdoc": "node packages/types/src/scripts/MetadataMdWrapper.js", - "build:decodedjson": "node packages/types/src/scripts/MetadataJsonDecodeWrapper.js", "check": "tslint --project . && tsc --noEmit --pretty", "clean": "polkadot-dev-clean-build", "postinstall": "polkadot-dev-yarn-only", diff --git a/packages/types/babelConfig.js b/packages/types/babelConfig.js deleted file mode 100644 index 49f4cabfcb..0000000000 --- a/packages/types/babelConfig.js +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env node -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -require('@babel/register')({ - extensions: ['.js', '.ts'], - plugins: [ - ['module-resolver', { - alias: { - '^@polkadot/types(.*)': './packages/types/src\\2' - } - }] - ] -}); diff --git a/packages/types/src/scripts/MetadataJsonDecode.ts b/packages/types/src/scripts/MetadataJsonDecode.ts deleted file mode 100644 index 98e84f7808..0000000000 --- a/packages/types/src/scripts/MetadataJsonDecode.ts +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -const fs = require('fs'); - -import Metadata from '../Metadata'; -import rpcdata from '../Metadata/v0/static'; - -function metadataStringifyAsJson () { - const decoded = new Metadata(rpcdata).asV0; - - return JSON.stringify(decoded.toJSON(), null, 2); -} - -function writeToJson () { - const options = { encoding: 'ascii' }; - const writeStream = fs.createWriteStream('packages/types/src/Metadata.decoded.json', options); - - writeStream.write(metadataStringifyAsJson()); - - writeStream.on('finish', () => { - console.log('wrote all decoded metadata to JSON file'); - }); - - writeStream.end('\n'); -} - -writeToJson(); diff --git a/packages/types/src/scripts/MetadataJsonDecodeWrapper.js b/packages/types/src/scripts/MetadataJsonDecodeWrapper.js deleted file mode 100644 index c76f509c47..0000000000 --- a/packages/types/src/scripts/MetadataJsonDecodeWrapper.js +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env node -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -require('../../babelConfig.js'); -require('./MetadataJsonDecode.ts'); diff --git a/packages/types/src/scripts/MetadataMd.ts b/packages/types/src/scripts/MetadataMd.ts index 440a03b942..828296cb29 100644 --- a/packages/types/src/scripts/MetadataMd.ts +++ b/packages/types/src/scripts/MetadataMd.ts @@ -14,7 +14,7 @@ import Method from '../Method'; const ANCHOR_TOP = ``; const LINK_BACK_TO_TOP = `Back To Top`; -const DESC_EXTRINSICS = '\n\n_The following sections contain Extrinsics methods are part of the default Substrate runtime. Since an Extrinsic is a holder of an object that is just an array of bytes to be included, it does not have a return._\n'; +const DESC_EXTRINSICS = '\n\n_The following sections contain Extrinsics methods are part of the default Substrate runtime._\n'; const DESC_EVENTS = '\n\nEvents are emitted for certain operations on the runtime. The following sections describe the events that are part of the default Substrate runtime.\n'; const DESC_RPC = '\n\n_The following sections contain RPC methods that are Remote Calls available by default and allow you to interact with the actual node, query, and submit. The RPCs are provided by Substrate itself._'; const DESC_STORAGE = '\n\n_The following sections contain Storage methods are part of the default Substrate runtime._\n'; @@ -23,24 +23,6 @@ function sectionLink (sectionName: string) { return `- **[${stringCamelCase(sectionName)}](#${stringCamelCase(sectionName)})**\n\n`; } -function generateSectionLinks (sectionName: string, metadata: MetadataV0) { - switch (sectionName) { - case 'events': - return metadata.events.map((i) => i).sort().map((data: any) => - sectionLink(data.name.toString()) - ).join(''); - - case 'extrinsics': - case 'storage': - return metadata.modules.map((i) => i).sort().map((runtimeModuleMetadata: any) => - sectionLink(runtimeModuleMetadata.prefix.toString()) - ).join(''); - - default: - throw new Error('Unknown section name provided to generate anchors'); - } -} - function generateSectionHeader (md: string, sectionName: string) { return `${md}\n___\n${LINK_BACK_TO_TOP}\n\n### ${sectionName}\n`; } @@ -85,14 +67,16 @@ function sortExtrinsicsSectionMethods (a: any, b: any) { function addEvents (metadata: MetadataV0) { const renderHeading = `## ${ANCHOR_TOP}Events${DESC_EVENTS}`; const orderedSections = metadata.events.map((i) => i).sort(); - const renderAnchors = generateSectionLinks('events', metadata); - - return orderedSections.reduce((md, meta) => { + let renderAnchors = ''; + const sections = orderedSections.reduce((md, meta) => { if (!meta.events || !meta.events.length) { return md; } const sectionName = stringCamelCase(meta.name.toString()); + + renderAnchors += sectionLink(sectionName); + const renderSection = generateSectionHeader(md, sectionName); const orderedMethods = meta.events.sort(sortExtrinsicsSectionMethods); @@ -106,20 +90,24 @@ function addEvents (metadata: MetadataV0) { return renderSignature + renderSummary; }, renderSection); - }, renderHeading + renderAnchors); + }, ''); + + return renderHeading + renderAnchors + sections; } function addExtrinsics (metadata: MetadataV0) { const renderHeading = `## ${ANCHOR_TOP}Extrinsics${DESC_EXTRINSICS}`; const orderedSections = metadata.modules.map((i) => i).sort(); - const renderAnchors = generateSectionLinks('extrinsics', metadata); - - return orderedSections.reduce((md, meta) => { + let renderAnchors = ''; + const sections = orderedSections.reduce((md, meta) => { if (!meta.module.call || !meta.module.call.functions.length) { return md; } const sectionName = stringCamelCase(meta.prefix.toString()); + + renderAnchors += sectionLink(sectionName); + const renderSection = generateSectionHeader(md, sectionName); const orderedMethods = meta.module.call.functions.sort(sortExtrinsicsSectionMethods); @@ -132,20 +120,24 @@ function addExtrinsics (metadata: MetadataV0) { return renderSignature + renderSummary; }, renderSection); - }, renderHeading + renderAnchors); + }, ''); + + return renderHeading + renderAnchors + sections; } function addStorage (metadata: MetadataV0) { const renderHeading = `## ${ANCHOR_TOP}Storage${DESC_STORAGE}`; const orderedSections = metadata.modules.sort(); - const renderAnchors = generateSectionLinks('storage', metadata) + sectionLink('substrate'); - - return orderedSections.reduce((md, moduleMetadata) => { + let renderAnchors = ''; + const sections = orderedSections.reduce((md, moduleMetadata) => { if (moduleMetadata.storage.isNone) { return md; } const sectionName = stringLowerFirst(moduleMetadata.storage.unwrap().prefix.toString()); + + renderAnchors += sectionLink('sectionName'); + const renderSection = generateSectionHeader(md, sectionName); const orderedMethods = moduleMetadata.storage.unwrap().functions.sort(); @@ -158,7 +150,9 @@ function addStorage (metadata: MetadataV0) { return renderSignature + renderSummary; }, renderSection); - }, renderHeading + renderAnchors); + }, ''); + + return renderHeading + renderAnchors + sectionLink('substrate') + sections; } function writeFile (name: string, ...chunks: Array) { diff --git a/packages/types/src/scripts/MetadataMdWrapper.js b/packages/types/src/scripts/MetadataMdWrapper.js index dcfbaf2db8..9e97124d17 100644 --- a/packages/types/src/scripts/MetadataMdWrapper.js +++ b/packages/types/src/scripts/MetadataMdWrapper.js @@ -3,5 +3,15 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -require('../../babelConfig.js'); +require('@babel/register')({ + extensions: ['.js', '.ts'], + plugins: [ + ['module-resolver', { + alias: { + '^@polkadot/types(.*)': './packages/types/src\\2' + } + }] + ] +}); + require('./MetadataMd.ts');