|
| 1 | +const fs = require('fs'); |
1 | 2 | const path = require('path'); |
2 | 3 | const axios = require('axios'); |
3 | 4 | const FormData = require('form-data'); |
@@ -34,12 +35,55 @@ const { |
34 | 35 | litActionRepositoryCommon, |
35 | 36 | } = loadLitActionExports(); |
36 | 37 |
|
| 38 | +function renderLitActionRepository(repo) { |
| 39 | + const actionEntries = Object.entries(repo).map( |
| 40 | + ([actionName, networks]) => { |
| 41 | + const networkEntries = Object.entries(networks) |
| 42 | + .map(([networkName, cid]) => ` ${networkName}: '${cid}',`) |
| 43 | + .join('\n'); |
| 44 | + |
| 45 | + return ` ${actionName}: Object.freeze({\n${networkEntries}\n }),`; |
| 46 | + } |
| 47 | + ); |
| 48 | + |
| 49 | + return `Object.freeze({\n${actionEntries.join('\n')}\n});`; |
| 50 | +} |
| 51 | + |
| 52 | +function renderLitActionRepositoryCommon(repo) { |
| 53 | + const commonEntries = Object.entries(repo) |
| 54 | + .map(([actionName, cid]) => ` ${actionName}: '${cid}'`) |
| 55 | + .join(',\n'); |
| 56 | + |
| 57 | + return `Object.freeze({\n${commonEntries}\n});`; |
| 58 | +} |
| 59 | + |
| 60 | +function updateConstantsFile(cidRepo, cidRepoCommon) { |
| 61 | + const constantsFilePath = path.resolve( |
| 62 | + __dirname, |
| 63 | + '../wrapped-keys/src/lib/lit-actions-client/constants.ts' |
| 64 | + ); |
| 65 | + |
| 66 | + const fileContents = `import { LitCidRepository, LitCidRepositoryCommon } from './types'; |
| 67 | +
|
| 68 | +const LIT_ACTION_CID_REPOSITORY: LitCidRepository = ${renderLitActionRepository( |
| 69 | + cidRepo |
| 70 | + )}; |
| 71 | +
|
| 72 | +const LIT_ACTION_CID_REPOSITORY_COMMON: LitCidRepositoryCommon = ${renderLitActionRepositoryCommon( |
| 73 | + cidRepoCommon |
| 74 | + )}; |
| 75 | +
|
| 76 | +export { LIT_ACTION_CID_REPOSITORY, LIT_ACTION_CID_REPOSITORY_COMMON }; |
| 77 | +`; |
| 78 | + |
| 79 | + fs.writeFileSync(constantsFilePath, fileContents); |
| 80 | +} |
| 81 | + |
37 | 82 | /** Usage: |
38 | 83 | * 1. Ensure you have a valid Pinata IPFS JWT in `LIT_IPFS_JWT` env var |
39 | | - * 2. Make sure you run `yarn build` to ensure that all LIT actions code has been built into the generated directory from the current commit |
40 | | - * 3. `node sync-actions-to-ipfs` -> this will print out JSON of the `LIT_ACTION_CID_REPOSITORY` and LIT_ACTION_CID_REPOSITORY_COMMON |
41 | | - * 4. Copy/paste the CIDs into those objects in `packages/wrapped-keys/src/lib/lit-actions-client/constants.ts` |
42 | | - * 5. Commit the changes and push them to your branch |
| 84 | + * 2. Make sure you run the library build (`pnpm nx build wrapped-keys-lit-actions`) so the generated actions are up to date |
| 85 | + * 3. `node sync-actions-to-ipfs` -> this will pin the latest lit actions, update `packages/wrapped-keys/src/lib/lit-actions-client/constants.ts`, and print the CID JSON for verification |
| 86 | + * 4. Review the diff in `constants.ts` and commit the changes |
43 | 87 | */ |
44 | 88 |
|
45 | 89 | const JWT = process.env.LIT_IPFS_JWT || ''; |
@@ -123,6 +167,10 @@ async function gogo() { |
123 | 167 | getCidRepository(litActionRepository), |
124 | 168 | ]); |
125 | 169 |
|
| 170 | + updateConstantsFile(cidRepo, cidRepoCommon); |
| 171 | + console.log( |
| 172 | + 'Updated constants file at packages/wrapped-keys/src/lib/lit-actions-client/constants.ts' |
| 173 | + ); |
126 | 174 | console.log('common', cidRepoCommon); |
127 | 175 | console.log('byNetwork', cidRepo); |
128 | 176 | } |
|
0 commit comments