-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create files modules and package commands
- Loading branch information
1 parent
7d31611
commit 81b0570
Showing
8 changed files
with
191 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,5 @@ | |
], | ||
}, | ||
keywords='github cli projects dependencies', | ||
packages=find_packages('src') | ||
packages=find_packages(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from .update_projects import update_projects | ||
from .ncu_update_projects import ncu_update_projects | ||
from .get_cli_version import get_cli_version | ||
from .check_outdated import check_outdated | ||
from .check_status import check_status | ||
|
||
# Exportando funções/módulos | ||
__all__ = ["update_projects", "ncu_update_projects", "get_cli_version", "check_outdated", "check_status"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
import subprocess | ||
|
||
# Função para verificar dependências desatualizadas em todos os projetos | ||
def check_outdated(base_dir): | ||
for dir in os.listdir(base_dir): | ||
full_path = os.path.join(base_dir, dir) | ||
if os.path.isdir(full_path): | ||
print("Entrando no diretório:", full_path) | ||
os.chdir(full_path) | ||
|
||
try: | ||
print("Rodando 'outdated' em", full_path) | ||
subprocess.run(['npm', 'outdated'], check=True) | ||
|
||
except subprocess.CalledProcessError as e: | ||
print(f"Erro ao verificar dependências desatualizadas em {full_path}:") | ||
print(e.stderr) | ||
|
||
os.chdir('..') | ||
|
||
print("Verificação concluída.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
import subprocess | ||
|
||
# Função para verificar o status do Git em todos os projetos | ||
def check_status(base_dir): | ||
for dir in os.listdir(base_dir): | ||
full_path = os.path.join(base_dir, dir) | ||
if os.path.isdir(full_path): | ||
print("Entrando no diretório:", full_path) | ||
os.chdir(full_path) | ||
|
||
try: | ||
print("Verificando o status do Git em", full_path) | ||
subprocess.run(['git', 'status'], check=True) | ||
|
||
except subprocess.CalledProcessError as e: | ||
print(f"Erro ao verificar o status do Git em {full_path}:") | ||
print(e.stderr) | ||
|
||
os.chdir('..') | ||
|
||
print("Verificação de status do Git concluída.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from importlib.metadata import version | ||
|
||
# Função para exibir a versão do programa | ||
def get_cli_version(): | ||
try: | ||
return version('gitman') | ||
except Exception: | ||
return "Versão desconhecida" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
import subprocess | ||
|
||
# Função para rodar npx npm-check-updates e atualizar dependências | ||
def ncu_update_projects(projects, commit_message, base_dir): | ||
project_list = projects.split(',') | ||
|
||
for project_dir in project_list: | ||
full_path = os.path.join(base_dir, project_dir) | ||
if not os.path.isdir(full_path): | ||
print(f"O diretório {full_path} não existe.") | ||
continue | ||
|
||
os.chdir(full_path) | ||
|
||
print(f"Atualizando todas as dependências em {full_path} com npm-check-updates") | ||
|
||
try: | ||
# Executa npx npm-check-updates | ||
ncu_result = subprocess.run(['npx', 'npm-check-updates', '-u'], capture_output=True, text=True) | ||
|
||
# Exibir a saída completa para depuração | ||
print(f"Saída do npx npm-check-updates:\n{ncu_result.stdout}") | ||
print(f"Erros do npx npm-check-updates:\n{ncu_result.stderr}") | ||
|
||
# Se houver atualizações, ncu_result.returncode será 1 | ||
if ncu_result.returncode not in [0, 1]: | ||
raise subprocess.CalledProcessError(ncu_result.returncode, ncu_result.args, output=ncu_result.stdout, stderr=ncu_result.stderr) | ||
|
||
# Executa npm install | ||
install_result = subprocess.run(['npm', 'install'], capture_output=True, text=True) | ||
|
||
# Exibir a saída completa para depuração | ||
print(f"Saída do npm install:\n{install_result.stdout}") | ||
print(f"Erros do npm install:\n{install_result.stderr}") | ||
|
||
if install_result.returncode != 0: | ||
raise subprocess.CalledProcessError(install_result.returncode, install_result.args, output=install_result.stdout, stderr=install_result.stderr) | ||
|
||
# Adiciona mudanças ao Git, cria um commit e faz push | ||
subprocess.run(['git', 'add', 'package.json', 'package-lock.json'], check=True) | ||
subprocess.run(['git', 'commit', '-m', commit_message], check=True) | ||
subprocess.run(['git', 'push'], check=True) | ||
|
||
except subprocess.CalledProcessError as e: | ||
print(f"Erro ao executar npm-check-updates ou npm install em {full_path}:") | ||
print(f"Comando: {e.cmd}") | ||
print(f"Retorno do comando: {e.returncode}") | ||
print(f"Saída: {e.output}") | ||
print(f"Erro: {e.stderr}") | ||
|
||
os.chdir('..') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import os | ||
import subprocess | ||
|
||
# Função para atualizar dependências de um projeto | ||
def update_projects(projects, ignored_deps, commit_message, base_dir): | ||
project_list = projects.split(',') | ||
|
||
for project_dir in project_list: | ||
full_path = os.path.join(base_dir, project_dir) | ||
if not os.path.isdir(full_path): | ||
print(f"O diretório {full_path} não existe.") | ||
continue | ||
|
||
os.chdir(full_path) | ||
|
||
print(f"Verificando dependências desatualizadas em {full_path}") | ||
|
||
try: | ||
# Gera uma lista de dependências desatualizadas com nome e versão | ||
outdated_result = subprocess.run( | ||
['npm', 'outdated', '--parseable', '--depth=0'], | ||
capture_output=True, text=True | ||
) | ||
|
||
# Exibir a saída completa para depuração | ||
print(f"Saída do npm outdated:\n{outdated_result.stdout}") | ||
print(f"Erros do npm outdated:\n{outdated_result.stderr}") | ||
|
||
# Se houver dependências desatualizadas, outdated_result.returncode será 1 | ||
if outdated_result.returncode not in [0, 1]: | ||
raise subprocess.CalledProcessError(outdated_result.returncode, outdated_result.args, output=outdated_result.stdout, stderr=outdated_result.stderr) | ||
|
||
outdated_packages = outdated_result.stdout.strip() | ||
|
||
if ignored_deps: | ||
ignored_array = ignored_deps.split(',') | ||
for ignored_dep in ignored_array: | ||
outdated_packages = '\n'.join( | ||
line for line in outdated_packages.split('\n') | ||
if not line.startswith(ignored_dep + ':') | ||
) | ||
|
||
if outdated_packages: | ||
print("Dependências desatualizadas encontradas. Atualizando dependências:") | ||
for package in outdated_packages.split('\n'): | ||
package_name = package.split(':')[1] | ||
print(f" - {package_name}") | ||
|
||
# Atualiza cada pacote individualmente | ||
for package in outdated_packages.split('\n'): | ||
package_name = package.split(':')[1] | ||
print(f"Atualizando {package_name}") | ||
subprocess.run(['npm', 'install', package_name, '--legacy-peer-deps'], check=True) | ||
|
||
# Adiciona mudanças ao Git, cria um commit e faz push | ||
subprocess.run(['git', 'add', 'package.json', 'package-lock.json'], check=True) | ||
subprocess.run(['git', 'commit', '-m', commit_message], check=True) | ||
subprocess.run(['git', 'push'], check=True) | ||
else: | ||
print(f"Todas as dependências estão atualizadas em {full_path}") | ||
|
||
except subprocess.CalledProcessError as e: | ||
print(f"Erro ao verificar/atualizar dependências em {full_path}:") | ||
print(f"Comando: {e.cmd}") | ||
print(f"Retorno do comando: {e.returncode}") | ||
print(f"Saída: {e.output}") | ||
print(f"Erro: {e.stderr}") | ||
|
||
os.chdir('..') |
Oops, something went wrong.