simple-photo-gallery 2.0.13 → 2.0.15-rc.18

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/index.cjs CHANGED
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var process4 = require('process');
4
+ var process3 = require('process');
5
5
  var commander = require('commander');
6
6
  var consola = require('consola');
7
7
  var child_process = require('child_process');
8
8
  var fs8 = require('fs');
9
- var path = require('path');
9
+ var path7 = require('path');
10
10
  var buffer = require('buffer');
11
- var url = require('url');
12
11
  var sharp2 = require('sharp');
13
12
  var blurhash = require('blurhash');
14
13
  var common = require('@simple-photo-gallery/common');
@@ -19,12 +18,11 @@ var Conf = require('conf');
19
18
  var axios = require('axios');
20
19
  var semverParser = require('semver-parser');
21
20
 
22
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
23
21
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
24
22
 
25
- var process4__default = /*#__PURE__*/_interopDefault(process4);
23
+ var process3__default = /*#__PURE__*/_interopDefault(process3);
26
24
  var fs8__default = /*#__PURE__*/_interopDefault(fs8);
27
- var path__default = /*#__PURE__*/_interopDefault(path);
25
+ var path7__default = /*#__PURE__*/_interopDefault(path7);
28
26
  var sharp2__default = /*#__PURE__*/_interopDefault(sharp2);
29
27
  var ExifReader__default = /*#__PURE__*/_interopDefault(ExifReader);
30
28
  var ffprobe__default = /*#__PURE__*/_interopDefault(ffprobe);
@@ -92,43 +90,9 @@ async function generateBlurHash(imagePath, componentX = 4, componentY = 3) {
92
90
  }
93
91
 
94
92
  // src/modules/build/utils/index.ts
