laporan-generator 2.9.0 → 3.0.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.
Files changed (54) hide show
  1. package/.agents/skills/laporan-generator/references/prompt.md +319 -0
  2. package/.agents/skills/laporan-generator/resources/Makefile +11 -7
  3. package/.agents/skills/laporan-generator/resources/build-docx.sh +4 -1
  4. package/.agents/skills/laporan-generator/resources/build.sh +4 -1
  5. package/.agents/skills/laporan-generator/resources/laporan +33 -16
  6. package/.agents/skills/laporan-generator/resources/laporan.ps1 +635 -628
  7. package/.agents/skills/laporan-generator/resources/scripts/bundle.py +24 -8
  8. package/.agents/skills/laporan-generator/resources/scripts/ingest.py +121 -0
  9. package/.agents/skills/laporan-generator/resources/scripts/report-doctor.py +9 -2
  10. package/.agents/skills/laporan-generator/resources/scripts/report-stats.py +9 -2
  11. package/.agents/skills/laporan-generator/resources/scripts/scan-preset.py +1 -1
  12. package/.agents/skills/laporan-generator/resources/scripts/test_scripts.py +8 -2
  13. package/.agents/skills/laporan-generator/scripts/build-docx.sh +4 -1
  14. package/.agents/skills/laporan-generator/scripts/build.sh +4 -1
  15. package/.agents/skills/laporan-generator/scripts/bundle.py +24 -8
  16. package/.agents/skills/laporan-generator/scripts/ingest.py +121 -0
  17. package/.agents/skills/laporan-generator/scripts/laporan +33 -16
  18. package/.agents/skills/laporan-generator/scripts/laporan.ps1 +635 -628
  19. package/.agents/skills/laporan-generator/scripts/report-doctor.py +9 -2
  20. package/.agents/skills/laporan-generator/scripts/report-stats.py +9 -2
  21. package/.agents/skills/laporan-generator/scripts/scan-preset.py +1 -1
  22. package/.agents/skills/laporan-generator/scripts/test_scripts.py +8 -2
  23. package/Makefile +11 -7
  24. package/README.md +48 -388
  25. package/bin/laporan-generator.js +10 -1
  26. package/build-docx.sh +4 -1
  27. package/build.sh +4 -1
  28. package/docs/prompt.md +319 -0
  29. package/laporan +33 -16
  30. package/laporan.ps1 +635 -628
  31. package/lib/init.js +62 -28
  32. package/lib/mcp.js +174 -3
  33. package/lib/sync-hosts.js +17 -9
  34. package/package.json +2 -10
  35. package/scripts/bundle.py +24 -8
  36. package/scripts/ingest.py +121 -0
  37. package/scripts/report-doctor.py +9 -2
  38. package/scripts/report-stats.py +9 -2
  39. package/scripts/scan-preset.py +1 -1
  40. package/scripts/test_scripts.py +8 -2
  41. package/templates/default/gambar/.gitkeep +1 -0
  42. /package/{apa.csl → templates/default/apa.csl} +0 -0
  43. /package/{chapters → templates/default/chapters}/bab1-pendahuluan.md +0 -0
  44. /package/{chapters → templates/default/chapters}/bab2-tinjauan-pustaka.md +0 -0
  45. /package/{chapters → templates/default/chapters}/bab3-metodologi.md +0 -0
  46. /package/{chapters → templates/default/chapters}/bab4-hasil-dan-pembahasan.md +0 -0
  47. /package/{chapters → templates/default/chapters}/bab5-penutup.md +0 -0
  48. /package/{cover.md → templates/default/cover.md} +0 -0
  49. /package/{docx.lua → templates/default/docx.lua} +0 -0
  50. /package/{logo.jpg → templates/default/logo.jpg} +0 -0
  51. /package/{metadata.yml → templates/default/metadata.yml} +0 -0
  52. /package/{reference.docx → templates/default/reference.docx} +0 -0
  53. /package/{references.bib → templates/default/references.bib} +0 -0
  54. /package/{template.typ → templates/default/template.typ} +0 -0
@@ -1,628 +1,635 @@
1
- # ==============================================================================
2
- # Laporan Generator CLI Helper for Windows PowerShell (.\laporan.ps1)
3
- # ==============================================================================
4
- param (
5
- [Parameter(Position=0)]
6
- [string]$Command = "help",
7
- [Parameter(Position=1)]
8
- [string]$SubCommand = "",
9
- [Parameter(Position=2)]
10
- [string]$Arg1 = "",
11
- [Parameter(Position=3)]
12
- [string]$Arg2 = "",
13
- [Parameter(ValueFromRemainingArguments=$true)]
14
- [string[]]$RemainingArgs
15
- )
16
-
17
- $ErrorActionPreference = "Stop"
18
- $env:PYTHONUTF8 = "1"
19
-
20
- # Pastikan folder localBin ada di PATH sesi saat ini jika ada
21
- $localBin = Join-Path $env:LOCALAPPDATA "laporan-generator\bin"
22
- if ((Test-Path $localBin) -and ($env:Path -notlike "*$localBin*")) {
23
- $env:Path = "$localBin;$env:Path"
24
- }
25
-
26
- function Get-PythonCommand {
27
- foreach ($cmd in @("python", "python3")) {
28
- $c = Get-Command $cmd -ErrorAction SilentlyContinue
29
- if ($c) {
30
- if ($c.Source -match "WindowsApps\\python") {
31
- continue
32
- }
33
- return $c.Source
34
- }
35
- }
36
- $fallback = Get-Command "python" -ErrorAction SilentlyContinue
37
- if ($fallback) { return $fallback.Source }
38
- return ""
39
- }
40
-
41
- function Show-Banner {
42
- Write-Host " ========================================================" -ForegroundColor Cyan
43
- Write-Host " LAPORAN GENERATOR CLI v2.9.0 " -ForegroundColor Cyan
44
- Write-Host " Otomatisasi Dokumen Akademik (Typst + DOCX Engine) " -ForegroundColor Cyan
45
- Write-Host " ========================================================" -ForegroundColor Cyan
46
- Write-Host ""
47
- }
48
-
49
- function Show-Help {
50
- Show-Banner
51
- Write-Host "Penggunaan: .\laporan.ps1 <perintah>" -ForegroundColor White
52
- Write-Host ""
53
- Write-Host "Perintah yang Tersedia:" -ForegroundColor White
54
- Write-Host " build Kompilasi PDF dan DOCX sekaligus" -ForegroundColor Green
55
- Write-Host " pdf Kompilasi dokumen PDF (via Typst)" -ForegroundColor Green
56
- Write-Host " docx Kompilasi dokumen Microsoft Word (.docx)" -ForegroundColor Green
57
- Write-Host " init Wizard interaktif untuk konfigurasi awal metadata" -ForegroundColor Green
58
- Write-Host " preset Kelola preset format kampus (list/show/apply/validate/diff/scan)" -ForegroundColor Green
59
- Write-Host " stats Analisis statistik kata, halaman, gambar, dan durasi baca" -ForegroundColor Green
60
- Write-Host " doctor Audit kesehatan proyek (broken images, sitasi hilang, dll.)" -ForegroundColor Green
61
- Write-Host " bundle Kemas seluruh laporan (PDF, DOCX, MD) menjadi arsip zip" -ForegroundColor Green
62
- Write-Host " setup Pasang dependensi sistem otomatis Windows (Typst, Pandoc, Magick)" -ForegroundColor Green
63
- Write-Host " mcp Jalankan Model Context Protocol (MCP) Server untuk AI Agent" -ForegroundColor Green
64
- Write-Host " sync-skills Sinkronkan skill AI agent & MCP ke Antigravity, Claude, OpenCode" -ForegroundColor Green
65
- Write-Host " uninstall Hapus integrasi skill dan perintah AI agent dari seluruh sistem" -ForegroundColor Green
66
- Write-Host " check Audit dependensi sistem dan struktur proyek" -ForegroundColor Green
67
- Write-Host " test Jalankan suite pengujian otomatis" -ForegroundColor Green
68
- Write-Host " view Buka dokumen Laporan.pdf di PDF viewer" -ForegroundColor Green
69
- Write-Host " watch Pantau perubahan berkas dan auto-rebuild" -ForegroundColor Green
70
- Write-Host " clean Bersihkan berkas output dan direktori sementara" -ForegroundColor Green
71
- Write-Host " help Tampilkan panduan bantuan ini" -ForegroundColor Green
72
- Write-Host ""
73
- Write-Host "Contoh:" -ForegroundColor Yellow
74
- Write-Host " .\laporan.ps1 build"
75
- Write-Host " .\laporan.ps1 stats"
76
- Write-Host " .\laporan.ps1 preset list"
77
- Write-Host " .\laporan.ps1 preset apply itb-ta"
78
- }
79
-
80
- function Cmd-Check {
81
- Show-Banner
82
- Write-Host "[1/2] Memeriksa Dependensi Sistem..." -ForegroundColor Blue
83
-
84
- $pyPath = Get-PythonCommand
85
- $pyFound = if ($pyPath) { Get-Command $pyPath -ErrorAction SilentlyContinue } else { $null }
86
-
87
- $imFound = Get-Command "magick" -ErrorAction SilentlyContinue
88
- if (-not $imFound -and -not ($env:OS -match "Windows")) {
89
- $imFound = Get-Command "convert" -ErrorAction SilentlyContinue
90
- }
91
-
92
- $deps = @(
93
- @{ Name="Pandoc"; Cmd="pandoc"; Found=(Get-Command "pandoc" -ErrorAction SilentlyContinue); Req=$true },
94
- @{ Name="Typst"; Cmd="typst"; Found=(Get-Command "typst" -ErrorAction SilentlyContinue); Req=$true },
95
- @{ Name="ImageMagick"; Cmd="magick/convert"; Found=$imFound; Req=$false },
96
- @{ Name="Python 3"; Cmd="python/python3"; Found=$pyFound; Req=$true },
97
- @{ Name="LibreOffice"; Cmd="soffice"; Found=(Get-Command "soffice" -ErrorAction SilentlyContinue); Req=$false }
98
- )
99
-
100
- $allOk = $true
101
- foreach ($d in $deps) {
102
- if ($d.Found) {
103
- Write-Host " [OK] $($d.Name) ($($d.Cmd)) terpasang: $($d.Found.Source)" -ForegroundColor Green
104
- } else {
105
- if ($d.Req) {
106
- Write-Host " [FAIL] $($d.Name) ($($d.Cmd)) TIDAK DITEMUKAN (Wajib)" -ForegroundColor Red
107
- $allOk = $false
108
- } else {
109
- Write-Host " [INFO] $($d.Name) ($($d.Cmd)) tidak ditemukan (Opsional)" -ForegroundColor Yellow
110
- }
111
- }
112
- }
113
-
114
- Write-Host ""
115
- Write-Host "[2/2] Memeriksa Berkas Proyek..." -ForegroundColor Blue
116
- $files = @("metadata.yml", "cover.md", "template.typ", "reference.docx", "references.bib", "docx.lua")
117
- foreach ($f in $files) {
118
- if (Test-Path $f) {
119
- Write-Host " [OK] Berkas $f ditemukan" -ForegroundColor Green
120
- } else {
121
- Write-Host " [FAIL] Berkas $f tidak ditemukan" -ForegroundColor Red
122
- $allOk = $false
123
- }
124
- }
125
-
126
- $dirs = @("presets", "chapters")
127
- foreach ($d in $dirs) {
128
- if (Test-Path $d) {
129
- Write-Host " [OK] Direktori $d ditemukan" -ForegroundColor Green
130
- } else {
131
- Write-Host " [FAIL] Direktori $d tidak ditemukan" -ForegroundColor Red
132
- $allOk = $false
133
- }
134
- }
135
-
136
- Write-Host ""
137
- if ($allOk) {
138
- Write-Host "Semua dependensi dan berkas proyek lengkap dan siap digunakan!" -ForegroundColor Green
139
- } else {
140
- Write-Host "Ada beberapa komponen yang kurang. Gunakan Docker jika ingin bebas instalasi lokal." -ForegroundColor Yellow
141
- }
142
- }
143
-
144
- function Cmd-Build-PDF {
145
- Show-Banner
146
- Write-Host "Membangun Dokumen PDF (Typst Engine)..." -ForegroundColor Blue
147
-
148
- $inputFiles = @("cover.md") + (Get-ChildItem -Path "chapters" -Filter "bab*.md" | Sort-Object Name | ForEach-Object { $_.FullName })
149
- $presetOpt = ""
150
- if (Test-Path "metadata.yml") {
151
- $content = Get-Content "metadata.yml" -Raw
152
- if ($content -match "(?:preset|margin_preset)\s*:\s*[`"']?([a-zA-Z0-9_-]+)[`"']?") {
153
- $presetName = $matches[1]
154
- if (Test-Path "presets\$presetName.yml") {
155
- $presetOpt = "--metadata-file=presets\$presetName.yml"
156
- }
157
- }
158
- }
159
-
160
- $pandocArgs = @()
161
- $pandocArgs += $inputFiles
162
- $pandocArgs += "--template=template.typ"
163
- if ($presetOpt) { $pandocArgs += $presetOpt }
164
- $pandocArgs += "--metadata-file=metadata.yml"
165
- $pandocArgs += "--citeproc"
166
- $pandocArgs += "--bibliography=references.bib"
167
- $pandocArgs += "--csl=apa.csl"
168
- $pandocArgs += "--metadata=reference-section-title=DAFTAR PUSTAKA"
169
- $pandocArgs += "--top-level-division=chapter"
170
- $pandocArgs += "--pdf-engine=typst"
171
- $pandocArgs += "--no-highlight"
172
- $pandocArgs += @("-o", "Laporan.pdf")
173
-
174
- & pandoc $pandocArgs
175
- if ($LASTEXITCODE -eq 0) {
176
- Write-Host ""
177
- Write-Host "=== PDF BERHASIL DIBUAT ===" -ForegroundColor Green
178
- Write-Host "Lokasi: $(Get-Location)\Laporan.pdf" -ForegroundColor Cyan
179
- } else {
180
- Write-Host "[ERROR] Kompilasi PDF gagal." -ForegroundColor Red
181
- }
182
- }
183
-
184
- function Cmd-Build-DOCX {
185
- Show-Banner
186
- Write-Host "Membangun Dokumen Microsoft Word (DOCX Multi-Pass)..." -ForegroundColor Blue
187
-
188
- if (-not (Test-Path "chapters")) {
189
- Write-Host "[ERROR] Direktori chapters/ tidak ditemukan." -ForegroundColor Red
190
- return
191
- }
192
-
193
- $pyCmd = Get-PythonCommand
194
- if (-not $pyCmd) {
195
- Write-Host "[ERROR] Python 3 dibutuhkan untuk memproses DOCX." -ForegroundColor Red
196
- return
197
- }
198
-
199
- $inputFiles = @("cover.md") + (Get-ChildItem -Path "chapters" -Filter "bab*.md" | Sort-Object Name | ForEach-Object { $_.FullName })
200
- $presetOpt = ""
201
- if (Test-Path "metadata.yml") {
202
- $content = Get-Content "metadata.yml" -Raw
203
- if ($content -match "(?:preset|margin_preset)\s*:\s*[`"']?([a-zA-Z0-9_-]+)[`"']?") {
204
- $presetName = $matches[1]
205
- if (Test-Path "presets\$presetName.yml") {
206
- $presetOpt = "--metadata-file=presets\$presetName.yml"
207
- }
208
- }
209
- }
210
-
211
- $tmpDocx = [System.IO.Path]::GetTempFileName() + ".docx"
212
- $sectDocx = [System.IO.Path]::GetTempFileName() + ".docx"
213
-
214
- try {
215
- $pandocArgs = @()
216
- $pandocArgs += $inputFiles
217
- if ($presetOpt) { $pandocArgs += $presetOpt }
218
- $pandocArgs += "--metadata-file=metadata.yml"
219
- $pandocArgs += "--citeproc"
220
- $pandocArgs += "--bibliography=references.bib"
221
- $pandocArgs += "--csl=apa.csl"
222
- $pandocArgs += "--metadata=reference-section-title=DAFTAR PUSTAKA"
223
- $pandocArgs += "--top-level-division=chapter"
224
- $pandocArgs += "--reference-doc=reference.docx"
225
- $pandocArgs += "--lua-filter=docx.lua"
226
- $pandocArgs += @("-o", $tmpDocx)
227
-
228
- & pandoc $pandocArgs
229
- if ($LASTEXITCODE -ne 0) {
230
- Write-Host "[ERROR] Kompilasi Pandoc ke DOCX gagal." -ForegroundColor Red
231
- return
232
- }
233
-
234
- & $pyCmd scripts/finalize-docx.py $tmpDocx $sectDocx
235
- & $pyCmd scripts/docx-pagenum.py $sectDocx Laporan.docx
236
-
237
- if (Test-Path "Laporan.docx") {
238
- Write-Host ""
239
- Write-Host "=== DOCX BERHASIL DIBUAT ===" -ForegroundColor Green
240
- Write-Host "Lokasi: $(Get-Location)\Laporan.docx" -ForegroundColor Cyan
241
- }
242
- } finally {
243
- Remove-Item -Force -ErrorAction SilentlyContinue $tmpDocx, $sectDocx
244
- }
245
- }
246
-
247
- function Cmd-Build {
248
- Show-Banner
249
- Write-Host "[1/2] Membangun Dokumen PDF (Typst Engine)..." -ForegroundColor Blue
250
- Cmd-Build-PDF
251
- Write-Host ""
252
- Write-Host "[2/2] Membangun Dokumen Microsoft Word (DOCX Multi-Pass)..." -ForegroundColor Blue
253
- Cmd-Build-DOCX
254
- Write-Host ""
255
- Write-Host "Dokumen PDF dan DOCX berhasil diproses!" -ForegroundColor Green
256
- }
257
-
258
- function Escape-Yaml {
259
- param ([string]$Val)
260
- if (-not $Val) { return "" }
261
- $Val = $Val -replace "\\", "\\\\"
262
- $Val = $Val -replace '"', '\"'
263
- $Val = $Val -replace "`r", ""
264
- $Val = $Val -replace "`n", " "
265
- return $Val
266
- }
267
-
268
- function Cmd-Init {
269
- Show-Banner
270
- Write-Host "Wizard Konfigurasi Laporan Akademik (Windows PowerShell)" -ForegroundColor Cyan
271
- Write-Host "Isi data di bawah ini (tekan Enter untuk memakai nilai default):"
272
- Write-Host ""
273
-
274
- $in_title = Read-Host "Judul Laporan [LAPORAN PROYEK AKADEMIK]"
275
- if (-not $in_title) { $in_title = "LAPORAN PROYEK AKADEMIK" }
276
-
277
- $in_subtitle = Read-Host "Subjudul [DOKUMENTASI DAN ANALISIS IMPLEMENTASI]"
278
- if (-not $in_subtitle) { $in_subtitle = "DOKUMENTASI DAN ANALISIS IMPLEMENTASI" }
279
-
280
- $in_course = Read-Host "Mata Kuliah [Proyek Perangkat Lunak]"
281
- if (-not $in_course) { $in_course = "Proyek Perangkat Lunak" }
282
-
283
- $in_lecturer = Read-Host "Dosen Pengampu [Dr. Nama Dosen, M.Kom.]"
284
- if (-not $in_lecturer) { $in_lecturer = "Dr. Nama Dosen, M.Kom." }
285
-
286
- $in_author = Read-Host "Nama Penulis 1 [Nama Mahasiswa]"
287
- if (-not $in_author) { $in_author = "Nama Mahasiswa" }
288
-
289
- $in_nim = Read-Host "NIM Penulis 1 [12345678]"
290
- if (-not $in_nim) { $in_nim = "12345678" }
291
-
292
- $in_institution = Read-Host "Institusi/Universitas [UNIVERSITAS TEKNOLOGI]"
293
- if (-not $in_institution) { $in_institution = "UNIVERSITAS TEKNOLOGI" }
294
-
295
- $in_faculty = Read-Host "Fakultas [FAKULTAS ILMU KOMPUTER]"
296
- if (-not $in_faculty) { $in_faculty = "FAKULTAS ILMU KOMPUTER" }
297
-
298
- $in_year = Read-Host "Tahun Akademik [2026/2027]"
299
- if (-not $in_year) { $in_year = "2026/2027" }
300
-
301
- Write-Host ""
302
- Write-Host "Pilihan Preset Format Kampus:" -ForegroundColor Blue
303
- Write-Host " standard / skripsi-4433 / ui-skripsi / itb-ta / ugm-skripsi / its-skripsi / unpad-skripsi"
304
- $in_preset = Read-Host "Preset Format [standard]"
305
- if (-not $in_preset) { $in_preset = "standard" }
306
-
307
- $curDate = (Get-Date -Format "MMMM yyyy")
308
-
309
- $escTitle = Escape-Yaml $in_title
310
- $escSubtitle = Escape-Yaml $in_subtitle
311
- $escCourse = Escape-Yaml $in_course
312
- $escLecturer = Escape-Yaml $in_lecturer
313
- $escAuthor = Escape-Yaml $in_author
314
- $escNim = Escape-Yaml $in_nim
315
- $escInstitution = Escape-Yaml $in_institution
316
- $escFaculty = Escape-Yaml $in_faculty
317
- $escYear = Escape-Yaml $in_year
318
- $escPreset = Escape-Yaml $in_preset
319
-
320
- $yamlContent = @"
321
- title: "$escTitle"
322
- subtitle: "$escSubtitle"
323
- course: "$escCourse"
324
- lecturer: "$escLecturer"
325
- author:
326
- - name: "$escAuthor"
327
- nim: "$escNim"
328
- institution: "$escInstitution"
329
- faculty: "$escFaculty"
330
- year: "$escYear"
331
- date: "$curDate"
332
- preset: "$escPreset"
333
- "@
334
-
335
- Set-Content -Path "metadata.yml" -Value $yamlContent
336
- Write-Host ""
337
- Write-Host "metadata.yml berhasil diperbarui!" -ForegroundColor Green
338
- Write-Host "Jalankan '.\laporan.ps1 build' untuk mulai menghasilkan laporan." -ForegroundColor Cyan
339
- }
340
-
341
- function Cmd-Test {
342
- Show-Banner
343
- Write-Host "Menjalankan Test Suite..." -ForegroundColor Blue
344
- $gitBash = "C:\Program Files\Git\bin\bash.exe"
345
- $bashCmd = if (Test-Path $gitBash) { $gitBash } elseif ((Get-Command "bash" -ErrorAction SilentlyContinue) -and (Get-Command "bash").Source -notmatch "system32\\bash\.exe") { "bash" } else { "" }
346
- if ($bashCmd -and (Test-Path "test.sh")) {
347
- & $bashCmd test.sh
348
- } else {
349
- $pyCmd = Get-PythonCommand
350
- if ($pyCmd) {
351
- Write-Host "Menjalankan validasi skema preset..." -ForegroundColor Blue
352
- if (Test-Path "scripts/validate-preset.py") {
353
- & $pyCmd scripts/validate-preset.py --all
354
- }
355
- if (Test-Path "scripts/test_scripts.py") {
356
- Write-Host ""
357
- Write-Host "Menjalankan unit test skrip Python..." -ForegroundColor Blue
358
- & $pyCmd scripts/test_scripts.py
359
- }
360
- } else {
361
- Write-Host "Test suite membutuhkan bash atau python3." -ForegroundColor Yellow
362
- }
363
- }
364
- }
365
-
366
- function Cmd-Preset {
367
- param ($Sub, $P1, $P2)
368
- $pyCmd = Get-PythonCommand
369
-
370
- switch ($Sub) {
371
- "list" {
372
- Show-Banner
373
- Write-Host "Daftar Preset Format Kampus Tersedia:" -ForegroundColor Blue
374
- Write-Host ""
375
- Get-ChildItem -Path "presets" -Filter "*.yml" | ForEach-Object {
376
- $presetId = $_.BaseName
377
- $name = (Select-String -Path $_.FullName -Pattern "^\s*name:\s*`"?(.*?)`"?\s*$" | Select-Object -First 1).Matches.Groups[1].Value
378
- $desc = (Select-String -Path $_.FullName -Pattern "^\s*description:\s*`"?(.*?)`"?\s*$" | Select-Object -First 1).Matches.Groups[1].Value
379
- Write-Host " * $presetId - $name" -ForegroundColor Green
380
- if ($desc) { Write-Host " $desc" -ForegroundColor Gray }
381
- Write-Host ""
382
- }
383
- }
384
- "show" {
385
- if (-not $P1) { Write-Host "Error: Sebutkan ID preset. Contoh: .\laporan.ps1 preset show itb-ta" -ForegroundColor Red; return }
386
- $file = "presets\$P1.yml"
387
- if (Test-Path $file) {
388
- Show-Banner
389
- Write-Host "Konfigurasi Preset: $P1" -ForegroundColor Cyan
390
- Write-Host "--------------------------------------------------------"
391
- Get-Content $file
392
- Write-Host "--------------------------------------------------------"
393
- } else {
394
- Write-Host "Preset '$P1' tidak ditemukan." -ForegroundColor Red
395
- }
396
- }
397
- "apply" {
398
- if (-not $P1) { Write-Host "Error: Sebutkan ID preset. Contoh: .\laporan.ps1 preset apply itb-ta" -ForegroundColor Red; return }
399
- $file = "presets\$P1.yml"
400
- if (-not (Test-Path $file)) { Write-Host "Preset '$P1' tidak ditemukan." -ForegroundColor Red; return }
401
- if (-not (Test-Path "metadata.yml")) { Write-Host "metadata.yml tidak ditemukan." -ForegroundColor Red; return }
402
-
403
- $content = Get-Content "metadata.yml" -Raw
404
- if ($content -match "preset\s*:") {
405
- $content = $content -replace "preset\s*:.*", "preset: `"$P1`""
406
- } else {
407
- $content += "`npreset: `"$P1`""
408
- }
409
- Set-Content -Path "metadata.yml" -Value $content -NoNewline
410
- Write-Host "[OK] Preset '$P1' berhasil diterapkan ke metadata.yml!" -ForegroundColor Green
411
- }
412
- "validate" {
413
- if (-not $pyCmd) { Write-Host "Error: Python 3 tidak ditemukan." -ForegroundColor Red; return }
414
- if ($P1) {
415
- $tgt = $P1
416
- if (Test-Path "presets\$tgt.yml") { $tgt = "presets\$tgt.yml" }
417
- & $pyCmd scripts/validate-preset.py $tgt
418
- } else {
419
- & $pyCmd scripts/validate-preset.py --all
420
- }
421
- }
422
- "diff" {
423
- if (-not $P1) { Write-Host "Error: Sebutkan setidaknya 1 preset untuk dibandingkan." -ForegroundColor Red; return }
424
- $f1 = "presets\$P1.yml"
425
- if (-not (Test-Path $f1)) { Write-Host "Preset '$P1' tidak ditemukan." -ForegroundColor Red; return }
426
- if ($P2) {
427
- $f2 = "presets\$P2.yml"
428
- if (-not (Test-Path $f2)) { Write-Host "Preset '$P2' tidak ditemukan." -ForegroundColor Red; return }
429
- Compare-Object (Get-Content $f1) (Get-Content $f2)
430
- } else {
431
- $curr = "standard"
432
- if (Test-Path "metadata.yml") {
433
- $content = Get-Content "metadata.yml" -Raw
434
- if ($content -match "(?:preset|margin_preset)\s*:\s*[`"']?([a-zA-Z0-9_-]+)[`"']?") {
435
- $curr = $matches[1]
436
- }
437
- }
438
- $f2 = "presets\$curr.yml"
439
- Compare-Object (Get-Content $f2) (Get-Content $f1)
440
- }
441
- }
442
- "scan" {
443
- if (-not $pyCmd) { Write-Host "Error: Python 3 tidak ditemukan." -ForegroundColor Red; return }
444
- if (-not $P1) { Write-Host "Error: Masukkan path file PDF pedoman kampus." -ForegroundColor Red; return }
445
- & $pyCmd scripts/scan-preset.py $P1 $P2
446
- }
447
- default {
448
- Write-Host "Gunakan: .\laporan.ps1 preset [list | show <id> | apply <id> | validate | diff <id> | scan <file>]" -ForegroundColor Yellow
449
- }
450
- }
451
- }
452
-
453
- function Cmd-Clean {
454
- Remove-Item -Force -ErrorAction SilentlyContinue Laporan.pdf, Laporan.docx, Laporan.html
455
- Remove-Item -Recurse -Force -ErrorAction SilentlyContinue tmp, dist
456
- Write-Host "[OK] Berkas output berhasil dibersihkan." -ForegroundColor Green
457
- }
458
-
459
- function Cmd-Stats {
460
- param([string[]]$ArgsList)
461
- $pyCmd = Get-PythonCommand
462
- if ($pyCmd) {
463
- & $pyCmd scripts/report-stats.py @ArgsList
464
- } else {
465
- Write-Host "Error: Python 3 tidak ditemukan." -ForegroundColor Red
466
- }
467
- }
468
-
469
- function Cmd-Doctor {
470
- param([string[]]$ArgsList)
471
- $pyCmd = Get-PythonCommand
472
- if ($pyCmd) {
473
- & $pyCmd scripts/report-doctor.py @ArgsList
474
- } else {
475
- Write-Host "Error: Python 3 tidak ditemukan." -ForegroundColor Red
476
- }
477
- }
478
-
479
- function Cmd-Bundle {
480
- param([string[]]$ArgsList)
481
- $pyCmd = Get-PythonCommand
482
- if ($pyCmd) {
483
- & $pyCmd scripts/bundle.py @ArgsList
484
- } else {
485
- Write-Host "Error: Python 3 tidak ditemukan." -ForegroundColor Red
486
- }
487
- }
488
-
489
- function Cmd-View {
490
- if (Test-Path "Laporan.pdf") {
491
- Start-Process "Laporan.pdf"
492
- } else {
493
- Write-Host "Laporan.pdf belum dibuat. Jalankan '.\laporan.ps1 build' terlebih dahulu." -ForegroundColor Red
494
- }
495
- }
496
-
497
- function Cmd-Watch {
498
- Show-Banner
499
- Write-Host "Memantau perubahan berkas dan auto-rebuild... (Tekan Ctrl+C untuk berhenti)" -ForegroundColor Cyan
500
- $scriptPath = $MyInvocation.MyCommand.Definition
501
- if (-not $scriptPath) { $scriptPath = $PSCommandPath }
502
- if (-not $scriptPath) { $scriptPath = ".\laporan.ps1" }
503
-
504
- $watcher = New-Object System.IO.FileSystemWatcher
505
- $watcher.Path = (Get-Location).Path
506
- $watcher.IncludeSubdirectories = $true
507
- $watcher.EnableRaisingEvents = $true
508
- $watcher.Filter = "*.*"
509
-
510
- $action = {
511
- $path = $Event.SourceEventArgs.FullPath
512
- if ($path -notmatch '(\.pdf|\.docx|tmp|dist|\.git)' -and ($path -match '(\.md|\.typ|\.yml|\.bib)')) {
513
- Write-Host "[Perubahan Terdeteksi] $path -> Membangun ulang..." -ForegroundColor Yellow
514
- if (Get-Command Cmd-Build -ErrorAction SilentlyContinue) {
515
- Cmd-Build
516
- } elseif ($using:scriptPath -and (Test-Path $using:scriptPath)) {
517
- & powershell -ExecutionPolicy Bypass -File $using:scriptPath build
518
- } else {
519
- powershell -ExecutionPolicy Bypass -File ".\laporan.ps1" build
520
- }
521
- }
522
- }
523
-
524
- Register-ObjectEvent $watcher "Changed" -Action $action | Out-Null
525
- Register-ObjectEvent $watcher "Created" -Action $action | Out-Null
526
-
527
- try {
528
- while ($true) { Start-Sleep -Seconds 1 }
529
- } finally {
530
- Get-EventSubscriber | Unregister-Event
531
- $watcher.Dispose()
532
- }
533
- }
534
-
535
- $extraArgs = @()
536
- if ($SubCommand) { $extraArgs += $SubCommand }
537
- if ($Arg1) { $extraArgs += $Arg1 }
538
- if ($Arg2) { $extraArgs += $Arg2 }
539
- if ($RemainingArgs) { $extraArgs += $RemainingArgs }
540
-
541
- switch ($Command.ToLower()) {
542
- "build" { Cmd-Build }
543
- "pdf" { Cmd-Build-PDF }
544
- "docx" { Cmd-Build-DOCX }
545
- "init" { Cmd-Init }
546
- "stats" { Cmd-Stats $extraArgs }
547
- "doctor" { Cmd-Doctor $extraArgs }
548
- "bundle" { Cmd-Bundle $extraArgs }
549
- "setup" { & powershell -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot "scripts\setup-deps.ps1") }
550
- "mcp" {
551
- if (Get-Command "node" -ErrorAction SilentlyContinue) {
552
- $mcpPath = Join-Path $PSScriptRoot "bin\mcp-server.js"
553
- if (Test-Path $mcpPath) {
554
- node $mcpPath @extraArgs
555
- } elseif (Get-Command "npx" -ErrorAction SilentlyContinue) {
556
- npx -y laporan-generator mcp @extraArgs
557
- } else {
558
- Write-Host "bin\mcp-server.js tidak ditemukan dan npx tidak tersedia." -ForegroundColor Red
559
- }
560
- } else {
561
- Write-Host "Node.js diperlukan untuk menjalankan MCP Server." -ForegroundColor Yellow
562
- }
563
- }
564
- "sync-skills" {
565
- if (Get-Command "node" -ErrorAction SilentlyContinue) {
566
- $genPath = Join-Path $PSScriptRoot "bin\laporan-generator.js"
567
- if (Test-Path $genPath) {
568
- node $genPath sync-hosts @extraArgs
569
- } elseif (Get-Command "npx" -ErrorAction SilentlyContinue) {
570
- npx -y laporan-generator sync-hosts @extraArgs
571
- } else {
572
- Write-Host "bin\laporan-generator.js tidak ditemukan dan npx tidak tersedia." -ForegroundColor Red
573
- }
574
- } else {
575
- Write-Host "Node.js diperlukan untuk sinkronisasi multi-host AI agent." -ForegroundColor Yellow
576
- }
577
- }
578
- "sync-hosts" {
579
- if (Get-Command "node" -ErrorAction SilentlyContinue) {
580
- $genPath = Join-Path $PSScriptRoot "bin\laporan-generator.js"
581
- if (Test-Path $genPath) {
582
- node $genPath sync-hosts @extraArgs
583
- } elseif (Get-Command "npx" -ErrorAction SilentlyContinue) {
584
- npx -y laporan-generator sync-hosts @extraArgs
585
- } else {
586
- Write-Host "bin\laporan-generator.js tidak ditemukan dan npx tidak tersedia." -ForegroundColor Red
587
- }
588
- } else {
589
- Write-Host "Node.js diperlukan untuk sinkronisasi multi-host AI agent." -ForegroundColor Yellow
590
- }
591
- }
592
- "uninstall" {
593
- if (Get-Command "node" -ErrorAction SilentlyContinue) {
594
- $genPath = Join-Path $PSScriptRoot "bin\laporan-generator.js"
595
- if (Test-Path $genPath) {
596
- node $genPath uninstall @extraArgs
597
- } elseif (Get-Command "npx" -ErrorAction SilentlyContinue) {
598
- npx -y laporan-generator uninstall @extraArgs
599
- } else {
600
- Write-Host "bin\laporan-generator.js tidak ditemukan dan npx tidak tersedia." -ForegroundColor Red
601
- }
602
- } else {
603
- Write-Host "Node.js diperlukan untuk membersihkan integrasi AI agent." -ForegroundColor Yellow
604
- }
605
- }
606
- "clean-skills" {
607
- if (Get-Command "node" -ErrorAction SilentlyContinue) {
608
- $genPath = Join-Path $PSScriptRoot "bin\laporan-generator.js"
609
- if (Test-Path $genPath) {
610
- node $genPath uninstall @extraArgs
611
- } elseif (Get-Command "npx" -ErrorAction SilentlyContinue) {
612
- npx -y laporan-generator uninstall @extraArgs
613
- } else {
614
- Write-Host "bin\laporan-generator.js tidak ditemukan dan npx tidak tersedia." -ForegroundColor Red
615
- }
616
- } else {
617
- Write-Host "Node.js diperlukan untuk membersihkan integrasi AI agent." -ForegroundColor Yellow
618
- }
619
- }
620
- "check" { Cmd-Check }
621
- "clean" { Cmd-Clean }
622
- "view" { Cmd-View }
623
- "watch" { Cmd-Watch }
624
- "test" { Cmd-Test }
625
- "preset" { Cmd-Preset $SubCommand $Arg1 $Arg2 }
626
- "help" { Show-Help }
627
- default { Show-Help }
628
- }
1
+ # ==============================================================================
2
+ # Laporan Generator CLI Helper for Windows PowerShell (.\laporan.ps1)
3
+ # ==============================================================================
4
+ param (
5
+ [Parameter(Position=0)]
6
+ [string]$Command = "help",
7
+ [Parameter(Position=1)]
8
+ [string]$SubCommand = "",
9
+ [Parameter(Position=2)]
10
+ [string]$Arg1 = "",
11
+ [Parameter(Position=3)]
12
+ [string]$Arg2 = "",
13
+ [Parameter(ValueFromRemainingArguments=$true)]
14
+ [string[]]$RemainingArgs
15
+ )
16
+
17
+ $ErrorActionPreference = "Stop"
18
+ $env:PYTHONUTF8 = "1"
19
+
20
+ # Pastikan folder localBin ada di PATH sesi saat ini jika ada
21
+ $localBin = Join-Path $env:LOCALAPPDATA "laporan-generator\bin"
22
+ if ((Test-Path $localBin) -and ($env:Path -notlike "*$localBin*")) {
23
+ $env:Path = "$localBin;$env:Path"
24
+ }
25
+
26
+ function Get-PythonCommand {
27
+ foreach ($cmd in @("python", "python3")) {
28
+ $c = Get-Command $cmd -ErrorAction SilentlyContinue
29
+ if ($c) {
30
+ if ($c.Source -match "WindowsApps\\python") {
31
+ continue
32
+ }
33
+ return $c.Source
34
+ }
35
+ }
36
+ $fallback = Get-Command "python" -ErrorAction SilentlyContinue
37
+ if ($fallback) { return $fallback.Source }
38
+ return ""
39
+ }
40
+
41
+ function Show-Banner {
42
+ Write-Host " ========================================================" -ForegroundColor Cyan
43
+ Write-Host " LAPORAN GENERATOR CLI v3.0.0 " -ForegroundColor Cyan
44
+ Write-Host " Otomatisasi Dokumen Akademik (Typst + DOCX Engine) " -ForegroundColor Cyan
45
+ Write-Host " ========================================================" -ForegroundColor Cyan
46
+ Write-Host ""
47
+ }
48
+
49
+ function Show-Help {
50
+ Show-Banner
51
+ Write-Host "Penggunaan: .\laporan.ps1 <perintah>" -ForegroundColor White
52
+ Write-Host ""
53
+ Write-Host "Perintah yang Tersedia:" -ForegroundColor White
54
+ Write-Host " build Kompilasi PDF dan DOCX sekaligus" -ForegroundColor Green
55
+ Write-Host " pdf Kompilasi dokumen PDF (via Typst)" -ForegroundColor Green
56
+ Write-Host " docx Kompilasi dokumen Microsoft Word (.docx)" -ForegroundColor Green
57
+ Write-Host " init Wizard interaktif untuk konfigurasi awal metadata" -ForegroundColor Green
58
+ Write-Host " preset Kelola preset format kampus (list/show/apply/validate/diff/scan)" -ForegroundColor Green
59
+ Write-Host " stats Analisis statistik kata, halaman, gambar, dan durasi baca" -ForegroundColor Green
60
+ Write-Host " doctor Audit kesehatan proyek (broken images, sitasi hilang, dll.)" -ForegroundColor Green
61
+ Write-Host " bundle Kemas seluruh laporan (PDF, DOCX, MD) menjadi arsip zip" -ForegroundColor Green
62
+ Write-Host " setup Pasang dependensi sistem otomatis Windows (Typst, Pandoc, Magick)" -ForegroundColor Green
63
+ Write-Host " mcp Jalankan Model Context Protocol (MCP) Server untuk AI Agent" -ForegroundColor Green
64
+ Write-Host " sync-skills Sinkronkan skill AI agent & MCP ke Antigravity, Claude, OpenCode" -ForegroundColor Green
65
+ Write-Host " uninstall Hapus integrasi skill dan perintah AI agent dari seluruh sistem" -ForegroundColor Green
66
+ Write-Host " check Audit dependensi sistem dan struktur proyek" -ForegroundColor Green
67
+ Write-Host " test Jalankan suite pengujian otomatis" -ForegroundColor Green
68
+ Write-Host " view Buka dokumen Laporan.pdf di PDF viewer" -ForegroundColor Green
69
+ Write-Host " watch Pantau perubahan berkas dan auto-rebuild" -ForegroundColor Green
70
+ Write-Host " clean Bersihkan berkas output dan direktori sementara" -ForegroundColor Green
71
+ Write-Host " help Tampilkan panduan bantuan ini" -ForegroundColor Green
72
+ Write-Host ""
73
+ Write-Host "Contoh:" -ForegroundColor Yellow
74
+ Write-Host " .\laporan.ps1 build"
75
+ Write-Host " .\laporan.ps1 stats"
76
+ Write-Host " .\laporan.ps1 preset list"
77
+ Write-Host " .\laporan.ps1 preset apply itb-ta"
78
+ }
79
+
80
+ function Cmd-Check {
81
+ Show-Banner
82
+ Write-Host "[1/2] Memeriksa Dependensi Sistem..." -ForegroundColor Blue
83
+
84
+ $pyPath = Get-PythonCommand
85
+ $pyFound = if ($pyPath) { Get-Command $pyPath -ErrorAction SilentlyContinue } else { $null }
86
+
87
+ $imFound = Get-Command "magick" -ErrorAction SilentlyContinue
88
+ if (-not $imFound -and -not ($env:OS -match "Windows")) {
89
+ $imFound = Get-Command "convert" -ErrorAction SilentlyContinue
90
+ }
91
+
92
+ $deps = @(
93
+ @{ Name="Pandoc"; Cmd="pandoc"; Found=(Get-Command "pandoc" -ErrorAction SilentlyContinue); Req=$true },
94
+ @{ Name="Typst"; Cmd="typst"; Found=(Get-Command "typst" -ErrorAction SilentlyContinue); Req=$true },
95
+ @{ Name="ImageMagick"; Cmd="magick/convert"; Found=$imFound; Req=$false },
96
+ @{ Name="Python 3"; Cmd="python/python3"; Found=$pyFound; Req=$true },
97
+ @{ Name="LibreOffice"; Cmd="soffice"; Found=(Get-Command "soffice" -ErrorAction SilentlyContinue); Req=$false }
98
+ )
99
+
100
+ $allOk = $true
101
+ foreach ($d in $deps) {
102
+ if ($d.Found) {
103
+ Write-Host " [OK] $($d.Name) ($($d.Cmd)) terpasang: $($d.Found.Source)" -ForegroundColor Green
104
+ } else {
105
+ if ($d.Req) {
106
+ Write-Host " [FAIL] $($d.Name) ($($d.Cmd)) TIDAK DITEMUKAN (Wajib)" -ForegroundColor Red
107
+ $allOk = $false
108
+ } else {
109
+ Write-Host " [INFO] $($d.Name) ($($d.Cmd)) tidak ditemukan (Opsional)" -ForegroundColor Yellow
110
+ }
111
+ }
112
+ }
113
+
114
+ Write-Host ""
115
+ Write-Host "[2/2] Memeriksa Berkas Proyek..." -ForegroundColor Blue
116
+ $tplPrefix = ""
117
+ if (-not (Test-Path "metadata.yml") -and (Test-Path "templates/default/metadata.yml")) {
118
+ $tplPrefix = "templates/default/"
119
+ }
120
+ $files = @("metadata.yml", "cover.md", "template.typ", "reference.docx", "references.bib", "docx.lua")
121
+ foreach ($f in $files) {
122
+ $targetPath = Join-Path $tplPrefix $f
123
+ if (Test-Path $targetPath) {
124
+ Write-Host " [OK] Berkas $f ditemukan ($targetPath)" -ForegroundColor Green
125
+ } else {
126
+ Write-Host " [FAIL] Berkas $f tidak ditemukan" -ForegroundColor Red
127
+ $allOk = $false
128
+ }
129
+ }
130
+
131
+ $dirs = @("presets", "${tplPrefix}chapters")
132
+ foreach ($d in $dirs) {
133
+ if (Test-Path $d) {
134
+ Write-Host " [OK] Direktori $d ditemukan" -ForegroundColor Green
135
+ } else {
136
+ Write-Host " [FAIL] Direktori $d tidak ditemukan" -ForegroundColor Red
137
+ $allOk = $false
138
+ }
139
+ }
140
+
141
+ Write-Host ""
142
+ if ($allOk) {
143
+ Write-Host "Semua dependensi dan berkas proyek lengkap dan siap digunakan!" -ForegroundColor Green
144
+ } else {
145
+ Write-Host "Ada beberapa komponen yang kurang. Gunakan Docker jika ingin bebas instalasi lokal." -ForegroundColor Yellow
146
+ }
147
+ }
148
+
149
+ function Cmd-Build-PDF {
150
+ Show-Banner
151
+ Write-Host "Membangun Dokumen PDF (Typst Engine)..." -ForegroundColor Blue
152
+
153
+ $inputFiles = @("cover.md") + (Get-ChildItem -Path "chapters" -Filter "bab*.md" | Sort-Object Name | ForEach-Object { $_.FullName })
154
+ $presetOpt = ""
155
+ if (Test-Path "metadata.yml") {
156
+ $content = Get-Content "metadata.yml" -Raw
157
+ if ($content -match "(?:preset|margin_preset)\s*:\s*[`"']?([a-zA-Z0-9_-]+)[`"']?") {
158
+ $presetName = $matches[1]
159
+ if (Test-Path "presets\$presetName.yml") {
160
+ $presetOpt = "--metadata-file=presets\$presetName.yml"
161
+ }
162
+ }
163
+ }
164
+
165
+ $pandocArgs = @()
166
+ $pandocArgs += $inputFiles
167
+ $pandocArgs += "--template=template.typ"
168
+ if ($presetOpt) { $pandocArgs += $presetOpt }
169
+ $pandocArgs += "--metadata-file=metadata.yml"
170
+ $pandocArgs += "--citeproc"
171
+ $pandocArgs += "--bibliography=references.bib"
172
+ $pandocArgs += "--csl=apa.csl"
173
+ $pandocArgs += "--metadata=reference-section-title=DAFTAR PUSTAKA"
174
+ $pandocArgs += "--top-level-division=chapter"
175
+ $pandocArgs += "--pdf-engine=typst"
176
+ $pandocArgs += "--no-highlight"
177
+ $pandocArgs += @("-o", "Laporan.pdf")
178
+
179
+ & pandoc $pandocArgs
180
+ if ($LASTEXITCODE -eq 0) {
181
+ Write-Host ""
182
+ Write-Host "=== PDF BERHASIL DIBUAT ===" -ForegroundColor Green
183
+ Write-Host "Lokasi: $(Get-Location)\Laporan.pdf" -ForegroundColor Cyan
184
+ } else {
185
+ Write-Host "[ERROR] Kompilasi PDF gagal." -ForegroundColor Red
186
+ }
187
+ }
188
+
189
+ function Cmd-Build-DOCX {
190
+ Show-Banner
191
+ Write-Host "Membangun Dokumen Microsoft Word (DOCX Multi-Pass)..." -ForegroundColor Blue
192
+
193
+ if (-not (Test-Path "chapters")) {
194
+ Write-Host "[ERROR] Direktori chapters/ tidak ditemukan." -ForegroundColor Red
195
+ return
196
+ }
197
+
198
+ $pyCmd = Get-PythonCommand
199
+ if (-not $pyCmd) {
200
+ Write-Host "[ERROR] Python 3 dibutuhkan untuk memproses DOCX." -ForegroundColor Red
201
+ return
202
+ }
203
+
204
+ $inputFiles = @("cover.md") + (Get-ChildItem -Path "chapters" -Filter "bab*.md" | Sort-Object Name | ForEach-Object { $_.FullName })
205
+ $presetOpt = ""
206
+ if (Test-Path "metadata.yml") {
207
+ $content = Get-Content "metadata.yml" -Raw
208
+ if ($content -match "(?:preset|margin_preset)\s*:\s*[`"']?([a-zA-Z0-9_-]+)[`"']?") {
209
+ $presetName = $matches[1]
210
+ if (Test-Path "presets\$presetName.yml") {
211
+ $presetOpt = "--metadata-file=presets\$presetName.yml"
212
+ }
213
+ }
214
+ }
215
+
216
+ $tmpDocx = [System.IO.Path]::GetTempFileName() + ".docx"
217
+ $sectDocx = [System.IO.Path]::GetTempFileName() + ".docx"
218
+
219
+ try {
220
+ $pandocArgs = @()
221
+ $pandocArgs += $inputFiles
222
+ if ($presetOpt) { $pandocArgs += $presetOpt }
223
+ $pandocArgs += "--metadata-file=metadata.yml"
224
+ $pandocArgs += "--citeproc"
225
+ $pandocArgs += "--bibliography=references.bib"
226
+ $pandocArgs += "--csl=apa.csl"
227
+ $pandocArgs += "--metadata=reference-section-title=DAFTAR PUSTAKA"
228
+ $pandocArgs += "--top-level-division=chapter"
229
+ $pandocArgs += "--reference-doc=reference.docx"
230
+ $pandocArgs += "--lua-filter=docx.lua"
231
+ $pandocArgs += @("-o", $tmpDocx)
232
+
233
+ & pandoc $pandocArgs
234
+ if ($LASTEXITCODE -ne 0) {
235
+ Write-Host "[ERROR] Kompilasi Pandoc ke DOCX gagal." -ForegroundColor Red
236
+ return
237
+ }
238
+
239
+ & $pyCmd scripts/finalize-docx.py $tmpDocx $sectDocx
240
+ & $pyCmd scripts/docx-pagenum.py $sectDocx Laporan.docx
241
+
242
+ if (Test-Path "Laporan.docx") {
243
+ Write-Host ""
244
+ Write-Host "=== DOCX BERHASIL DIBUAT ===" -ForegroundColor Green
245
+ Write-Host "Lokasi: $(Get-Location)\Laporan.docx" -ForegroundColor Cyan
246
+ }
247
+ } finally {
248
+ Remove-Item -Force -ErrorAction SilentlyContinue $tmpDocx, $sectDocx
249
+ }
250
+ }
251
+
252
+ function Cmd-Build {
253
+ Show-Banner
254
+ Write-Host "[1/2] Membangun Dokumen PDF (Typst Engine)..." -ForegroundColor Blue
255
+ Cmd-Build-PDF
256
+ Write-Host ""
257
+ Write-Host "[2/2] Membangun Dokumen Microsoft Word (DOCX Multi-Pass)..." -ForegroundColor Blue
258
+ Cmd-Build-DOCX
259
+ Write-Host ""
260
+ Write-Host "Dokumen PDF dan DOCX berhasil diproses!" -ForegroundColor Green
261
+ }
262
+
263
+ function Escape-Yaml {
264
+ param ([string]$Val)
265
+ if (-not $Val) { return "" }
266
+ $Val = $Val -replace "\\", "\\\\"
267
+ $Val = $Val -replace '"', '\"'
268
+ $Val = $Val -replace "`r", ""
269
+ $Val = $Val -replace "`n", " "
270
+ return $Val
271
+ }
272
+
273
+ function Cmd-Init {
274
+ Show-Banner
275
+ Write-Host "Wizard Konfigurasi Laporan Akademik (Windows PowerShell)" -ForegroundColor Cyan
276
+ Write-Host "Isi data di bawah ini (tekan Enter untuk memakai nilai default):"
277
+ Write-Host ""
278
+
279
+ $in_title = Read-Host "Judul Laporan [LAPORAN PROYEK AKADEMIK]"
280
+ if (-not $in_title) { $in_title = "LAPORAN PROYEK AKADEMIK" }
281
+
282
+ $in_subtitle = Read-Host "Subjudul [DOKUMENTASI DAN ANALISIS IMPLEMENTASI]"
283
+ if (-not $in_subtitle) { $in_subtitle = "DOKUMENTASI DAN ANALISIS IMPLEMENTASI" }
284
+
285
+ $in_course = Read-Host "Mata Kuliah [Proyek Perangkat Lunak]"
286
+ if (-not $in_course) { $in_course = "Proyek Perangkat Lunak" }
287
+
288
+ $in_lecturer = Read-Host "Dosen Pengampu [Dr. Nama Dosen, M.Kom.]"
289
+ if (-not $in_lecturer) { $in_lecturer = "Dr. Nama Dosen, M.Kom." }
290
+
291
+ $in_author = Read-Host "Nama Penulis 1 [Nama Mahasiswa]"
292
+ if (-not $in_author) { $in_author = "Nama Mahasiswa" }
293
+
294
+ $in_nim = Read-Host "NIM Penulis 1 [12345678]"
295
+ if (-not $in_nim) { $in_nim = "12345678" }
296
+
297
+ $in_institution = Read-Host "Institusi/Universitas [UNIVERSITAS TEKNOLOGI]"
298
+ if (-not $in_institution) { $in_institution = "UNIVERSITAS TEKNOLOGI" }
299
+
300
+ $in_faculty = Read-Host "Fakultas [FAKULTAS ILMU KOMPUTER]"
301
+ if (-not $in_faculty) { $in_faculty = "FAKULTAS ILMU KOMPUTER" }
302
+
303
+ $in_year = Read-Host "Tahun Akademik [2026/2027]"
304
+ if (-not $in_year) { $in_year = "2026/2027" }
305
+
306
+ Write-Host ""
307
+ Write-Host "Pilihan Preset Format Kampus:" -ForegroundColor Blue
308
+ Write-Host " standard / skripsi-4433 / ui-skripsi / itb-ta / ugm-skripsi / its-skripsi / unpad-skripsi"
309
+ $in_preset = Read-Host "Preset Format [standard]"
310
+ if (-not $in_preset) { $in_preset = "standard" }
311
+
312
+ $curDate = (Get-Date -Format "MMMM yyyy")
313
+
314
+ $escTitle = Escape-Yaml $in_title
315
+ $escSubtitle = Escape-Yaml $in_subtitle
316
+ $escCourse = Escape-Yaml $in_course
317
+ $escLecturer = Escape-Yaml $in_lecturer
318
+ $escAuthor = Escape-Yaml $in_author
319
+ $escNim = Escape-Yaml $in_nim
320
+ $escInstitution = Escape-Yaml $in_institution
321
+ $escFaculty = Escape-Yaml $in_faculty
322
+ $escYear = Escape-Yaml $in_year
323
+ $escPreset = Escape-Yaml $in_preset
324
+
325
+ $yamlContent = @"
326
+ title: "$escTitle"
327
+ subtitle: "$escSubtitle"
328
+ course: "$escCourse"
329
+ lecturer: "$escLecturer"
330
+ author:
331
+ - name: "$escAuthor"
332
+ nim: "$escNim"
333
+ institution: "$escInstitution"
334
+ faculty: "$escFaculty"
335
+ year: "$escYear"
336
+ date: "$curDate"
337
+ preset: "$escPreset"
338
+ "@
339
+
340
+ Set-Content -Path "metadata.yml" -Value $yamlContent
341
+ Write-Host ""
342
+ Write-Host "metadata.yml berhasil diperbarui!" -ForegroundColor Green
343
+ Write-Host "Jalankan '.\laporan.ps1 build' untuk mulai menghasilkan laporan." -ForegroundColor Cyan
344
+ }
345
+
346
+ function Cmd-Test {
347
+ Show-Banner
348
+ Write-Host "Menjalankan Test Suite..." -ForegroundColor Blue
349
+ $gitBash = "C:\Program Files\Git\bin\bash.exe"
350
+ $bashCmd = if (Test-Path $gitBash) { $gitBash } elseif ((Get-Command "bash" -ErrorAction SilentlyContinue) -and (Get-Command "bash").Source -notmatch "system32\\bash\.exe") { "bash" } else { "" }
351
+ if ($bashCmd -and (Test-Path "test.sh")) {
352
+ & $bashCmd test.sh
353
+ } else {
354
+ $pyCmd = Get-PythonCommand
355
+ if ($pyCmd) {
356
+ Write-Host "Menjalankan validasi skema preset..." -ForegroundColor Blue
357
+ if (Test-Path "scripts/validate-preset.py") {
358
+ & $pyCmd scripts/validate-preset.py --all
359
+ }
360
+ if (Test-Path "scripts/test_scripts.py") {
361
+ Write-Host ""
362
+ Write-Host "Menjalankan unit test skrip Python..." -ForegroundColor Blue
363
+ & $pyCmd scripts/test_scripts.py
364
+ }
365
+ } else {
366
+ Write-Host "Test suite membutuhkan bash atau python3." -ForegroundColor Yellow
367
+ }
368
+ }
369
+ }
370
+
371
+ function Cmd-Preset {
372
+ param ($Sub, $P1, $P2)
373
+ $pyCmd = Get-PythonCommand
374
+
375
+ switch ($Sub) {
376
+ "list" {
377
+ Show-Banner
378
+ Write-Host "Daftar Preset Format Kampus Tersedia:" -ForegroundColor Blue
379
+ Write-Host ""
380
+ Get-ChildItem -Path "presets" -Filter "*.yml" | ForEach-Object {
381
+ $presetId = $_.BaseName
382
+ $name = (Select-String -Path $_.FullName -Pattern "^\s*name:\s*`"?(.*?)`"?\s*$" | Select-Object -First 1).Matches.Groups[1].Value
383
+ $desc = (Select-String -Path $_.FullName -Pattern "^\s*description:\s*`"?(.*?)`"?\s*$" | Select-Object -First 1).Matches.Groups[1].Value
384
+ Write-Host " * $presetId - $name" -ForegroundColor Green
385
+ if ($desc) { Write-Host " $desc" -ForegroundColor Gray }
386
+ Write-Host ""
387
+ }
388
+ }
389
+ "show" {
390
+ if (-not $P1) { Write-Host "Error: Sebutkan ID preset. Contoh: .\laporan.ps1 preset show itb-ta" -ForegroundColor Red; return }
391
+ $file = "presets\$P1.yml"
392
+ if (Test-Path $file) {
393
+ Show-Banner
394
+ Write-Host "Konfigurasi Preset: $P1" -ForegroundColor Cyan
395
+ Write-Host "--------------------------------------------------------"
396
+ Get-Content $file
397
+ Write-Host "--------------------------------------------------------"
398
+ } else {
399
+ Write-Host "Preset '$P1' tidak ditemukan." -ForegroundColor Red
400
+ }
401
+ }
402
+ "apply" {
403
+ if (-not $P1) { Write-Host "Error: Sebutkan ID preset. Contoh: .\laporan.ps1 preset apply itb-ta" -ForegroundColor Red; return }
404
+ $file = "presets\$P1.yml"
405
+ if (-not (Test-Path $file)) { Write-Host "Preset '$P1' tidak ditemukan." -ForegroundColor Red; return }
406
+ if (-not (Test-Path "metadata.yml")) { Write-Host "metadata.yml tidak ditemukan." -ForegroundColor Red; return }
407
+
408
+ $content = Get-Content "metadata.yml" -Raw
409
+ if ($content -match "preset\s*:") {
410
+ $content = $content -replace "preset\s*:.*", "preset: `"$P1`""
411
+ } else {
412
+ $content += "`npreset: `"$P1`""
413
+ }
414
+ Set-Content -Path "metadata.yml" -Value $content -NoNewline
415
+ Write-Host "[OK] Preset '$P1' berhasil diterapkan ke metadata.yml!" -ForegroundColor Green
416
+ }
417
+ "validate" {
418
+ if (-not $pyCmd) { Write-Host "Error: Python 3 tidak ditemukan." -ForegroundColor Red; return }
419
+ if ($P1) {
420
+ $tgt = $P1
421
+ if (Test-Path "presets\$tgt.yml") { $tgt = "presets\$tgt.yml" }
422
+ & $pyCmd scripts/validate-preset.py $tgt
423
+ } else {
424
+ & $pyCmd scripts/validate-preset.py --all
425
+ }
426
+ }
427
+ "diff" {
428
+ if (-not $P1) { Write-Host "Error: Sebutkan setidaknya 1 preset untuk dibandingkan." -ForegroundColor Red; return }
429
+ $f1 = "presets\$P1.yml"
430
+ if (-not (Test-Path $f1)) { Write-Host "Preset '$P1' tidak ditemukan." -ForegroundColor Red; return }
431
+ if ($P2) {
432
+ $f2 = "presets\$P2.yml"
433
+ if (-not (Test-Path $f2)) { Write-Host "Preset '$P2' tidak ditemukan." -ForegroundColor Red; return }
434
+ Compare-Object (Get-Content $f1) (Get-Content $f2)
435
+ } else {
436
+ $curr = "standard"
437
+ if (Test-Path "metadata.yml") {
438
+ $content = Get-Content "metadata.yml" -Raw
439
+ if ($content -match "(?:preset|margin_preset)\s*:\s*[`"']?([a-zA-Z0-9_-]+)[`"']?") {
440
+ $curr = $matches[1]
441
+ }
442
+ }
443
+ $f2 = "presets\$curr.yml"
444
+ Compare-Object (Get-Content $f2) (Get-Content $f1)
445
+ }
446
+ }
447
+ "scan" {
448
+ if (-not $pyCmd) { Write-Host "Error: Python 3 tidak ditemukan." -ForegroundColor Red; return }
449
+ if (-not $P1) { Write-Host "Error: Masukkan path file PDF pedoman kampus." -ForegroundColor Red; return }
450
+ & $pyCmd scripts/scan-preset.py $P1 $P2
451
+ }
452
+ default {
453
+ Write-Host "Gunakan: .\laporan.ps1 preset [list | show <id> | apply <id> | validate | diff <id> | scan <file>]" -ForegroundColor Yellow
454
+ }
455
+ }
456
+ }
457
+
458
+ function Cmd-Clean {
459
+ Remove-Item -Force -ErrorAction SilentlyContinue Laporan.pdf, Laporan.docx, Laporan.html
460
+ Remove-Item -Recurse -Force -ErrorAction SilentlyContinue tmp, dist
461
+ Write-Host "[OK] Berkas output berhasil dibersihkan." -ForegroundColor Green
462
+ }
463
+
464
+ function Cmd-Stats {
465
+ param([string[]]$ArgsList)
466
+ $pyCmd = Get-PythonCommand
467
+ if ($pyCmd) {
468
+ & $pyCmd scripts/report-stats.py @ArgsList
469
+ } else {
470
+ Write-Host "Error: Python 3 tidak ditemukan." -ForegroundColor Red
471
+ }
472
+ }
473
+
474
+ function Cmd-Doctor {
475
+ param([string[]]$ArgsList)
476
+ $pyCmd = Get-PythonCommand
477
+ if ($pyCmd) {
478
+ & $pyCmd scripts/report-doctor.py @ArgsList
479
+ } else {
480
+ Write-Host "Error: Python 3 tidak ditemukan." -ForegroundColor Red
481
+ }
482
+ }
483
+
484
+ function Cmd-Bundle {
485
+ param([string[]]$ArgsList)
486
+ $pyCmd = Get-PythonCommand
487
+ if ($pyCmd) {
488
+ & $pyCmd scripts/bundle.py @ArgsList
489
+ } else {
490
+ Write-Host "Error: Python 3 tidak ditemukan." -ForegroundColor Red
491
+ }
492
+ }
493
+
494
+ function Cmd-View {
495
+ if (Test-Path "Laporan.pdf") {
496
+ Start-Process "Laporan.pdf"
497
+ } else {
498
+ Write-Host "Laporan.pdf belum dibuat. Jalankan '.\laporan.ps1 build' terlebih dahulu." -ForegroundColor Red
499
+ }
500
+ }
501
+
502
+ function Cmd-Watch {
503
+ Show-Banner
504
+ Write-Host "Memantau perubahan berkas dan auto-rebuild... (Tekan Ctrl+C untuk berhenti)" -ForegroundColor Cyan
505
+ $scriptPath = $MyInvocation.MyCommand.Definition
506
+ if (-not $scriptPath) { $scriptPath = $PSCommandPath }
507
+ if (-not $scriptPath) { $scriptPath = ".\laporan.ps1" }
508
+
509
+ $watcher = New-Object System.IO.FileSystemWatcher
510
+ $watcher.Path = (Get-Location).Path
511
+ $watcher.IncludeSubdirectories = $true
512
+ $watcher.EnableRaisingEvents = $true
513
+ $watcher.Filter = "*.*"
514
+
515
+ $action = {
516
+ $path = $Event.SourceEventArgs.FullPath
517
+ if ($path -notmatch '(\.pdf|\.docx|tmp|dist|\.git)' -and ($path -match '(\.md|\.typ|\.yml|\.bib)')) {
518
+ Write-Host "[Perubahan Terdeteksi] $path -> Membangun ulang..." -ForegroundColor Yellow
519
+ if (Get-Command Cmd-Build -ErrorAction SilentlyContinue) {
520
+ Cmd-Build
521
+ } elseif ($using:scriptPath -and (Test-Path $using:scriptPath)) {
522
+ & powershell -ExecutionPolicy Bypass -File $using:scriptPath build
523
+ } else {
524
+ powershell -ExecutionPolicy Bypass -File ".\laporan.ps1" build
525
+ }
526
+ }
527
+ }
528
+
529
+ Register-ObjectEvent $watcher "Changed" -Action $action | Out-Null
530
+ Register-ObjectEvent $watcher "Created" -Action $action | Out-Null
531
+
532
+ try {
533
+ while ($true) { Start-Sleep -Seconds 1 }
534
+ } finally {
535
+ Get-EventSubscriber | Unregister-Event
536
+ $watcher.Dispose()
537
+ }
538
+ }
539
+
540
+ $extraArgs = @()
541
+ if ($SubCommand) { $extraArgs += $SubCommand }
542
+ if ($Arg1) { $extraArgs += $Arg1 }
543
+ if ($Arg2) { $extraArgs += $Arg2 }
544
+ if ($RemainingArgs) { $extraArgs += $RemainingArgs }
545
+
546
+ switch ($Command.ToLower()) {
547
+ "build" { Cmd-Build }
548
+ "pdf" { Cmd-Build-PDF }
549
+ "docx" { Cmd-Build-DOCX }
550
+ "init" { Cmd-Init }
551
+ "import" { & (Get-Python-Command) (Join-Path $PSScriptRoot "scripts\ingest.py") @extraArgs }
552
+ "ingest" { & (Get-Python-Command) (Join-Path $PSScriptRoot "scripts\ingest.py") @extraArgs }
553
+ "stats" { Cmd-Stats $extraArgs }
554
+ "doctor" { Cmd-Doctor $extraArgs }
555
+ "bundle" { Cmd-Bundle $extraArgs }
556
+ "setup" { & powershell -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot "scripts\setup-deps.ps1") }
557
+ "mcp" {
558
+ if (Get-Command "node" -ErrorAction SilentlyContinue) {
559
+ $mcpPath = Join-Path $PSScriptRoot "bin\mcp-server.js"
560
+ if (Test-Path $mcpPath) {
561
+ node $mcpPath @extraArgs
562
+ } elseif (Get-Command "npx" -ErrorAction SilentlyContinue) {
563
+ npx -y laporan-generator mcp @extraArgs
564
+ } else {
565
+ Write-Host "bin\mcp-server.js tidak ditemukan dan npx tidak tersedia." -ForegroundColor Red
566
+ }
567
+ } else {
568
+ Write-Host "Node.js diperlukan untuk menjalankan MCP Server." -ForegroundColor Yellow
569
+ }
570
+ }
571
+ "sync-skills" {
572
+ if (Get-Command "node" -ErrorAction SilentlyContinue) {
573
+ $genPath = Join-Path $PSScriptRoot "bin\laporan-generator.js"
574
+ if (Test-Path $genPath) {
575
+ node $genPath sync-hosts @extraArgs
576
+ } elseif (Get-Command "npx" -ErrorAction SilentlyContinue) {
577
+ npx -y laporan-generator sync-hosts @extraArgs
578
+ } else {
579
+ Write-Host "bin\laporan-generator.js tidak ditemukan dan npx tidak tersedia." -ForegroundColor Red
580
+ }
581
+ } else {
582
+ Write-Host "Node.js diperlukan untuk sinkronisasi multi-host AI agent." -ForegroundColor Yellow
583
+ }
584
+ }
585
+ "sync-hosts" {
586
+ if (Get-Command "node" -ErrorAction SilentlyContinue) {
587
+ $genPath = Join-Path $PSScriptRoot "bin\laporan-generator.js"
588
+ if (Test-Path $genPath) {
589
+ node $genPath sync-hosts @extraArgs
590
+ } elseif (Get-Command "npx" -ErrorAction SilentlyContinue) {
591
+ npx -y laporan-generator sync-hosts @extraArgs
592
+ } else {
593
+ Write-Host "bin\laporan-generator.js tidak ditemukan dan npx tidak tersedia." -ForegroundColor Red
594
+ }
595
+ } else {
596
+ Write-Host "Node.js diperlukan untuk sinkronisasi multi-host AI agent." -ForegroundColor Yellow
597
+ }
598
+ }
599
+ "uninstall" {
600
+ if (Get-Command "node" -ErrorAction SilentlyContinue) {
601
+ $genPath = Join-Path $PSScriptRoot "bin\laporan-generator.js"
602
+ if (Test-Path $genPath) {
603
+ node $genPath uninstall @extraArgs
604
+ } elseif (Get-Command "npx" -ErrorAction SilentlyContinue) {
605
+ npx -y laporan-generator uninstall @extraArgs
606
+ } else {
607
+ Write-Host "bin\laporan-generator.js tidak ditemukan dan npx tidak tersedia." -ForegroundColor Red
608
+ }
609
+ } else {
610
+ Write-Host "Node.js diperlukan untuk membersihkan integrasi AI agent." -ForegroundColor Yellow
611
+ }
612
+ }
613
+ "clean-skills" {
614
+ if (Get-Command "node" -ErrorAction SilentlyContinue) {
615
+ $genPath = Join-Path $PSScriptRoot "bin\laporan-generator.js"
616
+ if (Test-Path $genPath) {
617
+ node $genPath uninstall @extraArgs
618
+ } elseif (Get-Command "npx" -ErrorAction SilentlyContinue) {
619
+ npx -y laporan-generator uninstall @extraArgs
620
+ } else {
621
+ Write-Host "bin\laporan-generator.js tidak ditemukan dan npx tidak tersedia." -ForegroundColor Red
622
+ }
623
+ } else {
624
+ Write-Host "Node.js diperlukan untuk membersihkan integrasi AI agent." -ForegroundColor Yellow
625
+ }
626
+ }
627
+ "check" { Cmd-Check }
628
+ "clean" { Cmd-Clean }
629
+ "view" { Cmd-View }
630
+ "watch" { Cmd-Watch }
631
+ "test" { Cmd-Test }
632
+ "preset" { Cmd-Preset $SubCommand $Arg1 $Arg2 }
633
+ "help" { Show-Help }
634
+ default { Show-Help }
635
+ }