create-ponder 0.4.6 → 0.4.8

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 (2) hide show
  1. package/dist/index.js +43 -35
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { writeFileSync as writeFileSync3 } from "node:fs";
4
+ import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync3 } from "node:fs";
5
5
  import path4 from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { cac } from "cac";
8
8
  import cpy from "cpy";
9
9
  import { execa } from "execa";
10
- import fs2 from "fs-extra";
10
+ import fs from "fs-extra";
11
11
  import { oraPromise } from "ora";
12
12
  import pico5 from "picocolors";
13
13
  import prettier3 from "prettier";
@@ -16,7 +16,7 @@ import { default as prompts } from "prompts";
16
16
  // package.json
17
17
  var package_default = {
18
18
  name: "create-ponder",
19
- version: "0.4.6",
19
+ version: "0.4.8",
20
20
  type: "module",
21
21
  description: "A CLI tool to create Ponder apps",
22
22
  license: "MIT",
@@ -58,6 +58,7 @@ var package_default = {
58
58
  "@types/validate-npm-package-name": "^4.0.2",
59
59
  abitype: "^0.10.2",
60
60
  dotenv: "^16.3.1",
61
+ rimraf: "^5.0.5",
61
62
  tsup: "^8.0.1",
62
63
  vitest: "^1.0.2"
63
64
  },
@@ -401,12 +402,11 @@ You can update by running: ${pico3.cyan(updateMessage)}
401
402
 
402
403
  // src/helpers/validate.ts
403
404
  import path2 from "path";
404
- import fs from "fs-extra";
405
+ import { pathExists } from "fs-extra";
405
406
  import pico4 from "picocolors";
406
407
  import validatePackageName from "validate-npm-package-name";
407
408
  async function validateProjectName({
408
- projectName,
409
- projectPath
409
+ projectName
410
410
  }) {
411
411
  const nameValidation = validatePackageName(projectName);
412
412
  if (!nameValidation.validForNewPackages) {
@@ -420,11 +420,20 @@ async function validateProjectName({
420
420
  problems: problems.map((problem) => `\u{1F449} ${problem}`).join("\n")
421
421
  };
422
422
  }
423
- const targetPath = path2.join(process.cwd(), projectPath);
424
- if (await fs.pathExists(targetPath))
423
+ return {
424
+ valid: true
425
+ };
426
+ }
427
+ async function validateProjectPath({
428
+ projectPath
429
+ }) {
430
+ if (await pathExists(projectPath))
425
431
  return {
426
432
  valid: false,
427
- message: `\u{1F648} the directory "${projectPath}" already exists.`,
433
+ message: `\u{1F648} the directory "${path2.relative(
434
+ process.cwd(),
435
+ projectPath
436
+ )}" already exists.`,
428
437
  problems: "\u{1F449} choose another name or delete the directory."
429
438
  };
430
439
  return {
@@ -695,8 +704,13 @@ async function run({
695
704
  let projectPath;
696
705
  if (args[0]) {
697
706
  projectPath = args[0].trim();
698
- const splitPath = projectPath.split("/");
707
+ if (!path4.isAbsolute(projectPath))
708
+ projectPath = path4.resolve(projectPath);
709
+ const splitPath = projectPath.split(path4.sep);
699
710
  projectName = splitPath[splitPath.length - 1]?.trim() || "";
711
+ const nameValidation = await validateProjectName({ projectName });
712
+ if (!nameValidation.valid)
713
+ throw new ValidationError(nameValidation);
700
714
  log2(pico5.green("\u2714"), pico5.bold("Using project name:"), projectName);
701
715
  } else {
702
716
  const res = await prompts({
@@ -705,24 +719,19 @@ async function run({
705
719
  message: "What's the name of your project?",
706
720
  type: "text",
707
721
  async validate(projectName2) {
708
- const validation = await validateProjectName({
709
- projectName: projectName2,
710
- projectPath: projectName2
711
- });
722
+ const validation = await validateProjectName({ projectName: projectName2 });
712
723
  if (!validation.valid)
713
724
  return validation.message;
714
725
  return true;
715
726
  }
716
727
  });
717
728
  projectName = res.projectName?.trim();
718
- projectPath = projectName;
729
+ projectPath = path4.resolve(projectName);
719
730
  }
720
- const nameValidation = await validateProjectName({
721
- projectName,
722
- projectPath
723
- });
724
- if (!nameValidation.valid)
725
- throw new ValidationError(nameValidation);
731
+ const pathValidation = await validateProjectPath({ projectPath });
732
+ if (!pathValidation.valid)
733
+ throw new ValidationError(pathValidation);
734
+ mkdirSync3(projectPath, { recursive: true });
726
735
  if (options.etherscan && !templateId)
727
736
  templateId = "etherscan";
728
737
  if (options.subgraph && !templateId)
@@ -748,7 +757,6 @@ async function run({
748
757
  if (!templateValidation.valid)
749
758
  throw new ValidationError(templateValidation);
750
759
  let config;
751
- const targetPath = path4.join(process.cwd(), projectPath);
752
760
  let url = options.etherscan;
753
761
  if (templateMeta.id === "etherscan") {
754
762
  if (!url) {
@@ -782,7 +790,7 @@ async function run({
782
790
  const host = new URL(url).host;
783
791
  const result = await oraPromise(
784
792
  fromEtherscan({
785
- rootDir: targetPath,
793
+ rootDir: projectPath,
786
794
  etherscanLink: url,
787
795
  etherscanApiKey: options.etherscanApiKey
788
796
  }),
@@ -799,7 +807,7 @@ async function run({
799
807
  }
800
808
  if (templateMeta.id === "subgraph") {
801
809
  const result = await oraPromise(
802
- fromSubgraphId({ rootDir: targetPath, subgraphId: subgraph }),
810
+ fromSubgraphId({ rootDir: projectPath, subgraphId: subgraph }),
803
811
  {
804
812
  text: "Fetching subgraph metadata. This may take a few seconds.",
805
813
  failText: "Failed to fetch subgraph metadata.",
@@ -810,7 +818,7 @@ async function run({
810
818
  warnings.push(...result.warnings);
811
819
  }
812
820
  const templatePath = path4.join(templatesPath, templateMeta.id);
813
- await cpy(path4.join(templatePath, "**", "*"), targetPath, {
821
+ await cpy(path4.join(templatePath, "**", "*"), projectPath, {
814
822
  rename: (name) => name.replace(/^_dot_/, ".")
815
823
  });
816
824
  if (config) {
@@ -847,7 +855,7 @@ async function run({
847
855
  });
848
856
  `;
849
857
  writeFileSync3(
850
- path4.join(targetPath, "ponder.config.ts"),
858
+ path4.join(projectPath, "ponder.config.ts"),
851
859
  await prettier3.format(configContent, { parser: "typescript" })
852
860
  );
853
861
  for (const [name, contract] of Object.entries(config.contracts)) {
@@ -867,19 +875,19 @@ async function run({
867
875
  ).join("\n")}
868
876
  `;
869
877
  writeFileSync3(
870
- path4.join(targetPath, `./src/${name}.ts`),
878
+ path4.join(projectPath, "src", `${name}.ts`),
871
879
  await prettier3.format(indexingFunctionFileContents, {
872
880
  parser: "typescript"
873
881
  })
874
882
  );
875
883
  }
876
884
  }
877
- const packageJson = await fs2.readJSON(path4.join(targetPath, "package.json"));
885
+ const packageJson = await fs.readJSON(path4.join(projectPath, "package.json"));
878
886
  packageJson.name = projectName;
879
887
  packageJson.dependencies["@ponder/core"] = `^${package_default.version}`;
880
888
  packageJson.devDependencies["eslint-config-ponder"] = `^${package_default.version}`;
881
- await fs2.writeFile(
882
- path4.join(targetPath, "package.json"),
889
+ await fs.writeFile(
890
+ path4.join(projectPath, "package.json"),
883
891
  JSON.stringify(packageJson, null, 2)
884
892
  );
885
893
  const packageManager = getPackageManager({ options });
@@ -889,7 +897,7 @@ async function run({
889
897
  ];
890
898
  await oraPromise(
891
899
  execa(packageManager, installArgs, {
892
- cwd: targetPath,
900
+ cwd: projectPath,
893
901
  env: {
894
902
  ...process.env,
895
903
  ADBLOCK: "1",
@@ -910,8 +918,8 @@ async function run({
910
918
  if (!options.skipGit) {
911
919
  await oraPromise(
912
920
  async () => {
913
- await execa("git", ["init"], { cwd: targetPath });
914
- await execa("git", ["add", "."], { cwd: targetPath });
921
+ await execa("git", ["init"], { cwd: projectPath });
922
+ await execa("git", ["add", "."], { cwd: projectPath });
915
923
  await execa(
916
924
  "git",
917
925
  [
@@ -920,7 +928,7 @@ async function run({
920
928
  "--message",
921
929
  "chore: initial commit from create-ponder"
922
930
  ],
923
- { cwd: targetPath }
931
+ { cwd: projectPath }
924
932
  );
925
933
  },
926
934
  {
@@ -945,7 +953,7 @@ async function run({
945
953
  log2();
946
954
  log2(
947
955
  `To start your app, run ${pico5.bold(
948
- pico5.cyan(`cd ${projectPath}`)
956
+ pico5.cyan(`cd ${path4.relative(process.cwd(), projectPath)}`)
949
957
  )} and then ${pico5.bold(
950
958
  pico5.cyan(
951
959
  `${packageManager}${packageManager === "npm" || packageManager === "bun" ? " run" : ""} dev`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ponder",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "type": "module",
5
5
  "description": "A CLI tool to create Ponder apps",
6
6
  "license": "MIT",
@@ -37,6 +37,7 @@
37
37
  "@types/validate-npm-package-name": "^4.0.2",
38
38
  "abitype": "^0.10.2",
39
39
  "dotenv": "^16.3.1",
40
+ "rimraf": "^5.0.5",
40
41
  "tsup": "^8.0.1",
41
42
  "vitest": "^1.0.2"
42
43
  },