@blotch/angular-lynx-native 22.2.20 → 22.2.22

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 (70) hide show
  1. package/README.md +8 -4
  2. package/dist/android/build.d.ts +6 -1
  3. package/dist/android/build.d.ts.map +1 -1
  4. package/dist/android/build.js +14 -3
  5. package/dist/android/icon.d.ts +29 -0
  6. package/dist/android/icon.d.ts.map +1 -0
  7. package/dist/android/icon.js +142 -0
  8. package/dist/android/project.d.ts +2 -1
  9. package/dist/android/project.d.ts.map +1 -1
  10. package/dist/android/project.js +5 -2
  11. package/dist/android/run.d.ts +10 -1
  12. package/dist/android/run.d.ts.map +1 -1
  13. package/dist/android/run.js +46 -1
  14. package/dist/dev-build.d.ts +16 -0
  15. package/dist/dev-build.d.ts.map +1 -0
  16. package/dist/dev-build.js +44 -0
  17. package/dist/generate.d.ts +26 -7
  18. package/dist/generate.d.ts.map +1 -1
  19. package/dist/generate.js +25 -10
  20. package/dist/index.d.ts +13 -4
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +77 -13
  23. package/dist/ios/build.d.ts +68 -12
  24. package/dist/ios/build.d.ts.map +1 -1
  25. package/dist/ios/build.js +210 -45
  26. package/dist/ios/iphone.d.ts +99 -0
  27. package/dist/ios/iphone.d.ts.map +1 -0
  28. package/dist/ios/iphone.js +207 -0
  29. package/dist/ios/project.d.ts +10 -1
  30. package/dist/ios/project.d.ts.map +1 -1
  31. package/dist/ios/project.js +27 -4
  32. package/dist/ios/run.d.ts +18 -3
  33. package/dist/ios/run.d.ts.map +1 -1
  34. package/dist/ios/run.js +34 -5
  35. package/dist/options.d.ts +49 -3
  36. package/dist/options.d.ts.map +1 -1
  37. package/dist/options.js +33 -1
  38. package/dist/permissions.d.ts.map +1 -1
  39. package/dist/permissions.js +6 -0
  40. package/dist/png.d.ts +38 -0
  41. package/dist/png.d.ts.map +1 -1
  42. package/dist/png.js +167 -0
  43. package/dist/run.d.ts +54 -6
  44. package/dist/run.d.ts.map +1 -1
  45. package/dist/run.js +16 -1
  46. package/package.json +5 -1
  47. package/templates/android/README.md +5 -1
  48. package/templates/android/app/src/debug/java/dev/angularlynx/shell/DevServer.kt +159 -0
  49. package/templates/android/app/src/debug/java/dev/angularlynx/shell/DevServerModules.kt +163 -0
  50. package/templates/android/app/src/debug/res/xml/network_security_config.xml +13 -0
  51. package/templates/android/app/src/main/AndroidManifest.xml +16 -0
  52. package/templates/android/app/src/main/java/dev/angularlynx/shell/AssetsModule.kt +22 -0
  53. package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +24 -1
  54. package/templates/android/app/src/main/java/dev/angularlynx/shell/ResourceFetchers.kt +12 -6
  55. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShareModule.kt +274 -0
  56. package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +57 -0
  57. package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +95 -0
  58. package/templates/android/app/src/main/res/mipmap/ic_launcher_round.xml +6 -0
  59. package/templates/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +6 -0
  60. package/templates/android/app/src/main/res/xml/share_paths.xml +8 -0
  61. package/templates/android/app/src/release/java/dev/angularlynx/shell/DevServer.kt +24 -0
  62. package/templates/ios/App/AngularLynxWebGL.h +7 -0
  63. package/templates/ios/App/AngularLynxWebGL.m +27 -0
  64. package/templates/ios/App/AngularLynxWebGLContext.m +139 -0
  65. package/templates/ios/App/AssetsModule.swift +21 -3
  66. package/templates/ios/App/BundleResourceFetcher.swift +46 -2
  67. package/templates/ios/App/DevServer.swift +190 -0
  68. package/templates/ios/App/DevServerModules.swift +223 -0
  69. package/templates/ios/App/LynxViewController.swift +11 -1
  70. package/templates/ios/App/ShareModule.swift +215 -0
