latinfo 0.13.0 → 0.13.2

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.
Files changed (2) hide show
  1. package/dist/index.js +65 -20
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -47,7 +47,7 @@ const local_search_1 = require("./local-search");
47
47
  const client_search_1 = require("./client-search");
48
48
  const odis_search_1 = require("./odis-search");
49
49
  const mphf_search_1 = require("./mphf-search");
50
- const VERSION = '0.13.0';
50
+ const VERSION = '0.13.2';
51
51
  const API_URL = process.env.LATINFO_API_URL || 'https://api.latinfo.dev';
52
52
  const GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID || 'Ov23li5fcQaiCsVtaMKK';
53
53
  const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.latinfo');
@@ -1786,12 +1786,16 @@ async function pipeTest(args) {
1786
1786
  }
1787
1787
  }
1788
1788
  // Run import with --limit 100
1789
- const scriptPath = path_1.default.join(repo, 'src', 'imports', `${sourceName}.ts`);
1789
+ // Check YAML for custom import_script path
1790
+ const importScriptMatch = yamlContent.match(/import_script:\s*(.+)/);
1791
+ const customScript = importScriptMatch ? path_1.default.join(repo, importScriptMatch[1].trim()) : null;
1792
+ const defaultScript = path_1.default.join(repo, 'src', 'imports', `${sourceName}.ts`);
1793
+ const scriptPath = customScript && fs_1.default.existsSync(customScript) ? customScript
1794
+ : fs_1.default.existsSync(defaultScript) ? defaultScript : null;
1790
1795
  const easypipePath = path_1.default.join(repo, 'src', 'imports', 'easypipe.ts');
1791
- const useEasypipe = !fs_1.default.existsSync(scriptPath);
1792
- const cmd = useEasypipe
1793
- ? `npx tsx ${easypipePath} ${yamlPath} --limit 100 --local`
1794
- : `npx tsx ${scriptPath} --limit 100 --local`;
1796
+ const cmd = scriptPath
1797
+ ? `npx tsx ${scriptPath} --limit 100 --local`
1798
+ : `npx tsx ${easypipePath} ${yamlPath} --limit 100 --local`;
1795
1799
  console.log(`[pipe] Gate 1: TEST (100 records)\n`);
1796
1800
  console.log(`Running: ${cmd}\n`);
1797
1801
  let output = '';
