Преглед на файлове

feat(scripts): перенос apk в корень проекта

horanchikk преди 5 месеца
родител
ревизия
8f7a33200d
променени са 4 файла, в които са добавени 28 реда и са изтрити 8 реда
  1. 3 1
      .env.example
  2. 1 1
      release.config.cjs
  3. 5 6
      scripts/mobileBuild.ts
  4. 19 0
      scripts/utils.ts

+ 3 - 1
.env.example

@@ -6,4 +6,6 @@ ACCOUNT_PASSWD=
 SENTRY_ORG=
 SENTRY_PROJECT=
 SENTRY_AUTH_TOKEN=
-SENTRY_DSN=
+SENTRY_DSN=
+
+APP_VERSION=development

+ 1 - 1
release.config.cjs

@@ -30,7 +30,7 @@ module.exports = {
       {
         assets: [
           {
-            path: 'android/app/build/outputs/apk/debug/app-debug.apk',
+            path: `${process.env.APP_VERSION}.apk`,
             label: 'Android APK [${nextRelease.version}]',
           },
         ],

+ 5 - 6
scripts/mobileBuild.ts

@@ -10,6 +10,7 @@ import {
   createDir,
   runCommand,
   ensureDownloadedAndExtracted,
+  renameWithOverwrite,
 } from './utils'
 
 initDE()
@@ -78,13 +79,10 @@ await new Listr(
                     Record<NodeJS.Platform, Partial<Record<NodeJS.Architecture, string>>>
                   > = {
                     linux: {
-                      x64: 'https://download.oracle.com/java/20/archive/jdk-20.0.2_linux-x64_bin.tar.gz',
-                      arm64: 'https://download.oracle.com/java/20/archive/jdk-20.0.2_linux-aarch64_bin.tar.gz',
+                      x64: `https://download.oracle.com/java/${config.JAVA_VERSION.split('.')[0]}/archive/jdk-${config.JAVA_VERSION}_linux-x64_bin.tar.gz`,
+                      arm64: `https://download.oracle.com/java/${config.JAVA_VERSION.split('.')[0]}/archive/jdk-${config.JAVA_VERSION}_linux-aarch64_bin.tar.gz`,
                     },
                     // TODO: add support for win32
-                    // win32: {
-                    //   x64: 'https://download.oracle.com/java/20/archive/jdk-20.0.2_windows-x64_bin.zip',
-                    // },
                   }
                   const platform = os.platform() as keyof typeof systemConfig
                   const arch = os.arch()
@@ -192,7 +190,8 @@ await new Listr(
                   task: subTask,
                   maxOutputLines: 3,
                 })
-                subTask.title = `APK built at: ${currentPath}/android/app/build/outputs/apk/debug/app-debug.apk`
+                renameWithOverwrite(`${currentPath}/android/app/build/outputs/apk/debug/app-debug.apk`, `${currentPath}/${process.env.APP_VERSION}.apk`)
+                subTask.title = `APK built at: ${currentPath}/${process.env.APP_VERSION}.apk`
               },
             },
             {

+ 19 - 0
scripts/utils.ts

@@ -13,6 +13,25 @@ export async function fileExistsAsync(filePath: string): Promise<boolean> {
   }
 }
 
+export async function renameWithOverwrite(oldPath: string, newPath: string): Promise<void> {
+  try {
+    try {
+      await fs.access(newPath);
+      await fs.unlink(newPath);
+      console.log(`Файл по пути "${newPath}" был удален`);
+    } catch (err) {
+      if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {
+        throw err;
+      }
+    }
+
+    await fs.rename(oldPath, newPath);
+  } catch (err) {
+    const error = err as NodeJS.ErrnoException;
+    throw error;
+  }
+}
+
 export async function removeDir(dir: string): Promise<void> {
   await fs.rm(dir, { recursive: true, force: true })
 }