Skip to content

Commit 187b4e4

Browse files
authored
feat(targets): Add optional id field to target config (#128)
Craft allows using multiple instances of the same target with different (or same!) configurations but it assumes `name` field is a unique identifier. This PR adds an optional `id` field to distinguish multiple targets with the same name such as multiple Docker images to publish.
1 parent b59fbd4 commit 187b4e4

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 0.12.0
44

55
- feat(docker): Add sourceFormat & targetFormat options (#125)
6+
- feat(targets): Add optional `id` field to target config (#128)
67

78
## 0.11.1
89

src/commands/publish.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,12 @@ async function publishToTargets(
137137
logger.debug('Initializing targets');
138138
for (const targetConfig of targetConfigList) {
139139
const targetClass = getTargetByName(targetConfig.name);
140+
const targetDescriptor = targetConfig.id
141+
? `${targetConfig.id}[${targetConfig.name}]`
142+
: targetConfig.name;
140143
if (!targetClass) {
141144
logger.warn(
142-
`Target implementation for "${targetConfig.name}" not found.`
145+
`Target implementation for "${targetDescriptor}" not found.`
143146
);
144147
continue;
145148
}
@@ -154,8 +157,11 @@ async function publishToTargets(
154157

155158
// Publish to all targets
156159
for (const target of targetList) {
160+
const targetDescriptor = target.config.id
161+
? `${target.config.id}[${target.name}]`
162+
: target.name;
157163
const publishMessage = `=== Publishing to target: ${chalk.bold(
158-
chalk.cyan(target.name)
164+
chalk.cyan(targetDescriptor)
159165
)} ===`;
160166
const delim = Array(stringLength(publishMessage) + 1).join('=');
161167
logger.info(' ');
@@ -455,7 +461,7 @@ export async function publishMain(argv: PublishOptions): Promise<any> {
455461
if (targetList[0] !== SpecialTarget.All) {
456462
targetConfigList = targetConfigList.filter(
457463
(targetConf: { [key: string]: any }) =>
458-
targetList.indexOf(targetConf.name) > -1
464+
targetList.indexOf(targetConf.id || targetConf.name) > -1
459465
);
460466
}
461467

@@ -476,7 +482,7 @@ export async function publishMain(argv: PublishOptions): Promise<any> {
476482

477483
// TODO init all targets earlier
478484
targetConfigList
479-
.map(t => t.name || '__undefined__')
485+
.map(t => (t.id ? `${t.id}[${t.name}]` : t.name || '__undefined__'))
480486
.forEach(target => logger.info(` - ${target}`));
481487
logger.info(' ');
482488

src/schemas/projectConfig.schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ const projectConfigJsonSchema = {
9696
name: {
9797
type: 'string',
9898
},
99+
id: {
100+
type: 'string',
101+
},
99102
includeNames: {
100103
type: 'string',
101104
},

src/schemas/project_config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface GithubGlobalConfig {
3131
*/
3232
export interface TargetConfig {
3333
name?: string;
34+
id?: string;
3435
includeNames?: string;
3536
excludeNames?: string;
3637
[k: string]: any;

0 commit comments

Comments
 (0)