@vamship/build-utils 2.0.0-3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/project.js +11 -0
- package/src/task-builders/not-supported-task-builder.js +11 -2
- package/src/task-builders/publish-aws-task-builder.js +5 -1
- package/src/task-builders/publish-task-builder.js +18 -1
- package/src/task-factories/aws-microservice-task-factory.js +15 -2
package/package.json
CHANGED
package/src/project.js
CHANGED
@@ -57,6 +57,12 @@ export class Project {
|
|
57
57
|
);
|
58
58
|
}
|
59
59
|
|
60
|
+
if (type === 'aws-microservice' && !aws) {
|
61
|
+
throw new Error(
|
62
|
+
`AWS microservice projects require AWS configuration`,
|
63
|
+
);
|
64
|
+
}
|
65
|
+
|
60
66
|
if (aws && aws.stacks && Object.keys(aws.stacks).length <= 0) {
|
61
67
|
throw new Error(`No AWS stacks defined`);
|
62
68
|
}
|
@@ -243,6 +249,11 @@ export class Project {
|
|
243
249
|
* @return {Array} A list of stack keys
|
244
250
|
*/
|
245
251
|
getCdkTargets() {
|
252
|
+
if (this._type !== 'aws-microservice') {
|
253
|
+
throw new Error(
|
254
|
+
'CDK targets are only available for AWS microservices',
|
255
|
+
);
|
256
|
+
}
|
246
257
|
return Object.keys(this._cdkTargets);
|
247
258
|
}
|
248
259
|
|
@@ -12,12 +12,21 @@ import { Project } from '../project.js';
|
|
12
12
|
export class NotSupportedTaskBuilder extends TaskBuilder {
|
13
13
|
/**
|
14
14
|
* Creates a new task builder.
|
15
|
+
*
|
16
|
+
* @param {String} [message] An optional message to display when the task is
|
17
|
+
* run.
|
15
18
|
*/
|
16
|
-
constructor() {
|
19
|
+
constructor(message) {
|
17
20
|
super(
|
18
21
|
'not-supported',
|
19
22
|
`Task that does nothing - used to indicate that a task is not supported for a project type.`,
|
20
23
|
);
|
24
|
+
|
25
|
+
if (typeof message !== 'string' || message.length <= 0) {
|
26
|
+
message = 'Task not defined for project';
|
27
|
+
}
|
28
|
+
|
29
|
+
this._message = message;
|
21
30
|
}
|
22
31
|
|
23
32
|
/**
|
@@ -33,7 +42,7 @@ export class NotSupportedTaskBuilder extends TaskBuilder {
|
|
33
42
|
if (!(project instanceof Project)) {
|
34
43
|
throw new Error('Invalid project (arg #1)');
|
35
44
|
}
|
36
|
-
return () => _fancyLog.warn(
|
45
|
+
return async () => _fancyLog.warn(this._message);
|
37
46
|
}
|
38
47
|
|
39
48
|
/**
|
@@ -30,7 +30,11 @@ export class PublishAwsTaskBuilder extends TaskBuilder {
|
|
30
30
|
if (typeof requireApproval !== 'boolean') {
|
31
31
|
throw new Error('Invalid requireApproval (arg #3)');
|
32
32
|
}
|
33
|
-
|
33
|
+
|
34
|
+
super(
|
35
|
+
`publish-aws-${target}`,
|
36
|
+
`Publish a CDK project to AWS: [${target}]`,
|
37
|
+
);
|
34
38
|
|
35
39
|
this._target = target;
|
36
40
|
this._environment = environment;
|
@@ -59,7 +59,24 @@ export class PublishTaskBuilder extends TaskBuilder {
|
|
59
59
|
}
|
60
60
|
// Type aws-microservice
|
61
61
|
else if (type === 'aws-microservice') {
|
62
|
-
|
62
|
+
const stacks = project.getCdkTargets();
|
63
|
+
const defaultStack = stacks.find((target) => target === 'default');
|
64
|
+
|
65
|
+
if (defaultStack) {
|
66
|
+
return [
|
67
|
+
new PublishAwsTaskBuilder(
|
68
|
+
defaultStack,
|
69
|
+
process.env.INFRA_ENV,
|
70
|
+
process.env.INFRA_NO_PROMPT === 'true',
|
71
|
+
),
|
72
|
+
];
|
73
|
+
} else {
|
74
|
+
return [
|
75
|
+
new NotSupportedTaskBuilder(
|
76
|
+
'No default stack defined for project. Please use an explicitly named publish task.',
|
77
|
+
),
|
78
|
+
];
|
79
|
+
}
|
63
80
|
}
|
64
81
|
// Type container
|
65
82
|
else if (type === 'container') {
|
@@ -9,6 +9,7 @@ import { PackageTaskBuilder } from '../task-builders/package-task-builder.js';
|
|
9
9
|
import { PublishTaskBuilder } from '../task-builders/publish-task-builder.js';
|
10
10
|
import { DocsTaskBuilder } from '../task-builders/docs-task-builder.js';
|
11
11
|
import { TestTaskBuilder } from '../task-builders/test-task-builder.js';
|
12
|
+
import { PublishAwsTaskBuilder } from '../task-builders/publish-aws-task-builder.js';
|
12
13
|
|
13
14
|
/**
|
14
15
|
* Represents a factory that generates a set of build tasks for a given project
|
@@ -36,6 +37,18 @@ export class AwsMicroserviceTaskFactory extends TaskFactory {
|
|
36
37
|
return [];
|
37
38
|
}
|
38
39
|
|
40
|
+
const publishTasks = this._project
|
41
|
+
.getCdkTargets()
|
42
|
+
.filter((stack) => stack !== 'default')
|
43
|
+
.map(
|
44
|
+
(stack) =>
|
45
|
+
new PublishAwsTaskBuilder(
|
46
|
+
stack,
|
47
|
+
process.env.INFRA_ENV,
|
48
|
+
process.env.INFRA_NO_PROMPT === 'true',
|
49
|
+
),
|
50
|
+
);
|
51
|
+
|
39
52
|
return [
|
40
53
|
new CleanTaskBuilder(),
|
41
54
|
new FormatTaskBuilder(),
|
@@ -47,7 +60,7 @@ export class AwsMicroserviceTaskFactory extends TaskFactory {
|
|
47
60
|
new DocsTaskBuilder(this._project),
|
48
61
|
new BuildTaskBuilder(this._project),
|
49
62
|
new PackageTaskBuilder(this._project),
|
50
|
-
new PublishTaskBuilder(
|
51
|
-
];
|
63
|
+
new PublishTaskBuilder(),
|
64
|
+
].concat(publishTasks);
|
52
65
|
}
|
53
66
|
}
|