codeplay-common 4.11.11 → 4.11.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +114 -101
  2. package/LICENSE +21 -21
  3. package/README.md +274 -229
  4. package/RELEASE_NOTES.md +110 -97
  5. package/files/buildCodeplay/add-splash-screen.js +256 -255
  6. package/files/buildCodeplay/apk-store-builder.js +97 -97
  7. package/files/buildCodeplay/codeplayBeforeBuild.js +45 -43
  8. package/files/buildCodeplay/ensure-current-build.cjs +42 -42
  9. package/files/buildCodeplay/fix-onesignal-plugin.js +96 -96
  10. package/files/buildCodeplay/ios-emi-admob-modification.js +49 -49
  11. package/files/buildCodeplay/manifestModification.js +38 -38
  12. package/files/buildCodeplay/newly added.txt +89 -89
  13. package/files/buildCodeplay/release-sync.config.json +4 -4
  14. package/files/buildCodeplay/remove-force-kotlin-disable.js +43 -43
  15. package/files/buildCodeplay/setSplashAnimation.js +227 -225
  16. package/files/buildCodeplay/splash-setup.cjs +88 -0
  17. package/files/buildCodeplay/splashxml/codeplay_splashScreen.xml +1 -1
  18. package/files/buildCodeplay/sync-admob-nextgen.js +219 -219
  19. package/files/buildCodeplay/versions.json +27 -27
  20. package/files/finalrelease +1263 -1246
  21. package/files/generate-ai-promo-video.js +23 -23
  22. package/files/ionic.config.json +6 -6
  23. package/files/scripts-common/generate-baseline-profile.js +46 -46
  24. package/files/scripts-common/run-codeplay-sync-after.js +21 -21
  25. package/files/scripts-common/screenshot/background-decorations.js +120 -120
  26. package/files/scripts-common/screenshot/frame-samples.js +117 -117
  27. package/files/scripts-common/setup-baseline-profile.js +291 -291
  28. package/files/take-screen-image.js +2 -1
  29. package/files/take-screen-video.js +644 -644
  30. package/package.json +3 -2
  31. package/runtime/splash-ready.mjs +52 -0
  32. package/scripts/ensure-current-build.test.cjs +76 -76
  33. package/scripts/splash-setup.test.cjs +142 -0
  34. package/scripts/sync-files.js +114 -113
  35. package/scripts/uninstall.js +2 -2
