eitri-cli 1.0.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/README.md +54 -0
- package/bitbucket-pipelines.toBeChanged.yml +64 -0
- package/boilerplate/mini-app-cafe-madeira.zip +0 -0
- package/check-version.js +12 -0
- package/config/default-eitri.js +1 -0
- package/config/dev.js +91 -0
- package/config/k8s-eitri.js +92 -0
- package/config/loc-eitri.js +92 -0
- package/config/prod-eitri.js +92 -0
- package/config/test-eitri.js +2 -0
- package/index-eitri.js +6 -0
- package/index.js +182 -0
- package/install-dev.bat +1 -0
- package/install-dev.sh +1 -0
- package/jest.config.js +6 -0
- package/jsconfig.json +9 -0
- package/package.json +80 -0
- package/publisher.js +53 -0
- package/src/cmd/clean.js +179 -0
- package/src/cmd/create.js +281 -0
- package/src/cmd/credentials.js +105 -0
- package/src/cmd/invite.js +87 -0
- package/src/cmd/list.js +36 -0
- package/src/cmd/login.js +51 -0
- package/src/cmd/manage-env.js +129 -0
- package/src/cmd/open-share.js +6 -0
- package/src/cmd/order-details.js +6 -0
- package/src/cmd/push-version.js +182 -0
- package/src/cmd/show-message-if-outdated-package.js +32 -0
- package/src/cmd/signup.js +69 -0
- package/src/cmd/start.js +171 -0
- package/src/cmd/tail-logs.js +26 -0
- package/src/cmd/test-initialization-params.js +6 -0
- package/src/cmd/validate.js +170 -0
- package/src/cmd/version.js +29 -0
- package/src/enum/WatcherOpts.js +3 -0
- package/src/enum/target.js +6 -0
- package/src/helpers/request-listener-helper.js +55 -0
- package/src/model/Payload.js +45 -0
- package/src/model/Target.js +76 -0
- package/src/model/User.js +11 -0
- package/src/service/AuthConfig.js +88 -0
- package/src/service/BlindGuardian.js +134 -0
- package/src/service/CliLogin.js +47 -0
- package/src/service/ConfigService.js +16 -0
- package/src/service/CredentialsService.js +47 -0
- package/src/service/GATrackingStrategy.js +16 -0
- package/src/service/HashFolder.js +79 -0
- package/src/service/Http.js +234 -0
- package/src/service/InviteService.js +45 -0
- package/src/service/ManageEnvService.js +10 -0
- package/src/service/MiniLog.js +132 -0
- package/src/service/QRCodeFactory.js +43 -0
- package/src/service/Server.js +239 -0
- package/src/service/StarterService.js +31 -0
- package/src/service/TagTree.js +101 -0
- package/src/service/TargetService.js +97 -0
- package/src/service/TrackService.js +11 -0
- package/src/service/TrackingEitriAnalytics.js +32 -0
- package/src/service/TrackingService.js +183 -0
- package/src/service/ValidateResult.js +57 -0
- package/src/service/Watcher.js +119 -0
- package/src/service/Workspace.js +1069 -0
- package/src/service/WorkspaceManager.js +74 -0
- package/src/service/factories/DoubtsStarterFactory.js +25 -0
- package/src/service/factories/MiniWebAppFactory.js +43 -0
- package/src/service/factories/QRCodeStarterFactory.js +78 -0
- package/src/service/factories/WebStarterFactory.js +88 -0
- package/src/service/factories/WoodCoffeeFactory.js +230 -0
- package/src/util/AboutTemplate.jsx +14 -0
- package/src/util/UrlUtils.js +12 -0
- package/src/util/UserLocalCredential.js +122 -0
- package/src/util/error-messages/error-messages.js +24 -0
- package/src/util/error-messages/invite/invite-error-messages.js +14 -0
- package/src/util/getCliVersion.js +13 -0
- package/src/util/getCreateFactory.js +9 -0
- package/src/util/ipv4.js +19 -0
- package/src/util/manage-env.js +65 -0
- package/src/util/open-docs.js +7 -0
- package/src/util/os.js +39 -0
- package/src/util/server-url.js +15 -0
- package/src/util/template-utils.js +21 -0
- package/src/view/index.html +19 -0
- package/targetMobileStickyness.md +47 -0
- package/targetWebStickyness.md +40 -0
- package/test/_fixtures/factory.js +30 -0
- package/test/_fixtures/miniWebApp/miniapp.conf.js +4 -0
- package/test/_fixtures/miniapp.conf.js +5 -0
- package/test/_fixtures/server/HelloWorldBackend.js +7 -0
- package/test/_fixtures/src/Home.js +5 -0
- package/test/_fixtures/src/Home2.js +5 -0
- package/test/_fixtures/src/commons/util.js +3 -0
- package/test/_fixtures/src/components/TagA.jsx +4 -0
- package/test/_fixtures/src/components/TagB.jsx +4 -0
- package/test/_fixtures/src/components/TagC.jsx +3 -0
- package/test/_fixtures/src/components/TagD.jsx +3 -0
- package/test/_fixtures/src/server/foo.js +7 -0
- package/test/_fixtures/src/views/AboutTemplate.jsx +14 -0
- package/test/_fixtures/woodcoffee/miniapp.conf.js +3 -0
- package/test/ame.conf.js +3 -0
- package/test/cmd/clean.test.js +66 -0
- package/test/cmd/create.test.js +252 -0
- package/test/cmd/credentials.test.js +159 -0
- package/test/cmd/list.test.js +74 -0
- package/test/cmd/manage-env.test.js +168 -0
- package/test/cmd/signup.test.js +20 -0
- package/test/cmd/start.test.js +5 -0
- package/test/miniapp.conf.js +3 -0
- package/test/model/Payload.test.js +35 -0
- package/test/service/BlindGuardian.test.js +84 -0
- package/test/service/CheckAmeConf.test.js +313 -0
- package/test/service/Http.test.js +312 -0
- package/test/service/InviteService.test.js +117 -0
- package/test/service/MiniWebAppFactory.test.js +40 -0
- package/test/service/TagTree.test.js +81 -0
- package/test/service/TargetService.test.js +48 -0
- package/test/service/TrackingService.test.js +105 -0
- package/test/service/UserAmeConf.test.js +47 -0
- package/test/service/WoodCoffeeFactory.test.js +148 -0
- package/test/service/Workspace.test.js +364 -0
- package/thinQrCode.md +58 -0
- package/v1.5.0.md +3 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const io = require('socket.io-client')
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const openDocs = require('../util/open-docs')
|
|
4
|
+
const QRCodeFactory = require('../service/QRCodeFactory')
|
|
5
|
+
const TrackingService = require('../service/TrackingService')
|
|
6
|
+
const config = require('config')
|
|
7
|
+
const Server = require('../service/Server')
|
|
8
|
+
const qrcodeTerminal = require('qrcode-terminal')
|
|
9
|
+
const TERMINAL_PRINTER_NAME = 'terminal'
|
|
10
|
+
|
|
11
|
+
class WorkspaceManager {
|
|
12
|
+
|
|
13
|
+
constructor(blindGuardian) {
|
|
14
|
+
this.blindGuardian = blindGuardian
|
|
15
|
+
this.baseUrl = config.get('workspaceManager').url
|
|
16
|
+
this.contextPath = config.get('workspaceManager').contextPath
|
|
17
|
+
this.ioPath = config.get('workspaceManager').path
|
|
18
|
+
this.verbose = false
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
qrConfig(configPath, args) {
|
|
22
|
+
const cliSocket = io.connect(this.baseUrl, { path: this.ioPath })
|
|
23
|
+
if (this.verbose) console.log(`Conectando ao ${this.baseUrl} path = ${this.ioPath} ...`)
|
|
24
|
+
cliSocket.on('connect', () => {
|
|
25
|
+
if (this.verbose) console.log(`Conectado ao ${this.baseUrl} path = ${this.ioPath} .`)
|
|
26
|
+
cliSocket.emit('getCliToken')
|
|
27
|
+
})
|
|
28
|
+
cliSocket.on('openDocs', () => {
|
|
29
|
+
openDocs()
|
|
30
|
+
})
|
|
31
|
+
cliSocket.on('token', async (token) => {
|
|
32
|
+
const fullUrl = `https://miniapps.amedigital.com/open/wm2?token=${token}`
|
|
33
|
+
|
|
34
|
+
if(args && args.verbose) {
|
|
35
|
+
console.log('QR Code URL', fullUrl)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if(process.env.AAT_QRCODE_PRINTER === TERMINAL_PRINTER_NAME || args && args.qrPrinter === TERMINAL_PRINTER_NAME) {
|
|
39
|
+
qrcodeTerminal.generate(fullUrl, { small: true } )
|
|
40
|
+
} else {
|
|
41
|
+
const qrCodePath = await new QRCodeFactory().create(fullUrl)
|
|
42
|
+
const sanitizedQrCodePath = qrCodePath.replace('/~', '')
|
|
43
|
+
if(args) {
|
|
44
|
+
Server.startServer({ qrCodePath: sanitizedQrCodePath, qrPrinter: args.qrPrinter })
|
|
45
|
+
} else {
|
|
46
|
+
Server.startServer({ qrCodePath: sanitizedQrCodePath })
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
cliSocket.on('error', (error) => {
|
|
51
|
+
if (this.verbose) console.log(error)
|
|
52
|
+
})
|
|
53
|
+
cliSocket.on('setCliConf', (conf, fn) => {
|
|
54
|
+
const confContent = `module.exports = ${JSON.stringify(conf, null, 4)}`
|
|
55
|
+
fs.writeFile(configPath, confContent, (err) => {
|
|
56
|
+
if (err) {
|
|
57
|
+
console.log('Erro ao salvar a config.')
|
|
58
|
+
fn('error')
|
|
59
|
+
} else {
|
|
60
|
+
console.log(`Credenciais salvas em ${configPath}.\nAperte control+c para finalizar.`)
|
|
61
|
+
this.track()
|
|
62
|
+
fn('success')
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
track() {
|
|
69
|
+
let trackingService = new TrackingService(this.blindGuardian)
|
|
70
|
+
trackingService.sendSignup()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = WorkspaceManager
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const open = require('open')
|
|
2
|
+
const config = require('config')
|
|
3
|
+
const DEFAULT_DOC_CREATE_URL = 'https://eitri.calindra.com.br/#/?id=create'
|
|
4
|
+
|
|
5
|
+
function DoubtsStarter(args, trackingService, watcher, workspace ) {
|
|
6
|
+
this.args = args
|
|
7
|
+
this.trackingService = trackingService
|
|
8
|
+
this.watcher = watcher
|
|
9
|
+
this.workspace = workspace
|
|
10
|
+
|
|
11
|
+
this.startServer = async function () {
|
|
12
|
+
await open((config.doc && config.doc.createUrl) || DEFAULT_DOC_CREATE_URL)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function DoubtsStarterFactory() {
|
|
17
|
+
this.create = function (args, trackingService, watcher, workspace) {
|
|
18
|
+
return new DoubtsStarter(args, trackingService, watcher, workspace)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = DoubtsStarterFactory
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const WookCoffee = require('./WoodCoffeeFactory')
|
|
4
|
+
const {getVersion} = require('../../cmd/version')
|
|
5
|
+
|
|
6
|
+
class MiniWebAppFactory extends WookCoffee {
|
|
7
|
+
|
|
8
|
+
async create(projectName, templateUrl) {
|
|
9
|
+
|
|
10
|
+
if(!templateUrl) {
|
|
11
|
+
throw new Error(`Forneça um template para criar seu Mini App. ${templateUrl} não é um template válido. Duvidas? Execute 'eitri create --help'`)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const projectPath = await this.verifyFolder(projectName)
|
|
15
|
+
|
|
16
|
+
await this.createTempFile()
|
|
17
|
+
|
|
18
|
+
await this.template(projectName, templateUrl, projectPath)
|
|
19
|
+
|
|
20
|
+
return { projectPath }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
writeAmeConf(project, conf, libsName) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
|
|
26
|
+
libsName.forEach(libName => {
|
|
27
|
+
conf[libName] = getVersion(libName)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
conf['version'] = '0.1.0'
|
|
31
|
+
|
|
32
|
+
let confString = `module.exports = ${JSON.stringify(conf, null, 4)}`
|
|
33
|
+
fs.writeFile(path.join(project.projectPath, 'miniapp.conf.js'), confString, (err) => {
|
|
34
|
+
if (err) {
|
|
35
|
+
return reject(err)
|
|
36
|
+
}
|
|
37
|
+
resolve()
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = MiniWebAppFactory
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const QRCodeFactory = require('../QRCodeFactory')
|
|
2
|
+
const TrackService = require('../TrackService')
|
|
3
|
+
const Server = require('../Server')
|
|
4
|
+
const qrcodeTerminal = require('qrcode-terminal')
|
|
5
|
+
const TERMINAL_PRINTER_NAME = 'terminal'
|
|
6
|
+
|
|
7
|
+
function QRCodeStarter(args, trackingService, watcher, workspace, targetConfig ) {
|
|
8
|
+
this.args = args
|
|
9
|
+
this.trackingService = trackingService
|
|
10
|
+
this.watcher = watcher
|
|
11
|
+
this.workspace = workspace
|
|
12
|
+
this.targetConfig = targetConfig
|
|
13
|
+
|
|
14
|
+
this.startServer = async function () {
|
|
15
|
+
let fullUrl
|
|
16
|
+
if (this.args.oldQrcode) {
|
|
17
|
+
fullUrl = await this.workspace.getWorkspaceURL(this.args, this.targetConfig)
|
|
18
|
+
} else {
|
|
19
|
+
const {miniAppUrl} = await this.workspace.getNewWorkspaceURL(this.args, this.targetConfig)
|
|
20
|
+
fullUrl = miniAppUrl
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (this.args.verbose) {
|
|
24
|
+
console.log(`QrCodeUrl: ${fullUrl}`)
|
|
25
|
+
}
|
|
26
|
+
const qrCodePath = await new QRCodeFactory().create(fullUrl)
|
|
27
|
+
|
|
28
|
+
if (this.args.verbose) {
|
|
29
|
+
console.log(`QrCode Path: ${qrCodePath}`)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if(process.env.AAT_QRCODE_PRINTER === TERMINAL_PRINTER_NAME || this.args.qrPrinter === TERMINAL_PRINTER_NAME) {
|
|
33
|
+
qrcodeTerminal.generate(fullUrl, {small: true})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const libsInfoForGA = this.args.libsInfoForGA
|
|
37
|
+
|
|
38
|
+
this.watcher.start()
|
|
39
|
+
let miniConf = this.workspace.getMiniConf()
|
|
40
|
+
TrackService.track(miniConf, this.trackingService, libsInfoForGA)
|
|
41
|
+
// tryToOpenAndroidEmulator(fullUrl, this.args)
|
|
42
|
+
if(this.args.showDeeplink){
|
|
43
|
+
console.log('######################################')
|
|
44
|
+
console.log('########### Deep Link URL ############')
|
|
45
|
+
console.log('######################################')
|
|
46
|
+
console.log(`${fullUrl}`)
|
|
47
|
+
console.log('######################################')
|
|
48
|
+
}
|
|
49
|
+
Server.startServer({ ...this.args, qrCodePath})
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function tryToOpenAndroidEmulator(fullUrl, args) {
|
|
54
|
+
try {
|
|
55
|
+
const cmd = `adb shell am start -a android.intent.action.VIEW -d "${encodeURIComponent(fullUrl)}"`
|
|
56
|
+
let options = {}
|
|
57
|
+
if (args.verbose) {
|
|
58
|
+
options.stdio = 'inherit'
|
|
59
|
+
require('child_process').execSync(cmd, options)
|
|
60
|
+
} else {
|
|
61
|
+
require('child_process').exec(cmd, options, () => {
|
|
62
|
+
// ignora erros
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
} catch(e) {
|
|
66
|
+
if (args.verbose) {
|
|
67
|
+
console.log(e)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function QRCodeContentFactory(){
|
|
73
|
+
this.create = function (args, trackingService, watcher, workspace, targetConfig) {
|
|
74
|
+
return new QRCodeStarter(args, trackingService, watcher, workspace, targetConfig )
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = QRCodeContentFactory
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const base64url = require('base64url')
|
|
2
|
+
const Server = require('../Server')
|
|
3
|
+
const TrackService = require('../TrackService')
|
|
4
|
+
const Payload = require('../../model/Payload')
|
|
5
|
+
|
|
6
|
+
function WebAppStarter(args, trackingService, watcher, workspace, targetConfig ) {
|
|
7
|
+
this.args = args
|
|
8
|
+
this.trackingService = trackingService
|
|
9
|
+
this.watcher = watcher
|
|
10
|
+
this.workspace = workspace
|
|
11
|
+
this.targetConfig = targetConfig
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const createWebMiniappPayload = (shareId) => {
|
|
15
|
+
const shareEnviroment = process.env.NODE_ENV || 'hml'
|
|
16
|
+
const payload = new Payload(shareId, shareEnviroment)
|
|
17
|
+
return base64url.encode(JSON.stringify(payload))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Cria url final de abertura do target, já com todos os parâmetros necessários
|
|
22
|
+
* @param {*} runnerUrl
|
|
23
|
+
* @param {*} slug
|
|
24
|
+
* @param {*} qrCodeConfig
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
const createUrlToOpenOnBrowser = (runnerUrl, slug, qrCodeConfig) => {
|
|
28
|
+
const payload = createWebMiniappPayload(qrCodeConfig.shareId)
|
|
29
|
+
return buildUrlToOpenOnStart(runnerUrl, slug, payload)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Monta a url que será aberta no browser com um payload já definido
|
|
34
|
+
* @param {*} runnerUrl
|
|
35
|
+
* @param {*} miniAppSlug
|
|
36
|
+
* @param {*} encodedMiniAppUrl
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
const buildUrlToOpenOnStart = (runnerUrl, miniAppSlug, encodedMiniAppUrl) => {
|
|
40
|
+
return `${runnerUrl}${miniAppSlug}/${encodedMiniAppUrl}`
|
|
41
|
+
}
|
|
42
|
+
this.startServer = async function () {
|
|
43
|
+
this.watcher.start()
|
|
44
|
+
|
|
45
|
+
const miniConf = this.workspace.getMiniConf()
|
|
46
|
+
const libsInfoForGA = this.args.libsInfoForGA
|
|
47
|
+
TrackService.track(miniConf, this.trackingService, libsInfoForGA)
|
|
48
|
+
|
|
49
|
+
const {miniAppConf} = await this.workspace.getNewWorkspaceURL(this.args, this.targetConfig)
|
|
50
|
+
const { slug } = miniConf
|
|
51
|
+
|
|
52
|
+
if(this.args.emulator){
|
|
53
|
+
Server.startServerEmulator({...this.args, bootstrapUrl: miniAppConf.miniAppBootstrapUrl, slug, http: this.workspace.getHttp() })
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if(this.args.local) {
|
|
58
|
+
const runnerUrl = this.targetConfig.runnerUrl
|
|
59
|
+
const urlToOpen = createUrlToOpenOnBrowser(runnerUrl, slug, miniAppConf)
|
|
60
|
+
|
|
61
|
+
Server.startMiniAppProxyServerAndOpenTarget({
|
|
62
|
+
...this.args,
|
|
63
|
+
http: this.workspace.getHttp(),
|
|
64
|
+
openPath: urlToOpen
|
|
65
|
+
})
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const runnerUrl = this.targetConfig.runnerUrl
|
|
70
|
+
const urlToOpen = createUrlToOpenOnBrowser(runnerUrl, slug, miniAppConf)
|
|
71
|
+
|
|
72
|
+
console.log('\nLink:' + '\n' + urlToOpen)
|
|
73
|
+
|
|
74
|
+
Server.startMiniAppProxyServerAndOpenTarget({
|
|
75
|
+
...this.args,
|
|
76
|
+
http: this.workspace.getHttp(),
|
|
77
|
+
openPath: urlToOpen
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function WebFactory() {
|
|
83
|
+
this.create = function (args, trackingService, watcher, workspace, targetConfig) {
|
|
84
|
+
return new WebAppStarter(args, trackingService, watcher, workspace, targetConfig)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = WebFactory
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const AdmZip = require('adm-zip')
|
|
4
|
+
const tmp = require('tmp')
|
|
5
|
+
const util = require('util')
|
|
6
|
+
const exec = util.promisify(require('child_process').exec)
|
|
7
|
+
const rm = util.promisify(fs.rm)
|
|
8
|
+
const { execSync } = require('child_process')
|
|
9
|
+
|
|
10
|
+
class WoodCoffee {
|
|
11
|
+
static COMPONENTS_LIBRARY_VERSION_HIGHLIGHTER = '###COMPONENTS_LIBRARY_VERSION_HIGHLIGHTER###'
|
|
12
|
+
static SUPER_APP_CLIENT_VERSION_HIGHLIGHTER = '###SUPER_APP_CLIENT_VERSION_HIGHLIGHTER###'
|
|
13
|
+
static SUPER_APP_CLIENT = 'eitri-app-client'
|
|
14
|
+
static MINIAPP_COMPONENTS = 'eitri-app-components'
|
|
15
|
+
|
|
16
|
+
async create(projectName, templateUrl, target) {
|
|
17
|
+
const projectPath = await this.verifyFolder(projectName)
|
|
18
|
+
let localPath
|
|
19
|
+
|
|
20
|
+
if (process.env.LOG_LEVEL === 'full') {
|
|
21
|
+
console.log('Boilerplate localPath', localPath)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
|
|
27
|
+
if (templateUrl) {
|
|
28
|
+
const projectStructure = await this.template(projectName, templateUrl, projectPath, target)
|
|
29
|
+
return { projectPath, structure: projectStructure }
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (error.message.includes('Command failed')) return await this.extractZip(localPath, projectPath)
|
|
33
|
+
console.error('Erro ao obter template', error)
|
|
34
|
+
}
|
|
35
|
+
return { projectPath }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @returns Objeto que representa a estrutura de diretorios do projeto criado
|
|
41
|
+
*/
|
|
42
|
+
async template(projectName, templateUrl, projectPath, target) {
|
|
43
|
+
await this.downloadFromGithub(templateUrl, projectName, projectPath)
|
|
44
|
+
const aboutJsxPath = path.join(projectPath, 'src', 'views', 'About.jsx')
|
|
45
|
+
|
|
46
|
+
const miniAppConf = require(path.join(projectPath, 'miniapp.conf.js'))
|
|
47
|
+
|
|
48
|
+
if(fs.existsSync(aboutJsxPath)) {
|
|
49
|
+
try {
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
await this.checkAboutJsx(aboutJsxPath)
|
|
53
|
+
// TODO EITRI descomentar qd as libs forem pro npm
|
|
54
|
+
await this.updateAboutJSXFile(aboutJsxPath, miniAppConf)
|
|
55
|
+
} catch (e) {
|
|
56
|
+
// 'Usando template consistente para o About.jsx.'
|
|
57
|
+
const templateAboutJsxPath = path.join(path.dirname(__dirname), '..', 'util', 'AboutTemplate.jsx')
|
|
58
|
+
await this.copyFile(templateAboutJsxPath, aboutJsxPath)
|
|
59
|
+
// TODO EITRI descomentar qd as libs forem pro npm
|
|
60
|
+
await this.updateAboutJSXFile(aboutJsxPath, miniAppConf)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
src: { views: {} },
|
|
66
|
+
miniAppConf
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async checkAboutJsx(aboutJsxPath) {
|
|
71
|
+
const contents = await this.getFile(aboutJsxPath)
|
|
72
|
+
if (!contents.includes(WoodCoffee.COMPONENTS_LIBRARY_VERSION_HIGHLIGHTER) || !contents.includes(WoodCoffee.SUPER_APP_CLIENT_VERSION_HIGHLIGHTER)) {
|
|
73
|
+
// 'O arquivo About.jsx baixado, não é um arquivo consistente.'
|
|
74
|
+
throw new Error('Faltam placeholders para exibicao da versao do components e client')
|
|
75
|
+
}
|
|
76
|
+
return true
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async updateAboutJSXFile(aboutJsxPath, newMiniAppConf) {
|
|
80
|
+
const superAppClientLibVersion = newMiniAppConf[WoodCoffee.SUPER_APP_CLIENT]
|
|
81
|
+
const componentsLibVersion = newMiniAppConf[WoodCoffee.MINIAPP_COMPONENTS]
|
|
82
|
+
const contents = await this.getFile(aboutJsxPath)
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
const replaced = contents
|
|
85
|
+
.replace(WoodCoffee.COMPONENTS_LIBRARY_VERSION_HIGHLIGHTER, componentsLibVersion)
|
|
86
|
+
.replace(WoodCoffee.SUPER_APP_CLIENT_VERSION_HIGHLIGHTER, superAppClientLibVersion)
|
|
87
|
+
|
|
88
|
+
fs.writeFile(aboutJsxPath, replaced, 'utf-8', function (err) {
|
|
89
|
+
if (err) {
|
|
90
|
+
console.error(err)
|
|
91
|
+
reject(err)
|
|
92
|
+
}
|
|
93
|
+
resolve()
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getFile(aboutJsxPath) {
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
fs.readFile(aboutJsxPath, 'utf-8', function (err, contents) {
|
|
101
|
+
if (err) {
|
|
102
|
+
console.error(err)
|
|
103
|
+
reject(err)
|
|
104
|
+
}
|
|
105
|
+
resolve(contents)
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async copyFile(currentPath, destinyPath) {
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
fs.copyFile(currentPath, destinyPath, (error) => {
|
|
113
|
+
if (error) {
|
|
114
|
+
console.error(error)
|
|
115
|
+
reject(error)
|
|
116
|
+
}
|
|
117
|
+
resolve()
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
validateFileName(folderName) {
|
|
123
|
+
const re = /[<>:"/\\|?*\x00-\x1F]|^(?:aux|con|clock\$|nul|prn|com[1-9]|lpt[1-9])$/i
|
|
124
|
+
if (re.test(folderName)) {
|
|
125
|
+
return false
|
|
126
|
+
}
|
|
127
|
+
return true
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
verifyFolder(projectName, options) {
|
|
131
|
+
options = options || {}
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
let projPath = process.cwd()
|
|
134
|
+
if (!this.validateFileName(projectName)) {
|
|
135
|
+
return reject(
|
|
136
|
+
`O nome do projeto ${projectName} possui caracteres proibidos.`,
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
if (projectName) {
|
|
140
|
+
projPath = path.join(process.cwd(), projectName)
|
|
141
|
+
}
|
|
142
|
+
const folder2check = path.join(projPath, 'src')
|
|
143
|
+
if (!options.supressLog) {
|
|
144
|
+
console.log('Verificando', folder2check)
|
|
145
|
+
}
|
|
146
|
+
if (fs.existsSync(folder2check)) {
|
|
147
|
+
return reject(
|
|
148
|
+
`A pasta ${folder2check} existe, abortando e deixando tudo inalterado.`,
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
resolve(projPath)
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
extractZip(localPath, projectPath) {
|
|
157
|
+
return new Promise((resolve, reject) => {
|
|
158
|
+
new AdmZip(localPath).extractAllToAsync(
|
|
159
|
+
/* target path*/ projectPath,
|
|
160
|
+
/* overwrite*/ true,
|
|
161
|
+
(err) => {
|
|
162
|
+
if (err) {
|
|
163
|
+
reject('Erro ao descompactar o boilerplate')
|
|
164
|
+
console.log(err)
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
console.log('Exemplo gerado.')
|
|
168
|
+
resolve()
|
|
169
|
+
},
|
|
170
|
+
)
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
createTempFile() {
|
|
175
|
+
return new Promise((resolve, reject) => {
|
|
176
|
+
tmp.file({ prefix: 'eitri-', postfix: '.zip', keep: true }, function (
|
|
177
|
+
err,
|
|
178
|
+
localPath,
|
|
179
|
+
) {
|
|
180
|
+
if (err) {
|
|
181
|
+
return reject(err)
|
|
182
|
+
}
|
|
183
|
+
resolve(localPath)
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
downloadFromGithub(boilerplateUrl, projectName, projectPath) {
|
|
189
|
+
return new Promise((resolve, reject) => {
|
|
190
|
+
const CMD = `git clone ${boilerplateUrl} ${projectName}`
|
|
191
|
+
exec(CMD, async (error, stdout, stderr) => {
|
|
192
|
+
if (error) {
|
|
193
|
+
console.error('Não foi possível obter o template remoto. Resolvendo localmente.')
|
|
194
|
+
return reject(error)
|
|
195
|
+
}
|
|
196
|
+
console.log('Download de template completo.')
|
|
197
|
+
Promise.resolve(rm(`${projectPath}/.git`, { recursive: true, force: true }))
|
|
198
|
+
resolve({ stdout: stdout, stderr: stderr })
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
writeAmeConf(project, conf) {
|
|
205
|
+
return new Promise((resolve, reject) => {
|
|
206
|
+
|
|
207
|
+
conf['version'] = '0.1.0'
|
|
208
|
+
let confString = `module.exports = ${JSON.stringify(conf, null, 4)}`
|
|
209
|
+
fs.writeFile(path.join(project.projectPath, 'miniapp.conf.js'), confString, (err) => {
|
|
210
|
+
if (err) {
|
|
211
|
+
return reject(err)
|
|
212
|
+
}
|
|
213
|
+
resolve()
|
|
214
|
+
})
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
_getLatestLibVersion(libName) {
|
|
219
|
+
try {
|
|
220
|
+
const cmd = `npm view ${libName} version`
|
|
221
|
+
const version = execSync(cmd).toString()
|
|
222
|
+
return version
|
|
223
|
+
} catch (error) {
|
|
224
|
+
console.error(`Não foi possível recuperar a última versão da biblioteca ${libName}.`)
|
|
225
|
+
throw error
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
module.exports = WoodCoffee
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<Window>
|
|
2
|
+
<Group>
|
|
3
|
+
<Circle icon={require('../assets/images/icon_ame.svg')} />
|
|
4
|
+
<Spacing size="sm" />
|
|
5
|
+
<Subtitle fontSize="xs" textAlign="center" color="neutralcolor-darkest">Detalhes desta versão</Subtitle>
|
|
6
|
+
<View>
|
|
7
|
+
<Subtitle textAlign="center" fontSize="xxxs" color="neutralcolor-darkest">Este mini-app foi desenvolvido utilizando as seguintes versões:</Subtitle>
|
|
8
|
+
<Spacing size="sm" />
|
|
9
|
+
<Paragraph textAlign="center">Versão da biblioteca de componentes: ###COMPONENTS_LIBRARY_VERSION_HIGHLIGHTER###</Paragraph>
|
|
10
|
+
<Spacing size="sm" />
|
|
11
|
+
<Paragraph textAlign="center">Versão da API de Super Client: ###SUPER_APP_CLIENT_VERSION_HIGHLIGHTER###</Paragraph>
|
|
12
|
+
</View>
|
|
13
|
+
</Group>
|
|
14
|
+
</Window>
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const os = require('os')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const config = require('config')
|
|
5
|
+
const TrackingEitriAnalytics = require('../service/TrackingEitriAnalytics')
|
|
6
|
+
|
|
7
|
+
class UserLocalCredential {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.miniappFolder = path.join(os.homedir(), '.eitri')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
_getNewConfigPath(conf = {}) {
|
|
13
|
+
const defaultConfigPath = path.join(
|
|
14
|
+
os.homedir(),
|
|
15
|
+
config.get('signup').get('configFilePath')
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
if (conf?.createCredential && conf?.devUser && conf?.devKey) {
|
|
19
|
+
return defaultConfigPath
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (fs.existsSync(defaultConfigPath)) {
|
|
23
|
+
return require(defaultConfigPath)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const oldDevConfigPath = path.resolve(
|
|
27
|
+
os.homedir(),
|
|
28
|
+
config.get('signup').get('oldConfigFilePath')
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
const miniAppNamePathIndex = oldDevConfigPath.indexOf('.miniapp/');
|
|
32
|
+
const onlyPath = oldDevConfigPath.substring(0, miniAppNamePathIndex + 9);
|
|
33
|
+
if (fs.existsSync(oldDevConfigPath)) {
|
|
34
|
+
fs.renameSync(onlyPath, onlyPath?.replace("/.miniapp", "/.eitri"))
|
|
35
|
+
return require(defaultConfigPath)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let e = new Error(
|
|
39
|
+
` Desculpe, parece que não há nenhuma configuração de credencial. \n Por favor, execute o comando "eitri login" no seu terminal.`
|
|
40
|
+
)
|
|
41
|
+
e.isSignupError = true
|
|
42
|
+
throw e
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fixMiniappCredentialLocation() {
|
|
46
|
+
const miniAppFolderExist = fs.existsSync(this.miniappFolder)
|
|
47
|
+
const newConfigPath = this._getNewConfigPath()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if (!miniAppFolderExist) {
|
|
51
|
+
console.log('Criando pasta .eitri')
|
|
52
|
+
try {
|
|
53
|
+
fs.mkdirSync(this.miniappFolder)
|
|
54
|
+
if (process.env.LOG_LEVEL === 'full')
|
|
55
|
+
console.log('Pasta .eitri criada com sucesso.')
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error(`Erro ao criar a pasta .eitri: ${error}`)
|
|
58
|
+
throw error
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
saveContent(conf) {
|
|
64
|
+
const configPath = this._getNewConfigPath();
|
|
65
|
+
const confContent = `module.exports = ${JSON.stringify(conf, null, 4)}`
|
|
66
|
+
const miniAppFolderExist = fs.existsSync(this.miniappFolder)
|
|
67
|
+
if (!miniAppFolderExist) {
|
|
68
|
+
console.log('Criando pasta .eitri')
|
|
69
|
+
try {
|
|
70
|
+
fs.mkdirSync(this.miniappFolder)
|
|
71
|
+
if (process.env.LOG_LEVEL === 'full')
|
|
72
|
+
console.log('Pasta .eitri criada com sucesso.')
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error(`Erro ao crair a pasta .eitri: ${error}`)
|
|
75
|
+
throw error
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
fs.writeFile(configPath, confContent, (err) => {
|
|
79
|
+
if (err) {
|
|
80
|
+
console.log('Erro ao salvar a config.')
|
|
81
|
+
fn('error')
|
|
82
|
+
} else {
|
|
83
|
+
console.log(`Credencial salva com sucesso!`)
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async asyncSaveContent(conf) {
|
|
89
|
+
const newConf = {
|
|
90
|
+
createCredential: true,
|
|
91
|
+
...conf
|
|
92
|
+
}
|
|
93
|
+
const configPath = this._getNewConfigPath(newConf);
|
|
94
|
+
const confContent = `module.exports = ${JSON.stringify(conf, null, 4)}`
|
|
95
|
+
const miniAppFolderExist = fs.existsSync(this.miniappFolder)
|
|
96
|
+
if (!miniAppFolderExist) {
|
|
97
|
+
console.log(' Criando a pasta .eitri...')
|
|
98
|
+
try {
|
|
99
|
+
fs.mkdirSync(this.miniappFolder)
|
|
100
|
+
if (process.env.LOG_LEVEL === 'full')
|
|
101
|
+
console.log('Pasta .eitri criada com sucesso.')
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error(`Erro ao criar a pasta .eitri: ${error}`)
|
|
104
|
+
throw error
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
await new Promise(function (resolve){
|
|
109
|
+
fs.writeFile(configPath, confContent, (err) => {
|
|
110
|
+
if (err) {
|
|
111
|
+
console.log('Erro ao salvar a config.')
|
|
112
|
+
fn('error')
|
|
113
|
+
} else {
|
|
114
|
+
console.log(` Credencial salva com sucesso!`)
|
|
115
|
+
resolve()
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
module.exports = UserLocalCredential
|