@account-kit/plugingen 4.0.0-alpha.9 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/esm/cli.js +1 -0
  2. package/dist/esm/cli.js.map +1 -1
  3. package/dist/esm/commands/generate/index.d.ts +2 -0
  4. package/dist/esm/commands/generate/index.js +23 -0
  5. package/dist/esm/commands/generate/index.js.map +1 -1
  6. package/dist/esm/commands/generate/phases/plugin-generator/get-contract-gen.js +1 -1
  7. package/dist/esm/commands/generate/phases/plugin-generator/get-contract-gen.js.map +1 -1
  8. package/dist/esm/commands/init.d.ts +2 -0
  9. package/dist/esm/commands/init.js +3 -0
  10. package/dist/esm/commands/init.js.map +1 -1
  11. package/dist/esm/config.d.ts +22 -0
  12. package/dist/esm/errors.js +5 -0
  13. package/dist/esm/errors.js.map +1 -1
  14. package/dist/esm/utils/findConfig.d.ts +8 -0
  15. package/dist/esm/utils/findConfig.js +9 -0
  16. package/dist/esm/utils/findConfig.js.map +1 -1
  17. package/dist/esm/utils/format.js +1 -0
  18. package/dist/esm/utils/format.js.map +1 -1
  19. package/dist/esm/utils/isUsingTypescript.js +1 -0
  20. package/dist/esm/utils/isUsingTypescript.js.map +1 -1
  21. package/dist/esm/utils/loadEnv.js +9 -4
  22. package/dist/esm/utils/loadEnv.js.map +1 -1
  23. package/dist/esm/utils/resolveConfig.d.ts +7 -0
  24. package/dist/esm/utils/resolveConfig.js +6 -0
  25. package/dist/esm/utils/resolveConfig.js.map +1 -1
  26. package/dist/esm/version.d.ts +1 -1
  27. package/dist/esm/version.js +3 -1
  28. package/dist/esm/version.js.map +1 -1
  29. package/dist/types/version.d.ts +1 -1
  30. package/dist/types/version.d.ts.map +1 -1
  31. package/package.json +7 -8
  32. package/src/commands/generate/phases/plugin-generator/get-contract-gen.ts +1 -1
  33. package/src/version.ts +1 -1
  34. package/dist/esm/package.json +0 -1
package/dist/esm/cli.js CHANGED
@@ -21,6 +21,7 @@ cli.help();
21
21
  cli.version(VERSION);
