mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 19:25:23 +00:00
Improved interfaces and model
This commit is contained in:
@@ -10,10 +10,25 @@ import formatMessage from "./messages";
|
|||||||
const readDir = promisify(_readdir);
|
const readDir = promisify(_readdir);
|
||||||
const readFile = promisify(_readFile);
|
const readFile = promisify(_readFile);
|
||||||
|
|
||||||
|
interface BundleUnit {
|
||||||
|
[key: string]: Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PartitionedBundle {
|
||||||
|
bundle: BundleUnit;
|
||||||
|
l10nBundle: {
|
||||||
|
[key: string]: BundleUnit
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FinalCertificates {
|
||||||
|
wwdr: forge.pki.Certificate;
|
||||||
|
signerCert: forge.pki.Certificate;
|
||||||
|
signerKey: forge.pki.PrivateKey;
|
||||||
|
}
|
||||||
|
|
||||||
interface FactoryOptions {
|
interface FactoryOptions {
|
||||||
model: string | {
|
model: string | BundleUnit,
|
||||||
[key: string]: Buffer
|
|
||||||
},
|
|
||||||
certificates: Certificates;
|
certificates: Certificates;
|
||||||
overrides?: Object;
|
overrides?: Object;
|
||||||
}
|
}
|
||||||
@@ -59,21 +74,12 @@ async function createPass(options: FactoryOptions) {
|
|||||||
return new Pass();
|
return new Pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BundleUnit {
|
|
||||||
[key: string]: Buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getModelContents(model: FactoryOptions["model"]) {
|
async function getModelContents(model: FactoryOptions["model"]) {
|
||||||
if (!(model && (typeof model === "string" || (typeof model === "object" && Object.keys(model).length)))) {
|
if (!(model && (typeof model === "string" || (typeof model === "object" && Object.keys(model).length)))) {
|
||||||
throw new Error("Unable to create Pass: invalid model provided");
|
throw new Error("Unable to create Pass: invalid model provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
let modelContents: {
|
let modelContents: PartitionedBundle;
|
||||||
bundle: BundleUnit,
|
|
||||||
l10nBundle: {
|
|
||||||
[key: string]: BundleUnit
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (typeof model === "string") {
|
if (typeof model === "string") {
|
||||||
modelContents = await getModelFolderContents(model);
|
modelContents = await getModelFolderContents(model);
|
||||||
@@ -149,7 +155,7 @@ async function getModelFolderContents(model: string): Promise<PartitionedBundle>
|
|||||||
bundle: bundleMap,
|
bundle: bundleMap,
|
||||||
l10nBundle: Object.assign({}, ...L10N_FilesListByFolder
|
l10nBundle: Object.assign({}, ...L10N_FilesListByFolder
|
||||||
.map((folder, index) => ({ [l10nFolders[index]]: folder }))
|
.map((folder, index) => ({ [l10nFolders[index]]: folder }))
|
||||||
) as { [key: string]: BundleUnit }
|
) as PartitionedBundle["l10nBundle"]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,12 +208,6 @@ function getModelBufferContents(model: BundleUnit): PartitionedBundle {
|
|||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface FinalCertificates {
|
|
||||||
wwdr: forge.pki.Certificate;
|
|
||||||
signerCert: forge.pki.Certificate;
|
|
||||||
signerKey: forge.pki.PrivateKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function readCertificatesFromOptions(options: Certificates): Promise<FinalCertificates> {
|
async function readCertificatesFromOptions(options: Certificates): Promise<FinalCertificates> {
|
||||||
if (!isValid(options, "certificatesSchema")) {
|
if (!isValid(options, "certificatesSchema")) {
|
||||||
throw new Error("Unable to create Pass: certificates schema validation failed.");
|
throw new Error("Unable to create Pass: certificates schema validation failed.");
|
||||||
|
|||||||
Reference in New Issue
Block a user