codeplay-common 4.6.3 → 4.6.5

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.
@@ -1,3 +1,8 @@
1
+ //node take-screen-image.js --delete 3
2
+ //node take-screen-image.js --delete 3,4,5
3
+
4
+
5
+
1
6
  const fs = require('node:fs');
2
7
  const path = require('node:path');
3
8
  const readline = require('node:readline/promises');
@@ -5,6 +10,7 @@ const { spawn, spawnSync } = require('node:child_process');
5
10
 
6
11
  const screenshotDirectory = path.join(__dirname, 'Auto-Screenshot', 'Store-image-Screenshot');
7
12
  const inFrameDirectory = path.join(__dirname, 'Auto-Screenshot', 'Store-image-Frame');
13
+ const autoScreenshotDirectory = path.join(__dirname, 'Auto-Screenshot');
8
14
  const aiAssetsDirectory = path.join(__dirname, 'AI-Assets');
9
15
  const amazonAssetsDirectory = path.join(aiAssetsDirectory, 'Amazon-Assets');
10
16
  const samsungAssetsDirectory = path.join(aiAssetsDirectory, 'Samsung-Assets');
@@ -97,6 +103,28 @@ const deviceProfiles = [
97
103
  orientationSensitive: true,
98
104
  mobile: true,
99
105
  },
106
+ {
107
+ name: 'ipad-store',
108
+ label: 'iPad App Store screenshot set',
109
+ outputDirectory: 'iPad-Store',
110
+ frameType: 'tablet',
111
+ width: 1024,
112
+ height: 1366,
113
+ deviceScaleFactor: 2,
114
+ mobile: true,
115
+ screenshotOnly: true,
116
+ },
117
+ {
118
+ name: 'iphone-store',
119
+ label: 'iPhone App Store screenshot set',
120
+ outputDirectory: 'iPhone-Store',
121
+ frameType: 'iphone',
122
+ width: 428,
123
+ height: 926,
124
+ deviceScaleFactor: 3,
125
+ mobile: true,
126
+ screenshotOnly: true,
127
+ },
100
128
  {
101
129
  name: 'apple-vision-pro',
102
130
  label: 'Apple Vision Pro',
@@ -317,7 +345,7 @@ function sanitizeName(input, fallback) {
317
345
  function getSelectedOutputDirectories(selectedProfiles) {
318
346
  return [...new Set(selectedProfiles.flatMap((profile) => ([
319
347
  path.join(screenshotDirectory, profile.outputDirectory),
320
- path.join(inFrameDirectory, profile.outputDirectory),
348
+ ...(profile.screenshotOnly ? [] : [path.join(inFrameDirectory, profile.outputDirectory)]),
321
349
  ])))];
322
350
  }
323
351
 
@@ -382,6 +410,8 @@ function parseArguments() {
382
410
  frameExisting: false,
383
411
  help: false,
384
412
  list: false,
413
+ deleteRequested: false,
414
+ deleteNames: '',
385
415
  prefix: '',
386
416
  profiles: '',
387
417
  };
@@ -401,6 +431,10 @@ function parseArguments() {
401
431
  options.help = true;
402
432
  } else if (argument === '--list') {
403
433
  options.list = true;
434
+ } else if (argument === '--delete') {
435
+ options.deleteRequested = true;
436
+ options.deleteNames = args[index + 1] || '';
437
+ index += 1;
404
438
  } else if (argument === '--prefix') {
405
439
  options.prefix = args[index + 1] || '';
406
440
  index += 1;
@@ -445,10 +479,47 @@ function printHelp() {
445
479
  console.log(' node take-screen-image.js --samsung-assets');
446
480
  console.log(' node take-screen-image.js --dry-run');
447
481
  console.log(' node take-screen-image.js --list');
482
+ console.log(' node take-screen-image.js --delete 3,4,5');
448
483
  console.log('');
449
484
  console.log('A normal capture automatically creates any missing Amazon, Samsung, and Play Store assets.');
450
485
  }
451
486
 
487
+ function deleteMatchingImages(input) {
488
+ const names = [...new Set(input.split(',').map((name) => name.trim()).filter(Boolean))];
489
+
490
+ if (!names.length) {
491
+ throw new Error('Provide one or more image names after --delete, for example: --delete 3,4,5');
492
+ }
493
+
494
+ const nameSet = new Set(names.map((name) => name.replace(/\.[^.]+$/, '')));
495
+ const imageExtensions = new Set(['.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp', '.svg']);
496
+ const deletedFiles = [];
497
+
498
+ function scanDirectory(directory) {
499
+ if (!fs.existsSync(directory)) return;
500
+
501
+ for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
502
+ const entryPath = path.join(directory, entry.name);
503
+
504
+ if (entry.isDirectory()) {
505
+ scanDirectory(entryPath);
506
+ continue;
507
+ }
508
+
509
+ const extension = path.extname(entry.name).toLowerCase();
510
+ const baseName = path.basename(entry.name, extension);
511
+ if (imageExtensions.has(extension) && nameSet.has(baseName)) {
512
+ fs.unlinkSync(entryPath);
513
+ deletedFiles.push(entryPath);
514
+ }
515
+ }
516
+ }
517
+
518
+ scanDirectory(autoScreenshotDirectory);
519
+ console.log(`Deleted ${deletedFiles.length} matching image(s) from ${autoScreenshotDirectory}.`);
520
+ for (const filePath of deletedFiles) console.log(`Deleted: ${filePath}`);
521
+ }
522
+
452
523
  function selectProfiles(input) {
453
524
  const orientation = getConfiguredOrientation();
454
525
  const names = input
@@ -1956,6 +2027,8 @@ async function captureFramedScreenshot(
1956
2027
  screenshotFileName,
1957
2028
  skipExisting = false,
1958
2029
  ) {
2030
+ if (profile.screenshotOnly) return false;
2031
+
1959
2032
  const framedProfileDirectory = path.join(inFrameDirectory, profile.outputDirectory);
1960
2033
  const framedScreenshotPath = path.join(framedProfileDirectory, screenshotFileName);
1961
2034
 
@@ -2054,6 +2127,7 @@ async function captureProfile(client, snapshot, profile, screenshotFileName) {
2054
2127
  fs.mkdirSync(profileDirectory, { recursive: true });
2055
2128
  fs.writeFileSync(screenshotPath, screenshotBuffer, { flag: 'wx' });
2056
2129
  console.log(`Saved ${profile.label}: ${screenshotPath}`);
2130
+ if (profile.screenshotOnly) return;
2057
2131
  await captureFramedScreenshot(
2058
2132
  client,
2059
2133
  screenshotBuffer,
@@ -2214,6 +2288,11 @@ async function main() {
2214
2288
  return;
2215
2289
  }
2216
2290
 
2291
+ if (options.deleteRequested) {
2292
+ deleteMatchingImages(options.deleteNames);
2293
+ return;
2294
+ }
2295
+
2217
2296
  options = await getInteractiveOptions(options);
2218
2297
 
2219
2298
  if (options.amazonAssets) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "4.6.3",
3
+ "version": "4.6.5",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",