@nativue/core 0.13.0 → 0.14.1

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 (57) hide show
  1. package/AGENTS.md +39 -7
  2. package/README.md +1 -0
  3. package/android/build.gradle.kts +4 -0
  4. package/android/nativue.settings.gradle.kts +2 -0
  5. package/android/src/main/java/dev/nativue/Bridge.kt +66 -7
  6. package/android/src/main/java/dev/nativue/NativueActivity.kt +12 -5
  7. package/android/src/main/java/dev/nativue/Permissions.kt +107 -0
  8. package/android/src/main/java/dev/nativue/Plugins.kt +98 -15
  9. package/cli/android-project.mjs +377 -0
  10. package/cli/app-config.mjs +526 -0
  11. package/cli/config.d.mts +162 -3
  12. package/cli/ios-project.mjs +652 -0
  13. package/cli/link.mjs +66 -71
  14. package/cli/nativue.mjs +39 -5
  15. package/cli/plugins.mjs +236 -0
  16. package/cli/prebuild.mjs +458 -0
  17. package/cli/run.mjs +2 -2
  18. package/cli/serialize.mjs +168 -0
  19. package/ios/AppLifecycle.swift +165 -0
  20. package/ios/Bridge.swift +53 -4
  21. package/ios/NativueView.swift +5 -1
  22. package/ios/Permissions.swift +19 -0
  23. package/ios/Plugins.swift +24 -0
  24. package/package.json +3 -2
  25. package/src/globals.ts +7 -1
  26. package/src/native-events.ts +99 -0
  27. package/src/native-functions.ts +16 -2
  28. package/src/permissions.ts +57 -0
  29. package/src/renderer.ts +5 -1
  30. package/src/router.ts +2 -1
  31. package/src/types.ts +3 -0
  32. package/template/android/app/src/debug/AndroidManifest.xml +4 -0
  33. package/template/android/app/src/main/java/MainActivity.kt +5 -0
  34. package/template/android/app/src/main/res/drawable-night-xxxhdpi/splash_logo.png +0 -0
  35. package/template/android/app/src/main/res/drawable-xxxhdpi/splash_logo.png +0 -0
  36. package/template/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +6 -0
  37. package/template/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  38. package/template/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png +0 -0
  39. package/template/android/app/src/main/res/values/colors.xml +4 -0
  40. package/template/android/app/src/main/res/values/styles.xml +15 -0
  41. package/template/android/app/src/main/res/values-night/styles.xml +5 -0
  42. package/template/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  43. package/template/android/gradle/wrapper/gradle-wrapper.properties +9 -0
  44. package/template/android/gradlew +248 -0
  45. package/template/android/gradlew.bat +112 -0
  46. package/template/ios/App/App.swift +18 -0
  47. package/template/ios/App/Assets.xcassets/AppIcon.appiconset/Contents.json +1 -0
  48. package/template/ios/App/Assets.xcassets/AppIcon.appiconset/icon.png +0 -0
  49. package/template/ios/App/Assets.xcassets/Contents.json +1 -0
  50. package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/Contents.json +11 -0
  51. package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo-dark@1x.png +0 -0
  52. package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo-dark@2x.png +0 -0
  53. package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo-dark@3x.png +0 -0
  54. package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo@1x.png +0 -0
  55. package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo@2x.png +0 -0
  56. package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo@3x.png +0 -0
  57. package/template/ios/App.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +15 -0
package/cli/config.d.mts CHANGED
@@ -1,19 +1,178 @@
1
1
  import type { Plugin as VitePlugin } from 'vite'
2
2
 
