File size: 1,940 Bytes
a4d930e
e8d4fce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4d930e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb9bc1b
a4d930e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""import subprocess

res = subprocess.run(
    ["npm", "install", "express", "axios", "node-telegram-bot-api"],
    capture_output=True,
    text=True
)


print("Output:")
print(res.stdout)

print("Errors (if any):")
print(res.stderr)

result = subprocess.run(
    ["node", "index.js"],
    capture_output=True,
    text=True
)

print("Output:")
print(result.stdout)

print("Errors (if any):")
print(result.stderr)"""


import subprocess
import os
import sys

PROJECT_DIR = "./"      # change if needed
DEPS_FILE = "deps.txt"  # text file with npm packages
ENTRY_FILE = "index.js" # your main node file


def run(cmd, cwd=None):
    process = subprocess.Popen(
        cmd,
        cwd=cwd,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        text=True,
        shell=True
    )
    for line in process.stdout:
        print(line, end="")
    process.wait()
    return process.returncode

run("curl https://api.telegram.org")

def check_node():
    return run("node -v") == 0 and run("npm -v") == 0


def install_from_txt():
    if not os.path.exists(DEPS_FILE):
        print("deps.txt not found!")
        return False

    with open(DEPS_FILE, "r") as f:
        packages = [line.strip() for line in f if line.strip()]

    if not packages:
        print("No dependencies listed.")
        return True

    print("Installing dependencies from deps.txt...")
    for pkg in packages:
        print(f"\nInstalling: {pkg}")
        code = run(f"npm install {pkg}", cwd=PROJECT_DIR)
        if code != 0:
            print(f"Failed to install {pkg}")
            return False

    return True


def run_node():
    print("\nStarting Node.js app...\n")
    return run(f"node {ENTRY_FILE}", cwd=PROJECT_DIR)


def main():
    if not check_node():
        print("Node.js or npm not installed.")
        sys.exit(1)

    if not install_from_txt():
        sys.exit(1)

    run_node()


if __name__ == "__main__":
    main()