eitri-cli 1.4.0-beta.7 → 1.4.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cmd/push-version.js +37 -1
- package/src/service/ReleaseService.js +16 -13
- package/src/util/GenericUtils.js +11 -0
- package/test/Executor.js +1 -1
- package/test/e2e/cli.test.js +1 -0
package/package.json
CHANGED
package/src/cmd/push-version.js
CHANGED
|
@@ -18,6 +18,7 @@ const targetService = new TargetService(workspace)
|
|
|
18
18
|
const vegvisirService = new VegvisirService()
|
|
19
19
|
const standardVersion = require('standard-version')
|
|
20
20
|
const releaseService = require('../service/ReleaseService')
|
|
21
|
+
const {isGitRepo} = require('../util/GenericUtils')
|
|
21
22
|
|
|
22
23
|
module.exports = async function pushVersion(cmdObj) {
|
|
23
24
|
try {
|
|
@@ -28,6 +29,8 @@ module.exports = async function pushVersion(cmdObj) {
|
|
|
28
29
|
return
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
const separator = '======================================================================='
|
|
33
|
+
|
|
31
34
|
try {
|
|
32
35
|
await validator.assertPushVersionMessage(cmdObj.message)
|
|
33
36
|
await validator.assertCommandNotRunning('push-version')
|
|
@@ -43,6 +46,40 @@ module.exports = async function pushVersion(cmdObj) {
|
|
|
43
46
|
const miniConf = workspace.getMiniConf()
|
|
44
47
|
|
|
45
48
|
if (cmdObj?.release) {
|
|
49
|
+
if (!isGitRepo()) {
|
|
50
|
+
const emptyGitRepoMessages = [
|
|
51
|
+
"Este projeto não tem um repositório git. Processo interrompido.",
|
|
52
|
+
"Por favor, inicialize o git neste repositório antes de",
|
|
53
|
+
"realizar [push-version --release]"
|
|
54
|
+
]
|
|
55
|
+
console.log(`\x1b[1m\x1b[31m${emptyGitRepoMessages?.join("\n")}\x1b[0m`);
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const currentBranch = childProcess.execSync("git branch --show-current", {encoding: 'utf-8'}).trim();
|
|
60
|
+
const allowedBranchs = ["main", "master"]
|
|
61
|
+
const isAllowedFlow = allowedBranchs?.includes(currentBranch)
|
|
62
|
+
if(!isAllowedFlow){
|
|
63
|
+
const warningMessages = [
|
|
64
|
+
'\n\n',
|
|
65
|
+
separator,
|
|
66
|
+
'Aviso: As condições obrigatórias não foram contempladas.',
|
|
67
|
+
'\n',
|
|
68
|
+
'Por favor, certifique-se de:',
|
|
69
|
+
'- Informar o comando "release" ao executar o script.',
|
|
70
|
+
'- Estar na branch "master" ou "main".',
|
|
71
|
+
` - Branch atual: [${currentBranch}]`,
|
|
72
|
+
'\n',
|
|
73
|
+
'Nenhuma versão foi gerada e enviada.',
|
|
74
|
+
separator,
|
|
75
|
+
'\n\n',
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
console.log(`\x1b[1m\x1b[33m${warningMessages?.join("\n")}\x1b[0m`);
|
|
79
|
+
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
46
83
|
console.log("Iniciando geração de versão com CI")
|
|
47
84
|
try {
|
|
48
85
|
await releaseService()
|
|
@@ -101,7 +138,6 @@ ${await targetService.getAppConfExampleSnippet()}
|
|
|
101
138
|
|
|
102
139
|
return
|
|
103
140
|
}
|
|
104
|
-
const separator = '======================================================================='
|
|
105
141
|
blindGuardian.readConf()
|
|
106
142
|
workspace.setServerUrl(config.get('workspace').url)
|
|
107
143
|
console.log('Conectando ao Eitri...')
|
|
@@ -5,6 +5,7 @@ const rimraf = require('rimraf');
|
|
|
5
5
|
|
|
6
6
|
const TEMP_FOLDER_NAME = "temp_eitri_ci"
|
|
7
7
|
const TEMP_CHANGELOG_FILE_NAME = "CHANGELOG_TEMP"
|
|
8
|
+
const CHANGELOG_FILE_NAME = "CHANGELOG.md"
|
|
8
9
|
|
|
9
10
|
module.exports = async function releaseService() {
|
|
10
11
|
_printLog(`\x1b[1m\x1b[32mIniciando Geração Automática de Versão\x1b[0m`)
|
|
@@ -44,7 +45,7 @@ async function _factoryReleaseConfig() {
|
|
|
44
45
|
"@semantic-release/git",
|
|
45
46
|
{
|
|
46
47
|
"assets": [
|
|
47
|
-
|
|
48
|
+
`${CHANGELOG_FILE_NAME}`,
|
|
48
49
|
"eitri-app.conf.js",
|
|
49
50
|
`!${TEMP_FOLDER_NAME}`
|
|
50
51
|
],
|
|
@@ -73,29 +74,31 @@ async function _installDependencies() {
|
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
async function _updateChangeLog() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
const hasTempChangelog = fs.existsSync(`${TEMP_FOLDER_NAME}/${TEMP_CHANGELOG_FILE_NAME}.md`)
|
|
78
|
+
if (hasTempChangelog) {
|
|
79
|
+
_printLog(`Iniciando atualização do ${CHANGELOG_FILE_NAME}`)
|
|
79
80
|
const contentNewChangelog = fs.readFileSync(`${TEMP_FOLDER_NAME}/${TEMP_CHANGELOG_FILE_NAME}.md`, "utf-8");
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
_printLog("INICIO 2 Iniciando geração de changelog", newPath)
|
|
81
|
+
const newPath = path.join(`${CHANGELOG_FILE_NAME}`)
|
|
82
|
+
|
|
83
83
|
if (!fs.existsSync(newPath)) {
|
|
84
84
|
await _createChangeLogMd()
|
|
85
85
|
}
|
|
86
|
+
|
|
86
87
|
const contentOriginalChangelog = fs.readFileSync(newPath, "utf-8")
|
|
87
|
-
_printLog("FIM 2 Iniciando geração de changelog")
|
|
88
88
|
const newContent = contentNewChangelog + "\n\n" + contentOriginalChangelog
|
|
89
89
|
fs.writeFileSync(newPath, newContent)
|
|
90
|
-
|
|
90
|
+
|
|
91
|
+
_printLog(`Arquivo ${CHANGELOG_FILE_NAME} atualizado`)
|
|
92
|
+
return
|
|
91
93
|
}
|
|
94
|
+
|
|
95
|
+
_throwError("Arquivo temporário de Changelog não gerado", {hasTempChangelog})
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
async function _clearResources() {
|
|
95
99
|
rimraf(TEMP_FOLDER_NAME, (error) => {
|
|
96
100
|
if (error) {
|
|
97
|
-
|
|
98
|
-
reject(error)
|
|
101
|
+
_throwError(`Erro ao remover a pasta ${TEMP_FOLDER_NAME}:`, error?.message)
|
|
99
102
|
} else {
|
|
100
103
|
_printLog(`Limpando pasta temporária ${TEMP_FOLDER_NAME}`);
|
|
101
104
|
}
|
|
@@ -103,9 +106,9 @@ async function _clearResources() {
|
|
|
103
106
|
}
|
|
104
107
|
|
|
105
108
|
async function _createChangeLogMd(newPath) {
|
|
106
|
-
_printLog(`Arquivo de
|
|
109
|
+
_printLog(`Arquivo de ${CHANGELOG_FILE_NAME} inexistente. [Changelog: ${newPath}]`)
|
|
107
110
|
_printLog("Criando arquivo")
|
|
108
|
-
fs.writeFileSync(
|
|
111
|
+
fs.writeFileSync(`${CHANGELOG_FILE_NAME}`, "");
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
function _printLog(text = "", isError = false) {
|
package/src/util/GenericUtils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const childProcess = require('child_process')
|
|
1
2
|
class GenericUtils {
|
|
2
3
|
|
|
3
4
|
static formatQrCodeCurrentDateTime = () => {
|
|
@@ -19,6 +20,16 @@ class GenericUtils {
|
|
|
19
20
|
return uuid && typeof uuid === "string" && regexExp.test(uuid)
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
static isGitRepo() {
|
|
24
|
+
try {
|
|
25
|
+
const gitCommand = "git branch --show-current";
|
|
26
|
+
const res = childProcess.execSync(gitCommand, {encoding: 'utf-8'}).trim();
|
|
27
|
+
return !!res
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
}
|
|
23
34
|
|
|
24
35
|
module.exports = GenericUtils
|
package/test/Executor.js
CHANGED
package/test/e2e/cli.test.js
CHANGED
|
@@ -9,6 +9,7 @@ const Helper = require("../Helper.js");
|
|
|
9
9
|
const ConfigService = require("../../src/service/ConfigService.js");
|
|
10
10
|
const Http = require("../../src/service/Http.js");
|
|
11
11
|
const BlindGuardian = require("../../src/service/BlindGuardian.js");
|
|
12
|
+
const childProcess = require('child_process')
|
|
12
13
|
|
|
13
14
|
describe("eitri-cli", () => {
|
|
14
15
|
const EITRI_WORK_DIR = path.join(__dirname, "..", "..", "developer-folder");
|