@agtm/ncli
Advanced tools
+1
-1
| { | ||
| "name": "@agtm/ncli", | ||
| "version": "5.3.0", | ||
| "version": "5.3.1", | ||
| "description": "Conjuntos de scripts para auxiliar no desenvolvimento de projetos node.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+48
-25
@@ -50,2 +50,23 @@ #!/usr/bin/env node | ||
| async function checkModuleHasChange (modulePath, moduleInfo) { | ||
| const status = await checkGitStatus(modulePath) | ||
| for (const file of status.files) { | ||
| // Se tem outros arquivos para commitar, já marca como has change diretamente | ||
| if (!['package-lock.json', 'package.json'].includes(file.path)) return true | ||
| const git = simpleGit(modulePath) | ||
| const diff = await git.diff(['--unified=0', '--no-color', '--no-prefix', 'package.json']) | ||
| const versionChangeRegex = /^(\+|\-)\s+"version":\s*"\d+\.\d+\.\d+",$/m | ||
| // Verifica se tem outras alterações além da versão | ||
| if (!versionChangeRegex.test(diff)) return true | ||
| } | ||
| return false | ||
| } | ||
| // Função para gerar o JSON com informações dos módulos | ||
@@ -57,2 +78,3 @@ async function generateModuleInfo () { | ||
| for (const moduleName of await fs.promises.readdir(modulesDirectory)) { | ||
| const modulePath = join(modulesDirectory, moduleName) | ||
@@ -84,4 +106,3 @@ if ((await fs.promises.stat(modulePath)).isDirectory()) { | ||
| try { | ||
| const status = await checkGitStatus(modulePath) | ||
| moduleInfo.hasChanges = status.files.length > 0 | ||
| moduleInfo.hasChanges = await checkModuleHasChange(modulePath, moduleInfo) | ||
| modulesInfo.push(moduleInfo) | ||
@@ -114,4 +135,2 @@ | ||
| function isModuleInstalled (moduleName) { | ||
@@ -150,5 +169,5 @@ | ||
| if (dependency === moduleInfo.name){ | ||
| if (dependency === moduleInfo.name) { | ||
| installedVersion = result.dependencies[dependency].version | ||
| }else{ | ||
| } else { | ||
| nestedModules[dependency] = result.dependencies[dependency] | ||
@@ -158,3 +177,6 @@ } | ||
| } | ||
| return {installedVersion, nestedModules} | ||
| return { | ||
| installedVersion, | ||
| nestedModules | ||
| } | ||
| } catch (e) { | ||
@@ -180,5 +202,5 @@ throw e | ||
| if (error.code === 1 && error.stdout){ | ||
| if (error.code === 1 && error.stdout) { | ||
| return false | ||
| }else{ | ||
| } else { | ||
| throw error | ||
@@ -190,3 +212,3 @@ } | ||
| // Função recursiva para verificar as versões das dependências | ||
| function checkNestedModules(targetModule, nestedModules, targetVersion, path = '') { | ||
| function checkNestedModules (targetModule, nestedModules, targetVersion, path = '') { | ||
@@ -200,5 +222,5 @@ let oldVersions = [] | ||
| if (nestedModuleName === targetModule){ | ||
| if (nestedModuleName === targetModule) { | ||
| if (nestedModule.version !== targetVersion){ | ||
| if (nestedModule.version !== targetVersion) { | ||
| oldVersions.push({ | ||
@@ -212,3 +234,3 @@ path: pathNestedModule, | ||
| if (nestedModule.dependencies){ | ||
| if (nestedModule.dependencies) { | ||
| const result = checkNestedModules(targetModule, nestedModule.dependencies, targetVersion, pathNestedModule) | ||
@@ -247,4 +269,7 @@ oldVersions = oldVersions.concat(result) | ||
| const oldNesteModulesDescription = (module.oldNestedModules.map(dep => { | ||
| const { path, version } = dep; | ||
| return `${path} ${chalk.red.bold(`[${version}]`)}`; | ||
| const { | ||
| path, | ||
| version | ||
| } = dep | ||
| return `${path} ${chalk.red.bold(`[${version}]`)}` | ||
| })).join('\n') | ||
@@ -255,4 +280,4 @@ | ||
| tableData.push([ | ||
| warn ? chalk.red.bold(module.name) : module.name, | ||
| linked ? chalk.red.bold('Linked') : 'No' , | ||
| warn ? chalk.red.bold(module.name) : module.name, | ||
| linked ? chalk.red.bold('Linked') : 'No', | ||
| hasChanges ? chalk.red.bold('YES') : 'No', | ||
@@ -269,7 +294,7 @@ isPublishable ? chalk.red.bold('YES') : 'No', | ||
| // Imprime a tabela no terminal | ||
| console.log(table(tableData)) | ||
| console.log(`\nReady for deployment: ${statusOk ? chalk.green.bold('Yes') : chalk.red.bold('NOT!!!') }\n`) | ||
| console.log(`\nReady for deployment: ${statusOk ? chalk.green.bold('Yes') : chalk.red.bold('NOT!!!')}\n`) | ||
| return statusOk | ||
| } | ||
@@ -290,3 +315,2 @@ | ||
| ///////////////////////////////////////////////////////////////// | ||
@@ -311,6 +335,5 @@ // Verifica versão instalada e se Modulo está linkado | ||
| if (!printTable(installedModules)) { | ||
| process.exit(1) | ||
| } | ||
| // console.log(moduleInfo) | ||
| printTable(installedModules) | ||
| // displayJSONResult(moduleInfo) |
100396
0.66%1052
1.84%