package/README.md CHANGED
@@ -6,10 +6,12 @@ User documentation: [Publishing your App](../website/docs/guide/building-for-pro
6
6
 
7
7
  ## What it does
8
8
 
9
- 1. **Generates** the native project from `templates/ios` or `templates/android` into the project's folder in Angular's build cache (`.angular/cache/<Angular version>/<project>/lynx-native/<platform>`, which `ng new` already gitignores and `ng cache clean` clears), writing the app options from `angular.json` into the few files the templates mark for it. It regenerates only when a hash of its inputs changes (this package's version, the template, the options, the icon), so Xcode and Gradle keep their incremental state.
9
+ 1. **Generates** the native project from `templates/ios` or `templates/android` into the project's folder in Angular's build cache (`.angular/cache/<Angular version>/<project>/lynx-native/<platform>`, which `ng new` already gitignores and `ng cache clean` clears), writing the app options from `angular.json` into the few files the templates mark for it. It regenerates only when a hash of its inputs changes (this package's version, the template, the options, the icon images), so Xcode and Gradle keep their incremental state.
10
10
  2. **Copies** `dist/` (without the web bundle) into the project.
11
11
  3. **Builds** it with `xcodebuild` or Gradle and copies the binaries to `dist/<platform>/`.
12
- 4. **Runs** it, with `--run` (`src/ios/run.ts`, `src/android/run.ts`): picks a simulator, emulator or phone (`--device`, else a running one, else the newest iPhone simulator or the first AVD) and starts it before step 3, so it boots while the app compiles; then installs the app and opens it. iOS uses `simctl` and shows the simulator in DeviceHub (`devices://device/open?id=<UDID>`) or, before Xcode 27.1, the Simulator app. Android uses the SDK's `adb` and `emulator` and opens the launcher activity by component.
12
+ 4. **Runs** it, with `--run` (`src/ios/run.ts`, `src/android/run.ts`): picks a simulator, emulator or phone (`--device`, else a running one, else the newest iPhone simulator or the first AVD) and starts it before step 3, so it boots while the app compiles; then installs the app and opens it. iOS uses `simctl` and shows the simulator in DeviceHub (`devices://device/open?id=<UDID>`) or, before Xcode 27.1, the Simulator app. When `--device` names a paired iPhone (`src/ios/iphone.ts`, found with `devicectl list devices`), step 3 builds a development-signed `-sdk iphoneos` app for it instead (`ios.teamId`, `-allowProvisioningUpdates`), and `devicectl` installs and opens it. Android uses the SDK's `adb` and `emulator` and opens the launcher activity by component.
13
+
14
+ 5. **Develops** in it, for `ng serve --platform ios|android` (`devServer` in `buildNativeApp`): generates the project into `lynx-native/<platform>-dev` without a bundle, builds Xcode's Debug configuration (for the picked simulator alone, into its own derived data) or Android's debug build type (`:app:assembleDebug`, the debug key), and opens it with the dev server's URL: a `-AngularLynxDevServer <url>` launch argument on iOS (`simctl launch`, `devicectl ... process launch`), `--es AngularLynxDevServer http://localhost:<port>/main.lynx.bundle` and `--es AngularLynxDevServerOrigin <the address the bundle was built with>` on Android, after `adb reverse tcp:<port> tcp:<port>`. A stamp next to the app (`src/dev-build.ts`) records the project's input hash and the device; when both match, the next `ng serve --platform` reinstalls the app without running Xcode or Gradle. An ejected project is always built, and one ejected before this existed (no `DevServer.swift` / `DevServer.kt`) fails with a message to eject again.
13
15
 
14
16
  An ejected project (`ios/` or `android/` with a `.angular-lynx-ejected` marker, written by `ng generate @blotch/angular-lynx:eject`) is built as it is and never regenerated.
15
17
 
@@ -19,13 +21,15 @@ Both are one full-screen `LynxView` running `main.lynx.bundle`; Angular Router d
19
21
 
20
22
  Both send the same global props, which the runtime's services read: `platform`, `theme` (again whenever the phone switches between light and dark), `appLocale` (the phone's language as a BCP 47 tag), `appTimeZone` (its time zone's IANA name, which the `intl` build option's `Intl.DateTimeFormat` uses), `isNotchScreen`, `edgeToEdge`, the safe-area insets `safeAreaTop`, `safeAreaBottom`, `safeAreaLeft` and `safeAreaRight` (again whenever they change), `osVersion` (which Lynx leaves out of the main thread's `SystemInfo`), and the accessibility settings `reduceMotion`, `reduceTransparency` (iOS only) and `increaseContrast`, again whenever the user changes one. Android 12 and later also send `dynamicColors`, the wallpaper's Material 3 color roles in light and dark (`DynamicColors.kt`), again when the user changes their wallpaper or colors. Lynx Explorer sends `theme` and `isNotchScreen` too, but no `appLocale`, `appTimeZone`, `osVersion` or accessibility settings. See [`templates/android/README.md`](templates/android/README.md) for the Android shell's details.
21
23
 
22
- Both register the native modules the runtime's services call, which Lynx Explorer doesn't have: `AngularLynxWebAuth` (`WebAuthModule.swift`, `WebAuthModule.kt`) opens `LynxWebAuthSession`'s sign-in page, in `ASWebAuthenticationSession` on iOS and a Custom Tab on Android, and returns the URL it redirects to. `AngularLynxLocalStorage` (`LocalStorageModule.swift`, `LocalStorageModule.kt`) keeps `LynxLocalStorage`'s values in a `UserDefaults` suite and a `SharedPreferences` file of their own. `AngularLynxSecureStorage` (`SecureStorageModule.swift`, `SecureStorageModule.kt`) keeps `LynxSecureStorage`'s in the Keychain on iOS and, on Android, in `SharedPreferences`, each value encrypted with AES-GCM by an Android Keystore key, a file Auto Backup leaves out (`res/xml/backup_rules.xml`, `data_extraction_rules.xml`). `AngularLynxLinking` (`LinkingModule.swift`, `LinkingModule.kt`) opens `LynxLinking`'s links: `openURL` with `UIApplication.open` and an `ACTION_VIEW` intent, `openInApp` in `SFSafariViewController` and a Custom Tab, and `canOpenURL` with `UIApplication.canOpenURL` and `resolveActivity`, which answer only for the schemes the generator writes from angular.json's `canOpenURLSchemes` (with `http`, `https`, `mailto`, `tel` and `sms`) into Info.plist's `LSApplicationQueriesSchemes` and the manifest's `<queries>`. `AngularLynxImagePicker` (`ImagePickerModule.swift`, `ImagePickerModule.kt`) lets the person pick a photo for `LynxImagePicker`, with `PHPickerViewController` on iOS and the Photo Picker on Android, neither of which needs a permission, and calls back with it as base64, re-encoded as an upright JPEG when the app asks for a smaller one or the photo is a format such as HEIC. Android also has `AngularLynxShell`, for the back button.
24
+ Both register the native modules the runtime's services call, which Lynx Explorer doesn't have: `AngularLynxWebAuth` (`WebAuthModule.swift`, `WebAuthModule.kt`) opens `LynxWebAuthSession`'s sign-in page, in `ASWebAuthenticationSession` on iOS and a Custom Tab on Android, and returns the URL it redirects to. `AngularLynxLocalStorage` (`LocalStorageModule.swift`, `LocalStorageModule.kt`) keeps `LynxLocalStorage`'s values in a `UserDefaults` suite and a `SharedPreferences` file of their own. `AngularLynxSecureStorage` (`SecureStorageModule.swift`, `SecureStorageModule.kt`) keeps `LynxSecureStorage`'s in the Keychain on iOS and, on Android, in `SharedPreferences`, each value encrypted with AES-GCM by an Android Keystore key, a file Auto Backup leaves out (`res/xml/backup_rules.xml`, `data_extraction_rules.xml`). `AngularLynxLinking` (`LinkingModule.swift`, `LinkingModule.kt`) opens `LynxLinking`'s links: `openURL` with `UIApplication.open` and an `ACTION_VIEW` intent, `openInApp` in `SFSafariViewController` and a Custom Tab, and `canOpenURL` with `UIApplication.canOpenURL` and `resolveActivity`, which answer only for the schemes the generator writes from angular.json's `canOpenURLSchemes` (with `http`, `https`, `mailto`, `tel` and `sms`) into Info.plist's `LSApplicationQueriesSchemes` and the manifest's `<queries>`. `AngularLynxImagePicker` (`ImagePickerModule.swift`, `ImagePickerModule.kt`) lets the person pick a photo for `LynxImagePicker`, with `PHPickerViewController` on iOS and the Photo Picker on Android, neither of which needs a permission, and calls back with it as base64, re-encoded as an upright JPEG when the app asks for a smaller one or the photo is a format such as HEIC. `AngularLynxShare` (`ShareModule.swift`, `ShareModule.kt`) opens `LynxShare`'s share sheet, `UIActivityViewController` on iOS and an `ACTION_SEND` chooser on Android, with the files written to temporary files on iOS and shared through a `FileProvider` on Android. Save Image on iOS needs `NSPhotoLibraryAddUsageDescription`, which the generator always writes (angular.json's `permissions.savePhotos`, with a default). Android also has `AngularLynxShell`, for the back button.
25
+
26
+ Only the development build (`ng serve --platform`) loads from a dev server: the code is in `App/DevServer.swift` and `App/DevServerModules.swift` under `#if DEBUG`, and in the debug source set on Android (`app/src/debug`, with a no-op `DevServer` in `app/src/release`), so a release build can't be pointed anywhere else. `DevServer` reads the URL from the launch argument or intent extra and keeps it (`UserDefaults`, `SharedPreferences`), so the app opened from the home screen loads from the same server. The loaders (`BundleResourceFetcher.swift`, `ResourceFetchers.kt`) and `AngularLynxAssets` then fetch every relative URL, and on Android every URL on the address the bundle was built with, from the dev server instead of the app, uncached. When the bundle itself doesn't load, `DevServer` covers the page with a message and loads it again every two seconds. rspeedy's live reload client talks to Lynx DevTool, which the shells don't have: `NativeModules.LynxWebSocketModule` (through `@lynx-js/websocket`) for the dev server's socket and `NativeModules.LynxDevToolSetModule.invokeCdp` for a full reload (a DevTool protocol `Page.reload`). The development build registers modules under those names (`DevWebSocketModule`, `DevReloadModule`): a WebSocket with `URLSessionWebSocketTask` and OkHttp that sends the same `websocketOpen`, `websocketMessage`, `websocketClosed` and `websocketFailed` global events as Lynx DevTool's, and a `Page.reload` that loads the bundle again, as DevTool's `LynxPageReloadHelper` does. URLSession sends an empty `Sec-WebSocket-Protocol` header for an empty protocol list, which the dev server refuses, so the iOS socket passes none then. On Android, the debug build's `network_security_config.xml` allows plain HTTP to any host, since the app's own `fetch()` of an imported file goes to the address the bundle was built with; the release build's allows it to `localhost` alone.
23
27
 
24
28
  `AngularLynxClipboard` (`ClipboardModule.swift`, `ClipboardModule.kt`) copies `LynxClipboard`'s text to `UIPasteboard.general` on iOS and `ClipboardManager` on Android, and reads it back.
25
29
 
26
30
  Both link Lynx's XElement library, which holds `<input>`, `<textarea>`, `<overlay>`, `<svg>`, `<blur-view>`, `<viewpager>`, `<refresh>`, the `<scroll-coordinator>` family, `<webview>` and `<video>`. Lynx's core doesn't include these, and a host that doesn't register them renders nothing for those tags (on Android, nothing after them either). XElement's AnimaX and Markdown elements are left out: the runtime doesn't support them. On iOS, `<blur-view>` is XElement's with more of UIKit in it (`App/BlurView.swift`): a `blur-material` attribute for UIKit's adaptive blur materials, which the glass components draw their design before iOS 26 on (Lynx's blur-view has only the styles from before iOS 13); Liquid Glass that materializes, dissolves and eases between effects inside a `glass-container`, where Lynx's sets its effect at once; and a `glass-effect-id` attribute that pairs two glass shapes across a change so one morphs into the other (`App/GlassTransitions.swift`).
27
31
 
28
- Both have `<canvas>` with WebGL2 (issue #211), which Lynx doesn't: a `canvas` element (`App/AngularLynxWebGL.m`'s `AngularLynxCanvas`, a `CAMetalLayer` view; `CanvasUI.kt`, a `TextureView`) and the `AngularLynxWebGL` module the runtime's WebGL2 context sends its calls to, which runs them on OpenGL ES 3.0 (`App/AngularLynxWebGLContext.m`, `WebGLContext.kt`). On iOS that's [ANGLE](https://chromium.googlesource.com/angle/angle)'s OpenGL ES, on Metal, which Safari draws WebGL with too: iOS's own OpenGL ES is deprecated, and the Simulator runs it on the CPU, at seconds a frame for a lit three.js scene (issue #238), where Metal draws on the Mac's GPU. ANGLE's `libEGL` and `libGLESv2` frameworks, and its headers, come in the Lynx frameworks zip (below). Android's OpenGL ES is the phone's, which the emulator already runs on the Mac's GPU. The runtime runs on Lynx's main thread and WebGL needs answers synchronously, so both turn on main-thread modules (`enableMTSModule`): the config's modules are then callable from main-thread JavaScript as `lynx.module(name)`. `AngularLynxAssets` (`App/AssetsModule.swift`, `AssetsModule.kt`) reads a file the app bundles for the main thread's `fetch`, which has no page URL to resolve `/static/...` against. The command numbers the WebGL module reads (`App/AngularLynxWebGLOps.h`, `WebGLOps.kt`) are generated from the runtime's `canvas/webgl-ops.ts` with `npm run generate:webgl-ops -w packages/native`; `scripts/webgl-ops.test.ts` fails when they're stale. UIKit's module imports Apple's OpenGL ES headers into every file, so `AngularLynxWebGLContext.m` turns off their deprecation warnings, which land on ANGLE's functions of the same names; the explicit link to `libGLESv2` comes before UIKit's automatic one to OpenGLES, so those calls bind to ANGLE.
32
+ Both have `<canvas>` with WebGL2 (issue #211), which Lynx doesn't: a `canvas` element (`App/AngularLynxWebGL.m`'s `AngularLynxCanvas`, a `CAMetalLayer` view; `CanvasUI.kt`, a `TextureView`) and the `AngularLynxWebGL` module the runtime's WebGL2 context sends its calls to, which runs them on OpenGL ES 3.0 (`App/AngularLynxWebGLContext.m`, `WebGLContext.kt`). On iOS that's [ANGLE](https://chromium.googlesource.com/angle/angle)'s OpenGL ES, on Metal, which Safari draws WebGL with too: iOS's own OpenGL ES is deprecated, and the Simulator runs it on the CPU, at seconds a frame for a lit three.js scene (issue #238), where Metal draws on the Mac's GPU. ANGLE's `libEGL` and `libGLESv2` frameworks, and its headers, come in the Lynx frameworks zip (below). Android's OpenGL ES is the phone's, which the emulator already runs on the Mac's GPU. The runtime runs on Lynx's main thread and WebGL needs answers synchronously, so both turn on main-thread modules (`enableMTSModule`): the config's modules are then callable from main-thread JavaScript as `lynx.module(name)`. The WebGL module's `encodeImage`, behind `canvas.toBlob()` and `toDataURL()`, reads the drawing buffer and encodes it as a PNG or JPEG with ImageIO or `Bitmap.compress`; on iOS it reads through a pixel pack buffer, since ANGLE on Metal reads straight into memory many times slower. `AngularLynxAssets` (`App/AssetsModule.swift`, `AssetsModule.kt`) reads a file the app bundles for the main thread's `fetch`, which has no page URL to resolve `/static/...` against. The command numbers the WebGL module reads (`App/AngularLynxWebGLOps.h`, `WebGLOps.kt`) are generated from the runtime's `canvas/webgl-ops.ts` with `npm run generate:webgl-ops -w packages/native`; `scripts/webgl-ops.test.ts` fails when they're stale. UIKit's module imports Apple's OpenGL ES headers into every file, so `AngularLynxWebGLContext.m` turns off their deprecation warnings, which land on ANGLE's functions of the same names; the explicit link to `libGLESv2` comes before UIKit's automatic one to OpenGLES, so those calls bind to ANGLE.
29
33
 
30
34
  | | iOS | Android |
31
35
  | ---------------- | ---------------------------------------------------- | -------------------------------------------------------- |
@@ -16,13 +16,18 @@ export declare const resolveAndroidSigning: (app: ResolvedApp, env?: NodeJS.Proc
16
16
  /**
17
17
  * Builds the Android shell into a release `.apk` (for emulators and
18
18
  * sideloading) and `.aab` (for Google Play). Returns the artifacts' paths.
19
+ *
20
+ * With `development`, `ng serve --platform android`'s app instead: the debug
21
+ * build type's `.apk` alone, which compiles the shell's dev server support in
22
+ * (src/debug) and is signed with the debug key.
19
23
  */
20
- export declare const buildAndroid: ({ project, app, outputDir, logFile, log, signing, }: {
24
+ export declare const buildAndroid: ({ project, app, outputDir, logFile, log, signing, development, }: {
21
25
  readonly project: PreparedProject;
22
26
  readonly app: ResolvedApp;
23
27
  readonly outputDir: string;
24
28
  readonly logFile: string;
25
29
  readonly log: (message: string) => void;
26
30
  readonly signing: AndroidSigning | undefined;
31
+ readonly development?: boolean;
27
32
  }) => Promise<string[]>;
28
33
  //# sourceMappingURL=build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src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AAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAChC,KAAK,WAAW,EAChB,MAAK,MAAM,CAAC,UAAwB,KACnC,cAAc,GAAG,SAgCnB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,kEAQhC;IACD,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,CAAC;IAC7C,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC,KAAG,OAAO,CAAC,MAAM,EAAE,CA8DnB,CAAC"}
@@ -40,8 +40,12 @@ export const resolveAndroidSigning = (app, env = process.env) => {
40
40
  /**
41
41
  * Builds the Android shell into a release `.apk` (for emulators and
42
42
  * sideloading) and `.aab` (for Google Play). Returns the artifacts' paths.
43
+ *
44
+ * With `development`, `ng serve --platform android`'s app instead: the debug
45
+ * build type's `.apk` alone, which compiles the shell's dev server support in
46
+ * (src/debug) and is signed with the debug key.
43
47
  */
44
- export const buildAndroid = async ({ project, app, outputDir, logFile, log, signing, }) => {
48
+ export const buildAndroid = async ({ project, app, outputDir, logFile, log, signing, development = false, }) => {
45
49
  // Signing values reach Gradle as project properties through
46
50
  // ORG_GRADLE_PROJECT_* environment variables: never on the command line,
47
51
  // which the process list and our build log would show, and never in a file
@@ -68,7 +72,7 @@ export const buildAndroid = async ({ project, app, outputDir, logFile, log, sign
68
72
  ORG_GRADLE_PROJECT_angularLynxKeyPassword: signing.keyPassword,
69
73
  }),
70
74
  };
71
- if (!signing) {
75
+ if (!signing && !development) {
72
76
  log('Signing the release build with the debug key: set android.signing in angular.json for a Google Play upload.');
73
77
  }
74
78
  log('Building the Android app');
@@ -78,9 +82,16 @@ export const buildAndroid = async ({ project, app, outputDir, logFile, log, sign
78
82
  // gradlew arrives without its executable bit.
79
83
  chmodSync(path.join(project.dir, 'gradlew'), 0o755);
80
84
  }
81
- await run(gradlew, [':app:assembleRelease', ':app:bundleRelease', '--console=plain'], { cwd: project.dir, logFile, env });
85
+ await run(gradlew, development
86
+ ? [':app:assembleDebug', '--console=plain']
87
+ : [':app:assembleRelease', ':app:bundleRelease', '--console=plain'], { cwd: project.dir, logFile, env });
82
88
  mkdirSync(outputDir, { recursive: true });
83
89
  const outputs = path.join(project.dir, 'app/build/outputs');
90
+ if (development) {
91
+ const apk = path.join(outputDir, `${app.artifactName}-dev.apk`);
92
+ cpSync(path.join(outputs, 'apk/debug/app-debug.apk'), apk);
93
+ return [apk];
94
+ }
84
95
  const apk = path.join(outputDir, `${app.artifactName}.apk`);
85
96
  const aab = path.join(outputDir, `${app.artifactName}.aab`);
86
97
  cpSync(path.join(outputs, 'apk/release/app-release.apk'), apk);
@@ -0,0 +1,29 @@
1
+ import { type ResolvedApp } from '../options.ts';
2
+ /** Each density's scale from dp to px, as Android names its folders. */
3
+ export declare const DENSITIES: Readonly<Record<string, number>>;
4
+ /**
5
+ * Writes the app's launcher icon into the project's resources, from the
6
+ * `icon` option (and `android.adaptiveIcon`'s layers):
7
+ *
8
+ * - `mipmap-<density>/ic_launcher.png` and `ic_launcher_round.png`, the flat
9
+ * icons Android 7 shows, square and round;
10
+ * - `mipmap-anydpi-v26/ic_launcher.xml` and `ic_launcher_round.xml`, the
11
+ * adaptive icon Android 8 and later show, with its layers as
12
+ * `mipmap-<density>/ic_launcher_foreground.png` and
13
+ * `ic_launcher_background.png`, or a color in `values/`.
14
+ *
15
+ * Every size is made here rather than left to Android to scale one big PNG:
16
+ * launchers scale bitmaps with a cheap filter, and a 1024 px image shrunk to
17
+ * 48 px that way comes out jagged.
18
+ */
19
+ export declare const writeAndroidIcon: (dir: string, app: ResolvedApp, projectRoot: string) => void;
20
+ /**
21
+ * The adaptive icon both `android:icon` and `android:roundIcon` point at:
22
+ * the launcher masks it to whatever shape it uses, round included.
23
+ */
24
+ export declare const adaptiveIconXml: ({ foreground, background, }: {
25
+ readonly foreground: boolean;
26
+ readonly background: "color" | "image";
27
+ }) => string;
28
+ export declare const backgroundColorResource: (color: string) => string;
29
+ //# sourceMappingURL=icon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icon.d.ts","sourceRoot":"","sources":["../../src/android/icon.ts"],"names":[],"mappings":"AASA,OAAO,EAAyB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAaxE,wEAAwE;AACxE,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMtD,CAAC;AAuBF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,GAC3B,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,aAAa,MAAM,KAClB,IAkFF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,6BAG7B;IACD,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC;CACxC,KAAG,MAeU,CAAC;AAEf,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,MAO1C,CAAC"}
@@ -0,0 +1,142 @@
1
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { ICON_BACKGROUND_COLOR } from "../options.js";
4
+ import { decodePng, encodePng, extendEdges, maskCircle, readPngSize, resize, } from "../png.js";
5
+ const RES = 'app/src/main/res';
6
+ /** Each density's scale from dp to px, as Android names its folders. */
7
+ export const DENSITIES = {
8
+ mdpi: 1,
9
+ hdpi: 1.5,
10
+ xhdpi: 2,
11
+ xxhdpi: 3,
12
+ xxxhdpi: 4,
13
+ };
14
+ /** A flat launcher icon is 48 dp square. */
15
+ const LEGACY_DP = 48;
16
+ /** An adaptive icon layer is 108 dp square... */
17
+ const LAYER_DP = 108;
18
+ /**
19
+ * ...of which the launcher shows the middle 72 dp at most, masked to its
20
+ * shape, and moves the layer by up to 18 dp around it.
21
+ */
22
+ const VISIBLE_DP = 72;
23
+ /**
24
+ * The template's vector placeholder (Angular's red shield), which an app with
25
+ * an icon replaces.
26
+ */
27
+ const PLACEHOLDERS = [
28
+ 'mipmap/ic_launcher.xml',
29
+ 'mipmap/ic_launcher_round.xml',
30
+ 'drawable/ic_launcher_background.xml',
31
+ 'drawable/ic_launcher_foreground.xml',
32
+ ];
33
+ /**
34
+ * Writes the app's launcher icon into the project's resources, from the
35
+ * `icon` option (and `android.adaptiveIcon`'s layers):
36
+ *
37
+ * - `mipmap-<density>/ic_launcher.png` and `ic_launcher_round.png`, the flat
38
+ * icons Android 7 shows, square and round;
39
+ * - `mipmap-anydpi-v26/ic_launcher.xml` and `ic_launcher_round.xml`, the
40
+ * adaptive icon Android 8 and later show, with its layers as
41
+ * `mipmap-<density>/ic_launcher_foreground.png` and
42
+ * `ic_launcher_background.png`, or a color in `values/`.
43
+ *
44
+ * Every size is made here rather than left to Android to scale one big PNG:
45
+ * launchers scale bitmaps with a cheap filter, and a 1024 px image shrunk to
46
+ * 48 px that way comes out jagged.
47
+ */
48
+ export const writeAndroidIcon = (dir, app, projectRoot) => {
49
+ if (!app.icon) {
50
+ return;
51
+ }
52
+ const res = path.join(dir, RES);
53
+ for (const placeholder of PLACEHOLDERS) {
54
+ rmSync(path.join(res, placeholder), { force: true });
55
+ }
56
+ const icon = loadIcon(projectRoot, app.icon, 'icon');
57
+ // resolveAppOptions has checked an adaptiveIcon has both layers.
58
+ const adaptive = app.android.adaptiveIcon;
59
+ const foreground = adaptive?.foreground
60
+ ? loadIcon(projectRoot, adaptive.foreground, 'android.adaptiveIcon.foreground')
61
+ : undefined;
62
+ const backgroundColor = adaptive?.background && ICON_BACKGROUND_COLOR.test(adaptive.background)
63
+ ? adaptive.background
64
+ : undefined;
65
+ const backgroundImage = adaptive?.background && !backgroundColor
66
+ ? loadIcon(projectRoot, adaptive.background, 'android.adaptiveIcon.background')
67
+ : undefined;
68
+ for (const [density, scale] of Object.entries(DENSITIES)) {
69
+ const folder = path.join(res, `mipmap-${density}`);
70
+ mkdirSync(folder, { recursive: true });
71
+ const legacy = resize(icon, LEGACY_DP * scale, LEGACY_DP * scale);
72
+ writeFileSync(path.join(folder, 'ic_launcher.png'), encodePng(legacy));
73
+ writeFileSync(path.join(folder, 'ic_launcher_round.png'), encodePng(maskCircle(legacy)));
74
+ const layer = LAYER_DP * scale;
75
+ if (foreground) {
76
+ writeFileSync(path.join(folder, 'ic_launcher_foreground.png'), encodePng(resize(foreground, layer, layer)));
77
+ }
78
+ if (!adaptive) {
79
+ // The default adaptive icon: the whole icon fills the 72 dp the mask
80
+ // shows, so a square icon designed for iOS loses only its corners (as
81
+ // it does there), and its edges continue into the margin the layer
82
+ // moves in. Scaling it to the full 108 dp would crop a third of it.
83
+ const visible = VISIBLE_DP * scale;
84
+ writeFileSync(path.join(folder, 'ic_launcher_background.png'), encodePng(extendEdges(resize(icon, visible, visible), (layer - visible) / 2)));
85
+ }
86
+ else if (backgroundImage) {
87
+ writeFileSync(path.join(folder, 'ic_launcher_background.png'), encodePng(resize(backgroundImage, layer, layer)));
88
+ }
89
+ }
90
+ if (backgroundColor) {
91
+ writeFileSync(path.join(res, 'values/ic_launcher_background.xml'), backgroundColorResource(backgroundColor));
92
+ }
93
+ const xml = adaptiveIconXml({
94
+ foreground: !!foreground,
95
+ background: backgroundColor ? 'color' : 'image',
96
+ });
97
+ mkdirSync(path.join(res, 'mipmap-anydpi-v26'), { recursive: true });
98
+ writeFileSync(path.join(res, 'mipmap-anydpi-v26/ic_launcher.xml'), xml);
99
+ writeFileSync(path.join(res, 'mipmap-anydpi-v26/ic_launcher_round.xml'), xml);
100
+ };
101
+ /**
102
+ * The adaptive icon both `android:icon` and `android:roundIcon` point at:
103
+ * the launcher masks it to whatever shape it uses, round included.
104
+ */
105
+ export const adaptiveIconXml = ({ foreground, background, }) => [
106
+ '<?xml version="1.0" encoding="utf-8"?>',
107
+ "<!-- Written by @blotch/angular-lynx-native from angular.json's icon options. -->",
108
+ '<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">',
109
+ background === 'color'
110
+ ? ' <background android:drawable="@color/ic_launcher_background" />'
111
+ : ' <background android:drawable="@mipmap/ic_launcher_background" />',
112
+ // A layer can't be left out, so the default icon, all background, has
113
+ // a transparent foreground.
114
+ foreground
115
+ ? ' <foreground android:drawable="@mipmap/ic_launcher_foreground" />'
116
+ : ' <foreground android:drawable="@android:color/transparent" />',
117
+ '</adaptive-icon>',
118
+ '',
119
+ ].join('\n');
120
+ export const backgroundColorResource = (color) => [
121
+ '<?xml version="1.0" encoding="utf-8"?>',
122
+ '<resources>',
123
+ ` <color name="ic_launcher_background">${color}</color>`,
124
+ '</resources>',
125
+ '',
126
+ ].join('\n');
127
+ /**
128
+ * Reads one of the icon options' PNGs, checking it's the 1024×1024 the
129
+ * docs ask for, so a wrong file fails here with the option's name rather
130
+ * than as a blurry or misplaced icon.
131
+ */
132
+ const loadIcon = (projectRoot, file, option) => {
133
+ const absolute = path.resolve(projectRoot, file);
134
+ if (!existsSync(absolute)) {
135
+ throw new Error(`${option}: ${file} doesn't exist.`);
136
+ }
137
+ const size = readPngSize(absolute);
138
+ if (size.width !== 1024 || size.height !== 1024) {
139
+ throw new Error(`${file} is ${size.width}×${size.height}. ${option} must be a 1024×1024 PNG.`);
140
+ }
141
+ return decodePng(readFileSync(absolute));
142
+ };
@@ -4,7 +4,8 @@ import type { ResolvedApp } from '../options.ts';
4
4
  * Writes the app options into the Android template: identity goes in
5
5
  * angular-lynx.properties (which app/build.gradle.kts reads), and permissions,
6
6
  * deep links and the apps canOpenURL can see go between the manifest's
7
- * `angular-lynx:*` markers.
7
+ * `angular-lynx:*` markers, and the icon options become the launcher icon's
8
+ * resources.
8
9
  */
9
10
  export declare const androidGenerator: PlatformGenerator;
10
11
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/android/project.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,eAAe,CAAC;AAY9D;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,iBAe9B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,WAOtC,CAAC;AAEN,eAAO,MAAM,UAAU,GAAI,KAAK,WAAW,KAAG,MAYhC,CAAC;AAEf,eAAO,MAAM,iBAAiB,GAAI,KAAK,WAAW,KAAG,MAiBpD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,KAAK,WAAW,KAAG,MAYjC,CAAC;AAEnB;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,WAAW,KAAG,MAUpC,CAAC;AAEf,2EAA2E;AAC3E,eAAO,MAAM,cAAc,GACzB,MAAK,MAAM,CAAC,UAAwB,KACnC,MAAM,GAAG,SAaX,CAAC"}
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/android/project.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,eAAe,CAAC;AAa9D;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,EAAE,iBAiB9B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,WAOtC,CAAC;AAEN,eAAO,MAAM,UAAU,GAAI,KAAK,WAAW,KAAG,MAYhC,CAAC;AAEf,eAAO,MAAM,iBAAiB,GAAI,KAAK,WAAW,KAAG,MAiBpD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,KAAK,WAAW,KAAG,MAYjC,CAAC;AAEnB;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,WAAW,KAAG,MAUpC,CAAC;AAEf,2EAA2E;AAC3E,eAAO,MAAM,cAAc,GACzB,MAAK,MAAM,CAAC,UAAwB,KACnC,MAAM,GAAG,SAaX,CAAC"}
@@ -2,6 +2,7 @@ import { chmodSync, existsSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  import { PERMISSION_MAP } from "../permissions.js";
5
+ import { writeAndroidIcon } from "./icon.js";
5
6
  import { escapeXml, replaceMarker } from "../xml.js";
6
7
  const MANIFEST = 'app/src/main/AndroidManifest.xml';
7
8
  const SCREEN_ORIENTATIONS = {
@@ -13,10 +14,11 @@ const SCREEN_ORIENTATIONS = {
13
14
  * Writes the app options into the Android template: identity goes in
14
15
  * angular-lynx.properties (which app/build.gradle.kts reads), and permissions,
15
16
  * deep links and the apps canOpenURL can see go between the manifest's
16
- * `angular-lynx:*` markers.
17
+ * `angular-lynx:*` markers, and the icon options become the launcher icon's
18
+ * resources.
17
19
  */
18
20
  export const androidGenerator = {
19
- configure: (dir, app) => {
21
+ configure: (dir, app, projectRoot) => {
20
22
  // npm keeps file modes when it packs, but a copy through another tool
21
23
  // (or a Windows checkout) may not, and Gradle can't start without it.
22
24
  chmodSync(path.join(dir, 'gradlew'), 0o755);
@@ -27,6 +29,7 @@ export const androidGenerator = {
27
29
  manifest = replaceMarker(manifest, 'deep-links', deepLinkEntries(app));
28
30
  manifest = replaceMarker(manifest, 'queries', queriesEntries(app));
29
31
  writeFileSync(manifestPath, manifest);
32
+ writeAndroidIcon(dir, app, projectRoot);
30
33
  },
31
34
  bundleDir: (dir) => path.join(dir, 'app/src/main/assets'),
32
35
  };
@@ -1,4 +1,4 @@
1
- import type { RunTarget } from '../run.ts';
1
+ import { type DevServerOptions, type RunTarget } from '../run.ts';
2
2
  /**
3
3
  * The activity the shell template declares: its manifest names `.MainActivity`
4
4
  * in the `dev.angularlynx.shell` namespace, whatever the app's ID is.
@@ -57,5 +57,14 @@ export declare const startAndroidDevice: ({ device, logFile, log, env, timing, }
57
57
  readonly env?: NodeJS.ProcessEnv;
58
58
  readonly timing?: typeof TIMING;
59
59
  }) => Promise<RunTarget>;
60
+ /**
61
+ * The intent extras that point the development app at the dev server
62
+ * (DevServer.kt reads them): the bundle at localhost, which `adb reverse`
63
+ * forwards to this machine, and the address the bundle was built with, so the
64
+ * app sends what the bundle asks of that address (lazy bundles, images, the
65
+ * live reload socket) to localhost too. Quoted, because adb runs `am` in the
66
+ * device's shell.
67
+ */
68
+ export declare const androidDevServerExtras: (devServer: DevServerOptions | undefined) => string[];
60
69
  export {};
61
70
  //# sourceMappingURL=run.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/android/run.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;;GAGG;AACH,eAAO,MAAM,cAAc,uCAAuC,CAAC;AAEnE,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gFAAgF;IAChF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,SAAS,EAQtD,CAAC;AAIL,mFAAmF;AACnF,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;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AW,gBAAgB,GAAG,SAAS,KACtC,MAAM,EAaR,CAAC"}
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
2
2
  import { closeSync, existsSync, openSync } from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { NativeBuildError, capture, run } from "../process.js";
5
+ import { DEV_SERVER_ARGUMENT, DEV_SERVER_ORIGIN_ARGUMENT, } from "../run.js";
5
6
  import { findAndroidSdk } from "./project.js";
6
7
  /**
7
8
  * The activity the shell template declares: its manifest names `.MainActivity`
@@ -139,7 +140,7 @@ export const startAndroidDevice = async ({ device, logFile, log, env = process.e
139
140
  }
140
141
  const emulatorLog = emulatorLogFile(logFile);
141
142
  return {
142
- launch: async (binary, app) => {
143
+ launch: async (binary, app, devServer) => {
143
144
  const serials = new Set(before.map((candidate) => candidate.serial));
144
145
  let serial = 'serial' in choice ? choice.serial : undefined;
145
146
  // An emulator shows up in `adb devices` a few seconds after it starts,
@@ -193,6 +194,18 @@ export const startAndroidDevice = async ({ device, logFile, log, env = process.e
193
194
  app.id,
194
195
  ]);
195
196
  const component = resolved?.trim().split('\n').at(-1)?.trim();
197
+ if (devServer) {
198
+ // Lets the app reach the dev server at localhost, whatever network
199
+ // the device is on: adb forwards the device's port to this
200
+ // machine's, over USB or wireless debugging, and an emulator's too.
201
+ await adb([
202
+ '-s',
203
+ serial,
204
+ 'reverse',
205
+ `tcp:${devServerPort(devServer)}`,
206
+ `tcp:${devServerPort(devServer)}`,
207
+ ]);
208
+ }
196
209
  // -S stops the copy a previous `--run` left open first, as iOS's
197
210
  // --terminate-running-process does.
198
211
  const output = await adb([
@@ -205,6 +218,7 @@ export const startAndroidDevice = async ({ device, logFile, log, env = process.e
205
218
  '-W',
206
219
  '-n',
207
220
  component?.includes('/') ? component : `${app.id}/${SHELL_ACTIVITY}`,
221
+ ...androidDevServerExtras(devServer),
208
222
  ]);
209
223
  // `am start` exits with 0 even when it fails, and says why on stdout,
210
224
  // last: `Error type 3`, then `Error: Activity class ... does not exist.`
@@ -219,6 +233,37 @@ export const startAndroidDevice = async ({ device, logFile, log, env = process.e
219
233
  },
220
234
  };
221
235
  };
236
+ /**
237
+ * The dev server's port, which `adb reverse` forwards.
238
+ */
239
+ const devServerPort = (devServer) => {
240
+ const url = new URL(devServer.bundleUrl);
241
+ return url.port || (url.protocol === 'https:' ? '443' : '80');
242
+ };
243
+ /**
244
+ * The intent extras that point the development app at the dev server
245
+ * (DevServer.kt reads them): the bundle at localhost, which `adb reverse`
246
+ * forwards to this machine, and the address the bundle was built with, so the
247
+ * app sends what the bundle asks of that address (lazy bundles, images, the
248
+ * live reload socket) to localhost too. Quoted, because adb runs `am` in the
249
+ * device's shell.
250
+ */
251
+ export const androidDevServerExtras = (devServer) => {
252
+ if (!devServer)
253
+ return [];
254
+ const built = new URL(devServer.bundleUrl);
255
+ const local = new URL(devServer.bundleUrl);
256
+ local.hostname = 'localhost';
257
+ return [
258
+ '--es',
259
+ DEV_SERVER_ARGUMENT,
260
+ shellQuote(local.href),
261
+ '--es',
262
+ DEV_SERVER_ORIGIN_ARGUMENT,
263
+ shellQuote(built.origin),
264
+ ];
265
+ };
266
+ const shellQuote = (value) => `'${value.replace(/'/g, `'\\''`)}'`;
222
267
  const capitalize = (text) => text[0].toUpperCase() + text.slice(1);
223
268
  const emulatorLogFile = (logFile) => path.join(path.dirname(logFile), 'emulator.log');
224
269
  /**
@@ -0,0 +1,16 @@
1
+ /**
2
+ * What the development app depends on: the generated project's input hash,
3
+ * and the device it was built for (an iPhone build is signed for that
4
+ * phone; a simulator build is compiled for that simulator's architecture).
5
+ */
6
+ export declare const devBuildKey: (projectHash: string, destination: string) => string;
7
+ /**
8
+ * The artifacts the last development build in `outputDir` left, when it was
9
+ * built for `key` and they're all still there; undefined to build again.
10
+ */
11
+ export declare const reusableDevBuild: (outputDir: string, key: string) => string[] | undefined;
12
+ /**
13
+ * Records a development build, for {@link reusableDevBuild}.
14
+ */
15
+ export declare const recordDevBuild: (outputDir: string, key: string, artifacts: readonly string[]) => void;
16
+ //# sourceMappingURL=dev-build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-build.d.ts","sourceRoot":"","sources":["../src/dev-build.ts"],"names":[],"mappings":"AAaA;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,aAAa,MAAM,EAAE,aAAa,MAAM,WAChC,CAAC;AAErC;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAC3B,WAAW,MAAM,EACjB,KAAK,MAAM,KACV,MAAM,EAAE,GAAG,SAab,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GACzB,WAAW,MAAM,EACjB,KAAK,MAAM,EACX,WAAW,SAAS,MAAM,EAAE,KAC3B,IAOA,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ /**
4
+ * Written next to `ng serve --platform`'s development app once it's built:
5
+ * the hash of the generated project it was built from and where it was built
6
+ * for, then the artifacts. A second `ng serve --platform` with the same
7
+ * native inputs then reinstalls the app without running Xcode or Gradle,
8
+ * which take a minute or more even with nothing to compile. The app loads
9
+ * its bundle from the dev server, so nothing else goes into it.
10
+ */
11
+ const STAMP = '.angular-lynx-build';
12
+ /**
13
+ * What the development app depends on: the generated project's input hash,
14
+ * and the device it was built for (an iPhone build is signed for that
15
+ * phone; a simulator build is compiled for that simulator's architecture).
16
+ */
17
+ export const devBuildKey = (projectHash, destination) => `${projectHash}\n${destination}\n`;
18
+ /**
19
+ * The artifacts the last development build in `outputDir` left, when it was
20
+ * built for `key` and they're all still there; undefined to build again.
21
+ */
22
+ export const reusableDevBuild = (outputDir, key) => {
23
+ const stamp = path.join(outputDir, STAMP);
24
+ if (!existsSync(stamp))
25
+ return undefined;
26
+ const contents = readFileSync(stamp, 'utf8');
27
+ if (!contents.startsWith(key))
28
+ return undefined;
29
+ const artifacts = contents
30
+ .slice(key.length)
31
+ .split('\n')
32
+ .filter(Boolean)
33
+ .map((artifact) => path.join(outputDir, artifact));
34
+ return artifacts.length > 0 && artifacts.every((file) => existsSync(file))
35
+ ? artifacts
36
+ : undefined;
37
+ };
38
+ /**
39
+ * Records a development build, for {@link reusableDevBuild}.
40
+ */
41
+ export const recordDevBuild = (outputDir, key, artifacts) => writeFileSync(path.join(outputDir, STAMP), key +
42
+ artifacts
43
+ .map((artifact) => path.relative(outputDir, artifact))
44
+ .join('\n'));
@@ -1,4 +1,4 @@
1
- import type { ResolvedApp } from './options.ts';
1
+ import { type ResolvedApp } from './options.ts';
2
2
  export type Platform = 'ios' | 'android';
3
3
  /** The shell templates shipped in this package. */
4
4
  export declare const TEMPLATES_DIR: string;
@@ -10,8 +10,11 @@ export declare const TEMPLATES_DIR: string;
10
10
  */
11
11
  export declare const EJECT_MARKER = ".angular-lynx-ejected";
12
12
  export type PlatformGenerator = {
13
- /** Writes the config into a fresh copy of the template. */
14
- readonly configure: (dir: string, app: ResolvedApp, projectRoot: string) => void;
13
+ /**
14
+ * Writes the config into a fresh copy of the template. `development` is
15
+ * true for `ng serve --platform`'s development app.
16
+ */
17
+ readonly configure: (dir: string, app: ResolvedApp, projectRoot: string, development?: boolean) => void;
15
18
  /** Where the Lynx bundle and its assets go inside the native project. */
16
19
  readonly bundleDir: (dir: string) => string;
17
20
  };
@@ -22,26 +25,42 @@ export type PreparedProject = {
22
25
  readonly ejected: boolean;
23
26
  /** False when the cached project matched the inputs and was reused. */
24
27
  readonly regenerated: boolean;
28
+ /**
29
+ * The hash of the generated project's inputs, or undefined for an ejected
30
+ * project, whose inputs are the user's own files.
31
+ */
32
+ readonly hash?: string;
25
33
  };
26
34
  /**
27
35
  * Makes the native project for a platform ready to build: the generated one in
28
36
  * `<workDir>/<platform>`, or the user's ejected folder.
29
37
  *
30
38
  * Generation is skipped when a hash of every input (this package's version,
31
- * the template files, the app options and the icon) matches the last run, so
39
+ * the template files, the app options and the icon images) matches the last run, so
32
40
  * Xcode and Gradle keep their incremental state between builds. The bundle is
33
41
  * copied in on every build, because it changes on every build.
42
+ *
43
+ * `ng serve --platform`'s development app is generated in a folder of its
44
+ * own, `<workDir>/<platform>-dev`, so it and `ng build --platform`'s app each
45
+ * keep their incremental build state, and one never regenerates or overwrites
46
+ * the other. It gets no bundle (`bundleDir` undefined): it loads the bundle
47
+ * from the dev server.
34
48
  */
35
- export declare const prepareProject: ({ platform, generator, projectRoot, workDir, app, bundleDir, packageVersion, }: {
49
+ export declare const prepareProject: ({ platform, generator, projectRoot, workDir, app, bundleDir, packageVersion, development, }: {
36
50
  readonly platform: Platform;
37
51
  readonly generator: PlatformGenerator;
38
52
  readonly projectRoot: string;
39
53
  /** Where generated projects go (see `BuildNativeAppOptions.workDir`). */
40
54
  readonly workDir: string;
41
55
  readonly app: ResolvedApp;
42
- /** The rspeedy output folder (dist/). */
43
- readonly bundleDir: string;
56
+ /**
57
+ * The rspeedy output folder (dist/), or undefined for the development app,
58
+ * which takes no bundle.
59
+ */
60
+ readonly bundleDir: string | undefined;
44
61
  readonly packageVersion: string;
62
+ /** The development app `ng serve --platform` runs. */
63
+ readonly development?: boolean;
45
64
  }) => PreparedProject;
46
65
  /**
47
66
  * Up to 22.2.2, native builds worked in `.angular-lynx/` at the project root.
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAC;AAEzC,mDAAmD;AACnD,eAAO,MAAM,aAAa,QAEzB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,0BAA0B,CAAC;AAIpD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,CAClB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,WAAW,EAChB,WAAW,EAAE,MAAM,KAChB,IAAI,CAAC;IACV,yEAAyE;IACz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