@vamship/build-utils 1.6.1 → 2.0.0-1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. package/package.json +40 -40
  2. package/src/directory.js +20 -24
  3. package/src/index.js +5 -17
  4. package/src/project.js +160 -433
  5. package/src/schema/project-definition.js +137 -0
  6. package/src/task-builder.js +100 -0
  7. package/src/task-builders/build-js-task-builder.js +57 -0
  8. package/src/task-builders/build-task-builder.js +78 -0
  9. package/src/task-builders/build-ts-task-builder.js +63 -0
  10. package/src/task-builders/build-ui-task-builder.js +45 -0
  11. package/src/task-builders/clean-task-builder.js +39 -0
  12. package/src/task-builders/copy-files-task-builder.js +78 -0
  13. package/src/task-builders/docs-js-task-builder.js +74 -0
  14. package/src/task-builders/docs-task-builder.js +74 -0
  15. package/src/task-builders/docs-ts-task-builder.js +52 -0
  16. package/src/task-builders/format-task-builder.js +61 -0
  17. package/src/task-builders/index.js +21 -17
  18. package/src/task-builders/lint-fix-task-builder.js +61 -0
  19. package/src/task-builders/lint-task-builder.js +56 -0
  20. package/src/task-builders/not-supported-task-builder.js +48 -0
  21. package/src/task-builders/package-aws-task-builder.js +105 -0
  22. package/src/task-builders/package-container-task-builder.js +132 -0
  23. package/src/task-builders/package-npm-task-builder.js +83 -0
  24. package/src/task-builders/package-task-builder.js +101 -0
  25. package/src/task-builders/publish-aws-task-builder.js +111 -0
  26. package/src/task-builders/publish-container-task-builder.js +103 -0
  27. package/src/task-builders/publish-npm-task-builder.js +60 -0
  28. package/src/task-builders/publish-task-builder.js +98 -0
  29. package/src/task-builders/test-task-builder.js +85 -0
  30. package/src/task-builders/test-ui-task-builder.js +65 -0
  31. package/src/task-builders/watch-task-builder.js +109 -0
  32. package/src/task-factories/api-task-factory.js +67 -0
  33. package/src/task-factories/aws-microservice-task-factory.js +53 -0
  34. package/src/task-factories/cli-task-factory.js +68 -0
  35. package/src/task-factories/container-task-factory.js +64 -0
  36. package/src/task-factories/index.js +8 -0
  37. package/src/task-factories/lib-task-factory.js +52 -0
  38. package/src/task-factories/ui-task-factory.js +48 -0
  39. package/src/task-factory.js +52 -0
  40. package/src/utils/semver-utils.js +29 -0
  41. package/src/utils/task-factory-utils.js +70 -0
  42. package/src/task-builders/build/build-js.js +0 -66
  43. package/src/task-builders/build/build-ts.js +0 -70
  44. package/src/task-builders/build/build-types.js +0 -47
  45. package/src/task-builders/build/build-ui.js +0 -67
  46. package/src/task-builders/build/index.js +0 -60
  47. package/src/task-builders/clean.js +0 -57
  48. package/src/task-builders/docs/docs-js.js +0 -41
  49. package/src/task-builders/docs/docs-ts.js +0 -40
  50. package/src/task-builders/docs/index.js +0 -32
  51. package/src/task-builders/format.js +0 -58
  52. package/src/task-builders/lint.js +0 -56
  53. package/src/task-builders/package/index.js +0 -50
  54. package/src/task-builders/package/package-aws.js +0 -58
  55. package/src/task-builders/package/package-docker.js +0 -128
  56. package/src/task-builders/package/package-npm.js +0 -25
  57. package/src/task-builders/package/package-types.js +0 -54
  58. package/src/task-builders/package/utils.js +0 -50
  59. package/src/task-builders/publish/index.js +0 -50
  60. package/src/task-builders/publish/publish-aws.js +0 -62
  61. package/src/task-builders/publish/publish-docker.js +0 -79
  62. package/src/task-builders/publish/publish-npm.js +0 -36
  63. package/src/task-builders/publish/publish-types.js +0 -36
  64. package/src/task-builders/test/index.js +0 -39
  65. package/src/task-builders/test/test-ui.js +0 -39
  66. package/src/task-builders/test/test.js +0 -67