95
- var __dirname$1 = path__default.default.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
96
- var SOCIAL_CARD_FONT_RELATIVE_PATH = path__default.default.join("assets", "fonts", "dejavu", "DejaVuSans-Bold.ttf");
97
- var socialCardFontBase64;
98
- function resolveFromCurrentDir(...segments) {
99
- return path__default.default.resolve(__dirname$1, ...segments);
100
- }
101
- function findSocialCardFontPath() {
102
- const fontCandidates = [
103
- resolveFromCurrentDir("../../../../", SOCIAL_CARD_FONT_RELATIVE_PATH),
104
- path__default.default.resolve(__dirname$1, "../", SOCIAL_CARD_FONT_RELATIVE_PATH),
105
- path__default.default.resolve(__dirname$1, "../../", SOCIAL_CARD_FONT_RELATIVE_PATH),
106
- path__default.default.resolve(process4__default.default.cwd(), SOCIAL_CARD_FONT_RELATIVE_PATH),
107
- path__default.default.resolve(process4__default.default.cwd(), "../", SOCIAL_CARD_FONT_RELATIVE_PATH),
108
- path__default.default.resolve(process4__default.default.cwd(), "../simple-photo-gallery/", SOCIAL_CARD_FONT_RELATIVE_PATH)
109
- ];
110
- for (const candidate of fontCandidates) {
111
- if (fs8__default.default.existsSync(candidate)) {
112
- return candidate;
113
- }
114
- }
115
- return null;
116
- }
117
- function getSocialCardFontBase64() {
118
- if (socialCardFontBase64 !== void 0) {
119
- return socialCardFontBase64;
120
- }
121
- const fontPath = findSocialCardFontPath();
122
- if (!fontPath) {
123
- socialCardFontBase64 = null;
124
- return null;
125
- }
126
- socialCardFontBase64 = fs8__default.default.readFileSync(fontPath).toString("base64");
127
- return socialCardFontBase64;
128
- }
129
93
  async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPath, ui) {
130
94
  ui?.start(`Creating social media card image`);
131
- const headerBasename = path__default.default.basename(headerPhotoPath, path__default.default.extname(headerPhotoPath));
95
+ const headerBasename = path7__default.default.basename(headerPhotoPath, path7__default.default.extname(headerPhotoPath));
132
96
  if (fs8__default.default.existsSync(ouputPath)) {
133
97
  ui?.success(`Social media card image already exists`);
134
98
  return headerBasename;
@@ -137,21 +101,11 @@ async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPa
137
101
  const resizedImageBuffer = await image.resize(1200, 631, { fit: "cover" }).jpeg({ quality: 90 }).toBuffer();
138
102
  const outputPath = ouputPath;
139
103
  await sharp2__default.default(resizedImageBuffer).toFile(outputPath);
140
- const fontBase64 = getSocialCardFontBase64();
141
- const fontFace = fontBase64 ? `
142
- @font-face {
143
- font-family: 'DejaVu Sans';
144
- src: url('data:font/ttf;base64,${fontBase64}') format('truetype');
145
- font-weight: 700;
146
- font-style: normal;
147
- }` : "";
148
- const fontFamily = fontBase64 ? "'DejaVu Sans', Arial, sans-serif" : "Arial, sans-serif";
149
104
  const svgText = `
150
105
  <svg width="1200" height="631" xmlns="http://www.w3.org/2000/svg">
151
106
  <defs>
152
107
  <style>
153
- ${fontFace}
154
- .title { font-family: ${fontFamily}; font-size: 96px; font-weight: bold; fill: white; stroke: black; stroke-width: 5; paint-order: stroke; text-anchor: middle; }
108
+ .title { font-family: 'Arial, sans-serif'; font-size: 96px; font-weight: bold; fill: white; stroke: black; stroke-width: 5; paint-order: stroke; text-anchor: middle; }
155
109
  </style>
156
110
  </defs>
157
111
  <text x="600" y="250" class="title">${title}</text>
@@ -165,7 +119,7 @@ async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPa
165
119
  async function createOptimizedHeaderImage(headerPhotoPath, outputFolder, ui) {
166
120
  ui?.start(`Creating optimized header images`);
167
121
  const image = await loadImage(headerPhotoPath);
168
- const headerBasename = path__default.default.basename(headerPhotoPath, path__default.default.extname(headerPhotoPath));
122
+ const headerBasename = path7__default.default.basename(headerPhotoPath, path7__default.default.extname(headerPhotoPath));
169
123
  const generatedFiles = [];
170
124
  ui?.debug("Generating blurhash for header image");
171
125
  const blurHash = await generateBlurHash(headerPhotoPath);
@@ -174,22 +128,22 @@ async function createOptimizedHeaderImage(headerPhotoPath, outputFolder, ui) {
174
128
  ui?.debug(`Creating landscape header image ${width}`);
175
129
  const avifFilename = `${headerBasename}_landscape_${width}.avif`;
176
130
  const jpgFilename = `${headerBasename}_landscape_${width}.jpg`;
177
- if (fs8__default.default.existsSync(path__default.default.join(outputFolder, avifFilename))) {
131
+ if (fs8__default.default.existsSync(path7__default.default.join(outputFolder, avifFilename))) {
178
132
  ui?.debug(`Landscape header image ${width} AVIF already exists`);
179
133
  } else {
180
134
  await cropAndResizeImage(
181
135
  image.clone(),
182
- path__default.default.join(outputFolder, avifFilename),
136
+ path7__default.default.join(outputFolder, avifFilename),
183
137
  width,
184
138
  width * landscapeYFactor,
185
139
  "avif"
186
140
  );
187
141
  }
188
142
  generatedFiles.push(avifFilename);
189
- if (fs8__default.default.existsSync(path__default.default.join(outputFolder, jpgFilename))) {
143
+ if (fs8__default.default.existsSync(path7__default.default.join(outputFolder, jpgFilename))) {
190
144
  ui?.debug(`Landscape header image ${width} JPG already exists`);
191
145
  } else {
192
- await cropAndResizeImage(image.clone(), path__default.default.join(outputFolder, jpgFilename), width, width * landscapeYFactor, "jpg");
146
+ await cropAndResizeImage(image.clone(), path7__default.default.join(outputFolder, jpgFilename), width, width * landscapeYFactor, "jpg");
193
147
  }
194
148
  generatedFiles.push(jpgFilename);
195
149
  }
@@ -198,16 +152,16 @@ async function createOptimizedHeaderImage(headerPhotoPath, outputFolder, ui) {
198
152
  ui?.debug(`Creating portrait header image ${width}`);
199
153
  const avifFilename = `${headerBasename}_portrait_${width}.avif`;
200
154
  const jpgFilename = `${headerBasename}_portrait_${width}.jpg`;
201
- if (fs8__default.default.existsSync(path__default.default.join(outputFolder, avifFilename))) {
155
+ if (fs8__default.default.existsSync(path7__default.default.join(outputFolder, avifFilename))) {
202
156
  ui?.debug(`Portrait header image ${width} AVIF already exists`);
203
157
  } else {
204
- await cropAndResizeImage(image.clone(), path__default.default.join(outputFolder, avifFilename), width, width * portraitYFactor, "avif");
158
+ await cropAndResizeImage(image.clone(), path7__default.default.join(outputFolder, avifFilename), width, width * portraitYFactor, "avif");
205
159
  }
206
160
  generatedFiles.push(avifFilename);
207
- if (fs8__default.default.existsSync(path__default.default.join(outputFolder, jpgFilename))) {
161
+ if (fs8__default.default.existsSync(path7__default.default.join(outputFolder, jpgFilename))) {
208
162
  ui?.debug(`Portrait header image ${width} JPG already exists`);
209
163
  } else {
210
- await cropAndResizeImage(image.clone(), path__default.default.join(outputFolder, jpgFilename), width, width * portraitYFactor, "jpg");
164
+ await cropAndResizeImage(image.clone(), path7__default.default.join(outputFolder, jpgFilename), width, width * portraitYFactor, "jpg");
211
165
  }
212
166
  generatedFiles.push(jpgFilename);
213
167
  }
@@ -240,12 +194,12 @@ function cleanupOldHeaderImages(outputFolder, currentHeaderBasename, ui) {
240
194
  const landscapeMatch = file.match(/^(.+)_landscape_\d+\.(avif|jpg)$/);
241
195
  const portraitMatch = file.match(/^(.+)_portrait_\d+\.(avif|jpg)$/);
242
196
  if (landscapeMatch && landscapeMatch[1] !== currentHeaderBasename) {
243
- const filePath = path__default.default.join(outputFolder, file);
197
+ const filePath = path7__default.default.join(outputFolder, file);
244
198
  ui?.debug(`Deleting old landscape header image: ${file}`);
245
199
  fs8__default.default.unlinkSync(filePath);
246
200
  deletedCount++;
247
201
  } else if (portraitMatch && portraitMatch[1] !== currentHeaderBasename) {
248
- const filePath = path__default.default.join(outputFolder, file);
202
+ const filePath = path7__default.default.join(outputFolder, file);
249
203
  ui?.debug(`Deleting old portrait header image: ${file}`);
250
204
  fs8__default.default.unlinkSync(filePath);
251
205
  deletedCount++;
@@ -259,7 +213,7 @@ function cleanupOldHeaderImages(outputFolder, currentHeaderBasename, ui) {
259
213
  }
260
214
  function findGalleries(basePath, recursive) {
261
215
  const galleryDirs = [];
262
- const galleryJsonPath = path__default.default.join(basePath, "gallery", "gallery.json");
216
+ const galleryJsonPath = path7__default.default.join(basePath, "gallery", "gallery.json");
263
217
  if (fs8__default.default.existsSync(galleryJsonPath)) {
264
218
  galleryDirs.push(basePath);
265
219
  }
@@ -268,7 +222,7 @@ function findGalleries(basePath, recursive) {
268
222
  const entries = fs8__default.default.readdirSync(basePath, { withFileTypes: true });
269
223
  for (const entry of entries) {
270
224
  if (entry.isDirectory() && entry.name !== "gallery") {
271
- const subPath = path__default.default.join(basePath, entry.name);
225
+ const subPath = path7__default.default.join(basePath, entry.name);
272
226
  const subResults = findGalleries(subPath, recursive);
273
227
  galleryDirs.push(...subResults);
274
228
  }
@@ -327,20 +281,20 @@ function migrateGalleryJson(deprecatedGalleryData, galleryJsonPath, ui) {
327
281
  ui.start("Old gallery.json format detected. Migrating gallery.json to the new data format.");
328
282
  let mediaBasePath;
329
283
  const imagePath = deprecatedGalleryData.sections[0].images[0].path;
330
- if (imagePath && imagePath !== path__default.default.join("..", path__default.default.basename(imagePath))) {
331
- mediaBasePath = path__default.default.resolve(path__default.default.join(path__default.default.dirname(galleryJsonPath)), path__default.default.dirname(imagePath));
284
+ if (imagePath && imagePath !== path7__default.default.join("..", path7__default.default.basename(imagePath))) {
285
+ mediaBasePath = path7__default.default.resolve(path7__default.default.join(path7__default.default.dirname(galleryJsonPath)), path7__default.default.dirname(imagePath));
332
286
  }
333
287
  const sections = deprecatedGalleryData.sections.map((section) => ({
334
288
  ...section,
335
289
  images: section.images.map((image) => ({
336
290
  ...image,
337
291
  path: void 0,
338
- filename: path__default.default.basename(image.path)
292
+ filename: path7__default.default.basename(image.path)
339
293
  }))
340
294
  }));
341
295
  const galleryData = {
342
296
  ...deprecatedGalleryData,
343
- headerImage: path__default.default.basename(deprecatedGalleryData.headerImage),
297
+ headerImage: path7__default.default.basename(deprecatedGalleryData.headerImage),
344
298
  sections,
345
299
  mediaBasePath
346
300
  };
@@ -352,7 +306,7 @@ function migrateGalleryJson(deprecatedGalleryData, galleryJsonPath, ui) {
352
306
  return galleryData;
353
307
  }
354
308
  function getMediaFileType(fileName) {
355
- const ext = path__default.default.extname(fileName).toLowerCase();
309
+ const ext = path7__default.default.extname(fileName).toLowerCase();
356
310
  if (IMAGE_EXTENSIONS.has(ext)) return "image";
357
311
  if (VIDEO_EXTENSIONS.has(ext)) return "video";
358
312
  return null;
@@ -380,7 +334,7 @@ async function scanDirectory(dirPath, ui) {
380
334
  mediaFiles.push(mediaFile);
381
335
  }
382
336
  } else if (entry.isDirectory() && entry.name !== "gallery") {
383
- subGalleryDirectories.push(path__default.default.join(dirPath, entry.name));
337
+ subGalleryDirectories.push(path7__default.default.join(dirPath, entry.name));
384
338
  }
385
339
  }
386
340
  } catch (error) {
@@ -416,12 +370,12 @@ async function getGallerySettingsFromUser(galleryName, defaultImage, ui) {
416
370
  return { title, description, url, headerImage };
417
371
  }
418
372
  async function createGalleryJson(mediaFiles, galleryJsonPath, scanPath, subGalleries = [], useDefaultSettings, ctaBanner, ui) {
419
- const galleryDir = path__default.default.dirname(galleryJsonPath);
420
- const isSameLocation = path__default.default.relative(scanPath, path__default.default.join(galleryDir, "..")) === "";
373
+ const galleryDir = path7__default.default.dirname(galleryJsonPath);
374
+ const isSameLocation = path7__default.default.relative(scanPath, path7__default.default.join(galleryDir, "..")) === "";
421
375
  const mediaBasePath = isSameLocation ? void 0 : scanPath;
422
376
  const relativeSubGalleries = subGalleries.map((subGallery) => ({
423
377
  ...subGallery,
424
- headerImage: subGallery.headerImage ? path__default.default.relative(galleryDir, subGallery.headerImage) : ""
378
+ headerImage: subGallery.headerImage ? path7__default.default.relative(galleryDir, subGallery.headerImage) : ""
425
379
  }));
426
380
  let galleryData = {
427
381
  title: "My Gallery",
@@ -444,8 +398,8 @@ async function createGalleryJson(mediaFiles, galleryJsonPath, scanPath, subGalle
444
398
  galleryData = {
445
399
  ...galleryData,
446
400
  ...await getGallerySettingsFromUser(
447
- path__default.default.basename(path__default.default.join(galleryDir, "..")),
448
- path__default.default.basename(mediaFiles[0]?.filename || ""),
401
+ path7__default.default.basename(path7__default.default.join(galleryDir, "..")),
402
+ path7__default.default.basename(mediaFiles[0]?.filename || ""),
449
403
  ui
450
404
  )
451
405
  };
@@ -453,8 +407,8 @@ async function createGalleryJson(mediaFiles, galleryJsonPath, scanPath, subGalle
453
407
  await fs8.promises.writeFile(galleryJsonPath, JSON.stringify(galleryData, null, 2));
454
408
  }
455
409
  async function galleryExists(outputPath) {
456
- const galleryPath = path__default.default.join(outputPath, "gallery");
457
- const galleryJsonPath = path__default.default.join(galleryPath, "gallery.json");
410
+ const galleryPath = path7__default.default.join(outputPath, "gallery");
411
+ const galleryJsonPath = path7__default.default.join(galleryPath, "gallery.json");
458
412
  try {
459
413
  await fs8.promises.access(galleryJsonPath);
460
414
  return true;
@@ -473,7 +427,7 @@ async function processDirectory(scanPath, outputPath, recursive, useDefaultSetti
473
427
  for (const subGalleryDir of subGalleryDirectories) {
474
428
  const result2 = await processDirectory(
475
429
  subGalleryDir,
476
- path__default.default.join(outputPath, path__default.default.basename(subGalleryDir)),
430
+ path7__default.default.join(outputPath, path7__default.default.basename(subGalleryDir)),
477
431
  recursive,
478
432
  useDefaultSettings,
479
433
  force,
@@ -488,8 +442,8 @@ async function processDirectory(scanPath, outputPath, recursive, useDefaultSetti
488
442
  }
489
443
  }
490
444
  if (mediaFiles.length > 0 || subGalleries.length > 0) {
491
- const galleryPath = path__default.default.join(outputPath, "gallery");
492
- const galleryJsonPath = path__default.default.join(galleryPath, "gallery.json");
445
+ const galleryPath = path7__default.default.join(outputPath, "gallery");
446
+ const galleryJsonPath = path7__default.default.join(galleryPath, "gallery.json");
493
447
  const exists = await galleryExists(outputPath);
494
448
  if (exists && !force) {
495
449
  const shouldOverride = await ui.prompt(`Gallery already exists at ${galleryJsonPath}. Do you want to override it?`, {
@@ -514,19 +468,19 @@ async function processDirectory(scanPath, outputPath, recursive, useDefaultSetti
514
468
  }
515
469
  const result = { totalFiles, totalGalleries };
516
470
  if (mediaFiles.length > 0 || subGalleries.length > 0) {
517
- const dirName = path__default.default.basename(scanPath);
471
+ const dirName = path7__default.default.basename(scanPath);
518
472
  result.subGallery = {
519
473
  title: capitalizeTitle(dirName),
520
474
  headerImage: mediaFiles[0]?.filename || "",
521
- path: path__default.default.join("..", dirName)
475
+ path: path7__default.default.join("..", dirName)
522
476
  };
523
477
  }
524
478
  return result;
525
479
  }
526
480
  async function init(options, ui) {
527
481
  try {
528
- const scanPath = path__default.default.resolve(options.photos);
529
- const outputPath = options.gallery ? path__default.default.resolve(options.gallery) : scanPath;
482
+ const scanPath = path7__default.default.resolve(options.photos);
483
+ const outputPath = options.gallery ? path7__default.default.resolve(options.gallery) : scanPath;
530
484
  const result = await processDirectory(
531
485
  scanPath,
532
486
  outputPath,
@@ -650,7 +604,7 @@ async function processImage(imagePath, thumbnailPath, thumbnailPathRetina, thumb
650
604
  const blurHash = await generateBlurHash(thumbnailPath);
651
605
  return {
652
606
  type: "image",
653
- filename: path__default.default.basename(imagePath),
607
+ filename: path7__default.default.basename(imagePath),
654
608
  alt: description,
655
609
  width: imageDimensions.width,
656
610
  height: imageDimensions.height,
@@ -681,7 +635,7 @@ async function processVideo(videoPath, thumbnailPath, thumbnailPathRetina, thumb
681
635
  const blurHash = await generateBlurHash(thumbnailPath);
682
636
  return {
683
637
  type: "video",
684
- filename: path__default.default.basename(videoPath),
638
+ filename: path7__default.default.basename(videoPath),
685
639
  alt: void 0,
686
640
  width: videoDimensions.width,
687
641
  height: videoDimensions.height,
@@ -697,11 +651,11 @@ async function processVideo(videoPath, thumbnailPath, thumbnailPathRetina, thumb
697
651
  }
698
652
  async function processMediaFile(mediaFile, mediaBasePath, thumbnailsPath, thumbnailSize, ui) {
699
653
  try {
700
- const filePath = path__default.default.resolve(path__default.default.join(mediaBasePath, mediaFile.filename));
654
+ const filePath = path7__default.default.resolve(path7__default.default.join(mediaBasePath, mediaFile.filename));
701
655
  const fileName = mediaFile.filename;
702
- const fileNameWithoutExt = path__default.default.parse(fileName).name;
656
+ const fileNameWithoutExt = path7__default.default.parse(fileName).name;
703
657
  const thumbnailFileName = `${fileNameWithoutExt}.avif`;
704
- const thumbnailPath = path__default.default.join(thumbnailsPath, thumbnailFileName);
658
+ const thumbnailPath = path7__default.default.join(thumbnailsPath, thumbnailFileName);
705
659
  const thumbnailPathRetina = thumbnailPath.replace(".avif", "@2x.avif");
706
660
  const lastMediaTimestamp = mediaFile.lastMediaTimestamp ? new Date(mediaFile.lastMediaTimestamp) : void 0;
707
661
  const verbose = ui.level === consola.LogLevels.debug;
@@ -727,8 +681,8 @@ async function processMediaFile(mediaFile, mediaBasePath, thumbnailsPath, thumbn
727
681
  }
728
682
  updatedMediaFile.filename = mediaFile.filename;
729
683
  if (updatedMediaFile.thumbnail) {
730
- updatedMediaFile.thumbnail.path = path__default.default.basename(thumbnailPath);
731
- updatedMediaFile.thumbnail.pathRetina = path__default.default.basename(thumbnailPathRetina);
684
+ updatedMediaFile.thumbnail.path = path7__default.default.basename(thumbnailPath);
685
+ updatedMediaFile.thumbnail.pathRetina = path7__default.default.basename(thumbnailPathRetina);
732
686
  if (mediaFile.thumbnail?.baseUrl) {
733
687
  updatedMediaFile.thumbnail.baseUrl = mediaFile.thumbnail.baseUrl;
734
688
  }
@@ -743,14 +697,14 @@ async function processMediaFile(mediaFile, mediaBasePath, thumbnailsPath, thumbn
743
697
  }
744
698
  }
745
699
  async function processGalleryThumbnails(galleryDir, ui) {
746
- const galleryJsonPath = path__default.default.join(galleryDir, "gallery", "gallery.json");
747
- const thumbnailsPath = path__default.default.join(galleryDir, "gallery", "images");
700
+ const galleryJsonPath = path7__default.default.join(galleryDir, "gallery", "gallery.json");
701
+ const thumbnailsPath = path7__default.default.join(galleryDir, "gallery", "images");
748
702
  ui.start(`Creating thumbnails: ${galleryDir}`);
749
703
  try {
750
704
  fs8__default.default.mkdirSync(thumbnailsPath, { recursive: true });
751
705
  const galleryData = parseGalleryJson(galleryJsonPath, ui);
752
706
  const thumbnailSize = galleryData.thumbnailSize || DEFAULT_THUMBNAIL_SIZE;
753
- const mediaBasePath = galleryData.mediaBasePath ?? path__default.default.join(galleryDir);
707
+ const mediaBasePath = galleryData.mediaBasePath ?? path7__default.default.join(galleryDir);
754
708
  let processedCount = 0;
755
709
  for (const section of galleryData.sections) {
756
710
  for (const [index, mediaFile] of section.images.entries()) {
@@ -797,8 +751,8 @@ function copyPhotos(galleryData, galleryDir, ui) {
797
751
  for (const section of galleryData.sections) {
798
752
  for (const image of section.images) {
799
753
  if (galleryData.mediaBasePath) {
800
- const sourcePath = path__default.default.join(galleryData.mediaBasePath, image.filename);
801
- const destPath = path__default.default.join(galleryDir, image.filename);
754
+ const sourcePath = path7__default.default.join(galleryData.mediaBasePath, image.filename);
755
+ const destPath = path7__default.default.join(galleryDir, image.filename);
802
756
  ui.debug(`Copying photo to ${destPath}`);
803
757
  fs8__default.default.copyFileSync(sourcePath, destPath);
804
758
  }
@@ -837,17 +791,17 @@ async function scanAndAppendNewFiles(galleryDir, galleryJsonPath, galleryData, u
837
791
  }
838
792
  async function buildGallery(galleryDir, templateDir, scan, shouldCreateThumbnails, ui, baseUrl, thumbsBaseUrl) {
839
793
  ui.start(`Building gallery ${galleryDir}`);
840
- const galleryJsonPath = path__default.default.join(galleryDir, "gallery", "gallery.json");
794
+ const galleryJsonPath = path7__default.default.join(galleryDir, "gallery", "gallery.json");
841
795
  let galleryData = parseGalleryJson(galleryJsonPath, ui);
842
796
  if (scan) {
843
797
  galleryData = await scanAndAppendNewFiles(galleryDir, galleryJsonPath, galleryData, ui);
844
798
  }
845
- const socialMediaCardImagePath = path__default.default.join(galleryDir, "gallery", "images", "social-media-card.jpg");
799
+ const socialMediaCardImagePath = path7__default.default.join(galleryDir, "gallery", "images", "social-media-card.jpg");
846
800
  const mediaBasePath = galleryData.mediaBasePath;
847
801
  const mediaBaseUrl = baseUrl || galleryData.mediaBaseUrl;
848
- const headerImagePath = mediaBasePath ? path__default.default.join(mediaBasePath, galleryData.headerImage) : path__default.default.resolve(galleryDir, galleryData.headerImage);
849
- const imagesFolder = path__default.default.join(galleryDir, "gallery", "images");
850
- const currentHeaderBasename = path__default.default.basename(headerImagePath, path__default.default.extname(headerImagePath));
802
+ const headerImagePath = mediaBasePath ? path7__default.default.join(mediaBasePath, galleryData.headerImage) : path7__default.default.resolve(galleryDir, galleryData.headerImage);
803
+ const imagesFolder = path7__default.default.join(galleryDir, "gallery", "images");
804
+ const currentHeaderBasename = path7__default.default.basename(headerImagePath, path7__default.default.extname(headerImagePath));
851
805
  if (shouldCreateThumbnails) {
852
806
  if (!fs8__default.default.existsSync(imagesFolder)) {
853
807
  fs8__default.default.mkdirSync(imagesFolder, { recursive: true });
@@ -890,7 +844,7 @@ async function buildGallery(galleryDir, templateDir, scan, shouldCreateThumbnail
890
844
  }
891
845
  if (!galleryData.metadata.image) {
892
846
  ui.debug("Updating gallery.json with social media card URL");
893
- galleryData.metadata.image = thumbsBaseUrl ? `${thumbsBaseUrl}/${path__default.default.basename(socialMediaCardImagePath)}` : `${galleryData.url || ""}/${path__default.default.relative(galleryDir, socialMediaCardImagePath)}`;
847
+ galleryData.metadata.image = thumbsBaseUrl ? `${thumbsBaseUrl}/${path7__default.default.basename(socialMediaCardImagePath)}` : `${galleryData.url || ""}/${path7__default.default.relative(galleryDir, socialMediaCardImagePath)}`;
894
848
  fs8__default.default.writeFileSync(galleryJsonPath, JSON.stringify(galleryData, null, 2));
895
849
  }
896
850
  if (shouldCreateThumbnails) {
@@ -898,20 +852,20 @@ async function buildGallery(galleryDir, templateDir, scan, shouldCreateThumbnail
898
852
  }
899
853
  ui.debug("Building gallery from template");
900
854
  try {
901
- process4__default.default.env.GALLERY_JSON_PATH = galleryJsonPath;
902
- process4__default.default.env.GALLERY_OUTPUT_DIR = path__default.default.join(galleryDir, "gallery");
855
+ process3__default.default.env.GALLERY_JSON_PATH = galleryJsonPath;
856
+ process3__default.default.env.GALLERY_OUTPUT_DIR = path7__default.default.join(galleryDir, "gallery");
903
857
  child_process.execSync("npx astro build", { cwd: templateDir, stdio: ui.level === consola.LogLevels.debug ? "inherit" : "ignore" });
904
858
  } catch (error) {
905
859
  ui.error(`Build failed for ${galleryDir}`);
906
860
  throw error;
907
861
  }
908
- const outputDir = path__default.default.join(galleryDir, "gallery");
909
- const buildDir = path__default.default.join(outputDir, "_build");
862
+ const outputDir = path7__default.default.join(galleryDir, "gallery");
863
+ const buildDir = path7__default.default.join(outputDir, "_build");
910
864
  ui.debug(`Copying build output to ${outputDir}`);
911
865
  fs8__default.default.cpSync(buildDir, outputDir, { recursive: true });
912
866
  ui.debug("Moving index.html to gallery directory");
913
- fs8__default.default.copyFileSync(path__default.default.join(outputDir, "index.html"), path__default.default.join(galleryDir, "index.html"));
914
- fs8__default.default.rmSync(path__default.default.join(outputDir, "index.html"));
867
+ fs8__default.default.copyFileSync(path7__default.default.join(outputDir, "index.html"), path7__default.default.join(galleryDir, "index.html"));
868
+ fs8__default.default.rmSync(path7__default.default.join(outputDir, "index.html"));
915
869
  ui.debug("Cleaning up build directory");
916
870
  fs8__default.default.rmSync(buildDir, { recursive: true, force: true });
917
871
  ui.success(`Gallery built successfully`);
@@ -924,12 +878,12 @@ async function build(options, ui) {
924
878
  return { processedGalleryCount: 0 };
925
879
  }
926
880
  const themePath = await undefined("@simple-photo-gallery/theme-modern/package.json");
927
- const themeDir = path__default.default.dirname(new URL(themePath).pathname);
881
+ const themeDir = path7__default.default.dirname(new URL(themePath).pathname);
928
882
  let totalGalleries = 0;
929
883
  for (const dir of galleryDirs) {
930
- const baseUrl = options.baseUrl ? `${options.baseUrl}${path__default.default.relative(options.gallery, dir)}` : void 0;
931
- const thumbsBaseUrl = options.thumbsBaseUrl ? `${options.thumbsBaseUrl}${path__default.default.relative(options.gallery, dir)}` : void 0;
932
- await buildGallery(path__default.default.resolve(dir), themeDir, options.scan, options.thumbnails, ui, baseUrl, thumbsBaseUrl);
884
+ const baseUrl = options.baseUrl ? `${options.baseUrl}${path7__default.default.relative(options.gallery, dir)}` : void 0;
885
+ const thumbsBaseUrl = options.thumbsBaseUrl ? `${options.thumbsBaseUrl}${path7__default.default.relative(options.gallery, dir)}` : void 0;
886
+ await buildGallery(path7__default.default.resolve(dir), themeDir, options.scan, options.thumbnails, ui, baseUrl, thumbsBaseUrl);
933
887
  ++totalGalleries;
934
888
  }
935
889
  ui.box(`Built ${totalGalleries} ${totalGalleries === 1 ? "gallery" : "galleries"} successfully`);
@@ -945,7 +899,7 @@ async function build(options, ui) {
945
899
  }
946
900
  async function cleanGallery(galleryDir, ui) {
947
901
  let filesRemoved = 0;
948
- const indexHtmlPath = path__default.default.join(galleryDir, "index.html");
902
+ const indexHtmlPath = path7__default.default.join(galleryDir, "index.html");
949
903
  if (fs8__default.default.existsSync(indexHtmlPath)) {
950
904
  try {
951
905
  fs8__default.default.rmSync(indexHtmlPath);
@@ -955,7 +909,7 @@ async function cleanGallery(galleryDir, ui) {
955
909
  ui?.warn(`Failed to remove index.html: ${error}`);
956
910
  }
957
911
  }
958
- const galleryPath = path__default.default.join(galleryDir, "gallery");
912
+ const galleryPath = path7__default.default.join(galleryDir, "gallery");
959
913
  if (fs8__default.default.existsSync(galleryPath)) {
960
914
  try {
961
915
  fs8__default.default.rmSync(galleryPath, { recursive: true, force: true });
@@ -974,7 +928,7 @@ async function cleanGallery(galleryDir, ui) {
974
928
  }
975
929
  async function clean(options, ui) {
976
930
  try {
977
- const basePath = path__default.default.resolve(options.gallery);
931
+ const basePath = path7__default.default.resolve(options.gallery);
978
932
  if (!fs8__default.default.existsSync(basePath)) {
979
933
  ui.error(`Directory does not exist: ${basePath}`);
980
934
  return { processedGalleryCount: 0 };
@@ -1023,7 +977,7 @@ var ApiTelemetryClient = class {
1023
977
  axios__default.default.post(this.endpoint, event, {
1024
978
  headers: {
1025
979
  "content-type": "application/json",
1026
- "user-agent": `simple-photo-gallery/${event.packageVersion} (${process4__default.default.platform}; ${process4__default.default.arch})`
980
+ "user-agent": `simple-photo-gallery/${event.packageVersion} (${process3__default.default.platform}; ${process3__default.default.arch})`
1027
981
  }
1028
982
  });
1029
983
  } catch {
@@ -1033,7 +987,7 @@ var ApiTelemetryClient = class {
1033
987
  var ConsoleTelemetryClient = class {
1034
988
  async record(event) {
1035
989
  const serialized = JSON.stringify(event, null, 2);
1036
- process4.stdout.write(`TELEMETRY EVENT: ${serialized}
990
+ process3.stdout.write(`TELEMETRY EVENT: ${serialized}
1037
991
  `);
1038
992
  }
1039
993
  };
