fix(cli): 🔥 create script - templates

This commit is contained in:
Leifer Mendez
2022-12-10 21:17:29 +01:00
parent 1036273a28
commit eebc3c9806
29 changed files with 417 additions and 61 deletions

View File

@@ -12,9 +12,13 @@ const copyFiles = async (from, to) => {
}
}
const copyBaseApp = async () => {
const BASEP_APP_PATH_FROM = `${process.cwd()}/starters/apps/base`
const BASEP_APP_PATH_TO = `${process.cwd()}/example-app-base`
/**
* Copiar directorio con archivos
* @param {*} templateName
*/
const copyBaseApp = async (templateName = null) => {
const BASEP_APP_PATH_FROM = `${process.cwd()}/starters/apps/${templateName}`
const BASEP_APP_PATH_TO = `${process.cwd()}/${templateName}`
await copyFiles(BASEP_APP_PATH_FROM, BASEP_APP_PATH_TO)
}

View File

@@ -10,29 +10,18 @@ const startInteractive = async () => {
const questions = [
{
type: 'text',
name: 'exampeOpt',
message:
'Quieres crear una app de ejemplo "example-app-example"? (Y/n)',
},
// {
// type: 'text',
// name: 'dependencies',
// message:
// 'Quieres actualizar las librerias "whatsapp-web.js"? (Y/n)',
// },
{
type: 'text',
name: 'cleanTmp',
message: 'Quieres limpiar la session del bot? (Y/n)',
name: 'outDir',
message: 'Quieres crear un bot? (Y/n)',
},
{
type: 'multiselect',
name: 'providerWs',
message: 'Proveedor de Whatsapp',
choices: [
{ title: 'whatsapp-web.js', value: 'whatsapp-web.js' },
{ title: 'whatsapp-web.js (gratis)', value: 'wweb' },
{ title: 'Twilio', value: 'twilio' },
{ title: 'Baileys (gratis)', value: 'bailey', disabled: true },
{ title: 'API Oficial (Meta)', value: 'meta', disabled: true },
{ title: 'Twilio', value: 'twilio', disabled: true },
],
max: 1,
hint: 'Espacio para selecionar',
@@ -43,9 +32,10 @@ const startInteractive = async () => {
name: 'providerDb',
message: 'Cual base de datos quieres usar',
choices: [
{ title: 'JSONFile', value: 'json' },
{ title: 'MySQL', value: 'mysql', disabled: true },
{ title: 'Mongo', value: 'mongo', disabled: true },
{ title: 'Memory', value: 'memory' },
{ title: 'Mongo', value: 'mongo' },
{ title: 'MySQL', value: 'mysql' },
{ title: 'Json', value: 'json', disabled: true },
],
max: 1,
hint: 'Espacio para selecionar',
@@ -64,11 +54,12 @@ const startInteractive = async () => {
const {
dependencies = '',
cleanTmp = '',
exampeOpt = '',
outDir = '',
providerDb = [],
providerWs = [],
} = response
/**
* @deprecated
* Question
* @returns
*/
@@ -83,6 +74,7 @@ const startInteractive = async () => {
}
/**
* @deprecated
* Question
* @returns
*/
@@ -96,17 +88,28 @@ const startInteractive = async () => {
}
}
const createApp = async () => {
const answer = exampeOpt.toLowerCase() || 'n'
/**
* Crear una app (copiar plantilla)
* @returns
*/
const createApp = async (templateName = null) => {
if (!templateName)
throw new Error('TEMPLATE_NAME_INVALID: ', templateName)
const answer = outDir.toLowerCase() || 'n'
if (answer.includes('n')) return true
if (answer.includes('y')) {
await copyBaseApp()
return true
await copyBaseApp(templateName)
return outDir
}
}
/**
* Selccionar Provider (meta, twilio, etc...)
* @returns
*/
const vendorProvider = async () => {
const [answer] = providerWs
if (!providerWs.length) {
console.log(
red(
@@ -116,11 +119,15 @@ const startInteractive = async () => {
process.exit(1)
}
console.log(yellow(`'Deberia crer una carpeta en root/provider'`))
return true
return answer
}
/**
* Selecionar adaptador de base de datos
* @returns
*/
const dbProvider = async () => {
const answer = providerDb
const [answer] = providerDb
if (!providerDb.length) {
console.log(
red(
@@ -129,18 +136,13 @@ const startInteractive = async () => {
)
process.exit(1)
}
if (answer === 'json') {
console.log('Deberia crer una carpeta en root/data')
return 1
}
return answer
}
await createApp()
await installOrUdpateDep()
await cleanAllSession()
await vendorProvider()
await dbProvider()
await jsonConfig()
const providerAdapter = await vendorProvider()
const dbAdapter = await dbProvider()
const NAME_DIR = ['base', providerAdapter, dbAdapter].join('-')
await createApp(NAME_DIR)
}
module.exports = { startInteractive }

View File

@@ -1,6 +1,6 @@
{
"name": "@bot-whatsapp/cli",
"version": "0.0.2-alpha.0",
"version": "0.0.4-alpha.0",
"description": "",
"main": "index.js",
"devDependencies": {

View File

@@ -1,3 +1,3 @@
#!/usr/bin/env node
const main = require('../lib/bin/bundle.create.cjs')
const main = require('../lib/bundle.create-bot-whatsapp.cjs')
main()

View File

@@ -1,12 +1,10 @@
const { startInteractive } = require('@bot-whatsapp/cli')
/**
* Main function
* Voy a llamar directo a CLI
* Temporalmente luego mejoro esta
* parte
* @returns
*/
const main = () => {
console.clear()
console.log(``)
console.log(`[PostInstall]: Este es el main function.`)
console.log(`[PostInstall]: 👌 Aqui podrias instalar cosas`)
console.log(``)
}
const main = () => startInteractive()
module.exports = main

View File

@@ -1,12 +1,15 @@
{
"name": "create-bot-whatsapp",
"version": "0.0.9-alpha.0",
"version": "0.0.13-alpha.0",
"description": "",
"main": "./lib/bin/bundle.create.cjs",
"main": "./lib/bundle.create-bot-whatsapp.cjs",
"files": [
"./starters/",
"./bin/create.js",
"./lib/bundle.create-bot-whatsapp.cjs"
],
"bin": "./bin/create.js",
"dependencies": {
"@bot-whatsapp/cli": "*"
},
"bin": {
"bot": "./lib/bin/bundle.create.cjs"
}
}

View File

@@ -1,9 +1,10 @@
const banner = require('../../config/banner.rollup.json')
const commonjs = require('@rollup/plugin-commonjs')
const copy = require('rollup-plugin-copy')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const { join } = require('path')
const PATH = join(__dirname, 'lib', 'bin', 'bundle.create.cjs')
const PATH = join(__dirname, 'lib', 'bundle.create-bot-whatsapp.cjs')
module.exports = {
input: join(__dirname, 'index.js'),
@@ -12,5 +13,11 @@ module.exports = {
file: PATH,
format: 'cjs',
},
plugins: [commonjs(), nodeResolve()],
plugins: [
copy({
targets: [{ src: 'starters/*', dest: join(__dirname, 'starters') }],
}),
commonjs(),
nodeResolve(),
],
}

View File

@@ -1,11 +1,14 @@
{
"name": "@bot-whatsapp/database",
"version": "0.0.2-alpha.0",
"version": "0.0.4-alpha.0",
"description": "Esto es el conector a mysql, pg, mongo",
"main": "./lib/mock/index.cjs",
"keywords": [],
"author": "",
"license": "ISC",
"files": [
"./lib/"
],
"dependencies": {
"dotenv": "^16.0.3",
"mongodb": "^4.11.0",

View File

@@ -1,11 +1,14 @@
{
"name": "@bot-whatsapp/provider",
"version": "0.0.7-alpha.0",
"version": "0.0.10-alpha.0",
"description": "Esto es el conector a Twilio, Meta, etc...",
"main": "./lib/mock/index.cjs",
"keywords": [],
"author": "",
"license": "ISC",
"files": [
"./lib/"
],
"dependencies": {
"@bot-whatsapp/bot": "*",
"qr-image": "^3.2.0"