dappbooster 0.1.2 → 0.2.1

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 +45 -40
  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,75 +1,80 @@
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
+ }
32
+
33
+ function getLatestTag() {
34
+ // Get all tags, sorted by version
35
+ const tags = execSync("git tag -l --sort=-v:refname")
36
+ .toString()
37
+ .trim()
38
+ .split("\n");
39
+
40
+ // Return the first (latest) tag
41
+ return tags[0];
42
+ }
30
43
 
31
44
  function cloneRepo(projectName) {
32
- // Sanitize the project name to create a valid directory name
33
45
  const sanitizedProjectName = projectName.replace(/[^a-zA-Z0-9-_]/g, "-");
34
46
  const projectDir = path.join(process.cwd(), sanitizedProjectName);
35
47
 
36
48
  try {
37
- console.log(`cloning DappBooster...`);
49
+ console.log(`Cloning DappBooster...`);
38
50
 
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
- );
51
+ // Clone the repository
52
+ execQuiet(`git clone --depth 1 --no-checkout "${repoUrl}" "${projectDir}"`);
46
53
 
47
54
  // Change to the project directory
48
55
  process.chdir(projectDir);
49
56
 
50
57
  // Fetch all tags
51
- execSync("git fetch --tags > /dev/null 2>&1", { stdio: "inherit" });
58
+ execQuiet("git fetch --tags");
52
59
 
53
60
  // Get the latest tag
54
- const latestTag = execSync(
55
- "git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null"
56
- )
57
- .toString()
58
- .trim();
61
+ const latestTag = getLatestTag();
59
62
 
60
- // Checkout the latest tag
61
- execSync(`git checkout "${latestTag}" > /dev/null 2>&1`, {
62
- stdio: "inherit",
63
- });
63
+ if (!latestTag) {
64
+ throw new Error("No tags found in the repository");
65
+ }
64
66
 
65
- process.chdir(projectDir);
67
+ // Checkout the latest tag
68
+ execQuiet(`git checkout "${latestTag}"`);
66
69
 
67
- execSync("rm -rf .git", { stdio: "inherit" });
70
+ // Remove the .git directory
71
+ fs.rmSync(path.join(projectDir, ".git"), { recursive: true, force: true });
68
72
 
69
- execSync("git init > /dev/null 2>&1", { stdio: "inherit" });
73
+ // Initialize a new git repository
74
+ execQuiet("git init");
70
75
 
71
- // Print the checked out tag
72
76
  console.log(`DappBooster repository cloned in ${projectDir}`);
77
+ console.log(`Latest version: ${latestTag}`);
73
78
  } catch (error) {
74
79
  console.error("An error occurred:", error.message);
75
80
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dappbooster",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "Script to easily start your project with dAppBooster",
5
5
  "main": "index.js",
6
6
  "bin": {