-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·67 lines (58 loc) · 1.53 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
const { execSync } = require("node:child_process");
const { exit, chdir } = require("node:process");
const { renameSync, existsSync, rmSync } = require("node:fs");
const args = process.argv.slice(2);
const repo = args[0];
if (!repo) {
console.error("provide a template name");
exit(1);
}
const repoUrl = `https://github.com/pr4j3sh/${repo}.git`;
const projectName = args[1] || repo;
const rm = [
".git",
".github",
"LICENSE",
"CODE_OF_CONDUCT.md",
"CONTRIBUTING.md",
"Dockerfile",
];
try {
execSync(`git clone ${repoUrl} ${projectName}`, { stdio: "inherit" });
if (projectName !== ".") {
chdir(projectName);
}
rm.forEach((item) => {
if (existsSync(item)) {
rmSync(item, { recursive: true, force: true });
}
});
if (existsSync("package.json")) {
console.log("");
console.log("Installing dependencies...");
execSync(`npm i`, { stdio: "inherit" });
}
if (existsSync(".env.example")) {
console.log("");
console.log("Creating .env file");
renameSync(".env.example", ".env");
}
console.log("");
console.log("Use command(s)");
if (projectName !== ".") {
console.log(` cd ${projectName}`);
}
if (existsSync("package.json")) {
console.log(" npm run dev");
} else if (existsSync("Cargo.toml")) {
console.log(" cargo run");
} else if (existsSync("Makefile")) {
console.log(" make run");
} else if (existsSync("pyproject.toml")) {
console.log(" python -m package.main");
}
} catch (error) {
console.error(error);
exit(1);
}