diff --git a/.eslintignore b/.eslintignore index c6f157a..6c4b500 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ -packages/docs/* \ No newline at end of file +packages/docs/* +packages/portal/* \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fd8fa3..968147b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: run: yarn install --immutable --network-timeout 300000 - name: Build Package - run: yarn build + run: yarn build:full - name: Build Eslint rules run: yarn lint:fix diff --git a/.github/workflows/releases-dev.yml b/.github/workflows/releases-dev.yml index a2d9979..6f380a2 100644 --- a/.github/workflows/releases-dev.yml +++ b/.github/workflows/releases-dev.yml @@ -27,7 +27,7 @@ jobs: run: yarn install --immutable --network-timeout 300000 - name: Build Package - run: yarn build + run: yarn build:full - name: Release @bot-whatsapp/bot run: yarn node ./scripts/release.js --name=bot --version= --token="${{ secrets.NPM_TOKEN }}" @@ -44,6 +44,9 @@ jobs: - name: Release @bot-whatsapp/provider run: yarn node ./scripts/release.js --name=provider --version= --token="${{ secrets.NPM_TOKEN }}" + - name: Release @bot-whatsapp/portal + run: yarn node ./scripts/release.js --name=portal --version= --token="${{ secrets.NPM_TOKEN }}" + - name: Commit Versioning & Push changes uses: stefanzweifel/git-auto-commit-action@v4 with: diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index daafe13..90f27fa 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -31,7 +31,7 @@ jobs: run: yarn install --immutable --network-timeout 300000 - name: Build Package - run: yarn build + run: yarn build:full - name: Release @bot-whatsapp/bot run: yarn node ./scripts/release.js --name=bot --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}" @@ -48,6 +48,9 @@ jobs: - name: Release @bot-whatsapp/provider run: yarn node ./scripts/release.js --name=provider --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}" + - name: Release @bot-whatsapp/portal + run: yarn node ./scripts/release.js --name=portal --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}" + - name: Set CHANGELOG run: yarn release diff --git a/package.json b/package.json index 72109ae..af82cd9 100644 --- a/package.json +++ b/package.json @@ -13,12 +13,15 @@ "contexts:rollup": "rollup --config ./packages/contexts/rollup-contexts.config.js", "database:rollup": "rollup --config ./packages/database/rollup-database.config.js", "create-bot-whatsapp:rollup": "rollup --config ./packages/create-bot-whatsapp/rollup-create.config.js", + "portal:rollup": "rollup --config ./packages/portal/rollup-portal.config.js", "format:check": "prettier --check ./packages", "format:write": "prettier --write ./packages", "fmt.staged": "pretty-quick --staged", "lint:check": "eslint ./packages", "lint:fix": "eslint --fix ./packages", - "build": "yarn run cli:rollup && yarn run bot:rollup && yarn run provider:rollup && yarn run database:rollup && yarn run contexts:rollup && yarn run create-bot-whatsapp:rollup", + "build:portal-web": "cd ./packages/portal/ && yarn run build.types && yarn run build.client && yarn run build.server && yarn run lint --fix", + "build:full": "yarn run build:portal-web && yarn run cli:rollup && yarn run bot:rollup && yarn run provider:rollup && yarn run database:rollup && yarn run contexts:rollup && yarn run create-bot-whatsapp:rollup && yarn run portal:rollup", + "build": "yarn run cli:rollup && yarn run bot:rollup && yarn run provider:rollup && yarn run database:rollup && yarn run contexts:rollup && yarn run create-bot-whatsapp:rollup && yarn run portal:rollup", "copy.lib": "node ./scripts/move.js", "test.unit": "node ./node_modules/uvu/bin.js packages test", "test.coverage": "node ./node_modules/c8/bin/c8.js npm run test.unit", @@ -39,6 +42,7 @@ "packages/database", "packages/provider", "packages/contexts", + "packages/portal", "packages/docs" ], "keywords": [ diff --git a/packages/bot/package.json b/packages/bot/package.json index 77cb142..7fd247a 100644 --- a/packages/bot/package.json +++ b/packages/bot/package.json @@ -1,6 +1,6 @@ { "name": "@bot-whatsapp/bot", - "version": "0.0.45-alpha.0", + "version": "0.0.46-alpha.0", "description": "", "main": "./lib/bundle.bot.cjs", "scripts": { @@ -28,5 +28,9 @@ }, "dependencies": { "dotenv": "^16.0.3" + }, + "repository": { + "type": "git", + "url": "https://github.com/codigoencasa/bot-whatsapp/tree/main/packages/bot" } } diff --git a/packages/cli/package.json b/packages/cli/package.json index 04118d7..c425310 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@bot-whatsapp/cli", - "version": "0.0.52-alpha.0", + "version": "0.0.53-alpha.0", "description": "", "main": "index.js", "devDependencies": { @@ -15,5 +15,9 @@ ], "bin": { "bot": "./bin/cli.js" + }, + "repository": { + "type": "git", + "url": "https://github.com/codigoencasa/bot-whatsapp/tree/main/packages/cli" } } diff --git a/packages/contexts/package.json b/packages/contexts/package.json index 29c2dcd..2301645 100644 --- a/packages/contexts/package.json +++ b/packages/contexts/package.json @@ -13,5 +13,9 @@ }, "dependencies": { "@bot-whatsapp/bot": "*" + }, + "repository": { + "type": "git", + "url": "https://github.com/codigoencasa/bot-whatsapp/tree/main/packages/contexts" } } diff --git a/packages/create-bot-whatsapp/package.json b/packages/create-bot-whatsapp/package.json index bb19123..b9cb9a3 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.63-alpha.0", + "version": "0.0.64-alpha.0", "description": "", "main": "./lib/bundle.create-bot-whatsapp.cjs", "files": [ @@ -11,5 +11,9 @@ "bin": "./bin/create.js", "dependencies": { "@bot-whatsapp/cli": "*" + }, + "repository": { + "type": "git", + "url": "https://github.com/codigoencasa/bot-whatsapp/tree/main/packages/create-bot-whatsapp" } } diff --git a/packages/database/package.json b/packages/database/package.json index cdab548..3d995be 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -1,6 +1,6 @@ { "name": "@bot-whatsapp/database", - "version": "0.0.44-alpha.0", + "version": "0.0.45-alpha.0", "description": "Esto es el conector a mysql, pg, mongo", "main": "./lib/mock/index.cjs", "keywords": [], @@ -19,5 +19,9 @@ "./mongo": "./lib/mongo/index.cjs", "./json": "./lib/json/index.cjs", "./mysql": "./lib/mysql/index.cjs" + }, + "repository": { + "type": "git", + "url": "https://github.com/codigoencasa/bot-whatsapp/tree/main/packages/database" } } diff --git a/packages/portal/.eslintignore b/packages/portal/.eslintignore new file mode 100644 index 0000000..73d2683 --- /dev/null +++ b/packages/portal/.eslintignore @@ -0,0 +1,33 @@ +**/*.log +**/.DS_Store +*. +.vscode/settings.json +.history +.yarn +bazel-* +bazel-bin +bazel-out +bazel-qwik +bazel-testlogs +dist +dist-dev +lib +lib-types +etc +external +node_modules +temp +tsc-out +tsdoc-metadata.json +target +output +rollup.config.js +build +.cache +.vscode +.rollup.cache +dist +tsconfig.tsbuildinfo +vite.config.ts +*.spec.tsx +*.spec.ts diff --git a/packages/portal/.eslintrc.cjs b/packages/portal/.eslintrc.cjs new file mode 100644 index 0000000..039b99a --- /dev/null +++ b/packages/portal/.eslintrc.cjs @@ -0,0 +1,41 @@ +module.exports = { + root: true, + env: { + browser: true, + es2021: true, + node: true, + }, + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:qwik/recommended', + ], + parser: '@typescript-eslint/parser', + parserOptions: { + tsconfigRootDir: __dirname, + project: ['./tsconfig.json'], + ecmaVersion: 2021, + sourceType: 'module', + ecmaFeatures: { + jsx: true, + }, + }, + plugins: ['@typescript-eslint'], + rules: { + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-inferrable-types': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/no-empty-interface': 'off', + '@typescript-eslint/no-namespace': 'off', + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-this-alias': 'off', + '@typescript-eslint/ban-types': 'off', + '@typescript-eslint/ban-ts-comment': 'off', + 'prefer-spread': 'off', + 'no-case-declarations': 'off', + 'no-console': 'off', + '@typescript-eslint/no-unused-vars': ['error'], + '@typescript-eslint/consistent-type-imports': 'warn', + }, +}; diff --git a/packages/portal/.gitignore b/packages/portal/.gitignore new file mode 100644 index 0000000..e95b829 --- /dev/null +++ b/packages/portal/.gitignore @@ -0,0 +1,38 @@ +# Build +/dist +/lib +/lib-types +/server + +# Development +node_modules + +# Cache +.cache +.mf +.vscode +.rollup.cache +tsconfig.tsbuildinfo + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +# Editor +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +# Yarn +.yarn/* +!.yarn/releases diff --git a/packages/portal/.prettierignore b/packages/portal/.prettierignore new file mode 100644 index 0000000..1592248 --- /dev/null +++ b/packages/portal/.prettierignore @@ -0,0 +1,6 @@ +# Files Prettier should not format +**/*.log +**/.DS_Store +*. +dist +node_modules diff --git a/packages/portal/README.md b/packages/portal/README.md new file mode 100644 index 0000000..0b9a2a9 --- /dev/null +++ b/packages/portal/README.md @@ -0,0 +1,71 @@ +# Qwik City App ⚡️ + +- [Qwik Docs](https://qwik.builder.io/) +- [Discord](https://qwik.builder.io/chat) +- [Qwik GitHub](https://github.com/BuilderIO/qwik) +- [@QwikDev](https://twitter.com/QwikDev) +- [Vite](https://vitejs.dev/) + +--- + +## Project Structure + +This project is using Qwik with [QwikCity](https://qwik.builder.io/qwikcity/overview/). QwikCity is just a extra set of tools on top of Qwik to make it easier to build a full site, including directory-based routing, layouts, and more. + +Inside your project, you'll see the following directory structure: + +``` +├── public/ +│ └── ... +└── src/ + ├── components/ + │ └── ... + └── routes/ + └── ... +``` + +- `src/routes`: Provides the directory based routing, which can include a hierarchy of `layout.tsx` layout files, and an `index.tsx` file as the page. Additionally, `index.ts` files are endpoints. Please see the [routing docs](https://qwik.builder.io/qwikcity/routing/overview/) for more info. + +- `src/components`: Recommended directory for components. + +- `public`: Any static assets, like images, can be placed in the public directory. Please see the [Vite public directory](https://vitejs.dev/guide/assets.html#the-public-directory) for more info. + +## Add Integrations and deployment + +Use the `npm run qwik add` command to add additional integrations. Some examples of integrations include: Cloudflare, Netlify or Express server, and the [Static Site Generator (SSG)](https://qwik.builder.io/qwikcity/static-site-generation/static-site-config/). + +```shell +npm run qwik add # or `yarn qwik add` +``` + +## Development + +Development mode uses [Vite's development server](https://vitejs.dev/). During development, the `dev` command will server-side render (SSR) the output. + +```shell +npm start # or `yarn start` +``` + +> Note: during dev mode, Vite may request a significant number of `.js` files. This does not represent a Qwik production build. + +## Preview + +The preview command will create a production build of the client modules, a production build of `src/entry.preview.tsx`, and run a local server. The preview server is only for convenience to locally preview a production build, and it should not be used as a production server. + +```shell +npm run preview # or `yarn preview` +``` + +## Production + +The production build will generate client and server modules by running both client and server build commands. Additionally, the build command will use Typescript to run a type check on the source code. + +```shell +npm run build # or `yarn build` +``` + +## Static Site Generator (Node.js) + +``` +npm run build.server +``` diff --git a/packages/portal/adaptors/static/vite.config.ts b/packages/portal/adaptors/static/vite.config.ts new file mode 100644 index 0000000..dba968a --- /dev/null +++ b/packages/portal/adaptors/static/vite.config.ts @@ -0,0 +1,19 @@ +import { staticAdaptor } from '@builder.io/qwik-city/adaptors/static/vite' +import { extendConfig } from '@builder.io/qwik-city/vite' +import baseConfig from '../../vite.config' + +export default extendConfig(baseConfig, () => { + return { + build: { + ssr: true, + rollupOptions: { + input: ['@qwik-city-plan'], + }, + }, + plugins: [ + staticAdaptor({ + origin: 'https://bot-whatsapp.netlify.app', + }), + ], + } +}) diff --git a/packages/portal/package.json b/packages/portal/package.json new file mode 100644 index 0000000..a184b1a --- /dev/null +++ b/packages/portal/package.json @@ -0,0 +1,52 @@ +{ + "name": "@bot-whatsapp/portal", + "version": "0.0.3-alpha.0", + "description": "Portal WEB para escanear QR", + "main": "./lib/portal.http.cjs", + "scripts": { + "build": "qwik build", + "build.client": "vite build", + "build.preview": "vite build --ssr src/entry.preview.tsx", + "build.server": "vite build -c adaptors/static/vite.config.ts", + "build.types": "tsc --incremental --noEmit", + "deploy": "echo 'Run \"npm run qwik add\" to install a server adaptor'", + "dev": "vite --mode ssr", + "dev.debug": "node --inspect-brk ./node_modules/vite/bin/vite.js --mode ssr --force", + "fmt": "prettier --write .", + "fmt.check": "prettier --check .", + "lint": "eslint \"src/**/*.ts*\"", + "preview": "qwik build preview && vite preview --open", + "start": "vite --open --mode ssr", + "qwik": "qwik" + }, + "files": [ + "./dist/*", + "./lib/portal.http.cjs" + ], + "devDependencies": { + "@builder.io/qwik": "0.16.2", + "@builder.io/qwik-city": "0.0.128", + "@types/eslint": "8.4.10", + "@types/node": "^18.11.18", + "@types/node-fetch": "latest", + "@typescript-eslint/eslint-plugin": "5.48.0", + "@typescript-eslint/parser": "5.48.0", + "eslint": "8.31.0", + "eslint-plugin-qwik": "0.16.2", + "node-fetch": "3.3.0", + "prettier": "2.8.1", + "typescript": "4.9.4", + "undici": "5.14.0", + "vite": "4.0.3", + "vite-tsconfig-paths": "3.5.0" + }, + "dependencies": { + "kleur": "^4.1.5", + "polka": "^0.5.2", + "serve-static": "^1.13.1" + }, + "repository": { + "type": "git", + "url": "https://github.com/codigoencasa/bot-whatsapp/tree/main/packages/portal" + } +} diff --git a/packages/portal/portal.http.js b/packages/portal/portal.http.js new file mode 100644 index 0000000..62dc676 --- /dev/null +++ b/packages/portal/portal.http.js @@ -0,0 +1,56 @@ +const { join } = require('path') +const { createReadStream, existsSync } = require('fs') +const { bgYellow, cyan } = require('kleur') +const polka = require('polka') + +const HTTP_PORT = process.env.PORT || 3000 +const QR_FILE = process.env.QR_FILE ?? 'qr.png' +const PUBLIC_URL = + process.env.PUBLIC_URL ?? + process.env.RAILWAY_STATIC_URL ?? + 'http://localhost' + +const dir = [join(__dirname, 'dist'), join(__dirname, '..', 'dist')].find((i) => + existsSync(i) +) +const serve = require('serve-static')(dir) + +/** + * Iniciamos Portal WEB para escanear QR + * @param {port:3000, publicSite:'http://mistio.com', qrFile:'qr.png', dir:__dirname} + */ +const start = ( + { port, publicSite, qrFile } = { + port: HTTP_PORT, + publicSite: PUBLIC_URL, + qrFile: QR_FILE, + } +) => { + polka() + .use(serve) + .get(qrFile, (_, res) => { + const qrSource = [ + join(process.cwd(), qrFile), + join(__dirname, '..', qrFile), + join(__dirname, qrFile), + ].find((i) => existsSync(i)) + + const qrMark = [ + join(__dirname, 'dist', 'water-mark.png'), + join(__dirname, '..', 'dist', 'water-mark.png'), + ].find((i) => existsSync(i)) + const fileStream = createReadStream(qrSource ?? qrMark) + res.writeHead(200, { 'Content-Type': 'image/png' }) + fileStream.pipe(res) + }) + .listen(port, () => { + console.log(``) + console.log(bgYellow(`🚩 ESCANEAR QR 🚩`)) + console.log(cyan(`Existen varias maneras de escanear el QR code`)) + console.log(cyan(`- Se ha creado un archivo /qr.png`)) + console.log(cyan(`- Tambien puedes visitar ${publicSite}:${port}`)) + console.log(``) + }) +} + +module.exports = start diff --git a/packages/portal/public/favicon.svg b/packages/portal/public/favicon.svg new file mode 100644 index 0000000..0ded7c1 --- /dev/null +++ b/packages/portal/public/favicon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/portal/public/manifest.json b/packages/portal/public/manifest.json new file mode 100644 index 0000000..44825fa --- /dev/null +++ b/packages/portal/public/manifest.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/web-manifest-combined.json", + "name": "qwik-project-name", + "short_name": "Welcome to Qwik", + "start_url": ".", + "display": "standalone", + "background_color": "#fff", + "description": "A Qwik project app." +} diff --git a/packages/portal/public/robots.txt b/packages/portal/public/robots.txt new file mode 100644 index 0000000..e69de29 diff --git a/packages/portal/public/water-mark.png b/packages/portal/public/water-mark.png new file mode 100644 index 0000000..e44ada3 Binary files /dev/null and b/packages/portal/public/water-mark.png differ diff --git a/packages/portal/rollup-portal.config.js b/packages/portal/rollup-portal.config.js new file mode 100644 index 0000000..ee955ff --- /dev/null +++ b/packages/portal/rollup-portal.config.js @@ -0,0 +1,13 @@ +const banner = require('../../config/banner.rollup.json') +const { join } = require('path') +const commonjs = require('@rollup/plugin-commonjs') + +module.exports = { + input: join(__dirname, 'portal.http.js'), + output: { + banner: banner['banner.output'].join(''), + file: join(__dirname, 'lib', 'portal.http.cjs'), + format: 'cjs', + }, + plugins: [commonjs()], +} diff --git a/packages/portal/src/components/header/header.css b/packages/portal/src/components/header/header.css new file mode 100644 index 0000000..b88f3da --- /dev/null +++ b/packages/portal/src/components/header/header.css @@ -0,0 +1,36 @@ +header { + display: flex; + background: white; +} + +header .logo a { + display: inline-block; + padding: 10px 10px 7px 20px; + text-decoration: none; +} + +header ul { + margin: 0; + padding: 3px 10px 0 0; + list-style: none; + flex: 1; + text-align: right; +} + +header li { + display: inline-block; + margin: 0; + padding: 0; +} + +header li a { + display: inline-block; + padding: 15px 10px; + text-decoration: none; + color: #1a1a1a; + font-weight: 500; +} + +header li a:hover { + text-decoration: underline; +} diff --git a/packages/portal/src/components/header/header.tsx b/packages/portal/src/components/header/header.tsx new file mode 100644 index 0000000..f1c7fa7 --- /dev/null +++ b/packages/portal/src/components/header/header.tsx @@ -0,0 +1,47 @@ +import { component$, useStylesScoped$ } from '@builder.io/qwik' +import { BotLogo } from '../icons/bot' +import styles from './header.css?inline' + +export default component$(() => { + useStylesScoped$(styles) + + return ( +
+ + +
+ ) +}) diff --git a/packages/portal/src/components/icons/bot.css b/packages/portal/src/components/icons/bot.css new file mode 100644 index 0000000..481f167 --- /dev/null +++ b/packages/portal/src/components/icons/bot.css @@ -0,0 +1,12 @@ +.logo { + display: flex; + gap: 0.5rem; + align-items: center; + align-content: center; + color: #1a1a1a; +} + +.logo h1 { + font-size: 1.5rem; + margin: 0; +} diff --git a/packages/portal/src/components/icons/bot.tsx b/packages/portal/src/components/icons/bot.tsx new file mode 100644 index 0000000..3c69ef7 --- /dev/null +++ b/packages/portal/src/components/icons/bot.tsx @@ -0,0 +1,18 @@ +import { component$, useStylesScoped$ } from '@builder.io/qwik' + +import styles from './bot.css?inline' + +export const BotLogo = component$(() => { + useStylesScoped$(styles) + return ( +
+ +

Chatbot

+
+ ) +}) diff --git a/packages/portal/src/components/icons/qwik.tsx b/packages/portal/src/components/icons/qwik.tsx new file mode 100644 index 0000000..3bd8d91 --- /dev/null +++ b/packages/portal/src/components/icons/qwik.tsx @@ -0,0 +1,38 @@ +export const QwikLogo = () => ( + + + + + + + + + +) diff --git a/packages/portal/src/components/qr/qr.css b/packages/portal/src/components/qr/qr.css new file mode 100644 index 0000000..37d8779 --- /dev/null +++ b/packages/portal/src/components/qr/qr.css @@ -0,0 +1,12 @@ +div img { + display: block; + background-color: #f0f0f0; + width: 350px; + height: 350px; + object-fit: contain; + border-radius: 10px; +} +div { + display: flex; + justify-content: center; +} diff --git a/packages/portal/src/components/qr/qr.tsx b/packages/portal/src/components/qr/qr.tsx new file mode 100644 index 0000000..a0fb3d2 --- /dev/null +++ b/packages/portal/src/components/qr/qr.tsx @@ -0,0 +1,35 @@ +import { + component$, + useClientEffect$, + useStore, + useStylesScoped$, +} from '@builder.io/qwik' +import { useLocation } from '@builder.io/qwik-city' +import style from './qr.css?inline' + +export const QR = component$(() => { + useStylesScoped$(style) + const state = useStore({ + count: 0, + }) + + useClientEffect$(() => { + setInterval(() => { + state.count++ + }, 800) + }) + + const location = useLocation() + const qrImage = location.query?.qr ?? 'qr.png' + + return ( +
+ { + const head = useDocumentHead() + const loc = useLocation() + + return ( + <> + {head.title} + + + + + + {head.meta.map((m) => ( + + ))} + + {head.links.map((l) => ( + + ))} + + {head.styles.map((s) => ( +