apibara 2.1.0-beta.4 → 2.1.0-beta.5

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.
@@ -705,6 +705,90 @@ async function createStorageRelatedFiles(options) {
705
705
  await createDrizzleStorageFiles(options);
706
706
  }
707
707
  }
708
+ const gitIgnoreItems = [
709
+ {
710
+ isRecommended: false,
711
+ value: "node_modules"
712
+ },
713
+ {
714
+ isRecommended: false,
715
+ value: "dist"
716
+ },
717
+ {
718
+ isRecommended: true,
719
+ description: "build and dev files of apibara",
720
+ value: ".apibara"
721
+ },
722
+ {
723
+ isRecommended: false,
724
+ value: ".env"
725
+ },
726
+ {
727
+ isRecommended: false,
728
+ description: "for mac users",
729
+ value: ".DS_Store"
730
+ }
731
+ ];
732
+ async function createGitIgnoreFile(cwd) {
733
+ const gitIgnorePath = path.join(cwd, ".gitignore");
734
+ if (fs.existsSync(gitIgnorePath)) {
735
+ const result = await prompts([
736
+ {
737
+ type: "select",
738
+ name: "overwrite",
739
+ message: `${cyan(".gitignore")} already exists. Please choose how to proceed:`,
740
+ initial: 0,
741
+ choices: [
742
+ {
743
+ title: "Choose items to append in your .gitignore",
744
+ value: "append"
745
+ },
746
+ {
747
+ title: "Keep original",
748
+ value: "ignore"
749
+ },
750
+ {
751
+ title: "Overwrite",
752
+ value: "overwrite"
753
+ }
754
+ ]
755
+ },
756
+ {
757
+ type: (overwrite2) => overwrite2 === "append" ? "multiselect" : null,
758
+ name: "ignoreItems",
759
+ message: "Choose items to append in your .gitignore",
760
+ choices: gitIgnoreItems.map((item) => ({
761
+ title: `${yellow(item.value)}${item.description ? ` - ${item.description}` : ""}${item.isRecommended ? ` ${green("(recommended)")}` : ""}`,
762
+ value: item.value
763
+ }))
764
+ }
765
+ ]);
766
+ const { overwrite, ignoreItems } = result;
767
+ if (overwrite === "append" && ignoreItems.length > 0) {
768
+ const gitIgnoreContent = fs.readFileSync(gitIgnorePath, "utf8");
769
+ fs.writeFileSync(
770
+ gitIgnorePath,
771
+ `${gitIgnoreContent}
772
+ ${result.ignoreItems.join("\n")}`
773
+ );
774
+ consola.success(`Updated ${cyan(".gitignore")}`);
775
+ return;
776
+ }
777
+ if (overwrite === "overwrite") {
778
+ fs.writeFileSync(
779
+ gitIgnorePath,
780
+ gitIgnoreItems.map((item) => item.value).join("\n")
781
+ );
782
+ consola.success(`Updated ${cyan(".gitignore")}`);
783
+ return;
784
+ }
785
+ }
786
+ fs.writeFileSync(
787
+ gitIgnorePath,
788
+ gitIgnoreItems.map((item) => item.value).join("\n")
789
+ );
790
+ consola.success(`Created ${cyan(".gitignore")}`);
791
+ }
708
792
 
