Skip to content

Commit

Permalink
feat: automation to update the management canister IDL
Browse files Browse the repository at this point in the history
  • Loading branch information
krpeacock committed Jun 4, 2024
1 parent b4f4682 commit 883091a
Show file tree
Hide file tree
Showing 8 changed files with 859 additions and 519 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ commands to keep in mind;

The following scripts can be found in [./bin](./bin):

- update-management-idl - Update the management canister IDL in @dfinity/agent

Monorepo-related scripts run in this order, but are usually invoked by `npm install`:

- npm-postinstall - Run with `npm run postinstall` in this monorepo package.
Expand Down
46 changes: 46 additions & 0 deletions bin/update-management-idl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { $, cd, fetch } from 'zx';
import path from 'path';

fetch(
'https://raw.githubusercontent.com/dfinity/interface-spec/master/spec/_attachments/ic.did',
).then(async res => {
res.text().then(async text => {
const root = path.resolve(__dirname, '..');

const candid = text;

await cd(`${root}/packages/agent/src/canisters`);

await $`echo ${candid} > management.did`;
let ts = (await $`didc bind management.did -t ts`).toString();
let js = (await $`didc bind management.did -t js`).toString();

const didcVersion = await $`didc --version`;

const prefix = `/*
* This file is generated from the candid for asset management.
* didc version: ${didcVersion.toString().split(' ')[1].trim()}
*/
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
`;

// replace first line of service

ts.replace(`export interface _SERVICE {`, `export default interface _SERVICE {`);
js.replace(`export const idlFactory = ({ IDL }) => {`, `export default ({ IDL }) => {`);

ts = prefix + ts;
js = prefix + js;

await $`echo ${js} > management_idl.ts`;
await $`echo ${ts} > management_service.ts`;

await cd(`${root}`);

await $`npm run prettier:format`;

console.log('Done!');
});
});
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- feat!: add support for proof of absence in Certificate lookups
- feat: `update-management-idl` automation to update the management canister IDL in `@dfinity/agent`

### Changed

Expand Down
24 changes: 21 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"typescript": "^5.2.2",
"url": "^0.11.3",
"webcrypto-core": "^1.7.7",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"zx": "^8.1.2"
},
"engines": {
"node": "^12 || ^14 || ^16 || >=17",
Expand All @@ -68,7 +69,8 @@
"prepare": "husky install",
"prettier:check": "npx -p prettier -p pretty-quick pretty-quick --check",
"prettier:format": "npx -p prettier -p pretty-quick pretty-quick",
"postversion": "npm run prettier:format"
"postversion": "npm run prettier:format",
"update-management-idl": "ts-node bin/update-management-idl.ts"
},
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit 883091a

Please sign in to comment.