eitri-cli 1.38.0 → 1.39.0-beta.2
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/eitri-cli-v2/eitri-cli-v2.darwin-arm64.node +0 -0
- package/eitri-cli-v2/eitri-cli-v2.darwin-x64.node +0 -0
- package/eitri-cli-v2/eitri-cli-v2.linux-x64-gnu.node +0 -0
- package/eitri-cli-v2/eitri-cli-v2.win32-x64-msvc.node +0 -0
- package/index.js +3 -20
- package/package.json +4 -49
- package/.eslintrc.json +0 -26
- package/.prettierrc +0 -6
- package/src/cmd/clean.js +0 -144
- package/src/cmd/create.js +0 -332
- package/src/cmd/credentials.js +0 -105
- package/src/cmd/doctor.js +0 -70
- package/src/cmd/invite.js +0 -87
- package/src/cmd/list.js +0 -36
- package/src/cmd/login.js +0 -70
- package/src/cmd/loginV2.js +0 -89
- package/src/cmd/manage-env.js +0 -129
- package/src/cmd/open-share.js +0 -6
- package/src/cmd/order-details.js +0 -6
- package/src/cmd/push-version.js +0 -260
- package/src/cmd/show-message-if-outdated-package.js +0 -32
- package/src/cmd/signup.js +0 -71
- package/src/cmd/start.js +0 -181
- package/src/cmd/tail-logs.js +0 -26
- package/src/cmd/test-initialization-params.js +0 -6
- package/src/cmd/validate.js +0 -164
- package/src/cmd/version.js +0 -18
- package/src/enum/WatcherOpts.js +0 -3
- package/src/enum/target.js +0 -6
- package/src/helpers/request-listener-helper.js +0 -55
- package/src/model/EitriAppType.js +0 -4
- package/src/model/Payload.js +0 -45
- package/src/model/Target.js +0 -61
- package/src/model/User.js +0 -11
- package/src/service/AuthConfig.js +0 -85
- package/src/service/BlindGuardian.js +0 -131
- package/src/service/CliLogin.js +0 -52
- package/src/service/ConfigService.js +0 -9
- package/src/service/CredentialsService.js +0 -47
- package/src/service/EitriAppManager.js +0 -32
- package/src/service/EitriAppService.js +0 -49
- package/src/service/Emulator/AndroidEmulatorService.js +0 -132
- package/src/service/Emulator/IOSEmulatorService.js +0 -71
- package/src/service/EmulatorService.js +0 -17
- package/src/service/GATrackingStrategy.js +0 -16
- package/src/service/HashFolder.js +0 -79
- package/src/service/Http.js +0 -300
- package/src/service/HuginService.js +0 -38
- package/src/service/InviteService.js +0 -45
- package/src/service/LibsService.js +0 -191
- package/src/service/ManageEnvService.js +0 -10
- package/src/service/MiniLog.js +0 -166
- package/src/service/PrerequisitesValidator.js +0 -99
- package/src/service/QRCodeFactory.js +0 -81
- package/src/service/ReleaseService.js +0 -126
- package/src/service/Server.js +0 -220
- package/src/service/StarterService.js +0 -31
- package/src/service/TagTree.js +0 -101
- package/src/service/TargetService.js +0 -97
- package/src/service/TrackService.js +0 -11
- package/src/service/TrackingEitriAnalytics.js +0 -26
- package/src/service/TrackingService.js +0 -183
- package/src/service/ValidateResult.js +0 -57
- package/src/service/Watcher.js +0 -118
- package/src/service/Workspace.js +0 -1045
- package/src/service/WorkspaceManager.js +0 -76
- package/src/service/factories/DoubtsStarterFactory.js +0 -25
- package/src/service/factories/MiniWebAppFactory.js +0 -44
- package/src/service/factories/QRCodeStarterFactory.js +0 -154
- package/src/service/factories/WebStarterFactory.js +0 -88
- package/src/service/factories/WoodCoffeeFactory.js +0 -292
- package/src/util/AboutTemplate.jsx +0 -14
- package/src/util/FileUtils.js +0 -25
- package/src/util/GenericUtils.js +0 -41
- package/src/util/LibUtil.js +0 -32
- package/src/util/LogUtil.js +0 -14
- package/src/util/UrlUtils.js +0 -12
- package/src/util/UserLocalCredential.js +0 -128
- package/src/util/convertKeysToCamelCase.js +0 -26
- package/src/util/error-messages/error-messages.js +0 -24
- package/src/util/error-messages/invite/invite-error-messages.js +0 -14
- package/src/util/getCliVersion.js +0 -13
- package/src/util/getCreateFactory.js +0 -9
- package/src/util/getWorkspace.js +0 -37
- package/src/util/ipv4.js +0 -19
- package/src/util/manage-env.js +0 -65
- package/src/util/open-docs.js +0 -7
- package/src/util/os.js +0 -39
- package/src/util/server-url.js +0 -15
- package/src/util/template-utils.js +0 -21
- package/src/view/index.html +0 -19
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.js
CHANGED
|
@@ -3,8 +3,6 @@ const commander = require("commander");
|
|
|
3
3
|
const program = new commander.Command();
|
|
4
4
|
const emoji = require("emojilib");
|
|
5
5
|
const path = require("path");
|
|
6
|
-
const { workspace } = require("./src/service/Workspace");
|
|
7
|
-
const configService = require("./src/service/ConfigService");
|
|
8
6
|
const VegvisirCommand = require("./src/modules/vegvisir/VegvisirCommand");
|
|
9
7
|
const AppCommand = require("./src/modules/app/AppCommand");
|
|
10
8
|
const debug = require("debug")("eitri:run");
|
|
@@ -32,17 +30,7 @@ const run = async () => {
|
|
|
32
30
|
// Temporariamente necessário por conta de no contexto do Rust não saber o diretório atual, dessa forma exportando o fullPath do config é possível.
|
|
33
31
|
// Quando se tornar uma CLI somente em rust no processo de instalação podemos declarar o caminho, como é via NPM pode ter caminhos variados de acordo com sistema de versionamento, NVM, Volta, ASDF é necessário a variável abaixo.
|
|
34
32
|
process.env.CONFIG_DIR_PATH = path.join(__dirname, "eitri-cli-v2", "config");
|
|
35
|
-
|
|
36
|
-
const srcFolder2watch = path.join(process.cwd(), "src");
|
|
37
|
-
workspace.setFolder2Watch(srcFolder2watch);
|
|
38
|
-
workspace.setServerUrl(`${configService.get("workspace").url}`);
|
|
39
|
-
} catch (e) {
|
|
40
|
-
debug("Erro no set da pasta", { message: e?.message, error: e });
|
|
41
|
-
if (process.env.LOG_LEVEL === "full") {
|
|
42
|
-
console.log("Current directory listening has failed", e);
|
|
43
|
-
}
|
|
44
|
-
// Continuando como antes...
|
|
45
|
-
}
|
|
33
|
+
|
|
46
34
|
|
|
47
35
|
|
|
48
36
|
try {
|
|
@@ -72,14 +60,9 @@ const run = async () => {
|
|
|
72
60
|
.option("--yes", "Aceita o redirecionamento para o console")
|
|
73
61
|
.option("-v, --verbose", "Exibe mais logs")
|
|
74
62
|
.action(async (cmdObj) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
await globalEitriCLIV2.login(cmdObj)
|
|
78
|
-
return
|
|
79
|
-
}
|
|
63
|
+
await globalEitriCLIV2.login(cmdObj)
|
|
64
|
+
return
|
|
80
65
|
|
|
81
|
-
console.log("\n\n Iniciando login \n");
|
|
82
|
-
require("./src/cmd/loginV2")(cmdObj);
|
|
83
66
|
});
|
|
84
67
|
|
|
85
68
|
program
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eitri-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.39.0-beta.2",
|
|
4
4
|
"description": "Command Line Interface to make \"Eitri-App\" with code and fire.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -24,43 +24,12 @@
|
|
|
24
24
|
"author": "Calindra",
|
|
25
25
|
"license": "ISC",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"adm-zip": "^0.5.9",
|
|
28
27
|
"axios": "^1.7.2",
|
|
29
|
-
"axios-cookiejar-support": "^5.0.2",
|
|
30
|
-
"base-64": "^0.1.0",
|
|
31
|
-
"base64url": "^3.0.1",
|
|
32
|
-
"camelcase": "^6.3.0",
|
|
33
|
-
"chalk": "^3.0.0",
|
|
34
|
-
"cheerio": "^1.0.0-rc.3",
|
|
35
|
-
"cli-progress": "^3.4.0",
|
|
36
28
|
"commander": "^9.2.0",
|
|
37
|
-
"
|
|
38
|
-
"cors": "^2.8.5",
|
|
29
|
+
"debug": "^4.4.0",
|
|
39
30
|
"emojilib": "^2.4.0",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"figlet": "^1.2.4",
|
|
43
|
-
"folder-hash": "^3.3.0",
|
|
44
|
-
"form-data": "^4.0.0",
|
|
45
|
-
"get-folder-size": "^2.0.1",
|
|
46
|
-
"inquirer": "^7.0.0",
|
|
47
|
-
"js-yaml": "^4.1.0",
|
|
48
|
-
"jsonwebtoken": "^9.0.2",
|
|
49
|
-
"lz-string": "^1.5.0",
|
|
50
|
-
"node-watch": "^0.6.3",
|
|
51
|
-
"open": "^7.0.0",
|
|
52
|
-
"ps-node": "^0.1.6",
|
|
53
|
-
"qrcode": "^1.5.3",
|
|
54
|
-
"semver": "^7.1.3",
|
|
55
|
-
"slugify": "^1.4.0",
|
|
56
|
-
"socket.io-client": "^4.5.2",
|
|
57
|
-
"standard-version": "^9.5.0",
|
|
58
|
-
"temp-dir": "^2.0.0",
|
|
59
|
-
"tmp": "^0.1.0",
|
|
60
|
-
"tough-cookie": "^4.1.4",
|
|
61
|
-
"tough-cookie-file-store": "^2.0.2",
|
|
62
|
-
"uuid": "^7.0.2",
|
|
63
|
-
"yaml": "^2.4.2"
|
|
31
|
+
"semver": "^7.7.0",
|
|
32
|
+
"uuid": "^7.0.2"
|
|
64
33
|
},
|
|
65
34
|
"devDependencies": {
|
|
66
35
|
"@commitlint/cli": "^17.7.2",
|
|
@@ -68,24 +37,10 @@
|
|
|
68
37
|
"@faker-js/faker": "^7.6.0",
|
|
69
38
|
"@semantic-release/changelog": "^6.0.3",
|
|
70
39
|
"@semantic-release/git": "^10.0.1",
|
|
71
|
-
"eslint": "^9.5.0",
|
|
72
|
-
"eslint-config-google": "^0.14.0",
|
|
73
|
-
"eslint-plugin-jest": "^28.6.0",
|
|
74
|
-
"eslint-plugin-prettier": "^5.1.3",
|
|
75
40
|
"husky": "^8.0.3",
|
|
76
41
|
"jest": "^29.7.0",
|
|
77
42
|
"lint-staged": "^9.5.0",
|
|
78
|
-
"nock": "^13.3.0",
|
|
79
|
-
"prettier": "^3.3.2",
|
|
80
43
|
"puppeteer": "22.12.1",
|
|
81
44
|
"semantic-release": "^22.0.8"
|
|
82
|
-
},
|
|
83
|
-
"resolutions": {
|
|
84
|
-
"lodash": "4.17.21",
|
|
85
|
-
"minimist": "1.2.6",
|
|
86
|
-
"ansi-regex": "5.0.1",
|
|
87
|
-
"merge": "2.1.1",
|
|
88
|
-
"tar": "6.1.9",
|
|
89
|
-
"handlebars": "4.7.7"
|
|
90
45
|
}
|
|
91
46
|
}
|
package/.eslintrc.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"extends": ["eslint:recommended", "google", "plugin:prettier/recommended", "plugin:jest/recommended"],
|
|
4
|
-
"plugins": ["prettier", "jest"],
|
|
5
|
-
"env": {
|
|
6
|
-
"es6": true,
|
|
7
|
-
"node": true
|
|
8
|
-
},
|
|
9
|
-
"globals": {
|
|
10
|
-
"Atomics": "readonly",
|
|
11
|
-
"SharedArrayBuffer": "readonly"
|
|
12
|
-
},
|
|
13
|
-
"parserOptions": {
|
|
14
|
-
"sourceType": "commonjs"
|
|
15
|
-
},
|
|
16
|
-
"rules": {
|
|
17
|
-
"jest/no-conditional-expect": "warn",
|
|
18
|
-
"jest/no-focused-tests": "warn",
|
|
19
|
-
"prefer-const": "warn",
|
|
20
|
-
"prefer-rest-params": "warn",
|
|
21
|
-
"no-unused-expressions": "error",
|
|
22
|
-
"no-undef": "error",
|
|
23
|
-
"prettier/prettier": "error",
|
|
24
|
-
"no-console": "off"
|
|
25
|
-
}
|
|
26
|
-
}
|
package/.prettierrc
DELETED
package/src/cmd/clean.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
const { workspace } = require('../service/Workspace')
|
|
2
|
-
const validator = require('./validate')
|
|
3
|
-
const TrackingService = require('../service/TrackingService')
|
|
4
|
-
const config = require('../service/ConfigService')
|
|
5
|
-
const TargetService = require('../service/TargetService')
|
|
6
|
-
const inquirer = require('inquirer')
|
|
7
|
-
const TrackingEitriAnalytics = require('../service/TrackingEitriAnalytics')
|
|
8
|
-
const UserLocalCredential = require('../util/UserLocalCredential')
|
|
9
|
-
|
|
10
|
-
const blindGuardian = workspace.blindGuardian
|
|
11
|
-
const trackingService = new TrackingService(blindGuardian)
|
|
12
|
-
const targetService = new TargetService(workspace)
|
|
13
|
-
|
|
14
|
-
module.exports = async function clean(cmdObj) {
|
|
15
|
-
try {
|
|
16
|
-
UserLocalCredential.checkForCredentials()
|
|
17
|
-
} catch (error) {
|
|
18
|
-
const errorMessage = cmdObj?.verbose ? error : error?.message
|
|
19
|
-
console.error("\n", errorMessage, "\n")
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
await validator.assertCommandNotRunning('clean')
|
|
25
|
-
|
|
26
|
-
blindGuardian.readConf()
|
|
27
|
-
workspace.setServerUrl(config.get('workspace').url)
|
|
28
|
-
await workspace.init()
|
|
29
|
-
|
|
30
|
-
console.log('Limpando compilador')
|
|
31
|
-
|
|
32
|
-
await workspace.clean()
|
|
33
|
-
|
|
34
|
-
console.log('[1] Limpo.')
|
|
35
|
-
|
|
36
|
-
TrackingEitriAnalytics.sendEvent({
|
|
37
|
-
eventName: "clean",
|
|
38
|
-
userId: workspace?.userEmail
|
|
39
|
-
})
|
|
40
|
-
process.exit(0)
|
|
41
|
-
} catch (e) {
|
|
42
|
-
TrackingEitriAnalytics.sendEvent({
|
|
43
|
-
eventName: "clean.error",
|
|
44
|
-
userId: workspace?.userEmail,
|
|
45
|
-
data: {
|
|
46
|
-
errorMessage: e?.message || ""
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
if(!e) {
|
|
51
|
-
console.error('Erro desconhecido')
|
|
52
|
-
process.exit(1)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (cmdObj.verbose) {
|
|
56
|
-
console.error('Falha deletando workspace remoto', e)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const exit = async () => {
|
|
60
|
-
await trackingService.sendError(e)
|
|
61
|
-
process.exit(1)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const { httpStatus, response } = e
|
|
65
|
-
|
|
66
|
-
if(response){
|
|
67
|
-
const { data } = response
|
|
68
|
-
|
|
69
|
-
const transactionId = data.req_id
|
|
70
|
-
|
|
71
|
-
const printError = (message) => console.error(`${transactionId}: ${message}`)
|
|
72
|
-
|
|
73
|
-
const tryExitWithFriendlyMessage = async () => {
|
|
74
|
-
if(data && data.friendlyMessage) {
|
|
75
|
-
const {friendlyMessage} = data
|
|
76
|
-
printError(friendlyMessage)
|
|
77
|
-
await exit()
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if(httpStatus === 403) {
|
|
82
|
-
await tryExitWithFriendlyMessage()
|
|
83
|
-
printError('Acesso negado! Confira se você está registrado como desenvolvedor deste Eitri-App.')
|
|
84
|
-
await exit()
|
|
85
|
-
}
|
|
86
|
-
if(httpStatus === 500) {
|
|
87
|
-
if(data && data.error.includes('ENOENT: no such file or directory')) {
|
|
88
|
-
// O workspace remoto ja nao existe, portanto nada fazemos.
|
|
89
|
-
console.log('[2] Limpeza finalizada com sucesso.')
|
|
90
|
-
await exit()
|
|
91
|
-
}
|
|
92
|
-
await tryExitWithFriendlyMessage()
|
|
93
|
-
printError('Erro interno!')
|
|
94
|
-
await exit()
|
|
95
|
-
}
|
|
96
|
-
printError('Ops: ocorreu um erro inesperado realizar a limpeza :-(')
|
|
97
|
-
}
|
|
98
|
-
console.error(`Ops: ocorreu um erro durante a limpeza: ${e.message}`)
|
|
99
|
-
await exit()
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function track(miniConf, start) {
|
|
104
|
-
let libs = await targetService.getLibs()
|
|
105
|
-
let event = {
|
|
106
|
-
superClientVersion: miniConf[libs.superAppClientLibName],
|
|
107
|
-
componentsVersion: miniConf[libs.componentsLibName],
|
|
108
|
-
miniAppSlug: miniConf.slug,
|
|
109
|
-
miniAppVersion: miniConf.version,
|
|
110
|
-
timeMs: Date.now() - start,
|
|
111
|
-
}
|
|
112
|
-
await trackingService.sendPushedVersion(event)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function checkErros(miniConf) {
|
|
116
|
-
let validateResult = validator.validate(miniConf)
|
|
117
|
-
validateResult.errors.forEach(message => console.log(message))
|
|
118
|
-
return validateResult
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async function logPermissionsAndOpenPrompt(addedPermissions, removedPermissions, cmdObj) {
|
|
122
|
-
const GREEN_COLOR = '\x1b[32m'
|
|
123
|
-
const RED_COLOR = '\x1b[31m'
|
|
124
|
-
const MINIMAL_LENGTH = 0
|
|
125
|
-
if(addedPermissions.length > MINIMAL_LENGTH) {
|
|
126
|
-
console.log(`${GREEN_COLOR}\nPermissões adicionadas: ${addedPermissions}${GREEN_COLOR}`)
|
|
127
|
-
}
|
|
128
|
-
if(removedPermissions.length > MINIMAL_LENGTH) {
|
|
129
|
-
console.log(`${RED_COLOR}Permissões removidas: ${removedPermissions}\n${RED_COLOR}`)
|
|
130
|
-
}
|
|
131
|
-
if(!cmdObj.yes && (addedPermissions.length > MINIMAL_LENGTH || removedPermissions.length > MINIMAL_LENGTH)) {
|
|
132
|
-
const answer = await inquirer.prompt([
|
|
133
|
-
{
|
|
134
|
-
name: 'option',
|
|
135
|
-
message: 'Houve uma alteração nas permissões em relação a versão publicada. Deseja Continuar?',
|
|
136
|
-
type: 'rawlist',
|
|
137
|
-
choices: ['Sim', 'Não']
|
|
138
|
-
}
|
|
139
|
-
])
|
|
140
|
-
if(answer.option === 'Não') {
|
|
141
|
-
process.exit(0)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
package/src/cmd/create.js
DELETED
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
const Watcher = require("../service/Watcher");
|
|
2
|
-
const inquirer = require("inquirer");
|
|
3
|
-
const slugify = require("slugify");
|
|
4
|
-
const configService = require("../service/ConfigService");
|
|
5
|
-
const { Workspace } = require("../service/Workspace");
|
|
6
|
-
const BlindGuardian = require("../service/BlindGuardian");
|
|
7
|
-
const HashFolder = require("../service/HashFolder");
|
|
8
|
-
const TrackingService = require("../service/TrackingService");
|
|
9
|
-
const { NAME_TITLE_REGEX, SLUG_REGEX } = require("./validate");
|
|
10
|
-
const handleStartServer = require("../service/StarterService");
|
|
11
|
-
const getCreateFactory = require("../util/getCreateFactory");
|
|
12
|
-
const UrlUtils = require("../util/UrlUtils");
|
|
13
|
-
const open = require("open");
|
|
14
|
-
// eslint-disable-next-line no-unused-vars
|
|
15
|
-
const Target = require("../model/Target");
|
|
16
|
-
const EitriAppManager = require("../service/EitriAppManager");
|
|
17
|
-
const WoodCoffee = require("../service/factories/WoodCoffeeFactory");
|
|
18
|
-
const TrackingEitriAnalytics = require("../service/TrackingEitriAnalytics");
|
|
19
|
-
const UserLocalCredential = require("../util/UserLocalCredential");
|
|
20
|
-
|
|
21
|
-
const blindGuardian = new BlindGuardian();
|
|
22
|
-
const hashFolder = new HashFolder();
|
|
23
|
-
const workspace = new Workspace(blindGuardian, hashFolder);
|
|
24
|
-
const trackingService = new TrackingService(blindGuardian, {
|
|
25
|
-
ignoreCredentialError: true,
|
|
26
|
-
});
|
|
27
|
-
const watcher = new Watcher(workspace, hashFolder, trackingService);
|
|
28
|
-
const ITEM_DOUBT = "DOUBTS";
|
|
29
|
-
const eitriAppManager = new EitriAppManager(blindGuardian);
|
|
30
|
-
|
|
31
|
-
const nameOrTitle = (inpt) => {
|
|
32
|
-
if (!NAME_TITLE_REGEX.test(inpt)) {
|
|
33
|
-
return "Não use caracteres especiais";
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const slug = (inpt) => {
|
|
39
|
-
if (!SLUG_REGEX.test(inpt)) {
|
|
40
|
-
return "Não use caracteres especiais";
|
|
41
|
-
}
|
|
42
|
-
return true;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// eslint-disable-next-line no-unused-vars
|
|
46
|
-
module.exports = async function create(projectName, cmdObj) {
|
|
47
|
-
blindGuardian.verbose = cmdObj.verbose
|
|
48
|
-
try {
|
|
49
|
-
UserLocalCredential.checkForCredentials()
|
|
50
|
-
} catch (error) {
|
|
51
|
-
const errorMessage = cmdObj?.verbose ? error : error?.message
|
|
52
|
-
console.error("\n", errorMessage, "\n")
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
console.log(
|
|
57
|
-
"Vamos criar o seu Eitri-App. Carregando configurações..."
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
const url = configService.get("workspace").url;
|
|
62
|
-
workspace.setServerUrl(url);
|
|
63
|
-
const clientApplication = await askClientApplication(cmdObj.application);
|
|
64
|
-
if (clientApplication.name === ITEM_DOUBT) {
|
|
65
|
-
open("https://docs.eitri.tech/")
|
|
66
|
-
handleStartServer(
|
|
67
|
-
cmdObj,
|
|
68
|
-
trackingService,
|
|
69
|
-
watcher,
|
|
70
|
-
workspace,
|
|
71
|
-
clientApplication.name
|
|
72
|
-
);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const responseAskProjMetadata = await askProjMetadata(clientApplication, cmdObj, projectName);
|
|
76
|
-
TrackingEitriAnalytics.sendEvent({
|
|
77
|
-
eventName: "create",
|
|
78
|
-
userId: workspace?.userEmail,
|
|
79
|
-
});
|
|
80
|
-
console.log("Eitri-App criado com sucesso!")
|
|
81
|
-
return responseAskProjMetadata
|
|
82
|
-
} catch (e) {
|
|
83
|
-
TrackingEitriAnalytics.sendEvent({
|
|
84
|
-
eventName: "create.error",
|
|
85
|
-
userId: workspace?.userEmail,
|
|
86
|
-
data: {
|
|
87
|
-
errorMessage: e?.message,
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
console.error(e?.message);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
async function askClientApplication(applicationName) {
|
|
95
|
-
const availableApplications = await eitriAppManager.findAllApplications();
|
|
96
|
-
|
|
97
|
-
console.log(
|
|
98
|
-
"\x1b[34m \nAgora, responda algumas perguntas:\n\x1b[0m"
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
if (availableApplications.length <= 0) {
|
|
102
|
-
console.log(
|
|
103
|
-
"Sua organização não contém nenhuma aplicação disponível para prosseguir com a criação."
|
|
104
|
-
);
|
|
105
|
-
process.exit(0);
|
|
106
|
-
}
|
|
107
|
-
if (applicationName) {
|
|
108
|
-
const clientApplication = availableApplications.find(application => application.name === applicationName)
|
|
109
|
-
if (clientApplication) {
|
|
110
|
-
return clientApplication
|
|
111
|
-
} else {
|
|
112
|
-
throw new Error(`Application not found by name ${applicationName}`)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
const cliOptions = [
|
|
116
|
-
{ name: ITEM_DOUBT, label: "Dúvidas? Veja documentação no browser" },
|
|
117
|
-
...availableApplications,
|
|
118
|
-
];
|
|
119
|
-
const createLabel = (tgt) => {
|
|
120
|
-
const orgLabel = tgt.organization?.name ? `(${tgt.organization?.name})`: ''
|
|
121
|
-
return `${tgt.label || tgt.name} ${orgLabel}`;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const res = await inquirer.prompt([
|
|
125
|
-
{
|
|
126
|
-
name: "accepted",
|
|
127
|
-
type: "rawlist",
|
|
128
|
-
message:
|
|
129
|
-
"Selecione o Aplicativo para o Eitri-App:",
|
|
130
|
-
choices: cliOptions.map(createLabel),
|
|
131
|
-
pageSize: 10,
|
|
132
|
-
loop: false,
|
|
133
|
-
},
|
|
134
|
-
]);
|
|
135
|
-
const clientApplication = cliOptions.find(
|
|
136
|
-
(tgt) => createLabel(tgt) === res.accepted
|
|
137
|
-
);
|
|
138
|
-
clientApplication.onSelected && clientApplication.onSelected();
|
|
139
|
-
return clientApplication;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async function askProjMetadata(clientApplication, cmdObj, projectName) {
|
|
143
|
-
const factory = new WoodCoffee();
|
|
144
|
-
let questions = createQuestions(projectName);
|
|
145
|
-
try {
|
|
146
|
-
await workspace.init();
|
|
147
|
-
} catch (e) {
|
|
148
|
-
console.log(e.message);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
let answers;
|
|
152
|
-
if (cmdObj.yes) {
|
|
153
|
-
answers = {
|
|
154
|
-
name: projectName,
|
|
155
|
-
title: projectName,
|
|
156
|
-
slug: projectName,
|
|
157
|
-
};
|
|
158
|
-
} else {
|
|
159
|
-
answers = await inquirer.prompt(questions);
|
|
160
|
-
}
|
|
161
|
-
let conf = {
|
|
162
|
-
...answers,
|
|
163
|
-
organization: { id: clientApplication.organizationId },
|
|
164
|
-
};
|
|
165
|
-
delete conf.organizationName;
|
|
166
|
-
|
|
167
|
-
let keepGoing = true;
|
|
168
|
-
while (keepGoing) {
|
|
169
|
-
try {
|
|
170
|
-
keepGoing = false;
|
|
171
|
-
await factory.verifyFolder(projectName, { supressLog: true });
|
|
172
|
-
|
|
173
|
-
// Comentado até implementarmos os múltiplos boilerplates nos targets do banco
|
|
174
|
-
//const {template} = cmdObj
|
|
175
|
-
|
|
176
|
-
const selectedTemplate = _getBoilerplateUrl(
|
|
177
|
-
clientApplication,
|
|
178
|
-
cmdObj
|
|
179
|
-
);
|
|
180
|
-
cmdObj.verbose &&
|
|
181
|
-
console.log(`Usando template ${selectedTemplate}`);
|
|
182
|
-
|
|
183
|
-
let templateProject = await factory.create(
|
|
184
|
-
projectName,
|
|
185
|
-
selectedTemplate,
|
|
186
|
-
clientApplication
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
// conf sera usado pra escrever o arquivo miniapp.conf.js e nao queremos 'target' la.
|
|
190
|
-
const eitriAppToCreate = {
|
|
191
|
-
...conf,
|
|
192
|
-
organizationId: clientApplication.organization.id,
|
|
193
|
-
applicationId: clientApplication.id,
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
// Cria no banco no final das configs locais
|
|
197
|
-
const eitriApp = await eitriAppManager.create(eitriAppToCreate);
|
|
198
|
-
|
|
199
|
-
conf["id"] = eitriApp.id;
|
|
200
|
-
conf["public-key"] = eitriApp.publicKey;
|
|
201
|
-
|
|
202
|
-
const templateEitriAppConf =
|
|
203
|
-
templateProject?.structure?.eitriAppConf;
|
|
204
|
-
|
|
205
|
-
const finalConf = {
|
|
206
|
-
...templateEitriAppConf,
|
|
207
|
-
...conf,
|
|
208
|
-
organizationId: clientApplication.organization.id,
|
|
209
|
-
applicationId: clientApplication.id,
|
|
210
|
-
"type":"module",
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
await factory.writeEitriAppConf(templateProject, finalConf);
|
|
214
|
-
} catch (err) {
|
|
215
|
-
if (cmdObj.verbose) {
|
|
216
|
-
console.error(
|
|
217
|
-
"Houve uma falha durante a criação do Eitri-App",
|
|
218
|
-
err
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (err.isDuplicatedError) {
|
|
223
|
-
if (cmdObj.yes) {
|
|
224
|
-
process.exit(1);
|
|
225
|
-
}
|
|
226
|
-
if (err.field === "name") {
|
|
227
|
-
keepGoing = true;
|
|
228
|
-
conf.name = await askName(projectName);
|
|
229
|
-
}
|
|
230
|
-
if (err.field === "slug") {
|
|
231
|
-
keepGoing = true;
|
|
232
|
-
conf.slug = await askSlug(projectName);
|
|
233
|
-
}
|
|
234
|
-
} else {
|
|
235
|
-
if (err.isAxiosError) {
|
|
236
|
-
console.log(err.response && err.response.status);
|
|
237
|
-
} else {
|
|
238
|
-
console.log(err);
|
|
239
|
-
}
|
|
240
|
-
await trackingService.sendError(err);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function createQuestions(projectName) {
|
|
247
|
-
return [
|
|
248
|
-
{
|
|
249
|
-
type: "input",
|
|
250
|
-
name: "name",
|
|
251
|
-
message: "Digite um nome legível para seu Eitri-App",
|
|
252
|
-
validate: nameOrTitle,
|
|
253
|
-
default: () => {
|
|
254
|
-
return projectName;
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
type: "input",
|
|
259
|
-
name: "title",
|
|
260
|
-
message: "Digite um nome para divulgação",
|
|
261
|
-
validate: nameOrTitle,
|
|
262
|
-
default: () => {
|
|
263
|
-
return projectName;
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
type: "input",
|
|
268
|
-
name: "slug",
|
|
269
|
-
message:
|
|
270
|
-
"Digite um nome único para seu Eitri-App. Não pode conter espaços",
|
|
271
|
-
default: (currentAnswers) => {
|
|
272
|
-
return slugify(currentAnswers.name).toLowerCase();
|
|
273
|
-
},
|
|
274
|
-
validate: slug,
|
|
275
|
-
},
|
|
276
|
-
];
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
async function askSlug(projectName) {
|
|
280
|
-
let answer = await inquirer.prompt([
|
|
281
|
-
{
|
|
282
|
-
type: "input",
|
|
283
|
-
name: "slug",
|
|
284
|
-
message: "Outro nome único para o Eitri-App:",
|
|
285
|
-
validate: slug,
|
|
286
|
-
default: () => {
|
|
287
|
-
return slugify(projectName).toLowerCase();
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
|
-
]);
|
|
291
|
-
return answer.slug;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
async function askName(projectName) {
|
|
295
|
-
let answer = await inquirer.prompt([
|
|
296
|
-
{
|
|
297
|
-
type: "input",
|
|
298
|
-
name: "name",
|
|
299
|
-
message: "Outro nome para o Eitri-App:",
|
|
300
|
-
validate: nameOrTitle,
|
|
301
|
-
default: () => {
|
|
302
|
-
return projectName;
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
]);
|
|
306
|
-
return answer.name;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
*
|
|
311
|
-
* @param {Target} target
|
|
312
|
-
* @param {*} cmdObj
|
|
313
|
-
*/
|
|
314
|
-
function _getBoilerplateUrl(target, cmdObj) {
|
|
315
|
-
const { template } = cmdObj;
|
|
316
|
-
if (!template || !target.miniAppBoilerplateList) {
|
|
317
|
-
return target.boilerplateUrl;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const boilerplate = target.miniAppBoilerplateList.find(
|
|
321
|
-
(bp) => bp.name === template
|
|
322
|
-
);
|
|
323
|
-
|
|
324
|
-
if (!boilerplate) {
|
|
325
|
-
console.error(
|
|
326
|
-
`O template [${template}] não existe para a aplicação que você selecionou.`
|
|
327
|
-
);
|
|
328
|
-
return process.exit(0);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return boilerplate.boilerplateUrl;
|
|
332
|
-
}
|