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.
- package/README.md +2 -2
- package/index.js +45 -40
- package/package.json +1 -1
package/README.md
CHANGED
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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(`
|
|
49
|
+
console.log(`Cloning DappBooster...`);
|
|
38
50
|
|
|
39
|
-
// Clone the repository
|
|
40
|
-
|
|
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
|
-
|
|
58
|
+
execQuiet("git fetch --tags");
|
|
52
59
|
|
|
53
60
|
// Get the latest tag
|
|
54
|
-
const latestTag =
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
63
|
+
if (!latestTag) {
|
|
64
|
+
throw new Error("No tags found in the repository");
|
|
65
|
+
}
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
// Checkout the latest tag
|
|
68
|
+
execQuiet(`git checkout "${latestTag}"`);
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
// Remove the .git directory
|
|
71
|
+
fs.rmSync(path.join(projectDir, ".git"), { recursive: true, force: true });
|
|
68
72
|
|
|
69
|
-
|
|
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);
|