next-competition-backend 1.0.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 (2) hide show
  1. package/package.json +14 -0
  2. package/setup.js +66 -0
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "next-competition-backend",
3
+ "version": "1.0.0",
4
+ "description": "Setup basic BE for Next JS based competition website",
5
+ "scripts": {},
6
+ "author": "Troll321",
7
+ "license": "ISC",
8
+ "bin": {
9
+ "next-competition-backend": "setup.js"
10
+ },
11
+ "dependencies": {
12
+ "@inquirer/prompts": "^8.2.0"
13
+ }
14
+ }
package/setup.js ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync } = require("child_process");
4
+ const { input, select } = require("@inquirer/prompts");
5
+ const path = require("path");
6
+ const TEMPLATE_REPO_URL = "https://github.com/Troll321/next-competition-backend-template";
7
+
8
+ const execCommand = (command, options = {}) => {
9
+ try {
10
+ execSync(command, { stdio: "inherit", ...options });
11
+ } catch (error) {
12
+ console.error(`Error executing command: ${command}`);
13
+ process.exit(1);
14
+ }
15
+ };
16
+
17
+ const setupRepository = async (projectName, packageManager) => {
18
+ execCommand(`git clone --depth=1 ${TEMPLATE_REPO_URL} ${projectName}`);
19
+
20
+ const projectPath = path.join(process.cwd(), projectName);
21
+ let installCommand;
22
+ switch (packageManager) {
23
+ case "npm":
24
+ installCommand = "npm install";
25
+ break;
26
+ case "pnpm":
27
+ installCommand = "pnpm install";
28
+ break;
29
+ case "yarn":
30
+ installCommand = "yarn install";
31
+ break;
32
+ case "bun":
33
+ installCommand = "bun install";
34
+ break;
35
+ default:
36
+ installCommand = "";
37
+ }
38
+ fs.rmSync(path.join(projectPath, ".git"), { recursive: true });
39
+ execCommand("git init", { cwd: projectPath });
40
+ execCommand("git add .", { cwd: projectPath });
41
+ execCommand('git commit -m "Initial commit"', { cwd: projectPath });
42
+
43
+ if (installCommand !== "") {
44
+ execCommand(installCommand, { cwd: projectPath });
45
+ }
46
+ };
47
+
48
+ const main = async () => {
49
+ const projectName = await input({ message: "Project name: " });
50
+ const packageManager = await select({
51
+ message: "Package manager?: ",
52
+ choices: [
53
+ { value: "npm" },
54
+ { value: "pnpm" },
55
+ { value: "yarn" },
56
+ { value: "bun" },
57
+ { value: "none", description: "If selected, won't try to download packages. You then should manually download packages." },
58
+ ],
59
+ });
60
+
61
+ await setupRepository(projectName, packageManager);
62
+ };
63
+
64
+ main().catch((err) => {
65
+ console.error(err.name ?? err);
66
+ });