@@ -1,98 +1,98 @@
1
- const { spawn } = require("child_process");
2
- const path = require("path");
3
- const fs = require("fs");
4
-
5
- // Paths
6
- //const projectRoot = path.join(__dirname, "..");
7
- const projectRoot = process.cwd();
8
- const androidPath = path.join(projectRoot, "android");
9
- const capacitorConfigPath = path.join(projectRoot, "capacitor.config.json");
10
-
11
- // Read capacitor.config.json
12
- if (!fs.existsSync(capacitorConfigPath)) {
13
- console.error("❌ capacitor.config.json not found!");
14
- process.exit(1);
15
- }
16
-
17
- const config = JSON.parse(fs.readFileSync(capacitorConfigPath, "utf8"));
18
-
19
- const buildOptions = config.android?.buildOptions;
20
-
21
- if (!buildOptions) {
22
- console.error("❌ android.buildOptions not found in capacitor.config.json");
23
- process.exit(1);
24
- }
25
-
26
- // Resolve keystore path (relative → absolute)
27
-
28
-
29
- const storePassword = buildOptions.keystorePassword;
30
- const keyAlias = buildOptions.keystoreAlias;
31
- const keyPassword = buildOptions.keystoreAliasPassword;
32
-
33
-
34
-
35
-
36
-
37
-
38
- const rawKeystorePath = buildOptions.keystorePath;
39
-
40
- // First try normal resolve
41
- let keystorePath = path.resolve(projectRoot, rawKeystorePath);
42
-
43
- // If not found, try trimming one "../"
44
- if (!fs.existsSync(keystorePath)) {
45
- console.log("⚠️ Keystore not found, attempting path correction...");
46
-
47
- const trimmedPath = rawKeystorePath.replace(/^\.\.\//, "");
48
- keystorePath = path.resolve(projectRoot, trimmedPath);
49
- }
50
-
51
- // Final validation
52
- if (!fs.existsSync(keystorePath)) {
53
- console.error("❌ Keystore file not found even after correction:", keystorePath);
54
- process.exit(1);
55
- }
56
-
57
- console.log("🔐 Using keystore:", keystorePath);
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
- // Gradle args
69
- const isWindows = process.platform === "win32";
70
- const command = isWindows ? "cmd.exe" : "sh";
71
- const args = [
72
- ...(isWindows ? ["/c", "gradlew.bat"] : ["./gradlew"]),
73
- "assembleRelease",
74
- `-Pandroid.injected.signing.store.file=${keystorePath}`,
75
- `-Pandroid.injected.signing.store.password=${storePassword}`,
76
- `-Pandroid.injected.signing.key.alias=${keyAlias}`,
77
- `-Pandroid.injected.signing.key.password=${keyPassword}`,
78
- ];
79
-
80
- // Run Gradle
81
- const gradle = spawn(command, args, {
82
- cwd: androidPath,
83
- stdio: "inherit",
84
- });
85
-
86
- gradle.on("error", (error) => {
87
- console.error("❌ Could not start Gradle:", error.message);
88
- process.exit(1);
89
- });
90
-
91
- gradle.on("close", (code) => {
92
- if (code === 0) {
93
- console.log("\n✅ Signed APK Generated Successfully!");
94
- } else {
95
- console.log("\n❌ Build Failed with code:", code);
96
- process.exit(code ?? 1);
97
- }
1
+ const { spawn } = require("child_process");
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+
5
+ // Paths
6
+ //const projectRoot = path.join(__dirname, "..");
7
+ const projectRoot = process.cwd();
8
+ const androidPath = path.join(projectRoot, "android");
9
+ const capacitorConfigPath = path.join(projectRoot, "capacitor.config.json");
10
+
11
+ // Read capacitor.config.json
12
+ if (!fs.existsSync(capacitorConfigPath)) {
13
+ console.error("❌ capacitor.config.json not found!");
14
+ process.exit(1);
15
+ }
16
+
17
+ const config = JSON.parse(fs.readFileSync(capacitorConfigPath, "utf8"));
18
+
19
+ const buildOptions = config.android?.buildOptions;
20
+
21
+ if (!buildOptions) {
22
+ console.error("❌ android.buildOptions not found in capacitor.config.json");
23
+ process.exit(1);
24
+ }
25
+
26
+ // Resolve keystore path (relative → absolute)
27
+
28
+
29
+ const storePassword = buildOptions.keystorePassword;
30
+ const keyAlias = buildOptions.keystoreAlias;
31
+ const keyPassword = buildOptions.keystoreAliasPassword;
32
+
33
+
34
+
35
+
36
+
37
+
38
+ const rawKeystorePath = buildOptions.keystorePath;
39
+
40
+ // First try normal resolve
41
+ let keystorePath = path.resolve(projectRoot, rawKeystorePath);
42
+
43
+ // If not found, try trimming one "../"
44
+ if (!fs.existsSync(keystorePath)) {
45
+ console.log("⚠️ Keystore not found, attempting path correction...");
46
+
47
+ const trimmedPath = rawKeystorePath.replace(/^\.\.\//, "");
48
+ keystorePath = path.resolve(projectRoot, trimmedPath);
49
+ }
50
+
51
+ // Final validation
52
+ if (!fs.existsSync(keystorePath)) {
53
+ console.error("❌ Keystore file not found even after correction:", keystorePath);
54
+ process.exit(1);
55
+ }
56
+
57
+ console.log("🔐 Using keystore:", keystorePath);
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+ // Gradle args
69
+ const isWindows = process.platform === "win32";
70
+ const command = isWindows ? "cmd.exe" : "sh";
71
+ const args = [
72
+ ...(isWindows ? ["/c", "gradlew.bat"] : ["./gradlew"]),
73
+ "assembleRelease",
74
+ `-Pandroid.injected.signing.store.file=${keystorePath}`,
75
+ `-Pandroid.injected.signing.store.password=${storePassword}`,
76
+ `-Pandroid.injected.signing.key.alias=${keyAlias}`,
77
+ `-Pandroid.injected.signing.key.password=${keyPassword}`,
78
+ ];
79
+
80
+ // Run Gradle
81
+ const gradle = spawn(command, args, {
82
+ cwd: androidPath,
83
+ stdio: "inherit",
84
+ });
85
+
86
+ gradle.on("error", (error) => {
87
+ console.error("❌ Could not start Gradle:", error.message);
88
+ process.exit(1);
89
+ });
90
+
91
+ gradle.on("close", (code) => {
92
+ if (code === 0) {
93
+ console.log("\n✅ Signed APK Generated Successfully!");
94
+ } else {
95
+ console.log("\n❌ Build Failed with code:", code);
96
+ process.exit(code ?? 1);
97
+ }
98
98
  });
@@ -1,4 +1,5 @@
1
- // Version 6.9: preserve configured notification icons during Android resource shrinking.
1
+ // Version 7.0: prepare shared splash readiness and migrate the legacy splash theme.
2
+ // Version 6.9: preserve configured notification icons during Android resource shrinking.
2
3
  // Version 6.8: preserve Capacitor permission annotations for Love Calculator Android builds.
3
4
  // Version 6.7: deferred IAP startup, ownership-safe ads, and unified store preparation.
4
5
  // Version 6.7: migrate AdMob files to ZIP-distributed folder packages.
@@ -228,7 +229,7 @@ const { execSync } = require("child_process");
228
229
  const { readFileSync } = require("fs");
229
230
  const readline = require('readline');
230
231
 
231
- // Complete asynchronous preparation before continuing the remaining build steps.
232
+ // Complete asynchronous preparation before continuing the remaining build steps.
232
233
  (async () => {
233
234
 
234
235
  // Standalone builds default to Android on every host OS.
@@ -342,9 +343,9 @@ const ROOT_DIR = path.join(process.cwd(), "src");
342
343
 
343
344
  function requireOrInstall(packageName) {
344
345
  try {
345
- require.resolve(packageName);
346
+ require.resolve(packageName);
346
347
  } catch (err) {
347
- if (err.code !== 'MODULE_NOT_FOUND') throw err;
348
+ if (err.code !== 'MODULE_NOT_FOUND') throw err;
348
349
 
349
350
  console.log(`📦 "${packageName}" not found. Installing automatically...`);
350
351
 
@@ -357,8 +358,8 @@ function requireOrInstall(packageName) {
357
358
  }
358
359
 
359
360
  }
360
- // Loading errors in an installed package must not trigger another install.
361
- return require(packageName);
361
+ // Loading errors in an installed package must not trigger another install.
362
+ return require(packageName);
362
363
  }
363
364
 
364
365
  const AdmZip = requireOrInstall("adm-zip");
@@ -998,7 +999,7 @@ const saveToGalleryAndSaveFileCheck_iOS = async () => {
998
999
  const SAVE_FILE_REGEX = /^(.*[\/\\])?(saveToGalleryAndSaveAnyFile-\d+(?:\.\d+)*)(-ios)?(\.js)?([?#].*)?$/;
999
1000
  const pendingChanges = [];
1000
1001
 
1001
- const ALLOWED_EXTENSIONS = ['.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.f7'];
1002
+ const ALLOWED_EXTENSIONS = ['.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.f7'];
1002
1003
  const referencedVersions = new Set();
1003
1004
  let aliasImportFound = false;
1004
1005
  let hasForbiddenEditorImport = false;
@@ -1047,7 +1048,7 @@ function scanSourceFile(dir) {
1047
1048
  */
1048
1049
 
1049
1050
  const baseName = path.basename(dir);
1050
- const shouldCheckGallery = !dir.split(path.sep).includes('node_modules') && !SKIP_FILES.includes(baseName)
1051
+ const shouldCheckGallery = !dir.split(path.sep).includes('node_modules') && !SKIP_FILES.includes(baseName)
1051
1052
  && ALLOWED_EXTENSIONS.some(ext => dir.endsWith(ext));
1052
1053
  const shouldCheckEditor = /\.(js|ts|f7)$/.test(dir);
1053
1054
  const shouldCheckOneSignal = /\.(js|mjs|cjs|ts|tsx|jsx|f7)$/.test(dir);
@@ -1068,21 +1069,21 @@ function scanSourceFile(dir) {
1068
1069
  }
1069
1070
  }
1070
1071
 
1071
- // Framework7 templates contain HTML quotes and expressions, not JavaScript.
1072
- // Mask everything outside <script> while retaining original edit offsets.
1073
- let scriptContent = content;
1074
- if (dir.endsWith('.f7')) {
1075
- const script = /<script\b[^>]*>([\s\S]*?)<\/script\s*>/i.exec(content);
1076
- if (script) {
1077
- const start = script.index + script[0].indexOf('>') + 1;
1078
- const end = start + script[1].length;
1079
- scriptContent = content.slice(0, start).replace(/[^\r\n]/g, ' ')
1080
- + script[1] + content.slice(end).replace(/[^\r\n]/g, ' ');
1081
- } else {
1082
- scriptContent = content.replace(/[^\r\n]/g, ' ');
1083
- }
1084
- }
1085
- const code = scriptContent.replace(COMMENT_OR_STRING_REGEX, (match, quote) =>
1072
+ // Framework7 templates contain HTML quotes and expressions, not JavaScript.
1073
+ // Mask everything outside <script> while retaining original edit offsets.
1074
+ let scriptContent = content;
1075
+ if (dir.endsWith('.f7')) {
1076
+ const script = /<script\b[^>]*>([\s\S]*?)<\/script\s*>/i.exec(content);
1077
+ if (script) {
1078
+ const start = script.index + script[0].indexOf('>') + 1;
1079
+ const end = start + script[1].length;
1080
+ scriptContent = content.slice(0, start).replace(/[^\r\n]/g, ' ')
1081
+ + script[1] + content.slice(end).replace(/[^\r\n]/g, ' ');
1082
+ } else {
1083
+ scriptContent = content.replace(/[^\r\n]/g, ' ');
1084
+ }
1085
+ }
1086
+ const code = scriptContent.replace(COMMENT_OR_STRING_REGEX, (match, quote) =>
1086
1087
  quote ? match : match.replace(/[^\r\n]/g, ' ')
1087
1088
  );
1088
1089
  const replacements = [];
@@ -1146,13 +1147,13 @@ if (referencedVersions.size || aliasImportFound) {
1146
1147
  const existingName = path.basename(aliasMatch[3]).match(SAVE_FILE_REGEX);
1147
1148
  if (!existingName) throw new Error('❌ @saveGallery must point to a versioned saveToGalleryAndSaveAnyFile helper.');
1148
1149
  }
1149
- // Imports can still mention deleted versions after a plugin update. Resolve the
1150
- // alias from installed files instead, using only the selected platform variant.
1151
- const jsDir = path.join(SOURCE_ROOT, 'js');
1152
- const pattern = isIOSBuild ? /^saveToGalleryAndSaveAnyFile-\d+(?:\.\d+)*-ios\.js$/ : /^saveToGalleryAndSaveAnyFile-\d+(?:\.\d+)*\.js$/;
1153
- const latestFile = getLatestVersionedFileName(jsDir, pattern);
1154
- if (!latestFile) throw new Error(`❌ No ${buildPlatform} save-gallery helper found in src/js.`);
1155
- const targetRelativePath = `./src/js/${latestFile}`;
1150
+ // Imports can still mention deleted versions after a plugin update. Resolve the
1151
+ // alias from installed files instead, using only the selected platform variant.
1152
+ const jsDir = path.join(SOURCE_ROOT, 'js');
1153
+ const pattern = isIOSBuild ? /^saveToGalleryAndSaveAnyFile-\d+(?:\.\d+)*-ios\.js$/ : /^saveToGalleryAndSaveAnyFile-\d+(?:\.\d+)*\.js$/;
1154
+ const latestFile = getLatestVersionedFileName(jsDir, pattern);
1155
+ if (!latestFile) throw new Error(`❌ No ${buildPlatform} save-gallery helper found in src/js.`);
1156
+ const targetRelativePath = `./src/js/${latestFile}`;
1156
1157
  const targetPath = path.resolve(path.dirname(viteConfigPath), targetRelativePath);
1157
1158
  if (!fs.existsSync(targetPath)) throw new Error(`❌ Cannot configure @saveGallery: target file does not exist: ${targetPath}`);
1158
1159
  const aliasEntry = `'@saveGallery': path.resolve(__dirname, '${targetRelativePath}')`;
@@ -1195,10 +1196,10 @@ if (pendingChanges.length) {
1195
1196
  }
1196
1197
  }
1197
1198
 
1198
- // Validate all pending edits before applying the automatic migration.
1199
+ // Validate all pending edits before applying the automatic migration.
1199
1200
  for (const change of pendingChanges) {
1200
1201
  if (fs.readFileSync(change.filePath, 'utf8') !== change.content) {
1201
- throw new Error(`❌ Source changed during alias migration: ${change.filePath}. Build cancelled; run it again.`);
1202
+ throw new Error(`❌ Source changed during alias migration: ${change.filePath}. Build cancelled; run it again.`);
1202
1203
  }
1203
1204
  }
1204
1205
  for (const change of pendingChanges) {
@@ -2471,7 +2472,7 @@ if (pluginDef.isFolder) {
2471
2472
  updateImports(pluginInfo.name, `${baseName}-${latestVersion}`);
2472
2473
 
2473
2474
  fs.rmSync(oldPath, { recursive: true, force: true });
2474
- sourceFileInventory = null; // updateImports cached files from the removed folder.
2475
+ sourceFileInventory = null; // updateImports cached files from the removed folder.
2475
2476
  // ✅ ADD THIS
2476
2477
  writeUpdateLine(`${pluginInfo.name} -> ${baseName}-${latestVersion}`);
2477
2478
 
@@ -2547,7 +2548,7 @@ existingFiles.forEach(file => {
2547
2548
  const oldPath = path.join(pluginDir, file);
2548
2549
 
2549
2550
  fs.unlinkSync(oldPath);
2550
- sourceFileInventory = null;
2551
+ sourceFileInventory = null;
2551
2552
 
2552
2553
  console.log(`🗑 Removed old file → ${file}`);
2553
2554
  //writeUpdateLine(`Removed old file: ${file}`);
@@ -3179,7 +3180,7 @@ function ensureMandatoryCapacitorPlugins() {
3179
3180
  ];
3180
3181
 
3181
3182
  for (const packageName of requiredPackages) {
3182
- if (getInstalledVersion(packageName)) {
3183
+ if (getInstalledVersion(packageName)) {
3183
3184
  console.log(`ℹ️ ${packageName} is already installed.`);
3184
3185
  continue;
3185
3186
  }
@@ -3204,7 +3205,7 @@ const syncCodeplaySystemBarsPackage = () => {
3204
3205
  return;
3205
3206
  }
3206
3207
 
3207
- if (!getInstalledVersion(CODEPLAY_SYSTEM_BARS_PLUGIN)) {
3208
+ if (!getInstalledVersion(CODEPLAY_SYSTEM_BARS_PLUGIN)) {
3208
3209
  runNpmCommand(`npm install ${CODEPLAY_SYSTEM_BARS_PLUGIN}`);
3209
3210
  return;
3210
3211
  }
@@ -3381,7 +3382,7 @@ const syncAdmobNextgenPackage = () => {
3381
3382
  console.log("ℹ️ emi-indo-cordova-plugin-admob is not installed.");
3382
3383
  }
3383
3384
 
3384
- if (!getInstalledVersion("capacitor-admob-nextgen")) {
3385
+ if (!getInstalledVersion("capacitor-admob-nextgen")) {
3385
3386
  runNpmCommand("npm install capacitor-admob-nextgen");
3386
3387
  } else {
3387
3388
  console.log("ℹ️ capacitor-admob-nextgen is already installed.");
@@ -3670,9 +3671,9 @@ const syncFirebaseAnalyticsPackages = () => {
3670
3671
  const analyticsConfig = getAnalyticsConfig();
3671
3672
 
3672
3673
  if (analyticsConfig.enabled) {
3673
- // The native wrapper uses registerPlugin; Firebase's optional web SDK is
3674
- // not required and its absence must not reinstall the native plugin.
3675
- if (!getInstalledVersion("@capacitor-firebase/analytics")) {
3674
+ // The native wrapper uses registerPlugin; Firebase's optional web SDK is
3675
+ // not required and its absence must not reinstall the native plugin.
3676
+ if (!getInstalledVersion("@capacitor-firebase/analytics")) {
3676
3677
  runNpmCommand("npm install @capacitor-firebase/analytics");
3677
3678
  } else {
3678
3679
  console.log("ℹ️ Firebase Analytics packages already installed.");
@@ -4098,7 +4099,7 @@ const syncRevenueCatIapSetup = () => {
4098
4099
  let packageChanged = false;
4099
4100
 
4100
4101
  if (revenueCatEnabledForCurrentStore) {
4101
- if (!getInstalledVersion("@revenuecat/purchases-capacitor")) {
4102
+ if (!getInstalledVersion("@revenuecat/purchases-capacitor")) {
4102
4103
  runNpmCommand("npm install @revenuecat/purchases-capacitor");
4103
4104
  packageChanged = true;
4104
4105
  } else {
@@ -4640,6 +4641,7 @@ async function main() {
4640
4641
  buildPackage.scripts = buildScripts;
4641
4642
  fs.writeFileSync(packageJsonPath, JSON.stringify(buildPackage, null, 2) + '\n');
4642
4643
  }
4644
+ require('./splash-setup.cjs').syncSplashSetup(process.cwd());
4643
4645
  validateThemeFolderLocation();
4644
4646
  validateAndRestoreSignDetails();
4645
4647
  ensureMandatoryCapacitorPlugins();
@@ -4647,8 +4649,8 @@ async function main() {
4647
4649
  await loadPluginVersions(); // 🔥 NEW
4648
4650
  await syncAgentInstructions();
4649
4651
  await checkPlugins();
4650
- // Downloads may add a newer helper or source files containing legacy imports.
4651
- await saveToGalleryAndSaveFileCheck_iOS();
4652
+ // Downloads may add a newer helper or source files containing legacy imports.
4653
+ await saveToGalleryAndSaveFileCheck_iOS();
4652
4654
 
4653
4655
  await syncAdmobNextgenMigration();
4654
4656
  syncCodeplaySystemBarsPackage();
@@ -1,42 +1,42 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { execSync, execFileSync } = require('child_process');
4
-
5
- function findVersionedBuildFiles(projectRoot) {
6
- const directory = path.join(projectRoot, 'buildCodeplay');
7
- if (!fs.existsSync(directory)) return [];
8
- return fs.readdirSync(directory, { withFileTypes: true })
9
- .filter(entry => entry.isFile() && /-\d+(?:\.\d+)*(?:-beta-\d+)?\.[^.]+$/i.test(entry.name))
10
- .map(entry => entry.name);
11
- }
12
-
13
- function ensureCurrentBuild(options = {}) {
14
- const projectRoot = path.resolve(options.projectRoot || process.cwd());
15
- const legacyFiles = findVersionedBuildFiles(projectRoot);
16
- if (!legacyFiles.length) return false;
17
-
18
- console.log(`Legacy buildCodeplay files found: ${legacyFiles.join(', ')}. Reinstalling codeplay-common before continuing.`);
19
- const runNpm = options.runNpm || (command => execSync(command, { cwd: projectRoot, stdio: 'inherit' }));
20
- runNpm('npm uninstall codeplay-common');
21
- runNpm('npm install codeplay-common');
22
-
23
- // Postinstall replaces the scripts and removes recognized legacy files.
24
- // Do not run stale code or retry indefinitely if migration did not finish.
25
- const remaining = findVersionedBuildFiles(projectRoot);
26
- if (remaining.length) {
27
- throw new Error(`Legacy buildCodeplay files remain after reinstall: ${remaining.join(', ')}. Build stopped; migrate these files before retrying.`);
28
- }
29
- const entrypoint = path.join(projectRoot, 'buildCodeplay', 'codeplayBeforeBuild.js');
30
- if (!fs.existsSync(entrypoint)) throw new Error('codeplayBeforeBuild.js is missing after reinstall. Build stopped.');
31
-
32
- // The current process loaded the old templates. Finish preparation in a fresh
33
- // process before the caller's remaining build commands are allowed to run.
34
- const runBeforeBuild = options.runBeforeBuild || (script => execFileSync(process.execPath, [script, ...process.argv.slice(2)], {
35
- cwd: projectRoot,
36
- stdio: 'inherit',
37
- }));
38
- runBeforeBuild(entrypoint);
39
- return true;
40
- }
41
-
42
- module.exports = { ensureCurrentBuild, findVersionedBuildFiles };
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { execSync, execFileSync } = require('child_process');
4
+
5
+ function findVersionedBuildFiles(projectRoot) {
6
+ const directory = path.join(projectRoot, 'buildCodeplay');
7
+ if (!fs.existsSync(directory)) return [];
8
+ return fs.readdirSync(directory, { withFileTypes: true })
9
+ .filter(entry => entry.isFile() && /-\d+(?:\.\d+)*(?:-beta-\d+)?\.[^.]+$/i.test(entry.name))
10
+ .map(entry => entry.name);
11
+ }
12
+
13
+ function ensureCurrentBuild(options = {}) {
14
+ const projectRoot = path.resolve(options.projectRoot || process.cwd());
15
+ const legacyFiles = findVersionedBuildFiles(projectRoot);
16
+ if (!legacyFiles.length) return false;
17
+
18
+ console.log(`Legacy buildCodeplay files found: ${legacyFiles.join(', ')}. Reinstalling codeplay-common before continuing.`);
19
+ const runNpm = options.runNpm || (command => execSync(command, { cwd: projectRoot, stdio: 'inherit' }));
20
+ runNpm('npm uninstall codeplay-common');
21
+ runNpm('npm install codeplay-common');
22
+
23
+ // Postinstall replaces the scripts and removes recognized legacy files.
24
+ // Do not run stale code or retry indefinitely if migration did not finish.
25
+ const remaining = findVersionedBuildFiles(projectRoot);
26
+ if (remaining.length) {
27
+ throw new Error(`Legacy buildCodeplay files remain after reinstall: ${remaining.join(', ')}. Build stopped; migrate these files before retrying.`);
28
+ }
29
+ const entrypoint = path.join(projectRoot, 'buildCodeplay', 'codeplayBeforeBuild.js');
30
+ if (!fs.existsSync(entrypoint)) throw new Error('codeplayBeforeBuild.js is missing after reinstall. Build stopped.');
31
+
32
+ // The current process loaded the old templates. Finish preparation in a fresh
33
+ // process before the caller's remaining build commands are allowed to run.
34
+ const runBeforeBuild = options.runBeforeBuild || (script => execFileSync(process.execPath, [script, ...process.argv.slice(2)], {
35
+ cwd: projectRoot,
36
+ stdio: 'inherit',
37
+ }));
38
+ runBeforeBuild(entrypoint);
39
+ return true;
40
+ }
41
+
42
+ module.exports = { ensureCurrentBuild, findVersionedBuildFiles };