@helloao/cli 0.0.13 → 0.0.14

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/esm/index.js CHANGED
@@ -5738,11 +5738,10 @@ var db_exports = {};
5738
5738
  __export(db_exports, {
5739
5739
  getChangedOrNewInputFiles: () => getChangedOrNewInputFiles,
5740
5740
  getDb: () => getDb,
5741
- getDbFromDir: () => getDbFromDir,
5742
5741
  getDbPath: () => getDbPath,
5743
5742
  getDbPathFromDir: () => getDbPathFromDir,
5744
5743
  getMigrationsPath: () => getMigrationsPath,
5745
- getPrismaDbFromDir: () => getPrismaDbFromDir,
5744
+ getPrismaDb: () => getPrismaDb,
5746
5745
  importCommentaries: () => importCommentaries,
5747
5746
  importFileBatch: () => importFileBatch,
5748
5747
  importFiles: () => importFiles,
@@ -6954,8 +6953,9 @@ function getDbPath(p) {
6954
6953
  }
6955
6954
  return getDbPathFromDir(process.cwd());
6956
6955
  }
6957
- function getPrismaDbFromDir(dir) {
6958
- const dbPath = getDbPathFromDir(dir);
6956
+ function getPrismaDb(path5) {
6957
+ const dbPath = getDbPath(path5);
6958
+ console.log("Opening database at", dbPath);
6959
6959
  const prisma = new import_prisma_gen.PrismaClient({
6960
6960
  datasources: {
6961
6961
  db: {
@@ -6965,12 +6965,13 @@ function getPrismaDbFromDir(dir) {
6965
6965
  });
6966
6966
  return prisma;
6967
6967
  }
6968
- async function getDbFromDir(dir) {
6969
- const dbPath = getDbPathFromDir(dir);
6970
- const db = await getDb(dbPath);
6968
+ async function getDb(path5) {
6969
+ const dbPath = getDbPath(path5);
6970
+ const db = await getDbFromPath(dbPath);
6971
6971
  return db;
6972
6972
  }
6973
- async function getDb(dbPath) {
6973
+ async function getDbFromPath(dbPath) {
6974
+ console.log("Opening database at", dbPath);
6974
6975
  const logger = log2.getLogger();
6975
6976
  const migrationsPath = await getMigrationsPath();
6976
6977
  if (!migrationsPath) {
@@ -8042,7 +8043,7 @@ async function initDb(dbPath, options) {
8042
8043
  }
8043
8044
  }
8044
8045
  } else {
8045
- const db = await getDb(getDbPath(dbPath));
8046
+ const db = await getDb(dbPath);
8046
8047
  db.close();
8047
8048
  }
8048
8049
  }
@@ -8051,7 +8052,7 @@ async function importTranslation(dir, dirs, options) {
8051
8052
  globalThis.DOMParser = DOMParser;
8052
8053
  globalThis.Element = Element;
8053
8054
  globalThis.Node = Node;
8054
- const db = await getDbFromDir(process.cwd());
8055
+ const db = await getDb(options.db);
8055
8056
  try {
8056
8057
  await importTranslations(
8057
8058
  db,
@@ -8069,7 +8070,7 @@ async function importTranslations2(dir, options) {
8069
8070
  globalThis.DOMParser = DOMParser;
8070
8071
  globalThis.Element = Element;
8071
8072
  globalThis.Node = Node;
8072
- const db = await getDbFromDir(process.cwd());
8073
+ const db = await getDb(options.db);
8073
8074
  try {
8074
8075
  const files = await readdir4(dir);
8075
8076
  const translationDirs = files.map((f) => path4.resolve(dir, f));
@@ -8089,7 +8090,7 @@ async function importCommentary(dir, dirs, options) {
8089
8090
  globalThis.DOMParser = DOMParser;
8090
8091
  globalThis.Element = Element;
8091
8092
  globalThis.Node = Node;
8092
- const db = await getDbFromDir(process.cwd());
8093
+ const db = await getDb(options.db);
8093
8094
  try {
8094
8095
  await importCommentaries(
8095
8096
  db,
@@ -8107,7 +8108,7 @@ async function importCommentaries2(dir, options) {
8107
8108
  globalThis.DOMParser = DOMParser;
8108
8109
  globalThis.Element = Element;
8109
8110
  globalThis.Node = Node;
8110
- const db = await getDbFromDir(process.cwd());
8111
+ const db = await getDb(options.db);
8111
8112
  try {
8112
8113
  const files = await readdir4(dir);
8113
8114
  const commentaryDirs = files.map((f) => path4.resolve(dir, f));
@@ -8278,7 +8279,7 @@ Found ${sources.length} sources for '${translationQuery}':`);
8278
8279
  }
8279
8280
  async function sourceTranslations(outputDir, translations, options = {}) {
8280
8281
  const logger = log7.getLogger();
8281
- const {
8282
+ let {
8282
8283
  convertToUsx3 = false,
8283
8284
  useDatabase = true,
8284
8285
  // Default to true
@@ -8313,20 +8314,27 @@ async function sourceTranslations(outputDir, translations, options = {}) {
8313
8314
  let db = null;
8314
8315
  let sourceExists = null;
8315
8316
  let sourceUpsert = null;
8316
- let skippedByDatabase = 0;
8317
8317
  if (useDatabase) {
8318
+ if (!overwrite) {
8319
+ overwrite = true;
8320
+ console.warn(
8321
+ "Overwriting files is enabled due to database tracking."
8322
+ );
8323
+ }
8318
8324
  logger.log("Connecting to database for download tracking...");
8319
- db = await getDbFromDir(process.cwd());
8325
+ db = await getDb(options.db);
8320
8326
  sourceExists = db.prepare(
8321
8327
  "SELECT usfmZipEtag, usfmDownloadDate FROM EBibleSource WHERE id = @id AND sha256 = @sha256;"
8322
8328
  );
8329
+ let skippedByDatabase = 0;
8330
+ let sourcesChecked = 0;
8331
+ let notDownloaded = 0;
8323
8332
  filteredSources = filteredSources.filter((source) => {
8324
- if (overwrite) {
8325
- return true;
8326
- }
8327
8333
  const existingSource = sourceExists.get(source);
8334
+ sourcesChecked++;
8328
8335
  if (existingSource) {
8329
8336
  if (!existingSource.usfmDownloadDate) {
8337
+ notDownloaded++;
8330
8338
  return true;
8331
8339
  }
8332
8340
  source.usfmZipEtag = existingSource.usfmZipEtag;
@@ -8341,13 +8349,18 @@ async function sourceTranslations(outputDir, translations, options = {}) {
8341
8349
  });
8342
8350
  if (skippedByDatabase > 0) {
8343
8351
  logger.log(
8344
- `Database filtering: Skipped ${skippedByDatabase} already downloaded sources`
8352
+ `Database filtering: Skipped ${skippedByDatabase} already downloaded sources.`
8345
8353
  );
8346
8354
  } else {
8347
- logger.log(
8348
- "Database filtering: No sources were skipped (none previously downloaded)"
8349
- );
8355
+ logger.log(`Database filtering: No sources were skipped.`);
8350
8356
  }
8357
+ logger.log(`Database filtering:`);
8358
+ logger.log(` \u2022 Checked: ${sourcesChecked}`);
8359
+ logger.log(` \u2022 Skipped: ${skippedByDatabase}`);
8360
+ logger.log(` \u2022 New: ${notDownloaded}`);
8361
+ logger.log(
8362
+ ` \u2022 Needs Update: ${filteredSources.length - notDownloaded}`
8363
+ );
8351
8364
  sourceUpsert = db.prepare(`INSERT INTO EBibleSource(
8352
8365
  id, translationId, title, shortTitle, languageCode, textDirection, copyright, description,
8353
8366
  oldTestamentBooks, oldTestamentChapters, oldTestamentVerses,
@@ -8554,9 +8567,9 @@ Total selected: ${selectedSources.length} sources from ${sourceGroups.size} tran
8554
8567
  if (!convertToUsx3) {
8555
8568
  source.usfmDownloadDate = DateTime2.utc().toISO();
8556
8569
  source.usfmDownloadPath = outputDir;
8557
- }
8558
- if (sourceUpsert) {
8559
- sourceUpsert.run(source);
8570
+ if (sourceUpsert) {
8571
+ sourceUpsert.run(source);
8572
+ }
8560
8573
  }
8561
8574
  } catch (error) {
8562
8575
  numErrored++;