22
22
  void (async () => {
23
23
  try {
24
+ // Parse CLI args without running command
24
25
  cli.parse(process.argv, { run: false });
25
26
  if (!cli.matchedCommand) {
26
27
  if (cli.args.length === 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAwB,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAoB,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC;AAE7B,GAAG;KACA,OAAO,CAAC,MAAM,EAAE,mCAAmC,CAAC;KACpD,MAAM,CAAC,qBAAqB,EAAE,8BAA8B,CAAC;KAC7D,MAAM,CAAC,mBAAmB,EAAE,2CAA2C,CAAC;KACxE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,OAAO,CAAC;KACjC,MAAM,CAAC,KAAK,EAAE,OAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAEzD,GAAG;KACA,OAAO,CACN,UAAU,EACV,6EAA6E,CAC9E;KACA,MAAM,CAAC,qBAAqB,EAAE,8BAA8B,CAAC;KAC7D,MAAM,CAAC,mBAAmB,EAAE,2CAA2C,CAAC;KACxE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,WAAW,CAAC;KACrC,MAAM,CAAC,KAAK,EAAE,OAAwB,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AAEjE,GAAG,CAAC,IAAI,EAAE,CAAC;AACX,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAErB,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,IAAI,CAAC;QAEH,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;YACxB,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO;oBAAE,GAAG,CAAC,UAAU,EAAE,CAAC;YAClE,CAAC;;gBAAM,MAAM,IAAI,KAAK,CAAC,oBAAoB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnE,CAAC;QACD,MAAM,GAAG,CAAC,iBAAiB,EAAE,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,KAAM,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { cac } from \"cac\";\nimport { generate, type GenerateOptions } from \"./commands/generate/index.js\";\nimport { init, type InitOptions } from \"./commands/init.js\";\nimport * as logger from \"./logger.js\";\nimport { VERSION } from \"./version.js\";\n\nconst cli = cac(\"plugingen\");\n\ncli\n .command(\"init\", \"Initialize a new plugingen config\")\n .option(\"-c, --config <path>\", \"[string] path to config file\")\n .option(\"-r, --root <path>\", \"[string] root path to resolve config from\")\n .example((name) => `${name} init`)\n .action(async (options: InitOptions) => init(options));\n\ncli\n .command(\n \"generate\",\n \"Generate code for all of the plugins configured within the plugingen config\"\n )\n .option(\"-c, --config <path>\", \"[string] path to config file\")\n .option(\"-r, --root <path>\", \"[string] root path to resolve config from\")\n .example((name) => `${name} generate`)\n .action(async (options: GenerateOptions) => generate(options));\n\ncli.help();\ncli.version(VERSION);\n\nvoid (async () => {\n try {\n // Parse CLI args without running command\n cli.parse(process.argv, { run: false });\n if (!cli.matchedCommand) {\n if (cli.args.length === 0) {\n if (!cli.options.help && !cli.options.version) cli.outputHelp();\n } else throw new Error(`Unknown command: ${cli.args.join(\" \")}`);\n }\n await cli.runMatchedCommand();\n } catch (error) {\n logger.error(`\\n${(error as Error).message}`);\n process.exit(1);\n }\n})();\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAwB,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAoB,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC;AAE7B,GAAG;KACA,OAAO,CAAC,MAAM,EAAE,mCAAmC,CAAC;KACpD,MAAM,CAAC,qBAAqB,EAAE,8BAA8B,CAAC;KAC7D,MAAM,CAAC,mBAAmB,EAAE,2CAA2C,CAAC;KACxE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,OAAO,CAAC;KACjC,MAAM,CAAC,KAAK,EAAE,OAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAEzD,GAAG;KACA,OAAO,CACN,UAAU,EACV,6EAA6E,CAC9E;KACA,MAAM,CAAC,qBAAqB,EAAE,8BAA8B,CAAC;KAC7D,MAAM,CAAC,mBAAmB,EAAE,2CAA2C,CAAC;KACxE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,WAAW,CAAC;KACrC,MAAM,CAAC,KAAK,EAAE,OAAwB,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AAEjE,GAAG,CAAC,IAAI,EAAE,CAAC;AACX,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAErB,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,IAAI,CAAC;QACH,yCAAyC;QACzC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;YACxB,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO;oBAAE,GAAG,CAAC,UAAU,EAAE,CAAC;YAClE,CAAC;;gBAAM,MAAM,IAAI,KAAK,CAAC,oBAAoB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnE,CAAC;QACD,MAAM,GAAG,CAAC,iBAAiB,EAAE,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,KAAM,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { cac } from \"cac\";\nimport { generate, type GenerateOptions } from \"./commands/generate/index.js\";\nimport { init, type InitOptions } from \"./commands/init.js\";\nimport * as logger from \"./logger.js\";\nimport { VERSION } from \"./version.js\";\n\nconst cli = cac(\"plugingen\");\n\ncli\n .command(\"init\", \"Initialize a new plugingen config\")\n .option(\"-c, --config <path>\", \"[string] path to config file\")\n .option(\"-r, --root <path>\", \"[string] root path to resolve config from\")\n .example((name) => `${name} init`)\n .action(async (options: InitOptions) => init(options));\n\ncli\n .command(\n \"generate\",\n \"Generate code for all of the plugins configured within the plugingen config\"\n )\n .option(\"-c, --config <path>\", \"[string] path to config file\")\n .option(\"-r, --root <path>\", \"[string] root path to resolve config from\")\n .example((name) => `${name} generate`)\n .action(async (options: GenerateOptions) => generate(options));\n\ncli.help();\ncli.version(VERSION);\n\nvoid (async () => {\n try {\n // Parse CLI args without running command\n cli.parse(process.argv, { run: false });\n if (!cli.matchedCommand) {\n if (cli.args.length === 0) {\n if (!cli.options.help && !cli.options.version) cli.outputHelp();\n } else throw new Error(`Unknown command: ${cli.args.join(\" \")}`);\n }\n await cli.runMatchedCommand();\n } catch (error) {\n logger.error(`\\n${(error as Error).message}`);\n process.exit(1);\n }\n})();\n"]}
@@ -1,6 +1,8 @@
1
1
  import z from "zod";
2
2
  declare const GenerateSchema: z.ZodObject<{
3
+ /** Path to config file */
3
4
  config: z.ZodOptional<z.ZodString>;
5
+ /** Directory to search for config file */
4
6
  root: z.ZodOptional<z.ZodString>;
5
7
  }, "strip", z.ZodTypeAny, {
6
8
  config?: string | undefined;
@@ -18,7 +18,9 @@ import { ExecutionAbiGenPhase } from "./phases/execution-abi-gen.js";
18
18
  import { PluginActionsGenPhase } from "./phases/plugin-actions/index.js";
19
19
  import { PluginGeneratorPhase } from "./phases/plugin-generator/index.js";
20
20
  const GenerateSchema = z.object({
21
+ /** Path to config file */
21
22
  config: z.string().optional(),
23
+ /** Directory to search for config file */
22
24
  root: z.string().optional(),
23
25
  });
24
26
  export async function generate(options = {}) {
@@ -30,6 +32,7 @@ export async function generate(options = {}) {
30
32
  throw error;
31
33
  throw error;
32
34
  }
35
+ // Get cli config file
33
36
  const configPath = await findConfig(options);
34
37
  if (!configPath) {
35
38
  if (options.config) {
@@ -38,6 +41,11 @@ export async function generate(options = {}) {
38
41
  throw new Error("Config not found");
39
42
  }
40
43
  const resolvedConfigs = await resolveConfig({ configPath });
44
+ // TODO: need to use this in the phases below and add support for JS within the generated code
45
+ // To support that we will likely need to:
46
+ // 1. generate a types.ts file instead of appending the types to the top of the generated code
47
+ // 2. in generated plugin.(ts|js) files we will either import the types or use the type reference comment
48
+ // 3. in generated plugin files we need to check if TS when specifying the types of methods
41
49
  const isTypeScript = await getIsUsingTypeScript();
42
50
  if (!isTypeScript) {
43
51
  throw new Error("Only typescript is supported at the moment.");
@@ -48,6 +56,7 @@ export async function generate(options = {}) {
48
56
  for (const config of configs) {
49
57
  if (isArrayConfig)
50
58
  logger.log(`Using config ${pc.gray(basename(configPath))}`);
59
+ // group configs by out dir
51
60
  if (!config.outDir)
52
61
  throw new Error("outDir is required.");
53
62
  if (outNames.has(config.outDir))
@@ -55,12 +64,14 @@ export async function generate(options = {}) {
55
64
  outNames.add(config.outDir);
56
65
  const spinner = logger.spinner();
57
66
  const pluginConfigs = config.plugins;
67
+ // Get contracts from config
58
68
  spinner.start("Resolving plugin contracts");
59
69
  if (!pluginConfigs || !pluginConfigs.length) {
60
70
  logger.warn("no plugins found in config");
61
71
  spinner.fail();
62
72
  return;
63
73
  }
74
+ // TODO: check that plugins are unique
64
75
  const plugins = pluginConfigs.map((plugin) => {
65
76
  const chain = plugin.chain ?? config.chain;
66
77
  const transport = http(plugin.rpcUrl ?? config.rpcUrl);
@@ -82,6 +93,7 @@ export async function generate(options = {}) {
82
93
  };
83
94
  });
84
95
  spinner.succeed();
96
+ // Generate plugin files
85
97
  await Promise.all(plugins.map((plugin) => generatePlugin({
86
98
  pluginConfig: plugin.pluginConfig,
87
99
  contract: plugin.contract,
@@ -89,6 +101,7 @@ export async function generate(options = {}) {
89
101
  })));
90
102
  }
91
103
  }
104
+ // Add more phases here if needed
92
105
  const phases = [
93
106
  ContractAddressesGenPhase,
94
107
  PluginGeneratorPhase,
@@ -99,6 +112,7 @@ const phases = [
99
112
  const generatePlugin = async ({ pluginConfig, contract, config, }) => {
100
113
  const spinner = logger.spinner();
101
114
  spinner.start(`Generating plugin ${pc.gray(pluginConfig.name)}`);
115
+ // Setup plugin generator
102
116
  const imports = new Map();
103
117
  const addImport = (moduleName, member) => {
104
118
  if (!imports.has(moduleName)) {
@@ -126,6 +140,7 @@ const generatePlugin = async ({ pluginConfig, contract, config, }) => {
126
140
  isPublic: isPublic ?? false,
127
141
  });
128
142
  };
143
+ // TODO: we need to handle the case where this isn't typescript because right now we generate types in here
129
144
  const result = await asyncPipe(...phases)({
130
145
  addImport,
131
146
  addType,
@@ -134,6 +149,7 @@ const generatePlugin = async ({ pluginConfig, contract, config, }) => {
134
149
  contract,
135
150
  pluginConfig,
136
151
  });
152
+ // Aggregate Result of phase
137
153
  const finalContent = dedent `
138
154
  ${Array.from(types.entries())
139
155
  .map(([name, type]) => `${type.isPublic ? "export" : ""} type ${name} = ${type.definition};`)
@@ -161,6 +177,12 @@ const generatePlugin = async ({ pluginConfig, contract, config, }) => {
161
177
  const writePlugin = async ({ config, content, imports, pluginConfig, }) => {
162
178
  const isTypeScript = await getIsUsingTypeScript();
163
179
  const pluginRegEx = /[pP]lugin/g;
180
+ // TODO: because we are now generating these ourselves, we have a lot more flexibility
181
+ // We could:
182
+ // 1. generate a types.ts file containing the type defs intead of merging them with content
183
+ // 2. generate an extensions.ts file which doesn't get overwritten on each generation
184
+ // 3. generate an index.ts file which correctly exports all of the types + exports the output of extensions.ts
185
+ // so that it's easier to extend and import without conflicts
164
186
  const pluginPath = `${config.outDir}/${kebabCase(pluginConfig.name.replaceAll(pluginRegEx, ""))}/plugin.${isTypeScript ? "ts" : "js"}`;
165
187
  const code = dedent `
166
188
  ${imports}
@@ -169,6 +191,7 @@ const writePlugin = async ({ config, content, imports, pluginConfig, }) => {
169
191
  `;
170
192
  const spinner = logger.spinner();
171
193
  spinner.start(`Writing plugin to ${pc.gray(pluginPath)}`);
194
+ // Format and write output
172
195
  const cwd = process.cwd();
173
196
  const outPath = resolve(cwd, pluginPath);
174
197
  await fs.ensureDir(dir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AAM,CAAC,OAAO,EAAE,CAAC;IACjC,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAE1D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACzC,MAAM,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,CAAC,OAAO,EAAE,CAAC;AACpB,CAAC,CAAC","sourcesContent":["import { asyncPipe } from \"@aa-sdk/core\";\nimport { kebabCase } from \"change-case\";\nimport dedent from \"dedent\";\nimport { default as fs } from \"fs-extra\";\nimport { basename, dirname, resolve } from \"pathe\";\nimport pc from \"picocolors\";\nimport {\n createPublicClient,\n getContract,\n http,\n type GetContractReturnType,\n type PublicClient,\n} from \"viem\";\nimport z from \"zod\";\nimport type { Config, PluginConfig } from \"../../config.js\";\nimport { IPluginAbi } from \"../../IPlugin.js\";\nimport * as logger from \"../../logger.js\";\nimport { findConfig } from \"../../utils/findConfig.js\";\nimport { format } from \"../../utils/format.js\";\nimport { getIsUsingTypeScript } from \"../../utils/isUsingTypescript.js\";\nimport { resolveConfig } from \"../../utils/resolveConfig.js\";\nimport { ContractAbiGenPhase } from \"./phases/contract-abi-gen.js\";\nimport { ContractAddressesGenPhase } from \"./phases/contract-addresses-gen.js\";\nimport { ExecutionAbiGenPhase } from \"./phases/execution-abi-gen.js\";\nimport { PluginActionsGenPhase } from \"./phases/plugin-actions/index.js\";\nimport { PluginGeneratorPhase } from \"./phases/plugin-generator/index.js\";\nimport type { Phase, PhaseInput } from \"./types.js\";\n\nconst GenerateSchema = z.object({\n /** Path to config file */\n config: z.string().optional(),\n /** Directory to search for config file */\n root: z.string().optional(),\n});\n\nexport type GenerateOptions = z.infer<typeof GenerateSchema>;\n\nexport async function generate(options: GenerateOptions = {}) {\n try {\n options = await GenerateSchema.parseAsync(options);\n } catch (error) {\n if (error instanceof z.ZodError) throw error;\n throw error;\n }\n\n // Get cli config file\n const configPath = await findConfig(options);\n if (!configPath) {\n if (options.config) {\n throw new Error(`Config not found at ${pc.gray(options.config)}`);\n }\n\n throw new Error(\"Config not found\");\n }\n\n const resolvedConfigs = await resolveConfig({ configPath });\n // TODO: need to use this in the phases below and add support for JS within the generated code\n // To support that we will likely need to:\n // 1. generate a types.ts file instead of appending the types to the top of the generated code\n // 2. in generated plugin.(ts|js) files we will either import the types or use the type reference comment\n // 3. in generated plugin files we need to check if TS when specifying the types of methods\n const isTypeScript = await getIsUsingTypeScript();\n if (!isTypeScript) {\n throw new Error(\"Only typescript is supported at the moment.\");\n }\n\n const outNames = new Set<string>();\n const isArrayConfig = Array.isArray(resolvedConfigs);\n const configs = isArrayConfig ? resolvedConfigs : [resolvedConfigs];\n\n for (const config of configs) {\n if (isArrayConfig)\n logger.log(`Using config ${pc.gray(basename(configPath))}`);\n\n // group configs by out dir\n if (!config.outDir) throw new Error(\"outDir is required.\");\n if (outNames.has(config.outDir))\n throw new Error(`outDir \"${config.outDir}\" must be unique.`);\n outNames.add(config.outDir);\n const spinner = logger.spinner();\n const pluginConfigs = config.plugins;\n\n // Get contracts from config\n spinner.start(\"Resolving plugin contracts\");\n if (!pluginConfigs || !pluginConfigs.length) {\n logger.warn(\"no plugins found in config\");\n spinner.fail();\n return;\n }\n\n // TODO: check that plugins are unique\n const plugins = pluginConfigs.map((plugin) => {\n const chain = plugin.chain ?? config.chain;\n const transport = http(plugin.rpcUrl ?? config.rpcUrl);\n\n const client = createPublicClient({\n chain,\n transport,\n });\n\n if (!(chain.id in plugin.addresses)) {\n spinner.fail();\n throw new Error(\n `contract address missing for the reference chain ${chain.id}`\n );\n }\n\n return {\n contract: getContract({\n address: plugin.addresses[chain.id],\n abi: IPluginAbi,\n client,\n }),\n pluginConfig: plugin,\n };\n });\n spinner.succeed();\n\n // Generate plugin files\n await Promise.all(\n plugins.map((plugin) =>\n generatePlugin({\n pluginConfig: plugin.pluginConfig,\n contract: plugin.contract,\n config,\n })\n )\n );\n }\n}\n\n// Add more phases here if needed\nconst phases: Phase[] = [\n ContractAddressesGenPhase,\n PluginGeneratorPhase,\n PluginActionsGenPhase,\n ExecutionAbiGenPhase,\n ContractAbiGenPhase,\n];\n\nconst generatePlugin = async ({\n pluginConfig,\n contract,\n config,\n}: {\n pluginConfig: PluginConfig;\n contract: GetContractReturnType<typeof IPluginAbi, PublicClient>;\n config: Config;\n}) => {\n const spinner = logger.spinner();\n spinner.start(`Generating plugin ${pc.gray(pluginConfig.name)}`);\n // Setup plugin generator\n const imports: Map<\n string,\n {\n types: Set<string>;\n members: Set<string>;\n }\n > = new Map();\n const addImport: PhaseInput[\"addImport\"] = (moduleName, member) => {\n if (!imports.has(moduleName)) {\n imports.set(moduleName, {\n types: new Set(),\n members: new Set(),\n });\n }\n\n const module = imports.get(moduleName)!;\n if (member.isType) {\n module.types.add(member.name);\n } else {\n module.members.add(member.name);\n }\n };\n const content: string[] = [];\n const types: Map<string, { definition: string; isPublic: boolean }> =\n new Map();\n const addType: PhaseInput[\"addType\"] = (typeName, typeDef, isPublic) => {\n if (types.has(typeName)) {\n throw new Error(`Type ${typeName} already exists`);\n }\n\n types.set(typeName, {\n definition: typeDef.replace(\";\", \"\"),\n isPublic: isPublic ?? false,\n });\n };\n\n // TODO: we need to handle the case where this isn't typescript because right now we generate types in here\n const result = await asyncPipe(...phases)({\n addImport,\n addType,\n content,\n config,\n contract,\n pluginConfig,\n });\n\n // Aggregate Result of phase\n const finalContent = dedent`\n ${Array.from(types.entries())\n .map(\n ([name, type]) =>\n `${type.isPublic ? \"export\" : \"\"} type ${name} = ${type.definition};`\n )\n .join(\"\\n\\n\")}\n\n ${result.content.join(\"\\n\\n\")}\n`;\n\n const finalImports = Array.from(imports.entries())\n .map(([moduleName, { members, types }]) => {\n return dedent`\n import { ${Array.from(members.values()).join(\",\")} ${\n members.size > 0 ? \",\" : \"\"\n } ${Array.from(types.values())\n .map((x) => `type ${x}`)\n .join(\",\")} } from \"${moduleName}\";\n `;\n })\n .join(\"\\n\");\n spinner.succeed();\n await writePlugin({\n config,\n content: finalContent,\n imports: finalImports,\n pluginConfig,\n });\n};\n\nconst writePlugin = async ({\n config,\n content,\n imports,\n pluginConfig,\n}: {\n pluginConfig: PluginConfig;\n config: Config;\n content: string;\n imports: string;\n}) => {\n const isTypeScript = await getIsUsingTypeScript();\n\n const pluginRegEx: RegExp = /[pP]lugin/g;\n // TODO: because we are now generating these ourselves, we have a lot more flexibility\n // We could:\n // 1. generate a types.ts file containing the type defs intead of merging them with content\n // 2. generate an extensions.ts file which doesn't get overwritten on each generation\n // 3. generate an index.ts file which correctly exports all of the types + exports the output of extensions.ts\n // so that it's easier to extend and import without conflicts\n const pluginPath = `${config.outDir}/${kebabCase(\n pluginConfig.name.replaceAll(pluginRegEx, \"\")\n )}/plugin.${isTypeScript ? \"ts\" : \"js\"}`;\n\n const code = dedent`\n ${imports}\n\n ${content}\n`;\n\n const spinner = logger.spinner();\n spinner.start(`Writing plugin to ${pc.gray(pluginPath)}`);\n // Format and write output\n const cwd = process.cwd();\n const outPath = resolve(cwd, pluginPath);\n await fs.ensureDir(dirname(outPath));\n const formatted = await format(code);\n await fs.writeFile(outPath, formatted);\n spinner.succeed();\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/generate/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,UAAU,CAAC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Z,CAAC;IAEA,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IACjC,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1D,0BAA0B;IAC1B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACzC,MAAM,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,CAAC,OAAO,EAAE,CAAC;AACpB,CAAC,CAAC","sourcesContent":["import { asyncPipe } from \"@aa-sdk/core\";\nimport { kebabCase } from \"change-case\";\nimport dedent from \"dedent\";\nimport { default as fs } from \"fs-extra\";\nimport { basename, dirname, resolve } from \"pathe\";\nimport pc from \"picocolors\";\nimport {\n createPublicClient,\n getContract,\n http,\n type GetContractReturnType,\n type PublicClient,\n} from \"viem\";\nimport z from \"zod\";\nimport type { Config, PluginConfig } from \"../../config.js\";\nimport { IPluginAbi } from \"../../IPlugin.js\";\nimport * as logger from \"../../logger.js\";\nimport { findConfig } from \"../../utils/findConfig.js\";\nimport { format } from \"../../utils/format.js\";\nimport { getIsUsingTypeScript } from \"../../utils/isUsingTypescript.js\";\nimport { resolveConfig } from \"../../utils/resolveConfig.js\";\nimport { ContractAbiGenPhase } from \"./phases/contract-abi-gen.js\";\nimport { ContractAddressesGenPhase } from \"./phases/contract-addresses-gen.js\";\nimport { ExecutionAbiGenPhase } from \"./phases/execution-abi-gen.js\";\nimport { PluginActionsGenPhase } from \"./phases/plugin-actions/index.js\";\nimport { PluginGeneratorPhase } from \"./phases/plugin-generator/index.js\";\nimport type { Phase, PhaseInput } from \"./types.js\";\n\nconst GenerateSchema = z.object({\n /** Path to config file */\n config: z.string().optional(),\n /** Directory to search for config file */\n root: z.string().optional(),\n});\n\nexport type GenerateOptions = z.infer<typeof GenerateSchema>;\n\nexport async function generate(options: GenerateOptions = {}) {\n try {\n options = await GenerateSchema.parseAsync(options);\n } catch (error) {\n if (error instanceof z.ZodError) throw error;\n throw error;\n }\n\n // Get cli config file\n const configPath = await findConfig(options);\n if (!configPath) {\n if (options.config) {\n throw new Error(`Config not found at ${pc.gray(options.config)}`);\n }\n\n throw new Error(\"Config not found\");\n }\n\n const resolvedConfigs = await resolveConfig({ configPath });\n // TODO: need to use this in the phases below and add support for JS within the generated code\n // To support that we will likely need to:\n // 1. generate a types.ts file instead of appending the types to the top of the generated code\n // 2. in generated plugin.(ts|js) files we will either import the types or use the type reference comment\n // 3. in generated plugin files we need to check if TS when specifying the types of methods\n const isTypeScript = await getIsUsingTypeScript();\n if (!isTypeScript) {\n throw new Error(\"Only typescript is supported at the moment.\");\n }\n\n const outNames = new Set<string>();\n const isArrayConfig = Array.isArray(resolvedConfigs);\n const configs = isArrayConfig ? resolvedConfigs : [resolvedConfigs];\n\n for (const config of configs) {\n if (isArrayConfig)\n logger.log(`Using config ${pc.gray(basename(configPath))}`);\n\n // group configs by out dir\n if (!config.outDir) throw new Error(\"outDir is required.\");\n if (outNames.has(config.outDir))\n throw new Error(`outDir \"${config.outDir}\" must be unique.`);\n outNames.add(config.outDir);\n const spinner = logger.spinner();\n const pluginConfigs = config.plugins;\n\n // Get contracts from config\n spinner.start(\"Resolving plugin contracts\");\n if (!pluginConfigs || !pluginConfigs.length) {\n logger.warn(\"no plugins found in config\");\n spinner.fail();\n return;\n }\n\n // TODO: check that plugins are unique\n const plugins = pluginConfigs.map((plugin) => {\n const chain = plugin.chain ?? config.chain;\n const transport = http(plugin.rpcUrl ?? config.rpcUrl);\n\n const client = createPublicClient({\n chain,\n transport,\n });\n\n if (!(chain.id in plugin.addresses)) {\n spinner.fail();\n throw new Error(\n `contract address missing for the reference chain ${chain.id}`\n );\n }\n\n return {\n contract: getContract({\n address: plugin.addresses[chain.id],\n abi: IPluginAbi,\n client,\n }),\n pluginConfig: plugin,\n };\n });\n spinner.succeed();\n\n // Generate plugin files\n await Promise.all(\n plugins.map((plugin) =>\n generatePlugin({\n pluginConfig: plugin.pluginConfig,\n contract: plugin.contract,\n config,\n })\n )\n );\n }\n}\n\n// Add more phases here if needed\nconst phases: Phase[] = [\n ContractAddressesGenPhase,\n PluginGeneratorPhase,\n PluginActionsGenPhase,\n ExecutionAbiGenPhase,\n ContractAbiGenPhase,\n];\n\nconst generatePlugin = async ({\n pluginConfig,\n contract,\n config,\n}: {\n pluginConfig: PluginConfig;\n contract: GetContractReturnType<typeof IPluginAbi, PublicClient>;\n config: Config;\n}) => {\n const spinner = logger.spinner();\n spinner.start(`Generating plugin ${pc.gray(pluginConfig.name)}`);\n // Setup plugin generator\n const imports: Map<\n string,\n {\n types: Set<string>;\n members: Set<string>;\n }\n > = new Map();\n const addImport: PhaseInput[\"addImport\"] = (moduleName, member) => {\n if (!imports.has(moduleName)) {\n imports.set(moduleName, {\n types: new Set(),\n members: new Set(),\n });\n }\n\n const module = imports.get(moduleName)!;\n if (member.isType) {\n module.types.add(member.name);\n } else {\n module.members.add(member.name);\n }\n };\n const content: string[] = [];\n const types: Map<string, { definition: string; isPublic: boolean }> =\n new Map();\n const addType: PhaseInput[\"addType\"] = (typeName, typeDef, isPublic) => {\n if (types.has(typeName)) {\n throw new Error(`Type ${typeName} already exists`);\n }\n\n types.set(typeName, {\n definition: typeDef.replace(\";\", \"\"),\n isPublic: isPublic ?? false,\n });\n };\n\n // TODO: we need to handle the case where this isn't typescript because right now we generate types in here\n const result = await asyncPipe(...phases)({\n addImport,\n addType,\n content,\n config,\n contract,\n pluginConfig,\n });\n\n // Aggregate Result of phase\n const finalContent = dedent`\n ${Array.from(types.entries())\n .map(\n ([name, type]) =>\n `${type.isPublic ? \"export\" : \"\"} type ${name} = ${type.definition};`\n )\n .join(\"\\n\\n\")}\n\n ${result.content.join(\"\\n\\n\")}\n`;\n\n const finalImports = Array.from(imports.entries())\n .map(([moduleName, { members, types }]) => {\n return dedent`\n import { ${Array.from(members.values()).join(\",\")} ${\n members.size > 0 ? \",\" : \"\"\n } ${Array.from(types.values())\n .map((x) => `type ${x}`)\n .join(\",\")} } from \"${moduleName}\";\n `;\n })\n .join(\"\\n\");\n spinner.succeed();\n await writePlugin({\n config,\n content: finalContent,\n imports: finalImports,\n pluginConfig,\n });\n};\n\nconst writePlugin = async ({\n config,\n content,\n imports,\n pluginConfig,\n}: {\n pluginConfig: PluginConfig;\n config: Config;\n content: string;\n imports: string;\n}) => {\n const isTypeScript = await getIsUsingTypeScript();\n\n const pluginRegEx: RegExp = /[pP]lugin/g;\n // TODO: because we are now generating these ourselves, we have a lot more flexibility\n // We could:\n // 1. generate a types.ts file containing the type defs intead of merging them with content\n // 2. generate an extensions.ts file which doesn't get overwritten on each generation\n // 3. generate an index.ts file which correctly exports all of the types + exports the output of extensions.ts\n // so that it's easier to extend and import without conflicts\n const pluginPath = `${config.outDir}/${kebabCase(\n pluginConfig.name.replaceAll(pluginRegEx, \"\")\n )}/plugin.${isTypeScript ? \"ts\" : \"js\"}`;\n\n const code = dedent`\n ${imports}\n\n ${content}\n`;\n\n const spinner = logger.spinner();\n spinner.start(`Writing plugin to ${pc.gray(pluginPath)}`);\n // Format and write output\n const cwd = process.cwd();\n const outPath = resolve(cwd, pluginPath);\n await fs.ensureDir(dirname(outPath));\n const formatted = await format(code);\n await fs.writeFile(outPath, formatted);\n spinner.succeed();\n};\n"]}
@@ -19,7 +19,7 @@ export const GetContractGenPhase = async (input) => {
19
19
  address: address || addresses[client.chain.id],
20
20
  abi: ${pluginConfig.name}Abi,
21
21
  client: client,
22
- });
22
+ }) as GetContractReturnType<typeof ${pluginConfig.name}Abi, PublicClient, Address>;
23
23
  }`);
24
24
  return input;
25
25
  };
@@ -1 +1 @@
1
- {"version":3,"file":"get-contract-gen.js","sourceRoot":"","sources":["../../../../../../src/commands/generate/phases/plugin-generator/get-contract-gen.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,MAAM,CAAC,MAAM,mBAAmB,GAAU,KAAK,EAAE,KAAK,EAAE,EAAE;IACxD,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IAEnD,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1D,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACnE,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACrD,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,SAAS,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC,CAAC;IAE1D,OAAO,CAAC,IAAI,CAAC,MAAM,CAAA;;;;oCAIe,YAAY,CAAC,IAAI;;;;;eAKtC,YAAY,CAAC,IAAI;;;IAG5B,CAAC,CAAC;IAEJ,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import dedent from \"dedent\";\nimport type { Phase } from \"../../types\";\n\nexport const GetContractGenPhase: Phase = async (input) => {\n const { content, pluginConfig, addImport } = input;\n\n addImport(\"viem\", { name: \"getContract\", isType: false });\n addImport(\"viem\", { name: \"GetContractReturnType\", isType: true });\n addImport(\"viem\", { name: \"Address\", isType: true });\n addImport(\"viem\", { name: \"Transport\", isType: true });\n addImport(\"viem\", { name: \"PublicClient\", isType: true });\n addImport(\"viem\", { name: \"Client\", isType: true });\n addImport(\"@aa-sdk/core\", { name: \"ChainNotFoundError\" });\n\n content.push(dedent`\n getContract: <C extends Client>(\n client: C,\n address?: Address\n ): GetContractReturnType<typeof ${pluginConfig.name}Abi, PublicClient, Address> => {\n if (!client.chain) throw new ChainNotFoundError();\n\n return getContract({\n address: address || addresses[client.chain.id],\n abi: ${pluginConfig.name}Abi,\n client: client,\n });\n }`);\n\n return input;\n};\n"]}
1
+ {"version":3,"file":"get-contract-gen.js","sourceRoot":"","sources":["../../../../../../src/commands/generate/phases/plugin-generator/get-contract-gen.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,MAAM,CAAC,MAAM,mBAAmB,GAAU,KAAK,EAAE,KAAK,EAAE,EAAE;IACxD,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IAEnD,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1D,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACnE,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACrD,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,SAAS,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC,CAAC;IAE1D,OAAO,CAAC,IAAI,CAAC,MAAM,CAAA;;;;oCAIe,YAAY,CAAC,IAAI;;;;;eAKtC,YAAY,CAAC,IAAI;;2CAEW,YAAY,CAAC,IAAI;IACxD,CAAC,CAAC;IAEJ,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import dedent from \"dedent\";\nimport type { Phase } from \"../../types\";\n\nexport const GetContractGenPhase: Phase = async (input) => {\n const { content, pluginConfig, addImport } = input;\n\n addImport(\"viem\", { name: \"getContract\", isType: false });\n addImport(\"viem\", { name: \"GetContractReturnType\", isType: true });\n addImport(\"viem\", { name: \"Address\", isType: true });\n addImport(\"viem\", { name: \"Transport\", isType: true });\n addImport(\"viem\", { name: \"PublicClient\", isType: true });\n addImport(\"viem\", { name: \"Client\", isType: true });\n addImport(\"@aa-sdk/core\", { name: \"ChainNotFoundError\" });\n\n content.push(dedent`\n getContract: <C extends Client>(\n client: C,\n address?: Address\n ): GetContractReturnType<typeof ${pluginConfig.name}Abi, PublicClient, Address> => {\n if (!client.chain) throw new ChainNotFoundError();\n\n return getContract({\n address: address || addresses[client.chain.id],\n abi: ${pluginConfig.name}Abi,\n client: client,\n }) as GetContractReturnType<typeof ${pluginConfig.name}Abi, PublicClient, Address>;\n }`);\n\n return input;\n};\n"]}
@@ -1,5 +1,7 @@
1
1
  export type InitOptions = {
2
+ /** Path to config file */
2
3
  config?: string;
4
+ /** Directory to init config file */
3
5
  root?: string;
4
6
  };
5
7
  export declare function init(options?: InitOptions): Promise<string>;
@@ -1,3 +1,4 @@
1
+ // borrows heavily from https://github.com/wevm/wagmi/blob/main/packages/cli/src/commands/init.ts
1
2
  import dedent from "dedent";
2
3
  import { default as fs } from "fs-extra";
3
4
  import { relative, resolve } from "pathe";
@@ -21,6 +22,7 @@ export async function init(options = {}) {
21
22
  throw fromZodError(error, { prefix: "Invalid option" });
22
23
  throw error;
23
24
  }
25
+ // Check for existing config file
24
26
  const configPath = await findConfig(options);
25
27
  if (configPath) {
26
28
  logger.info(`Config already exists at ${pc.gray(relative(process.cwd(), configPath))}`);
@@ -28,6 +30,7 @@ export async function init(options = {}) {
28
30
  }
29
31
  const spinner = logger.spinner();
30
32
  spinner.start("Creating config");
33
+ // Check if project is using TypeScript
31
34
  const isUsingTypeScript = await getIsUsingTypeScript();
32
35
  const rootDir = resolve(options.root || process.cwd());
33
36
  let outPath;
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AASrE,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC5B,CAAC,CAAC;AAEH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,UAAuB,EAAE;IAClD,IAAI,CAAC;QACH,OAAO,GAAG,MAAM,UAA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AAC;QACN,OAAO,GAAG,MAAM,CAAC;;;;uBAIE,MAAM,CAAA;;;;;;;OAOtB,CAAC,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC;KAC/B,CAAC,CAAC;IACL,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,CAAC,OAAO,EAAE,CAAC;IAClB,MAAM,CAAC,OAAO,CACZ,qBAAqB,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC,EAAE,CACjE,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["// borrows heavily from https://github.com/wevm/wagmi/blob/main/packages/cli/src/commands/init.ts\nimport dedent from \"dedent\";\nimport { default as fs } from \"fs-extra\";\nimport { relative, resolve } from \"pathe\";\nimport pc from \"picocolors\";\nimport z from \"zod\";\nimport { fromZodError } from \"../errors.js\";\nimport * as logger from \"../logger.js\";\nimport { findConfig } from \"../utils/findConfig.js\";\nimport { format } from \"../utils/format.js\";\nimport { getIsUsingTypeScript } from \"../utils/isUsingTypescript.js\";\n\nexport type InitOptions = {\n /** Path to config file */\n config?: string;\n /** Directory to init config file */\n root?: string;\n};\n\nconst InitSchema = z.object({\n config: z.string().optional(),\n root: z.string().optional(),\n});\n\nexport async function init(options: InitOptions = {}) {\n try {\n options = await InitSchema.parseAsync(options);\n } catch (error) {\n if (error instanceof z.ZodError)\n throw fromZodError(error, { prefix: \"Invalid option\" });\n throw error;\n }\n\n // Check for existing config file\n const configPath = await findConfig(options);\n if (configPath) {\n logger.info(\n `Config already exists at ${pc.gray(relative(process.cwd(), configPath))}`\n );\n return configPath;\n }\n\n const spinner = logger.spinner();\n spinner.start(\"Creating config\");\n // Check if project is using TypeScript\n const isUsingTypeScript = await getIsUsingTypeScript();\n const rootDir = resolve(options.root || process.cwd());\n let outPath: string;\n if (options.config) {\n outPath = resolve(rootDir, options.config);\n } else {\n const extension = isUsingTypeScript ? \"ts\" : \"js\";\n outPath = resolve(rootDir, `plugingen.config.${extension}`);\n }\n\n let content: string;\n if (isUsingTypeScript) {\n content = dedent(`\n import { defineConfig } from '@account-kit/plugingen';\n import { sepolia } from \"viem/chains\";\n \n export default defineConfig({\n outDir: \"./src/generated\",\n chain: sepolia,\n rpcUrl: \"https://ethereum-sepolia.publicnode.com\",\n plugins: [],\n });\n `);\n } else {\n content = dedent(`\n // @ts-check\n\n /** @type {import('@account-kit/plugingen').Config} */\n export default ${dedent`\n {\n outDir: \"./src/generated\",\n chain: sepolia,\n rpcUrl: \"https://ethereum-sepolia.publicnode.com\",\n plugins: [],\n }\n `.replace(/\"(\\d*)\":/gm, \"$1:\")}\n `);\n }\n\n const formatted = await format(content);\n await fs.writeFile(outPath, formatted);\n spinner.succeed();\n logger.success(\n `Config created at ${pc.gray(relative(process.cwd(), outPath))}`\n );\n\n return outPath;\n}\n"]}
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AASrE,MAAM,UAAU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MAAM,SAAS,GAAG,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QAClD,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,oBAAoB,SAAS,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,IAAI,OAAe,CAAC;IACpB,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO,GAAG,MAAM,CAAC;;;;;;;;;;KAUhB,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,MAAM,CAAC;;;;uBAIE,MAAM,CAAA;;;;;;;OAOtB,CAAC,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC;KAC/B,CAAC,CAAC;IACL,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,CAAC,OAAO,EAAE,CAAC;IAClB,MAAM,CAAC,OAAO,CACZ,qBAAqB,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC,EAAE,CACjE,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["// borrows heavily from https://github.com/wevm/wagmi/blob/main/packages/cli/src/commands/init.ts\nimport dedent from \"dedent\";\nimport { default as fs } from \"fs-extra\";\nimport { relative, resolve } from \"pathe\";\nimport pc from \"picocolors\";\nimport z from \"zod\";\nimport { fromZodError } from \"../errors.js\";\nimport * as logger from \"../logger.js\";\nimport { findConfig } from \"../utils/findConfig.js\";\nimport { format } from \"../utils/format.js\";\nimport { getIsUsingTypeScript } from \"../utils/isUsingTypescript.js\";\n\nexport type InitOptions = {\n /** Path to config file */\n config?: string;\n /** Directory to init config file */\n root?: string;\n};\n\nconst InitSchema = z.object({\n config: z.string().optional(),\n root: z.string().optional(),\n});\n\nexport async function init(options: InitOptions = {}) {\n try {\n options = await InitSchema.parseAsync(options);\n } catch (error) {\n if (error instanceof z.ZodError)\n throw fromZodError(error, { prefix: \"Invalid option\" });\n throw error;\n }\n\n // Check for existing config file\n const configPath = await findConfig(options);\n if (configPath) {\n logger.info(\n `Config already exists at ${pc.gray(relative(process.cwd(), configPath))}`\n );\n return configPath;\n }\n\n const spinner = logger.spinner();\n spinner.start(\"Creating config\");\n // Check if project is using TypeScript\n const isUsingTypeScript = await getIsUsingTypeScript();\n const rootDir = resolve(options.root || process.cwd());\n let outPath: string;\n if (options.config) {\n outPath = resolve(rootDir, options.config);\n } else {\n const extension = isUsingTypeScript ? \"ts\" : \"js\";\n outPath = resolve(rootDir, `plugingen.config.${extension}`);\n }\n\n let content: string;\n if (isUsingTypeScript) {\n content = dedent(`\n import { defineConfig } from '@account-kit/plugingen';\n import { sepolia } from \"viem/chains\";\n \n export default defineConfig({\n outDir: \"./src/generated\",\n chain: sepolia,\n rpcUrl: \"https://ethereum-sepolia.publicnode.com\",\n plugins: [],\n });\n `);\n } else {\n content = dedent(`\n // @ts-check\n\n /** @type {import('@account-kit/plugingen').Config} */\n export default ${dedent`\n {\n outDir: \"./src/generated\",\n chain: sepolia,\n rpcUrl: \"https://ethereum-sepolia.publicnode.com\",\n plugins: [],\n }\n `.replace(/\"(\\d*)\":/gm, \"$1:\")}\n `);\n }\n\n const formatted = await format(content);\n await fs.writeFile(outPath, formatted);\n spinner.succeed();\n logger.success(\n `Config created at ${pc.gray(relative(process.cwd(), outPath))}`\n );\n\n return outPath;\n}\n"]}
@@ -1,12 +1,34 @@
1
1
  import type { Abi, Address, Chain, Hex, parseAbiParameters } from "viem";
2
2
  import type { Evaluate, MaybeArray, MaybePromise } from "./types";
3
3
  export type ContractConfig<chainId extends number = number, requiredChainId extends number | undefined = undefined> = {
4
+ /**
5
+ * Contract ABI
6
+ */
4
7
  abi: Abi;
8
+ /**
9
+ * Contract address or addresses.
10
+ *
11
+ * Accepts an object `{ [chainId]: address }` to support multiple chains.
12
+ *
13
+ * @example
14
+ * '0x314159265dd8dbb310642f98f50c066173c1259b'
15
+ *
16
+ * @example
17
+ * {
18
+ * 1: '0x314159265dd8dbb310642f98f50c066173c1259b',
19
+ * 5: '0x112234455c3a32fd11230c42e7bccd4a84e02010',
20
+ * }
21
+ */
5
22
  address?: Address | (requiredChainId extends number ? Record<requiredChainId, Address> & Partial<Record<chainId, Address>> : Record<chainId, Address>) | undefined;
23
+ /**
24
+ * Name of contract.
25
+ */
6
26
  name: string;
7
27
  };
8
28
  export type Contract = Evaluate<ContractConfig & {
29
+ /** Generated string content */
9
30
  content: string;
31
+ /** Meta info about contract */
10
32
  meta: {
11
33
  abiName: string;
12
34
  addressName?: string | undefined;
@@ -1,4 +1,5 @@
1
1
  import {} from "zod";
2
+ // from https://github.com/wevm/wagmi/blob/main/packages/cli/src/errors.ts
2
3
  class ValidationError extends Error {
3
4
  constructor(message, options) {
4
5
  super(message);
@@ -11,6 +12,7 @@ class ValidationError extends Error {
11
12
  this.details = options.details;
12
13
  }
13
14
  }
15
+ // From https://github.com/causaly/zod-validation-error
14
16
  export function fromZodError(zError, { maxIssuesInMessage = 99, issueSeparator = "\n- ", prefixSeparator = "\n- ", prefix = "Validation Error", } = {}) {
15
17
  function joinPath(arr) {
16
18
  return arr.reduce((acc, value) => {
@@ -21,13 +23,16 @@ export function fromZodError(zError, { maxIssuesInMessage = 99, issueSeparator =
21
23
  }, "");
22
24
  }
23
25
  const reason = zError.errors
26
+ // limit max number of issues printed in the reason section
24
27
  .slice(0, maxIssuesInMessage)
28
+ // format error message
25
29
  .map((issue) => {
26
30
  const { message, path } = issue;
27
31
  if (path.length > 0)
28
32
  return `${message} at \`${joinPath(path)}\``;
29
33
  return message;
30
34
  })
35
+ // concat as string
31
36
  .join(issueSeparator);
32
37
  const message = reason ? [prefix, reason].join(prefixSeparator) : prefix;
33
38
  return new ValidationError(message, {
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"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CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAEzE,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE;QAClC,OAAO,EAAE,MAAM,CAAC,MAAM;KACvB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type z } from \"zod\";\n\n// from https://github.com/wevm/wagmi/blob/main/packages/cli/src/errors.ts\nclass ValidationError extends Error {\n details: Zod.ZodIssue[];\n\n constructor(\n message: string,\n options: {\n details: Zod.ZodIssue[];\n }\n ) {\n super(message);\n this.details = options.details;\n }\n}\n\n// From https://github.com/causaly/zod-validation-error\nexport function fromZodError(\n zError: z.ZodError,\n {\n maxIssuesInMessage = 99,\n issueSeparator = \"\\n- \",\n prefixSeparator = \"\\n- \",\n prefix = \"Validation Error\",\n }: {\n maxIssuesInMessage?: number;\n issueSeparator?: string;\n prefixSeparator?: string;\n prefix?: string;\n } = {}\n): ValidationError {\n function joinPath(arr: Array<string | number>): string {\n return arr.reduce<string>((acc, value) => {\n if (typeof value === \"number\") return `${acc}[${value}]`;\n const separator = acc === \"\" ? \"\" : \".\";\n return acc + separator + value;\n }, \"\");\n }\n\n const reason = zError.errors\n // limit max number of issues printed in the reason section\n .slice(0, maxIssuesInMessage)\n // format error message\n .map((issue) => {\n const { message, path } = issue;\n if (path.length > 0) return `${message} at \\`${joinPath(path)}\\``;\n return message;\n })\n // concat as string\n .join(issueSeparator);\n\n const message = reason ? [prefix, reason].join(prefixSeparator) : prefix;\n\n return new ValidationError(message, {\n details: zError.errors,\n });\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,KAAK,CAAC;AAE7B,0EAA0E;AAC1E,MAAM,eAAgB,SAAQ,KAAK;IAGjC,YACE,OAAe,EACf,OAEC;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QARjB;;;;;WAAwB;QAStB,IAAI,CAAC,OAAO,GAAG,OAAO,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,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type z } from \"zod\";\n\n// from https://github.com/wevm/wagmi/blob/main/packages/cli/src/errors.ts\nclass ValidationError extends Error {\n details: Zod.ZodIssue[];\n\n constructor(\n message: string,\n options: {\n details: Zod.ZodIssue[];\n }\n ) {\n super(message);\n this.details = options.details;\n }\n}\n\n// From https://github.com/causaly/zod-validation-error\nexport function fromZodError(\n zError: z.ZodError,\n {\n maxIssuesInMessage = 99,\n issueSeparator = \"\\n- \",\n prefixSeparator = \"\\n- \",\n prefix = \"Validation Error\",\n }: {\n maxIssuesInMessage?: number;\n issueSeparator?: string;\n prefixSeparator?: string;\n prefix?: string;\n } = {}\n): ValidationError {\n function joinPath(arr: Array<string | number>): string {\n return arr.reduce<string>((acc, value) => {\n if (typeof value === \"number\") return `${acc}[${value}]`;\n const separator = acc === \"\" ? \"\" : \".\";\n return acc + separator + value;\n }, \"\");\n }\n\n const reason = zError.errors\n // limit max number of issues printed in the reason section\n .slice(0, maxIssuesInMessage)\n // format error message\n .map((issue) => {\n const { message, path } = issue;\n if (path.length > 0) return `${message} at \\`${joinPath(path)}\\``;\n return message;\n })\n // concat as string\n .join(issueSeparator);\n\n const message = reason ? [prefix, reason].join(prefixSeparator) : prefix;\n\n return new ValidationError(message, {\n details: zError.errors,\n });\n}\n"]}
@@ -1,6 +1,14 @@
1
1
  type FindConfigParameters = {
2
+ /** Config file name */
2
3
  config?: string;
4
+ /** Config file directory */
3
5
  root?: string;
4
6
  };
7
+ /**
8
+ * Resolves path to plugingen CLI config file.
9
+ *
10
+ * @param {FindConfigParameters | undefined} parameters - optional override parameters for finding the config object
11
+ * @returns {string} the path to the config file
12
+ */
5
13
  export declare function findConfig(parameters?: FindConfigParameters): Promise<string | undefined>;
6
14
  export {};
@@ -1,12 +1,21 @@
1
+ // source: https://github.com/wevm/wagmi/blob/main/packages/cli/src/utils/findConfig.ts
1
2
  import { findUp } from "find-up";
2
3
  import { default as fs } from "fs-extra";
3
4
  import { resolve } from "pathe";
5
+ // Do not reorder
6
+ // In order of preference files are checked
4
7
  const configFiles = [
5
8
  "plugingen.config.ts",
6
9
  "plugingen.config.js",
7
10
  "plugingen.config.mjs",
8
11
  "plugingen.config.mts",
9
12
  ];
13
+ /**
14
+ * Resolves path to plugingen CLI config file.
15
+ *
16
+ * @param {FindConfigParameters | undefined} parameters - optional override parameters for finding the config object
17
+ * @returns {string} the path to the config file
18
+ */
10
19
  export async function findConfig(parameters = {}) {
11
20
  const { config, root } = parameters;
12
21
  const rootDir = resolve(root || process.cwd());
@@ -1 +1 @@
1
- {"version":3,"file":"findConfig.js","sourceRoot":"","sources":["../../../src/utils/findConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAIhC,MAAM,WAAW,GAAG;IAClB,qBAAqB;IACrB,qBAAqB;IACrB,sBAAsB;IACtB,sBAAsB;CACvB,CAAC;AAeF,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,aAAmC,EAAE;IACpE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC;IACpC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/C,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACtC,IAAI,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QACzC,OAAO;IACT,CAAC;IACD,OAAO,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["// source: https://github.com/wevm/wagmi/blob/main/packages/cli/src/utils/findConfig.ts\nimport { findUp } from \"find-up\";\nimport { default as fs } from \"fs-extra\";\nimport { resolve } from \"pathe\";\n\n// Do not reorder\n// In order of preference files are checked\nconst configFiles = [\n \"plugingen.config.ts\",\n \"plugingen.config.js\",\n \"plugingen.config.mjs\",\n \"plugingen.config.mts\",\n];\n\ntype FindConfigParameters = {\n /** Config file name */\n config?: string;\n /** Config file directory */\n root?: string;\n};\n\n/**\n * Resolves path to plugingen CLI config file.\n *\n * @param {FindConfigParameters | undefined} parameters - optional override parameters for finding the config object\n * @returns {string} the path to the config file\n */\nexport async function findConfig(parameters: FindConfigParameters = {}) {\n const { config, root } = parameters;\n const rootDir = resolve(root || process.cwd());\n if (config) {\n const path = resolve(rootDir, config);\n if (fs.pathExistsSync(path)) return path;\n return;\n }\n return findUp(configFiles, { cwd: rootDir });\n}\n"]}
1
+ {"version":3,"file":"findConfig.js","sourceRoot":"","sources":["../../../src/utils/findConfig.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,iBAAiB;AACjB,2CAA2C;AAC3C,MAAM,WAAW,GAAG;IAClB,qBAAqB;IACrB,qBAAqB;IACrB,sBAAsB;IACtB,sBAAsB;CACvB,CAAC;AASF;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,aAAmC,EAAE;IACpE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC;IACpC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/C,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACtC,IAAI,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QACzC,OAAO;IACT,CAAC;IACD,OAAO,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["// source: https://github.com/wevm/wagmi/blob/main/packages/cli/src/utils/findConfig.ts\nimport { findUp } from \"find-up\";\nimport { default as fs } from \"fs-extra\";\nimport { resolve } from \"pathe\";\n\n// Do not reorder\n// In order of preference files are checked\nconst configFiles = [\n \"plugingen.config.ts\",\n \"plugingen.config.js\",\n \"plugingen.config.mjs\",\n \"plugingen.config.mts\",\n];\n\ntype FindConfigParameters = {\n /** Config file name */\n config?: string;\n /** Config file directory */\n root?: string;\n};\n\n/**\n * Resolves path to plugingen CLI config file.\n *\n * @param {FindConfigParameters | undefined} parameters - optional override parameters for finding the config object\n * @returns {string} the path to the config file\n */\nexport async function findConfig(parameters: FindConfigParameters = {}) {\n const { config, root } = parameters;\n const rootDir = resolve(root || process.cwd());\n if (config) {\n const path = resolve(rootDir, config);\n if (fs.pathExistsSync(path)) return path;\n return;\n }\n return findUp(configFiles, { cwd: rootDir });\n}\n"]}
@@ -1,3 +1,4 @@
1
+ // https://github.com/wevm/wagmi/blob/main/packages/cli/src/utils/format.ts
1
2
  import prettier from "prettier";
2
3
  export async function format(content) {
3
4
  const config = await prettier.resolveConfig(process.cwd());
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/utils/format.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAAe;IAC1C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC3D,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE;QAC9B,MAAM,EAAE,YAAY;QACpB,GAAG,MAAM;QACT,OAAO,EAAE,EAAE;KACZ,CAAC,CAAC;AACL,CAAC","sourcesContent":["// https://github.com/wevm/wagmi/blob/main/packages/cli/src/utils/format.ts\nimport prettier from \"prettier\";\n\nexport async function format(content: string) {\n const config = await prettier.resolveConfig(process.cwd());\n return prettier.format(content, {\n parser: \"typescript\",\n ...config,\n plugins: [],\n });\n}\n"]}
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/utils/format.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAAe;IAC1C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC3D,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE;QAC9B,MAAM,EAAE,YAAY;QACpB,GAAG,MAAM;QACT,OAAO,EAAE,EAAE;KACZ,CAAC,CAAC;AACL,CAAC","sourcesContent":["// https://github.com/wevm/wagmi/blob/main/packages/cli/src/utils/format.ts\nimport prettier from \"prettier\";\n\nexport async function format(content: string) {\n const config = await prettier.resolveConfig(process.cwd());\n return prettier.format(content, {\n parser: \"typescript\",\n ...config,\n plugins: [],\n });\n}\n"]}
@@ -1,3 +1,4 @@
1
+ // https://github.com/wevm/wagmi/blob/main/packages/cli/src/utils/getIsUsingTypeScript.ts
1
2
  import { findUp } from "find-up";
2
3
  export async function getIsUsingTypeScript() {
3
4
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"isUsingTypescript.js","sourceRoot":"","sources":["../../../src/utils/isUsingTypescript.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAC1B,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,eAAe,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QACxD,IAAI,QAAQ;YAAE,OAAO,IAAI,CAAC;QAE1B,MAAM,eAAe,GAAG,MAAM,MAAM,CAClC,CAAC,2BAA2B,EAAE,4BAA4B,CAAC,EAC3D;YACE,GAAG;SACJ,CACF,CAAC;QACF,IAAI,eAAe;YAAE,OAAO,IAAI,CAAC;QAEjC,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["// https://github.com/wevm/wagmi/blob/main/packages/cli/src/utils/getIsUsingTypeScript.ts\nimport { findUp } from \"find-up\";\n\nexport async function getIsUsingTypeScript() {\n try {\n const cwd = process.cwd();\n const tsconfig = await findUp(\"tsconfig.json\", { cwd });\n if (tsconfig) return true;\n\n const plugingenConfig = await findUp(\n [\"plugingenConfig.config.ts\", \"plugingenConfig.config.mts\"],\n {\n cwd,\n }\n );\n if (plugingenConfig) return true;\n\n return false;\n } catch {\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"isUsingTypescript.js","sourceRoot":"","sources":["../../../src/utils/isUsingTypescript.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAC1B,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,eAAe,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QACxD,IAAI,QAAQ;YAAE,OAAO,IAAI,CAAC;QAE1B,MAAM,eAAe,GAAG,MAAM,MAAM,CAClC,CAAC,2BAA2B,EAAE,4BAA4B,CAAC,EAC3D;YACE,GAAG;SACJ,CACF,CAAC;QACF,IAAI,eAAe;YAAE,OAAO,IAAI,CAAC;QAEjC,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["// https://github.com/wevm/wagmi/blob/main/packages/cli/src/utils/getIsUsingTypeScript.ts\nimport { findUp } from \"find-up\";\n\nexport async function getIsUsingTypeScript() {\n try {\n const cwd = process.cwd();\n const tsconfig = await findUp(\"tsconfig.json\", { cwd });\n if (tsconfig) return true;\n\n const plugingenConfig = await findUp(\n [\"plugingenConfig.config.ts\", \"plugingenConfig.config.mts\"],\n {\n cwd,\n }\n );\n if (plugingenConfig) return true;\n\n return false;\n } catch {\n return false;\n }\n}\n"]}
@@ -1,19 +1,21 @@
1
+ // https://github.com/wevm/wagmi/blob/main/packages/cli/src/utils/loadEnv.ts
1
2
  import { parse } from "dotenv";
2
3
  import { expand } from "dotenv-expand";
3
4
  import { existsSync, readFileSync, statSync } from "node:fs";
4
5
  import { dirname, join } from "node:path";
6
+ // https://github.com/vitejs/vite/blob/main/packages/vite/src/node/env.ts#L7
5
7
  export function loadEnv(config = {}) {
6
8
  const mode = config.mode;
7
9
  if (mode === "local") {
8
10
  throw new Error(`"local" cannot be used as a mode name because it conflicts with the .local postfix for .env files.`);
9
11
  }
10
12
  const envFiles = [
11
- ".env",
12
- ".env.local",
13
+ /** default file */ ".env",
14
+ /** local file */ ".env.local",
13
15
  ...(mode
14
16
  ? [
15
- `.env.${mode}`,
16
- `.env.${mode}.local`,
17
+ /** mode file */ `.env.${mode}`,
18
+ /** mode local file */ `.env.${mode}.local`,
17
19
  ]
18
20
  : []),
19
21
  ];
@@ -28,9 +30,12 @@ export function loadEnv(config = {}) {
28
30
  return Object.entries(parse(readFileSync(path)));
29
31
  }));
30
32
  try {
33
+ // let environment variables use each other
31
34
  expand({ parsed });
32
35
  }
33
36
  catch (error) {
37
+ // custom error handling until https://github.com/motdotla/dotenv-expand/issues/65 is fixed upstream
38
+ // check for message "TypeError: Cannot read properties of undefined (reading 'split')"
34
39
  if (error.message.includes("split")) {
35
40
  throw new Error("dotenv-expand failed to expand env vars. Maybe you need to escape `$`?");
36
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"loadEnv.js","sourceRoot":"","sources":["../../../src/utils/loadEnv.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAG1C,MAAM,UAAU,OAAO,CACrB,SAGI,EAAE;IAEN,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IACzB,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,oGAAoG,CACrG,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG;QACK,MAAM;QACR,YAAY;QAC9B,GAAG,CAAC,IAAI;YACN,CAAC,CAAC;gBACmB,QAAQ,IAAI,EAAE;gBACR,QAAQ,IAAI,QAAQ;aAC5C;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC9C,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAC/B,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACxB,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;YACtC,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,MAAM;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,IAAI;YAAE,OAAO,EAAE,CAAC;QACrB,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC,CAAC,CACH,CAAC;IAEF,IAA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v-expand\";\n\nimport { existsSync, readFileSync, statSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\n// https://github.com/vitejs/vite/blob/main/packages/vite/src/node/env.ts#L7\nexport function loadEnv(\n config: {\n mode?: string;\n envDir?: string;\n } = {}\n): Record<string, string> {\n const mode = config.mode;\n if (mode === \"local\") {\n throw new Error(\n `\"local\" cannot be used as a mode name because it conflicts with the .local postfix for .env files.`\n );\n }\n\n const envFiles = [\n /** default file */ \".env\",\n /** local file */ \".env.local\",\n ...(mode\n ? [\n /** mode file */ `.env.${mode}`,\n /** mode local file */ `.env.${mode}.local`,\n ]\n : []),\n ];\n\n const envDir = config.envDir ?? process.cwd();\n const parsed = Object.fromEntries(\n envFiles.flatMap((file) => {\n const path = lookupFile(envDir, [file], {\n pathOnly: true,\n rootDir: envDir,\n });\n if (!path) return [];\n return Object.entries(parse(readFileSync(path)));\n })\n );\n\n try {\n // let environment variables use each other\n expand({ parsed });\n } catch (error) {\n // custom error handling until https://github.com/motdotla/dotenv-expand/issues/65 is fixed upstream\n // check for message \"TypeError: Cannot read properties of undefined (reading 'split')\"\n if ((error as Error).message.includes(\"split\")) {\n throw new Error(\n \"dotenv-expand failed to expand env vars. Maybe you need to escape `$`?\"\n );\n }\n throw error;\n }\n\n return parsed;\n}\n\nfunction lookupFile(\n dir: string,\n formats: string[],\n options?: {\n pathOnly?: boolean;\n rootDir?: string;\n predicate?: (file: string) => boolean;\n }\n): string | undefined {\n for (const format of formats) {\n const fullPath = join(dir, format);\n if (existsSync(fullPath) && statSync(fullPath).isFile()) {\n const result = options?.pathOnly\n ? fullPath\n : readFileSync(fullPath, \"utf-8\");\n if (!options?.predicate || options.predicate(result)) {\n return result;\n }\n }\n }\n\n const parentDir = dirname(dir);\n if (\n parentDir !== dir &&\n (!options?.rootDir || parentDir.startsWith(options?.rootDir))\n )\n return lookupFile(parentDir, formats, options);\n\n return undefined;\n}\n"]}
1
+ {"version":3,"file":"loadEnv.js","sourceRoot":"","sources":["../../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Env.ts\nimport { parse } from \"dotenv\";\nimport { expand } from \"dotenv-expand\";\n\nimport { existsSync, readFileSync, statSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\n// https://github.com/vitejs/vite/blob/main/packages/vite/src/node/env.ts#L7\nexport function loadEnv(\n config: {\n mode?: string;\n envDir?: string;\n } = {}\n): Record<string, string> {\n const mode = config.mode;\n if (mode === \"local\") {\n throw new Error(\n `\"local\" cannot be used as a mode name because it conflicts with the .local postfix for .env files.`\n );\n }\n\n const envFiles = [\n /** default file */ \".env\",\n /** local file */ \".env.local\",\n ...(mode\n ? [\n /** mode file */ `.env.${mode}`,\n /** mode local file */ `.env.${mode}.local`,\n ]\n : []),\n ];\n\n const envDir = config.envDir ?? process.cwd();\n const parsed = Object.fromEntries(\n envFiles.flatMap((file) => {\n const path = lookupFile(envDir, [file], {\n pathOnly: true,\n rootDir: envDir,\n });\n if (!path) return [];\n return Object.entries(parse(readFileSync(path)));\n })\n );\n\n try {\n // let environment variables use each other\n expand({ parsed });\n } catch (error) {\n // custom error handling until https://github.com/motdotla/dotenv-expand/issues/65 is fixed upstream\n // check for message \"TypeError: Cannot read properties of undefined (reading 'split')\"\n if ((error as Error).message.includes(\"split\")) {\n throw new Error(\n \"dotenv-expand failed to expand env vars. Maybe you need to escape `$`?\"\n );\n }\n throw error;\n }\n\n return parsed;\n}\n\nfunction lookupFile(\n dir: string,\n formats: string[],\n options?: {\n pathOnly?: boolean;\n rootDir?: string;\n predicate?: (file: string) => boolean;\n }\n): string | undefined {\n for (const format of formats) {\n const fullPath = join(dir, format);\n if (existsSync(fullPath) && statSync(fullPath).isFile()) {\n const result = options?.pathOnly\n ? fullPath\n : readFileSync(fullPath, \"utf-8\");\n if (!options?.predicate || options.predicate(result)) {\n return result;\n }\n }\n }\n\n const parentDir = dirname(dir);\n if (\n parentDir !== dir &&\n (!options?.rootDir || parentDir.startsWith(options?.rootDir))\n )\n return lookupFile(parentDir, formats, options);\n\n return undefined;\n}\n"]}
@@ -1,7 +1,14 @@
1
1
  import type { Config } from "../config";
2
2
  import type { MaybeArray } from "../types";
3
3
  type ResolveConfigParameters = {
4
+ /** Path to config file */
4
5
  configPath: string;
5
6
  };
7
+ /**
8
+ * Bundles and returns config object from path.
9
+ *
10
+ * @param {ResolveConfigParameters} parameters - Parameters to resolve config
11
+ * @returns {Promise<MaybeArray<Config>>} an array of the config objects
12
+ */
6
13
  export declare function resolveConfig(parameters: ResolveConfigParameters): Promise<MaybeArray<Config>>;
7
14
  export {};
@@ -1,4 +1,10 @@
1
1
  import { bundleRequire } from "bundle-require";
2
+ /**
3
+ * Bundles and returns config object from path.
4
+ *
5
+ * @param {ResolveConfigParameters} parameters - Parameters to resolve config
6
+ * @returns {Promise<MaybeArray<Config>>} an array of the config objects
7
+ */
2
8
  export async function resolveConfig(parameters) {
3
9
  const { configPath } = parameters;
4
10
  const res = await bundleRequire({ filepath: configPath });
@@ -1 +1 @@
1
- {"version":3,"file":"resolveConfig.js","sourceRoot":"","sources":["../../../src/utils/resolveConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAe/C,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,UAAmC;IAEnC,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,CAAC;IAClC,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;IAC1D,IAAI,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC;IAC7B,IAAI,MAAM,CAAC,OAAO;QAAE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;IAC5C,IAAI,OAAO,MAAM,KAAK,UAAU;QAAE,OAAO,MAAM,CAAC;IAChD,OAAO,MAAM,MAAM,EAAE,CAAC;AACxB,CAAC","sourcesContent":["import { bundleRequire } from \"bundle-require\";\nimport type { Config } from \"../config\";\nimport type { MaybeArray } from \"../types\";\n\ntype ResolveConfigParameters = {\n /** Path to config file */\n configPath: string;\n};\n\n/**\n * Bundles and returns config object from path.\n *\n * @param {ResolveConfigParameters} parameters - Parameters to resolve config\n * @returns {Promise<MaybeArray<Config>>} an array of the config objects\n */\nexport async function resolveConfig(\n parameters: ResolveConfigParameters\n): Promise<MaybeArray<Config>> {\n const { configPath } = parameters;\n const res = await bundleRequire({ filepath: configPath });\n let config = res.mod.default;\n if (config.default) config = config.default;\n if (typeof config !== \"function\") return config;\n return await config();\n}\n"]}
1
+ {"version":3,"file":"resolveConfig.js","sourceRoot":"","sources":["../../../src/utils/resolveConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAS/C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,UAAmC;IAEnC,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,CAAC;IAClC,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;IAC1D,IAAI,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC;IAC7B,IAAI,MAAM,CAAC,OAAO;QAAE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;IAC5C,IAAI,OAAO,MAAM,KAAK,UAAU;QAAE,OAAO,MAAM,CAAC;IAChD,OAAO,MAAM,MAAM,EAAE,CAAC;AACxB,CAAC","sourcesContent":["import { bundleRequire } from \"bundle-require\";\nimport type { Config } from \"../config\";\nimport type { MaybeArray } from \"../types\";\n\ntype ResolveConfigParameters = {\n /** Path to config file */\n configPath: string;\n};\n\n/**\n * Bundles and returns config object from path.\n *\n * @param {ResolveConfigParameters} parameters - Parameters to resolve config\n * @returns {Promise<MaybeArray<Config>>} an array of the config objects\n */\nexport async function resolveConfig(\n parameters: ResolveConfigParameters\n): Promise<MaybeArray<Config>> {\n const { configPath } = parameters;\n const res = await bundleRequire({ filepath: configPath });\n let config = res.mod.default;\n if (config.default) config = config.default;\n if (typeof config !== \"function\") return config;\n return await config();\n}\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "4.0.0-alpha.9";
1
+ export declare const VERSION = "4.0.0-beta.1";
@@ -1,2 +1,4 @@
1
- export const VERSION = "4.0.0-alpha.9";
1
+ // This file is autogenerated by inject-version.ts. Any changes will be
2
+ // overwritten on commit!
3
+ export const VERSION = "4.0.0-beta.1";
2
4
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.0.0-alpha.9\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.0.0-beta.1\";\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "4.0.0-alpha.9";
1
+ export declare const VERSION = "4.0.0-beta.1";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,kBAAkB,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@account-kit/plugingen",
3
- "version": "4.0.0-alpha.9",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "A CLI tool that enables you to generate TS code for your ERC-6900 plugins",
5
5
  "author": "Alchemy",
6
6
  "license": "MIT",
@@ -34,10 +34,10 @@
34
34
  "plugingen": "./dist/esm/cli.js"
35
35
  },
36
36
  "scripts": {
37
- "prebuild": "node --loader ts-node/esm ./inject-version.ts",
37
+ "prebuild": "npx tsx ./inject-version.ts",
38
38
  "build": "yarn clean && yarn build:esm && yarn build:types",
39
- "build:esm": "tsc --project tsconfig.build.json --module es2020 --outDir ./dist/esm --removeComments && echo > ./dist/esm/package.json '{\"type\":\"module\"}'",
40
- "build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
39
+ "build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm",
40
+ "build:types": "tsc --project tsconfig.build.json --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
41
41
  "postbuild": "chmod +x ./dist/esm/cli.js",
42
42
  "clean": "rm -rf ./dist"
43
43
  },
@@ -60,7 +60,7 @@
60
60
  },
61
61
  "homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
62
62
  "dependencies": {
63
- "@aa-sdk/core": "^4.0.0-alpha.9",
63
+ "@aa-sdk/core": "^4.0.0-beta.1",
64
64
  "bundle-require": "^4.0.2",
65
65
  "cac": "^6.7.14",
66
66
  "change-case": "^5.4.3",
@@ -73,11 +73,10 @@
73
73
  "pathe": "^1.1.2",
74
74
  "picocolors": "^1.0.0",
75
75
  "prettier": "^3.2.5",
76
- "viem": "2.8.6",
77
76
  "zod": "^3.22.4"
78
77
  },
79
78
  "peerDependencies": {
80
- "viem": "2.8.6"
79
+ "viem": "^2.20.0"
81
80
  },
82
- "gitHead": "9616a7ab7dc70320b508e5674bb61ef0723a8b59"
81
+ "gitHead": "5e0db61aaa6b55e7da3e04d00822392b946b3882"
83
82
  }
@@ -23,7 +23,7 @@ export const GetContractGenPhase: Phase = async (input) => {
23
23
  address: address || addresses[client.chain.id],
24
24
  abi: ${pluginConfig.name}Abi,
25
25
  client: client,
26
- });
26
+ }) as GetContractReturnType<typeof ${pluginConfig.name}Abi, PublicClient, Address>;
27
27
  }`);
28
28
 
29
29
  return input;
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.0.0-alpha.9";
3
+ export const VERSION = "4.0.0-beta.1";
@@ -1 +0,0 @@
1
- {"type":"module"}