@joptimus/allspark
v1.0.1
Published
Programmatic API for modifying iOS and Android mobile project configuration files
Maintainers
Readme
@joptimus/allspark
Programmatic API for modifying iOS and Android mobile project configuration files. Fork of @trapezedev/project.
Installation
npm install @joptimus/allsparkQuick Start
import { MobileProject } from '@joptimus/allspark';
const project = new MobileProject('/path/to/your/app', {
ios: { path: 'ios' },
android: { path: 'android' },
});
await project.load();
// iOS: set bundle ID
project.ios?.setBundleId(null, null, 'com.example.myapp');
// Android: set version code
project.android?.setVersionCode(42);
// Write all changes to disk
await project.commit();MobileProject
new MobileProject(projectRoot: string, config?: MobileProjectConfig)Config shape:
{
ios?: { path: string }, // relative path to iOS project dir
android?: { path: string }, // relative path to Android project dir
enableIos?: boolean, // default: true
enableAndroid?: boolean, // default: true
}| Method | Description |
|--------|-------------|
| load() | Detect framework and load iOS/Android sub-projects |
| commit() | Write all pending changes to disk |
| copyFile(src, dest) | Copy a file into the project root |
| detectFramework() | Returns detected framework (Capacitor, Cordova, Flutter, React Native, .NET MAUI, NativeScript, Native iOS, Native Android) |
IosProject (project.ios)
| Method | Signature | Description |
|--------|-----------|-------------|
| getTargets | () => IosTarget[] \| null | All targets in the Xcode project |
| getTarget | (name: string) => IosTarget \| null | Target by name |
| getAppTarget | () => IosTarget \| null | Main app target |
| getAppTargetName | () => string \| null | Name of the main app target |
| getBundleId | (target, build?) => string \| null | Get PRODUCT_BUNDLE_IDENTIFIER |
| setBundleId | (target, build, bundleId) | Set PRODUCT_BUNDLE_IDENTIFIER |
| getBuildConfigurations | (target) => IosTargetBuildConfiguration[] | All build configs for a target |
| getBuildConfigurationNames | (target) => string[] | Config names (Debug, Release, etc.) |
| getProductName | (target?) => string \| null | Get PRODUCT_NAME |
| setProductName | (target, name) | Set PRODUCT_NAME |
| getBuild | (target, build?) => Promise<any> | Get CURRENT_PROJECT_VERSION |
| setBuild | (target, build, number) | Set CURRENT_PROJECT_VERSION |
| incrementBuild | (target?, build?) | Increment build number |
| getVersion | (target, build) => string | Get MARKETING_VERSION |
| setVersion | (target, build, version) | Set MARKETING_VERSION |
| getBuildProperty | (target, build, key) => string \| null | Get any Xcode build property |
| setBuildProperty | (target, build, key, value) | Set any Xcode build property |
| addFramework | (target, framework, opts?) | Add a framework to a target |
| getFrameworks | (target) => IosFramework[] | Frameworks for a target |
| getEntitlementsFile | (target, build?) => string \| null | Path to entitlements file |
| getEntitlements | (target, build?) => Promise<any> | Parsed entitlements plist |
| addEntitlements | (target, build, entries) | Merge entitlements |
| setEntitlements | (target, build, entries) | Replace entitlements |
| getInfoPlist | (target, build?) => Promise<string> | Relative path to Info.plist |
| getInfoPlistFilename | (target, build?) => Promise<string \| null> | Full path to Info.plist |
| updateInfoPlist | (target, build, entries, mergeMode?) | Merge/replace Info.plist entries |
| getDisplayName | (target, build?) => Promise<string \| null> | Get CFBundleDisplayName |
| setDisplayName | (target, build, name) | Set CFBundleDisplayName |
| addFile | (path) => Promise<void> | Add a source file to the Xcode project |
| copyFile | (src, dest) => Promise<void> | Copy a file into the iOS project |
| getPbxProject | () => IosPbxProject \| null | Raw pbxproject object |
| getProjectFile | (path, create) => T \| null | Get or create a VFS file container |
| getXmlFile | (path) => XmlFile \| null | Get an XML file container |
| getPlistFile | (path) => PlistFile \| null | Get a plist file container |
| xcodeprojName | () => Promise<string> | Name of the .xcodeproj directory |
| pbxprojName | () => Promise<string> | Name of the .pbxproj file |
Target/Build parameters
target: passnullto use the main app target automaticallybuild: passnullto apply to all build configurations (Debug + Release)
AndroidProject (project.android)
| Method | Signature | Description |
|--------|-----------|-------------|
| getBuildGradle | () => GradleFile \| null | Root build.gradle |
| getAppBuildGradle | () => GradleFile \| null | app/build.gradle |
| getAndroidManifest | () => XmlFile | AndroidManifest.xml |
| getPackageName | () => Promise<string \| undefined> | Current package/namespace |
| setPackageName | (name) => Promise<void> | Rename package in manifest, gradle, and Java source |
| getVersionCode | () => Promise<number \| null> | versionCode |
| setVersionCode | (code: number) | Set versionCode |
| incrementVersionCode | () => Promise<void> | Increment versionCode by 1 |
| getVersionName | () => Promise<string \| null> | versionName |
| setVersionName | (name: string) | Set versionName |
| getVersionNameSuffix | () => Promise<string \| null> | versionNameSuffix |
| setVersionNameSuffix | (suffix: string) | Set versionNameSuffix |
| setAppName | (name: string) => Promise<void> | Set app display name |
| getGradlePluginVersion | () => Promise<string \| null> | Android Gradle plugin version |
| getGradleFile | (path: string) => Promise<GradleFile \| null> | Load a Gradle file by relative path |
| getXmlFile | (path: string) => XmlFile \| null | Get an XML file container |
| getResourceXmlFile | (resourcePath: string) => XmlFile \| null | Get an XML file from res/ |
| getPropertiesFile | (path: string) => PropertiesFile \| null | Get a .properties file container |
| getResource | (resDir, file, options?) => Promise<Buffer> | Read a resource file |
| addResource | (resDir, file, contents) => Promise<void> | Write a file to res/<resDir>/ |
| copyFile | (src, dest) => Promise<void> | Copy a file into the Android project |
| copyToResources | (resDir, file, source) => Promise<void> | Copy a file into res/ |
| getMainActivityFilename | () => string | Name of the main activity Java file |
| getMainActivityPath | () => Promise<string> | Relative path to the main activity |
| getResourcesPath | () => string | Relative path to res/ |
| getResourcesRoot | () => string \| null | Absolute path to res/ |
| getProjectFile | (path, create) => T \| null | Get or create a VFS file container |
License
MIT
