(project: string, type: string, targetName: string, resources: string | string[])
| 115 | } |
| 116 | |
| 117 | applyTarget(project: string, type: string, targetName: string, resources: string | string[]) { |
| 118 | if (!TARGET_TYPES[type]) { |
| 119 | throw new FirebaseError( |
| 120 | `Unrecognized target type ${clc.bold(type)}. Must be one of ${Object.keys( |
| 121 | TARGET_TYPES, |
| 122 | ).join(", ")}`, |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | if (typeof resources === "string") { |
| 127 | resources = [resources]; |
| 128 | } |
| 129 | |
| 130 | const changed: { resource: string; target: string }[] = []; |
| 131 | |
| 132 | // remove resources from existing targets |
| 133 | for (const resource of resources) { |
| 134 | const cur = this.findTarget(project, type, resource); |
| 135 | if (cur && cur !== targetName) { |
| 136 | this.unsetTargetResource(project, type, cur, resource); |
| 137 | changed.push({ resource: resource, target: cur }); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | // apply resources to new target |
| 142 | const existing = this.target(project, type, targetName); |
| 143 | const list = Array.from(new Set(existing.concat(resources))).sort(); |
| 144 | this.set(["targets", project, type, targetName], list); |
| 145 | |
| 146 | this.save(); |
| 147 | return changed; |
| 148 | } |
| 149 | |
| 150 | removeTarget(project: string, type: string, resource: string): string | null { |
| 151 | const name = this.findTarget(project, type, resource); |
no test coverage detected