@@ -1060,11 +1014,11 @@ var TelemetryService = class {
1060
1014
  if (override) {
1061
1015
  return override === "1";
1062
1016
  }
1063
- if (process4__default.default.env.CI || process4__default.default.env.DO_NOT_TRACK) {
1017
+ if (process3__default.default.env.CI || process3__default.default.env.DO_NOT_TRACK) {
1064
1018
  return false;
1065
1019
  }
1066
- if (process4__default.default.env.SPG_TELEMETRY) {
1067
- return process4__default.default.env.SPG_TELEMETRY === "1";
1020
+ if (process3__default.default.env.SPG_TELEMETRY) {
1021
+ return process3__default.default.env.SPG_TELEMETRY === "1";
1068
1022
  }
1069
1023
  const stored = this.getStoredPreference();
1070
1024
  if (stored === void 0) {
@@ -1106,7 +1060,7 @@ var TelemetryService = class {
1106
1060
  durationMs: now - startedAt,
1107
1061
  packageName: this.packageName,
1108
1062
  packageVersion: this.packageVersion,
1109
- nodeVersion: process4__default.default.version,
1063
+ nodeVersion: process3__default.default.version,
1110
1064
  osPlatform: os__default.default.platform(),
1111
1065
  osRelease: os__default.default.release(),
1112
1066
  osArch: os__default.default.arch(),
@@ -1140,7 +1094,7 @@ var TelemetryService = class {
1140
1094
  /** Returns the telemetry client. */
1141
1095
  getClient() {
1142
1096
  if (!this.client) {
1143
- switch (process4__default.default.env.SPG_TELEMETRY_PROVIDER) {
1097
+ switch (process3__default.default.env.SPG_TELEMETRY_PROVIDER) {
1144
1098
  case "none": {
1145
1099
  this.client = void 0;
1146
1100
  break;
@@ -1232,7 +1186,7 @@ async function waitForUpdateCheck(checkPromise) {
1232
1186
  // package.json
1233
1187
  var package_default = {
1234
1188
  name: "simple-photo-gallery",
1235
- version: "2.0.13"};
1189
+ version: "2.0.15-rc.18"};
1236
1190
 
1237
1191
  // src/index.ts
1238
1192
  var program = new commander.Command();
@@ -1274,7 +1228,7 @@ function withCommandContext(handler) {
1274
1228
  } catch (error) {
1275
1229
  ui.debug(error);
1276
1230
  errorInfo = error instanceof Error ? { name: error.name, message: error.message } : { name: "UnknownError", message: String(error) };
1277
- process4__default.default.exitCode = 1;
1231
+ process3__default.default.exitCode = 1;
1278
1232
  }
1279
1233
  const updateInfo = await waitForUpdateCheck(updateCheckPromise);
1280
1234
  if (updateInfo) {
@@ -1296,14 +1250,14 @@ function withCommandContext(handler) {
1296
1250
  program.command("init").description("Initialize a gallery by scaning a folder for images and videos").option(
1297
1251
  "-p, --photos <path>",
1298
1252
  "Path to the folder where the photos are stored. Default: current working directory",
1299
- process4__default.default.cwd()
1253
+ process3__default.default.cwd()
1300
1254
  ).option(
1301
1255
  "-g, --gallery <path>",
1302
1256
  "Path to the directory where the gallery will be initialized. Default: same directory as the photos folder"
1303
1257
  ).option("-r, --recursive", "Recursively create galleries from all photos subdirectories", false).option("-d, --default", "Use default gallery settings instead of asking the user", false).option("-f, --force", "Force override existing galleries without asking", false).option("--cta-banner", "Add a Simple Photo Gallery call-to-action banner to the end of the gallery", false).action(withCommandContext((options, ui) => init(options, ui)));
1304
- program.command("thumbnails").description("Create thumbnails for all media files in the gallery").option("-g, --gallery <path>", "Path to the directory of the gallery. Default: current working directory", process4__default.default.cwd()).option("-r, --recursive", "Scan subdirectories recursively", false).action(withCommandContext((options, ui) => thumbnails(options, ui)));
1305
- program.command("build").description("Build the HTML gallery in the specified directory").option("-g, --gallery <path>", "Path to the directory of the gallery. Default: current working directory", process4__default.default.cwd()).option("-r, --recursive", "Scan subdirectories recursively", false).option("-b, --base-url <url>", "Base URL where the photos are hosted").option("-t, --thumbs-base-url <url>", "Base URL where the thumbnails are hosted").option("--no-thumbnails", "Skip creating thumbnails when building the gallery", true).option("--no-scan", "Do not scan for new photos when building the gallery", true).action(withCommandContext((options, ui) => build(options, ui)));
1306
- program.command("clean").description("Remove all gallery files and folders (index.html, gallery/)").option("-g, --gallery <path>", "Path to the directory of the gallery. Default: current working directory", process4__default.default.cwd()).option("-r, --recursive", "Clean subdirectories recursively", false).action(withCommandContext((options, ui) => clean(options, ui)));
1258
+ program.command("thumbnails").description("Create thumbnails for all media files in the gallery").option("-g, --gallery <path>", "Path to the directory of the gallery. Default: current working directory", process3__default.default.cwd()).option("-r, --recursive", "Scan subdirectories recursively", false).action(withCommandContext((options, ui) => thumbnails(options, ui)));
1259
+ program.command("build").description("Build the HTML gallery in the specified directory").option("-g, --gallery <path>", "Path to the directory of the gallery. Default: current working directory", process3__default.default.cwd()).option("-r, --recursive", "Scan subdirectories recursively", false).option("-b, --base-url <url>", "Base URL where the photos are hosted").option("-t, --thumbs-base-url <url>", "Base URL where the thumbnails are hosted").option("--no-thumbnails", "Skip creating thumbnails when building the gallery", true).option("--no-scan", "Do not scan for new photos when building the gallery", true).action(withCommandContext((options, ui) => build(options, ui)));
1260
+ program.command("clean").description("Remove all gallery files and folders (index.html, gallery/)").option("-g, --gallery <path>", "Path to the directory of the gallery. Default: current working directory", process3__default.default.cwd()).option("-r, --recursive", "Clean subdirectories recursively", false).action(withCommandContext((options, ui) => clean(options, ui)));
1307
1261
  program.command("telemetry").description("Manage anonymous telemetry preferences. Use 1 to enable, 0 to disable, or no argument to check status").option("-s, --state <state>", "Enable (1) or disable (0) telemetry", parseTelemetryOption).action(withCommandContext((options, ui) => telemetry(options, ui, telemetryService)));
1308
1262
  program.parse();
1309
1263
  //# sourceMappingURL=index.cjs.map