@@ -1852,12 +1856,17 @@ async function pipeValidate(args) {
1852
1856
  requireGate(status, 'test', 'validate');
1853
1857
  const repo = getRepoPath();
1854
1858
  const { execSync: run } = await Promise.resolve().then(() => __importStar(require('child_process')));
1855
- const scriptPath = path_1.default.join(repo, 'src', 'imports', `${sourceName}.ts`);
1859
+ const yamlPath = path_1.default.join(repo, 'sources', `${sourceName}.yaml`);
1860
+ const yamlContent = fs_1.default.existsSync(yamlPath) ? fs_1.default.readFileSync(yamlPath, 'utf-8') : '';
1861
+ const importScriptMatch = yamlContent.match(/import_script:\s*(.+)/);
1862
+ const customScript = importScriptMatch ? path_1.default.join(repo, importScriptMatch[1].trim()) : null;
1863
+ const defaultScript = path_1.default.join(repo, 'src', 'imports', `${sourceName}.ts`);
1864
+ const scriptPath = customScript && fs_1.default.existsSync(customScript) ? customScript
1865
+ : fs_1.default.existsSync(defaultScript) ? defaultScript : null;
1856
1866
  const easypipePath = path_1.default.join(repo, 'src', 'imports', 'easypipe.ts');
1857
- const useEasypipe = !fs_1.default.existsSync(scriptPath);
1858
- const cmd = useEasypipe
1859
- ? `npx tsx ${easypipePath} ${path_1.default.join(repo, 'sources', `${sourceName}.yaml`)} --local`
1860
- : `npx tsx ${scriptPath} --local`;
1867
+ const cmd = scriptPath
1868
+ ? `npx tsx ${scriptPath} --local`
1869
+ : `npx tsx ${easypipePath} ${yamlPath} --local`;
1861
1870
  console.log(`[pipe] Gate 2: VALIDATE (full import, local only — no R2 upload)\n`);
1862
1871
  console.log(`Running: ${cmd}\n`);
1863
1872
  try {
@@ -1914,7 +1923,29 @@ async function pipeStage(args) {
1914
1923
  run(`scp ${devVarsLocal} ${RUNNER}:${remoteRepo}/.dev.vars`, { stdio: 'pipe' });
1915
1924
  }
1916
1925
  catch { }
1917
- // 3. Run import on Linux Mint
1926
+ // 3. Install deps on Linux Mint from YAML
1927
+ const yamlPath = path_1.default.join(repo, 'sources', `${sourceName}.yaml`);
1928
+ const yamlContent = fs_1.default.existsSync(yamlPath) ? fs_1.default.readFileSync(yamlPath, 'utf-8') : '';
1929
+ const depsMatch = yamlContent.match(/dependencies:\n([\s\S]*?)(?=\n\w|\n$|$)/);
1930
+ if (depsMatch) {
1931
+ const deps = depsMatch[1].split('\n').map(l => l.replace(/^\s*-\s*/, '').trim()).filter(Boolean);
1932
+ if (deps.length > 0) {
1933
+ console.log(`[pipe] Installing deps on Linux Mint: ${deps.join(', ')}...`);
1934
+ try {
1935
+ run(`ssh ${RUNNER} "cd ${remoteRepo} && npm install ${deps.join(' ')}"`, { stdio: 'inherit', timeout: 120_000 });
1936
+ // Install playwright browsers if needed
1937
+ if (deps.some(d => d.includes('playwright'))) {
1938
+ console.log(`[pipe] Installing Playwright browser...`);
1939
+ run(`ssh ${RUNNER} "cd ${remoteRepo} && npx playwright install chromium --with-deps"`, { stdio: 'inherit', timeout: 120_000 });
1940
+ }
1941
+ }
1942
+ catch {
1943
+ console.error('[pipe] Failed to install deps on Linux Mint');
1944
+ process.exit(1);
1945
+ }
1946
+ }
1947
+ }
1948
+ // 4. Run import on Linux Mint
1918
1949
  console.log(`[pipe] Running import on Linux Mint...`);
1919
1950
  try {
1920
1951
  run(`ssh ${RUNNER} "cd ${remoteRepo} && set -a && source .env 2>/dev/null; source .dev.vars 2>/dev/null; set +a && R2_BUCKET_NAME=latinfo-data npx tsx src/imports/${sourceName}.ts"`, {
@@ -2130,17 +2161,31 @@ async function pipePublish(args) {
2130
2161
  const { execSync: run } = await Promise.resolve().then(() => __importStar(require('child_process')));
2131
2162
  const RUNNER = 'f3mt0@100.109.82.87';
2132
2163
  console.log(`[pipe] Gate 4: PUBLISH\n`);
2133
- // 1. Git add + commit + push
2164
+ // 1. Auto-generate sources.ts from YAMLs
2165
+ console.log(`[pipe] Generating sources.ts...`);
2166
+ try {
2167
+ run(`npx tsx src/imports/generate-sources.ts`, { cwd: repo, stdio: 'inherit' });
2168
+ }
2169
+ catch {
2170
+ console.error(`[pipe] Failed to generate sources.ts`);
2171
+ process.exit(1);
2172
+ }
2173
+ // 2. Git add + commit + push
2134
2174
  console.log(`[pipe] Committing to repo...`);
2135
- const files = [`sources/${sourceName}.yaml`];
2175
+ const files = [`sources/${sourceName}.yaml`, 'src/sources.ts'];
2136
2176
  const scriptPath = path_1.default.join(repo, 'src', 'imports', `${sourceName}.ts`);
2137
- if (fs_1.default.existsSync(scriptPath))
2177
+ const yamlContent = fs_1.default.readFileSync(path_1.default.join(repo, 'sources', `${sourceName}.yaml`), 'utf-8');
2178
+ const importScriptMatch = yamlContent.match(/import_script:\s*(.+)/);
2179
+ const customScript = importScriptMatch ? importScriptMatch[1].trim() : null;
2180
+ if (customScript && fs_1.default.existsSync(path_1.default.join(repo, customScript)))
2181
+ files.push(customScript);
2182
+ else if (fs_1.default.existsSync(scriptPath))
2138
2183
  files.push(`src/imports/${sourceName}.ts`);
2184
+ const docsFile = `docs/sources/${sourceName}.md`;
2185
+ if (fs_1.default.existsSync(path_1.default.join(repo, docsFile)))
2186
+ files.push(docsFile);
2139
2187
  try {
2140
- const docsFile = `docs/sources/${sourceName}.md`;
2141
- if (fs_1.default.existsSync(path_1.default.join(repo, docsFile)))
2142
- files.push(docsFile);
2143
- run(`git add ${files.join(' ')} src/sources.ts .github/workflows/import.yml`, { cwd: repo, stdio: 'pipe' });
2188
+ run(`git add ${files.join(' ')}`, { cwd: repo, stdio: 'pipe' });
2144
2189
  run(`git commit -m "Add data source: ${sourceName}"`, { cwd: repo, stdio: 'pipe' });
2145
2190
  run(`git push`, { cwd: repo, stdio: 'pipe' });
2146
2191
  console.log(`[pipe] Pushed to remote.`);
@@ -2170,7 +2215,7 @@ async function pipePublish(args) {
2170
2215
  // 4. Restart search server
2171
2216
  console.log(`[pipe] Restarting search server on Linux Mint...`);
2172
2217
  try {
2173
- run(`ssh ${RUNNER} "sudo systemctl restart search-server 2>/dev/null || echo 'No service yet'"`, { stdio: 'inherit' });
2218
+ run(`ssh ${RUNNER} "sudo systemctl restart latinfo-search 2>/dev/null || echo 'No service yet'"`, { stdio: 'inherit' });
2174
2219
  }
2175
2220
  catch { }
2176
2221
  console.log(`\n[pipe] Gate 4 PASSED ✓`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "latinfo",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "description": "Tax registry & procurement API for Latin America. Query RUC, DNI, NIT, licitaciones from Peru & Colombia. Offline MPHF search, full OCDS data, updated daily.",
5
5
  "homepage": "https://latinfo.dev",
6
6
  "repository": {