codeplay-common 4.4.8 → 4.5.0

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.
@@ -1910,17 +1910,6 @@ async function fetchVersions() {
1910
1910
 
1911
1911
  }
1912
1912
 
1913
- function readInstalledAgentInstructionsVersion() {
1914
- const versionFile = path.join(
1915
- process.cwd(),
1916
- AGENT_INSTRUCTIONS_DIR,
1917
- AGENT_INSTRUCTIONS_VERSION_FILE
1918
- );
1919
-
1920
- if (!fs.existsSync(versionFile)) return "0";
1921
- return String(fs.readFileSync(versionFile, "utf8")).trim() || "0";
1922
- }
1923
-
1924
1913
  function getAgentInstructionsZipLayout(zip) {
1925
1914
  const entries = zip.getEntries().filter(entry => !entry.isDirectory);
1926
1915
 
@@ -1969,23 +1958,35 @@ function getAgentInstructionsZipLayout(zip) {
1969
1958
  return { agentFile: agentFile.entry, supportFiles };
1970
1959
  }
1971
1960
 
1961
+ function readInstalledAgentInstructionsVersion(projectRoot) {
1962
+ const versionFile = path.join(projectRoot, AGENT_INSTRUCTIONS_DIR, AGENT_INSTRUCTIONS_VERSION_FILE);
1963
+ if (!fs.existsSync(versionFile)) return "0";
1964
+
1965
+ const installedVersion = String(fs.readFileSync(versionFile, "utf8")).trim();
1966
+ return /^\d+(?:\.\d+)*$/.test(installedVersion) ? installedVersion : "0";
1967
+ }
1968
+
1972
1969
  async function syncAgentInstructions() {
1970
+ const projectRoot = process.cwd();
1971
+ const targetAgentFile = path.join(projectRoot, AGENT_INSTRUCTIONS_FILE);
1972
+ const targetAgentDir = path.join(projectRoot, AGENT_INSTRUCTIONS_DIR);
1973
+ const hasAgentDirectoryFiles =
1974
+ fs.existsSync(targetAgentDir) &&
1975
+ fs.statSync(targetAgentDir).isDirectory() &&
1976
+ fs.readdirSync(targetAgentDir).some(name => name !== AGENT_INSTRUCTIONS_VERSION_FILE);
1977
+ const requiredFilesExist = fs.existsSync(targetAgentFile) && hasAgentDirectoryFiles;
1978
+ const localVersion = readInstalledAgentInstructionsVersion(projectRoot);
1979
+
1973
1980
  const versions = await fetchVersions();
1974
1981
  const remoteVersion = String(versions?.[AGENT_INSTRUCTIONS_VERSION_KEY] || "").trim();
1975
1982
 
1976
1983
  if (!/^\d+(?:\.\d+)*$/.test(remoteVersion)) {
1977
- console.log(`ℹ️ No valid "${AGENT_INSTRUCTIONS_VERSION_KEY}" version found on the server. Skipping agent instructions update.`);
1978
- return;
1984
+ throw new Error(`Required agent instructions could not be resolved from the server.`);
1979
1985
  }
1980
1986
 
1981
- const projectRoot = process.cwd();
1982
- const targetAgentFile = path.join(projectRoot, AGENT_INSTRUCTIONS_FILE);
1983
- const targetAgentDir = path.join(projectRoot, AGENT_INSTRUCTIONS_DIR);
1984
- const localVersion = readInstalledAgentInstructionsVersion();
1985
- const filesAreMissing = !fs.existsSync(targetAgentFile) || !fs.existsSync(targetAgentDir);
1986
-
1987
- if (!filesAreMissing && compareVersionStrings(remoteVersion, localVersion) <= 0) {
1988
- console.log(`✅ Agent instructions are up to date (version ${localVersion}).`);
1987
+ const remoteIsNewer = compareVersionStrings(remoteVersion, localVersion) > 0;
1988
+ if (requiredFilesExist && !remoteIsNewer) {
1989
+ console.log(`✅ Agent instructions do not need an update (local ${localVersion}, online ${remoteVersion}).`);
1989
1990
  return;
1990
1991
  }
1991
1992
 
@@ -1998,8 +1999,7 @@ async function syncAgentInstructions() {
1998
1999
  try {
1999
2000
  console.log(`🔍 Checking latest agent instructions: ${zipName}`);
2000
2001
  if (!(await urlExists(url))) {
2001
- console.warn(`⚠️ Agent instructions archive not found: ${url}`);
2002
- return;
2002
+ throw new Error(`Required agent instructions archive not found: ${url}`);
2003
2003
  }
2004
2004
 
2005
2005
  await downloadFile(url, zipPath);
@@ -2017,6 +2017,7 @@ async function syncAgentInstructions() {
2017
2017
  fs.writeFileSync(stagedSupportFile, entry.getData());
2018
2018
  });
2019
2019
 
2020
+ fs.rmSync(targetAgentDir, { recursive: true, force: true });
2020
2021
  fs.mkdirSync(targetAgentDir, { recursive: true });
2021
2022
  fs.copyFileSync(stagedAgentFile, targetAgentFile);
2022
2023
  fs.cpSync(stagedAgentDir, targetAgentDir, { recursive: true, force: true });
@@ -2027,9 +2028,9 @@ async function syncAgentInstructions() {
2027
2028
  );
2028
2029
 
2029
2030
  writeUpdateLine(`Agent instructions ${localVersion} -> ${remoteVersion}`);
2030
- console.log(`✅ Agent instructions updated directly in the project root → v${remoteVersion}`);
2031
+ console.log(`✅ Agent instructions replaced in the project root → v${remoteVersion}.`);
2031
2032
  } catch (error) {
2032
- console.warn(`⚠️ Agent instructions update failed: ${error?.message || error}`);
2033
+ throw new Error(`Required agent instructions installation failed: ${error?.message || error}`);
2033
2034
  } finally {
2034
2035
  fs.rmSync(tempRoot, { recursive: true, force: true });
2035
2036
  }
@@ -5,8 +5,10 @@ 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 aiAssetsDirectory = path.join(__dirname, 'AI-Assets');
9
+ const amazonAssetsDirectory = path.join(aiAssetsDirectory, 'Amazon-Assets');
10
+ const samsungAssetsDirectory = path.join(aiAssetsDirectory, 'Samsung-Assets');
11
+ const playstoreAssetsDirectory = path.join(aiAssetsDirectory, 'Playstore-Assets');
10
12
  const capacitorConfigPath = path.join(__dirname, 'capacitor.config.json');
11
13
  const amazonIconPath = path.join(__dirname, 'resources', 'icon-only.png');
12
14
  const temporaryDirectory = path.join(__dirname, 'agent-temp');
@@ -20,6 +22,9 @@ const samsungAssetDefinitions = [
20
22
  { fileName: 'edge-screen-160x2560.png', type: 'edge-screen', width: 160, height: 2560 },
21
23
  { fileName: 'edge-screen-single-550x2560.png', type: 'edge-screen-single-plus', width: 550, height: 2560 },
22
24
  ];
25
+ const playstoreAssetDefinitions = [
26
+ { fileName: 'feature-graphic-1024x500.png', width: 1024, height: 500 },
27
+ ];
23
28
  const browserExecutablePaths = [
24
29
  'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
25
30
  'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
@@ -441,7 +446,7 @@ function printHelp() {
441
446
  console.log(' node take-screen-image.js --dry-run');
442
447
  console.log(' node take-screen-image.js --list');
443
448
  console.log('');
444
- console.log('A normal capture automatically creates any missing Amazon and Samsung store assets.');
449
+ console.log('A normal capture automatically creates any missing Amazon, Samsung, and Play Store assets.');
445
450
  }
446
451
 
447
452
  function selectProfiles(input) {
@@ -1522,6 +1527,81 @@ function createAmazonAssetHtml(asset, appName, iconBuffer, storeCopy) {
1522
1527
  </html>`;
1523
1528
  }
1524
1529
 
1530
+ function createPlaystoreFeatureHtml(appName, iconBuffer, storeCopy) {
1531
+ const iconDataUrl = `data:image/png;base64,${iconBuffer.toString('base64')}`;
1532
+ const safeAppName = escapeHtml(appName);
1533
+ const safeCallout = escapeHtml(storeCopy.amazonCallout);
1534
+ const featureMarkup = storeCopy.featureLabels.slice(0, 5)
1535
+ .map((label, index) => `<span><i>0${index + 1}</i>${escapeHtml(label)}</span>`)
1536
+ .join('');
1537
+
1538
+ return `<!doctype html>
1539
+ <html>
1540
+ <head>
1541
+ <meta charset="utf-8" />
1542
+ <style>
1543
+ * { box-sizing: border-box; }
1544
+ html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
1545
+ body {
1546
+ display: flex;
1547
+ align-items: center;
1548
+ padding: 42px 64px;
1549
+ color: #f7fbff;
1550
+ background: radial-gradient(circle at 84% 18%, rgba(53,212,235,0.3), transparent 31%), linear-gradient(120deg, #111729, #231039 58%, #071522);
1551
+ font-family: Arial, Helvetica, sans-serif;
1552
+ }
1553
+ main { display: flex; width: 100%; height: 100%; align-items: center; justify-content: space-between; gap: 48px; }
1554
+ .copy { max-width: 570px; }
1555
+ img { width: 128px; height: 128px; border-radius: 30px; object-fit: contain; }
1556
+ small { display: block; margin-top: 24px; color: #35d4eb; font-size: 18px; font-weight: 700; letter-spacing: 4px; text-transform: uppercase; }
1557
+ h1 { margin: 12px 0 18px; font-size: 64px; line-height: 0.98; }
1558
+ p { margin: 0; color: #b8c5d4; font-size: 23px; line-height: 1.35; }
1559
+ .features { display: grid; width: 340px; gap: 12px; }
1560
+ .features span { display: flex; align-items: center; gap: 16px; padding: 17px 20px; border: 1px solid rgba(255,255,255,0.16); border-radius: 15px; background: rgba(8,16,28,0.6); font-size: 18px; font-weight: 700; }
1561
+ .features i { color: #c9ff41; font-size: 13px; font-style: normal; }
1562
+ </style>
1563
+ </head>
1564
+ <body><main><section class="copy"><img src="${iconDataUrl}" /><small>Explore ${safeAppName}</small><h1>${safeAppName}</h1><p>${safeCallout}</p></section><section class="features">${featureMarkup}</section></main></body>
1565
+ </html>`;
1566
+ }
1567
+
1568
+ async function createPlaystoreAssets(client, skipExisting = false) {
1569
+ if (!fs.existsSync(amazonIconPath)) {
1570
+ throw new Error(`Play Store asset source icon was not found: ${amazonIconPath}`);
1571
+ }
1572
+
1573
+ const config = JSON.parse(fs.readFileSync(capacitorConfigPath, 'utf8'));
1574
+ const appName = config.appName || 'App';
1575
+ const storeCopy = getStoreAssetCopy(config);
1576
+ const iconBuffer = fs.readFileSync(amazonIconPath);
1577
+ fs.mkdirSync(playstoreAssetsDirectory, { recursive: true });
1578
+
1579
+ for (const asset of playstoreAssetDefinitions) {
1580
+ const outputPath = path.join(playstoreAssetsDirectory, asset.fileName);
1581
+ if (skipExisting && fs.existsSync(outputPath)) continue;
1582
+
1583
+ await client.send('Emulation.setDeviceMetricsOverride', {
1584
+ width: asset.width, height: asset.height, deviceScaleFactor: 1, mobile: false,
1585
+ screenWidth: asset.width, screenHeight: asset.height, positionX: 0, positionY: 0,
1586
+ });
1587
+ const frameTree = await client.send('Page.getFrameTree');
1588
+ await client.send('Page.setDocumentContent', {
1589
+ frameId: frameTree.frameTree.frame.id,
1590
+ html: createPlaystoreFeatureHtml(appName, iconBuffer, storeCopy),
1591
+ });
1592
+ await client.send('Runtime.evaluate', {
1593
+ expression: `Promise.all([...document.images].map((image) => image.complete ? Promise.resolve() : new Promise((resolve) => image.addEventListener('load', resolve, { once: true })))).then(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))))`,
1594
+ awaitPromise: true,
1595
+ returnByValue: true,
1596
+ });
1597
+ const screenshot = await client.send('Page.captureScreenshot', {
1598
+ format: 'png', fromSurface: true, captureBeyondViewport: false,
1599
+ });
1600
+ fs.writeFileSync(outputPath, Buffer.from(screenshot.data, 'base64'));
1601
+ console.log(`Saved Play Store feature ${asset.width}x${asset.height}: ${outputPath}`);
1602
+ }
1603
+ }
1604
+
1525
1605
  async function createAmazonAssets(client, skipExisting = false) {
1526
1606
  if (!fs.existsSync(amazonIconPath)) {
1527
1607
  throw new Error(`Amazon asset source icon was not found: ${amazonIconPath}`);
@@ -1754,9 +1834,12 @@ async function createMissingStoreAssets() {
1754
1834
  const hasMissingSamsungAssets = samsungAssetDefinitions.some((asset) => (
1755
1835
  !fs.existsSync(path.join(samsungAssetsDirectory, asset.fileName))
1756
1836
  ));
1837
+ const hasMissingPlaystoreAssets = playstoreAssetDefinitions.some((asset) => (
1838
+ !fs.existsSync(path.join(playstoreAssetsDirectory, asset.fileName))
1839
+ ));
1757
1840
 
1758
- if (!hasMissingAmazonAssets && !hasMissingSamsungAssets) {
1759
- console.log('Amazon and Samsung store assets already exist.');
1841
+ if (!hasMissingAmazonAssets && !hasMissingSamsungAssets && !hasMissingPlaystoreAssets) {
1842
+ console.log('Amazon, Samsung, and Play Store assets already exist.');
1760
1843
  return;
1761
1844
  }
1762
1845
 
@@ -1774,12 +1857,15 @@ async function createMissingStoreAssets() {
1774
1857
  if (hasMissingSamsungAssets) {
1775
1858
  await createSamsungAssets(client, true);
1776
1859
  }
1860
+ if (hasMissingPlaystoreAssets) {
1861
+ await createPlaystoreAssets(client, true);
1862
+ }
1777
1863
  } finally {
1778
1864
  if (client) client.close();
1779
1865
  if (browser) await closeReplayBrowser(browser);
1780
1866
  }
1781
1867
 
1782
- console.log('Missing Amazon and Samsung store assets created.');
1868
+ console.log('Missing Amazon, Samsung, and Play Store assets created.');
1783
1869
  }
1784
1870
 
1785
1871
  async function captureFramedScreenshot(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "4.4.8",
3
+ "version": "4.5.0",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",