@graphprotocol/graph-cli 0.37.2 → 0.37.3-alpha-20230110163550-d64bef6

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 (206) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/babel.config.js +3 -0
  3. package/dist/bin.js +6 -0
  4. package/dist/cli.js +32 -0
  5. package/dist/codegen/schema.js +250 -0
  6. package/dist/codegen/schema.test.js +458 -0
  7. package/dist/codegen/template.js +65 -0
  8. package/dist/codegen/types/conversions.js +359 -0
  9. package/dist/codegen/types/index.js +71 -0
  10. package/dist/codegen/types/index.test.js +563 -0
  11. package/dist/codegen/typescript.js +200 -0
  12. package/dist/codegen/util.js +46 -0
  13. package/dist/codegen/util.test.js +93 -0
  14. package/dist/command-helpers/abi.js +78 -0
  15. package/dist/command-helpers/auth.js +77 -0
  16. package/dist/command-helpers/compiler.js +66 -0
  17. package/dist/command-helpers/data-sources.js +29 -0
  18. package/dist/command-helpers/fs.js +9 -0
  19. package/dist/command-helpers/gluegun.js +49 -0
  20. package/dist/command-helpers/ipfs.js +5 -0
  21. package/dist/command-helpers/jsonrpc.js +29 -0
  22. package/dist/command-helpers/network.js +93 -0
  23. package/dist/command-helpers/network.test.js +86 -0
  24. package/dist/command-helpers/node.js +40 -0
  25. package/dist/command-helpers/scaffold.js +112 -0
  26. package/dist/command-helpers/spinner.js +84 -0
  27. package/dist/command-helpers/studio.js +13 -0
  28. package/dist/command-helpers/studio.test.js +41 -0
  29. package/dist/command-helpers/subgraph.js +24 -0
  30. package/dist/command-helpers/version.js +74 -0
  31. package/dist/command-helpers/version.test.js +179 -0
  32. package/dist/commands/add.js +190 -0
  33. package/dist/commands/auth.js +127 -0
  34. package/dist/commands/build.js +140 -0
  35. package/dist/commands/codegen.js +135 -0
  36. package/dist/commands/create.js +86 -0
  37. package/dist/commands/deploy.js +334 -0
  38. package/dist/commands/init.js +788 -0
  39. package/dist/commands/local.js +387 -0
  40. package/dist/commands/remove.js +86 -0
  41. package/dist/commands/test.js +295 -0
  42. package/dist/compiler/asc.js +83 -0
  43. package/dist/compiler/index.js +474 -0
  44. package/dist/debug.js +16 -0
  45. package/dist/migrations/mapping_api_version_0_0_1.js +78 -0
  46. package/dist/migrations/mapping_api_version_0_0_2.js +76 -0
  47. package/dist/migrations/mapping_api_version_0_0_3.js +78 -0
  48. package/dist/migrations/mapping_api_version_0_0_4.js +80 -0
  49. package/dist/migrations/mapping_api_version_0_0_5.js +80 -0
  50. package/dist/migrations/spec_version_0_0_2.js +49 -0
  51. package/dist/migrations/spec_version_0_0_3.js +54 -0
  52. package/dist/migrations/util/load-manifest.js +18 -0
  53. package/dist/migrations/util/versions.js +29 -0
  54. package/dist/migrations.js +56 -0
  55. package/dist/protocols/arweave/manifest.graphql +57 -0
  56. package/dist/protocols/arweave/scaffold/manifest.js +18 -0
  57. package/dist/protocols/arweave/scaffold/mapping.js +52 -0
  58. package/dist/protocols/arweave/subgraph.js +23 -0
  59. package/dist/protocols/cosmos/manifest.graphql +76 -0
  60. package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
  61. package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
  62. package/dist/protocols/cosmos/subgraph.js +25 -0
  63. package/dist/protocols/ethereum/abi.js +140 -0
  64. package/dist/protocols/ethereum/codegen/abi.js +451 -0
  65. package/dist/protocols/ethereum/codegen/abi.test.js +328 -0
  66. package/dist/protocols/ethereum/codegen/template.js +50 -0
  67. package/dist/protocols/ethereum/contract.js +20 -0
  68. package/dist/protocols/ethereum/manifest.graphql +94 -0
  69. package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
  70. package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
  71. package/dist/protocols/ethereum/subgraph.js +171 -0
  72. package/dist/protocols/ethereum/type-generator.js +125 -0
  73. package/dist/protocols/index.js +268 -0
  74. package/dist/protocols/ipfs/codegen/file_template.js +50 -0
  75. package/dist/protocols/near/contract.js +41 -0
  76. package/dist/protocols/near/manifest.graphql +64 -0
  77. package/dist/protocols/near/scaffold/manifest.js +16 -0
  78. package/dist/protocols/near/scaffold/mapping.js +38 -0
  79. package/dist/protocols/near/subgraph.js +20 -0
  80. package/dist/protocols/subgraph.js +2 -0
  81. package/dist/protocols/substreams/manifest.graphql +45 -0
  82. package/dist/protocols/substreams/scaffold/manifest.js +12 -0
  83. package/dist/protocols/substreams/subgraph.js +23 -0
  84. package/dist/scaffold/cosmos.test.js +83 -0
  85. package/dist/scaffold/ethereum.test.js +505 -0
  86. package/dist/scaffold/index.js +128 -0
  87. package/dist/scaffold/mapping.js +61 -0
  88. package/dist/scaffold/near.test.js +86 -0
  89. package/dist/scaffold/schema.js +83 -0
  90. package/dist/scaffold/tests.js +175 -0
  91. package/dist/schema.js +54 -0
  92. package/dist/subgraph.js +249 -0
  93. package/dist/type-generator.js +224 -0
  94. package/dist/validation/contract.js +46 -0
  95. package/dist/validation/index.js +8 -0
  96. package/dist/validation/manifest.js +271 -0
  97. package/dist/validation/schema.js +796 -0
  98. package/dist/validation/schema.test.js +35 -0
  99. package/dist/watcher.js +79 -0
  100. package/jest.config.js +1 -1
  101. package/package.json +16 -9
  102. package/{bin/graph → src/bin.ts} +2 -1
  103. package/src/cli.ts +36 -0
  104. package/src/codegen/schema.js +23 -22
  105. package/src/codegen/schema.test.js +33 -27
  106. package/src/codegen/{template.js → template.ts} +8 -6
  107. package/src/codegen/types/conversions.ts +382 -0
  108. package/src/codegen/types/index.js +4 -7
  109. package/src/codegen/types/index.test.js +10 -4
  110. package/src/codegen/{typescript.js → typescript.ts} +44 -26
  111. package/src/codegen/util.js +1 -1
  112. package/src/codegen/util.test.js +5 -2
  113. package/src/command-helpers/abi.js +46 -30
  114. package/src/command-helpers/auth.js +6 -9
  115. package/src/command-helpers/compiler.js +4 -6
  116. package/src/command-helpers/data-sources.js +8 -11
  117. package/src/command-helpers/fs.ts +5 -0
  118. package/src/command-helpers/gluegun.js +2 -4
  119. package/src/command-helpers/ipfs.ts +3 -0
  120. package/src/command-helpers/{jsonrpc.js → jsonrpc.ts} +11 -16
  121. package/src/command-helpers/network.js +58 -44
  122. package/src/command-helpers/network.test.js +23 -19
  123. package/src/command-helpers/node.js +3 -7
  124. package/src/command-helpers/scaffold.js +34 -25
  125. package/src/command-helpers/{spinner.js → spinner.ts} +10 -10
  126. package/src/command-helpers/studio.test.js +61 -30
  127. package/src/command-helpers/studio.ts +20 -0
  128. package/src/command-helpers/{subgraph.js → subgraph.ts} +6 -6
  129. package/src/command-helpers/version.js +11 -16
  130. package/src/command-helpers/version.test.js +111 -82
  131. package/src/commands/add.js +49 -35
  132. package/src/commands/auth.js +13 -25
  133. package/src/commands/build.js +9 -9
  134. package/src/commands/codegen.js +12 -12
  135. package/src/commands/create.js +22 -22
  136. package/src/commands/deploy.js +39 -34
  137. package/src/commands/init.js +21 -24
  138. package/src/commands/local.js +15 -14
  139. package/src/commands/remove.js +22 -22
  140. package/src/commands/test.js +86 -70
  141. package/src/compiler/{asc.js → asc.ts} +29 -16
  142. package/src/compiler/index.js +18 -18
  143. package/src/{debug.js → debug.ts} +2 -2
  144. package/src/migrations/mapping_api_version_0_0_1.js +7 -7
  145. package/src/migrations/mapping_api_version_0_0_2.js +5 -5
  146. package/src/migrations/mapping_api_version_0_0_3.js +7 -7
  147. package/src/migrations/mapping_api_version_0_0_4.js +7 -7
  148. package/src/migrations/mapping_api_version_0_0_5.js +7 -7
  149. package/src/migrations/spec_version_0_0_2.js +5 -5
  150. package/src/migrations/spec_version_0_0_3.js +5 -5
  151. package/src/migrations/util/load-manifest.js +6 -9
  152. package/src/migrations/util/versions.js +5 -10
  153. package/src/{migrations.js → migrations.ts} +14 -15
  154. package/src/protocols/arweave/scaffold/manifest.js +1 -4
  155. package/src/protocols/arweave/scaffold/mapping.js +1 -3
  156. package/src/protocols/arweave/subgraph.ts +22 -0
  157. package/src/protocols/cosmos/scaffold/manifest.js +1 -4
  158. package/src/protocols/cosmos/scaffold/mapping.js +1 -3
  159. package/src/protocols/cosmos/subgraph.js +2 -2
  160. package/src/protocols/ethereum/abi.js +7 -13
  161. package/src/protocols/ethereum/codegen/abi.js +219 -222
  162. package/src/protocols/ethereum/codegen/abi.test.js +6 -6
  163. package/src/protocols/ethereum/codegen/template.js +3 -5
  164. package/src/protocols/ethereum/contract.js +3 -2
  165. package/src/protocols/ethereum/scaffold/manifest.js +4 -7
  166. package/src/protocols/ethereum/scaffold/mapping.js +4 -11
  167. package/src/protocols/ethereum/subgraph.js +21 -20
  168. package/src/protocols/ethereum/type-generator.js +24 -30
  169. package/src/protocols/{index.js → index.ts} +65 -46
  170. package/src/protocols/ipfs/codegen/file_template.js +2 -2
  171. package/src/protocols/near/{contract.js → contract.ts} +16 -12
  172. package/src/protocols/near/scaffold/manifest.js +2 -5
  173. package/src/protocols/near/scaffold/mapping.js +1 -3
  174. package/src/protocols/near/subgraph.js +3 -6
  175. package/src/protocols/subgraph.ts +12 -0
  176. package/src/protocols/substreams/scaffold/{manifest.js → manifest.ts} +2 -7
  177. package/src/protocols/substreams/subgraph.ts +22 -0
  178. package/src/scaffold/cosmos.test.js +3 -3
  179. package/src/scaffold/ethereum.test.js +4 -4
  180. package/src/scaffold/index.js +7 -7
  181. package/src/scaffold/mapping.js +3 -3
  182. package/src/scaffold/near.test.js +3 -3
  183. package/src/scaffold/schema.js +4 -4
  184. package/src/scaffold/tests.js +72 -58
  185. package/src/schema.ts +26 -0
  186. package/src/{subgraph.js → subgraph.ts} +80 -60
  187. package/src/type-generator.js +20 -20
  188. package/src/validation/contract.js +2 -6
  189. package/src/validation/index.js +1 -1
  190. package/src/validation/manifest.js +24 -22
  191. package/src/validation/schema.test.js +1 -1
  192. package/src/validation/{schema.js → schema.ts} +268 -221
  193. package/src/{watcher.js → watcher.ts} +23 -12
  194. package/tests/cli/globalSetup.js +2 -2
  195. package/tests/cli/globalTeardown.js +2 -2
  196. package/tests/cli/init.test.js +2 -2
  197. package/tests/cli/util.js +7 -13
  198. package/tsconfig.json +18 -0
  199. package/src/cli.js +0 -38
  200. package/src/codegen/types/conversions.js +0 -329
  201. package/src/command-helpers/fs.js +0 -8
  202. package/src/command-helpers/ipfs.js +0 -6
  203. package/src/command-helpers/studio.js +0 -15
  204. package/src/protocols/arweave/subgraph.js +0 -20
  205. package/src/protocols/substreams/subgraph.js +0 -17
  206. package/src/schema.js +0 -23
