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

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()