docs(example-app): add cli crate app

This commit is contained in:
Leifer Mendez
2022-11-30 21:39:30 +01:00
parent 81b0aab850
commit df8282015d
9 changed files with 122 additions and 8 deletions

2
.gitignore vendored
View File

@@ -23,7 +23,7 @@ tmp/
.yarn/*
!.yarn/releases
.fleet/
example-app/
example-app*/
qr.svg
package-lock.json
yarn-error.log

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
yarn run format:check && yarn run format:write && git add .
yarn run format:write && git add .

View File

@@ -43,6 +43,20 @@ __Linking__
yarn link.dist
```
__Example-app__
```
yarn run cli
```
Abrir carpeta example-app-base
```
npm link @bot-whatsapp/bot -S
npm link @bot-whatsapp/provider -S
npm link @bot-whatsapp/database -S
npm i
npm start
```
__Commit y Push__
El proyecto tiene implementado __[husky](https://typicode.github.io/husky/#/)__ es una herramienta que dispara unas acciones al momento de hacer commit y hacer push
@@ -52,7 +66,7 @@ __push:__ Cada push ejecutar `yarn run test` el cual ejecuta los test internos q
__Example-app__

View File

@@ -66,6 +66,7 @@
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.26.0",
"eslint-config-prettier": "^8.5.0",
"fs-extra": "^11.1.0",
"git-cz": "^4.9.0",
"husky": "^8.0.2",
"only-allow": "^1.1.1",

View File

@@ -0,0 +1,21 @@
const fs = require('fs-extra')
/**
* Copy files
*/
const copyFiles = async (from, to) => {
try {
await fs.copy(from, to)
console.log('success!')
} catch (err) {
console.error(err)
}
}
const copyBaseApp = async () => {
const BASEP_APP_PATH_FROM = `${process.cwd()}/starters/apps/base`
const BASEP_APP_PATH_TO = `${process.cwd()}/example-app-base`
await copyFiles(BASEP_APP_PATH_FROM, BASEP_APP_PATH_TO)
}
module.exports = { copyBaseApp }

View File

@@ -2,6 +2,7 @@ const prompts = require('prompts')
const { yellow, red } = require('kleur')
const { installAll } = require('../install')
const { cleanSession } = require('../clean')
const { copyBaseApp } = require('../create-app')
const { checkNodeVersion, checkOs } = require('../check')
const { jsonConfig } = require('../configuration')
@@ -9,10 +10,15 @@ const startInteractive = async () => {
const questions = [
{
type: 'text',
name: 'dependencies',
message:
'Quieres actualizar las librerias "whatsapp-web.js"? (Y/n)',
name: 'exampeOpt',
message: 'Quieres crear una app de ejemplo "example-app"? (Y/n)',
},
// {
// type: 'text',
// name: 'dependencies',
// message:
// 'Quieres actualizar las librerias "whatsapp-web.js"? (Y/n)',
// },
{
type: 'text',
name: 'cleanTmp',
@@ -57,11 +63,12 @@ const startInteractive = async () => {
const {
dependencies = '',
cleanTmp = '',
exampeOpt = '',
providerDb = [],
providerWs = [],
} = response
/**
* Question #1
* Question
* @returns
*/
const installOrUdpateDep = async () => {
@@ -75,7 +82,7 @@ const startInteractive = async () => {
}
/**
* Question #2
* Question
* @returns
*/
const cleanAllSession = async () => {
@@ -88,6 +95,16 @@ const startInteractive = async () => {
}
}
const createApp = async () => {
const answer = exampeOpt.toLowerCase() || 'n'
if (answer.includes('n')) return true
if (answer.includes('y')) {
await copyBaseApp()
return true
}
}
const vendorProvider = async () => {
if (!providerWs.length) {
console.log(
@@ -117,6 +134,7 @@ const startInteractive = async () => {
}
}
await createApp()
await installOrUdpateDep()
await cleanAllSession()
await vendorProvider()

33
starters/apps/base/app.js Normal file
View File

@@ -0,0 +1,33 @@
const {
createBot,
createProvider,
createFlow,
addKeyword,
} = require('@bot-whatsapp/bot')
/**
* ATENCION: Si vas a usar el provider whatsapp-web.js
* recuerda ejecutar npm i whatsapp-web.js@latest
*/
const WebWhatsappProvider = require('@bot-whatsapp/provider/web-whatsapp')
const MockAdapter = require('@bot-whatsapp/database/mock')
const flowPrincipal = addKeyword(['hola', 'ole', 'HOLA'])
.addAnswer('Bienvenido a mi tienda')
.addAnswer('Como puedo ayudarte?')
.addAnswer(['Tengo:', 'Zapatos', 'Bolsos', 'etc..'])
const main = async () => {
const adapterDB = new MockAdapter()
const adapterFlow = createFlow([flowPrincipal])
const adapterProvider = createProvider(WebWhatsappProvider)
createBot({
flow: adapterFlow,
provider: adapterProvider,
database: adapterDB,
})
}
main()

View File

@@ -0,0 +1,15 @@
{
"name": "bot-whatsapp-base",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"keywords": [],
"dependencies": {
"whatsapp-web.js": "^1.18.3"
},
"author": "",
"license": "ISC"
}

View File

@@ -963,6 +963,7 @@ __metadata:
cz-conventional-changelog: ^3.3.0
eslint: ^8.26.0
eslint-config-prettier: ^8.5.0
fs-extra: ^11.1.0
git-cz: ^4.9.0
husky: ^8.0.2
only-allow: ^1.1.1
@@ -4379,6 +4380,17 @@ __metadata:
languageName: node
linkType: hard
"fs-extra@npm:^11.1.0":
version: 11.1.0
resolution: "fs-extra@npm:11.1.0"
dependencies:
graceful-fs: ^4.2.0
jsonfile: ^6.0.1
universalify: ^2.0.0
checksum: 5ca476103fa1f5ff4a9b3c4f331548f8a3c1881edaae323a4415d3153b5dc11dc6a981c8d1dd93eec8367ceee27b53f8bd27eecbbf66ffcdd04927510c171e7f
languageName: node
linkType: hard
"fs-extra@npm:^8.1.0":
version: 8.1.0
resolution: "fs-extra@npm:8.1.0"