@@ -0,0 +1,295 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const binary_install_raw_1 = require("binary-install-raw");
7
+ const os_1 = __importDefault(require("os"));
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const node_fetch_1 = __importDefault(require("node-fetch"));
10
+ const gluegun_1 = require("gluegun");
11
+ const gluegun_2 = require("../command-helpers/gluegun");
12
+ const path_1 = __importDefault(require("path"));
13
+ const semver_1 = __importDefault(require("semver"));
14
+ const child_process_1 = require("child_process");
15
+ const js_yaml_1 = __importDefault(require("js-yaml"));
16
+ const HELP = `
17
+ ${chalk_1.default.bold('graph test')} ${chalk_1.default.dim('[options]')} ${chalk_1.default.bold('<datasource>')}
18
+
19
+ ${chalk_1.default.dim('Options:')}
20
+ -c, --coverage Run the tests in coverage mode
21
+ -d, --docker Run the tests in a docker container(Note: Please execute from the root folder of the subgraph)
22
+ -f --force Binary - overwrites folder + file when downloading. Docker - rebuilds the docker image
23
+ -h, --help Show usage information
24
+ -l, --logs Logs to the console information about the OS, CPU model and download url (debugging purposes)
25
+ -r, --recompile Force-recompile tests
26
+ -v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
27
+ `;
28
+ exports.default = {
29
+ description: 'Runs rust binary for subgraph testing',
30
+ run: async (toolbox) => {
31
+ // Read CLI parameters
32
+ let { c, coverage, d, docker, f, force, h, help, l, logs, r, recompile, v, version } = toolbox.parameters.options;
33
+ let opts = {};
34
+ // Support both long and short option variants
35
+ opts.coverage = coverage || c;
36
+ opts.docker = docker || d;
37
+ opts.force = force || f;
38
+ opts.help = help || h;
39
+ opts.logs = logs || l;
40
+ opts.recompile = recompile || r;
41
+ opts.version = version || v;
42
+ opts.testsFolder = './tests';
43
+ // Fix if a boolean flag (e.g -c, --coverage) has an argument
44
+ try {
45
+ (0, gluegun_2.fixParameters)(toolbox.parameters, {
46
+ h,
47
+ help,
48
+ c,
49
+ coverage,
50
+ d,
51
+ docker,
52
+ f,
53
+ force,
54
+ l,
55
+ logs,
56
+ r,
57
+ recompile,
58
+ });
59
+ }
60
+ catch (e) {
61
+ gluegun_1.print.error(e.message);
62
+ process.exitCode = 1;
63
+ return;
64
+ }
65
+ let datasource = toolbox.parameters.first || toolbox.parameters.array[0];
66
+ // Show help text if requested
67
+ if (opts.help) {
68
+ gluegun_1.print.info(HELP);
69
+ return;
70
+ }
71
+ // Check if matchstick.yaml config exists
72
+ if (gluegun_1.filesystem.exists('matchstick.yaml')) {
73
+ try {
74
+ // Load the config
75
+ let config = await js_yaml_1.default.load(gluegun_1.filesystem.read('matchstick.yaml', 'utf8'));
76
+ // Check if matchstick.yaml and testsFolder not null
77
+ if (config && config.testsFolder) {
78
+ // assign test folder from matchstick.yaml if present
79
+ opts.testsFolder = config.testsFolder;
80
+ }
81
+ }
82
+ catch (error) {
83
+ gluegun_1.print.info('A problem occurred while reading matchstick.yaml. Please attend to the errors below:');
84
+ gluegun_1.print.error(error.message);
85
+ process.exit(1);
86
+ }
87
+ }
88
+ opts.cachePath = path_1.default.join(opts.testsFolder, '.latest.json');
89
+ setVersionFromCache(opts);
90
+ // Fetch the latest version tag if version is not specified with -v/--version or if the version is not cached
91
+ if (opts.force || (!opts.version && !opts.latestVersion)) {
92
+ gluegun_1.print.info('Fetching latest version tag');
93
+ let result = await (0, node_fetch_1.default)('https://api.github.com/repos/LimeChain/matchstick/releases/latest');
94
+ let json = await result.json();
95
+ opts.latestVersion = json.tag_name;
96
+ gluegun_1.filesystem.file(opts.cachePath, {
97
+ content: {
98
+ version: json.tag_name,
99
+ timestamp: Date.now(),
100
+ },
101
+ });
102
+ }
103
+ if (opts.docker) {
104
+ runDocker(datasource, opts);
105
+ }
106
+ else {
107
+ runBinary(datasource, opts);
108
+ }
109
+ },
110
+ };
111
+ async function setVersionFromCache(opts) {
112
+ if (gluegun_1.filesystem.exists(opts.cachePath) == 'file') {
113
+ let cached = gluegun_1.filesystem.read(opts.cachePath, 'json');
114
+ // Get the cache age in days
115
+ let cacheAge = (Date.now() - cached.timestamp) / (1000 * 60 * 60 * 24);
116
+ // If cache age is less than 1 day, use the cached version
117
+ if (cacheAge < 1) {
118
+ opts.latestVersion = cached.version;
119
+ }
120
+ }
121
+ }
122
+ async function runBinary(datasource, opts) {
123
+ let coverageOpt = opts.coverage;
124
+ let forceOpt = opts.force;
125
+ let logsOpt = opts.logs;
126
+ let versionOpt = opts.version;
127
+ let latestVersion = opts.latestVersion;
128
+ let recompileOpt = opts.recompile;
129
+ const platform = await getPlatform(logsOpt);
130
+ const url = `https://github.com/LimeChain/matchstick/releases/download/${versionOpt || latestVersion}/${platform}`;
131
+ if (logsOpt) {
132
+ gluegun_1.print.info(`Download link: ${url}`);
133
+ }
134
+ let binary = new binary_install_raw_1.Binary(platform, url, versionOpt || latestVersion);
135
+ forceOpt ? await binary.install(true) : await binary.install(false);
136
+ let args = new Array();
137
+ if (coverageOpt)
138
+ args.push('-c');
139
+ if (recompileOpt)
140
+ args.push('-r');
141
+ if (datasource)
142
+ args.push(datasource);
143
+ args.length > 0 ? binary.run(...args) : binary.run();
144
+ }
145
+ async function getPlatform(logsOpt) {
146
+ const type = os_1.default.type();
147
+ const arch = os_1.default.arch();
148
+ const cpuCore = os_1.default.cpus()[0];
149
+ const isAppleSilicon = arch === 'arm64' && /Apple (M1|M2|processor)/.test(cpuCore.model);
150
+ const linuxInfo = type === 'Linux' ? await getLinuxInfo() : {};
151
+ const linuxDistro = linuxInfo.name;
152
+ const release = linuxInfo.version || os_1.default.release();
153
+ const majorVersion = parseInt(linuxInfo.version, 10) || semver_1.default.major(release);
154
+ if (logsOpt) {
155
+ gluegun_1.print.info(`OS type: ${linuxDistro || type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`);
156
+ }
157
+ if (arch === 'x64' || isAppleSilicon) {
158
+ if (type === 'Darwin') {
159
+ if (majorVersion === 18 || majorVersion === 19) {
160
+ return 'binary-macos-10.15'; // GitHub dropped support for macOS 10.14 in Actions, but it seems 10.15 binary works on 10.14 too
161
+ }
162
+ else if (isAppleSilicon) {
163
+ return 'binary-macos-11-m1';
164
+ }
165
+ return 'binary-macos-11';
166
+ }
167
+ else if (type === 'Linux') {
168
+ if (majorVersion === 18) {
169
+ return 'binary-linux-18';
170
+ }
171
+ if (majorVersion === 22) {
172
+ return 'binary-linux-22';
173
+ }
174
+ else {
175
+ return 'binary-linux-20';
176
+ }
177
+ }
178
+ }
179
+ throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`);
180
+ }
181
+ async function getLinuxInfo() {
182
+ try {
183
+ let result = await gluegun_1.system.run("cat /etc/*-release | grep -E '(^VERSION|^NAME)='", {
184
+ trim: true,
185
+ });
186
+ let infoArray = result
187
+ .replace(/['"]+/g, '')
188
+ .split('\n')
189
+ .map(p => p.split('='));
190
+ let linuxInfo = {};
191
+ infoArray.forEach(val => {
192
+ linuxInfo[val[0].toLowerCase()] = val[1];
193
+ });
194
+ return linuxInfo;
195
+ }
196
+ catch (error) {
197
+ gluegun_1.print.error(`Error fetching the Linux version:\n ${error}`);
198
+ process.exit(1);
199
+ }
200
+ }
201
+ async function runDocker(datasource, opts) {
202
+ let coverageOpt = opts.coverage;
203
+ let forceOpt = opts.force;
204
+ let versionOpt = opts.version;
205
+ let latestVersion = opts.latestVersion;
206
+ let recompileOpt = opts.recompile;
207
+ // Remove binary-install-raw binaries, because docker has permission issues
208
+ // when building the docker images
209
+ await gluegun_1.filesystem.remove('./node_modules/binary-install-raw/bin');
210
+ // Get current working directory
211
+ let current_folder = await gluegun_1.filesystem.cwd();
212
+ // Declate dockerfilePath with default location
213
+ let dockerfilePath = path_1.default.join(opts.testsFolder || 'tests', '.docker/Dockerfile');
214
+ // Check if the Dockerfil already exists
215
+ let dockerfileExists = gluegun_1.filesystem.exists(dockerfilePath);
216
+ // Generate the Dockerfile only if it doesn't exists,
217
+ // version flag and/or force flag is passed.
218
+ if (!dockerfileExists || versionOpt || forceOpt) {
219
+ await dockerfile(dockerfilePath, versionOpt, latestVersion);
220
+ }
221
+ // Run a command to check if matchstick image already exists
222
+ (0, child_process_1.exec)('docker images -q matchstick', (error, stdout, stderr) => {
223
+ // Collect all(if any) flags and options that have to be passed to the matchstick binary
224
+ let testArgs = '';
225
+ if (coverageOpt)
226
+ testArgs = testArgs + ' -c';
227
+ if (recompileOpt)
228
+ testArgs = testArgs + ' -r';
229
+ if (datasource)
230
+ testArgs = testArgs + ' ' + datasource;
231
+ // Build the `docker run` command options and flags
232
+ let dockerRunOpts = [
233
+ 'run',
234
+ '-it',
235
+ '--rm',
236
+ '--mount',
237
+ `type=bind,source=${current_folder},target=/matchstick`,
238
+ ];
239
+ if (testArgs !== '') {
240
+ dockerRunOpts.push('-e');
241
+ dockerRunOpts.push(`ARGS=${testArgs.trim()}`);
242
+ }
243
+ dockerRunOpts.push('matchstick');
244
+ // If a matchstick image does not exists, the command returns an empty string,
245
+ // else it'll return the image ID. Skip `docker build` if an image already exists
246
+ // Delete current image(if any) and rebuild.
247
+ // Use spawn() and {stdio: 'inherit'} so we can see the logs in real time.
248
+ if (!dockerfileExists || stdout === '' || versionOpt || forceOpt) {
249
+ if (stdout !== '') {
250
+ (0, child_process_1.exec)('docker image rm matchstick', (error, stdout, stderr) => {
251
+ gluegun_1.print.info(chalk_1.default.bold(`Removing matchstick image\n${stdout}`));
252
+ });
253
+ }
254
+ // Build a docker image. If the process has executed successfully
255
+ // run a container from that image.
256
+ (0, child_process_1.spawn)('docker', ['build', '-f', dockerfilePath, '-t', 'matchstick', '.'], {
257
+ stdio: 'inherit',
258
+ }).on('close', code => {
259
+ if (code === 0) {
260
+ (0, child_process_1.spawn)('docker', dockerRunOpts, { stdio: 'inherit' });
261
+ }
262
+ });
263
+ }
264
+ else {
265
+ gluegun_1.print.info('Docker image already exists. Skipping `docker build` command.');
266
+ // Run the container from the existing matchstick docker image
267
+ (0, child_process_1.spawn)('docker', dockerRunOpts, { stdio: 'inherit' });
268
+ }
269
+ });
270
+ }
271
+ // Downloads Dockerfile template from the demo-subgraph repo
272
+ // Replaces the placeholders with their respective values
273
+ async function dockerfile(dockerfilePath, versionOpt, latestVersion) {
274
+ let spinner = gluegun_1.print.spin('Generating Dockerfile...');
275
+ try {
276
+ // Fetch the Dockerfile template content from the demo-subgraph repo
277
+ let content = await (0, node_fetch_1.default)('https://raw.githubusercontent.com/LimeChain/demo-subgraph/main/Dockerfile').then(response => {
278
+ if (response.ok) {
279
+ return response.text();
280
+ }
281
+ else {
282
+ throw new Error(`Status Code: ${response.status}, with error: ${response.statusText}`);
283
+ }
284
+ });
285
+ // Write the Dockerfile
286
+ await gluegun_1.filesystem.write(dockerfilePath, content);
287
+ // Replaces the version placeholders
288
+ await gluegun_1.patching.replace(dockerfilePath, '<MATCHSTICK_VERSION>', versionOpt || latestVersion);
289
+ }
290
+ catch (error) {
291
+ spinner.fail(`A problem occurred while generating the Dockerfile. Please attend to the errors below:\n ${error.message}`);
292
+ process.exit(1);
293
+ }
294
+ spinner.succeed('Successfully generated Dockerfile.');
295
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.compile = exports.ready = void 0;
27
+ const asc = __importStar(require("assemblyscript/cli/asc"));
28
+ const createExitHandler = (inputFile) => () => {
29
+ throw new Error(`The AssemblyScript compiler crashed when compiling this file: '${inputFile}'
30
+ Suggestion: try to comment the whole file and uncomment it little by little while re-running the graph-cli until you isolate the line where the problem happens.
31
+ Also, please contact us so we can make the CLI better by handling errors like this. You can reach out in any of these links:
32
+ - Discord channel: https://discord.gg/eM8CA6WA9r
33
+ - Github issues: https://github.com/graphprotocol/graph-cli/issues`);
34
+ };
35
+ const setupExitHandler = (exitHandler) => process.addListener('exit', exitHandler);
36
+ const removeExitHandler = (exitHandler) => process.removeListener('exit', exitHandler);
37
+ // Important note, the `asc.main` callback function parameter is synchronous,
38
+ // that's why this function doesn't need to be `async` and the throw works properly.
39
+ const assemblyScriptCompiler = (argv, options) => asc.main(argv, options, err => {
40
+ if (err) {
41
+ throw err;
42
+ }
43
+ return 0;
44
+ });
45
+ const compilerDefaults = {
46
+ stdout: process.stdout,
47
+ stderr: process.stdout,
48
+ };
49
+ // You MUST call this function once before compiling anything.
50
+ // Internally it just delegates to the AssemblyScript compiler
51
+ // which just delegates to the binaryen lib.
52
+ const ready = async () => {
53
+ await asc.ready;
54
+ };
55
+ exports.ready = ready;
56
+ // For now this function doesn't check if `asc` is ready, because
57
+ // it requires an asynchronous wait. Whenever you call this function,
58
+ // it doesn't matter how many times, just make sure you call `ready`
59
+ // once before everything..
60
+ const compile = ({ inputFile, global, baseDir, libs, outputFile, }) => {
61
+ const exitHandler = createExitHandler(inputFile);
62
+ setupExitHandler(exitHandler);
63
+ const compilerArgs = [
64
+ '--explicitStart',
65
+ '--exportRuntime',
66
+ '--runtime',
67
+ 'stub',
68
+ inputFile,
69
+ global,
70
+ '--baseDir',
71
+ baseDir,
72
+ '--lib',
73
+ libs,
74
+ '--outFile',
75
+ outputFile,
76
+ '--optimize',
77
+ '--debug',
78
+ ];
79
+ assemblyScriptCompiler(compilerArgs, compilerDefaults);
80
+ // only if compiler succeded, that is, when the line above doesn't throw
81
+ removeExitHandler(exitHandler);
82
+ };
83
+ exports.compile = compile;