@vamship/build-utils 1.6.1 → 2.0.0-2
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +41 -40
- package/src/directory.js +20 -24
- package/src/index.js +5 -17
- package/src/project.js +160 -433
- package/src/schema/project-definition.js +137 -0
- package/src/task-builder.js +100 -0
- package/src/task-builders/build-js-task-builder.js +57 -0
- package/src/task-builders/build-task-builder.js +78 -0
- package/src/task-builders/build-ts-task-builder.js +63 -0
- package/src/task-builders/build-ui-task-builder.js +45 -0
- package/src/task-builders/clean-task-builder.js +39 -0
- package/src/task-builders/copy-files-task-builder.js +78 -0
- package/src/task-builders/docs-js-task-builder.js +74 -0
- package/src/task-builders/docs-task-builder.js +74 -0
- package/src/task-builders/docs-ts-task-builder.js +52 -0
- package/src/task-builders/format-task-builder.js +61 -0
- package/src/task-builders/index.js +21 -17
- package/src/task-builders/lint-fix-task-builder.js +61 -0
- package/src/task-builders/lint-task-builder.js +56 -0
- package/src/task-builders/not-supported-task-builder.js +48 -0
- package/src/task-builders/package-aws-task-builder.js +105 -0
- package/src/task-builders/package-container-task-builder.js +132 -0
- package/src/task-builders/package-npm-task-builder.js +83 -0
- package/src/task-builders/package-task-builder.js +101 -0
- package/src/task-builders/publish-aws-task-builder.js +111 -0
- package/src/task-builders/publish-container-task-builder.js +103 -0
- package/src/task-builders/publish-npm-task-builder.js +60 -0
- package/src/task-builders/publish-task-builder.js +98 -0
- package/src/task-builders/test-task-builder.js +85 -0
- package/src/task-builders/test-ui-task-builder.js +65 -0
- package/src/task-builders/watch-task-builder.js +109 -0
- package/src/task-factories/api-task-factory.js +67 -0
- package/src/task-factories/aws-microservice-task-factory.js +53 -0
- package/src/task-factories/cli-task-factory.js +68 -0
- package/src/task-factories/container-task-factory.js +64 -0
- package/src/task-factories/index.js +8 -0
- package/src/task-factories/lib-task-factory.js +52 -0
- package/src/task-factories/ui-task-factory.js +48 -0
- package/src/task-factory.js +52 -0
- package/src/utils/semver-utils.js +29 -0
- package/src/utils/task-factory-utils.js +70 -0
- package/src/task-builders/build/build-js.js +0 -66
- package/src/task-builders/build/build-ts.js +0 -70
- package/src/task-builders/build/build-types.js +0 -47
- package/src/task-builders/build/build-ui.js +0 -67
- package/src/task-builders/build/index.js +0 -60
- package/src/task-builders/clean.js +0 -57
- package/src/task-builders/docs/docs-js.js +0 -41
- package/src/task-builders/docs/docs-ts.js +0 -40
- package/src/task-builders/docs/index.js +0 -32
- package/src/task-builders/format.js +0 -58
- package/src/task-builders/lint.js +0 -56
- package/src/task-builders/package/index.js +0 -50
- package/src/task-builders/package/package-aws.js +0 -58
- package/src/task-builders/package/package-docker.js +0 -128
- package/src/task-builders/package/package-npm.js +0 -25
- package/src/task-builders/package/package-types.js +0 -54
- package/src/task-builders/package/utils.js +0 -50
- package/src/task-builders/publish/index.js +0 -50
- package/src/task-builders/publish/publish-aws.js +0 -62
- package/src/task-builders/publish/publish-docker.js +0 -79
- package/src/task-builders/publish/publish-npm.js +0 -36
- package/src/task-builders/publish/publish-types.js +0 -36
- package/src/task-builders/test/index.js +0 -39
- package/src/task-builders/test/test-ui.js +0 -39
- package/src/task-builders/test/test.js +0 -67
package/src/project.js
CHANGED
@@ -1,274 +1,100 @@
|
|
1
|
-
|
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
|
-
|
4
|
-
|
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
|
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
|
21
|
-
*
|
22
|
-
* a project.
|
12
|
+
* Represents a build project that encapsulates one or more relavent build
|
13
|
+
* tasks.
|
23
14
|
*/
|
24
|
-
|
15
|
+
export class Project {
|
25
16
|
/**
|
26
|
-
*
|
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
|
-
* @
|
110
|
-
*
|
111
|
-
* properties.
|
19
|
+
* @param {Object} projectDefinition An object that contains the project
|
20
|
+
* definition.
|
112
21
|
*/
|
113
|
-
|
114
|
-
if (
|
115
|
-
|
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
|
-
|
119
|
-
|
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
|
-
`
|
34
|
+
`Schema validation failed [${instancePath
|
35
|
+
.replace(/\//g, '.')
|
36
|
+
.trim()} ${message}]`,
|
131
37
|
);
|
132
38
|
}
|
133
39
|
|
134
|
-
|
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
|
-
`
|
56
|
+
`Schema validation failed [.version is not a valid semantic version]`,
|
137
57
|
);
|
138
58
|
}
|
139
59
|
|
140
|
-
|
141
|
-
|
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.
|
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.
|
148
|
-
this.
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
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
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
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
|
-
|
298
|
-
|
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
|
-
*
|
128
|
+
* Gets the name of the project.
|
329
129
|
*
|
330
|
-
* @
|
130
|
+
* @returns {String} The project name.
|
331
131
|
*/
|
332
132
|
get name() {
|
333
133
|
return this._name;
|
334
134
|
}
|
335
135
|
|
336
136
|
/**
|
337
|
-
*
|
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
|
-
* @
|
139
|
+
* @returns {String} The project description.
|
349
140
|
*/
|
350
|
-
get
|
351
|
-
return this.
|
141
|
+
get description() {
|
142
|
+
return this._description;
|
352
143
|
}
|
353
144
|
|
354
145
|
/**
|
355
|
-
*
|
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
|
-
* @
|
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
|
-
*
|
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
|
-
* @
|
157
|
+
* @returns {String} The project name in kebab case.
|
386
158
|
*/
|
387
|
-
get
|
388
|
-
return this.
|
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
|
-
* @
|
167
|
+
* @returns {String} The expected config file name.
|
412
168
|
*/
|
413
|
-
get
|
414
|
-
return this.
|
169
|
+
get configFileName() {
|
170
|
+
return `.${_camelCase(this._unscopedName)}rc`;
|
415
171
|
}
|
416
172
|
|
417
173
|
/**
|
418
|
-
*
|
174
|
+
* Gets the version of the project.
|
419
175
|
*
|
420
|
-
* @
|
176
|
+
* @returns {String} The project version.
|
421
177
|
*/
|
422
|
-
get
|
423
|
-
return this.
|
178
|
+
get version() {
|
179
|
+
return this._version;
|
424
180
|
}
|
425
181
|
|
426
182
|
/**
|
427
|
-
*
|
183
|
+
* Gets the type of the project.
|
428
184
|
*
|
429
|
-
* @
|
185
|
+
* @returns {String} The project type.
|
430
186
|
*/
|
431
|
-
get
|
432
|
-
return this.
|
187
|
+
get type() {
|
188
|
+
return this._type;
|
433
189
|
}
|
434
190
|
|
435
191
|
/**
|
436
|
-
*
|
437
|
-
* project.
|
192
|
+
* Gets the language of the project.
|
438
193
|
*
|
439
|
-
* @
|
194
|
+
* @returns {String} The project language.
|
440
195
|
*/
|
441
|
-
get
|
442
|
-
return this.
|
196
|
+
get language() {
|
197
|
+
return this._language;
|
443
198
|
}
|
444
199
|
|
445
200
|
/**
|
446
|
-
*
|
447
|
-
* directory.
|
201
|
+
* Gets the root directory of the project.
|
448
202
|
*
|
449
|
-
* @
|
203
|
+
* @returns {Directory} The project root directory
|
450
204
|
*/
|
451
|
-
get
|
452
|
-
return this.
|
205
|
+
get rootDir() {
|
206
|
+
return this._rootDir;
|
453
207
|
}
|
454
208
|
|
455
209
|
/**
|
456
|
-
*
|
457
|
-
* image.
|
210
|
+
* Gets a colorized banner for the project.
|
458
211
|
*
|
459
|
-
* @
|
212
|
+
* @returns {String} The colorized banner text.
|
460
213
|
*/
|
461
|
-
get
|
462
|
-
return this.
|
214
|
+
get banner() {
|
215
|
+
return this._banner;
|
463
216
|
}
|
464
217
|
|
465
218
|
/**
|
466
|
-
*
|
219
|
+
* Returns a list of static file patterns configured for the project.
|
467
220
|
*
|
468
|
-
* @
|
221
|
+
* @returns {Array} An array of glob strings used to identify static files
|
222
|
+
* copied over during a build.
|
469
223
|
*/
|
470
|
-
|
471
|
-
return this.
|
224
|
+
getStaticFilePatterns() {
|
225
|
+
return this._staticFilePatterns.concat([]);
|
472
226
|
}
|
473
227
|
|
474
228
|
/**
|
475
|
-
*
|
476
|
-
*
|
229
|
+
* Returns a list of environment variables that must be defined for the
|
230
|
+
* build.
|
477
231
|
*
|
478
|
-
* @
|
232
|
+
* @returns {Array} An array of environment variable names.
|
479
233
|
*/
|
480
|
-
|
481
|
-
return this.
|
234
|
+
getRequiredEnv() {
|
235
|
+
return this._requiredEnv.concat([]);
|
482
236
|
}
|
483
237
|
|
484
238
|
/**
|
485
|
-
*
|
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 {
|
243
|
+
* @return {Array} A list of stack keys
|
488
244
|
*/
|
489
|
-
|
490
|
-
return this.
|
245
|
+
getCdkTargets() {
|
246
|
+
return Object.keys(this._cdkTargets);
|
491
247
|
}
|
492
248
|
|
493
249
|
/**
|
494
|
-
*
|
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 {
|
499
|
-
*
|
252
|
+
* @param {String} target The CDK target name
|
253
|
+
* @returns {Object} The CDK definition corresponding to the target.
|
500
254
|
*/
|
501
|
-
|
502
|
-
if (
|
503
|
-
|
255
|
+
getCdkStackDefinition(target) {
|
256
|
+
if (typeof target !== 'string' || target.length <= 0) {
|
257
|
+
throw new Error('Invalid CDK target (arg #1)');
|
504
258
|
}
|
505
|
-
|
506
|
-
|
507
|
-
|
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
|
-
|
554
|
-
return this.
|
275
|
+
getContainerTargets() {
|
276
|
+
return Object.keys(this._containerTargets);
|
555
277
|
}
|
556
278
|
|
557
279
|
/**
|
558
|
-
*
|
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
|
-
* @
|
282
|
+
* @param {String} target The CDK target name
|
283
|
+
* @returns {Object} The container definition corresponding to the target.
|
563
284
|
*/
|
564
|
-
|
565
|
-
|
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
|
299
|
+
* Returns a list of project enviornment variables that are not defined in
|
300
|
+
* the current execution environment.
|
570
301
|
*
|
571
|
-
* @
|
572
|
-
* @return {String} The stack name that maps to the key.
|
302
|
+
* @return {Array} An array of missing environment variables.
|
573
303
|
*/
|
574
|
-
|
575
|
-
|
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
|
+
}
|