@vamship/build-utils 1.0.4 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +15 -15
- package/src/project.js +14 -0
- package/src/task-builders/build/build-js.js +5 -1
- package/src/task-builders/build/build-ui.js +67 -0
- package/src/task-builders/build/index.js +18 -10
- package/src/task-builders/format.js +3 -1
- package/src/task-builders/test/index.js +39 -0
- package/src/task-builders/test/test-ui.js +39 -0
- /package/src/task-builders/{test.js → test/test.js} +0 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vamship/build-utils",
|
3
|
-
"version": "1.0
|
3
|
+
"version": "1.4.0",
|
4
4
|
"description": "Utility library for build tooling",
|
5
5
|
"main": "src/index.js",
|
6
6
|
"scripts": {
|
@@ -41,26 +41,26 @@
|
|
41
41
|
},
|
42
42
|
"homepage": "https://github.com/vamship/build-utils#readme",
|
43
43
|
"devDependencies": {
|
44
|
-
"chai": "^4.3.
|
44
|
+
"chai": "^4.3.6",
|
45
45
|
"chai-as-promised": "^7.1.1",
|
46
|
-
"eslint": "^
|
47
|
-
"jsdoc": "^3.6.
|
48
|
-
"mocha": "^9.
|
49
|
-
"nodemon": "^2.0.
|
46
|
+
"eslint": "^8.10.0",
|
47
|
+
"jsdoc": "^3.6.10",
|
48
|
+
"mocha": "^9.2.2",
|
49
|
+
"nodemon": "^2.0.15",
|
50
50
|
"nyc": "^15.1.0",
|
51
|
-
"prettier": "^2.
|
52
|
-
"rewire": "^
|
53
|
-
"sinon": "^
|
51
|
+
"prettier": "^2.5.1",
|
52
|
+
"rewire": "^6.0.0",
|
53
|
+
"sinon": "^13.0.1",
|
54
54
|
"sinon-chai": "^3.7.0"
|
55
55
|
},
|
56
56
|
"dependencies": {
|
57
|
-
"camelcase": "^6.
|
57
|
+
"camelcase": "^6.3.0",
|
58
58
|
"delete": "^1.1.0",
|
59
59
|
"docdash": "^1.2.0",
|
60
|
-
"dotenv": "^
|
61
|
-
"dotenv-expand": "^
|
60
|
+
"dotenv": "^16.0.0",
|
61
|
+
"dotenv-expand": "^8.0.2",
|
62
62
|
"execa": "^5.1.1",
|
63
|
-
"fancy-log": "^
|
63
|
+
"fancy-log": "^2.0.0",
|
64
64
|
"mkdirp": "^1.0.4",
|
65
65
|
"semver": "^7.3.5"
|
66
66
|
},
|
@@ -82,8 +82,8 @@
|
|
82
82
|
},
|
83
83
|
"optionalDependencies": {
|
84
84
|
"gulp-jsdoc3": "= 3.0.0",
|
85
|
-
"typedoc": ">=
|
86
|
-
"typescript": ">=
|
85
|
+
"typedoc": ">=0.22.13",
|
86
|
+
"typescript": ">=4.6.2"
|
87
87
|
},
|
88
88
|
"engines": {
|
89
89
|
"node": ">= 14.18.1",
|
package/src/project.js
CHANGED
@@ -12,6 +12,7 @@ const SUPPORTED_PROJECT_TYPES = [
|
|
12
12
|
'api',
|
13
13
|
'aws-microservice',
|
14
14
|
'container',
|
15
|
+
'ui',
|
15
16
|
];
|
16
17
|
const SUPPORTED_LANGUAGES = ['js', 'ts'];
|
17
18
|
|
@@ -121,6 +122,7 @@ module.exports = class Project {
|
|
121
122
|
requiredEnv,
|
122
123
|
exportedTypes,
|
123
124
|
aws,
|
125
|
+
staticFilePatterns,
|
124
126
|
} = buildMetadata;
|
125
127
|
|
126
128
|
if (SUPPORTED_PROJECT_TYPES.indexOf(projectType) < 0) {
|
@@ -143,6 +145,8 @@ module.exports = class Project {
|
|
143
145
|
this._projectType = projectType;
|
144
146
|
this._language = language;
|
145
147
|
this._exportedTypes = exportedTypes;
|
148
|
+
this._staticFilePatterns =
|
149
|
+
staticFilePatterns instanceof Array ? staticFilePatterns : [];
|
146
150
|
|
147
151
|
this._hasTypescript = this._language === 'ts';
|
148
152
|
this._hasServer = this._projectType === 'api';
|
@@ -438,6 +442,16 @@ module.exports = class Project {
|
|
438
442
|
return this._exportedTypes;
|
439
443
|
}
|
440
444
|
|
445
|
+
/**
|
446
|
+
* Additional files to copy from the source directory to the build
|
447
|
+
* directory.
|
448
|
+
*
|
449
|
+
* @return {String}
|
450
|
+
*/
|
451
|
+
get staticFilePatterns() {
|
452
|
+
return this._staticFilePatterns;
|
453
|
+
}
|
454
|
+
|
441
455
|
/**
|
442
456
|
* Determines whether or not the project can be packaged up as a docker
|
443
457
|
* image.
|
@@ -36,9 +36,13 @@ module.exports = (project, options) => {
|
|
36
36
|
extras.push('Dockerfile*');
|
37
37
|
}
|
38
38
|
|
39
|
+
const staticFilePatterns = ['js', 'json'].concat(
|
40
|
+
project.staticFilePatterns
|
41
|
+
);
|
42
|
+
|
39
43
|
const paths = dirs
|
40
44
|
.map((dir) => rootDir.getChild(dir))
|
41
|
-
.map((dir) =>
|
45
|
+
.map((dir) => staticFilePatterns.map((ext) => dir.getAllFilesGlob(ext)))
|
42
46
|
.reduce((result, arr) => result.concat(arr), [])
|
43
47
|
.concat(extras.map((item) => rootDir.getFileGlob(item)));
|
44
48
|
|
@@ -0,0 +1,67 @@
|
|
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
|
+
};
|
@@ -27,18 +27,26 @@ module.exports = (project, options) => {
|
|
27
27
|
return;
|
28
28
|
}
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
if (project.
|
34
|
-
const
|
35
|
-
tasks
|
36
|
-
|
37
|
-
|
38
|
-
|
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)];
|
39
47
|
}
|
40
48
|
|
41
|
-
|
49
|
+
task = _gulp.parallel(tasks);
|
42
50
|
if (!watch) {
|
43
51
|
task.displayName = 'build';
|
44
52
|
task.description = 'Transpile/copy source files into working directory';
|
@@ -29,7 +29,9 @@ module.exports = (project, options) => {
|
|
29
29
|
const paths = dirs
|
30
30
|
.map((dir) => rootDir.getChild(dir))
|
31
31
|
.map((dir) =>
|
32
|
-
['ts', 'js', 'json', 'py'].map((ext) =>
|
32
|
+
['ts', 'js', 'json', 'py', 'tsx', 'jsx'].map((ext) =>
|
33
|
+
dir.getAllFilesGlob(ext)
|
34
|
+
)
|
33
35
|
)
|
34
36
|
.reduce((result, arr) => result.concat(arr), [])
|
35
37
|
.concat(extras.map((file) => rootDir.getFileGlob(file)));
|
@@ -0,0 +1,39 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const _gulp = require('gulp');
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Builder function that can be used to generate a gulp task to execute
|
7
|
+
* instrumented unit/api tests.
|
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 { testType, watch } = Object.assign(
|
18
|
+
{ testType: 'unit', watch: false },
|
19
|
+
options
|
20
|
+
);
|
21
|
+
const tasks = [];
|
22
|
+
if (project.projectType !== 'ui') {
|
23
|
+
const nonUiTests = require('./test');
|
24
|
+
tasks.push(nonUiTests(project, options));
|
25
|
+
} else {
|
26
|
+
const uiTests = require('./test-ui');
|
27
|
+
tasks.push(uiTests(project, options));
|
28
|
+
}
|
29
|
+
const task = _gulp.parallel(tasks);
|
30
|
+
if (!watch) {
|
31
|
+
task.displayName = `test-${testType}`;
|
32
|
+
task.description = `Execute ${testType} tests`;
|
33
|
+
} else {
|
34
|
+
task.displayName = `watch-test-${testType}`;
|
35
|
+
task.description = `Automatically execute ${testType} tests on change`;
|
36
|
+
}
|
37
|
+
|
38
|
+
return task;
|
39
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const _gulp = require('gulp');
|
4
|
+
const _execa = require('execa');
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Builder function that can be used to generate a gulp task to execute
|
8
|
+
* instrumented unit/api tests.
|
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 { testType, watch } = Object.assign(
|
19
|
+
{ testType: 'unit', watch: false },
|
20
|
+
options
|
21
|
+
);
|
22
|
+
|
23
|
+
const rootDir = project.jsRootDir;
|
24
|
+
const jestBin = project.rootDir.getFilePath('node_modules/.bin/jest');
|
25
|
+
let args = ['--config', 'jest.config.js', '--coverage'];
|
26
|
+
|
27
|
+
if (watch) {
|
28
|
+
args.push('--watchAll');
|
29
|
+
const watchTask = () => _execa(jestBin, args, { stdio: 'inherit' });
|
30
|
+
watchTask.displayName = `watch-test-${testType}`;
|
31
|
+
watchTask.description = `Automatically execute ${testType} tests on change`;
|
32
|
+
return watchTask;
|
33
|
+
}
|
34
|
+
|
35
|
+
const task = () => _execa(jestBin, args, { stdio: 'inherit' });
|
36
|
+
task.displayName = `test-${testType}`;
|
37
|
+
task.description = `Execute ${testType} tests`;
|
38
|
+
return task;
|
39
|
+
};
|
File without changes
|