diff --git a/.gitignore b/.gitignore index 114cdfc..d7f50c1 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,7 @@ tmp/ .yarn/* !.yarn/releases .fleet/ -example-app/ +example-app*/ qr.svg package-lock.json yarn-error.log \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit index bc41446..9c7e438 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -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 . diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 137d83d..d79944a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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__ + diff --git a/package.json b/package.json index 42286bd..1bc9979 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/cli/create-app/index.js b/packages/cli/create-app/index.js new file mode 100644 index 0000000..e766240 --- /dev/null +++ b/packages/cli/create-app/index.js @@ -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 } diff --git a/packages/cli/interactive/index.js b/packages/cli/interactive/index.js index c86a568..6b3dbf6 100644 --- a/packages/cli/interactive/index.js +++ b/packages/cli/interactive/index.js @@ -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() diff --git a/starters/apps/base/app.js b/starters/apps/base/app.js new file mode 100644 index 0000000..64f9100 --- /dev/null +++ b/starters/apps/base/app.js @@ -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() diff --git a/starters/apps/base/package.json b/starters/apps/base/package.json new file mode 100644 index 0000000..167c0dc --- /dev/null +++ b/starters/apps/base/package.json @@ -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" +} diff --git a/yarn.lock b/yarn.lock index f037320..d3847f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"