@vamship/build-utils 1.5.3 → 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 -51
  2. package/src/directory.js +36 -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
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ import TaskBuilder from '../task-builder.js';
4
+ import { Project } from '../project.js';
5
+ import { execa as _execa } from 'execa';
6
+
7
+ /**
8
+ * Builder function that can be used to generate a gulp task to execute
9
+ * instrumented web UI tests.
10
+ */
11
+ export class TestUiTaskBuilder extends TaskBuilder {
12
+ /**
13
+ * Creates a new task builder.
14
+ */
15
+ constructor() {
16
+ super('test-ui', `Execute web UI tests`);
17
+ }
18
+
19
+ /**
20
+ * Generates a gulp task to execute automated tests
21
+ *
22
+ * @protected
23
+ * @param {Object} project Reference to the project for which the task needs
24
+ * to be defined.
25
+ *
26
+ * @returns {Function} A gulp task.
27
+ */
28
+ _createTask(project) {
29
+ if (!(project instanceof Project)) {
30
+ throw new Error('Invalid project (arg #1)');
31
+ }
32
+ const jestBin = project.rootDir.getFilePath('node_modules/.bin/jest');
33
+ const task = () =>
34
+ _execa(jestBin, ['--config', 'jest.config.js', '--coverage'], {
35
+ stdio: 'inherit',
36
+ }).then(undefined, (err) => {
37
+ /*
38
+ * Do nothing. This handler prevents the gulp task from
39
+ * crashing with an unhandled error.
40
+ */
41
+ });
42
+ return task;
43
+ }
44
+
45
+ /**
46
+ * @override
47
+ */
48
+ getWatchPaths(project) {
49
+ if (!(project instanceof Project)) {
50
+ throw new Error('Invalid project (arg #1)');
51
+ }
52
+ const dirs = ['src', 'test', 'infra'];
53
+ const exts = ['md', 'html', 'json', 'js', 'jsx', 'ts', 'tsx'];
54
+ const rootDir =
55
+ project.language === 'ts'
56
+ ? project.rootDir.getChild('working')
57
+ : project.rootDir;
58
+
59
+ return dirs
60
+ .map((dir) =>
61
+ exts.map((ext) => rootDir.getChild(dir).getAllFilesGlob(ext)),
62
+ )
63
+ .flat();
64
+ }
65
+ }
@@ -0,0 +1,109 @@
1
+ import TaskBuilder from '../task-builder.js';
2
+ import { Project } from '../project.js';
3
+ import _gulp from 'gulp';
4
+ import _fancyLog from 'fancy-log';
5
+ import _colors from 'ansi-colors';
6
+
7
+ /**
8
+ * Builder that adds a watcher to an existing task.
9
+ */
10
+ export class WatchTaskBuilder extends TaskBuilder {
11
+ /**
12
+ * Creates a new task builder.
13
+ *
14
+ * @param {Function} task Reference to the task that needs to be watched.
15
+ * @param {Array} paths An array of paths to monitor for changes and trigger
16
+ * the task on change.
17
+ */
18
+ constructor(task, paths) {
19
+ if (typeof task !== 'function') {
20
+ throw new Error('Invalid task (arg #1)');
21
+ }
22
+ if (!(paths instanceof Array)) {
23
+ throw new Error('Invalid paths (arg #2)');
24
+ }
25
+ super(
26
+ `watch-${task.displayName}`,
27
+ `[Monitor and execute] ${task.description}`,
28
+ );
29
+
30
+ this._task = task;
31
+ this._paths = paths.concat([]);
32
+ }
33
+
34
+ /**
35
+ * Generates a gulp task to clean up temporary project files.
36
+ *
37
+ * @protected
38
+ * @param {Object} project Reference to the project for which the task needs
39
+ * to be defined.
40
+ *
41
+ * @returns {Function} A gulp task.
42
+ */
43
+ _createTask(project) {
44
+ if (!(project instanceof Project)) {
45
+ throw new Error('Invalid project (arg #1)');
46
+ }
47
+ const taskRunner = (done) => {
48
+ const result = this._task();
49
+ if (!result) {
50
+ _fancyLog(
51
+ 'Task returned no result. Skipping. Will rerun on next change.',
52
+ );
53
+ done();
54
+ } else if (result.then) {
55
+ return result.then(
56
+ () => {
57
+ _fancyLog(
58
+ 'Task was resolved successfully. Will rerun on next change.',
59
+ );
60
+ done();
61
+ },
62
+ (err) => {
63
+ _fancyLog(
64
+ 'Task was rejected with errors. Will rerun on next change.',
65
+ );
66
+ done();
67
+ },
68
+ );
69
+ } else if (result.on) {
70
+ return result
71
+ .on('error', (err) => {
72
+ _fancyLog(
73
+ 'Task stream reported errors. Will rerun on next change.',
74
+ );
75
+ done();
76
+ })
77
+ .on('end', () => {
78
+ _fancyLog(
79
+ 'Task stream completed successfully. Will rerun on next change.',
80
+ );
81
+ done();
82
+ });
83
+ } else {
84
+ _fancyLog(
85
+ 'Task is neither promise nor stream. Skipping. Will rerun on next change.',
86
+ );
87
+ done();
88
+ }
89
+ };
90
+ taskRunner.description = this._task.description;
91
+ const taskName = _colors.cyan(this._task.displayName);
92
+ const task = _gulp.series(
93
+ async () => _fancyLog(`Running task ${taskName}`),
94
+ taskRunner,
95
+ async () => _fancyLog('Task completed'),
96
+ );
97
+ return () => _gulp.watch(this._paths, task);
98
+ }
99
+
100
+ /**
101
+ * @override
102
+ */
103
+ getWatchPaths(project) {
104
+ if (!(project instanceof Project)) {
105
+ throw new Error('Invalid project (arg #1)');
106
+ }
107
+ return [];
108
+ }
109
+ }
@@ -0,0 +1,67 @@
1
+ import TaskFactory from '../task-factory.js';
2
+
3
+ import { CleanTaskBuilder } from '../task-builders/clean-task-builder.js';
4
+ import { FormatTaskBuilder } from '../task-builders/format-task-builder.js';
5
+ import { LintTaskBuilder } from '../task-builders/lint-task-builder.js';
6
+ import { LintFixTaskBuilder } from '../task-builders/lint-fix-task-builder.js';
7
+ import { BuildTaskBuilder } from '../task-builders/build-task-builder.js';
8
+ import { PackageTaskBuilder } from '../task-builders/package-task-builder.js';
9
+ import { PublishTaskBuilder } from '../task-builders/publish-task-builder.js';
10
+ import { DocsTaskBuilder } from '../task-builders/docs-task-builder.js';
11
+ import { PackageContainerTaskBuilder } from '../task-builders/package-container-task-builder.js';
12
+ import { PublishContainerTaskBuilder } from '../task-builders/publish-container-task-builder.js';
13
+ import { generateAdditionalContainerTasks } from '../utils/task-factory-utils.js';
14
+ import { TestTaskBuilder } from '../task-builders/test-task-builder.js';
15
+
16
+ /**
17
+ * Represents a factory that generates a set of build tasks for an api type project
18
+ */
19
+ export class ApiTaskFactory extends TaskFactory {
20
+ /**
21
+ * Creates a new instance of TaskFactory, initialized for a given project.
22
+ * @param {Project} project The project to generate build tasks for.
23
+ */
24
+ constructor(project) {
25
+ super(project);
26
+ }
27
+
28
+ /**
29
+ * Protected abstract method that can be overridden to provide the
30
+ * necessary tasks for a given project type.
31
+ *
32
+ * @returns {Array} An array of task builders.
33
+ */
34
+ _createTaskBuilders() {
35
+ const { type } = this._project;
36
+ if (type !== 'api') {
37
+ return [];
38
+ }
39
+
40
+ // Helper function to generate the set of tasks for each additional container
41
+ // if needed
42
+ const additionalTaskList = (target) => {
43
+ return [
44
+ new PackageContainerTaskBuilder(target),
45
+ new PublishContainerTaskBuilder(target),
46
+ ];
47
+ };
48
+ const additionalTasks = generateAdditionalContainerTasks(
49
+ this._project,
50
+ additionalTaskList,
51
+ );
52
+
53
+ return [
54
+ new CleanTaskBuilder(),
55
+ new FormatTaskBuilder(),
56
+ new LintTaskBuilder(),
57
+ new LintFixTaskBuilder(),
58
+ new TestTaskBuilder('unit'),
59
+ new TestTaskBuilder('api'),
60
+
61
+ new DocsTaskBuilder(this._project),
62
+ new BuildTaskBuilder(this._project),
63
+ new PackageTaskBuilder(this._project),
64
+ new PublishTaskBuilder(this._project),
65
+ ].concat(additionalTasks);
66
+ }
67
+ }
@@ -0,0 +1,53 @@
1
+ import TaskFactory from '../task-factory.js';
2
+
3
+ import { CleanTaskBuilder } from '../task-builders/clean-task-builder.js';
4
+ import { FormatTaskBuilder } from '../task-builders/format-task-builder.js';
5
+ import { LintTaskBuilder } from '../task-builders/lint-task-builder.js';
6
+ import { LintFixTaskBuilder } from '../task-builders/lint-fix-task-builder.js';
7
+ import { BuildTaskBuilder } from '../task-builders/build-task-builder.js';
8
+ import { PackageTaskBuilder } from '../task-builders/package-task-builder.js';
9
+ import { PublishTaskBuilder } from '../task-builders/publish-task-builder.js';
10
+ import { DocsTaskBuilder } from '../task-builders/docs-task-builder.js';
11
+ import { TestTaskBuilder } from '../task-builders/test-task-builder.js';
12
+
13
+ /**
14
+ * Represents a factory that generates a set of build tasks for a given project
15
+ * type. This is an abstract class that must be extended to provide a list of
16
+ * task builders for a given project type.
17
+ */
18
+ export class AwsMicroserviceTaskFactory extends TaskFactory {
19
+ /**
20
+ * Creates a new instance of TaskFactory, initialized for a given project.
21
+ * @param {Project} project The project to generate build tasks for.
22
+ */
23
+ constructor(project) {
24
+ super(project);
25
+ }
26
+
27
+ /**
28
+ * Protected abstract method that can be overridden to provide the
29
+ * necessary tasks for a given project type.
30
+ *
31
+ * @returns {Array} An array of task builders.
32
+ */
33
+ _createTaskBuilders() {
34
+ const { type } = this._project;
35
+ if (type !== 'aws-microservice') {
36
+ return [];
37
+ }
38
+
39
+ return [
40
+ new CleanTaskBuilder(),
41
+ new FormatTaskBuilder(),
42
+ new LintTaskBuilder(),
43
+ new LintFixTaskBuilder(),
44
+ new TestTaskBuilder('unit'),
45
+ new TestTaskBuilder('api'),
46
+
47
+ new DocsTaskBuilder(this._project),
48
+ new BuildTaskBuilder(this._project),
49
+ new PackageTaskBuilder(this._project),
50
+ new PublishTaskBuilder(this._project),
51
+ ];
52
+ }
53
+ }
@@ -0,0 +1,68 @@
1
+ import TaskFactory from '../task-factory.js';
2
+
3
+ import { CleanTaskBuilder } from '../task-builders/clean-task-builder.js';
4
+ import { FormatTaskBuilder } from '../task-builders/format-task-builder.js';
5
+ import { LintTaskBuilder } from '../task-builders/lint-task-builder.js';
6
+ import { LintFixTaskBuilder } from '../task-builders/lint-fix-task-builder.js';
7
+ import { BuildTaskBuilder } from '../task-builders/build-task-builder.js';
8
+ import { PackageTaskBuilder } from '../task-builders/package-task-builder.js';
9
+ import { PublishTaskBuilder } from '../task-builders/publish-task-builder.js';
10
+ import { DocsTaskBuilder } from '../task-builders/docs-task-builder.js';
11
+ import { PackageContainerTaskBuilder } from '../task-builders/package-container-task-builder.js';
12
+ import { PublishContainerTaskBuilder } from '../task-builders/publish-container-task-builder.js';
13
+ import { generateAdditionalContainerTasks } from '../utils/task-factory-utils.js';
14
+ import { TestTaskBuilder } from '../task-builders/test-task-builder.js';
15
+
16
+ /**
17
+ * Represents a factory that generates a set of build tasks for a given project
18
+ * type. This is an abstract class that must be extended to provide a list of
19
+ * task builders for a given project type.
20
+ */
21
+ export class CliTaskFactory extends TaskFactory {
22
+ /**
23
+ * Creates a new instance of TaskFactory, initialized for a given project.
24
+ * @param {Project} project The project to generate build tasks for.
25
+ */
26
+ constructor(project) {
27
+ super(project);
28
+ }
29
+
30
+ /**
31
+ * Protected abstract method that can be overridden to provide the
32
+ * necessary tasks for a given project type.
33
+ *
34
+ * @returns {Array} An array of task builders.
35
+ */
36
+ _createTaskBuilders() {
37
+ const { type } = this._project;
38
+ if (type !== 'cli') {
39
+ return [];
40
+ }
41
+
42
+ // Helper function to generate the set of tasks for each additional container
43
+ // if needed
44
+ const additionalTaskList = (target) => {
45
+ return [
46
+ new PackageContainerTaskBuilder(target),
47
+ new PublishContainerTaskBuilder(target),
48
+ ];
49
+ };
50
+ const additionalTasks = generateAdditionalContainerTasks(
51
+ this._project,
52
+ additionalTaskList,
53
+ );
54
+
55
+ return [
56
+ new CleanTaskBuilder(),
57
+ new FormatTaskBuilder(),
58
+ new LintTaskBuilder(),
59
+ new LintFixTaskBuilder(),
60
+ new TestTaskBuilder('unit'),
61
+
62
+ new DocsTaskBuilder(this._project),
63
+ new BuildTaskBuilder(this._project),
64
+ new PackageTaskBuilder(this._project),
65
+ new PublishTaskBuilder(this._project),
66
+ ].concat(additionalTasks);
67
+ }
68
+ }
@@ -0,0 +1,64 @@
1
+ import TaskFactory from '../task-factory.js';
2
+
3
+ import { CleanTaskBuilder } from '../task-builders/clean-task-builder.js';
4
+ import { FormatTaskBuilder } from '../task-builders/format-task-builder.js';
5
+ import { LintTaskBuilder } from '../task-builders/lint-task-builder.js';
6
+ import { LintFixTaskBuilder } from '../task-builders/lint-fix-task-builder.js';
7
+ import { PackageTaskBuilder } from '../task-builders/package-task-builder.js';
8
+ import { PublishTaskBuilder } from '../task-builders/publish-task-builder.js';
9
+ import { DocsTaskBuilder } from '../task-builders/docs-task-builder.js';
10
+ import { PackageContainerTaskBuilder } from '../task-builders/package-container-task-builder.js';
11
+ import { PublishContainerTaskBuilder } from '../task-builders/publish-container-task-builder.js';
12
+ import { generateAdditionalContainerTasks } from '../utils/task-factory-utils.js';
13
+
14
+ /**
15
+ * Represents a factory that generates a set of build tasks for a given project
16
+ * type. This is an abstract class that must be extended to provide a list of
17
+ * task builders for a given project type.
18
+ */
19
+ export class ContainerTaskFactory extends TaskFactory {
20
+ /**
21
+ * Creates a new instance of TaskFactory, initialized for a given project.
22
+ * @param {Project} project The project to generate build tasks for.
23
+ */
24
+ constructor(project) {
25
+ super(project);
26
+ }
27
+
28
+ /**
29
+ * Protected abstract method that can be overridden to provide the
30
+ * necessary tasks for a given project type.
31
+ *
32
+ * @returns {Array} An array of task builders.
33
+ */
34
+ _createTaskBuilders() {
35
+ const { type } = this._project;
36
+ if (type !== 'container') {
37
+ return [];
38
+ }
39
+
40
+ // Helper function to generate the set of tasks for each additional container
41
+ // if needed
42
+ const additionalTaskList = (target) => {
43
+ return [
44
+ new PackageContainerTaskBuilder(target),
45
+ new PublishContainerTaskBuilder(target),
46
+ ];
47
+ };
48
+ const additionalTasks = generateAdditionalContainerTasks(
49
+ this._project,
50
+ additionalTaskList,
51
+ );
52
+
53
+ return [
54
+ new CleanTaskBuilder(),
55
+ new FormatTaskBuilder(),
56
+ new LintTaskBuilder(),
57
+ new LintFixTaskBuilder(),
58
+
59
+ new DocsTaskBuilder(this._project),
60
+ new PackageTaskBuilder(this._project),
61
+ new PublishTaskBuilder(this._project),
62
+ ].concat(additionalTasks);
63
+ }
64
+ }
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ export * from './lib-task-factory.js';
4
+ export * from './api-task-factory.js';
5
+ export * from './cli-task-factory.js';
6
+ export * from './ui-task-factory.js';
7
+ export * from './container-task-factory.js';
8
+ export * from './aws-microservice-task-factory.js';
@@ -0,0 +1,52 @@
1
+ import TaskFactory from '../task-factory.js';
2
+
3
+ import { CleanTaskBuilder } from '../task-builders/clean-task-builder.js';
4
+ import { FormatTaskBuilder } from '../task-builders/format-task-builder.js';
5
+ import { LintTaskBuilder } from '../task-builders/lint-task-builder.js';
6
+ import { LintFixTaskBuilder } from '../task-builders/lint-fix-task-builder.js';
7
+ import { TestTaskBuilder } from '../task-builders/test-task-builder.js';
8
+ import { BuildTaskBuilder } from '../task-builders/build-task-builder.js';
9
+ import { PackageTaskBuilder } from '../task-builders/package-task-builder.js';
10
+ import { PublishTaskBuilder } from '../task-builders/publish-task-builder.js';
11
+ import { DocsTaskBuilder } from '../task-builders/docs-task-builder.js';
12
+
13
+ /**
14
+ * Represents a factory that generates a set of build tasks for a given project
15
+ * type. This is an abstract class that must be extended to provide a list of
16
+ * task builders for a given project type.
17
+ */
18
+ export class LibTaskFactory extends TaskFactory {
19
+ /**
20
+ * Creates a new instance of TaskFactory, initialized for a given project.
21
+ * @param {Project} project The project to generate build tasks for.
22
+ */
23
+ constructor(project) {
24
+ super(project);
25
+ }
26
+
27
+ /**
28
+ * Protected abstract method that can be overridden to provide the
29
+ * necessary tasks for a given project type.
30
+ *
31
+ * @returns {Array} An array of task builders.
32
+ */
33
+ _createTaskBuilders() {
34
+ const { type } = this._project;
35
+ if (type !== 'lib') {
36
+ return [];
37
+ }
38
+
39
+ return [
40
+ new CleanTaskBuilder(),
41
+ new FormatTaskBuilder(),
42
+ new LintTaskBuilder(),
43
+ new LintFixTaskBuilder(),
44
+ new TestTaskBuilder('unit'),
45
+
46
+ new DocsTaskBuilder(this._project),
47
+ new BuildTaskBuilder(this._project),
48
+ new PackageTaskBuilder(this._project),
49
+ new PublishTaskBuilder(this._project),
50
+ ];
51
+ }
52
+ }
@@ -0,0 +1,48 @@
1
+ import TaskFactory from '../task-factory.js';
2
+
3
+ import { CleanTaskBuilder } from '../task-builders/clean-task-builder.js';
4
+ import { FormatTaskBuilder } from '../task-builders/format-task-builder.js';
5
+ import { LintTaskBuilder } from '../task-builders/lint-task-builder.js';
6
+ import { LintFixTaskBuilder } from '../task-builders/lint-fix-task-builder.js';
7
+ import { BuildTaskBuilder } from '../task-builders/build-task-builder.js';
8
+ import { DocsTaskBuilder } from '../task-builders/docs-task-builder.js';
9
+ import { TestUiTaskBuilder } from '../task-builders/test-ui-task-builder.js';
10
+
11
+ /**
12
+ * Represents a factory that generates a set of build tasks for a given project
13
+ * type. This is an abstract class that must be extended to provide a list of
14
+ * task builders for a given project type.
15
+ */
16
+ export class UiTaskFactory extends TaskFactory {
17
+ /**
18
+ * Creates a new instance of TaskFactory, initialized for a given project.
19
+ * @param {Project} project The project to generate build tasks for.
20
+ */
21
+ constructor(project) {
22
+ super(project);
23
+ }
24
+
25
+ /**
26
+ * Protected abstract method that can be overridden to provide the
27
+ * necessary tasks for a given project type.
28
+ *
29
+ * @returns {Array} An array of task builders.
30
+ */
31
+ _createTaskBuilders() {
32
+ const { type } = this._project;
33
+ if (type !== 'ui') {
34
+ return [];
35
+ }
36
+
37
+ return [
38
+ new CleanTaskBuilder(),
39
+ new FormatTaskBuilder(),
40
+ new LintTaskBuilder(),
41
+ new LintFixTaskBuilder(),
42
+ new TestUiTaskBuilder(),
43
+
44
+ new DocsTaskBuilder(this._project),
45
+ new BuildTaskBuilder(this._project),
46
+ ];
47
+ }
48
+ }
@@ -0,0 +1,52 @@
1
+ import { Project } from './project.js';
2
+ import { WatchTaskBuilder } from './task-builders/watch-task-builder.js';
3
+
4
+ /**
5
+ * Represents a factory that generates a set of build tasks for a given project
6
+ * type. This is an abstract class that must be extended to provide a list of
7
+ * task builders for a given project type.
8
+ */
9
+ export default class TaskFactory {
10
+ /**
11
+ * Creates a new instance of TaskFactory, initialized for a given project.
12
+ * @param {Project} project The project to generate build tasks for.
13
+ */
14
+ constructor(project) {
15
+ if (!(project instanceof Project)) {
16
+ throw new Error('Invalid project (arg #1)');
17
+ }
18
+ this._project = project;
19
+ }
20
+
21
+ /**
22
+ * Protected abstract method that can be overridden to provide the
23
+ * necessary tasks for a given project type.
24
+ *
25
+ * @returns {Array} An array of task builders.
26
+ */
27
+ _createTaskBuilders() {
28
+ return [];
29
+ }
30
+
31
+ /**
32
+ * Creates a set of build tasks for the project.
33
+ *
34
+ * @returns {Array} An array of gulp tasks.
35
+ */
36
+ createTasks() {
37
+ const project = this._project;
38
+ const builders = this._createTaskBuilders();
39
+ const watchBuilders = builders
40
+ .filter((builder) => builder.getWatchPaths(project).length > 0)
41
+ .map(
42
+ (builder) =>
43
+ new WatchTaskBuilder(
44
+ builder.buildTask(project),
45
+ builder.getWatchPaths(project),
46
+ ),
47
+ );
48
+ return builders
49
+ .concat(watchBuilders)
50
+ .map((builder) => builder.buildTask(project));
51
+ }
52
+ }
@@ -0,0 +1,29 @@
1
+ import semver from 'semver';
2
+
3
+ /**
4
+ * Checks if a given input tag is a valid semantic version, and returns an array
5
+ * of the four corresponding tags (ex. tag = '1.2.3' => ['1.2.3', '1.2', '1', 'latest']).
6
+ * If tag = '1.2' => ['1.2.0', '1.2', '1', 'latest'].
7
+ * If tag = '1' => ['1.0.0', '1.0', '1', 'latest'].
8
+ * If the tag is not a semantic version, such as 'latest' simply returns ['latest']
9
+ *
10
+ * @param {String} tag String input for tag name of docker image
11
+ * @returns {Array} Array of tag strings
12
+ */
13
+ export function getSemverComponents(tag) {
14
+ const semTag = semver.coerce(tag);
15
+ if (!semver.valid(semTag)) {
16
+ return [tag];
17
+ }
18
+
19
+ const major = semver.major(semTag);
20
+ const minor = semver.minor(semTag);
21
+ const patch = semver.patch(semTag);
22
+
23
+ return [
24
+ `${major}.${minor}.${patch}`,
25
+ `${major}.${minor}`,
26
+ `${major}`,
27
+ 'latest',
28
+ ];
29
+ }