@tywalk/pcf-helper-run 1.1.17 → 1.1.20

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.
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const child_process_1 = require("child_process");
4
+ const package_json_1 = require("../package.json");
5
+ test('displays version', (done) => {
6
+ const task = (0, child_process_1.spawn)('node', ['./dist/index.js', '-v']);
7
+ let output = '';
8
+ task.stdout.on('data', (data) => {
9
+ output += data.toString();
10
+ });
11
+ task.on('close', (code) => {
12
+ console.log(output);
13
+ expect(output).toContain(package_json_1.version);
14
+ expect(code).toBe(0);
15
+ done();
16
+ });
17
+ });
18
+ test('errors if no path is provided', (done) => {
19
+ const task = (0, child_process_1.spawn)('node', ['./index.js', '-p']);
20
+ let output = '';
21
+ task.stdout.on('data', (data) => {
22
+ output += data.toString();
23
+ });
24
+ task.stderr.on('data', (data) => {
25
+ console.error(`stderr: ${data}`);
26
+ });
27
+ task.on('close', (code) => {
28
+ console.log(output);
29
+ expect(code).toBe(1);
30
+ done();
31
+ });
32
+ });
33
+ test('errors if incorrect command is provided', (done) => {
34
+ const task = (0, child_process_1.spawn)('node', ['./index.js', '-p', 'test', 'invalid']);
35
+ let output = '';
36
+ task.stdout.on('data', (data) => {
37
+ output += data.toString();
38
+ });
39
+ task.stderr.on('data', (data) => {
40
+ console.error(`stderr: ${data}`);
41
+ });
42
+ task.on('close', (code) => {
43
+ console.log(output);
44
+ expect(code).toBe(1);
45
+ done();
46
+ });
47
+ });
package/dist/index.js ADDED
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ var _a, _b, _c, _d;
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const upgrade_pcf_1 = __importDefault(require("@tywalk/pcf-helper/dist/tasks/upgrade-pcf"));
9
+ const build_pcf_1 = __importDefault(require("@tywalk/pcf-helper/dist/tasks/build-pcf"));
10
+ const import_pcf_1 = __importDefault(require("@tywalk/pcf-helper/dist/tasks/import-pcf"));
11
+ const init_pcf_1 = __importDefault(require("@tywalk/pcf-helper/dist/tasks/init-pcf"));
12
+ const color_logger_1 = require("@tywalk/color-logger");
13
+ const package_json_1 = require("./package.json");
14
+ const performanceUtil_1 = require("./util/performanceUtil");
15
+ const [, , ...args] = process.argv;
16
+ const commandArgument = (_b = (_a = args.at(0)) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
17
+ if (['-v', '--version'].includes(commandArgument)) {
18
+ console.log('v%s', package_json_1.version);
19
+ process.exit(0);
20
+ }
21
+ const logger = new color_logger_1.Logger('log');
22
+ const verboseArgument = args.find(a => ['-v', '--verbose'].includes(a));
23
+ if (typeof verboseArgument !== 'undefined') {
24
+ logger.setDebug(true);
25
+ }
26
+ logger.log('PCF Helper Run version\n', package_json_1.version);
27
+ if (typeof commandArgument === 'undefined' || !['upgrade', 'build', 'import', 'deploy', 'init'].includes(commandArgument)) {
28
+ logger.error('Command [command] (upgrade, build, import, deploy) is required.');
29
+ process.exit(1);
30
+ }
31
+ const runAll = commandArgument === 'deploy';
32
+ const pathArgument = args.find(a => ['-p', '--path'].includes(a));
33
+ if (typeof pathArgument === 'undefined') {
34
+ logger.error('Path argument is required. Use --path to specify the path to solution folder.');
35
+ process.exit(1);
36
+ }
37
+ const pathIndex = args.indexOf(pathArgument) + 1;
38
+ const path = args.at(pathIndex);
39
+ if (typeof path === 'undefined') {
40
+ logger.error('Path argument is required. Use --path to specify the path to solution folder.');
41
+ process.exit(1);
42
+ }
43
+ const tick = performance.now();
44
+ const envArgument = (_c = args.find(a => ['-env', '--environment'].includes(a))) !== null && _c !== void 0 ? _c : '';
45
+ let envIndex = args.indexOf(envArgument) + 1;
46
+ let env = '';
47
+ if (envIndex > 0) {
48
+ env = (_d = args.at(envIndex)) !== null && _d !== void 0 ? _d : '';
49
+ }
50
+ function executeTasks() {
51
+ if (commandArgument === 'upgrade' || runAll) {
52
+ const upgradeResult = upgrade_pcf_1.default.run(path);
53
+ if (upgradeResult === 1)
54
+ return 1;
55
+ }
56
+ if (commandArgument === 'build' || runAll) {
57
+ const buildResult = build_pcf_1.default.run(path);
58
+ if (buildResult === 1)
59
+ return 1;
60
+ }
61
+ if (commandArgument === 'import' || runAll) {
62
+ const importResult = import_pcf_1.default.run(path, env);
63
+ if (importResult === 1)
64
+ return 1;
65
+ }
66
+ if (commandArgument === 'init') {
67
+ const importResult = init_pcf_1.default.run(path, env);
68
+ if (importResult === 1)
69
+ return 1;
70
+ }
71
+ return 0;
72
+ }
73
+ var result = 0;
74
+ try {
75
+ logger.log('[PCF Helper Run] ' + (0, performanceUtil_1.formatTime)(new Date()) + ' ' + commandArgument + ' started.\n');
76
+ result = executeTasks();
77
+ if (result === 0) {
78
+ logger.log('[PCF Helper Run] ' + commandArgument + ' completed successfully!');
79
+ }
80
+ else {
81
+ logger.log('[PCF Helper Run] ' + commandArgument + ' completed with errors.');
82
+ }
83
+ }
84
+ catch (e) {
85
+ logger.error('[PCF Helper Run] One or more tasks failed while deploying: ', (e && e.message) || 'unkown error');
86
+ result = 1;
87
+ }
88
+ finally {
89
+ const tock = performance.now();
90
+ logger.log((0, performanceUtil_1.formatMsToSec)('[PCF Helper Run] ' + (0, performanceUtil_1.formatTime)(new Date()) + ' ' + commandArgument + ' finished in %is.', tock - tick));
91
+ }
92
+ process.exit(result);
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@tywalk/pcf-helper-run",
3
+ "version": "1.1.20",
4
+ "description": "A simple command-line utility for building and publishing PCF controls to Dataverse.",
5
+ "types": "./types/",
6
+ "files": [
7
+ "dist",
8
+ "types"
9
+ ],
10
+ "repository": {
11
+ "url": "git+https://github.com/tywalk/pcf-helper.git"
12
+ },
13
+ "scripts": {
14
+ "test": "jest",
15
+ "build": "tsc",
16
+ "upgrade": "npm version patch --no-git-tag-version",
17
+ "ready": "npm run upgrade && npm run build"
18
+ },
19
+ "keywords": [
20
+ "pcf"
21
+ ],
22
+ "author": "tywalk",
23
+ "bin": {
24
+ "pcf-helper-run": "dist/index.js"
25
+ },
26
+ "dependencies": {
27
+ "@tywalk/color-logger": "^1.0.3",
28
+ "@tywalk/pcf-helper": "^1.4.16"
29
+ },
30
+ "devDependencies": {
31
+ "@types/jest": "^29.5.14",
32
+ "@types/node": "^22.13.11",
33
+ "jest": "^29.7.0",
34
+ "ts-jest": "^29.3.0",
35
+ "typescript": "^5.8.2"
36
+ }
37
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.formatMsToSec = formatMsToSec;
7
+ exports.formatTime = formatTime;
8
+ const util_1 = __importDefault(require("util"));
9
+ var formatter = new Intl.DateTimeFormat('en-US', {
10
+ hour: '2-digit',
11
+ minute: '2-digit',
12
+ second: '2-digit',
13
+ hour12: false
14
+ });
15
+ /**
16
+ * Formats a number of milliseconds into seconds.
17
+ *
18
+ * @param {string} format - The string format to use when formatting the number of seconds.
19
+ * @param {number} ms - The number of milliseconds to be formatted.
20
+ *
21
+ * @returns {string} The formatted number of seconds.
22
+ */
23
+ function formatMsToSec(format, ms) {
24
+ const seconds = ms / 1000;
25
+ return util_1.default.format(format, seconds);
26
+ }
27
+ /**
28
+ * Formats a Date object into a human-readable string.
29
+ *
30
+ * @param {Date} date - The date object to be formatted.
31
+ *
32
+ * @returns {string} The formatted string.
33
+ */
34
+ function formatTime(date) {
35
+ return formatter.format(date);
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tywalk/pcf-helper-run",
3
- "version": "1.1.17",
3
+ "version": "1.1.20",
4
4
  "description": "A simple command-line utility for building and publishing PCF controls to Dataverse.",
5
5
  "types": "./types/",
6
6
  "files": [
@@ -24,12 +24,12 @@
24
24
  "pcf-helper-run": "dist/index.js"
25
25
  },
26
26
  "dependencies": {
27
- "@tywalk/pcf-helper": "^1.4.13"
27
+ "@tywalk/color-logger": "^1.0.3",
28
+ "@tywalk/pcf-helper": "^1.4.16"
28
29
  },
29
30
  "devDependencies": {
30
31
  "@types/jest": "^29.5.14",
31
32
  "@types/node": "^22.13.11",
32
- "@tywalk/color-logger": "^1.0.3",
33
33
  "jest": "^29.7.0",
34
34
  "ts-jest": "^29.3.0",
35
35
  "typescript": "^5.8.2"
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Formats a number of milliseconds into seconds.
3
+ *
4
+ * @param {string} format - The string format to use when formatting the number of seconds.
5
+ * @param {number} ms - The number of milliseconds to be formatted.
6
+ *
7
+ * @returns {string} The formatted number of seconds.
8
+ */
9
+ declare function formatMsToSec(format: string, ms: number): string;
10
+ /**
11
+ * Formats a Date object into a human-readable string.
12
+ *
13
+ * @param {Date} date - The date object to be formatted.
14
+ *
15
+ * @returns {string} The formatted string.
16
+ */
17
+ declare function formatTime(date: Date): string;
18
+ export { formatMsToSec, formatTime };