709
793
  async function initializeProject({
710
794
  argTargetDir,
@@ -789,24 +873,25 @@ async function initializeProject({
789
873
  JSON.stringify(packageJson, null, 2) + "\n"
790
874
  );
791
875
  await formatFile(packageJsonPath);
792
- consola$1.success("Created ", cyan("package.json"));
876
+ consola$1.success("Created", cyan("package.json"));
793
877
  if (isTs) {
794
878
  const tsConfigPath = path.join(root, "tsconfig.json");
795
879
  const tsConfig = generateTsConfig();
796
880
  fs.writeFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2) + "\n");
797
881
  await formatFile(tsConfigPath);
798
- consola$1.success("Created ", cyan("tsconfig.json"));
882
+ consola$1.success("Created", cyan("tsconfig.json"));
799
883
  }
800
884
  const apibaraConfigPath = path.join(root, `apibara.config.${configExt}`);
801
885
  const apibaraConfig = generateApibaraConfig(isTs);
802
886
  fs.writeFileSync(apibaraConfigPath, apibaraConfig);
803
887
  await formatFile(apibaraConfigPath);
804
- consola$1.success("Created ", cyan(`apibara.config.${configExt}`));
888
+ consola$1.success("Created", cyan(`apibara.config.${configExt}`));
805
889
  const indexersDir = path.join(root, "indexers");
806
890
  if (!fs.existsSync(indexersDir)) {
807
891
  fs.mkdirSync(indexersDir, { recursive: true });
808
892
  consola$1.success(`Created ${cyan("indexers")} directory`);
809
893
  }
894
+ await createGitIgnoreFile(root);
810
895
  console.log("\n");
811
896
  consola$1.ready(green("Project initialized successfully"));
812
897
  console.log();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apibara",
3
- "version": "2.1.0-beta.4",
3
+ "version": "2.1.0-beta.5",
4
4
  "type": "module",
5
5
  "main": "./dist/core/index.mjs",
6
6
  "exports": {
@@ -76,7 +76,7 @@
76
76
  "playground:start": "pnpm playground start --dir playground --indexer starknet"
77
77
  },
78
78
  "devDependencies": {
79
- "@apibara/starknet": "2.1.0-beta.4",
79
+ "@apibara/starknet": "2.1.0-beta.5",
80
80
  "@types/fs-extra": "^11.0.4",
81
81
  "@types/node": "^20.14.0",
82
82
  "@types/prompts": "^2.4.9",
@@ -87,8 +87,8 @@
87
87
  "vitest": "^1.6.0"
88
88
  },
89
89
  "dependencies": {
90
- "@apibara/indexer": "2.1.0-beta.4",
91
- "@apibara/protocol": "2.1.0-beta.4",
90
+ "@apibara/indexer": "2.1.0-beta.5",
91
+ "@apibara/protocol": "2.1.0-beta.5",
92
92
  "@rollup/plugin-commonjs": "^26.0.1",
93
93
  "@rollup/plugin-json": "^6.1.0",
94
94
  "@rollup/plugin-node-resolve": "^15.2.3",
@@ -5,6 +5,7 @@ import prompts from "prompts";
5
5
  import { addIndexer } from "./add";
6
6
  import { cyan, green } from "./colors";
7
7
  import {
8
+ createGitIgnoreFile,
8
9
  generateApibaraConfig,
9
10
  generatePackageJson,
10
11
  generateTsConfig,
@@ -129,7 +130,7 @@ export async function initializeProject({
129
130
  JSON.stringify(packageJson, null, 2) + "\n",
130
131
  );
131
132
  await formatFile(packageJsonPath);
132
- consola.success("Created ", cyan("package.json"));
133
+ consola.success("Created", cyan("package.json"));
133
134
 
134
135
  // Generate tsconfig.json if TypeScript
135
136
  if (isTs) {
@@ -137,7 +138,7 @@ export async function initializeProject({
137
138
  const tsConfig = generateTsConfig();
138
139
  fs.writeFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2) + "\n");
139
140
  await formatFile(tsConfigPath);
140
- consola.success("Created ", cyan("tsconfig.json"));
141
+ consola.success("Created", cyan("tsconfig.json"));
141
142
  }
142
143
 
143
144
  const apibaraConfigPath = path.join(root, `apibara.config.${configExt}`);
@@ -145,7 +146,7 @@ export async function initializeProject({
145
146
  const apibaraConfig = generateApibaraConfig(isTs);
146
147
  fs.writeFileSync(apibaraConfigPath, apibaraConfig);
147
148
  await formatFile(apibaraConfigPath);
148
- consola.success("Created ", cyan(`apibara.config.${configExt}`));
149
+ consola.success("Created", cyan(`apibara.config.${configExt}`));
149
150
 
150
151
  // Create "indexers" directory if not exists
151
152
  const indexersDir = path.join(root, "indexers");
@@ -154,6 +155,8 @@ export async function initializeProject({
154
155
  consola.success(`Created ${cyan("indexers")} directory`);
155
156
  }
156
157
 
158
+ await createGitIgnoreFile(root);
159
+
157
160
  console.log("\n");
158
161
 
159
162
  consola.ready(green("Project initialized successfully"));
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { consola } from "consola";
4
+ import prompts from "prompts";
4
5
  import { type ObjectLiteralExpression, Project, SyntaxKind } from "ts-morph";
5
6
  import { cyan, green, magenta, yellow } from "./colors";
6
7
  import { packageVersions } from "./constants";
@@ -466,3 +467,103 @@ export async function createStorageRelatedFiles(options: IndexerOptions) {
466
467
  await createDrizzleStorageFiles(options);
467
468
  }
468
469
  }
470
+
471
+ const gitIgnoreItems: {
472
+ isRecommended: boolean;
473
+ description?: string;
474
+ value: string;
475
+ }[] = [
476
+ {
477
+ isRecommended: false,
478
+ value: "node_modules",
479
+ },
480
+ {
481
+ isRecommended: false,
482
+ value: "dist",
483
+ },
484
+ {
485
+ isRecommended: true,
486
+ description: "build and dev files of apibara",
487
+ value: ".apibara",
488
+ },
489
+ {
490
+ isRecommended: false,
491
+ value: ".env",
492
+ },
493
+ {
494
+ isRecommended: false,
495
+ description: "for mac users",
496
+ value: ".DS_Store",
497
+ },
498
+ ];
499
+
500
+ export async function createGitIgnoreFile(cwd: string) {
501
+ const gitIgnorePath = path.join(cwd, ".gitignore");
502
+
503
+ if (fs.existsSync(gitIgnorePath)) {
504
+ const result = await prompts([
505
+ {
506
+ type: "select",
507
+ name: "overwrite",
508
+ message: `${cyan(".gitignore")} already exists. Please choose how to proceed:`,
509
+ initial: 0,
510
+ choices: [
511
+ {
512
+ title: "Choose items to append in your .gitignore",
513
+ value: "append",
514
+ },
515
+ {
516
+ title: "Keep original",
517
+ value: "ignore",
518
+ },
519
+ {
520
+ title: "Overwrite",
521
+ value: "overwrite",
522
+ },
523
+ ],
524
+ },
525
+ {
526
+ type: (overwrite: "append" | "ignore" | "overwrite") =>
527
+ overwrite === "append" ? "multiselect" : null,
528
+ name: "ignoreItems",
529
+ message: "Choose items to append in your .gitignore",
530
+ choices: gitIgnoreItems.map((item) => ({
531
+ title: `${yellow(item.value)}${
532
+ item.description ? ` - ${item.description}` : ""
533
+ }${item.isRecommended ? ` ${green("(recommended)")}` : ""}`,
534
+ value: item.value,
535
+ })),
536
+ },
537
+ ]);
538
+
539
+ const { overwrite, ignoreItems } = result as {
540
+ overwrite: "append" | "ignore" | "overwrite";
541
+ ignoreItems: string[];
542
+ };
543
+
544
+ if (overwrite === "append" && ignoreItems.length > 0) {
545
+ const gitIgnoreContent = fs.readFileSync(gitIgnorePath, "utf8");
546
+ fs.writeFileSync(
547
+ gitIgnorePath,
548
+ `${gitIgnoreContent}\n${result.ignoreItems.join("\n")}`,
549
+ );
550
+ consola.success(`Updated ${cyan(".gitignore")}`);
551
+ return;
552
+ }
553
+
554
+ if (overwrite === "overwrite") {
555
+ fs.writeFileSync(
556
+ gitIgnorePath,
557
+ gitIgnoreItems.map((item) => item.value).join("\n"),
558
+ );
559
+ consola.success(`Updated ${cyan(".gitignore")}`);
560
+ return;
561
+ }
562
+ }
563
+
564
+ fs.writeFileSync(
565
+ gitIgnorePath,
566
+ gitIgnoreItems.map((item) => item.value).join("\n"),
567
+ );
568
+ consola.success(`Created ${cyan(".gitignore")}`);
569
+ }