@clazic/urban 0.2.21 → 0.2.23
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/package.json +1 -1
- package/scripts/setup-poppler.js +35 -94
package/package.json
CHANGED
package/scripts/setup-poppler.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// setup-poppler.js: Windows에서 poppler (pdftoppm) 자동 설치
|
|
3
|
-
//
|
|
4
|
-
// 실패해도 설치 자체를 중단하지 않음 (exit 0 보장)
|
|
3
|
+
// PowerShell 내장 Invoke-WebRequest + Expand-Archive 사용 (외부 의존성 없음)
|
|
5
4
|
|
|
6
5
|
import { execSync } from 'child_process';
|
|
7
|
-
import { existsSync, mkdirSync,
|
|
8
|
-
import {
|
|
9
|
-
import { homedir, tmpdir } from 'os';
|
|
6
|
+
import { existsSync, mkdirSync, writeFileSync, readdirSync } from 'fs';
|
|
7
|
+
import { homedir } from 'os';
|
|
10
8
|
import { join } from 'path';
|
|
11
|
-
import https from 'https';
|
|
12
|
-
|
|
13
|
-
if (process.platform !== 'win32') process.exit(0);
|
|
14
9
|
|
|
15
10
|
const URBAN_HOME = process.env.URBAN_HOME ?? join(homedir(), '.urban');
|
|
16
11
|
const POPPLER_DIR = join(URBAN_HOME, 'bin', 'poppler');
|
|
17
12
|
const BIN_PATH_FILE = join(URBAN_HOME, 'bin', 'poppler-bin-path.txt');
|
|
18
13
|
|
|
19
|
-
/**
|
|
14
|
+
/** 재귀 탐색으로 pdftoppm.exe가 있는 폴더 반환 */
|
|
20
15
|
function findBinDir(dir) {
|
|
21
16
|
if (!existsSync(dir)) return null;
|
|
22
17
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
@@ -31,65 +26,14 @@ function findBinDir(dir) {
|
|
|
31
26
|
return null;
|
|
32
27
|
}
|
|
33
28
|
|
|
34
|
-
/** 시스템 PATH 또는 로컬 설치 여부 확인 */
|
|
35
29
|
function hasPdftoppm() {
|
|
36
30
|
try { execSync('where pdftoppm', { stdio: 'ignore', shell: true }); return true; } catch {}
|
|
37
31
|
return findBinDir(POPPLER_DIR) !== null;
|
|
38
32
|
}
|
|
39
33
|
|
|
40
|
-
/** GitHub API에서 최신 릴리즈 zip URL 조회 */
|
|
41
|
-
function getLatestZipUrl() {
|
|
42
|
-
return new Promise((resolve, reject) => {
|
|
43
|
-
https.get({
|
|
44
|
-
hostname: 'api.github.com',
|
|
45
|
-
path: '/repos/oschwartz10612/poppler-windows/releases/latest',
|
|
46
|
-
headers: { 'User-Agent': 'urban-postinstall' },
|
|
47
|
-
}, (res) => {
|
|
48
|
-
let data = '';
|
|
49
|
-
res.on('data', d => data += d);
|
|
50
|
-
res.on('end', () => {
|
|
51
|
-
try {
|
|
52
|
-
const json = JSON.parse(data);
|
|
53
|
-
const asset = json.assets?.find(a => a.name.endsWith('.zip'));
|
|
54
|
-
resolve(asset?.browser_download_url ?? null);
|
|
55
|
-
} catch (e) { reject(e); }
|
|
56
|
-
});
|
|
57
|
-
}).on('error', reject);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** HTTPS 다운로드 (리다이렉트 최대 5회) */
|
|
62
|
-
function download(url, dest, hops = 5) {
|
|
63
|
-
return new Promise((resolve, reject) => {
|
|
64
|
-
if (hops <= 0) { reject(new Error('Too many redirects')); return; }
|
|
65
|
-
https.get(url, { headers: { 'User-Agent': 'urban-postinstall' } }, (res) => {
|
|
66
|
-
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
67
|
-
download(res.headers.location, dest, hops - 1).then(resolve, reject);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (res.statusCode !== 200) { reject(new Error(`HTTP ${res.statusCode}`)); return; }
|
|
71
|
-
const file = createWriteStream(dest);
|
|
72
|
-
res.pipe(file);
|
|
73
|
-
file.on('finish', () => file.close(resolve));
|
|
74
|
-
file.on('error', reject);
|
|
75
|
-
}).on('error', reject);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** unzipper로 압축 해제 */
|
|
80
|
-
async function extractZip(zipPath, destDir) {
|
|
81
|
-
const { default: unzipper } = await import('unzipper');
|
|
82
|
-
const { createReadStream } = await import('fs');
|
|
83
|
-
mkdirSync(destDir, { recursive: true });
|
|
84
|
-
await createReadStream(zipPath)
|
|
85
|
-
.pipe(unzipper.Extract({ path: destDir }))
|
|
86
|
-
.promise();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
34
|
async function main() {
|
|
90
35
|
if (hasPdftoppm()) {
|
|
91
36
|
console.log('[urban] pdftoppm 이미 설치됨 — 건너뜀');
|
|
92
|
-
// 로컬 설치 경로가 있으면 경로 파일 업데이트
|
|
93
37
|
const binDir = findBinDir(POPPLER_DIR);
|
|
94
38
|
if (binDir) {
|
|
95
39
|
mkdirSync(join(URBAN_HOME, 'bin'), { recursive: true });
|
|
@@ -98,46 +42,43 @@ async function main() {
|
|
|
98
42
|
return;
|
|
99
43
|
}
|
|
100
44
|
|
|
101
|
-
console.log('[urban] poppler (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
try {
|
|
105
|
-
execSync(
|
|
106
|
-
'winget install --exact --silent --accept-package-agreements --accept-source-agreements "oschwartz10612.poppler"',
|
|
107
|
-
{ stdio: 'pipe', shell: true, timeout: 120_000 }
|
|
108
|
-
);
|
|
109
|
-
console.log('[urban] poppler 설치 완료 (winget)');
|
|
110
|
-
return;
|
|
111
|
-
} catch {
|
|
112
|
-
console.log('[urban] winget 실패 → GitHub 릴리즈에서 직접 다운로드...');
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// ── 2. GitHub 릴리즈 직접 다운로드 ────────────────────────────────
|
|
116
|
-
const url = await getLatestZipUrl();
|
|
117
|
-
if (!url) throw new Error('GitHub 릴리즈 URL을 가져오지 못했습니다');
|
|
118
|
-
|
|
119
|
-
console.log(`[urban] 다운로드 중: ${url}`);
|
|
120
|
-
const zipPath = join(tmpdir(), 'poppler-windows.zip');
|
|
121
|
-
await download(url, zipPath);
|
|
45
|
+
console.log('[urban] poppler 다운로드 중 (GitHub → ~/.urban/bin/poppler)...');
|
|
46
|
+
mkdirSync(POPPLER_DIR, { recursive: true });
|
|
47
|
+
mkdirSync(join(URBAN_HOME, 'bin'), { recursive: true });
|
|
122
48
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
49
|
+
const psQ = (s) => String(s).replace(/'/g, "''");
|
|
50
|
+
|
|
51
|
+
// PowerShell: GitHub API에서 최신 릴리즈 zip 다운로드 → Expand-Archive
|
|
52
|
+
const ps = `
|
|
53
|
+
$ErrorActionPreference = 'Stop'
|
|
54
|
+
$api = Invoke-RestMethod -Uri 'https://api.github.com/repos/oschwartz10612/poppler-windows/releases/latest' -Headers @{'User-Agent'='urban-installer'}
|
|
55
|
+
$url = ($api.assets | Where-Object { $_.name -like '*.zip' })[0].browser_download_url
|
|
56
|
+
$zip = Join-Path $env:TEMP 'poppler-windows.zip'
|
|
57
|
+
$dest = '${psQ(POPPLER_DIR)}'
|
|
58
|
+
Write-Host "[urban] 다운로드: $url"
|
|
59
|
+
Invoke-WebRequest -Uri $url -OutFile $zip -UseBasicParsing
|
|
60
|
+
Write-Host "[urban] 압축 해제 중..."
|
|
61
|
+
Expand-Archive -Path $zip -DestinationPath $dest -Force
|
|
62
|
+
Remove-Item $zip -ErrorAction SilentlyContinue
|
|
63
|
+
Write-Host "[urban] 완료: $dest"
|
|
64
|
+
`.trim();
|
|
65
|
+
|
|
66
|
+
const encoded = Buffer.from(ps, 'utf16le').toString('base64');
|
|
67
|
+
execSync(`powershell -NoProfile -ExecutionPolicy Bypass -EncodedCommand ${encoded}`, {
|
|
68
|
+
stdio: 'inherit',
|
|
69
|
+
timeout: 300_000,
|
|
70
|
+
});
|
|
126
71
|
|
|
127
|
-
// pdftoppm.exe 위치 탐색
|
|
128
72
|
const binDir = findBinDir(POPPLER_DIR);
|
|
129
|
-
if (!binDir) throw new Error('
|
|
73
|
+
if (!binDir) throw new Error('pdftoppm.exe를 찾을 수 없습니다');
|
|
130
74
|
|
|
131
|
-
// 데몬 시작 스크립트가 PATH에 주입할 수 있도록 경로 저장
|
|
132
|
-
mkdirSync(join(URBAN_HOME, 'bin'), { recursive: true });
|
|
133
75
|
writeFileSync(BIN_PATH_FILE, binDir, 'utf8');
|
|
134
|
-
|
|
135
76
|
console.log(`[urban] poppler 설치 완료 → ${binDir}`);
|
|
136
77
|
}
|
|
137
78
|
|
|
138
|
-
|
|
139
|
-
.catch(err => {
|
|
79
|
+
if (process.platform === 'win32') {
|
|
80
|
+
await main().catch(err => {
|
|
140
81
|
console.warn('[urban] poppler 자동 설치 실패 (계속 진행):', err.message);
|
|
141
|
-
console.warn('[urban] 수동 설치:
|
|
142
|
-
})
|
|
143
|
-
|
|
82
|
+
console.warn('[urban] 수동 설치: https://github.com/oschwartz10612/poppler-windows/releases');
|
|
83
|
+
});
|
|
84
|
+
}
|