From 40b0d9691e6f5c3d98bfef5ab5e4357f535d8145 Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Fri, 9 Dec 2022 13:50:01 +0100 Subject: [PATCH] chore(ci): :zap: script releases --- .eslintignore | 1 + .eslintrc.js | 6 +- packages/bot/package.json | 2 +- packages/bot/provider/provider.class.js | 2 +- packages/cli/package.json | 2 +- packages/create-bot-whatsapp/package.json | 2 +- packages/database/package.json | 2 +- packages/provider/package.json | 2 +- packages/provider/src/twilio/index.js | 2 +- packages/provider/src/web-whatsapp/index.js | 36 +++++----- scripts/release.js | 75 ++++++++++++++++----- 11 files changed, 88 insertions(+), 44 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..c6f157a --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +packages/docs/* \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js index ec92cad..ebab551 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,5 +10,9 @@ module.exports = { parserOptions: { ecmaVersion: 'latest', }, - rules: {}, + rules: { + 'no-unsafe-negation': 'off', + 'no-prototype-builtins': 'off', + 'no-useless-escape': 'off', + }, } diff --git a/packages/bot/package.json b/packages/bot/package.json index 356987f..18f4ce0 100644 --- a/packages/bot/package.json +++ b/packages/bot/package.json @@ -1,6 +1,6 @@ { "name": "@bot-whatsapp/bot", - "version": "0.0.1", + "version": "0.0.4-alpha.0", "description": "", "main": "./lib/bundle.bot.cjs", "scripts": { diff --git a/packages/bot/provider/provider.class.js b/packages/bot/provider/provider.class.js index 5fc4bb8..212f042 100644 --- a/packages/bot/provider/provider.class.js +++ b/packages/bot/provider/provider.class.js @@ -19,7 +19,7 @@ class ProviderClass extends EventEmitter { * */ - sendMessage = async (userId, message, sendMessage) => { + sendMessage = async (userId, message) => { if (NODE_ENV !== 'production') console.log('[sendMessage]', { userId, message }) return message diff --git a/packages/cli/package.json b/packages/cli/package.json index cf31149..1e15a00 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@bot-whatsapp/cli", - "version": "0.0.1", + "version": "0.0.2-alpha.0", "description": "", "main": "index.js", "devDependencies": { diff --git a/packages/create-bot-whatsapp/package.json b/packages/create-bot-whatsapp/package.json index 2e37314..9ca3258 100644 --- a/packages/create-bot-whatsapp/package.json +++ b/packages/create-bot-whatsapp/package.json @@ -1,6 +1,6 @@ { "name": "create-bot-whatsapp", - "version": "0.0.1", + "version": "0.0.9-alpha.0", "description": "", "main": "./lib/bin/bundle.create.cjs", "dependencies": { diff --git a/packages/database/package.json b/packages/database/package.json index 7502870..0787b05 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -1,6 +1,6 @@ { "name": "@bot-whatsapp/database", - "version": "0.0.1", + "version": "0.0.2-alpha.0", "description": "Esto es el conector a mysql, pg, mongo", "main": "./lib/mock/index.cjs", "keywords": [], diff --git a/packages/provider/package.json b/packages/provider/package.json index dac5bd1..3c40e4c 100644 --- a/packages/provider/package.json +++ b/packages/provider/package.json @@ -1,6 +1,6 @@ { "name": "@bot-whatsapp/provider", - "version": "0.0.1", + "version": "0.0.2-alpha.0", "description": "Esto es el conector a Twilio, Meta, etc...", "main": "./lib/mock/index.cjs", "keywords": [], diff --git a/packages/provider/src/twilio/index.js b/packages/provider/src/twilio/index.js index 592e4d7..7c8b2aa 100644 --- a/packages/provider/src/twilio/index.js +++ b/packages/provider/src/twilio/index.js @@ -81,7 +81,7 @@ class TwilioProvider extends ProviderClass { * @param {*} buttons [] * @returns */ - sendButtons = async (number, message, buttons = []) => { + sendButtons = async () => { console.log(``) console.log( `[NOTA]: Actualmente enviar botons con Twilio esta en desarrollo` diff --git a/packages/provider/src/web-whatsapp/index.js b/packages/provider/src/web-whatsapp/index.js index e3cafcf..3437a38 100644 --- a/packages/provider/src/web-whatsapp/index.js +++ b/packages/provider/src/web-whatsapp/index.js @@ -1,13 +1,7 @@ -const { - Client, - LocalAuth, - MessageMedia, - Buttons, - List, -} = require('whatsapp-web.js') +const { Client, LocalAuth, MessageMedia, Buttons } = require('whatsapp-web.js') const { ProviderClass } = require('@bot-whatsapp/bot') const { Console } = require('console') -const { createWriteStream, existsSync } = require('fs') +const { createWriteStream } = require('fs') const { cleanNumber, generateImage, @@ -134,19 +128,19 @@ class WebWhatsappProvider extends ProviderClass { * @param {*} buttons [] * @returns */ - sendList = async (number, message, listInput = []) => { - let sections = [ - { - title: 'sectionTitle', - rows: [ - { title: 'ListItem1', description: 'desc' }, - { title: 'ListItem2' }, - ], - }, - ] - let list = new List('List body', 'btnText', sections, 'Title', 'footer') - return this.vendor.sendMessage(number, list) - } + // sendList = async (number, message, listInput = []) => { + // let sections = [ + // { + // title: 'sectionTitle', + // rows: [ + // { title: 'ListItem1', description: 'desc' }, + // { title: 'ListItem2' }, + // ], + // }, + // ] + // let list = new List('List body', 'btnText', sections, 'Title', 'footer') + // return this.vendor.sendMessage(number, list) + // } /** * Enviar un mensaje solo texto diff --git a/scripts/release.js b/scripts/release.js index 14c2952..d0a9932 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -1,11 +1,23 @@ const { writeFile, readFileSync } = require('fs') const { join } = require('path') -const { exec, spawn } = require('node:child_process') +const { spawn, execFile } = require('node:child_process') +const process = require('node:process') +const util = require('node:util') + +const OS_ENVIROMENT_WIN = process.platform.includes('win32') const semver = require('semver') +const NPM_COMMAND = OS_ENVIROMENT_WIN ? 'npm.cmd' : 'npm' const [PKG_ARG, PKG_ARG_VERSION] = process.argv.slice(2) || [null] const PATH_PACKAGES = join(__dirname, '..', `packages`) +const cmd = util.promisify(execFile) + +/** + * Leer package json + * @param {*} packageName + * @returns + */ const readPackage = (packageName = null) => { const pkgJson = join(PATH_PACKAGES, packageName, 'package.json') const rawFile = readFileSync(pkgJson, 'utf-8') @@ -14,18 +26,27 @@ const readPackage = (packageName = null) => { return JSON.parse(rawFile) } +/** + * Actualizar package json + * @param {*} packageName + * @param {*} newPkgJson + */ const updatePackage = (packageName = null, newPkgJson) => { - const pkgJson = join(PATH_PACKAGES, packageName, 'package.json') - writeFile(pkgJson, newPkgJson, (err) => { - if (err) throw err + return new Promise((resolve, reject) => { + const pkgJson = join(PATH_PACKAGES, packageName, 'package.json') + if (!Object.keys(newPkgJson).length) throw new Error(`ERROR_FILE_READ`) + writeFile(pkgJson, newPkgJson, (err) => { + if (err) reject(err) + resolve(true) + }) }) } /** - * Actualizar ramdon version de package + * Actualizar version * @param {*} packageName */ -const updateVersion = (packageName = null, number = null) => { +const updateVersion = async (packageName = null, number = null) => { if (!packageName) throw new Error(`PATH_ERROR_PACKAGE: ${packageName}`) const pkgJsonObject = readPackage(packageName) @@ -42,20 +63,44 @@ const updateVersion = (packageName = null, number = null) => { null, 2 ) - updatePackage(packageName, newPkgJson) + await updatePackage(packageName, newPkgJson) return { version: newVersion } } -// const publishRelease = async (packageName) => { -// const pkgTarName = `builder.io-qwik-${version}.tgz` -// await execa('npm', ['pack'], { cwd: distPkgDir }) -// } +const packRelease = async (packageName) => { + const pkgJson = join(PATH_PACKAGES, packageName) + const { stdout } = await cmd(NPM_COMMAND, ['pack'], { + stdio: 'inherit', + cwd: pkgJson, + }) + return stdout +} + +const publishRelease = async (packageName, latest = false) => { + const args = !latest ? ['--tag', 'next'] : ['--access', 'public'] + const pkgJson = join(PATH_PACKAGES, packageName) + const { stdout } = await cmd(NPM_COMMAND, ['publish'].concat(args), { + stdio: 'inherit', + cwd: pkgJson, + }) + console.log(stdout) + return stdout +} /** * Recibe los argumentos entrantes */ -if (PKG_ARG) { - const pkgName = PKG_ARG ? PKG_ARG.split('=').at(1) : null - const pkgNumber = PKG_ARG_VERSION ? PKG_ARG_VERSION.split('=').at(1) : null - updateVersion(pkgName, pkgNumber) + +const main = async () => { + if (PKG_ARG) { + const pkgName = PKG_ARG ? PKG_ARG.split('=').at(1) : null + const pkgNumber = PKG_ARG_VERSION + ? PKG_ARG_VERSION.split('=').at(1) + : null + await updateVersion(pkgName, pkgNumber) + await packRelease(pkgName) + await publishRelease(pkgName) + } } + +main()