eitri-cli 1.4.0-beta.6 → 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 +2 -2
- package/src/cmd/push-version.js +39 -22
- package/src/service/ReleaseService.js +126 -0
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eitri-cli",
|
|
3
|
-
"version": "1.4.0-beta.
|
|
3
|
+
"version": "1.4.0-beta.8",
|
|
4
4
|
"description": "Command Line Interface to make \"Eitri-App\" with code and fire.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"lint-staged": "^9.5.0",
|
|
79
79
|
"nock": "^13.3.0",
|
|
80
80
|
"puppeteer": "^21.4.1",
|
|
81
|
-
"semantic-release": "^22.0.
|
|
81
|
+
"semantic-release": "^22.0.8"
|
|
82
82
|
},
|
|
83
83
|
"resolutions": {
|
|
84
84
|
"lodash": "4.17.21",
|
package/src/cmd/push-version.js
CHANGED
|
@@ -17,6 +17,8 @@ const trackingService = new TrackingService(blindGuardian)
|
|
|
17
17
|
const targetService = new TargetService(workspace)
|
|
18
18
|
const vegvisirService = new VegvisirService()
|
|
19
19
|
const standardVersion = require('standard-version')
|
|
20
|
+
const releaseService = require('../service/ReleaseService')
|
|
21
|
+
const {isGitRepo} = require('../util/GenericUtils')
|
|
20
22
|
|
|
21
23
|
module.exports = async function pushVersion(cmdObj) {
|
|
22
24
|
try {
|
|
@@ -27,6 +29,8 @@ module.exports = async function pushVersion(cmdObj) {
|
|
|
27
29
|
return
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
const separator = '======================================================================='
|
|
33
|
+
|
|
30
34
|
try {
|
|
31
35
|
await validator.assertPushVersionMessage(cmdObj.message)
|
|
32
36
|
await validator.assertCommandNotRunning('push-version')
|
|
@@ -42,9 +46,43 @@ module.exports = async function pushVersion(cmdObj) {
|
|
|
42
46
|
const miniConf = workspace.getMiniConf()
|
|
43
47
|
|
|
44
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
|
+
|
|
45
83
|
console.log("Iniciando geração de versão com CI")
|
|
46
84
|
try {
|
|
47
|
-
await
|
|
85
|
+
await releaseService()
|
|
48
86
|
const lastTag = childProcess.execSync('git describe --tags --abbrev=0').toString().trim();
|
|
49
87
|
const newVersion = lastTag?.replace(/^v/, "");
|
|
50
88
|
console.log(`Nova versão preparada: ${newVersion}`)
|
|
@@ -100,7 +138,6 @@ ${await targetService.getAppConfExampleSnippet()}
|
|
|
100
138
|
|
|
101
139
|
return
|
|
102
140
|
}
|
|
103
|
-
const separator = '======================================================================='
|
|
104
141
|
blindGuardian.readConf()
|
|
105
142
|
workspace.setServerUrl(config.get('workspace').url)
|
|
106
143
|
console.log('Conectando ao Eitri...')
|
|
@@ -217,23 +254,3 @@ async function logPermissionsAndOpenPrompt(addedPermissions, removedPermissions,
|
|
|
217
254
|
}
|
|
218
255
|
}
|
|
219
256
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
async function releaseGenerator(cmdObj) {
|
|
223
|
-
return new Promise((resolve, reject) => {
|
|
224
|
-
standardVersion({
|
|
225
|
-
noVerify: true,
|
|
226
|
-
silent: true,
|
|
227
|
-
releaseCommitMessageFormat: "[skip ci]"
|
|
228
|
-
}).then(() => {
|
|
229
|
-
resolve()
|
|
230
|
-
}).catch(err => {
|
|
231
|
-
if (cmdObj?.verbose) {
|
|
232
|
-
console.error(`standard-version failed with message: ${err?.message}`)
|
|
233
|
-
}
|
|
234
|
-
const errorMessage = "Ocorreu um erro ao gerar a versão. Por favor, verifique se a versão foi gerada no Console."
|
|
235
|
-
reject(errorMessage)
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
})
|
|
239
|
-
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const childProcess = require('child_process')
|
|
4
|
+
const rimraf = require('rimraf');
|
|
5
|
+
|
|
6
|
+
const TEMP_FOLDER_NAME = "temp_eitri_ci"
|
|
7
|
+
const TEMP_CHANGELOG_FILE_NAME = "CHANGELOG_TEMP"
|
|
8
|
+
const CHANGELOG_FILE_NAME = "CHANGELOG.md"
|
|
9
|
+
|
|
10
|
+
module.exports = async function releaseService() {
|
|
11
|
+
_printLog(`\x1b[1m\x1b[32mIniciando Geração Automática de Versão\x1b[0m`)
|
|
12
|
+
await _factoryTempFolder()
|
|
13
|
+
await _factoryReleaseConfig()
|
|
14
|
+
await _downloadDependencies()
|
|
15
|
+
await _installDependencies()
|
|
16
|
+
await _updateChangeLog()
|
|
17
|
+
await _clearResources()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function _factoryTempFolder() {
|
|
21
|
+
try {
|
|
22
|
+
fs.mkdirSync(TEMP_FOLDER_NAME, {recursive: true})
|
|
23
|
+
} catch (error) {
|
|
24
|
+
_throwError("Erro ao gerar pasta temporária", error?.message)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function _factoryReleaseConfig() {
|
|
29
|
+
try {
|
|
30
|
+
const releasercContent = {
|
|
31
|
+
"branches": [
|
|
32
|
+
"main",
|
|
33
|
+
"master",
|
|
34
|
+
],
|
|
35
|
+
"plugins": [
|
|
36
|
+
"@semantic-release/commit-analyzer",
|
|
37
|
+
"@semantic-release/release-notes-generator",
|
|
38
|
+
[
|
|
39
|
+
"@semantic-release/changelog",
|
|
40
|
+
{
|
|
41
|
+
"changelogFile": `${TEMP_CHANGELOG_FILE_NAME}.md`
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
[
|
|
45
|
+
"@semantic-release/git",
|
|
46
|
+
{
|
|
47
|
+
"assets": [
|
|
48
|
+
`${CHANGELOG_FILE_NAME}`,
|
|
49
|
+
"eitri-app.conf.js",
|
|
50
|
+
`!${TEMP_FOLDER_NAME}`
|
|
51
|
+
],
|
|
52
|
+
"message": "chore(release): ${nextRelease.version}[skip ci]\n\n${nextRelease.notes}"
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const releasercFilePath = path.join(TEMP_FOLDER_NAME, '.releaserc.json');
|
|
59
|
+
fs.writeFileSync(releasercFilePath, JSON.stringify(releasercContent, null, 2));
|
|
60
|
+
} catch (error) {
|
|
61
|
+
_throwError("Erro ao criar o arquivo de configuração da release", error?.message)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function _downloadDependencies() {
|
|
66
|
+
_printLog("Baixando as configurações. Este processo pode demorar alguns segundos.")
|
|
67
|
+
childProcess.execSync(`cd ${TEMP_FOLDER_NAME}/ && npm i semantic-release @semantic-release/git @semantic-release/changelog`)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function _installDependencies() {
|
|
71
|
+
_printLog("Instalando configuração temporária de CI. Este processo pode demorar alguns segundos.")
|
|
72
|
+
childProcess.execSync(`cd ${TEMP_FOLDER_NAME}/ && npx semantic-release --no-ci --no-npm-publish --no-github-publish --working-directory=${TEMP_FOLDER_NAME} --skip-verify-conditions`)
|
|
73
|
+
_printLog("Configuração de CI instalada", TEMP_CHANGELOG_FILE_NAME)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function _updateChangeLog() {
|
|
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}`)
|
|
80
|
+
const contentNewChangelog = fs.readFileSync(`${TEMP_FOLDER_NAME}/${TEMP_CHANGELOG_FILE_NAME}.md`, "utf-8");
|
|
81
|
+
const newPath = path.join(`${CHANGELOG_FILE_NAME}`)
|
|
82
|
+
|
|
83
|
+
if (!fs.existsSync(newPath)) {
|
|
84
|
+
await _createChangeLogMd()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const contentOriginalChangelog = fs.readFileSync(newPath, "utf-8")
|
|
88
|
+
const newContent = contentNewChangelog + "\n\n" + contentOriginalChangelog
|
|
89
|
+
fs.writeFileSync(newPath, newContent)
|
|
90
|
+
|
|
91
|
+
_printLog(`Arquivo ${CHANGELOG_FILE_NAME} atualizado`)
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
_throwError("Arquivo temporário de Changelog não gerado", {hasTempChangelog})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function _clearResources() {
|
|
99
|
+
rimraf(TEMP_FOLDER_NAME, (error) => {
|
|
100
|
+
if (error) {
|
|
101
|
+
_throwError(`Erro ao remover a pasta ${TEMP_FOLDER_NAME}:`, error?.message)
|
|
102
|
+
} else {
|
|
103
|
+
_printLog(`Limpando pasta temporária ${TEMP_FOLDER_NAME}`);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function _createChangeLogMd(newPath) {
|
|
109
|
+
_printLog(`Arquivo de ${CHANGELOG_FILE_NAME} inexistente. [Changelog: ${newPath}]`)
|
|
110
|
+
_printLog("Criando arquivo")
|
|
111
|
+
fs.writeFileSync(`${CHANGELOG_FILE_NAME}`, "");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function _printLog(text = "", isError = false) {
|
|
115
|
+
if (isError) {
|
|
116
|
+
console.error("\n" + text)
|
|
117
|
+
} else {
|
|
118
|
+
console.log("\n" + text)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function _throwError(text = "", errorMessage = "") {
|
|
123
|
+
const error = `${text} [message: ${errorMessage}]`
|
|
124
|
+
_printLog(error, !!error)
|
|
125
|
+
throw new Error(error)
|
|
126
|
+
}
|
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");
|