dappbooster 0.3.3 → 0.3.4

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/.prettierrc +7 -0
  2. package/index.js +90 -23
  3. package/package.json +1 -1
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "bracketSpacing": true,
3
+ "printWidth": 100,
4
+ "semi": false,
5
+ "singleQuote": true,
6
+ "trailingComma": "all"
7
+ }
package/index.js CHANGED
@@ -3,19 +3,73 @@
3
3
  import { execSync } from "child_process";
4
4
  import { join } from "path";
5
5
  import { rmSync } from "fs";
6
+ import readline from "readline";
6
7
  import chalk from "chalk";
8
+ import os from "os";
9
+
10
+ const commandSilencer = os.platform() === "win32" ? '> nul 2>&1' : '> /dev/null 2>&1'
11
+
12
+ const repoUrls = {
13
+ barebones: "https://github.com/BootNodeDev/dAppBooster.git",
14
+ example: "https://github.com/BootNodeDev/dAppBoosterLandingPage.git",
15
+ };
7
16
 
8
- const repoUrl = "https://github.com/bootnodedev/dappbooster.git";
9
17
  const projectName = process.argv[2];
10
18
 
19
+ // Check if the project name is valid
11
20
  if (!projectName || !/^[a-zA-Z0-9-_]+$/.test(projectName)) {
12
- console.error("Invalid directory name. Please enter a valid project name.");
21
+ console.error(`${chalk.red.bold("Invalid directory name. Please enter a valid project name.")}`);
13
22
  process.exit(1);
14
23
  }
15
24
 
16
- cloneRepo(projectName);
25
+ // Prompt the user to select the repository type
26
+ promptUserForRepoType()
27
+ .then((repoType) => {
28
+ const repoUrl = repoUrls[repoType];
29
+ cloneRepo(projectName, repoUrl);
30
+ })
31
+ .catch((error) => {
32
+ console.error(chalk.red.bold("Error:"), error.message);
33
+ process.exit(1);
34
+ });
35
+
36
+ /**
37
+ * @description Prompt the user to select the repository type
38
+ * @returns {Promise<string>} The selected repository type
39
+ */
40
+ function promptUserForRepoType() {
41
+ return new Promise((resolve, reject) => {
42
+ const rl = readline.createInterface({
43
+ input: process.stdin,
44
+ output: process.stdout,
45
+ });
46
+
47
+ rl.question(
48
+ `You can choose to start with a ${chalk.green.bold('Barebones')} project or a project with ${chalk.green.bold('Examples')} and demo code (B/e):`,
49
+ (answer) => {
50
+ rl.close();
51
+ const selection = answer.trim().toUpperCase();
52
+ if (selection === "B" || selection === "") {
53
+ resolve("barebones");
54
+ } else if (selection === "E") {
55
+ resolve("example");
56
+ } else {
57
+ reject(new Error("Invalid selection. Please choose B or E."));
58
+ }
59
+ }
60
+ );
61
+ });
62
+ }
63
+
64
+ /**
65
+ * @description Get the latest tag in the repository
66
+ * @param {Object} execOptions The options to pass to the exec
67
+ * @returns {string} The latest tag in the repository
68
+ */
69
+ function getLatestTag(execOptions) {
70
+ // Fetch all tags
71
+ execSync(`git fetch --tags ${commandSilencer}`, execOptions);
17
72
 
18
- function getLatestTag() {
19
73
  // Get all tags, sorted by version
20
74
  const tags = execSync("git tag -l --sort=-v:refname")
21
75
  .toString()
@@ -26,7 +80,13 @@ function getLatestTag() {
26
80
  return tags[0];
27
81
  }
28
82
 
29
- function cloneRepo(projectName) {
83
+ /**
84
+ * @description Clone the specified repository
85
+ * @param {string} projectName The name of the project
86
+ * @param {string} repoUrl The URL of the repository
87
+ * @returns {void}
88
+ */
89
+ function cloneRepo(projectName, repoUrl) {
30
90
  const sanitizedProjectName = projectName.replace(/[^a-zA-Z0-9-_]/g, "-");
31
91
  const projectDir = join(process.cwd(), sanitizedProjectName);
32
92
  const execOptions = {
@@ -35,7 +95,7 @@ function cloneRepo(projectName) {
35
95
  };
36
96
 
37
97
  try {
38
- console.log(`Cloning dAppBooster...`);
98
+ console.log(`\nCloning dAppBooster...`);
39
99
 
40
100
  // Clone the repository
41
101
  execSync(
@@ -46,43 +106,50 @@ function cloneRepo(projectName) {
46
106
  // Change to the project directory
47
107
  process.chdir(projectDir);
48
108
 
49
- // Fetch all tags
50
- execSync("git fetch --tags", execOptions);
51
-
52
109
  // Get the latest tag
53
110
  const latestTag = getLatestTag();
54
111
 
55
- if (!latestTag) {
56
- throw new Error("No tags found in the repository");
112
+ if (latestTag) {
113
+ console.log(`Checking out latest tag: ${latestTag}`);
114
+ execSync(`git checkout "${latestTag}"`, execOptions);
115
+ } else {
116
+ console.log(`No tags found, checking out ${chalk.bold('main')} branch...`);
117
+ execSync("git checkout main", execOptions);
57
118
  }
58
119
 
59
- // Checkout the latest tag
60
- execSync(`git checkout "${latestTag}"`, execOptions);
61
-
62
120
  // Remove the .git directory
63
121
  rmSync(join(projectDir, ".git"), { recursive: true, force: true });
64
122
 
65
123
  // Initialize a new git repository
66
124
  execSync("git init", execOptions);
67
125
 
68
- console.log(`dAppBooster repository cloned in ${chalk.bold(projectDir)}`);
69
- console.log(`Latest version: ${chalk.bold(latestTag)}`);
126
+ // Success
127
+ console.log(`\ndAppBooster repository cloned in ${chalk.bold(projectDir)}`);
128
+ if (latestTag) {
129
+ console.log(`Latest version: ${chalk.bold(latestTag)}`);
130
+ }
131
+
132
+ console.log(`\n---\n`);
133
+ // Some extra instructions for the user
70
134
  console.log(`
71
- ${chalk.green.bold(
72
- "You can now start your project with the following commands:"
73
- )}
135
+ ${chalk.blue.bold("You can now start your project with the following commands:")}
74
136
 
75
- ${chalk.blue("# Change to the project directory")}
137
+ ${chalk.gray.italic("# Change to the project directory")}
76
138
  $ ${chalk.cyan(`cd ${sanitizedProjectName}`)}
77
139
 
78
- ${chalk.blue("# Install dependencies")}
140
+ ${chalk.gray.italic("# Install dependencies")}
79
141
  $ ${chalk.cyan("pnpm install")}
80
142
 
81
- ${chalk.blue("# Copy the example environment file")}
143
+ ${chalk.gray.italic("# Copy the example environment file")}
82
144
  $ ${chalk.cyan("cp .env.example .env.local")}
83
145
 
84
- ${chalk.blue("# Start the development server")}
146
+ ${chalk.gray.italic("# Start the development server")}
85
147
  $ ${chalk.cyan("pnpm dev")}
148
+
149
+ ---
150
+
151
+ Remember to also check out the docs in ${chalk.green.bold("https://docs.dappbooster.dev/")}
152
+
86
153
  `);
87
154
  } catch (error) {
88
155
  console.error(`${chalk.bold.red("An error occurred:")}`, error.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dappbooster",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Script to easily start your project with dAppBooster",
5
5
  "main": "index.js",
6
6
  "bin": {