From 860bd8539f0ce12f287c3574302fcc4fc0243d80 Mon Sep 17 00:00:00 2001 From: Leifer Date: Thu, 27 Oct 2022 11:10:04 +0200 Subject: [PATCH] generate json file --- .gitignore | 5 +-- package-lock.json | 18 ++++++---- packages/cli/README.md | 2 +- packages/cli/configuration/index.js | 33 ++++++++++++++++++ packages/cli/install/index.js | 10 ++++-- packages/cli/interactive/index.js | 2 ++ packages/cli/lib/bundle.cjs | 54 +++++++++++++++++++++++++---- packages/cli/package.json | 3 ++ 8 files changed, 109 insertions(+), 18 deletions(-) create mode 100644 packages/cli/configuration/index.js diff --git a/.gitignore b/.gitignore index b38ba23..08ca802 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /node_modules -/node_modules/* session.json chats/* !chats/.gitkeep @@ -9,4 +8,6 @@ mediaSend/* !mediaSend/.gitkeep !mediaSend/nota-de-voz.mp3 .env -.wwebjs_auth \ No newline at end of file +.wwebjs_auth +packages/cli/config.json +config.json \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index a7a85fa..8b77770 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6135,9 +6135,9 @@ "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, "node_modules/whatsapp-web.js": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.18.0.tgz", - "integrity": "sha512-3cCW28/w7llZmTgiO9osumaopOuBBduvyuW02yfy3q9Rz4Wq9Oe1dRedE/kkq764zB8AZcuTs0tE8OKTq2Zobw==", + "version": "1.18.2", + "resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.18.2.tgz", + "integrity": "sha512-RMzLgstoS9hLK4ix+RchDxXdpuSXuV8jm7SDb/8xc5Ju09zrkOP11dj/4XYszmuwNR0n1VsxNQGp39pnulmcUA==", "dependencies": { "@pedroslopez/moduleraid": "^5.0.2", "fluent-ffmpeg": "^2.1.2", @@ -6431,6 +6431,9 @@ "packages/cli": { "version": "1.0.0", "license": "ISC", + "dependencies": { + "whatsapp-web.js": "^1.18.2" + }, "devDependencies": { "cross-spawn": "^7.0.3", "detect-package-manager": "^2.0.1", @@ -7500,7 +7503,8 @@ "detect-package-manager": "^2.0.1", "kleur": "^4.1.5", "prompts": "^2.4.2", - "rimraf": "^3.0.2" + "rimraf": "^3.0.2", + "whatsapp-web.js": "1.18.2" } }, "cli-tableau": { @@ -11106,9 +11110,9 @@ "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, "whatsapp-web.js": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.18.0.tgz", - "integrity": "sha512-3cCW28/w7llZmTgiO9osumaopOuBBduvyuW02yfy3q9Rz4Wq9Oe1dRedE/kkq764zB8AZcuTs0tE8OKTq2Zobw==", + "version": "1.18.2", + "resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.18.2.tgz", + "integrity": "sha512-RMzLgstoS9hLK4ix+RchDxXdpuSXuV8jm7SDb/8xc5Ju09zrkOP11dj/4XYszmuwNR0n1VsxNQGp39pnulmcUA==", "requires": { "@pedroslopez/moduleraid": "^5.0.2", "archiver": "^5.3.1", diff --git a/packages/cli/README.md b/packages/cli/README.md index 784a459..9923c6c 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -5,7 +5,7 @@ - [x] Obtener Package Manager - [x] Revisar las libreria de WhatsappWeb para obtener version reciente - [x] Opcion interactiva de limpiar session -- [ ] Opcion de generar `json` con la configuracion +- [x] Opcion de generar `json` con la configuracion - [x] Agregar `rollup` para limpiar el codigo --- diff --git a/packages/cli/configuration/index.js b/packages/cli/configuration/index.js new file mode 100644 index 0000000..50565d9 --- /dev/null +++ b/packages/cli/configuration/index.js @@ -0,0 +1,33 @@ +const { writeFile } = require('fs').promises +const { join } = require('path') + +/** + * JSON_TEMPLATE = {[key:string]{...pros}} + */ +const JSON_TEMPLATE = { + provider: { + vendor: '', + }, + database: { + host: '', + password: '', + port: '', + username: '', + db: '', + }, + io: { + vendor: '', + }, +} + +const PATH_CONFIG = join(process.cwd(), 'config.json') + +const jsonConfig = () => { + return writeFile( + PATH_CONFIG, + JSON.stringify(JSON_TEMPLATE, null, 2), + 'utf-8' + ) +} + +module.exports = { jsonConfig } diff --git a/packages/cli/install/index.js b/packages/cli/install/index.js index 0b5d4f5..dddc3be 100644 --- a/packages/cli/install/index.js +++ b/packages/cli/install/index.js @@ -1,9 +1,15 @@ -const { readFileSync } = require('fs') +const { readFileSync, existsSync } = require('fs') const { join } = require('path') const { installDeps } = require('./tool') +const PATHS_DIR = [ + join(__dirname, 'pkg-to-update.json'), + join(__dirname, '..', 'pkg-to-update.json'), +] + const PKG_TO_UPDATE = () => { - const data = readFileSync(join(__dirname, 'pkg-to-update.json'), 'utf-8') + const PATH_INDEX = PATHS_DIR.findIndex((a) => existsSync(a)) + const data = readFileSync(PATHS_DIR[PATH_INDEX], 'utf-8') const dataParse = JSON.parse(data) const pkg = Object.keys(dataParse).map((n) => `${n}@${dataParse[n]}`) return pkg diff --git a/packages/cli/interactive/index.js b/packages/cli/interactive/index.js index 9ac4502..c86a568 100644 --- a/packages/cli/interactive/index.js +++ b/packages/cli/interactive/index.js @@ -3,6 +3,7 @@ const { yellow, red } = require('kleur') const { installAll } = require('../install') const { cleanSession } = require('../clean') const { checkNodeVersion, checkOs } = require('../check') +const { jsonConfig } = require('../configuration') const startInteractive = async () => { const questions = [ @@ -120,6 +121,7 @@ const startInteractive = async () => { await cleanAllSession() await vendorProvider() await dbProvider() + await jsonConfig() } module.exports = { startInteractive } diff --git a/packages/cli/lib/bundle.cjs b/packages/cli/lib/bundle.cjs index cccaf14..7d68589 100644 --- a/packages/cli/lib/bundle.cjs +++ b/packages/cli/lib/bundle.cjs @@ -76,12 +76,18 @@ const installDeps$1 = (pkgManager, packageList) => { var tool = { getPkgManage, installDeps: installDeps$1 }; -const { readFileSync } = require$$0$1; -const { join: join$1 } = require$$1$1; +const { readFileSync, existsSync } = require$$0$1; +const { join: join$2 } = require$$1$1; const { installDeps } = tool; +const PATHS_DIR = [ + join$2(__dirname, 'pkg-to-update.json'), + join$2(__dirname, '..', 'pkg-to-update.json'), +]; + const PKG_TO_UPDATE = () => { - const data = readFileSync(join$1(__dirname, 'pkg-to-update.json'), 'utf-8'); + const PATH_INDEX = PATHS_DIR.findIndex((a) => existsSync(a)); + const data = readFileSync(PATHS_DIR[PATH_INDEX], 'utf-8'); const dataParse = JSON.parse(data); const pkg = Object.keys(dataParse).map((n) => `${n}@${dataParse[n]}`); return pkg @@ -96,11 +102,11 @@ var install = { installAll: installAll$1 }; const rimraf = require$$0$2; const { yellow: yellow$2 } = require$$0; -const { join } = require$$1$1; +const { join: join$1 } = require$$1$1; const PATH_WW = [ - join(process.cwd(), '.wwebjs_auth'), - join(process.cwd(), 'session.json'), + join$1(process.cwd(), '.wwebjs_auth'), + join$1(process.cwd(), 'session.json'), ]; const cleanSession$1 = () => { @@ -153,11 +159,46 @@ const checkOs$1 = () => { var check = { checkNodeVersion: checkNodeVersion$1, checkOs: checkOs$1 }; +const { writeFile } = require$$0$1.promises; +const { join } = require$$1$1; + +/** + * JSON_TEMPLATE = {[key:string]{...pros}} + */ +const JSON_TEMPLATE = { + provider: { + vendor: '', + }, + database: { + host: '', + password: '', + port: '', + username: '', + db: '', + }, + io: { + vendor: '', + }, +}; + +const PATH_CONFIG = join(process.cwd(), 'config.json'); + +const jsonConfig$1 = () => { + return writeFile( + PATH_CONFIG, + JSON.stringify(JSON_TEMPLATE, null, 2), + 'utf-8' + ) +}; + +var configuration = { jsonConfig: jsonConfig$1 }; + const prompts = require$$0$3; const { yellow, red } = require$$0; const { installAll } = install; const { cleanSession } = clean; const { checkNodeVersion, checkOs } = check; +const { jsonConfig } = configuration; const startInteractive$1 = async () => { const questions = [ @@ -275,6 +316,7 @@ const startInteractive$1 = async () => { await cleanAllSession(); await vendorProvider(); await dbProvider(); + await jsonConfig(); }; var interactive = { startInteractive: startInteractive$1 }; diff --git a/packages/cli/package.json b/packages/cli/package.json index 35667bd..5a0e787 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -21,5 +21,8 @@ "kleur": "^4.1.5", "prompts": "^2.4.2", "rimraf": "^3.0.2" + }, + "dependencies": { + "whatsapp-web.js": "^1.18.2" } }