3
+ /** A value of Info.plist or the entitlements. */
4
+ export type PlistValue = string | number | boolean | PlistValue[] | { [key: string]: PlistValue }
5
+
6
+ export type PlistDictionary = { [key: string]: PlistValue }
7
+
8
+ /** An XML element: attribute names keep their prefix, 'android:name' or 'tools:node'. */
9
+ export interface XmlElement {
10
+ tag: string
11
+ attributes: Record<string, string>
12
+ children: XmlElement[]
13
+ text?: string
14
+ }
15
+
16
+ /** A file copied into the app: a sound, a font, an XML file a manifest entry points at. */
17
+ export interface Resource {
18
+ /** Relative to the app, or absolute: a package passes `fileURLToPath(new URL('./chime.wav', import.meta.url))`. */
19
+ source: string
20
+ /** iOS: at the bundle's root, named destination (defaults to the file's name). false: not on iOS. */
21
+ ios?: false | { destination?: string }
22
+ /**
23
+ * Android: res/<type>/<name>.<extension>, or assets/<name>. type defaults to 'raw' ('font' for a
24
+ * font); name to the file's, without its extension: lowercase letters, digits and underscores.
25
+ */
26
+ android?: false | { type?: 'raw' | 'font' | 'drawable' | 'xml' | 'assets'; name?: string }
27
+ /** A font: listed in UIAppFonts on iOS, in res/font on Android. */
28
+ font?: boolean
29
+ }
30
+
31
+ /** The app's Gradle setup: the plugins' gradle mods, then android.gradle. */
32
+ export interface AndroidGradle {
33
+ /** Applied to the app; a version is set in the root build file. */
34
+ plugins: { id: string; version?: string }[]
35
+ /** The app's implementation dependencies, e.g. 'com.squareup.okhttp3:okhttp:4.12.0'. */
36
+ dependencies: string[]
37
+ manifestPlaceholders: Record<string, string>
38
+ /** Maven repositories, e.g. 'https://jitpack.io'. */
39
+ repositories: string[]
40
+ /** gradle.properties */
41
+ properties: Record<string, string>
42
+ }
43
+
44
+ /**
45
+ * An iOS app extension the app embeds, built from a folder of Swift files. It doesn't link nativue:
46
+ * it's plain Swift.
47
+ */
48
+ export interface IosTarget {
49
+ /** The target's name, and its Swift module: letters, digits and underscores. */
50
+ name: string
51
+ type: 'notification-service' | 'notification-content' | 'widget' | 'share'
52
+ /** The folder of its Swift files: a package passes an absolute path. */
53
+ sources: string
54
+ /** Added to the app's bundle identifier, e.g. '.NotificationService'. */
55
+ bundleIdSuffix: string
56
+ /** Defaults to the app's, 15.1. */
57
+ deploymentTarget?: string
58
+ /** Merged over { NSExtension: { NSExtensionPointIdentifier } } for its type. */
59
+ infoPlist?: PlistDictionary
60
+ entitlements?: PlistDictionary
61
+ /** true: shares the app's ios.appGroups. */
62
+ appGroups?: boolean
63
+ buildSettings?: Record<string, string>
64
+ }
65
+
66
+ export interface PrebuildContext {
67
+ /** nativue.config.ts, with its defaults. */
68
+ config: NativueConfig
69
+ /** The app's folder. */
70
+ projectRoot: string
71
+ platform: 'ios' | 'android'
72
+ }
73
+
3
74
  /**
4
- * A plugin of nativue.config.ts, e.g. @nativue/tailwind: build-time work through Vite plugins, and a
5
- * module the app imports before it runs.
75
+ * A plugin of nativue.config.ts, e.g. @nativue/tailwind: build-time work through Vite plugins, a
76
+ * module the app imports before it runs, and mods of the native files prebuild generates. A package
77
+ * declares its own in package.json, `"nativue": { "plugin": "./plugin.mjs" }`, whose default export
78
+ * is `(options?) => NativuePlugin`: it's applied without options unless nativue.config.ts lists it.
6
79
  */
7
80
  export interface NativuePlugin {
81
+ /** A package's own plugin: the package's name. */
8
82
  name: string
9
83
  /** Added to the bundler's (Vite's) plugins. */
10
84
  vite?: VitePlugin | VitePlugin[]
11
85
  /** Imported before the app runs, resolved from the app: a package path or a virtual module. */
12
86
  runtime?: string
87
+ /** Copied into the app, like the config's resources, before them. */
88
+ resources?: Resource[]
89
+ /** Change the documents in place; the app's own config fields are applied after them. */
90
+ ios?: {
91
+ infoPlist?: (infoPlist: PlistDictionary, context: PrebuildContext) => void
92
+ entitlements?: (entitlements: PlistDictionary, context: PrebuildContext) => void
93
+ /** Extension targets the app embeds: push yours. */
94
+ targets?: (targets: IosTarget[], context: PrebuildContext) => void
95
+ }
96
+ android?: {
97
+ /** The app's AndroidManifest.xml: a package's own entries belong in its library manifest. */
98
+ manifest?: (manifest: XmlElement, context: PrebuildContext) => void
99
+ /** res/values/strings.xml, by name. */
100
+ strings?: (strings: Record<string, string>, context: PrebuildContext) => void
101
+ /** The app's Gradle files. A package's own dependencies belong in its build.gradle.kts. */
102
+ gradle?: (gradle: AndroidGradle, context: PrebuildContext) => void
103
+ }
13
104
  }
