( app: App, options: BuildPackageOptions, )
| 49 | } |
| 50 | |
| 51 | export async function buildPackage( |
| 52 | app: App, |
| 53 | options: BuildPackageOptions, |
| 54 | ): Promise<BuildPackageResult> { |
| 55 | const { choices, rootChoiceIds, quickAddVersion } = options; |
| 56 | const excludedIds = new Set(options.excludedChoiceIds ?? []); |
| 57 | const createdAt = options.createdAt ?? new Date().toISOString(); |
| 58 | |
| 59 | const closure = collectChoiceClosure(choices, rootChoiceIds, { |
| 60 | excludedChoiceIds: excludedIds, |
| 61 | }); |
| 62 | const includedChoiceIds = new Set(closure.choiceIds); |
| 63 | const scripts = collectScriptDependencies(closure.catalog, closure.choiceIds); |
| 64 | const files = collectFileDependencies(closure.catalog, closure.choiceIds); |
| 65 | |
| 66 | const assetDescriptors = collectAssetDescriptors(scripts, files); |
| 67 | |
| 68 | const assets = await encodeAssets(app, assetDescriptors); |
| 69 | const secretOptionNamesByPath = buildSecretOptionNamesByPath( |
| 70 | assets.encodedAssets, |
| 71 | ); |
| 72 | |
| 73 | const packageChoices: QuickAddPackageChoice[] = closure.choiceIds.map( |
| 74 | (choiceId) => { |
| 75 | const entry = closure.catalog.get(choiceId); |
| 76 | if (!entry) throw new Error(`Choice '${choiceId}' missing from catalog.`); |
| 77 | const clonedChoice = deepClone(entry.choice); |
| 78 | pruneChoiceTree(clonedChoice, includedChoiceIds); |
| 79 | stripUserScriptSecretRefsFromChoice(clonedChoice, { |
| 80 | secretOptionNamesByPath, |
| 81 | stripUnknownStringSettings: true, |
| 82 | }); |
| 83 | return { |
| 84 | choice: clonedChoice, |
| 85 | pathHint: [...entry.path], |
| 86 | parentChoiceId: entry.parentId, |
| 87 | }; |
| 88 | }, |
| 89 | ); |
| 90 | |
| 91 | const normalizedRootIds = rootChoiceIds.filter((id) => |
| 92 | includedChoiceIds.has(id), |
| 93 | ); |
| 94 | |
| 95 | const pkg: QuickAddPackage = { |
| 96 | schemaVersion: QUICKADD_PACKAGE_SCHEMA_VERSION, |
| 97 | quickAddVersion, |
| 98 | createdAt, |
| 99 | rootChoiceIds: [...normalizedRootIds], |
| 100 | choices: packageChoices, |
| 101 | assets: assets.encodedAssets, |
| 102 | }; |
| 103 | |
| 104 | return { |
| 105 | pkg, |
| 106 | missingChoiceIds: closure.missingChoiceIds, |
| 107 | missingAssets: assets.missingAssets, |
| 108 | }; |
no test coverage detected