@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
@@ -0,0 +1,70 @@
1
+ import { Project } from '../project.js';
2
+ import { LibTaskFactory } from '../task-factories/lib-task-factory.js';
3
+ import { ApiTaskFactory } from '../task-factories/api-task-factory.js';
4
+ import { CliTaskFactory } from '../task-factories/cli-task-factory.js';
5
+ import { AwsMicroserviceTaskFactory } from '../task-factories/aws-microservice-task-factory.js';
6
+ import { UiTaskFactory } from '../task-factories/ui-task-factory.js';
7
+ import { ContainerTaskFactory } from '../task-factories/container-task-factory.js';
8
+
9
+ /**
10
+ * For a project that has multiple containers defined, this function will return
11
+ * the additional tasks for each container. These tasks may be called by name
12
+ * following the naming convention package-container-${targetContainerName} and
13
+ * publish-container-${targetContainerName} for example.
14
+ *
15
+ * @param {Project} project The project for which to generate additional package
16
+ * and publish tasks.
17
+ * @param {Function} additionalTaskList A function that returns the set of task
18
+ * builders to be generated for each container. Takes container target as input.
19
+ * @returns {Array} An array of tasks, empty if no extra containers are defined
20
+ */
21
+ export function generateAdditionalContainerTasks(project, additionalTaskList) {
22
+ if (!(project instanceof Project)) {
23
+ throw new Error('Invalid project (arg #1)');
24
+ }
25
+
26
+ if (typeof additionalTaskList !== 'function') {
27
+ throw new Error('Invalid additionalTaskList (arg #2)');
28
+ }
29
+
30
+ const tasks = [];
31
+ const containerTargets = project.getContainerTargets();
32
+
33
+ // > 1 since default container
34
+ if (containerTargets.length > 1) {
35
+ containerTargets
36
+ .filter((target) => target !== 'default')
37
+ .forEach((target) => {
38
+ tasks.push(...additionalTaskList(target));
39
+ });
40
+ }
41
+
42
+ return tasks;
43
+ }
44
+
45
+ /**
46
+ * Initializes a task factory for a given project type.
47
+ *
48
+ * @param {Project} project The project to generate build tasks for.
49
+ * @returns {TaskFactory} A task factory for the given project type.
50
+ */
51
+ export function getTaskFactory(project) {
52
+ if (!(project instanceof Project)) {
53
+ throw new Error('Invalid project (arg #1)');
54
+ }
55
+ if (project.type === 'lib') {
56
+ return new LibTaskFactory(project);
57
+ } else if (project.type === 'api') {
58
+ return new ApiTaskFactory(project);
59
+ } else if (project.type === 'cli') {
60
+ return new CliTaskFactory(project);
61
+ } else if (project.type === 'ui') {
62
+ return new UiTaskFactory(project);
63
+ } else if (project.type === 'aws-microservice') {
64
+ return new AwsMicroserviceTaskFactory(project);
65
+ } else if (project.type === 'container') {
66
+ return new ContainerTaskFactory(project);
67
+ } else {
68
+ throw new Error(`Unrecognized project type (value=${project.type})`);
69
+ }
70
+ }
@@ -1,66 +0,0 @@
1
- 'use strict';
2
-
3
- const _gulp = require('gulp');
4
-
5
- /**
6
- * Sub builder that creates a task that will copy javascript files from source
7
- * to build directories. This method will return a watcher if the watch option
8
- * is set to true.
9
- *
10
- * @private
11
- * @param {Object} project Reference to an object that contains project metadata
12
- * that can be used to customize build outputs.
13
- * @param {Object} options An options object that can be used to customize the
14
- * task.
15
- *
16
- * @returns {Function} A gulp task.
17
- */
18
- module.exports = (project, options) => {
19
- const { watch } = Object.assign({ watch: false }, options);
20
- const rootDir = project.rootDir;
21
- const workingDir = rootDir.getChild('working');
22
-
23
- const dirs = ['src', 'test'];
24
- if (project.projectType === 'aws-microservice') {
25
- dirs.push('infra');
26
- }
27
-
28
- const extras = [
29
- project.configFileName,
30
- 'package.json',
31
- '.npmignore',
32
- '.npmrc',
33
- ];
34
-
35
- if (project.hasDocker) {
36
- extras.push('Dockerfile*');
37
- }
38
-
39
- const staticFilePatterns = ['js', 'json'].concat(
40
- project.staticFilePatterns
41
- );
42
-
43
- const paths = dirs
44
- .map((dir) => rootDir.getChild(dir))
45
- .map((dir) => staticFilePatterns.map((ext) => dir.getAllFilesGlob(ext)))
46
- .reduce((result, arr) => result.concat(arr), [])
47
- .concat(extras.map((item) => rootDir.getFileGlob(item)));
48
-
49
- const task = () =>
50
- _gulp
51
- .src(paths, { allowEmpty: true, base: rootDir.globPath })
52
- .pipe(_gulp.dest(workingDir.absolutePath));
53
-
54
- task.displayName = 'build-js';
55
- task.description = 'Copy javascript files from source to build directory';
56
-
57
- if (watch) {
58
- const watchTask = () => _gulp.watch(paths, task);
59
- watchTask.displayName = 'watch-build-js';
60
- watchTask.description =
61
- 'Automatically copy javascript files to build directory on change';
62
-
63
- return watchTask;
64
- }
65
- return task;
66
- };
@@ -1,70 +0,0 @@
1
- 'use strict';
2
-
3
- const _gulp = require('gulp');
4
- const _typescript = require('gulp-typescript');
5
-
6
- /**
7
- * Sub builder that creates a task that will transpile typescript files into
8
- * javascript files. This method will return a watcher if the watch option
9
- * is set to true.
10
- *
11
- * @private
12
- * @param {Object} project Reference to an object that contains project metadata
13
- * that can be used to customize build outputs.
14
- * @param {Object} options An options object that can be used to customize the
15
- * task.
16
- *
17
- * @returns {Function} A gulp task.
18
- */
19
- module.exports = (project, options) => {
20
- const { watch } = Object.assign({ watch: false }, options);
21
- const rootDir = project.rootDir;
22
- const workingDir = rootDir.getChild('working');
23
-
24
- const dirs = ['src', 'test'];
25
- if (project.projectType === 'aws-microservice') {
26
- dirs.push('infra');
27
- }
28
-
29
- const tsProject = _typescript.createProject('tsconfig.json');
30
-
31
- const paths = dirs
32
- .map((dir) => rootDir.getChild(dir))
33
- .map((dir) => ['ts'].map((ext) => dir.getAllFilesGlob(ext)))
34
- .reduce((result, arr) => result.concat(arr), []);
35
-
36
- const distFiles = [
37
- rootDir.getFileGlob('package-lock.json'),
38
- rootDir.getFileGlob('Dockerfile*'),
39
- rootDir.getFileGlob('LICENSE'),
40
- rootDir.getFileGlob('README.md'),
41
- rootDir.getFileGlob('.env'),
42
- rootDir.getFileGlob(project.configFileName),
43
- ];
44
-
45
- const buildTask = () =>
46
- _gulp
47
- .src(paths, { base: rootDir.globPath })
48
- .pipe(tsProject())
49
- .pipe(_gulp.dest(workingDir.absolutePath));
50
-
51
- const copyTask = () =>
52
- _gulp
53
- .src(distFiles, { allowEmpty: true })
54
- .pipe(_gulp.dest(workingDir.absolutePath));
55
-
56
- const task = _gulp.parallel([copyTask, buildTask]);
57
-
58
- task.displayName = 'build-ts';
59
- task.description = 'Build typescript source files to javascript files';
60
-
61
- if (watch) {
62
- const watchTask = () => _gulp.watch(paths, task);
63
- watchTask.displayName = 'watch-build-ts';
64
- watchTask.description =
65
- 'Automatically build typescript files on change';
66
-
67
- return watchTask;
68
- }
69
- return task;
70
- };
@@ -1,47 +0,0 @@
1
- 'use strict';
2
-
3
- const _gulp = require('gulp');
4
-
5
- /**
6
- * Sub builder that creates a task that will copy type declaration files that
7
- * have been marked for export from source to build directories. This method
8
- * will return a watcher if the watch option is set to true.
9
- *
10
- * @private
11
- * @param {Object} project Reference to an object that contains project metadata
12
- * that can be used to customize build outputs.
13
- * @param {Object} options An options object that can be used to customize the
14
- * task.
15
- *
16
- * @returns {Function} A gulp task.
17
- */
18
- module.exports = (project, options) => {
19
- const { watch } = Object.assign({ watch: false }, options);
20
- const rootDir = project.rootDir;
21
- const workingDir = rootDir.getChild('working');
22
-
23
- const paths = [project.exportedTypes]
24
- .map((dir) => rootDir.getChild(dir))
25
- .map((dir) => [undefined].map((ext) => dir.getAllFilesGlob(ext)))
26
- .reduce((result, arr) => result.concat(arr), []);
27
- console.log('building types');
28
-
29
- const task = () =>
30
- _gulp
31
- .src(paths, { allowEmpty: true, base: rootDir.globPath })
32
- .pipe(_gulp.dest(workingDir.absolutePath));
33
-
34
- task.displayName = 'build-types';
35
- task.description =
36
- 'Copy type declaration files from source to build directory';
37
-
38
- if (watch) {
39
- const watchTask = () => _gulp.watch(paths, task);
40
- watchTask.displayName = 'watch-build-types';
41
- watchTask.description =
42
- 'Automatically copy type declaration files to build directory on change';
43
-
44
- return watchTask;
45
- }
46
- return task;
47
- };
@@ -1,67 +0,0 @@
1
- 'use strict';
2
-
3
- const _gulp = require('gulp');
4
- const _typescript = require('gulp-typescript');
5
- const _execa = require('execa');
6
-
7
- /**
8
- * Sub builder that creates a task that will build UI project
9
- * using vite. This method will return a watcher if the watch option
10
- * is set to true.
11
- *
12
- * @private
13
- * @param {Object} project Reference to an object that contains project metadata
14
- * that can be used to customize build outputs.
15
- * @param {Object} options An options object that can be used to customize the
16
- * task.
17
- *
18
- * @returns {Function} A gulp task.
19
- */
20
- module.exports = (project, options) => {
21
- const { watch } = Object.assign({ watch: false }, options);
22
- const rootDir = project.rootDir;
23
- const workingDir = rootDir.getChild('working');
24
-
25
- const viteBin = project.rootDir.getFilePath('node_modules/.bin/vite');
26
-
27
- const dirs = ['src', 'test'];
28
-
29
- const distFiles = [
30
- rootDir.getFileGlob('_scripts/*'),
31
- rootDir.getFileGlob('nginx.conf'),
32
- rootDir.getFileGlob('package-lock.json'),
33
- rootDir.getFileGlob('Dockerfile*'),
34
- rootDir.getFileGlob('LICENSE'),
35
- rootDir.getFileGlob('README.md'),
36
- rootDir.getFileGlob('.env'),
37
- rootDir.getFileGlob(project.configFileName),
38
- ];
39
- const copyTask = () =>
40
- _gulp
41
- .src(distFiles, { allowEmpty: true })
42
- .pipe(_gulp.dest(workingDir.absolutePath));
43
-
44
- const args = ['build'];
45
- const buildTask = () => _execa(viteBin, args, { stdio: 'inherit' });
46
- buildTask.displayName = 'build-ui';
47
- buildTask.description = 'Build the UI project';
48
-
49
- const task = _gulp.series([buildTask, copyTask]);
50
-
51
- if (watch) {
52
- const paths = dirs
53
- .map((dir) => rootDir.getChild(dir))
54
- .map((dir) => ['ts', 'tsx'].map((ext) => dir.getAllFilesGlob(ext)))
55
- .reduce((result, arr) => result.concat(arr), []);
56
-
57
- args.push('--watch');
58
- const buildTask = () => _execa(viteBin, args, { stdio: 'inherit' });
59
- const task = _gulp.series([buildTask, copyTask]);
60
- const watchTask = () => _gulp.watch(paths, task);
61
- watchTask.displayName = 'watch-build-ui';
62
- watchTask.description = 'Automatically build the UI project on change';
63
- return watchTask;
64
- }
65
-
66
- return task;
67
- };
@@ -1,60 +0,0 @@
1
- 'use strict';
2
-
3
- const _gulp = require('gulp');
4
-
5
- /**
6
- * Builder function that can be used to generate a gulp task to build source
7
- * files. The task takes on different implementations based on project types.
8
- * For example, this task will compile typescript projects, copy AWS
9
- * microservice projects to the target directory, and has no effect on other
10
- * pure javascript projects.
11
- *
12
- * @param {Object} project Reference to an object that contains project metadata
13
- * that can be used to customize build outputs.
14
- * @param {Object} options An options object that can be used to customize the
15
- * task.
16
- *
17
- * @returns {Function} A gulp task.
18
- */
19
- module.exports = (project, options) => {
20
- const { watch } = Object.assign({ watch: false }, options);
21
-
22
- if (
23
- !project.hasExportedTypes &&
24
- !project.hasTypescript &&
25
- project.projectType !== 'aws-microservice'
26
- ) {
27
- return;
28
- }
29
-
30
- let task;
31
- let tasks;
32
-
33
- if (project.projectType !== 'ui') {
34
- const jsBuild = require('./build-js');
35
- tasks = [jsBuild(project, options)];
36
-
37
- if (project.hasTypescript) {
38
- const tsBuild = require('./build-ts');
39
- tasks.push(tsBuild(project, options));
40
- } else if (project.hasExportedTypes) {
41
- const typesBuild = require('./build-types');
42
- tasks.push(typesBuild(project, options));
43
- }
44
- } else {
45
- const tsBuild = require('./build-ui');
46
- tasks = [tsBuild(project, options)];
47
- }
48
-
49
- task = _gulp.parallel(tasks);
50
- if (!watch) {
51
- task.displayName = 'build';
52
- task.description = 'Transpile/copy source files into working directory';
53
- } else {
54
- task.displayName = 'watch-build';
55
- task.description =
56
- 'Automatically transpile/copy source files on change';
57
- }
58
-
59
- return task;
60
- };
@@ -1,57 +0,0 @@
1
- 'use strict';
2
-
3
- const _delete = require('delete');
4
-
5
- /**
6
- * Builder function that can be used to generate a gulp task to clean temporary
7
- * project files.
8
- *
9
- * @param {Object} project Reference to an object that contains project metadata
10
- * that can be used to customize build outputs.
11
- * @param {Object} options An options object that can be used to customize the
12
- * task.
13
- *
14
- * @returns {Function} A gulp task.
15
- */
16
- module.exports = (project, options) => {
17
- const rootDir = project.rootDir;
18
-
19
- const dirs = ['coverage', 'dist'];
20
- const extras = [];
21
-
22
- if (
23
- project.hasExportedTypes ||
24
- project.hasTypescript ||
25
- project.projectType === 'aws-microservice'
26
- ) {
27
- dirs.push('working');
28
- }
29
-
30
- if (project.hasTypescript) {
31
- dirs.push('.tscache');
32
- extras.push({
33
- name: 'typescript-temp',
34
- path: rootDir.getFileGlob('tscommand-*.tmp.txt'),
35
- });
36
- }
37
-
38
- if (project.projectType === 'aws-microservice') {
39
- dirs.push('cdk.out');
40
- }
41
-
42
- if (project.hasServer) {
43
- extras.push({
44
- name: 'logs',
45
- path: rootDir.getChild('logs').getAllFilesGlob('log'),
46
- });
47
- }
48
-
49
- const paths = dirs.map((dir) => rootDir.getChild(dir).globPath);
50
- const task = () => _delete(paths);
51
-
52
- task.displayName = 'clean';
53
- task.description =
54
- 'Cleans out working, distribution and temporary files and directories';
55
-
56
- return task;
57
- };
@@ -1,41 +0,0 @@
1
- 'use strict';
2
-
3
- const _gulp = require('gulp');
4
- const _gulpJsdoc = require('gulp-jsdoc3');
5
-
6
- /**
7
- * Sub builder that creates a task that will generate documentation from
8
- * javascript files.
9
- *
10
- * @private
11
- * @param {Object} project Reference to an object that contains project metadata
12
- * that can be used to customize build outputs.
13
- * @param {Object} options An options object that can be used to customize the
14
- * task.
15
- *
16
- * @returns {Function} A gulp task.
17
- */
18
- module.exports = (project, options) => {
19
- const { rootDir, name, version } = project;
20
-
21
- const docOptions = Object.assign(
22
- {
23
- opts: {
24
- readme: rootDir.getFilePath('README.md'),
25
- destination: rootDir.getFilePath(`docs/${name}/${version}`),
26
- template: rootDir.getFilePath('node_modules/docdash'),
27
- },
28
- },
29
- options
30
- );
31
-
32
- const paths = ['src']
33
- .map((dir) => rootDir.getChild(dir))
34
- .map((dir) => ['js'].map((ext) => dir.getAllFilesGlob(ext)))
35
- .reduce((result, arr) => result.concat(arr), []);
36
-
37
- const task = () =>
38
- _gulp.src(paths, { allowEmpty: true }).pipe(_gulpJsdoc(docOptions));
39
-
40
- return task;
41
- };
@@ -1,40 +0,0 @@
1
- 'use strict';
2
-
3
- const _gulp = require('gulp');
4
- const _gulpTypedoc = require('gulp-typedoc');
5
-
6
- /**
7
- * Sub builder that creates a task that will generate documentation from
8
- * typescript files.
9
- *
10
- * @private
11
- * @param {Object} project Reference to an object that contains project metadata
12
- * that can be used to customize build outputs.
13
- * @param {Object} options An options object that can be used to customize the
14
- * task.
15
- *
16
- * @returns {Function} A gulp task.
17
- */
18
- module.exports = (project, options) => {
19
- const { rootDir, name, version } = project;
20
-
21
- const docOptions = Object.assign(
22
- {
23
- name: `${name} Documentation`,
24
- disableOutputCheck: true,
25
- readme: rootDir.getFilePath('README.md'),
26
- out: rootDir.getFilePath(`docs/${name}/${version}`),
27
- },
28
- options
29
- );
30
-
31
- const paths = ['src']
32
- .map((dir) => rootDir.getChild(dir))
33
- .map((dir) => ['ts'].map((ext) => dir.getAllFilesGlob(ext)))
34
- .reduce((result, arr) => result.concat(arr), []);
35
-
36
- const task = () =>
37
- _gulp.src(paths, { allowEmpty: true }).pipe(_gulpTypedoc(docOptions));
38
-
39
- return task;
40
- };
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- const _gulp = require('gulp');
4
-
5
- /**
6
- * Builder function that can be used to generate a gulp task that generates
7
- * documentation from code docs. The task takes on different implementations
8
- * based on the programming language - javascript or typescript.
9
- *
10
- * @param {Object} project Reference to an object that contains project metadata
11
- * that can be used to customize build outputs.
12
- * @param {Object} options An options object that can be used to customize the
13
- * task.
14
- *
15
- * @returns {Function} A gulp task.
16
- */
17
- module.exports = (project, options) => {
18
- let createTask = null;
19
-
20
- if (project.hasTypescript) {
21
- createTask = require('./docs-ts');
22
- } else {
23
- createTask = require('./docs-js');
24
- }
25
-
26
- const task = createTask(project, options);
27
-
28
- task.displayName = 'docs';
29
- task.description = 'Generates project documentation from code docs';
30
-
31
- return task;
32
- };
@@ -1,58 +0,0 @@
1
- 'use strict';
2
-
3
- const _gulp = require('gulp');
4
- const _prettier = require('gulp-prettier');
5
-
6
- /**
7
- * Builder function that can be used to generate a gulp task to format source
8
- * files.
9
- *
10
- * @param {Object} project Reference to an object that contains project metadata
11
- * that can be used to customize build outputs.
12
- * @param {Object} options An options object that can be used to customize the
13
- * task.
14
- *
15
- * @returns {Function} A gulp task.
16
- */
17
- module.exports = (project, options) => {
18
- const { watch } = Object.assign({ watch: false }, options);
19
-
20
- const rootDir = project.rootDir;
21
-
22
- const dirs = ['src', 'test', '.gulp'];
23
- const extras = ['Gulpfile.js', 'README.md'];
24
-
25
- if (project.projectType === 'aws-microservice') {
26
- dirs.push('infra');
27
- }
28
-
29
- const paths = dirs
30
- .map((dir) => rootDir.getChild(dir))
31
- .map((dir) =>
32
- ['ts', 'js', 'json', 'py', 'tsx', 'jsx'].map((ext) =>
33
- dir.getAllFilesGlob(ext)
34
- )
35
- )
36
- .reduce((result, arr) => result.concat(arr), [])
37
- .concat(extras.map((file) => rootDir.getFileGlob(file)));
38
-
39
- const task = () =>
40
- _gulp
41
- .src(paths, { allowEmpty: true, base: rootDir.globPath })
42
- .pipe(_prettier())
43
- .pipe(_gulp.dest(rootDir.absolutePath));
44
-
45
- task.displayName = 'format';
46
- task.description = 'Formats all source files, README.md and build scripts';
47
-
48
- if (watch) {
49
- const watch = () =>
50
- _gulp.watch(paths, { usePolling: true, delay: 5000 }, task);
51
-
52
- watch.displayName = 'watch-format';
53
- watch.description = 'Automatically format files on change';
54
-
55
- return watch;
56
- }
57
- return task;
58
- };
@@ -1,56 +0,0 @@
1
- 'use strict';
2
-
3
- const _gulp = require('gulp');
4
- const _eslint = require('gulp-eslint');
5
-
6
- /**
7
- * Builder function that can be used to generate a gulp task to format source
8
- * files.
9
- *
10
- * @param {Object} project Reference to an object that contains project metadata
11
- * that can be used to customize build outputs.
12
- * @param {Object} options An options object that can be used to customize the
13
- * task.
14
- *
15
- * @returns {Function} A gulp task.
16
- */
17
- module.exports = (project, options) => {
18
- const { watch } = Object.assign({ watch: false }, options);
19
-
20
- const rootDir = project.rootDir;
21
- const extensions = ['js'];
22
- const dirs = ['src', 'test'];
23
-
24
- if (project.hasTypescript) {
25
- extensions.push('ts');
26
- }
27
-
28
- if (project.projectType === 'aws-microservice') {
29
- dirs.push('infra');
30
- }
31
-
32
- const paths = dirs
33
- .map((dir) => rootDir.getChild(dir))
34
- .map((dir) => extensions.map((ext) => dir.getAllFilesGlob(ext)))
35
- .reduce((result, arr) => result.concat(arr), []);
36
-
37
- const task = () =>
38
- _gulp
39
- .src(paths, { allowEmpty: true })
40
- .pipe(_eslint())
41
- .pipe(_eslint.format())
42
- .pipe(_eslint.failAfterError());
43
-
44
- task.displayName = 'lint';
45
- task.description = 'Lints source files';
46
-
47
- if (watch) {
48
- return task;
49
- } else {
50
- const watchTask = () => _gulp.watch(paths, task);
51
- watchTask.displayName = 'watch-lint';
52
- watchTask.description = 'Automatically lint files on change';
53
-
54
- return watchTask;
55
- }
56
- };