mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-17 19:26:23 +00:00
fix(cli): ⚡ create-starter
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,5 @@
|
||||
/node_modules
|
||||
/packages/create-bot-whatsapp/starters
|
||||
/packages/*/starters
|
||||
/packages/*/node_modules
|
||||
/packages/*/dist
|
||||
/packages/*/docs/dist
|
||||
|
||||
@@ -16,9 +16,9 @@ const copyFiles = async (from, to) => {
|
||||
* Copiar directorio con archivos
|
||||
* @param {*} templateName
|
||||
*/
|
||||
const copyBaseApp = async (templateName = null, rootDir = process.cwd()) => {
|
||||
const BASEP_APP_PATH_FROM = `${rootDir}/starters/apps/${templateName}`
|
||||
const BASEP_APP_PATH_TO = `${rootDir}/${templateName}`
|
||||
const copyBaseApp = async (fromDir = process.cwd(), toDir = process.cwd()) => {
|
||||
const BASEP_APP_PATH_FROM = `${fromDir}`
|
||||
const BASEP_APP_PATH_TO = `${toDir}`
|
||||
await copyFiles(BASEP_APP_PATH_FROM, BASEP_APP_PATH_TO)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
const prompts = require('prompts')
|
||||
const { yellow, red } = require('kleur')
|
||||
const { yellow, red, cyan } = require('kleur')
|
||||
const { copyBaseApp } = require('../create-app')
|
||||
const { join } = require('path')
|
||||
const { existsSync } = require('fs')
|
||||
const { checkNodeVersion, checkOs } = require('../check')
|
||||
|
||||
const bannerDone = () => {
|
||||
console.log(``)
|
||||
console.log(
|
||||
cyan(
|
||||
[
|
||||
`[Agradecimientos]: Este es un proyecto OpenSource, si tienes intenciones de colaborar puedes hacerlo:`,
|
||||
`[😉] Comprando un cafe https://www.buymeacoffee.com/leifermendez`,
|
||||
`[⭐] Dar estrella https://github.com/leifermendez/bot-whatsapp`,
|
||||
`[🚀] Realizando mejoras en el codigo`,
|
||||
].join('\n')
|
||||
)
|
||||
)
|
||||
console.log(``)
|
||||
}
|
||||
|
||||
const startInteractive = async () => {
|
||||
const questions = [
|
||||
{
|
||||
@@ -49,43 +66,29 @@ const startInteractive = async () => {
|
||||
}
|
||||
const response = await prompts(questions, { onCancel })
|
||||
const { outDir = '', providerDb = [], providerWs = [] } = response
|
||||
/**
|
||||
* @deprecated
|
||||
* Question
|
||||
* @returns
|
||||
*/
|
||||
// const installOrUdpateDep = async () => {
|
||||
// const answer = dependencies.toLowerCase() || 'n'
|
||||
// if (answer.includes('n')) return true
|
||||
|
||||
// if (answer.includes('y')) {
|
||||
// await installAll()
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
|
||||
// const cleanAllSession = async () => {
|
||||
// const answer = cleanTmp.toLowerCase() || 'n'
|
||||
// if (answer.includes('n')) return true
|
||||
|
||||
// if (answer.includes('y')) {
|
||||
// await cleanSession()
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Crear una app (copiar plantilla)
|
||||
* @returns
|
||||
*/
|
||||
const createApp = async (templateName = null) => {
|
||||
if (!templateName)
|
||||
throw new Error('TEMPLATE_NAME_INVALID: ', templateName)
|
||||
|
||||
const possiblesPath = [
|
||||
join(__dirname, 'starters', 'apps', templateName),
|
||||
join(__dirname, '..', 'starters', 'apps', templateName),
|
||||
join(__dirname, '..', '..', 'starters', 'apps', templateName),
|
||||
]
|
||||
|
||||
const answer = outDir.toLowerCase() || 'n'
|
||||
if (answer.includes('n')) return true
|
||||
|
||||
if (answer.includes('y')) {
|
||||
await copyBaseApp(templateName)
|
||||
const indexOfPath = possiblesPath.find((a) => existsSync(a))
|
||||
await copyBaseApp(indexOfPath, join(process.cwd(), templateName))
|
||||
console.log(``)
|
||||
console.log(yellow(`cd ${templateName}`))
|
||||
console.log(yellow(`npm install`))
|
||||
console.log(yellow(`npm start`))
|
||||
console.log(``)
|
||||
|
||||
return outDir
|
||||
}
|
||||
}
|
||||
@@ -104,7 +107,6 @@ const startInteractive = async () => {
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
console.log(yellow(`'Deberia crer una carpeta en root/provider'`))
|
||||
return answer
|
||||
}
|
||||
|
||||
@@ -129,6 +131,7 @@ const startInteractive = async () => {
|
||||
const dbAdapter = await dbProvider()
|
||||
const NAME_DIR = ['base', providerAdapter, dbAdapter].join('-')
|
||||
await createApp(NAME_DIR)
|
||||
bannerDone()
|
||||
}
|
||||
|
||||
module.exports = { startInteractive }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/cli",
|
||||
"version": "0.0.5-alpha.0",
|
||||
"version": "0.0.14-alpha.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"devDependencies": {
|
||||
@@ -10,6 +10,7 @@
|
||||
"kleur": "^4.1.5"
|
||||
},
|
||||
"files": [
|
||||
"./starters/",
|
||||
"./lib/cli/bundle.cli.cjs"
|
||||
],
|
||||
"bin": {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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')
|
||||
|
||||
@@ -12,5 +13,11 @@ module.exports = {
|
||||
file: PATH,
|
||||
format: 'cjs',
|
||||
},
|
||||
plugins: [commonjs(), nodeResolve()],
|
||||
plugins: [
|
||||
copy({
|
||||
targets: [{ src: 'starters/*', dest: join(__dirname, 'starters') }],
|
||||
}),
|
||||
commonjs(),
|
||||
nodeResolve(),
|
||||
],
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "create-bot-whatsapp",
|
||||
"version": "0.0.14-alpha.0",
|
||||
"version": "0.0.20-alpha.0",
|
||||
"description": "",
|
||||
"main": "./lib/bundle.create-bot-whatsapp.cjs",
|
||||
"files": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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')
|
||||
|
||||
@@ -13,11 +13,5 @@ module.exports = {
|
||||
file: PATH,
|
||||
format: 'cjs',
|
||||
},
|
||||
plugins: [
|
||||
copy({
|
||||
targets: [{ src: 'starters/*', dest: join(__dirname, 'starters') }],
|
||||
}),
|
||||
commonjs(),
|
||||
nodeResolve(),
|
||||
],
|
||||
plugins: [commonjs(), nodeResolve()],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user