14
105
 
15
- export interface NativueConfig {
106
+ /** nativue.config.ts: the app, which `nativue prebuild` generates ios/ and android/ from. */
107
+ export interface GeneratedProjectsConfig {
108
+ prebuild?: true
109
+ /** Shown under the app's icon. */
110
+ name: string
111
+ /** Deep links open the app: `myapp://...`. Several, e.g. to keep an old one working. */
112
+ scheme: string | string[]
113
+ /** Shown to people, three numbers: '1.2.0'. Defaults to '1.0.0'. */
114
+ version?: string
115
+ /** Raised for every release the stores get: CFBundleVersion and versionCode. Defaults to 1. */
116
+ buildNumber?: number
117
+ /** A 1024×1024 PNG, relative to the app. */
118
+ icon?: string
119
+ /** The launch screen: a logo on a color. */
120
+ splash?: {
121
+ /** A 360×360 PNG, shown 120 points wide. */
122
+ image?: string
123
+ /** In dark mode; defaults to image. */
124
+ darkImage?: string
125
+ /** e.g. '#F1F5F9'; defaults to white. */
126
+ backgroundColor?: string
127
+ /** Defaults to backgroundColor. */
128
+ darkBackgroundColor?: string
129
+ }
130
+ /** Files copied into the app, e.g. [{ source: './assets/chime.wav' }]. */
131
+ resources?: Resource[]
132
+ ios: {
133
+ /** e.g. com.company.myapp */
134
+ bundleIdentifier: string
135
+ /** Signs the app for phones: the team id under Signing & Capabilities in Xcode. */
136
+ appleTeamId?: string
137
+ /** Keys added to Info.plist, e.g. { NSCameraUsageDescription: 'Scans receipts' }. */
138
+ infoPlist?: Record<string, PlistValue>
139
+ /** e.g. { 'aps-environment': 'development' } */
140
+ entitlements?: Record<string, PlistValue>
141
+ /** The app's App Groups, shared with extension targets that ask for them, e.g. ['group.com.company.myapp']. */
142
+ appGroups?: string[]
143
+ }
144
+ android: {
145
+ /** The applicationId and the Kotlin package, e.g. com.company.myapp: no hyphens. */
146
+ package: string
147
+ /** e.g. ['android.permission.CAMERA'] */
148
+ permissions?: string[]
149
+ /** Removed even when a package's manifest asks for them, e.g. ['android.permission.READ_MEDIA_IMAGES'] */
150
+ blockedPermissions?: string[]
151
+ /** e.g. { dependencies: ['com.squareup.okhttp3:okhttp:4.12.0'] } */
152
+ gradle?: Partial<AndroidGradle>
153
+ /** Android 8+'s icon: a square PNG whose logo fits in the middle 61%, on a color. */
154
+ adaptiveIcon?: { foregroundImage: string; backgroundColor?: string }
155
+ /**
156
+ * Signs release builds. The passwords are read when Gradle builds, from a Gradle property
157
+ * (~/.gradle/gradle.properties) or an environment variable of these names.
158
+ */
159
+ signing?: {
160
+ /** Outside android/, e.g. './credentials/upload.keystore' */
161
+ storeFile: string
162
+ keyAlias: string
163
+ storePasswordEnv: string
164
+ keyPasswordEnv: string
165
+ }
166
+ }
16
167
  plugins?: NativuePlugin[]
17
168
  }
18
169
 
170
+ /** An app that keeps ios/ and android/ by hand: nativue only links its packages' native code. */
171
+ export interface ManualProjectsConfig {
172
+ prebuild: false
173
+ plugins?: NativuePlugin[]
174
+ }
175
+
176
+ export type NativueConfig = GeneratedProjectsConfig | ManualProjectsConfig
177
+
19
178
  export function defineConfig(config: NativueConfig): NativueConfig