speclore 0.1.4 → 0.1.6

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/cli/index.js CHANGED
@@ -1413,6 +1413,13 @@ function formatCellValue(value) {
1413
1413
  if (typeof value === "string") return value;
1414
1414
  if (typeof value === "number" || typeof value === "boolean") return String(value);
1415
1415
  if (value instanceof Date) return value.toISOString();
1416
+ if (typeof value === "object" && value !== null && "v" in value) {
1417
+ const cell = value;
1418
+ if (cell.w != null) return cell.w;
1419
+ if (cell.v == null) return "";
1420
+ if (typeof cell.v === "string" || typeof cell.v === "number" || typeof cell.v === "boolean") return String(cell.v);
1421
+ return JSON.stringify(cell.v);
1422
+ }
1416
1423
  return "";
1417
1424
  }
1418
1425
  var init_excel_utils = __esm({
@@ -1422,7 +1429,7 @@ var init_excel_utils = __esm({
1422
1429
  });
1423
1430
 
1424
1431
  // src/plugins/builtin/xlsx-reader.ts
1425
- import ExcelJS from "exceljs";
1432
+ import { readFile, utils } from "xlsx";
1426
1433
  var XlsxReader;
1427
1434
  var init_xlsx_reader = __esm({
1428
1435
  "src/plugins/builtin/xlsx-reader.ts"() {
@@ -1434,27 +1441,23 @@ var init_xlsx_reader = __esm({
1434
1441
  canRead(source) {
1435
1442
  return /\.xlsx$/i.test(source) || /\.xls$/i.test(source);
1436
1443
  }
1437
- async read(source) {
1438
- const workbook = new ExcelJS.Workbook();
1439
- await workbook.xlsx.readFile(source);
1444
+ read(source) {
1445
+ const workbook = readFile(source);
1440
1446
  const requirements = [];
1441
- for (const sheet of workbook.worksheets) {
1442
- const sheetName = sheet.name;
1443
- const headers = [];
1444
- const rows = [];
1445
- sheet.eachRow((row, rowNumber) => {
1446
- if (rowNumber === 1) {
1447
- row.eachCell((cell, colNumber) => {
1448
- headers[colNumber - 1] = formatCellValue(cell.value);
1449
- });
1450
- } else {
1451
- const obj = {};
1452
- row.eachCell((cell, colNumber) => {
1453
- const key = headers[colNumber - 1] ?? `Col${colNumber}`;
1454
- obj[key] = formatCellValue(cell.value);
1455
- });
1456
- rows.push(obj);
1457
- }
1447
+ for (const sheetName of workbook.SheetNames) {
1448
+ const sheet = workbook.Sheets[sheetName];
1449
+ if (!sheet) continue;
1450
+ const allRows = utils.sheet_to_json(sheet, { header: 1, defval: "" });
1451
+ if (allRows.length === 0) continue;
1452
+ const headers = allRows[0].map((cell) => formatCellValue(cell));
1453
+ const dataRows = allRows.slice(1);
1454
+ const rows = dataRows.map((row) => {
1455
+ const obj = {};
1456
+ row.forEach((cell, colNumber) => {
1457
+ const key = headers[colNumber] ?? `Col${colNumber + 1}`;
1458
+ obj[key] = formatCellValue(cell);
1459
+ });
1460
+ return obj;
1458
1461
  });
1459
1462
  for (let i = 0; i < rows.length; i++) {
1460
1463
  const row = rows[i];
@@ -1473,7 +1476,7 @@ var init_xlsx_reader = __esm({
1473
1476
  }
1474
1477
  }
1475
1478
  }
1476
- return requirements;
1479
+ return Promise.resolve(requirements);
1477
1480
  }
1478
1481
  };
1479
1482
  }
@@ -2785,44 +2788,51 @@ var init_docx_reader2 = __esm({
2785
2788
 
2786
2789
  // src/core/requirement-reader/xlsx-reader.ts
2787
2790
  import { basename as basename4, extname as extname4 } from "path";
2788
- import ExcelJS2 from "exceljs";
2789
- async function readXlsxFile(filePath) {
2790
- const workbook = new ExcelJS2.Workbook();
2791
- await workbook.xlsx.readFile(filePath);
2791
+ import { readFile as readFile2, utils as utils2 } from "xlsx";
2792
+ function readXlsxFile(filePath) {
2793
+ const workbook = readFile2(filePath);
2792
2794
  const id = basename4(filePath, extname4(filePath)).toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff-]/g, "-").replace(/-+/g, "-");
2793
- const sheet = workbook.worksheets[0];
2795
+ const firstSheetName = workbook.SheetNames[0];
2796
+ if (!firstSheetName) {
2797
+ return Promise.reject(new Error(`No sheets found in ${filePath}`));
2798
+ }
2799
+ const sheet = workbook.Sheets[firstSheetName];
2794
2800
  if (!sheet) {
2795
- throw new Error(`No sheets found in ${filePath}`);
2796
- }
2797
- const title = sheet.name;
2798
- const headers = [];
2799
- const rows = [];
2800
- sheet.eachRow((row, rowNumber) => {
2801
- if (rowNumber === 1) {
2802
- row.eachCell((cell, colNumber) => {
2803
- headers[colNumber - 1] = formatCellValue(cell.value);
2804
- });
2805
- } else {
2806
- const obj = {};
2807
- row.eachCell((cell, colNumber) => {
2808
- const key = headers[colNumber - 1] ?? `Col${colNumber}`;
2809
- obj[key] = formatCellValue(cell.value);
2810
- });
2811
- rows.push(obj);
2812
- }
2801
+ return Promise.reject(new Error(`Sheet "${firstSheetName}" not found in ${filePath}`));
2802
+ }
2803
+ const title = firstSheetName;
2804
+ const rows = utils2.sheet_to_json(sheet, { header: 1, defval: "" });
2805
+ if (rows.length === 0) {
2806
+ return Promise.resolve({
2807
+ id,
2808
+ title,
2809
+ description: "",
2810
+ rawContent: "",
2811
+ confidence: 0.85
2812
+ });
2813
+ }
2814
+ const headers = rows[0].map((cell) => formatCellValue(cell));
2815
+ const dataRows = rows.slice(1);
2816
+ const objects = dataRows.map((row) => {
2817
+ const obj = {};
2818
+ row.forEach((cell, colNumber) => {
2819
+ const key = headers[colNumber] ?? `Col${colNumber + 1}`;
2820
+ obj[key] = formatCellValue(cell);
2821
+ });
2822
+ return obj;
2813
2823
  });
2814
- const textRows = rows.map((row) => {
2824
+ const textRows = objects.map((row) => {
2815
2825
  const cells = Object.entries(row).map(([key, value]) => `${key}: ${value}`).join(" | ");
2816
2826
  return cells;
2817
2827
  });
2818
2828
  const content = textRows.join("\n");
2819
- return {
2829
+ return Promise.resolve({
2820
2830
  id,
2821
2831
  title,
2822
2832
  description: content,
2823
2833
  rawContent: content,
2824
2834
  confidence: 0.85
2825
- };
2835
+ });
2826
2836
  }
2827
2837
  var init_xlsx_reader2 = __esm({
2828
2838
  "src/core/requirement-reader/xlsx-reader.ts"() {
@@ -2833,10 +2843,10 @@ var init_xlsx_reader2 = __esm({
2833
2843
 
2834
2844
  // src/core/requirement-reader/pdf-reader.ts
2835
2845
  import { basename as basename5, extname as extname5 } from "path";
2836
- import { readFile } from "fs/promises";
2846
+ import { readFile as readFile3 } from "fs/promises";
2837
2847
  async function readPdfFile(filePath) {
2838
2848
  const pdfParse = (await import("pdf-parse")).default;
2839
- const dataBuffer = await readFile(filePath);
2849
+ const dataBuffer = await readFile3(filePath);
2840
2850
  const data = await pdfParse(dataBuffer);
2841
2851
  const id = basename5(filePath, extname5(filePath)).toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff-]/g, "-").replace(/-+/g, "-");
2842
2852
  const lines = data.text.split("\n").filter((l) => l.trim());