create-ponder 0.0.9 → 0.0.11

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.
package/dist/src/index.js CHANGED
@@ -1,98 +1,54 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
4
  };
12
- var __copyProps = (to, from, except, desc) => {
13
- if ((from && typeof from === "object") || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, {
17
- get: () => from[key],
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
19
- });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (
24
- (target = mod != null ? __create(__getProtoOf(mod)) : {}),
25
- __copyProps(
26
- isNodeMode || !mod || !mod.__esModule
27
- ? __defProp(target, "default", { value: mod, enumerable: true })
28
- : target,
29
- mod
30
- )
31
- );
32
- var __toCommonJS = (mod) =>
33
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
- var src_exports = {};
35
- __export(src_exports, {
36
- run: () => run,
37
- });
38
- module.exports = __toCommonJS(src_exports);
39
- var import_ethers = require("ethers");
40
- var import_node_child_process = require("node:child_process");
41
- var import_node_fs = require("node:fs");
42
- var import_node_path = __toESM(require("node:path"));
43
- var import_picocolors = __toESM(require("picocolors"));
44
- var import_prettier = __toESM(require("prettier"));
45
- var import_detectPackageManager = require("./helpers/detectPackageManager");
46
- var import_basic = require("./templates/basic");
47
- var import_etherscan = require("./templates/etherscan");
48
- var import_subgraph = require("./templates/subgraph");
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.run = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const node_child_process_1 = require("node:child_process");
9
+ const node_fs_1 = require("node:fs");
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const picocolors_1 = __importDefault(require("picocolors"));
12
+ const prettier_1 = __importDefault(require("prettier"));
13
+ const detectPackageManager_1 = require("./helpers/detectPackageManager");
14
+ const basic_1 = require("./templates/basic");
15
+ const etherscan_1 = require("./templates/etherscan");
16
+ const subgraph_1 = require("./templates/subgraph");
49
17
  const run = async (options, overrides = {}) => {
50
- const { ponderRootDir } = options;
51
- (0, import_node_fs.mkdirSync)(
52
- import_node_path.default.join(ponderRootDir, "abis"),
53
- { recursive: true }
54
- );
55
- (0, import_node_fs.mkdirSync)(
56
- import_node_path.default.join(ponderRootDir, "handlers"),
57
- { recursive: true }
58
- );
59
- let ponderConfig;
60
- if (options.fromSubgraph) {
61
- console.log(
62
- import_picocolors.default.cyan("[create-ponder] ") +
63
- `Bootstrapping from subgraph`
64
- );
65
- ponderConfig = (0, import_subgraph.fromSubgraph)(options);
66
- } else if (options.fromEtherscan) {
67
- console.log(
68
- import_picocolors.default.cyan("[create-ponder] ") +
69
- `Bootstrapping from Etherscan`
70
- );
71
- ponderConfig = await (0, import_etherscan.fromEtherscan)(options);
72
- } else {
73
- ponderConfig = (0, import_basic.fromBasic)(options);
74
- }
75
- ponderConfig.sources.forEach((source) => {
76
- const abi = (0, import_node_fs.readFileSync)(
77
- import_node_path.default.join(ponderRootDir, source.abi),
78
- {
79
- encoding: "utf-8",
80
- }
81
- );
82
- const abiInterface = new import_ethers.ethers.utils.Interface(abi);
83
- const eventNames = Object.keys(abiInterface.events);
84
- const handlers = eventNames.map((eventName) => {
85
- const eventBaseName = eventName.split("(")[0];
86
- const handlerFunctionType = `${eventBaseName}Handler`;
87
- const handlerFunctionName = `handle${eventBaseName}`;
88
- return {
89
- handlerFunctionType,
90
- handlerFunction: `const ${handlerFunctionName}: ${handlerFunctionType} = async (event, context) => { return }
91
- `,
92
- handlerExport: `${eventBaseName}: ${handlerFunctionName}`,
93
- };
94
- });
95
- const handlerFileContents = `
18
+ const { ponderRootDir } = options;
19
+ // Create required directories.
20
+ (0, node_fs_1.mkdirSync)(node_path_1.default.join(ponderRootDir, "abis"), { recursive: true });
21
+ (0, node_fs_1.mkdirSync)(node_path_1.default.join(ponderRootDir, "handlers"), { recursive: true });
22
+ let ponderConfig;
23
+ if (options.fromSubgraph) {
24
+ console.log(picocolors_1.default.cyan("[create-ponder] ") + `Bootstrapping from subgraph`);
25
+ ponderConfig = (0, subgraph_1.fromSubgraph)(options);
26
+ }
27
+ else if (options.fromEtherscan) {
28
+ console.log(picocolors_1.default.cyan("[create-ponder] ") + `Bootstrapping from Etherscan`);
29
+ ponderConfig = await (0, etherscan_1.fromEtherscan)(options);
30
+ }
31
+ else {
32
+ ponderConfig = (0, basic_1.fromBasic)(options);
33
+ }
34
+ // Write the handler ts files.
35
+ ponderConfig.sources.forEach((source) => {
36
+ const abi = (0, node_fs_1.readFileSync)(node_path_1.default.join(ponderRootDir, source.abi), {
37
+ encoding: "utf-8",
38
+ });
39
+ const abiInterface = new ethers_1.ethers.utils.Interface(abi);
40
+ const eventNames = Object.keys(abiInterface.events);
41
+ const handlers = eventNames.map((eventName) => {
42
+ const eventBaseName = eventName.split("(")[0];
43
+ const handlerFunctionType = `${eventBaseName}Handler`;
44
+ const handlerFunctionName = `handle${eventBaseName}`;
45
+ return {
46
+ handlerFunctionType,
47
+ handlerFunction: `const ${handlerFunctionName}: ${handlerFunctionType} = async (event, context) => { return }\n`,
48
+ handlerExport: `${eventBaseName}: ${handlerFunctionName}`,
49
+ };
50
+ });
51
+ const handlerFileContents = `
96
52
  import { ${handlers.map((h) => h.handlerFunctionType).join(",")} }
97
53
  from '../generated/handlers'
98
54
 
@@ -102,20 +58,13 @@ const run = async (options, overrides = {}) => {
102
58
  ${handlers.map((h) => h.handlerExport).join(",")}
103
59
  }
104
60
  `;
105
- (0, import_node_fs.writeFileSync)(
106
- import_node_path.default.join(
107
- ponderRootDir,
108
- `./handlers/${source.name}.ts`
109
- ),
110
- import_prettier.default.format(handlerFileContents, {
111
- parser: "typescript",
112
- })
113
- );
114
- });
115
- const handlerIndexFileContents = `
61
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(ponderRootDir, `./handlers/${source.name}.ts`), prettier_1.default.format(handlerFileContents, { parser: "typescript" }));
62
+ });
63
+ // Write the handler index.ts file.
64
+ const handlerIndexFileContents = `
116
65
  ${ponderConfig.sources
117
- .map((source) => `import { ${source.name} } from "./${source.name}"`)
118
- .join("\n")}
66
+ .map((source) => `import { ${source.name} } from "./${source.name}"`)
67
+ .join("\n")}
119
68
 
120
69
  export default {
121
70
  ${ponderConfig.sources
@@ -123,13 +72,9 @@ const run = async (options, overrides = {}) => {
123
72
  .join(",")}
124
73
  }
125
74
  `;
126
- (0, import_node_fs.writeFileSync)(
127
- import_node_path.default.join(ponderRootDir, `./handlers/index.ts`),
128
- import_prettier.default.format(handlerIndexFileContents, {
129
- parser: "typescript",
130
- })
131
- );
132
- const finalPonderConfig = `const { graphqlPlugin } = require("@ponder/graphql");
75
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(ponderRootDir, `./handlers/index.ts`), prettier_1.default.format(handlerIndexFileContents, { parser: "typescript" }));
76
+ // Write the ponder.config.js file.
77
+ const finalPonderConfig = `const { graphqlPlugin } = require("@ponder/graphql");
133
78
 
134
79
  /**
135
80
  * @type {import('@ponder/core').PonderConfig}
@@ -139,30 +84,18 @@ const ponderConfig = {
139
84
  database: {
140
85
  kind: "sqlite",
141
86
  },
142
- networks: ${JSON.stringify(ponderConfig.networks).replaceAll(
143
- /"process.env.PONDER_RPC_URL_(.*?)"/g,
144
- "process.env.PONDER_RPC_URL_$1"
145
- )},
87
+ networks: ${JSON.stringify(ponderConfig.networks).replaceAll(/"process.env.PONDER_RPC_URL_(.*?)"/g, "process.env.PONDER_RPC_URL_$1")},
146
88
  sources: ${JSON.stringify(ponderConfig.sources)},
147
89
  };
148
90
 
149
91
  module.exports = ponderConfig;`;
150
- (0, import_node_fs.writeFileSync)(
151
- import_node_path.default.join(ponderRootDir, "ponder.config.js"),
152
- import_prettier.default.format(finalPonderConfig, { parser: "babel" })
153
- );
154
- const uniqueChainIds = Array.from(
155
- new Set(ponderConfig.networks.map((n) => n.chainId))
156
- );
157
- const envLocal = `${uniqueChainIds.map(
158
- (chainId) => `PONDER_RPC_URL_${chainId}=""
159
- `
160
- )}`;
161
- (0, import_node_fs.writeFileSync)(
162
- import_node_path.default.join(ponderRootDir, ".env.local"),
163
- envLocal
164
- );
165
- const packageJson = `
92
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(ponderRootDir, "ponder.config.js"), prettier_1.default.format(finalPonderConfig, { parser: "babel" }));
93
+ // Write the .env.local file.
94
+ const uniqueChainIds = Array.from(new Set(ponderConfig.networks.map((n) => n.chainId)));
95
+ const envLocal = `${uniqueChainIds.map((chainId) => `PONDER_RPC_URL_${chainId}=""\n`)}`;
96
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(ponderRootDir, ".env.local"), envLocal);
97
+ // Write the package.json file.
98
+ const packageJson = `
166
99
  {
167
100
  "private": true,
168
101
  "scripts": {
@@ -182,11 +115,9 @@ module.exports = ponderConfig;`;
182
115
  }
183
116
  }
184
117
  `;
185
- (0, import_node_fs.writeFileSync)(
186
- import_node_path.default.join(ponderRootDir, "package.json"),
187
- import_prettier.default.format(packageJson, { parser: "json" })
188
- );
189
- const tsConfig = `
118
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(ponderRootDir, "package.json"), prettier_1.default.format(packageJson, { parser: "json" }));
119
+ // Write the tsconfig.json file.
120
+ const tsConfig = `
190
121
  {
191
122
  "compilerOptions": {
192
123
  "target": "esnext",
@@ -199,83 +130,28 @@ module.exports = ponderConfig;`;
199
130
  "exclude": ["node_modules"]
200
131
  }
201
132
  `;
202
- (0, import_node_fs.writeFileSync)(
203
- import_node_path.default.join(ponderRootDir, "tsconfig.json"),
204
- import_prettier.default.format(tsConfig, { parser: "json" })
205
- );
206
- (0, import_node_fs.writeFileSync)(
207
- import_node_path.default.join(ponderRootDir, ".gitignore"),
208
- `node_modules/
209
- .DS_Store
210
-
211
- .env.local
212
- .ponder/
213
- generated/`
214
- );
215
- const packageManager = await (0, import_detectPackageManager.detect)();
216
- const runCommand =
217
- packageManager === "npm" ? `${packageManager} run` : packageManager;
218
- const renderYaml = `
219
- # This file was generated by \`create-ponder\`. You can deploy your Ponder app
220
- # by signing in to https://render.com, connecting this repository, and clicking Deploy.
221
-
222
- services:
223
- - type: web
224
- name: ponder-app
225
- env: node
226
- buildCommand: ${packageManager} install
227
- startCommand: ${runCommand} start
228
- envVars:
229
- - key: DATABASE_URL
230
- fromDatabase:
231
- name: ponder-db
232
- property: connectionString
233
- ${ponderConfig.networks
234
- .map(
235
- (n) => ` - key: PONDER_RPC_URL_${n.chainId}
236
- sync: false`
237
- )
238
- .join("\n")}
239
-
240
- databases:
241
- - name: ponder-db
242
- postgresMajorVersion: 14
243
- `;
244
- (0, import_node_fs.writeFileSync)(
245
- import_node_path.default.join(ponderRootDir, "render.yaml"),
246
- import_prettier.default.format(renderYaml, { parser: "yaml" })
247
- );
248
- console.log(
249
- import_picocolors.default.cyan("[create-ponder] ") +
250
- `Installing using ${packageManager}`
251
- );
252
- const installCommand = overrides.installCommand
253
- ? overrides.installCommand
254
- : `${packageManager} install`;
255
- (0, import_node_child_process.execSync)(installCommand, {
256
- cwd: ponderRootDir,
257
- stdio: "inherit",
258
- });
259
- console.log(
260
- import_picocolors.default.cyan("[create-ponder] ") + `Generating types`
261
- );
262
- (0, import_node_child_process.execSync)(
263
- `${runCommand} --silent codegen --silent`,
264
- {
265
- cwd: ponderRootDir,
266
- stdio: "inherit",
267
- }
268
- );
269
- console.log(
270
- import_picocolors.default.cyan("[create-ponder] ") +
271
- import_picocolors.default.green("Done! ") +
272
- `To get started run ${import_picocolors.default.yellow(
273
- `${runCommand} dev`
274
- )}`
275
- );
133
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(ponderRootDir, "tsconfig.json"), prettier_1.default.format(tsConfig, { parser: "json" }));
134
+ // Write the .gitignore file.
135
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(ponderRootDir, ".gitignore"), `node_modules/\n.DS_Store\n\n.env.local\n.ponder/\ngenerated/`);
136
+ const packageManager = await (0, detectPackageManager_1.detect)();
137
+ const runCommand = packageManager === "npm" ? `${packageManager} run` : packageManager;
138
+ // Install packages.
139
+ console.log(picocolors_1.default.cyan("[create-ponder] ") + `Installing using ${packageManager}`);
140
+ const installCommand = overrides.installCommand
141
+ ? overrides.installCommand
142
+ : `${packageManager} install`;
143
+ (0, node_child_process_1.execSync)(installCommand, {
144
+ cwd: ponderRootDir,
145
+ stdio: "inherit",
146
+ });
147
+ // Run codegen.
148
+ console.log(picocolors_1.default.cyan("[create-ponder] ") + `Generating types`);
149
+ (0, node_child_process_1.execSync)(`${runCommand} --silent codegen --silent`, {
150
+ cwd: ponderRootDir,
151
+ stdio: "inherit",
152
+ });
153
+ console.log(picocolors_1.default.cyan("[create-ponder] ") +
154
+ picocolors_1.default.green("Done! ") +
155
+ `To get started run ${picocolors_1.default.yellow(`${runCommand} dev`)}`);
276
156
  };
277
- // Annotate the CommonJS export names for ESM import in node:
278
- 0 &&
279
- (module.exports = {
280
- run,
281
- });
157
+ exports.run = run;
@@ -0,0 +1,3 @@
1
+ import type { PartialPonderConfig } from "src/index";
2
+ import type { CreatePonderOptions } from "../bin/create-ponder";
3
+ export declare const fromBasic: (options: CreatePonderOptions) => PartialPonderConfig;
@@ -1,54 +1,19 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
4
  };
12
- var __copyProps = (to, from, except, desc) => {
13
- if ((from && typeof from === "object") || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, {
17
- get: () => from[key],
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
19
- });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (
24
- (target = mod != null ? __create(__getProtoOf(mod)) : {}),
25
- __copyProps(
26
- isNodeMode || !mod || !mod.__esModule
27
- ? __defProp(target, "default", { value: mod, enumerable: true })
28
- : target,
29
- mod
30
- )
31
- );
32
- var __toCommonJS = (mod) =>
33
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
- var basic_exports = {};
35
- __export(basic_exports, {
36
- fromBasic: () => fromBasic,
37
- });
38
- module.exports = __toCommonJS(basic_exports);
39
- var import_node_fs = require("node:fs");
40
- var import_node_path = __toESM(require("node:path"));
41
- var import_prettier = __toESM(require("prettier"));
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fromBasic = void 0;
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const prettier_1 = __importDefault(require("prettier"));
42
10
  const fromBasic = (options) => {
43
- const { ponderRootDir } = options;
44
- const abiFileContents = `[]`;
45
- const abiRelativePath = "./abis/ExampleContract.json";
46
- const abiAbsolutePath = import_node_path.default.join(
47
- ponderRootDir,
48
- abiRelativePath
49
- );
50
- (0, import_node_fs.writeFileSync)(abiAbsolutePath, abiFileContents);
51
- const schemaGraphqlFileContents = `
11
+ const { ponderRootDir } = options;
12
+ const abiFileContents = `[]`;
13
+ const abiRelativePath = "./abis/ExampleContract.json";
14
+ const abiAbsolutePath = node_path_1.default.join(ponderRootDir, abiRelativePath);
15
+ (0, node_fs_1.writeFileSync)(abiAbsolutePath, abiFileContents);
16
+ const schemaGraphqlFileContents = `
52
17
  type ExampleToken @entity {
53
18
  id: ID!
54
19
  tokenId: Int!
@@ -59,42 +24,32 @@ const fromBasic = (options) => {
59
24
  BAD
60
25
  }
61
26
  `;
62
- const ponderSchemaFilePath = import_node_path.default.join(
63
- ponderRootDir,
64
- "schema.graphql"
65
- );
66
- (0, import_node_fs.writeFileSync)(
67
- ponderSchemaFilePath,
68
- import_prettier.default.format(schemaGraphqlFileContents, {
69
- parser: "graphql",
70
- })
71
- );
72
- const ponderConfig = {
73
- plugins: ["graphqlPlugin()"],
74
- database: {
75
- kind: "sqlite",
76
- },
77
- networks: [
78
- {
79
- name: "mainnet",
80
- chainId: 1,
81
- rpcUrl: `process.env.PONDER_RPC_URL_1`,
82
- },
83
- ],
84
- sources: [
85
- {
86
- name: "ExampleContract",
87
- network: "mainnet",
88
- address: "0x0",
89
- abi: abiRelativePath,
90
- startBlock: 1234567,
91
- },
92
- ],
93
- };
94
- return ponderConfig;
27
+ // Generate the schema.graphql file.
28
+ const ponderSchemaFilePath = node_path_1.default.join(ponderRootDir, "schema.graphql");
29
+ (0, node_fs_1.writeFileSync)(ponderSchemaFilePath, prettier_1.default.format(schemaGraphqlFileContents, { parser: "graphql" }));
30
+ // Build the partial ponder config.
31
+ const ponderConfig = {
32
+ plugins: ["graphqlPlugin()"],
33
+ database: {
34
+ kind: "sqlite",
35
+ },
36
+ networks: [
37
+ {
38
+ name: "mainnet",
39
+ chainId: 1,
40
+ rpcUrl: `process.env.PONDER_RPC_URL_1`,
41
+ },
42
+ ],
43
+ sources: [
44
+ {
45
+ name: "ExampleContract",
46
+ network: "mainnet",
47
+ address: "0x0",
48
+ abi: abiRelativePath,
49
+ startBlock: 1234567,
50
+ },
51
+ ],
52
+ };
53
+ return ponderConfig;
95
54
  };
96
- // Annotate the CommonJS export names for ESM import in node:
97
- 0 &&
98
- (module.exports = {
99
- fromBasic,
100
- });
55
+ exports.fromBasic = fromBasic;
@@ -0,0 +1,3 @@
1
+ import type { PartialPonderConfig } from "src/index";
2
+ import type { CreatePonderOptions } from "../bin/create-ponder";
3
+ export declare const fromEtherscan: (options: CreatePonderOptions) => Promise<PartialPonderConfig>;