Added support for additional buffers

This commit is contained in:
Alexander Cerutti
2019-07-09 23:44:36 +02:00
parent d4f67d9b12
commit 6252f4d6a4
2 changed files with 34 additions and 12 deletions

21
API.md
View File

@@ -60,7 +60,7 @@ ___
#### constructor() #### constructor()
```typescript ```typescript
const pass = await createPass({ ... }); const pass = await createPass({ ... }, Buffer.from([ ... ]));
``` ```
**Returns**: **Returns**:
@@ -71,15 +71,16 @@ const pass = await createPass({ ... });
| Key | Type | Description | Optional | Default Value | | Key | Type | Description | Optional | Default Value |
|-----|------|---------------|:-------------:|:-----------:| |-----|------|---------------|:-------------:|:-----------:|
| options | Object | The options to create the pass | false | - | options | Object | The options to create the pass | `false` | -
| options.model | String/Path/Buffer Object | The model path or a Buffer Object with path as key and Buffer as content | false | - | options.model | String \| Path \| Buffer Object | The model path or a Buffer Object with path as key and Buffer as content | `false` | -
| options.certificates | Object | The certificate object containing the paths to certs files. | false | - | options.certificates | Object | The certificate object containing the paths to certs files. | `false` | -
| options.certificates.wwdr | String/Path | The path to Apple WWDR certificate or its content. | false | - | options.certificates.wwdr | String \| Path | The path to Apple WWDR certificate or its content. | `false` | -
| options.certificates.signerCert | String/Path | The path to Developer certificate file or its content. | false | - | options.certificates.signerCert | String \| Path | The path to Developer certificate file or its content. | `false` | -
| options.certificates.signerKey | Object/String | The object containing developer certificate's key and passphrase. If string, it can be the path to the key file or its content. If object, must have `keyFile` key and might need `passphrase`. | false | - | options.certificates.signerKey | Object/String | The object containing developer certificate's key and passphrase. If string, it can be the path to the key file or its content. If object, must have `keyFile` key and might need `passphrase`. | `false` | -
| options.certificates.signerKey.keyFile | String/Path | The path to developer certificate key or its content. | false | - | options.certificates.signerKey.keyFile | String \| Path | The path to developer certificate key or its content. | `false` | -
| options.certificates.signerKey.passphrase | String \| Number | The passphrase to use to unlock the key. | false | - | options.certificates.signerKey.passphrase | String \| Number | The passphrase to use to unlock the key. | `false` | -
| options.overrides | Object | Dictionary containing all the keys you can override in the pass.json file and does not have a method to get overridden. | true | { } | options.overrides | Object | Dictionary containing all the keys you can override in the pass.json file and does not have a method to get overridden. | `true` | `{ }`
| additionalBuffers | Buffer Object | Dictionary with path as key and Buffer as a content. Each will represent a file to be added to the final model. These will have priority on model ones | `true` | `{ }`
<br><br> <br><br>
<a name="localizing_passes"></a> <a name="localizing_passes"></a>

View File

@@ -1,11 +1,11 @@
import { Pass } from "./pass"; import { Pass } from "./pass";
import { FactoryOptions } from "./schema"; import { FactoryOptions, BundleUnit } from "./schema";
import formatMessage from "./messages"; import formatMessage from "./messages";
import { getModelContents, readCertificatesFromOptions } from "./parser"; import { getModelContents, readCertificatesFromOptions } from "./parser";
export type Pass = InstanceType<typeof Pass> export type Pass = InstanceType<typeof Pass>
export async function createPass(options: FactoryOptions): Promise<Pass> { export async function createPass(options: FactoryOptions, additionalBuffers: BundleUnit): Promise<Pass> {
if (!(options && Object.keys(options).length)) { if (!(options && Object.keys(options).length)) {
throw new Error(formatMessage("CP_NO_OPTS")); throw new Error(formatMessage("CP_NO_OPTS"));
} }
@@ -16,6 +16,12 @@ export async function createPass(options: FactoryOptions): Promise<Pass> {
readCertificatesFromOptions(options.certificates) readCertificatesFromOptions(options.certificates)
]); ]);
if (additionalBuffers) {
const [ additionalL10n, additionalBundle ] = splitBundle(additionalBuffers);
Object.assign(bundle["l10nBundle"], additionalL10n);
Object.assign(bundle["bundle"], additionalBundle);
}
return new Pass({ return new Pass({
model: bundle, model: bundle,
certificates, certificates,
@@ -26,3 +32,18 @@ export async function createPass(options: FactoryOptions): Promise<Pass> {
throw new Error(formatMessage("CP_INIT_ERROR")); throw new Error(formatMessage("CP_INIT_ERROR"));
} }
} }
/**
* Applies a partition to split one bundle
* to two
* @param origin
*/
function splitBundle(origin: Object): [BundleUnit, BundleUnit] {
const keys = Object.keys(origin);
return keys.reduce(([ l10n, bundle ], current) =>
current.includes(".lproj") &&
[ { ...l10n, [current]: origin[current] }, bundle] ||
[ l10n, {...bundle, [current]: origin[current] }]
, [{},{}]);
}