| """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 = "./" |
| DEPS_FILE = "deps.txt" |
| ENTRY_FILE = "index.js" |
|
|
|
|
| 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() |