dappbooster 0.1.2 → 0.2.0

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 (3) hide show
  1. package/README.md +2 -2
  2. package/index.js +29 -36
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # dAB-cloner
1
+ # dAppBooster starter
2
2
 
3
3
  A script to clone dAppBooster and cleanup the history to freshly start your new project
4
4
 
5
5
  # Usage
6
6
 
7
7
  ```shell
8
- $ npx dappbooster <projectDirectory>
8
+ $ pnpx dappbooster <projectDirectory>
9
9
  ```
package/index.js CHANGED
@@ -1,74 +1,67 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const { execSync } = require("child_process");
4
- // const fs = require("fs");
5
4
  const path = require("path");
6
- // const readline = require("readline");
5
+ const fs = require("fs");
6
+ const os = require("os");
7
7
 
8
8
  const repoUrl = "https://github.com/bootnodedev/dappbooster.git";
9
9
  const projectName = process.argv[2];
10
10
 
11
- // const rl = readline.createInterface({
12
- // input: process.stdin,
13
- // output: process.stdout,
14
- // });
15
-
16
- try {
17
- /^[a-zA-Z0-9-_]+/.test(projectName);
18
- cloneRepo(projectName);
19
- return;
20
- } catch (error) {
11
+ if (!projectName || !/^[a-zA-Z0-9-_]+$/.test(projectName)) {
21
12
  console.error("Invalid directory name. Please enter a valid project name.");
22
13
  process.exit(1);
23
14
  }
24
15
 
25
- // request project name to continue
26
- // rl.question("Enter the project name: ", (projectName) => {
27
- // rl.close();
28
- // cloneRepo(projectName);
29
- // });
16
+ cloneRepo(projectName);
17
+
18
+ function execQuiet(command) {
19
+ const options = {
20
+ stdio: "pipe",
21
+ shell: true,
22
+ };
23
+
24
+ if (os.platform() === "win32") {
25
+ command = `${command} > nul 2>&1`;
26
+ } else {
27
+ command = `${command} > /dev/null 2>&1`;
28
+ }
29
+
30
+ return execSync(command, options);
31
+ }
30
32
 
31
33
  function cloneRepo(projectName) {
32
- // Sanitize the project name to create a valid directory name
33
34
  const sanitizedProjectName = projectName.replace(/[^a-zA-Z0-9-_]/g, "-");
34
35
  const projectDir = path.join(process.cwd(), sanitizedProjectName);
35
36
 
36
37
  try {
37
- console.log(`cloning DappBooster...`);
38
+ console.log(`Cloning DappBooster...`);
38
39
 
39
- // Clone the repository with minimum history
40
- execSync(
41
- `git clone --depth 1 --no-checkout "${repoUrl}" "${projectDir}" > /dev/null 2>&1`,
42
- {
43
- stdio: "inherit",
44
- }
45
- );
40
+ // Clone the repository
41
+ execQuiet(`git clone --depth 1 --no-checkout "${repoUrl}" "${projectDir}"`);
46
42
 
47
43
  // Change to the project directory
48
44
  process.chdir(projectDir);
49
45
 
50
46
  // Fetch all tags
51
- execSync("git fetch --tags > /dev/null 2>&1", { stdio: "inherit" });
47
+ execQuiet("git fetch --tags");
52
48
 
53
49
  // Get the latest tag
54
50
  const latestTag = execSync(
55
- "git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null"
51
+ "git describe --tags $(git rev-list --tags --max-count=1)"
56
52
  )
57
53
  .toString()
58
54
  .trim();
59
55
 
60
56
  // Checkout the latest tag
61
- execSync(`git checkout "${latestTag}" > /dev/null 2>&1`, {
62
- stdio: "inherit",
63
- });
64
-
65
- process.chdir(projectDir);
57
+ execQuiet(`git checkout "${latestTag}"`);
66
58
 
67
- execSync("rm -rf .git", { stdio: "inherit" });
59
+ // Remove the .git directory
60
+ fs.rmSync(path.join(projectDir, ".git"), { recursive: true, force: true });
68
61
 
69
- execSync("git init > /dev/null 2>&1", { stdio: "inherit" });
62
+ // Initialize a new git repository
63
+ execQuiet("git init");
70
64
 
71
- // Print the checked out tag
72
65
  console.log(`DappBooster repository cloned in ${projectDir}`);
73
66
  } catch (error) {
74
67
  console.error("An error occurred:", error.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dappbooster",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Script to easily start your project with dAppBooster",
5
5
  "main": "index.js",
6
6
  "bin": {