codeplay-common 4.4.2 → 4.4.3

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.
@@ -5,11 +5,21 @@ const { spawn, spawnSync } = require('node:child_process');
5
5
 
6
6
  const screenshotDirectory = path.join(__dirname, 'Auto-Screenshot', 'Store-image-Screenshot');
7
7
  const inFrameDirectory = path.join(__dirname, 'Auto-Screenshot', 'Store-image-Frame');
8
- const amazonAssetsDirectory = path.join(__dirname, 'Auto-Screenshot', 'Amazon-assets');
9
- const samsungAssetsDirectory = path.join(__dirname, 'Auto-Screenshot', 'Samsung-assets');
8
+ const amazonAssetsDirectory = path.join(__dirname, 'Auto-Screenshot', 'Amazon-Assets');
9
+ const samsungAssetsDirectory = path.join(__dirname, 'Auto-Screenshot', 'Samsung-Assets');
10
10
  const capacitorConfigPath = path.join(__dirname, 'capacitor.config.json');
11
11
  const amazonIconPath = path.join(__dirname, 'resources', 'icon-only.png');
12
12
  const temporaryDirectory = path.join(__dirname, 'agent-temp');
13
+ const amazonAssetDefinitions = [
14
+ { fileName: 'icon-1280x720.png', type: 'icon', width: 1280, height: 720 },
15
+ { fileName: 'background-image-1920x1080.png', type: 'background-image', width: 1920, height: 1080 },
16
+ { fileName: 'featured-content-logo-640x260.png', type: 'featured-logo', width: 640, height: 260, transparent: true },
17
+ { fileName: 'featured-content-background-1920x720.png', type: 'featured-background', width: 1920, height: 720 },
18
+ ];
19
+ const samsungAssetDefinitions = [
20
+ { fileName: 'edge-screen-160x2560.png', type: 'edge-screen', width: 160, height: 2560 },
21
+ { fileName: 'edge-screen-single-550x2560.png', type: 'edge-screen-single-plus', width: 550, height: 2560 },
22
+ ];
13
23
  const browserExecutablePaths = [
14
24
  'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
15
25
  'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
@@ -430,6 +440,8 @@ function printHelp() {
430
440
  console.log(' node take-screen-image.js --samsung-assets');
431
441
  console.log(' node take-screen-image.js --dry-run');
432
442
  console.log(' node take-screen-image.js --list');
443
+ console.log('');
444
+ console.log('A normal capture automatically creates any missing Amazon and Samsung store assets.');
433
445
  }
434
446
 
435
447
  function selectProfiles(input) {
@@ -1510,7 +1522,7 @@ function createAmazonAssetHtml(asset, appName, iconBuffer, storeCopy) {
1510
1522
  </html>`;
1511
1523
  }
1512
1524
 
1513
- async function createAmazonAssets(client) {
1525
+ async function createAmazonAssets(client, skipExisting = false) {
1514
1526
  if (!fs.existsSync(amazonIconPath)) {
1515
1527
  throw new Error(`Amazon asset source icon was not found: ${amazonIconPath}`);
1516
1528
  }
@@ -1519,16 +1531,15 @@ async function createAmazonAssets(client) {
1519
1531
  const appName = config.appName || 'App';
1520
1532
  const storeCopy = getStoreAssetCopy(config);
1521
1533
  const iconBuffer = fs.readFileSync(amazonIconPath);
1522
- const assets = [
1523
- { fileName: 'icon-1280x720.png', type: 'icon', width: 1280, height: 720 },
1524
- { fileName: 'background-image-1920x1080.png', type: 'background-image', width: 1920, height: 1080 },
1525
- { fileName: 'featured-content-logo-640x260.png', type: 'featured-logo', width: 640, height: 260, transparent: true },
1526
- { fileName: 'featured-content-background-1920x720.png', type: 'featured-background', width: 1920, height: 720 },
1527
- ];
1528
-
1529
1534
  fs.mkdirSync(amazonAssetsDirectory, { recursive: true });
1530
1535
 
1531
- for (const asset of assets) {
1536
+ for (const asset of amazonAssetDefinitions) {
1537
+ const outputPath = path.join(amazonAssetsDirectory, asset.fileName);
1538
+
1539
+ if (skipExisting && fs.existsSync(outputPath)) {
1540
+ continue;
1541
+ }
1542
+
1532
1543
  await client.send('Emulation.setDeviceMetricsOverride', {
1533
1544
  width: asset.width,
1534
1545
  height: asset.height,
@@ -1562,7 +1573,6 @@ async function createAmazonAssets(client) {
1562
1573
  captureBeyondViewport: false,
1563
1574
  omitBackground: Boolean(asset.transparent),
1564
1575
  });
1565
- const outputPath = path.join(amazonAssetsDirectory, asset.fileName);
1566
1576
  fs.writeFileSync(outputPath, Buffer.from(screenshot.data, 'base64'));
1567
1577
  console.log(`Saved Amazon asset ${asset.width}x${asset.height}: ${outputPath}`);
1568
1578
  }
@@ -1673,7 +1683,7 @@ function createSamsungAssetHtml(asset, appName, iconBuffer, storeCopy) {
1673
1683
  </html>`;
1674
1684
  }
1675
1685
 
1676
- async function createSamsungAssets(client) {
1686
+ async function createSamsungAssets(client, skipExisting = false) {
1677
1687
  if (!fs.existsSync(amazonIconPath)) {
1678
1688
  throw new Error(`Samsung asset source icon was not found: ${amazonIconPath}`);
1679
1689
  }
@@ -1682,15 +1692,17 @@ async function createSamsungAssets(client) {
1682
1692
  const appName = config.appName || 'App';
1683
1693
  const storeCopy = getStoreAssetCopy(config);
1684
1694
  const iconBuffer = fs.readFileSync(amazonIconPath);
1685
- const assets = [
1686
- { fileName: 'edge-screen-160x2560.png', type: 'edge-screen', width: 160, height: 2560 },
1687
- { fileName: 'edge-screen-single-plus-550x2560.png', type: 'edge-screen-single-plus', width: 550, height: 2560 },
1688
- ];
1689
1695
  const maximumFileSize = 1024 * 1024;
1690
1696
 
1691
1697
  fs.mkdirSync(samsungAssetsDirectory, { recursive: true });
1692
1698
 
1693
- for (const asset of assets) {
1699
+ for (const asset of samsungAssetDefinitions) {
1700
+ const outputPath = path.join(samsungAssetsDirectory, asset.fileName);
1701
+
1702
+ if (skipExisting && fs.existsSync(outputPath)) {
1703
+ continue;
1704
+ }
1705
+
1694
1706
  await client.send('Emulation.setDeviceMetricsOverride', {
1695
1707
  width: asset.width,
1696
1708
  height: asset.height,
@@ -1719,7 +1731,6 @@ async function createSamsungAssets(client) {
1719
1731
  fromSurface: true,
1720
1732
  captureBeyondViewport: false,
1721
1733
  });
1722
- const outputPath = path.join(samsungAssetsDirectory, asset.fileName);
1723
1734
  const outputBuffer = Buffer.from(screenshot.data, 'base64');
1724
1735
 
1725
1736
  if (outputBuffer.length >= maximumFileSize) {
@@ -1736,6 +1747,41 @@ async function createSamsungAssets(client) {
1736
1747
  }
1737
1748
  }
1738
1749
 
1750
+ async function createMissingStoreAssets() {
1751
+ const hasMissingAmazonAssets = amazonAssetDefinitions.some((asset) => (
1752
+ !fs.existsSync(path.join(amazonAssetsDirectory, asset.fileName))
1753
+ ));
1754
+ const hasMissingSamsungAssets = samsungAssetDefinitions.some((asset) => (
1755
+ !fs.existsSync(path.join(samsungAssetsDirectory, asset.fileName))
1756
+ ));
1757
+
1758
+ if (!hasMissingAmazonAssets && !hasMissingSamsungAssets) {
1759
+ console.log('Amazon and Samsung store assets already exist.');
1760
+ return;
1761
+ }
1762
+
1763
+ let browser;
1764
+ let client;
1765
+
1766
+ try {
1767
+ browser = await launchReplayBrowser();
1768
+ client = await createReplayPage(browser);
1769
+
1770
+ if (hasMissingAmazonAssets) {
1771
+ await createAmazonAssets(client, true);
1772
+ }
1773
+
1774
+ if (hasMissingSamsungAssets) {
1775
+ await createSamsungAssets(client, true);
1776
+ }
1777
+ } finally {
1778
+ if (client) client.close();
1779
+ if (browser) await closeReplayBrowser(browser);
1780
+ }
1781
+
1782
+ console.log('Missing Amazon and Samsung store assets created.');
1783
+ }
1784
+
1739
1785
  async function captureFramedScreenshot(
1740
1786
  client,
1741
1787
  screenshotBuffer,
@@ -2037,6 +2083,10 @@ async function main() {
2037
2083
  return;
2038
2084
  }
2039
2085
 
2086
+ if (!options.dryRun) {
2087
+ await createMissingStoreAssets();
2088
+ }
2089
+
2040
2090
  const selectedProfiles = selectProfiles(options.profiles);
2041
2091
 
2042
2092
  if (options.frameExisting) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "4.4.2",
3
+ "version": "4.4.3",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",