-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: automation to update the management canister IDL
- Loading branch information
Showing
8 changed files
with
859 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.