package/src/project.js CHANGED
@@ -1,274 +1,100 @@
1
- 'use strict';
1
+ import semver from 'semver';
2
+ import { camelCase as _camelCase } from 'change-case';
3
+ import Ajv from 'ajv';
4
+ import _colors from 'ansi-colors';
2
5
 
3
- const _camelcase = require('camelcase');
4
- const Directory = require('./directory');
5
- const _dotEnv = require('dotenv');
6
- const _dotEnvExpand = require('dotenv-expand');
7
- const _fs = require('fs');
6
+ import _projectDataSchema from './schema/project-definition.js';
7
+ import { Directory } from './directory.js';
8
8
 
9
- const SUPPORTED_PROJECT_TYPES = [
10
- 'lib',
11
- 'cli',
12
- 'api',
13
- 'aws-microservice',
14
- 'container',
15
- 'ui',
16
- ];
17
- const SUPPORTED_LANGUAGES = ['js', 'ts'];
9
+ const _validateProjectData = new Ajv().compile(_projectDataSchema);
18
10
 
19
11
  /**
20
- * Represents project configuration. This class will encapsulate information
21
- * about projects that should help automate the build/test/deploy toolchain for
22
- * a project.
12
+ * Represents a build project that encapsulates one or more relavent build
13
+ * tasks.
23
14
  */
