Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS native output from json (to npm_dist) #34

Merged
merged 5 commits into from
Oct 29, 2021
Merged

JS native output from json (to npm_dist) #34

merged 5 commits into from
Oct 29, 2021

Conversation

jacogr
Copy link
Contributor

@jacogr jacogr commented Oct 29, 2021

Adds scripts/js/build_js.mjs that does the following -

  1. create index.{js, cjs} versions from the ss58-registry.json input
  2. adjusts the package.json file to allow for export maps
  3. adds an explicit index.d.ts file for TypeScript consumers

This is executed via npm run build that creates the output in the npm_dist folder. At this point is is completely ready for publishing to the npm registry, so cd npm_dist && npm publish --access public will publish (assuming all the right credentials are found locally)

The reason for the JS outputs is that import or require from json is still well, up-in-the-air from a standards perspective. For instance under Node extra flags are now required to enable this.

In general having a full build setup via something else would probably be overkill, hence the small script that copies stuff and generates the JS output. Cannot beat no additional dependencies.

Additionally the PR also adds -

  • a types.d.ts file in the root for TypeScript definitions for the registry structure
  • an updated .gitignore to skip the npm_dist folder (alongside the changes in Version package.json from Cargo.toml (via script) #33)
  • alignment for the package.json version from the current master status

With this available alongside #33 it can really be published to npm from CI.

Comment on lines 41 to 45
const code = JSON.stringify(registry, null, 2)
.replace(/\n "/g, '\n\t\t') // change the leading key " into '
.replace(/":/g, ':') // change the trailing key ": into :
.replace(/"/g, "'") // use single quotes elsewhere
.replace(/ /g, '\t'); // change all tabs into spaces
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this, it ends up looking like this in npm_dist/index.js -

export default [
	{
		prefix: 0,
		network: 'polkadot',
		displayName: 'Polkadot Relay Chain',
		symbols: [
			'DOT'
		],
		decimals: [
			10
		],
		standardAccount: '*25519',
		website: 'https://polkadot.network'
	},
	{
		prefix: 1,
...

@bkchr
Copy link
Member

bkchr commented Oct 29, 2021

Needs to be updated

scripts/js/build_js.mjs Outdated Show resolved Hide resolved
@bkchr bkchr merged commit f1931a4 into main Oct 29, 2021
@bkchr bkchr deleted the jg-build-publish branch October 29, 2021 12:42
@jacogr jacogr mentioned this pull request Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants