0.0.3 • Published 12 months ago

@roninoss/plugin-primitives v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Plugin Primitives

What is it?

A collection of type-safe config plugin primitives that handle common native configuration tasks.

API

withColor šŸ¤–

Adds, modifies, or removes a color value from the colors.xml file. Supports both normal and night modes.

withColor(config, {
  name: "primaryColor",
  value: "#000000",
  night: true,
});

withString šŸ¤–

Adds, modifies, or removes a string value from the strings.xml file.

withString(config, {
  name: "stringName",
  value: "Hello, world!",
  translatable: true,
});

withEntitlement šŸŽ

Adds, modifies, or removes an entitlement to your app, allowing it to access a feature on the device.

withEntitlement(config, {
  key: "com.apple.developer.healthkit.access",
  value: "yes",
});

withInfo šŸŽ

Adds, modifies, or removes a key/value pair to the Info.plist file.

withInfo(config, {
  key: "NSHealthShareUsageDescription",
  value: "We need access to your health data.",
});

withPbxProject šŸŽ

Modifies the project.pbxproj file by overwritting it with an updated version. The plugin will use the project.pbxproj file found in the parallelDir directory, which defaults to plugins and overwitten. This ensures that the iOS project is always in a consistent state.

withPbxProject(config);

withModifyFile šŸ¤– šŸŽ

Modifies an arbitrary file by

  1. Finding and replacing a string
withModifyFile(config, {
  filePath: "ios/AppDelegate.m",
  find: "something",
  replace: "something else",
});
  1. Inserting a string at a specific anchor and offset
withModifyFile(config, {
  filePath: "ios/myapp/AppDelegate.mmm",
  newSrc: "hello",
  anchor: "something",
  offset: 0,
});

This is primaririly used to modify unstructured files that don't have a specific format. For structured files, use more specific plugins like withInfo, withColor, etc.

withSourceFile šŸ¤– šŸŽ

Adds a source file to the project. Accepts an optional contents parameter to specify the contents of the file. If not provided, the contents will be read from the file at plugins/<filePath>. Also accepts an optional parallelDir parameter (which defaults to plugins) to specify a directory (relative to the project root) to place the file in. The parallel directory mirrors the ios or android directory structure.

withSourceFile(config, {
  filePath: "ios/myapp/NewFile.swift",
});

Example file structure:

ios/
ā”œā”€ā”€ myapp/
│   ā”œā”€ā”€ NewFile.swift
|   └── ...
plugins/
ā”œā”€ā”€ ios/
│   └── myapp/
│       └── NewFile.swift
└── ...

withResourceFile šŸ¤– šŸŽ

Add a resource file to the project. Accepts an optional parallelDir parameter (which defaults to plugins) to specify a directory (relative to the project root) to place the file in. The parallel directory mirrors the ios or android directory structure.

withResourceFile(config, {
  filePath: "android/src/main/res/values/strings2.xml",
});

Example file structure:

android/
ā”œā”€ā”€ src/
|   ā”œā”€ā”€ ...
│   └── main/
│       └── res/
│           └── values/
│               └── strings2.xml
|
plugins/
ā”œā”€ā”€ android/
│   └── src/
│       └── main/
│           └── res/
│               └── values/
│                   └── strings2.xml
└── ...

withRemoveFile šŸ¤– šŸŽ

Removes a file and any references to it from the project.

withRemoveFile(config, {
  filePath: "path/to/file",
});

withPlugins šŸ¤– šŸŽ

Applies multiple plugins. Accepts an array of plugins, where each element is either a plugin or a tuple of a plugin and its (type-safe) options.

withPlugins(config, [
  withPbxProject,
  [withEntitlement, { key: "aps-environment", value: "development" }],
  [withColor, { name: "primaryColor", value: "#000000", night: true }],
]);
0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago