@tywalk/pcf-helper-run 1.1.13 → 1.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/pcf-helper-run.test.js +57 -0
- package/index.js +22 -11
- package/package.json +7 -3
- package/util/performanceUtil.js +28 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const { spawn } = require('child_process');
|
|
2
|
+
const version = require('../package.json').version;
|
|
3
|
+
|
|
4
|
+
test('displays version', (done) => {
|
|
5
|
+
const task = spawn('node', ['./index.js', '-v']);
|
|
6
|
+
|
|
7
|
+
let output = '';
|
|
8
|
+
task.stdout.on('data', (data) => {
|
|
9
|
+
output += data.toString();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
task.on('close', (code) => {
|
|
13
|
+
console.log(output);
|
|
14
|
+
expect(output).toContain(version);
|
|
15
|
+
expect(code).toBe(0);
|
|
16
|
+
done();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
test('errors if no path is provided', (done) => {
|
|
22
|
+
const task = spawn('node', ['./index.js', '-p']);
|
|
23
|
+
|
|
24
|
+
let output = '';
|
|
25
|
+
task.stdout.on('data', (data) => {
|
|
26
|
+
output += data.toString();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
task.stderr.on('data', (data) => {
|
|
30
|
+
console.error(`stderr: ${data}`);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
task.on('close', (code) => {
|
|
34
|
+
console.log(output);
|
|
35
|
+
expect(code).toBe(1);
|
|
36
|
+
done();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('errors if incorrect command is provided', (done) => {
|
|
41
|
+
const task = spawn('node', ['./index.js', '-p', 'test', 'invalid']);
|
|
42
|
+
|
|
43
|
+
let output = '';
|
|
44
|
+
task.stdout.on('data', (data) => {
|
|
45
|
+
output += data.toString();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
task.stderr.on('data', (data) => {
|
|
49
|
+
console.error(`stderr: ${data}`);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
task.on('close', (code) => {
|
|
53
|
+
console.log(output);
|
|
54
|
+
expect(code).toBe(1);
|
|
55
|
+
done();
|
|
56
|
+
});
|
|
57
|
+
});
|
package/index.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
const upgradeTask = require('@tywalk/pcf-helper/tasks/upgrade-pcf');
|
|
3
3
|
const buildTask = require('@tywalk/pcf-helper/tasks/build-pcf');
|
|
4
4
|
const importTask = require('@tywalk/pcf-helper/tasks/import-pcf');
|
|
5
|
+
const { Logger } = require('@tywalk/color-logger');
|
|
5
6
|
const version = require('./package.json').version;
|
|
6
|
-
const { formatMsToSec } = require('./util/performanceUtil');
|
|
7
|
+
const { formatMsToSec, formatTime } = require('./util/performanceUtil');
|
|
7
8
|
const [, , ...args] = process.argv;
|
|
8
9
|
|
|
9
10
|
const commandArgument = args.at(0)?.toLowerCase();
|
|
@@ -12,25 +13,32 @@ if (['-v', '--version'].includes(commandArgument)) {
|
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
const logger = new Logger();
|
|
17
|
+
|
|
18
|
+
const verboseArgument = args.find(a => ['-v', '--verbose'].includes(a));
|
|
19
|
+
if (typeof verboseArgument !== 'undefined') {
|
|
20
|
+
logger.setDebug(true);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
logger.log('PCF Helper Run version\n', version);
|
|
16
24
|
|
|
17
25
|
if (typeof commandArgument === 'undefined' || !['upgrade', 'build', 'import', 'deploy'].includes(commandArgument)) {
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
logger.error('Command [command] (upgrade, build, import, deploy) is required.');
|
|
27
|
+
process.exit(1);
|
|
20
28
|
}
|
|
21
29
|
const runAll = commandArgument === 'deploy';
|
|
22
30
|
|
|
23
31
|
const pathArgument = args.find(a => ['-p', '--path'].includes(a));
|
|
24
32
|
if (typeof pathArgument === 'undefined') {
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
logger.error('Path argument is required. Use --path to specify the path to solution folder.');
|
|
34
|
+
process.exit(1);
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
const pathIndex = args.indexOf(pathArgument) + 1;
|
|
30
38
|
const path = args.at(pathIndex);
|
|
31
39
|
if (typeof path === 'undefined') {
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
logger.error('Path argument is required. Use --path to specify the path to solution folder.');
|
|
41
|
+
process.exit(1);
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
const tick = performance.now();
|
|
@@ -60,16 +68,19 @@ function executeTasks() {
|
|
|
60
68
|
|
|
61
69
|
var result = 0;
|
|
62
70
|
try {
|
|
71
|
+
logger.log('[PCF Helper Run] ' + formatTime(new Date()) + ' ' + commandArgument + ' started.\n');
|
|
63
72
|
result = executeTasks();
|
|
64
73
|
if (result === 0) {
|
|
65
|
-
|
|
74
|
+
logger.log('[PCF Helper Run] ' + commandArgument + ' completed successfully!');
|
|
75
|
+
} else {
|
|
76
|
+
logger.log('[PCF Helper Run] ' + commandArgument + ' completed with errors.');
|
|
66
77
|
}
|
|
67
78
|
} catch (e) {
|
|
68
|
-
|
|
79
|
+
logger.error('[PCF Helper Run] One or more tasks failed while deploying: ', (e && e.message) || 'unkown error');
|
|
69
80
|
result = 1;
|
|
70
81
|
} finally {
|
|
71
82
|
const tock = performance.now();
|
|
72
|
-
|
|
83
|
+
logger.log(formatMsToSec('[PCF Helper Run] ' + formatTime(new Date()) + ' ' + commandArgument + ' finished in %is.', tock - tick));
|
|
73
84
|
}
|
|
74
85
|
|
|
75
86
|
return result;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tywalk/pcf-helper-run",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15",
|
|
4
4
|
"description": "A simple command-line utility for building and publishing PCF controls to Dataverse.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "git+https://github.com/tywalk/pcf-helper.git"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "
|
|
9
|
+
"test": "jest"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [
|
|
12
12
|
"pcf"
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"pcf-helper-run": "./index.js"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@tywalk/
|
|
19
|
+
"@tywalk/color-logger": "^1.0.0",
|
|
20
|
+
"@tywalk/pcf-helper": "^1.4.12"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"jest": "^29.7.0"
|
|
20
24
|
}
|
|
21
25
|
}
|
package/util/performanceUtil.js
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
1
|
const util = require('node:util');
|
|
2
2
|
|
|
3
|
+
var formatter = new Intl.DateTimeFormat('en-US', {
|
|
4
|
+
hour: '2-digit',
|
|
5
|
+
minute: '2-digit',
|
|
6
|
+
second: '2-digit',
|
|
7
|
+
hour12: false
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Formats a number of milliseconds into seconds.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} format - The string format to use when formatting the number of seconds.
|
|
14
|
+
* @param {number} ms - The number of milliseconds to be formatted.
|
|
15
|
+
*
|
|
16
|
+
* @returns {string} The formatted number of seconds.
|
|
17
|
+
*/
|
|
3
18
|
function formatMsToSec(format, ms) {
|
|
4
19
|
const seconds = ms / 1000;
|
|
5
20
|
return util.format(format, seconds);
|
|
6
21
|
}
|
|
7
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Formats a Date object into a human-readable string.
|
|
25
|
+
*
|
|
26
|
+
* @param {Date} date - The date object to be formatted.
|
|
27
|
+
*
|
|
28
|
+
* @returns {string} The formatted string.
|
|
29
|
+
*/
|
|
30
|
+
function formatTime(date) {
|
|
31
|
+
return formatter.format(date);
|
|
32
|
+
}
|
|
33
|
+
|
|
8
34
|
module.exports = {
|
|
9
|
-
formatMsToSec
|
|
35
|
+
formatMsToSec,
|
|
36
|
+
formatTime
|
|
10
37
|
}
|