24
- module.exports = class Project {
15
+ export class Project {
25
16
  /**
26
- * @param {Object} packageConfig Reference to the project configuration.
27
- * This is typically the contents of package.json, with an additional
28
- * set of properties called `buildMetadata`.
29
- * @param {Object} [buildMetadata] An optional build metadata object that
30
- * will override the build metadata defined within packageConfig.
31
- */
32
- constructor(packageConfig, buildMetadata) {
33
- if (!packageConfig || typeof packageConfig !== 'object') {
34
- throw new Error('Invalid packageConfig (arg #1)');
35
- }
36
-
37
- const config = Object.assign({}, packageConfig);
38
- config.buildMetadata = Object.assign(
39
- {},
40
- config.buildMetadata,
41
- buildMetadata
42
- );
43
-
44
- this._name = config.name;
45
- this._license = config.license;
46
- this._keywords = (config.keywords || []).slice();
47
- this._unscopedName = config.name.replace(/^@[^/]*\//, '');
48
- this._snakeCasedName = config.name
49
- .replace(/^@/, '')
50
- .replace(/\//g, '-');
51
- this._version = config.version;
52
- this._description = config.description;
53
- this._initProjectProperties(config.buildMetadata);
54
-
55
- const tree = {
56
- src: null,
57
- test: {
58
- unit: null,
59
- api: null,
60
- },
61
- infra: null,
62
- working: {
63
- src: null,
64
- test: {
65
- unit: null,
66
- api: null,
67
- },
68
- infra: null,
69
- node_modules: null,
70
- },
71
- dist: null,
72
- docs: null,
73
- node_modules: null,
74
- coverage: null,
75
- '.gulp': null,
76
- '.tscache': null,
77
- logs: null,
78
- 'cdk.out': null,
79
- };
80
-
81
- if (this._hasExportedTypes) {
82
- let rootParentDir = tree;
83
- let workingParentDir = tree.working;
84
-
85
- const exportedTypesDirs = this._exportedTypes.split('/');
86
- const lastIndex = exportedTypesDirs.length - 1;
87
-
88
- exportedTypesDirs.forEach((dirName, index) => {
89
- const isLastIndex = index === lastIndex;
90
-
91
- if (!rootParentDir[dirName]) {
92
- rootParentDir[dirName] = isLastIndex ? null : {};
93
- }
94
- rootParentDir = rootParentDir[dirName];
95
-
96
- if (!workingParentDir[dirName]) {
97
- workingParentDir[dirName] = isLastIndex ? null : {};
98
- }
99
- workingParentDir = workingParentDir[dirName];
100
- });
101
- }
102
-
103
- this._rootDir = Directory.createTree('./', tree);
104
- }
105
-
106
- /**
107
- * Initializes project properties using values from a metadata object.
17
+ * Creates a new project based on the specified build metadata.
108
18
  *
109
- * @private
110
- * @param {Object} buildMetadata The metadata to use when initializing
111
- * properties.
19
+ * @param {Object} projectDefinition An object that contains the project
20
+ * definition.
112
21
  */
113
- _initProjectProperties(buildMetadata) {
114
- if (!buildMetadata || typeof buildMetadata !== 'object') {
115
- throw new Error('Invalid buildMetadata (arg #1)');
22
+ constructor(projectDefinition) {
23
+ if (
24
+ !projectDefinition ||
25
+ projectDefinition instanceof Array ||
26
+ typeof projectDefinition !== 'object'
27
+ ) {
28
+ throw new Error('Invalid project definition (arg #1)');
116
29
  }
117
30
 
118
- const {
119
- projectType,
120
- language,
121
- docker,
122
- requiredEnv,
123
- exportedTypes,
124
- aws,
125
- staticFilePatterns,
126
- } = buildMetadata;
127
-
128
- if (SUPPORTED_PROJECT_TYPES.indexOf(projectType) < 0) {
31
+ if (!_validateProjectData(projectDefinition)) {
32
+ const { instancePath, message } = _validateProjectData.errors[0];
129
33
  throw new Error(
130
- `Invalid projectType (buildMetadata.projectType).\n\tMust be one of: [${SUPPORTED_PROJECT_TYPES}]`
34
+ `Schema validation failed [${instancePath
35
+ .replace(/\//g, '.')
36
+ .trim()} ${message}]`,
131
37
  );
132
38
  }
133
39
 
134
- if (SUPPORTED_LANGUAGES.indexOf(language) < 0) {
40
+ const {
41
+ name,
42
+ version,
43
+ description,
44
+ buildMetadata: {
45
+ type,
46
+ language,
47
+ requiredEnv,
48
+ staticFilePatterns,
49
+ aws,
50
+ container,
51
+ },
52
+ } = projectDefinition;
53
+
54
+ if (!semver.valid(version)) {
135
55
  throw new Error(
136
- `Invalid language (buildMetadata.language)\n\tMust be one of: [${SUPPORTED_LANGUAGES}]`
56
+ `Schema validation failed [.version is not a valid semantic version]`,
137
57
  );
138
58
  }
139
59
 
140
- this._requiredEnv = [];
141
- if (requiredEnv instanceof Array) {
142
- this._requiredEnv = requiredEnv.concat([]);
60
+ if (aws && aws.stacks && Object.keys(aws.stacks).length <= 0) {
61
+ throw new Error(`No AWS stacks defined`);
143
62
  }
144
63
 
145
- this._projectType = projectType;
64
+ this._name = name;
65
+ this._description = description;
66
+ this._unscopedName = name.replace(/^@[^/]*\//, '');
67
+ this._kebabCasedName = name.replace(/^@/, '').replace(/\//g, '-');
68
+ this._version = version;
69
+ this._type = type;
146
70
  this._language = language;
147
- this._exportedTypes = exportedTypes;
148
- this._staticFilePatterns =
149
- staticFilePatterns instanceof Array ? staticFilePatterns : [];
150
-
151
- this._hasTypescript = this._language === 'ts';
152
- this._hasServer = this._projectType === 'api';
153
- this._hasExportedTypes =
154
- typeof exportedTypes === 'string' && exportedTypes.length > 0;
155
-
156
- if (this._projectType === 'aws-microservice') {
157
- if (!aws || typeof aws !== 'object') {
158
- throw new Error(
159
- 'The project is an AWS microservice, but does not define AWS configuration'
160
- );
161
- }
162
-
163
- if (!aws.stacks || typeof aws.stacks !== 'object') {
164
- throw new Error(
165
- 'The project is an AWS microservice, but does not define AWS stacks'
166
- );
167
- }
168
-
169
- this._awsRegion = aws.region;
170
- this._awsProfile = aws.profile;
171
- this._cdkStacks = aws.stacks;
172
- } else {
173
- this._awsRegion = undefined;
174
- this._awsProfile = undefined;
175
- this._cdkStacks = {};
176
- }
177
-
178
- this._hasDocker =
179
- this._projectType !== 'lib' &&
180
- this._projectType !== 'aws-microservice' &&
181
- docker &&
182
- typeof docker === 'object';
183
-
184
- this._dockerTargets = this._initDockerTargets(docker);
185
- }
186
-
187
- /**
188
- * Initialize docker targets for the project.
189
- *
190
- * @param docker The docker configuration section for the project.
191
- */
192
- _initDockerTargets(docker) {
193
- if (!this._hasDocker) return [];
71
+ this._staticFilePatterns = staticFilePatterns || [];
72
+ this._requiredEnv = requiredEnv || [];
73
+ this._aws = aws || { stacks: {} };
74
+ this._cdkTargets = Object.keys(this._aws.stacks).reduce(
75
+ (result, key) => {
76
+ result[key] = { name: this._aws.stacks[key] };
77
+ return result;
78
+ },
79
+ {},
80
+ );
81
+ this._container = container || {};
194
82
 
195
- if (docker.repo || docker.registry || docker.buildArgs) {
196
- // Deprecated settings
197
- let repo = docker.repo;
198
- if (!repo) {
199
- repo = docker.registry
200
- ? `${docker.registry}/${this._unscopedName}`
201
- : this._unscopedName;
202
- }
203
- return [
204
- {
83
+ this._containerTargets = Object.keys(this._container).reduce(
84
+ (result, key) => {
85
+ const { repo, buildFile, buildArgs } = this._container[key];
86
+ result[key] = {
87
+ name: key,
205
88
  repo,
206
- name: 'default',
207
- buildFile: 'Dockerfile',
208
- buildArgs: this._initializeFromEnv(docker.buildArgs),
209
- isDefault: true,
210
- isDeprecated: true,
211
- },
212
- ];
213
- }
214
-
215
- return Object.keys(docker).map((key) => {
216
- const config = docker[key];
217
- if (!config || typeof config !== 'object') {
218
- throw new Error(
219
- `Docker target configuration is invalid for target: [${key}]`
220
- );
221
- }
222
- if (typeof config.repo !== 'string' || config.repo.length <= 0) {
223
- throw new Error(
224
- `Docker target does not define a valid repo: [${key}]`
225
- );
226
- }
227
-
228
- const { repo, buildFile, buildArgs } = config;
229
- return {
230
- repo,
231
- name: key,
232
- buildFile: buildFile || 'Dockerfile',
233
- buildArgs: this._initializeFromEnv(buildArgs),
234
- isDefault: key === 'default',
235
- isDeprecated: false,
236
- };
237
- });
238
- }
239
-
240
- /**
241
- * Loops through the specified object, and replaces specific values from
242
- * those defined in the current environment. Returns a new object with the
243
- * replaced values. Only properties whose values are '__ENV__' will be
244
- * replaced with environment equivalents.
245
- *
246
- * @param map The initial set of key value mappings.
247
- *
248
- * @returns {Array} An array of objects containing "name" and "value"
249
- * properties that contain the key and the values (replaced from
250
- * environment if applicable)
251
- */
252
- _initializeFromEnv(map) {
253
- if (!map || map instanceof Array || typeof map !== 'object') {
254
- return [];
255
- }
256
- return Object.keys(map).map((name) => {
257
- let value = map[name];
258
- if (value == '__ENV__') {
259
- value = process.env[name];
260
- }
261
- return { name, value };
262
- });
263
- }
89
+ buildFile,
90
+ buildArgs,
91
+ };
92
+ return result;
93
+ },
94
+ {},
95
+ );
264
96
 
265
- /**
266
- * Initializes a directory tree for the project based on project properties.
267
- *
268
- * @private
269
- */
270
- _initProjectTree() {
271
- const tree = {
97
+ this._rootDir = Directory.createTree('./', {
272
98
  src: null,
273
99
  test: {
274
100
  unit: null,
@@ -292,251 +118,149 @@ module.exports = class Project {
292
118
  '.tscache': null,
293
119
  logs: null,
294
120
  'cdk.out': null,
295
- };
296
-
297
- if (this._projectType === 'aws-microservice') {
298
- tree.infra = null;
299
- tree.working.infra = null;
300
- tree.working.node_modules = null;
301
- tree['cdk.out'] = null;
302
- }
303
- }
304
-
305
- /**
306
- * An object representation of the project's root directory.
307
- *
308
- * @returns {Directory}
309
- */
310
- get rootDir() {
311
- return this._rootDir;
312
- }
313
-
314
- /**
315
- * An object representation of the root directory for all javascript files.
316
- * For typescript projects, this would be the directory containing the
317
- * transpiled files.
318
- *
319
- * @returns {Directory}
320
- */
321
- get jsRootDir() {
322
- return this._hasTypescript
323
- ? this._rootDir.getChild('working')
324
- : this._rootDir;
121
+ });
122
+ this._banner = `${_colors.cyan(this._name)}@${_colors.green(
123
+ this._version,
124
+ )} (${_colors.blue(this._type)} - ${_colors.yellow(this._language)})`;
325
125
  }
326
126
 
327
127
  /**
328
- * The name of the project as defined in package.json.
128
+ * Gets the name of the project.
329
129
  *
330
- * @return {String}
130
+ * @returns {String} The project name.
331
131
  */
332
132
  get name() {
333
133
  return this._name;
334
134
  }
335
135
 
336
136
  /**
337
- * The license of the project as defined in package.json.
338
- *
339
- * @return {String}
340
- */
341
- get license() {
342
- return this._license;
343
- }
344
-
345
- /**
346
- * The keywords for the project as defined in package.json.
137
+ * Gets the description of the project.
347
138
  *
348
- * @return {String}
139
+ * @returns {String} The project description.
349
140
  */
350
- get keywords() {
351
- return this._keywords;
141
+ get description() {
142
+ return this._description;
352
143
  }
353
144
 
354
145
  /**
355
- * The name of the project without including its scope. IF the project has
356
- * no scope, the unscoped name will match the project name.
146
+ * Gets the name of the project without any scoping prefixes.
357
147
  *
358
- * @return {String}
148
+ * @returns {String} The project name (without scope).
359
149
  */
360
150
  get unscopedName() {
361
151
  return this._unscopedName;
362
152
  }
363
153
 
364
154
  /**
365
- * The name of the project formatted in snake case. Ideal for use when
366
- * generating package names. This property does not include the file
367
- * extension (.tgz).
368
- */
369
- get snakeCasedName() {
370
- return this._snakeCasedName;
371
- }
372
-
373
- /**
374
- * The version of the project as defined in package.json.
375
- *
376
- * @return {String}
377
- */
378
- get version() {
379
- return this._version;
380
- }
381
-
382
- /**
383
- * The description of the project as defined in package.json.
155
+ * Gets the name of the project in kebab case.
384
156
  *
385
- * @return {String}
157
+ * @returns {String} The project name in kebab case.
386
158
  */
387
- get description() {
388
- return this._description;
159
+ get kebabCasedName() {
160
+ return this._kebabCasedName;
389
161
  }
390
162
 
391
163
  /**
392
164
  * Gets the name of the expected configuration file name based on the name
393
165
  * of the project.
394
- */
395
- get configFileName() {
396
- return `.${_camelcase(this._unscopedName)}rc`;
397
- }
398
-
399
- /**
400
- * The project type of the project (lib/api/cli).
401
- *
402
- * @return {String}
403
- */
404
- get projectType() {
405
- return this._projectType;
406
- }
407
-
408
- /**
409
- * The language used by the project (js/ts).
410
166
  *
411
- * @return {String}
167
+ * @returns {String} The expected config file name.
412
168
  */
413
- get language() {
414
- return this._language;
169
+ get configFileName() {
170
+ return `.${_camelCase(this._unscopedName)}rc`;
415
171
  }
416
172
 
417
173
  /**
418
- * Returns the AWS region configured for the project.
174
+ * Gets the version of the project.
419
175
  *
420
- * @return {String}
176
+ * @returns {String} The project version.
421
177
  */
422
- get awsRegion() {
423
- return this._awsRegion;
178
+ get version() {
179
+ return this._version;
424
180
  }
425
181
 
426
182
  /**
427
- * Returns the AWS profile configured for the project.
183
+ * Gets the type of the project.
428
184
  *
429
- * @return {String}
185
+ * @returns {String} The project type.
430
186
  */
431
- get awsProfile() {
432
- return this._awsProfile;
187
+ get type() {
188
+ return this._type;
433
189
  }
434
190
 
435
191
  /**
436
- * The path to the directory that contains the types exported by this
437
- * project.
192
+ * Gets the language of the project.
438
193
  *
439
- * @return {String}
194
+ * @returns {String} The project language.
440
195
  */
441
- get exportedTypes() {
442
- return this._exportedTypes;
196
+ get language() {
197
+ return this._language;
443
198
  }
444
199
 
445
200
  /**
446
- * Additional files to copy from the source directory to the build
447
- * directory.
201
+ * Gets the root directory of the project.
448
202
  *
449
- * @return {String}
203
+ * @returns {Directory} The project root directory
450
204
  */
451
- get staticFilePatterns() {
452
- return this._staticFilePatterns;
205
+ get rootDir() {
206
+ return this._rootDir;
453
207
  }
454
208
 
455
209
  /**
456
- * Determines whether or not the project can be packaged up as a docker
457
- * image.
210
+ * Gets a colorized banner for the project.
458
211
  *
459
- * @return {Boolean}
212
+ * @returns {String} The colorized banner text.
460
213
  */
461
- get hasDocker() {
462
- return this._hasDocker;
214
+ get banner() {
215
+ return this._banner;
463
216
  }
464
217
 
465
218
  /**
466
- * Determines whether or not the project contains typescript files.
219
+ * Returns a list of static file patterns configured for the project.
467
220
  *
468
- * @return {Boolean}
221
+ * @returns {Array} An array of glob strings used to identify static files
222
+ * copied over during a build.
469
223
  */
470
- get hasTypescript() {
471
- return this._hasTypescript;
224
+ getStaticFilePatterns() {
225
+ return this._staticFilePatterns.concat([]);
472
226
  }
473
227
 
474
228
  /**
475
- * Determines whether or not the project has a server component that might
476
- * require API tests or the ability to host a local server.
229
+ * Returns a list of environment variables that must be defined for the
230
+ * build.
477
231
  *
478
- * @return {Boolean}
232
+ * @returns {Array} An array of environment variable names.
479
233
  */
480
- get hasServer() {
481
- return this._hasServer;
234
+ getRequiredEnv() {
235
+ return this._requiredEnv.concat([]);
482
236
  }
483
237
 
484
238
  /**
485
- * Determines if the project has any types to export.
239
+ * Returns a list of CDK stack keys defined for the project. These stack
240
+ * keys will be used to generate deploy tasks for each. Each key maps to a
241
+ * specific CDK stack that can be deployed.
486
242
  *
487
- * @return {String}
243
+ * @return {Array} A list of stack keys
488
244
  */
489
- get hasExportedTypes() {
490
- return this._hasExportedTypes;
245
+ getCdkTargets() {
246
+ return Object.keys(this._cdkTargets);
491
247
  }
492
248
 
493
249
  /**
494
- * Initializes a list of environment variables from the specified files.
495
- * If environment variables are repeated in files, the declaration in the
496
- * first file takes precedence over the others.
250
+ * Gets CDK stack information based on the cdk stack key.
497
251
  *
498
- * @param {Array} [files=[]] A list of files to load environment variables
499
- * from.
252
+ * @param {String} target The CDK target name
253
+ * @returns {Object} The CDK definition corresponding to the target.
500
254
  */
501
- initEnv(envFiles) {
502
- if (!(envFiles instanceof Array)) {
503
- envFiles = [];
255
+ getCdkStackDefinition(target) {
256
+ if (typeof target !== 'string' || target.length <= 0) {
257
+ throw new Error('Invalid CDK target (arg #1)');
504
258
  }
505
- envFiles
506
- .filter((file) => _fs.existsSync(file))
507
- .forEach((file) =>
508
- _dotEnvExpand.expand(_dotEnv.config({ path: file }))
509
- );
510
- }
511
-
512
- /**
513
- * Returns a list of required environment variables. These parameters can
514
- * be checked during build/package time to ensure that they exist, before
515
- * performing any actions.
516
- *
517
- * @return {Array}
518
- */
519
- getRequiredEnv() {
520
- return this._requiredEnv.concat([]);
521
- }
522
-
523
- /**
524
- * Checks to see if all required variables have been defined in the
525
- * environment. This is typically a runtime call, executed prior to
526
- * building/packaging a project.
527
- */
528
- validateRequiredEnv() {
529
- const missingVars = [];
530
- this._requiredEnv.forEach((param) => {
531
- if (!process.env[param]) {
532
- missingVars.push(param);
533
- }
534
- });
535
- if (missingVars.length > 0) {
536
- throw new Error(
537
- `Required environment variables not defined: ${missingVars}`
538
- );
259
+ const stack = this._cdkTargets[target];
260
+ if (!stack) {
261
+ throw new Error(`CDK target has not been defined (${target})`);
539
262
  }
263
+ return Object.assign({}, stack);
540
264
  }
541
265
 
542
266
  /**
@@ -545,36 +269,39 @@ module.exports = class Project {
545
269
  * - repo: The docker repo
546
270
  * - buildFile: The name of the build file to use
547
271
  * - buildArgs: Arguments to be passed to the docker build
548
- * - isDefault: Determines if the current target is the default one
549
- * - isDeprecated: Determines if the target uses a deprecated configuration.
550
272
  *
551
273
  * @return {Array}
552
274
  */
553
- getDockerTargets() {
554
- return this._dockerTargets.concat([]);
275
+ getContainerTargets() {
276
+ return Object.keys(this._containerTargets);
555
277
  }
556
278
 
557
279
  /**
558
- * Returns a list of CDK stack keys defined for the project. These stack
559
- * keys will be used to generate deploy tasks for each. Each key maps to a
560
- * specific CDK stack that can be deployed.
280
+ * Gets CDK stack information based on the cdk stack key.
561
281
  *
562
- * @return {Array} A list of stack keys
282
+ * @param {String} target The CDK target name
283
+ * @returns {Object} The container definition corresponding to the target.
563
284
  */
564
- getCdkStacks() {
565
- return Object.keys(this._cdkStacks);
285
+ getContainerDefinition(target) {
286
+ if (typeof target !== 'string' || target.length <= 0) {
287
+ throw new Error('Invalid container target (arg #1)');
288
+ }
289
+ const container = this._containerTargets[target];
290
+ if (!container) {
291
+ throw new Error(
292
+ `Container target has not been defined (${target})`,
293
+ );
294
+ }
295
+ return Object.assign({}, container);
566
296
  }
567
297
 
568
298
  /**
569
- * Returns the name of the stack corresponding to the stack key.
299
+ * Returns a list of project enviornment variables that are not defined in
300
+ * the current execution environment.
570
301
  *
571
- * @param {String} key The CDK stack key to use when looking up the name.
572
- * @return {String} The stack name that maps to the key.
302
+ * @return {Array} An array of missing environment variables.
573
303
  */
574
- getCdkStackName(key) {
575
- if (typeof key !== 'string' || key.length <= 0) {
576
- throw new Error('Invalid stack key (arg #1)');
577
- }
578
- return this._cdkStacks[key];
304
+ getUndefinedEnvironmentVariables() {
305
+ return this._requiredEnv.filter((env) => !process.env[env]);
579
306
  }
580
- };
307
+ }