@pasosdejesus/m 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blockchain/deployments.d.ts +40 -0
- package/dist/blockchain/deployments.d.ts.map +1 -0
- package/dist/blockchain/deployments.js +64 -0
- package/dist/debug/DebugConsole.d.ts +22 -0
- package/dist/debug/DebugConsole.d.ts.map +1 -0
- package/dist/debug/DebugConsole.js +79 -0
- package/dist/debug/Logger.d.ts +38 -0
- package/dist/debug/Logger.d.ts.map +1 -0
- package/dist/debug/Logger.js +94 -0
- package/dist/debug/index.d.ts +6 -0
- package/dist/debug/index.d.ts.map +1 -0
- package/dist/debug/index.js +4 -0
- package/dist/debug/useLogger.d.ts +14 -0
- package/dist/debug/useLogger.d.ts.map +1 -0
- package/dist/debug/useLogger.js +23 -0
- package/dist/debug/utils.d.ts +10 -0
- package/dist/debug/utils.d.ts.map +1 -0
- package/dist/debug/utils.js +53 -0
- package/dist/e2e/assertions.d.ts +5 -0
- package/dist/e2e/assertions.d.ts.map +1 -0
- package/dist/e2e/assertions.js +18 -0
- package/dist/e2e/browser.d.ts +37 -0
- package/dist/e2e/browser.d.ts.map +1 -0
- package/dist/e2e/browser.js +97 -0
- package/dist/e2e/env.d.ts +18 -0
- package/dist/e2e/env.d.ts.map +1 -0
- package/dist/e2e/env.js +57 -0
- package/dist/e2e/index.d.ts +11 -0
- package/dist/e2e/index.d.ts.map +1 -0
- package/dist/e2e/index.js +8 -0
- package/dist/e2e/navigation.d.ts +4 -0
- package/dist/e2e/navigation.d.ts.map +1 -0
- package/dist/e2e/navigation.js +32 -0
- package/dist/e2e/siwe-mock.d.ts +11 -0
- package/dist/e2e/siwe-mock.d.ts.map +1 -0
- package/dist/e2e/siwe-mock.js +112 -0
- package/dist/e2e/siwe.d.ts +15 -0
- package/dist/e2e/siwe.d.ts.map +1 -0
- package/dist/e2e/siwe.js +85 -0
- package/dist/e2e/wallet-mock.d.ts +13 -0
- package/dist/e2e/wallet-mock.d.ts.map +1 -0
- package/dist/e2e/wallet-mock.js +91 -0
- package/dist/i18n/common-cli.d.ts +11 -0
- package/dist/i18n/common-cli.d.ts.map +1 -0
- package/dist/i18n/common-cli.js +22 -0
- package/dist/i18n/createTranslator.d.ts +28 -0
- package/dist/i18n/createTranslator.d.ts.map +1 -0
- package/dist/i18n/createTranslator.js +48 -0
- package/dist/i18n/index.d.ts +4 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +2 -0
- package/dist/i18n/locales/cli.d.ts +3 -0
- package/dist/i18n/locales/cli.d.ts.map +1 -0
- package/dist/i18n/locales/cli.js +180 -0
- package/dist/i18n/types.d.ts +3 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/index.test.js +10 -0
- package/dist/m.d.ts +2 -0
- package/dist/m.d.ts.map +1 -0
- package/dist/m.js +334 -0
- package/dist/plugin.d.ts +10 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +7 -0
- package/dist/shadcn_components/cn.d.ts +13 -0
- package/dist/shadcn_components/cn.d.ts.map +1 -0
- package/dist/shadcn_components/cn.js +15 -0
- package/dist/shadcn_components/ui/accordion.d.ts +8 -0
- package/dist/shadcn_components/ui/accordion.d.ts.map +1 -0
- package/dist/shadcn_components/ui/accordion.js +14 -0
- package/dist/shadcn_components/ui/alert-dialog.d.ts +21 -0
- package/dist/shadcn_components/ui/alert-dialog.d.ts.map +1 -0
- package/dist/shadcn_components/ui/alert-dialog.js +27 -0
- package/dist/shadcn_components/ui/alert.d.ts +9 -0
- package/dist/shadcn_components/ui/alert.d.ts.map +1 -0
- package/dist/shadcn_components/ui/alert.js +22 -0
- package/dist/shadcn_components/ui/avatar.d.ts +7 -0
- package/dist/shadcn_components/ui/avatar.d.ts.map +1 -0
- package/dist/shadcn_components/ui/avatar.js +12 -0
- package/dist/shadcn_components/ui/badge.d.ts +10 -0
- package/dist/shadcn_components/ui/badge.d.ts.map +1 -0
- package/dist/shadcn_components/ui/badge.js +22 -0
- package/dist/shadcn_components/ui/button.d.ts +11 -0
- package/dist/shadcn_components/ui/button.d.ts.map +1 -0
- package/dist/shadcn_components/ui/button.js +31 -0
- package/dist/shadcn_components/ui/card.d.ts +10 -0
- package/dist/shadcn_components/ui/card.d.ts.map +1 -0
- package/dist/shadcn_components/ui/card.js +24 -0
- package/dist/shadcn_components/ui/checkbox.d.ts +5 -0
- package/dist/shadcn_components/ui/checkbox.d.ts.map +1 -0
- package/dist/shadcn_components/ui/checkbox.js +9 -0
- package/dist/shadcn_components/ui/dialog.d.ts +20 -0
- package/dist/shadcn_components/ui/dialog.d.ts.map +1 -0
- package/dist/shadcn_components/ui/dialog.js +23 -0
- package/dist/shadcn_components/ui/dropdown-menu.d.ts +28 -0
- package/dist/shadcn_components/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/shadcn_components/ui/dropdown-menu.js +36 -0
- package/dist/shadcn_components/ui/form.d.ts +24 -0
- package/dist/shadcn_components/ui/form.d.ts.map +1 -0
- package/dist/shadcn_components/ui/form.js +63 -0
- package/dist/shadcn_components/ui/input.d.ts +4 -0
- package/dist/shadcn_components/ui/input.d.ts.map +1 -0
- package/dist/shadcn_components/ui/input.js +6 -0
- package/dist/shadcn_components/ui/label.d.ts +6 -0
- package/dist/shadcn_components/ui/label.d.ts.map +1 -0
- package/dist/shadcn_components/ui/label.js +10 -0
- package/dist/shadcn_components/ui/menubar.d.ts +29 -0
- package/dist/shadcn_components/ui/menubar.d.ts.map +1 -0
- package/dist/shadcn_components/ui/menubar.js +46 -0
- package/dist/shadcn_components/ui/popover.d.ts +7 -0
- package/dist/shadcn_components/ui/popover.d.ts.map +1 -0
- package/dist/shadcn_components/ui/popover.js +10 -0
- package/dist/shadcn_components/ui/progress.d.ts +5 -0
- package/dist/shadcn_components/ui/progress.d.ts.map +1 -0
- package/dist/shadcn_components/ui/progress.js +8 -0
- package/dist/shadcn_components/ui/radio-group.d.ts +6 -0
- package/dist/shadcn_components/ui/radio-group.d.ts.map +1 -0
- package/dist/shadcn_components/ui/radio-group.js +15 -0
- package/dist/shadcn_components/ui/scroll-area.d.ts +6 -0
- package/dist/shadcn_components/ui/scroll-area.d.ts.map +1 -0
- package/dist/shadcn_components/ui/scroll-area.js +12 -0
- package/dist/shadcn_components/ui/select.d.ts +14 -0
- package/dist/shadcn_components/ui/select.d.ts.map +1 -0
- package/dist/shadcn_components/ui/select.js +27 -0
- package/dist/shadcn_components/ui/separator.d.ts +5 -0
- package/dist/shadcn_components/ui/separator.d.ts.map +1 -0
- package/dist/shadcn_components/ui/separator.js +8 -0
- package/dist/shadcn_components/ui/sheet.d.ts +26 -0
- package/dist/shadcn_components/ui/sheet.d.ts.map +1 -0
- package/dist/shadcn_components/ui/sheet.js +37 -0
- package/dist/shadcn_components/ui/skeleton.d.ts +3 -0
- package/dist/shadcn_components/ui/skeleton.d.ts.map +1 -0
- package/dist/shadcn_components/ui/skeleton.js +6 -0
- package/dist/shadcn_components/ui/slider.d.ts +5 -0
- package/dist/shadcn_components/ui/slider.d.ts.map +1 -0
- package/dist/shadcn_components/ui/slider.js +8 -0
- package/dist/shadcn_components/ui/switch.d.ts +5 -0
- package/dist/shadcn_components/ui/switch.d.ts.map +1 -0
- package/dist/shadcn_components/ui/switch.js +8 -0
- package/dist/shadcn_components/ui/table.d.ts +11 -0
- package/dist/shadcn_components/ui/table.d.ts.map +1 -0
- package/dist/shadcn_components/ui/table.js +20 -0
- package/dist/shadcn_components/ui/tabs.d.ts +8 -0
- package/dist/shadcn_components/ui/tabs.d.ts.map +1 -0
- package/dist/shadcn_components/ui/tabs.js +13 -0
- package/dist/shadcn_components/ui/textarea.d.ts +4 -0
- package/dist/shadcn_components/ui/textarea.d.ts.map +1 -0
- package/dist/shadcn_components/ui/textarea.js +8 -0
- package/dist/shadcn_components/ui/toast.d.ts +16 -0
- package/dist/shadcn_components/ui/toast.d.ts.map +1 -0
- package/dist/shadcn_components/ui/toast.js +34 -0
- package/dist/shadcn_components/ui/toaster.d.ts +2 -0
- package/dist/shadcn_components/ui/toaster.d.ts.map +1 -0
- package/dist/shadcn_components/ui/toaster.js +10 -0
- package/dist/shadcn_components/ui/tooltip.d.ts +8 -0
- package/dist/shadcn_components/ui/tooltip.d.ts.map +1 -0
- package/dist/shadcn_components/ui/tooltip.js +11 -0
- package/dist/shadcn_components/ui/use-toast.d.ts +45 -0
- package/dist/shadcn_components/ui/use-toast.d.ts.map +1 -0
- package/dist/shadcn_components/ui/use-toast.js +126 -0
- package/dist/tasks/context.d.ts +13 -0
- package/dist/tasks/context.d.ts.map +1 -0
- package/dist/tasks/context.js +310 -0
- package/dist/tasks/create.d.ts +2 -0
- package/dist/tasks/create.d.ts.map +1 -0
- package/dist/tasks/create.js +91 -0
- package/dist/tasks/db.d.ts +19 -0
- package/dist/tasks/db.d.ts.map +1 -0
- package/dist/tasks/db.js +791 -0
- package/dist/tasks/e2e.d.ts +2 -0
- package/dist/tasks/e2e.d.ts.map +1 -0
- package/dist/tasks/e2e.js +124 -0
- package/dist/tasks/edit.d.ts +7 -0
- package/dist/tasks/edit.d.ts.map +1 -0
- package/dist/tasks/edit.js +471 -0
- package/dist/tasks/engine.d.ts +2 -0
- package/dist/tasks/engine.d.ts.map +1 -0
- package/dist/tasks/engine.js +149 -0
- package/dist/tasks/env-diff.d.ts +2 -0
- package/dist/tasks/env-diff.d.ts.map +1 -0
- package/dist/tasks/env-diff.js +140 -0
- package/dist/tasks/fuzzy.d.ts +9 -0
- package/dist/tasks/fuzzy.d.ts.map +1 -0
- package/dist/tasks/fuzzy.js +153 -0
- package/dist/tasks/glob.d.ts +5 -0
- package/dist/tasks/glob.d.ts.map +1 -0
- package/dist/tasks/glob.js +57 -0
- package/dist/tasks/grep.d.ts +9 -0
- package/dist/tasks/grep.d.ts.map +1 -0
- package/dist/tasks/grep.js +93 -0
- package/dist/tasks/readfile.d.ts +2 -0
- package/dist/tasks/readfile.d.ts.map +1 -0
- package/dist/tasks/readfile.js +177 -0
- package/dist/tasks/update.d.ts +5 -0
- package/dist/tasks/update.d.ts.map +1 -0
- package/dist/tasks/update.js +200 -0
- package/dist/tasks/util.d.ts +12 -0
- package/dist/tasks/util.d.ts.map +1 -0
- package/dist/tasks/util.js +42 -0
- package/dist/tasks/wallet.d.ts +2 -0
- package/dist/tasks/wallet.d.ts.map +1 -0
- package/dist/tasks/wallet.js +697 -0
- package/dist/tasks/writefile.d.ts +2 -0
- package/dist/tasks/writefile.d.ts.map +1 -0
- package/dist/tasks/writefile.js +66 -0
- package/dist/templates/AGENTS.md.hbs +81 -0
- package/dist/templates/ARCHITECTURE.md.hbs +146 -0
- package/dist/templates/CONTRIBUTING.md.hbs +83 -0
- package/dist/templates/LICENCIA.md +21 -0
- package/dist/templates/LICENSE.md +15 -0
- package/dist/templates/Makefile +16 -0
- package/dist/templates/README.md.hbs +111 -0
- package/dist/templates/apps/.env.example.hbs +75 -0
- package/dist/templates/apps/hardhat/.prettierrc +16 -0
- package/dist/templates/apps/hardhat/MOCK_USDT_README.md +20 -0
- package/dist/templates/apps/hardhat/Makefile +13 -0
- package/dist/templates/apps/hardhat/README.md +129 -0
- package/dist/templates/apps/hardhat/bin/MusdtVerification +4 -0
- package/dist/templates/apps/hardhat/bin/approveDepositOwner +7 -0
- package/dist/templates/apps/hardhat/bin/contractVerification +9 -0
- package/dist/templates/apps/hardhat/bin/deployMockUSDT +7 -0
- package/dist/templates/apps/hardhat/bin/prepadJ.sh +14 -0
- package/dist/templates/apps/hardhat/bin/verifyMockUSDT +7 -0
- package/dist/templates/apps/hardhat/contracts/MockUSDT.sol +47 -0
- package/dist/templates/apps/hardhat/hardhat.config.ts +102 -0
- package/dist/templates/apps/hardhat/package.json +55 -0
- package/dist/templates/apps/hardhat/scripts/approveDepositOwner.ts +22 -0
- package/dist/templates/apps/hardhat/scripts/deployMockUSDT.ts +49 -0
- package/dist/templates/apps/hardhat/scripts/verifyDeployment.ts +93 -0
- package/dist/templates/apps/hardhat/scripts/verifyMockUSDT.ts +52 -0
- package/dist/templates/apps/hardhat/sync-abis.mjs +58 -0
- package/dist/templates/apps/hardhat/test/MockUSDT.test.ts +40 -0
- package/dist/templates/apps/hardhat/tsconfig.json +27 -0
- package/dist/templates/apps/nextjs/.config/kysely.config.ts +36 -0
- package/dist/templates/apps/nextjs/Makefile +24 -0
- package/dist/templates/apps/nextjs/README.md.hbs +76 -0
- package/dist/templates/apps/nextjs/abis/IERC20.json +74 -0
- package/dist/templates/apps/nextjs/abis/MockUSDT.json +242 -0
- package/dist/templates/apps/nextjs/abis/ReentrancyGuard.json +1 -0
- package/dist/templates/apps/nextjs/app/globals.css +3 -0
- package/dist/templates/apps/nextjs/app/layout.tsx.hbs +26 -0
- package/dist/templates/apps/nextjs/app/page.tsx.hbs +225 -0
- package/dist/templates/apps/nextjs/app/testui/page.tsx +371 -0
- package/dist/templates/apps/nextjs/bin/m +8 -0
- package/dist/templates/apps/nextjs/components.json +21 -0
- package/dist/templates/apps/nextjs/next-env.d.ts +5 -0
- package/dist/templates/apps/nextjs/next.config.ts +10 -0
- package/dist/templates/apps/nextjs/package.json.hbs +48 -0
- package/dist/templates/apps/nextjs/pnpm-workspace.yaml +13 -0
- package/dist/templates/apps/nextjs/postcss.config.mjs +6 -0
- package/dist/templates/apps/nextjs/tailwind.config.js +11 -0
- package/dist/templates/apps/nextjs/tests/helpers.ts +31 -0
- package/dist/templates/apps/nextjs/tests/index.test.ts +7 -0
- package/dist/templates/apps/nextjs/tests/setup-env.ts.hbs +8 -0
- package/dist/templates/apps/nextjs/tests/test-utils.example.test.ts +168 -0
- package/dist/templates/apps/nextjs/tsconfig.json +44 -0
- package/dist/templates/apps/nextjs/tsconfig.test.json +38 -0
- package/dist/templates/apps/nextjs/vitest.config.ts +13 -0
- package/dist/test-utils/fs-mocks.d.ts +32 -0
- package/dist/test-utils/fs-mocks.d.ts.map +1 -0
- package/dist/test-utils/fs-mocks.js +63 -0
- package/dist/test-utils/i18n-mock.d.ts +21 -0
- package/dist/test-utils/i18n-mock.d.ts.map +1 -0
- package/dist/test-utils/i18n-mock.js +29 -0
- package/dist/test-utils/index.d.ts +12 -0
- package/dist/test-utils/index.d.ts.map +1 -0
- package/dist/test-utils/index.js +11 -0
- package/dist/test-utils/kysely-mocks.d.ts +298 -0
- package/dist/test-utils/kysely-mocks.d.ts.map +1 -0
- package/dist/test-utils/kysely-mocks.js +173 -0
- package/dist/test-utils/radix-mocks.d.ts +134 -0
- package/dist/test-utils/radix-mocks.d.ts.map +1 -0
- package/dist/test-utils/radix-mocks.js +175 -0
- package/dist/test-utils/rainbowkit-mocks.d.ts +80 -0
- package/dist/test-utils/rainbowkit-mocks.d.ts.map +1 -0
- package/dist/test-utils/rainbowkit-mocks.js +247 -0
- package/dist/test-utils/viem-mocks.d.ts +86 -0
- package/dist/test-utils/viem-mocks.d.ts.map +1 -0
- package/dist/test-utils/viem-mocks.js +54 -0
- package/dist/util/cli-parser.d.ts +20 -0
- package/dist/util/cli-parser.d.ts.map +1 -0
- package/dist/util/cli-parser.js +38 -0
- package/dist/util/colors.d.ts +5 -0
- package/dist/util/colors.d.ts.map +1 -0
- package/dist/util/colors.js +5 -0
- package/dist/util/locale.d.ts +3 -0
- package/dist/util/locale.d.ts.map +1 -0
- package/dist/util/locale.js +10 -0
- package/dist/wba/client.d.ts +19 -0
- package/dist/wba/client.d.ts.map +1 -0
- package/dist/wba/client.js +31 -0
- package/dist/wba/index.d.ts +4 -0
- package/dist/wba/index.d.ts.map +1 -0
- package/dist/wba/index.js +2 -0
- package/dist/wba/routes/event.d.ts +32 -0
- package/dist/wba/routes/event.d.ts.map +1 -0
- package/dist/wba/routes/event.js +42 -0
- package/dist/wba/routes/index.d.ts +3 -0
- package/dist/wba/routes/index.d.ts.map +1 -0
- package/dist/wba/routes/index.js +2 -0
- package/dist/wba/routes/summary.d.ts +44 -0
- package/dist/wba/routes/summary.d.ts.map +1 -0
- package/dist/wba/routes/summary.js +146 -0
- package/dist/wba/server.d.ts +18 -0
- package/dist/wba/server.d.ts.map +1 -0
- package/dist/wba/server.js +29 -0
- package/dist/wba/types.d.ts +68 -0
- package/dist/wba/types.d.ts.map +1 -0
- package/dist/wba/types.js +6 -0
- package/package.json +223 -0
- package/src/blockchain/README.md +80 -0
- package/src/debug/README.md +94 -0
- package/src/e2e/README.md +105 -0
- package/src/i18n/README.md +143 -0
- package/src/shadcn_components/README.md +125 -0
- package/src/tasks/README.md +69 -0
- package/src/test-utils/README.md +638 -0
- package/src/util/README.md +18 -0
- package/src/wba/README.md +175 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// src/tasks/engine.ts
|
|
2
|
+
// Engine management: setup, list, check for shared modules (WBA, credentials, etc.)
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { success, info, problem } from '../util/colors.js';
|
|
6
|
+
import { createTranslator } from '../i18n/createTranslator.js';
|
|
7
|
+
import { detectLocale } from '../util/locale.js';
|
|
8
|
+
import commonCli from '../i18n/common-cli.js';
|
|
9
|
+
const t = createTranslator(detectLocale(), {
|
|
10
|
+
en: {
|
|
11
|
+
'engine.unknown': 'Unknown engine command: {{0}}. Use: wba:setup, credentials:setup, list, check',
|
|
12
|
+
},
|
|
13
|
+
es: {
|
|
14
|
+
'engine.unknown': 'Comando de motor desconocido: {{0}}. Use: wba:setup, credentials:setup, list, check',
|
|
15
|
+
},
|
|
16
|
+
}, commonCli);
|
|
17
|
+
function getArg(args, name) {
|
|
18
|
+
const idx = args.indexOf(name);
|
|
19
|
+
return idx >= 0 && idx + 1 < args.length ? args[idx + 1] : null;
|
|
20
|
+
}
|
|
21
|
+
function nextMigrationNumber(dir) {
|
|
22
|
+
if (!fs.existsSync(dir))
|
|
23
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
24
|
+
const files = fs.readdirSync(dir).filter(f => f.endsWith('.sql'));
|
|
25
|
+
const timestamp = new Date().toISOString().replace(/[-:T]/g, '').slice(0, 14);
|
|
26
|
+
return `${timestamp}${String(files.length + 1).padStart(3, '0')}`;
|
|
27
|
+
}
|
|
28
|
+
async function cmdWbaSetup() {
|
|
29
|
+
const migrateDir = path.join(process.cwd(), 'db', 'migrate');
|
|
30
|
+
const num = nextMigrationNumber(migrateDir);
|
|
31
|
+
const webEventPath = path.join(migrateDir, `${num}_create_web_event.sql`);
|
|
32
|
+
fs.writeFileSync(webEventPath, `-- Migration: create web_event table for WBA analytics
|
|
33
|
+
CREATE TABLE IF NOT EXISTS web_event (
|
|
34
|
+
id SERIAL PRIMARY KEY,
|
|
35
|
+
session_id VARCHAR(64),
|
|
36
|
+
event_type VARCHAR(40) NOT NULL,
|
|
37
|
+
pathname VARCHAR(200),
|
|
38
|
+
locale VARCHAR(5),
|
|
39
|
+
referrer VARCHAR(500),
|
|
40
|
+
user_agent VARCHAR(500),
|
|
41
|
+
ip VARCHAR(45),
|
|
42
|
+
wallet VARCHAR(42),
|
|
43
|
+
metadata JSONB,
|
|
44
|
+
created_at TIMESTAMP DEFAULT NOW()
|
|
45
|
+
);
|
|
46
|
+
`);
|
|
47
|
+
const num2 = nextMigrationNumber(migrateDir);
|
|
48
|
+
const txPath = path.join(migrateDir, `${num2}_create_transaction.sql`);
|
|
49
|
+
fs.writeFileSync(txPath, `-- Migration: create transaction table for WBA analytics
|
|
50
|
+
-- Required columns: crypto, amount, wallet
|
|
51
|
+
-- Run: bin/m db:migrate
|
|
52
|
+
CREATE TABLE IF NOT EXISTS transaction (
|
|
53
|
+
id SERIAL PRIMARY KEY,
|
|
54
|
+
crypto VARCHAR(10) NOT NULL,
|
|
55
|
+
amount NUMERIC NOT NULL,
|
|
56
|
+
wallet VARCHAR(42) NOT NULL,
|
|
57
|
+
created_at TIMESTAMP DEFAULT NOW()
|
|
58
|
+
);
|
|
59
|
+
`);
|
|
60
|
+
success(`✅ WBA migrations created:`);
|
|
61
|
+
console.log(` ${webEventPath}`);
|
|
62
|
+
console.log(` ${txPath}`);
|
|
63
|
+
console.log(` Run: bin/m db:migrate`);
|
|
64
|
+
}
|
|
65
|
+
async function cmdCredentialsSetup() {
|
|
66
|
+
const migrateDir = path.join(process.cwd(), 'db', 'migrate');
|
|
67
|
+
const num = nextMigrationNumber(migrateDir);
|
|
68
|
+
const metaPath = path.join(migrateDir, `${num}_create_credential_metadata.sql`);
|
|
69
|
+
fs.writeFileSync(metaPath, `-- Migration: create credential_metadata cache table
|
|
70
|
+
CREATE TABLE IF NOT EXISTS credential_metadata (
|
|
71
|
+
token_id INTEGER NOT NULL,
|
|
72
|
+
chain_id VARCHAR(20) NOT NULL DEFAULT 'celo',
|
|
73
|
+
name VARCHAR(255) NOT NULL,
|
|
74
|
+
type VARCHAR(50) NOT NULL,
|
|
75
|
+
site VARCHAR(50) NOT NULL,
|
|
76
|
+
is_premium BOOLEAN DEFAULT false,
|
|
77
|
+
is_soulbound BOOLEAN DEFAULT true,
|
|
78
|
+
image_url TEXT NOT NULL,
|
|
79
|
+
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
|
80
|
+
PRIMARY KEY (token_id, chain_id)
|
|
81
|
+
);
|
|
82
|
+
`);
|
|
83
|
+
const num2 = nextMigrationNumber(migrateDir);
|
|
84
|
+
const emissionPath = path.join(migrateDir, `${num2}_create_credential_emission.sql`);
|
|
85
|
+
fs.writeFileSync(emissionPath, `-- Migration: create credential_emission tracking table
|
|
86
|
+
-- Adjust wallet_address or usuario_id per project needs
|
|
87
|
+
CREATE TABLE IF NOT EXISTS credential_emission (
|
|
88
|
+
id BIGSERIAL PRIMARY KEY,
|
|
89
|
+
wallet_address VARCHAR(42) NOT NULL,
|
|
90
|
+
token_id INTEGER NOT NULL,
|
|
91
|
+
chain_id VARCHAR(20) NOT NULL DEFAULT 'celo',
|
|
92
|
+
emitted_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
|
93
|
+
UNIQUE(wallet_address, token_id, chain_id)
|
|
94
|
+
);
|
|
95
|
+
`);
|
|
96
|
+
success(`✅ Credential migrations created:`);
|
|
97
|
+
console.log(` ${metaPath}`);
|
|
98
|
+
console.log(` ${emissionPath}`);
|
|
99
|
+
console.log(` Run: bin/m db:migrate`);
|
|
100
|
+
}
|
|
101
|
+
async function cmdList() {
|
|
102
|
+
console.log('Available engines:');
|
|
103
|
+
console.log(' wba — Web analytics (web_event + transaction)');
|
|
104
|
+
console.log(' credentials — Blockchain credentials (credential_metadata + credential_emission)');
|
|
105
|
+
console.log();
|
|
106
|
+
console.log('Install: bin/m eng:<name>:setup');
|
|
107
|
+
console.log('Verify: bin/m eng:check');
|
|
108
|
+
}
|
|
109
|
+
async function cmdCheck() {
|
|
110
|
+
info('Verifying engine schemas...');
|
|
111
|
+
const { runDbCheck } = await import('./db.js');
|
|
112
|
+
await runDbCheck();
|
|
113
|
+
}
|
|
114
|
+
export async function runEngine(args) {
|
|
115
|
+
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
|
|
116
|
+
console.log('Engine commands:');
|
|
117
|
+
console.log(' eng:wba:setup — Create WBA migration files');
|
|
118
|
+
console.log(' eng:credentials:setup — Create credential migration files');
|
|
119
|
+
console.log(' eng:list — List available engines');
|
|
120
|
+
console.log(' eng:check — Verify engine schemas');
|
|
121
|
+
}
|
|
122
|
+
const command = args[0];
|
|
123
|
+
const rest = args.slice(1);
|
|
124
|
+
try {
|
|
125
|
+
if (command === 'wba' && rest[0] === 'setup') {
|
|
126
|
+
await cmdWbaSetup();
|
|
127
|
+
}
|
|
128
|
+
else if (command === 'credentials' && rest[0] === 'setup') {
|
|
129
|
+
await cmdCredentialsSetup();
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
switch (command) {
|
|
133
|
+
case 'list':
|
|
134
|
+
await cmdList();
|
|
135
|
+
break;
|
|
136
|
+
case 'check':
|
|
137
|
+
await cmdCheck();
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
problem(t('engine.unknown', command));
|
|
141
|
+
throw new Error(t('engine.unknown', command));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
problem(err.message || String(err));
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-diff.d.ts","sourceRoot":"","sources":["../../src/tasks/env-diff.ts"],"names":[],"mappings":"AA0DA,wBAAsB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,iBA2FtE"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* env:diff — Compares two .env files.
|
|
3
|
+
*
|
|
4
|
+
* Without arguments: compares ../.env.example against ../.env.
|
|
5
|
+
* With arguments: env:diff <base> <target>
|
|
6
|
+
*
|
|
7
|
+
* Reports four categories:
|
|
8
|
+
* 1. Variables only in base (missing in target) — most prominent
|
|
9
|
+
* 2. Variables only in target (not in base)
|
|
10
|
+
* 3. Variables with different values — horizontal list
|
|
11
|
+
* 4. Variables with equal values — horizontal list
|
|
12
|
+
*/
|
|
13
|
+
import * as fs from 'fs';
|
|
14
|
+
import * as path from 'path';
|
|
15
|
+
import { problem, success, info, warn } from '../util/colors.js';
|
|
16
|
+
function parseEnvFile(filePath) {
|
|
17
|
+
try {
|
|
18
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
19
|
+
const vars = {};
|
|
20
|
+
for (const line of content.split('\n')) {
|
|
21
|
+
const trimmed = line.trim();
|
|
22
|
+
if (!trimmed || trimmed.startsWith('#'))
|
|
23
|
+
continue;
|
|
24
|
+
const eqIdx = trimmed.indexOf('=');
|
|
25
|
+
if (eqIdx === -1)
|
|
26
|
+
continue;
|
|
27
|
+
const key = trimmed.substring(0, eqIdx).trim();
|
|
28
|
+
const value = trimmed.substring(eqIdx + 1);
|
|
29
|
+
if (key)
|
|
30
|
+
vars[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return vars;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function formatHorizontalList(items, maxWidth = 78) {
|
|
39
|
+
if (items.length === 0)
|
|
40
|
+
return '';
|
|
41
|
+
let line = '';
|
|
42
|
+
const lines = [];
|
|
43
|
+
for (let i = 0; i < items.length; i++) {
|
|
44
|
+
const sep = i < items.length - 1 ? ', ' : '';
|
|
45
|
+
const candidate = line + items[i] + sep;
|
|
46
|
+
if (candidate.length > maxWidth && line.length > 0) {
|
|
47
|
+
lines.push(line.trimEnd());
|
|
48
|
+
line = ' ' + items[i] + sep;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
line = candidate;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (line.trim())
|
|
55
|
+
lines.push(line.trimEnd());
|
|
56
|
+
return lines.join('\n');
|
|
57
|
+
}
|
|
58
|
+
export async function runEnvDiff(baseFile, targetFile) {
|
|
59
|
+
if (baseFile === '--help' || baseFile === '-h'
|
|
60
|
+
|| targetFile === '--help' || targetFile === '-h') {
|
|
61
|
+
info('Uso: m env:diff [base] [target]');
|
|
62
|
+
info(' Sin argumentos: compara ../.env.example vs ../.env');
|
|
63
|
+
info(' Con 1 argumento: compara ../.env.example vs el archivo dado');
|
|
64
|
+
info(' Con 2 argumentos: compara base vs target');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!baseFile && !targetFile) {
|
|
68
|
+
baseFile = path.join(process.cwd(), '..', '.env.example');
|
|
69
|
+
targetFile = path.join(process.cwd(), '..', '.env');
|
|
70
|
+
}
|
|
71
|
+
else if (baseFile && !targetFile) {
|
|
72
|
+
targetFile = baseFile;
|
|
73
|
+
baseFile = path.join(process.cwd(), '..', '.env.example');
|
|
74
|
+
}
|
|
75
|
+
const baseVars = parseEnvFile(baseFile);
|
|
76
|
+
const targetVars = parseEnvFile(targetFile);
|
|
77
|
+
if (baseVars === null) {
|
|
78
|
+
problem(`No se pudo leer: ${baseFile}`);
|
|
79
|
+
process.exit(2);
|
|
80
|
+
}
|
|
81
|
+
if (targetVars === null) {
|
|
82
|
+
problem(`No se pudo leer: ${targetFile}`);
|
|
83
|
+
process.exit(2);
|
|
84
|
+
}
|
|
85
|
+
const baseKeys = new Set(Object.keys(baseVars));
|
|
86
|
+
const targetKeys = new Set(Object.keys(targetVars));
|
|
87
|
+
const onlyBase = [...baseKeys].filter(k => !targetKeys.has(k)).sort();
|
|
88
|
+
const onlyTarget = [...targetKeys].filter(k => !baseKeys.has(k)).sort();
|
|
89
|
+
const common = [...baseKeys].filter(k => targetKeys.has(k)).sort();
|
|
90
|
+
const different = [];
|
|
91
|
+
const equal = [];
|
|
92
|
+
for (const key of common) {
|
|
93
|
+
if (baseVars[key] === targetVars[key]) {
|
|
94
|
+
equal.push(key);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
different.push(key);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
console.log();
|
|
101
|
+
info(` Base: ${baseFile} (${baseKeys.size} variables)`);
|
|
102
|
+
info(` Target: ${targetFile} (${targetKeys.size} variables)`);
|
|
103
|
+
console.log();
|
|
104
|
+
let hasDiff = false;
|
|
105
|
+
if (onlyBase.length > 0) {
|
|
106
|
+
hasDiff = true;
|
|
107
|
+
warn('⚠ Solo en .env.example (faltan en .env):');
|
|
108
|
+
for (const k of onlyBase)
|
|
109
|
+
console.log(` ${k}`);
|
|
110
|
+
console.log();
|
|
111
|
+
}
|
|
112
|
+
if (onlyTarget.length > 0) {
|
|
113
|
+
hasDiff = true;
|
|
114
|
+
warn('⚠ Solo en .env (no están en .env.example):');
|
|
115
|
+
for (const k of onlyTarget)
|
|
116
|
+
console.log(` ${k}`);
|
|
117
|
+
console.log();
|
|
118
|
+
}
|
|
119
|
+
if (different.length > 0) {
|
|
120
|
+
hasDiff = true;
|
|
121
|
+
warn('≠ Diferentes:');
|
|
122
|
+
console.log(formatHorizontalList(different));
|
|
123
|
+
console.log();
|
|
124
|
+
}
|
|
125
|
+
if (!hasDiff) {
|
|
126
|
+
success('✓ .env.example y .env son idénticos.');
|
|
127
|
+
process.exit(0);
|
|
128
|
+
}
|
|
129
|
+
if (equal.length > 0) {
|
|
130
|
+
if (equal.length > 10) {
|
|
131
|
+
success(`= Iguales: ${equal.length} variables`);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
success('= Iguales:');
|
|
135
|
+
console.log(formatHorizontalList(equal));
|
|
136
|
+
}
|
|
137
|
+
console.log();
|
|
138
|
+
}
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function similarity(a: string, b: string, maxDistance?: number): number;
|
|
2
|
+
export declare function findBestMatch(search: string, content: string, threshold?: number, fileExt?: string): {
|
|
3
|
+
found: boolean;
|
|
4
|
+
text: string;
|
|
5
|
+
similarity: number;
|
|
6
|
+
startIndex: number;
|
|
7
|
+
endIndex: number;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=fuzzy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fuzzy.d.ts","sourceRoot":"","sources":["../../src/tasks/fuzzy.ts"],"names":[],"mappings":"AA2GA,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAM7E;AAGD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAa,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG;IAC1G,KAAK,EAAE,OAAO,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAmEA"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Funciones de fuzzy matching optimizadas para ai:edit
|
|
2
|
+
// Reglas de normalización por extensión de archivo
|
|
3
|
+
const rulesByExtension = {
|
|
4
|
+
// Lenguajes donde es SEGURO normalizar comillas
|
|
5
|
+
'js': { normalizeWhitespace: true, normalizePunctuationSpacing: true, normalizeQuotes: true, normalizeQuoteType: 'unify' },
|
|
6
|
+
'ts': { normalizeWhitespace: true, normalizePunctuationSpacing: true, normalizeQuotes: true, normalizeQuoteType: 'unify' },
|
|
7
|
+
'jsx': { normalizeWhitespace: true, normalizePunctuationSpacing: true, normalizeQuotes: true, normalizeQuoteType: 'unify' },
|
|
8
|
+
'tsx': { normalizeWhitespace: true, normalizePunctuationSpacing: true, normalizeQuotes: true, normalizeQuoteType: 'unify' },
|
|
9
|
+
// Archivos de texto plano
|
|
10
|
+
'md': { normalizeWhitespace: true, normalizePunctuationSpacing: true, normalizeQuotes: true, normalizeQuoteType: 'unify' },
|
|
11
|
+
'txt': { normalizeWhitespace: true, normalizePunctuationSpacing: true, normalizeQuotes: true, normalizeQuoteType: 'unify' },
|
|
12
|
+
// Por defecto: NO normalizar nada (seguro)
|
|
13
|
+
'default': { normalizeWhitespace: false, normalizePunctuationSpacing: false, normalizeQuotes: false, normalizeQuoteType: 'preserve' }
|
|
14
|
+
};
|
|
15
|
+
function getNormalizationRules(fileExt) {
|
|
16
|
+
if (!fileExt)
|
|
17
|
+
return rulesByExtension.default;
|
|
18
|
+
return rulesByExtension[fileExt] || rulesByExtension.default;
|
|
19
|
+
}
|
|
20
|
+
// Normalizar texto para comparación rápida (fingerprint)
|
|
21
|
+
function quickFingerprint(str) {
|
|
22
|
+
return str
|
|
23
|
+
.replace(/\s+/g, ' ') // espacios múltiples → uno
|
|
24
|
+
.replace(/\t/g, ' ') // tabs → espacios
|
|
25
|
+
.replace(/[“”]/g, '"') // comillas curvas → rectas
|
|
26
|
+
.replace(/[‘’]/g, "'") // comillas simples curvas → rectas
|
|
27
|
+
.slice(0, 200); // solo primeros 200 caracteres para fingerprint
|
|
28
|
+
}
|
|
29
|
+
// Normalización completa para fuzzy matching (configurable por tipo de archivo)
|
|
30
|
+
function normalizeForFuzzy(str, rules) {
|
|
31
|
+
let result = str;
|
|
32
|
+
if (rules.normalizeWhitespace) {
|
|
33
|
+
result = result
|
|
34
|
+
.replace(/\s+/g, ' ')
|
|
35
|
+
.replace(/\t/g, ' ');
|
|
36
|
+
}
|
|
37
|
+
if (rules.normalizeQuotes) {
|
|
38
|
+
result = result
|
|
39
|
+
.replace(/[“”]/g, '"')
|
|
40
|
+
.replace(/[‘’]/g, "'");
|
|
41
|
+
if (rules.normalizeQuoteType === 'unify') {
|
|
42
|
+
result = result.replace(/['"]/g, '"');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// Solo normalizar comillas curvas a rectas, pero mantener diferencia
|
|
47
|
+
result = result
|
|
48
|
+
.replace(/[“”]/g, '"')
|
|
49
|
+
.replace(/[‘’]/g, "'");
|
|
50
|
+
}
|
|
51
|
+
if (rules.normalizePunctuationSpacing) {
|
|
52
|
+
result = result.replace(/\s*([;:,.!?])\s*/g, '$1');
|
|
53
|
+
}
|
|
54
|
+
return result.trim();
|
|
55
|
+
}
|
|
56
|
+
// Distancia de Levenshtein optimizada (solo calcular si es necesario)
|
|
57
|
+
function levenshtein(a, b, maxDistance) {
|
|
58
|
+
// Si se especifica distancia máxima, podemos abortar temprano
|
|
59
|
+
const m = a.length;
|
|
60
|
+
const n = b.length;
|
|
61
|
+
if (Math.abs(m - n) > (maxDistance || 100)) {
|
|
62
|
+
return (maxDistance || 100) + 1;
|
|
63
|
+
}
|
|
64
|
+
let prev = new Array(n + 1).fill(0);
|
|
65
|
+
let curr = new Array(n + 1).fill(0);
|
|
66
|
+
for (let j = 0; j <= n; j++)
|
|
67
|
+
prev[j] = j;
|
|
68
|
+
for (let i = 1; i <= m; i++) {
|
|
69
|
+
curr[0] = i;
|
|
70
|
+
const minPossible = Math.min(...prev);
|
|
71
|
+
if (maxDistance !== undefined && minPossible > maxDistance) {
|
|
72
|
+
return maxDistance + 1;
|
|
73
|
+
}
|
|
74
|
+
for (let j = 1; j <= n; j++) {
|
|
75
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
76
|
+
curr[j] = Math.min(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + cost);
|
|
77
|
+
}
|
|
78
|
+
;
|
|
79
|
+
[prev, curr] = [curr, prev];
|
|
80
|
+
}
|
|
81
|
+
return prev[n];
|
|
82
|
+
}
|
|
83
|
+
// Calcular similitud (0 a 1) con límite de tiempo
|
|
84
|
+
export function similarity(a, b, maxDistance) {
|
|
85
|
+
if (a.length === 0 && b.length === 0)
|
|
86
|
+
return 1;
|
|
87
|
+
const maxLen = Math.max(a.length, b.length);
|
|
88
|
+
const distance = levenshtein(a, b, maxDistance);
|
|
89
|
+
if (maxDistance !== undefined && distance > maxDistance)
|
|
90
|
+
return 0;
|
|
91
|
+
return 1 - distance / maxLen;
|
|
92
|
+
}
|
|
93
|
+
// Buscar la mejor coincidencia en el contenido (optimizado)
|
|
94
|
+
export function findBestMatch(search, content, threshold = 0.85, fileExt) {
|
|
95
|
+
// 1. Exact match (rápido)
|
|
96
|
+
const exactIndex = content.indexOf(search);
|
|
97
|
+
if (exactIndex !== -1) {
|
|
98
|
+
return {
|
|
99
|
+
found: true,
|
|
100
|
+
text: search,
|
|
101
|
+
similarity: 1,
|
|
102
|
+
startIndex: exactIndex,
|
|
103
|
+
endIndex: exactIndex + search.length
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// Obtener reglas según extensión
|
|
107
|
+
const rules = getNormalizationRules(fileExt);
|
|
108
|
+
// 2. Normalized exact match (ignorar diferencias de formato)
|
|
109
|
+
const normalizedSearch = normalizeForFuzzy(search, rules);
|
|
110
|
+
const normalizedContent = normalizeForFuzzy(content, rules);
|
|
111
|
+
const normalizedIndex = normalizedContent.indexOf(normalizedSearch);
|
|
112
|
+
if (normalizedIndex !== -1) {
|
|
113
|
+
// Encontrar la posición original en content que corresponde a normalizedIndex
|
|
114
|
+
let originalStart = 0;
|
|
115
|
+
let normalizedPos = 0;
|
|
116
|
+
// Avanzar hasta la posición normalizada
|
|
117
|
+
for (let i = 0; i < content.length && normalizedPos < normalizedIndex; i++) {
|
|
118
|
+
const chunk = content[i];
|
|
119
|
+
const normalizedChunk = normalizeForFuzzy(chunk, rules);
|
|
120
|
+
if (normalizedChunk.length > 0) {
|
|
121
|
+
normalizedPos += normalizedChunk.length;
|
|
122
|
+
}
|
|
123
|
+
originalStart = i + 1;
|
|
124
|
+
}
|
|
125
|
+
// Extraer la subcadena original que coincide
|
|
126
|
+
let originalEnd = originalStart;
|
|
127
|
+
let matchedNormalized = '';
|
|
128
|
+
for (let i = originalStart; i < content.length && matchedNormalized.length < normalizedSearch.length; i++) {
|
|
129
|
+
const chunk = content[i];
|
|
130
|
+
const normalizedChunk = normalizeForFuzzy(chunk, rules);
|
|
131
|
+
if (normalizedChunk.length > 0) {
|
|
132
|
+
matchedNormalized += normalizedChunk;
|
|
133
|
+
}
|
|
134
|
+
originalEnd = i + 1;
|
|
135
|
+
}
|
|
136
|
+
const originalText = content.substring(originalStart, originalEnd);
|
|
137
|
+
return {
|
|
138
|
+
found: true,
|
|
139
|
+
text: originalText,
|
|
140
|
+
similarity: 0.95,
|
|
141
|
+
startIndex: originalStart,
|
|
142
|
+
endIndex: originalEnd
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
// 3. Si no, no hay match (por ahora, para no complicar)
|
|
146
|
+
return {
|
|
147
|
+
found: false,
|
|
148
|
+
text: '',
|
|
149
|
+
similarity: 0,
|
|
150
|
+
startIndex: -1,
|
|
151
|
+
endIndex: -1
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../src/tasks/glob.ts"],"names":[],"mappings":"AAqBA,wBAAsB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,iBAyChG"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { glob } from 'glob';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { info, success, problem } from '../util/colors.js';
|
|
4
|
+
import { setClipboard } from './edit.js';
|
|
5
|
+
import { createTranslator } from '../i18n/createTranslator.js';
|
|
6
|
+
import { detectLocale } from '../util/locale.js';
|
|
7
|
+
import commonCli from '../i18n/common-cli.js';
|
|
8
|
+
const t = createTranslator(detectLocale(), {
|
|
9
|
+
en: {
|
|
10
|
+
'glob.no_files': 'No files found. Diagnostic copied to clipboard.',
|
|
11
|
+
'glob.done': '✅ Search completed ({{0}}KB copied to clipboard)',
|
|
12
|
+
'glob.error': '❌ Error: {{0}}. Diagnostic copied to clipboard.',
|
|
13
|
+
},
|
|
14
|
+
es: {
|
|
15
|
+
'glob.no_files': 'No se encontraron archivos. Diagnóstico copiado al portapapeles.',
|
|
16
|
+
'glob.done': '✅ Búsqueda completada ({{0}}KB copiados al portapapeles)',
|
|
17
|
+
'glob.error': '❌ Error: {{0}}. Diagnóstico copiado al portapapeles.',
|
|
18
|
+
},
|
|
19
|
+
}, commonCli);
|
|
20
|
+
export async function runAiGlob(pattern, options = {}) {
|
|
21
|
+
const searchPath = options.path ? resolve(process.cwd(), options.path) : process.cwd();
|
|
22
|
+
const ignore = options.ignore || ['node_modules/**', 'dist/**', '.git/**'];
|
|
23
|
+
try {
|
|
24
|
+
const files = await glob(pattern, { cwd: searchPath, ignore, absolute: false });
|
|
25
|
+
if (files.length === 0) {
|
|
26
|
+
const diagnostic = `🔍 No se encontraron archivos para el patrón: "${pattern}"
|
|
27
|
+
|
|
28
|
+
Ruta buscada: ${searchPath}
|
|
29
|
+
Ignorados: ${ignore.join(', ')}
|
|
30
|
+
|
|
31
|
+
Sugerencias:
|
|
32
|
+
1. Verifica que el patrón sea correcto (ej: "*.ts", "src/**/*.tsx").
|
|
33
|
+
2. Usa --path para especificar una ruta diferente.
|
|
34
|
+
3. Usa --ignore para excluir patrones adicionales.
|
|
35
|
+
4. Ejecuta: ls -la ${searchPath} para confirmar que hay archivos.`;
|
|
36
|
+
await setClipboard(diagnostic);
|
|
37
|
+
info(t('glob.no_files'));
|
|
38
|
+
}
|
|
39
|
+
const output = files.join('\n');
|
|
40
|
+
console.log(output);
|
|
41
|
+
await setClipboard(output);
|
|
42
|
+
success(t('glob.done', Math.round(output.length / 1024).toString()));
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
const diagnostic = `❌ Error en glob: ${err.message}
|
|
46
|
+
|
|
47
|
+
Patrón: "${pattern}"
|
|
48
|
+
Ruta: ${searchPath}
|
|
49
|
+
|
|
50
|
+
Sugerencias:
|
|
51
|
+
1. Verifica la sintaxis del patrón glob.
|
|
52
|
+
2. Asegura que la ruta sea correcta y exista.
|
|
53
|
+
3. Si el patrón es complejo, simplifícalo (ej: "*.ts" en lugar de "**/*.ts").`;
|
|
54
|
+
await setClipboard(diagnostic);
|
|
55
|
+
problem(t('glob.error', err.message));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../src/tasks/grep.ts"],"names":[],"mappings":"AAyBA,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,iBAuEvE"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { info, success, problem } from '../util/colors.js';
|
|
4
|
+
import { setClipboard, getClipboard } from './edit.js';
|
|
5
|
+
import { createTranslator } from '../i18n/createTranslator.js';
|
|
6
|
+
import { detectLocale } from '../util/locale.js';
|
|
7
|
+
import commonCli from '../i18n/common-cli.js';
|
|
8
|
+
const t = createTranslator(detectLocale(), {
|
|
9
|
+
en: {
|
|
10
|
+
'grep.empty_clipboard': '❌ Empty clipboard',
|
|
11
|
+
'grep.done': '✅ Search completed ({{0}}KB copied to clipboard)',
|
|
12
|
+
'grep.no_matches': 'No matches found in clipboard',
|
|
13
|
+
'grep.error': '❌ Error: {{0}}. Diagnostic copied to clipboard.',
|
|
14
|
+
'grep.no_files': 'No matches found. Diagnostic copied to clipboard.',
|
|
15
|
+
},
|
|
16
|
+
es: {
|
|
17
|
+
'grep.empty_clipboard': '❌ Portapapeles vacío',
|
|
18
|
+
'grep.done': '✅ Búsqueda completada ({{0}}KB copiados al portapapeles)',
|
|
19
|
+
'grep.no_matches': 'No se encontraron coincidencias en el portapapeles',
|
|
20
|
+
'grep.error': '❌ Error: {{0}}. Diagnóstico copiado al portapapeles.',
|
|
21
|
+
'grep.no_files': 'No se encontraron coincidencias. Diagnóstico copiado al portapapeles.',
|
|
22
|
+
},
|
|
23
|
+
}, commonCli);
|
|
24
|
+
export async function runAiGrep(pattern, options = {}) {
|
|
25
|
+
if (!options.path) {
|
|
26
|
+
const clipboardContent = await getClipboard();
|
|
27
|
+
if (!clipboardContent) {
|
|
28
|
+
problem(t('grep.empty_clipboard'));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const lines = clipboardContent.split('\n');
|
|
32
|
+
const matches = [];
|
|
33
|
+
for (let i = 0; i < lines.length; i++) {
|
|
34
|
+
if (lines[i].includes(pattern)) {
|
|
35
|
+
matches.push(`${i + 1}: ${lines[i]}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (matches.length > 0) {
|
|
39
|
+
const output = matches.join('\n');
|
|
40
|
+
console.log(output);
|
|
41
|
+
await setClipboard(output);
|
|
42
|
+
success(t('grep.done', Math.round(output.length / 1024).toString()));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
info(t('grep.no_matches'));
|
|
46
|
+
await setClipboard('');
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const searchPath = resolve(process.cwd(), options.path);
|
|
51
|
+
const args = ['-r', '-n'];
|
|
52
|
+
if (options.context)
|
|
53
|
+
args.push('-C', String(options.context));
|
|
54
|
+
if (options.ignoreCase)
|
|
55
|
+
args.push('-i');
|
|
56
|
+
args.push(pattern, searchPath);
|
|
57
|
+
const result = spawnSync('grep', args, { encoding: 'utf-8' });
|
|
58
|
+
if (result.error) {
|
|
59
|
+
const diagnostic = `❌ Error en la búsqueda: ${result.error.message}
|
|
60
|
+
|
|
61
|
+
Patrón: "${pattern}"
|
|
62
|
+
Ruta: ${searchPath}
|
|
63
|
+
Comando: grep ${args.join(' ')}
|
|
64
|
+
|
|
65
|
+
Sugerencias:
|
|
66
|
+
1. Verifica que la ruta exista.
|
|
67
|
+
2. Verifica los permisos de los archivos.`;
|
|
68
|
+
await setClipboard(diagnostic);
|
|
69
|
+
problem(t('grep.error', result.error.message));
|
|
70
|
+
}
|
|
71
|
+
const output = (result.stdout || '').trim();
|
|
72
|
+
const errOutput = (result.stderr || '').trim();
|
|
73
|
+
if (output) {
|
|
74
|
+
console.log(output);
|
|
75
|
+
await setClipboard(output);
|
|
76
|
+
success(t('grep.done', Math.round(output.length / 1024).toString()));
|
|
77
|
+
}
|
|
78
|
+
else if (errOutput) {
|
|
79
|
+
problem(`❌ ${errOutput}`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const diagnostic = `🔍 No se encontraron coincidencias para: "${pattern}"
|
|
83
|
+
|
|
84
|
+
Ruta buscada: ${searchPath}
|
|
85
|
+
|
|
86
|
+
Sugerencias:
|
|
87
|
+
1. Verifica que el patrón sea correcto.
|
|
88
|
+
2. Usa --ignore-case si el caso podría ser diferente.
|
|
89
|
+
3. Verifica que haya archivos en: ${searchPath}`;
|
|
90
|
+
await setClipboard(diagnostic);
|
|
91
|
+
info(t('grep.no_files'));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readfile.d.ts","sourceRoot":"","sources":["../../src/tasks/readfile.ts"],"names":[],"mappings":"AA6DA,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,iBAmG/C"}
|