MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / create_project

Method create_project

mod/project/nodejs/nodeMod.py:35–116  ·  view source on GitHub ↗

@name 创建项目 @param get: dict_obj {} get.project_cwd string 项目路径 /www/wwwroot/my_project 必传 get.project_name string 项目名称 my_project 必传 get.project_type string 项目类型 nodejs/pm2/general 必传 get.project

(self, get)

Source from the content-addressed store, hash-verified

33
34 # 2024/7/11 下午2:44 创建项目
35 def create_project(self, get):
36 '''
37 @name 创建项目
38 @param get: dict_obj {}
39 get.project_cwd string 项目路径 /www/wwwroot/my_project 必传
40 get.project_name string 项目名称 my_project 必传
41 get.project_type string 项目类型 nodejs/pm2/general 必传
42 get.project_script string 启动脚本 start/dev/... 必传
43 get.run_user string 运行用户 www/root/... 必传
44 get.port string 端口 4001 非必传
45 get.env string 环境变量 key=value\nkey=value\n... 非必传
46 get.nodejs_version string node版本 v20.15.0 必传
47 get.pkg_manager string 包管理器 npm/yarn/pnpm/... 必传
48 get.not_install_pkg bool 是否安装依赖包 True/False 非必传
49 get.release_firewall bool 是否放行防火墙 True/False 非必传
50 get.is_power_on bool 是否开机启动 True/False 非必传
51 get.max_memory_limit int 最大内存限制 4096 非必传
52 get.bind_extranet bool 是否绑定外网 True/False 依赖于get.port 非必传
53 get.domains list 域名列表 ["www.bt.cn", "bt.cn", ...] 非必传
54 get.project_ps string 备注 ps 非必传
55 '''
56 self.set_self_get(get)
57 self.set_def_name(get.def_name)
58 get.project_cwd = get.get("project_cwd", None)
59 if get.project_cwd is None:
60 self.ws_err_exit(False, 'project_cwd参数不能为空', code=2)
61 if not os.path.exists(get.project_cwd):
62 self.ws_err_exit(False, '指定项目目录不存在', code=2)
63 if not os.path.isdir(get.project_cwd):
64 self.ws_err_exit(False, '指定项目录不是一个目录', code=2)
65 get.project_name = get.get("project_name", None)
66 if get.project_name is None:
67 self.ws_err_exit(False, 'project_name参数不能为空', code=2)
68 get.project_name = public.xssencode2(get.project_name)
69 get.project_type = get.get("project_type", None)
70 if get.project_type is None:
71 self.ws_err_exit(False, 'project_type参数不能为空', code=2)
72 if get.project_type != "nodejs":
73 self.ws_err_exit(False, '此模型仅支持nodejs项目', code=2)
74 get.project_script = get.get("project_script", None)
75 if get.project_script is None:
76 self.ws_err_exit(False, 'project_script参数不能为空', code=2)
77 get.run_user = get.get("run_user", "www")
78 get.env = get.get("env", "")
79 if get.env != "":
80 get.env = get.env.split("\n")
81 for env in get.env:
82 if not "=" in env:
83 self.ws_err_exit(False, "环境变量: {} 格式错误,请重新输入例如:key=value".format(env), code=2)
84
85 get.not_install_pkg = get.get("not_install_pkg", False)
86 get.release_firewall = get.get("release_firewall", False)
87 get.is_power_on = get.get("is_power_on", True)
88 get.max_memory_limit = get.get("max_memory_limit", 4096)
89
90 package_file = "{}/package.json".format(get.project_cwd)
91 get.package_info = {}
92 if os.path.exists(package_file):

Callers

nothing calls this directly

Calls 15

create_siteMethod · 0.95
set_configMethod · 0.95
start_projectMethod · 0.95
PackageManageClass · 0.90
set_self_getMethod · 0.80
ws_err_exitMethod · 0.80
readFileMethod · 0.80
check_node_versionMethod · 0.80
install_packageMethod · 0.80
set_def_nameMethod · 0.45
getMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected