@tywalk/pcf-helper 1.4.24 ā 1.4.26
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/README.md +6 -0
- package/dist/__tests__/pcf-helper-build.test.js +1 -1
- package/dist/__tests__/pcf-helper-deploy.test.js +1 -1
- package/dist/__tests__/pcf-helper-import.test.js +1 -1
- package/dist/__tests__/pcf-helper-init.test.js +1 -1
- package/dist/__tests__/pcf-helper-session.test.js +32 -0
- package/dist/__tests__/pcf-helper-upgrade.test.js +1 -1
- package/dist/bin/deploy.js +10 -2
- package/dist/bin/session.js +60 -0
- package/dist/package.json +6 -3
- package/dist/tasks/index.js +1 -0
- package/dist/tasks/session-pcf.js +252 -0
- package/package.json +6 -3
- package/types/__tests__/pcf-helper-session.test.d.ts +1 -0
- package/types/bin/session.d.ts +2 -0
- package/types/tasks/index.d.ts +1 -0
- package/types/tasks/session-pcf.d.ts +9 -0
package/README.md
CHANGED
|
@@ -25,3 +25,9 @@ This tool requires the following:
|
|
|
25
25
|
"init": "pcf-helper-init --path <path to pcf project folder (optional)> --name <name of the pcf project> --publisher-name <powerapps publisher name> --publisher-prefix <powerapps publisher prefix>"
|
|
26
26
|
},
|
|
27
27
|
```
|
|
28
|
+
|
|
29
|
+
## Contributing
|
|
30
|
+
|
|
31
|
+
### Deployment
|
|
32
|
+
|
|
33
|
+
|
|
@@ -13,7 +13,7 @@ test('build displays version', (done) => {
|
|
|
13
13
|
});
|
|
14
14
|
task.on('close', (code) => {
|
|
15
15
|
console.log(output);
|
|
16
|
-
expect(output).toContain(package_json_1.version);
|
|
16
|
+
expect(output).toContain(`v${package_json_1.version}`);
|
|
17
17
|
expect(code).toBe(0);
|
|
18
18
|
done();
|
|
19
19
|
});
|
|
@@ -13,7 +13,7 @@ test('deploy displays version', (done) => {
|
|
|
13
13
|
});
|
|
14
14
|
task.on('close', (code) => {
|
|
15
15
|
console.log(output);
|
|
16
|
-
expect(output).toContain(package_json_1.version);
|
|
16
|
+
expect(output).toContain(`v${package_json_1.version}`);
|
|
17
17
|
expect(code).toBe(0);
|
|
18
18
|
done();
|
|
19
19
|
});
|
|
@@ -10,7 +10,7 @@ test('import displays version', (done) => {
|
|
|
10
10
|
});
|
|
11
11
|
task.on('close', (code) => {
|
|
12
12
|
console.log(output);
|
|
13
|
-
expect(output).toContain(package_json_1.version);
|
|
13
|
+
expect(output).toContain(`v${package_json_1.version}`);
|
|
14
14
|
expect(code).toBe(0);
|
|
15
15
|
done();
|
|
16
16
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
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('session displays version', (done) => {
|
|
6
|
+
const task = (0, child_process_1.spawn)('node', ['./dist/bin/session.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(`v${package_json_1.version}`);
|
|
14
|
+
expect(code).toBe(0);
|
|
15
|
+
done();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
test('session errors if no args are provided', (done) => {
|
|
19
|
+
const task = (0, child_process_1.spawn)('node', ['./dist/bin/session.js', '-e']);
|
|
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
|
+
});
|
|
@@ -10,7 +10,7 @@ test('upgrade displays version', (done) => {
|
|
|
10
10
|
});
|
|
11
11
|
task.on('close', (code) => {
|
|
12
12
|
console.log(output);
|
|
13
|
-
expect(output).toContain(package_json_1.version);
|
|
13
|
+
expect(output).toContain(`v${package_json_1.version}`);
|
|
14
14
|
expect(code).toBe(0);
|
|
15
15
|
done();
|
|
16
16
|
});
|
package/dist/bin/deploy.js
CHANGED
|
@@ -51,6 +51,14 @@ if (['-v', '--version'].includes(commandArgument)) {
|
|
|
51
51
|
console.log('v%s', package_json_1.version);
|
|
52
52
|
process.exit(0);
|
|
53
53
|
}
|
|
54
|
+
const timeout = (0, argumentUtil_1.getArgValue)(args, ['-t', '--timeout']);
|
|
55
|
+
if (typeof timeout !== 'undefined') {
|
|
56
|
+
const timeoutNumber = Number(timeout);
|
|
57
|
+
if (isNaN(timeoutNumber) || timeoutNumber <= 0) {
|
|
58
|
+
color_logger_1.default.error('Timeout argument must be a positive number representing milliseconds.');
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
54
62
|
const verboseArgument = args.find(a => ['-v', '--verbose'].includes(a));
|
|
55
63
|
if (typeof verboseArgument !== 'undefined') {
|
|
56
64
|
color_logger_1.default.setDebug(true);
|
|
@@ -73,10 +81,10 @@ function executeTasks() {
|
|
|
73
81
|
const upgradeResult = upgradeTask.runUpgrade(path, typeof verboseArgument !== 'undefined');
|
|
74
82
|
if (upgradeResult === 1)
|
|
75
83
|
return 1;
|
|
76
|
-
const buildResult = buildTask.runBuild(path, typeof verboseArgument !== 'undefined');
|
|
84
|
+
const buildResult = buildTask.runBuild(path, typeof verboseArgument !== 'undefined', typeof timeout !== 'undefined' ? Number(timeout) : undefined);
|
|
77
85
|
if (buildResult === 1)
|
|
78
86
|
return 1;
|
|
79
|
-
const importResult = importTask.runImport(path, env, typeof verboseArgument !== 'undefined');
|
|
87
|
+
const importResult = importTask.runImport(path, env, typeof verboseArgument !== 'undefined', typeof timeout !== 'undefined' ? Number(timeout) : undefined);
|
|
80
88
|
if (importResult === 1)
|
|
81
89
|
return 1;
|
|
82
90
|
return 0;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
const task = __importStar(require("../tasks/session-pcf"));
|
|
41
|
+
const package_json_1 = require("../package.json");
|
|
42
|
+
const color_logger_1 = __importDefault(require("@tywalk/color-logger"));
|
|
43
|
+
const commander_1 = require("commander");
|
|
44
|
+
const program = new commander_1.Command();
|
|
45
|
+
program
|
|
46
|
+
.option('-v, --version', 'output the version number')
|
|
47
|
+
.option('-vv, --verbose', 'enable verbose logging')
|
|
48
|
+
.parse();
|
|
49
|
+
const options = program.opts();
|
|
50
|
+
if (options.version) {
|
|
51
|
+
console.log('v%s', package_json_1.version);
|
|
52
|
+
process.exit(0);
|
|
53
|
+
}
|
|
54
|
+
if (options.verbose) {
|
|
55
|
+
color_logger_1.default.setLevel('debug');
|
|
56
|
+
color_logger_1.default.debug('Verbose logging enabled');
|
|
57
|
+
}
|
|
58
|
+
color_logger_1.default.log('PCF Helper version', package_json_1.version);
|
|
59
|
+
const config = task.loadConfig();
|
|
60
|
+
task.runSession(config.remoteEnvironmentUrl, config.remoteScriptToIntercept, config.remoteStylesheetToIntercept, config.localBundlePath, config.localCssPath);
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tywalk/pcf-helper",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.26",
|
|
4
4
|
"description": "Command line helper for building and publishing PCF controls to Dataverse.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "./types/",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"pcf-helper-build": "dist/bin/build.js",
|
|
27
27
|
"pcf-helper-import": "dist/bin/import.js",
|
|
28
28
|
"pcf-helper-deploy": "dist/bin/deploy.js",
|
|
29
|
-
"pcf-helper-init": "dist/bin/init.js"
|
|
29
|
+
"pcf-helper-init": "dist/bin/init.js",
|
|
30
|
+
"pcf-helper-session": "dist/bin/session.js"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@types/jest": "^29.5.14",
|
|
@@ -36,6 +37,8 @@
|
|
|
36
37
|
"typescript": "^5.8.2"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@tywalk/color-logger": "^1.0.3"
|
|
40
|
+
"@tywalk/color-logger": "^1.0.3",
|
|
41
|
+
"commander": "^14.0.3",
|
|
42
|
+
"playwright": "^1.58.2"
|
|
40
43
|
}
|
|
41
44
|
}
|
package/dist/tasks/index.js
CHANGED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.runSession = runSession;
|
|
16
|
+
exports.loadConfig = loadConfig;
|
|
17
|
+
const color_logger_1 = __importDefault(require("@tywalk/color-logger"));
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
const fs_1 = __importDefault(require("fs"));
|
|
20
|
+
const playwright_1 = require("playwright");
|
|
21
|
+
const commander_1 = require("commander");
|
|
22
|
+
function loadConfig() {
|
|
23
|
+
const program = new commander_1.Command();
|
|
24
|
+
program
|
|
25
|
+
.option('-u, --url <url>', 'remote environment URL')
|
|
26
|
+
.option('-s, --script <script>', 'remote script to intercept')
|
|
27
|
+
.option('-t, --stylesheet <stylesheet>', 'remote stylesheet to intercept')
|
|
28
|
+
.option('-b, --bundle <path>', 'local bundle path')
|
|
29
|
+
.option('-c, --css <path>', 'local CSS path')
|
|
30
|
+
.option('-f, --config <path>', 'config file path', 'dev-config.json')
|
|
31
|
+
.parse();
|
|
32
|
+
const options = program.opts();
|
|
33
|
+
// Load file config if exists
|
|
34
|
+
let fileConfig = {};
|
|
35
|
+
const configPath = path_1.default.join(__dirname, options.config);
|
|
36
|
+
console.log(`š Looking for config file at: ${configPath}`);
|
|
37
|
+
if (fs_1.default.existsSync(configPath)) {
|
|
38
|
+
fileConfig = JSON.parse(fs_1.default.readFileSync(configPath, 'utf8'));
|
|
39
|
+
console.log(`ā
Loaded config file: ${JSON.stringify(fileConfig, null, 2)}`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log(`ā ļø Config file not found, using defaults or CLI/env options.`);
|
|
43
|
+
}
|
|
44
|
+
// Get the base URL first
|
|
45
|
+
const remoteEnvironmentUrl = options.url ||
|
|
46
|
+
process.env.REMOTE_ENVIRONMENT_URL ||
|
|
47
|
+
fileConfig.remoteEnvironmentUrl ||
|
|
48
|
+
'https://app.your-remote-environment.com';
|
|
49
|
+
// Handle script argument - support both relative paths and full URLs
|
|
50
|
+
let remoteScriptToIntercept = options.script ||
|
|
51
|
+
process.env.REMOTE_SCRIPT_TO_INTERCEPT ||
|
|
52
|
+
fileConfig.remoteScriptToIntercept ||
|
|
53
|
+
'https://app.your-remote-environment.com/static/js/remote-control-bundle.js';
|
|
54
|
+
// If script is a relative path (doesn't start with http/https), combine with base URL
|
|
55
|
+
if (remoteScriptToIntercept && !remoteScriptToIntercept.startsWith('http')) {
|
|
56
|
+
// Normalize the base URL (remove trailing slash)
|
|
57
|
+
const baseUrl = remoteEnvironmentUrl.replace(/\/$/, '');
|
|
58
|
+
// Normalize the script path (ensure it starts with /)
|
|
59
|
+
const scriptPath = remoteScriptToIntercept.startsWith('/')
|
|
60
|
+
? remoteScriptToIntercept
|
|
61
|
+
: '/' + remoteScriptToIntercept;
|
|
62
|
+
remoteScriptToIntercept = `${baseUrl}${scriptPath}`;
|
|
63
|
+
}
|
|
64
|
+
let remoteStylesheetToIntercept = options.stylesheet ||
|
|
65
|
+
process.env.REMOTE_STYLESHEET_TO_INTERCEPT ||
|
|
66
|
+
fileConfig.remoteStylesheetToIntercept ||
|
|
67
|
+
'https://app.your-remote-environment.com/static/css/remote-control-styles.css';
|
|
68
|
+
// If stylesheet is a relative path (doesn't start with http/https), combine with base URL
|
|
69
|
+
if (remoteStylesheetToIntercept && !remoteStylesheetToIntercept.startsWith('http')) {
|
|
70
|
+
// Normalize the base URL (remove trailing slash)
|
|
71
|
+
const baseUrl = remoteEnvironmentUrl.replace(/\/$/, '');
|
|
72
|
+
// Normalize the stylesheet path (ensure it starts with /)
|
|
73
|
+
const stylesheetPath = remoteStylesheetToIntercept.startsWith('/')
|
|
74
|
+
? remoteStylesheetToIntercept
|
|
75
|
+
: '/' + remoteStylesheetToIntercept;
|
|
76
|
+
remoteStylesheetToIntercept = `${baseUrl}${stylesheetPath}`;
|
|
77
|
+
}
|
|
78
|
+
// Priority: CLI args > env vars > config file > defaults
|
|
79
|
+
return {
|
|
80
|
+
remoteEnvironmentUrl: remoteEnvironmentUrl,
|
|
81
|
+
remoteScriptToIntercept: remoteScriptToIntercept,
|
|
82
|
+
remoteStylesheetToIntercept: remoteStylesheetToIntercept,
|
|
83
|
+
localCssPath: options.css ||
|
|
84
|
+
process.env.LOCAL_CSS_PATH ||
|
|
85
|
+
fileConfig.localCssPath ||
|
|
86
|
+
path_1.default.join(__dirname, 'dist', 'local-control-styles.css'),
|
|
87
|
+
localBundlePath: options.bundle ||
|
|
88
|
+
process.env.LOCAL_BUNDLE_PATH ||
|
|
89
|
+
fileConfig.localBundlePath ||
|
|
90
|
+
path_1.default.join(__dirname, 'dist', 'local-control-bundle.js')
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function runSession(remoteEnvironmentUrl, remoteScriptToIntercept, remoteStylesheetToIntercept, localBundlePath, localCssPath) {
|
|
94
|
+
const REMOTE_ENVIRONMENT_URL = remoteEnvironmentUrl;
|
|
95
|
+
const REMOTE_SCRIPT_TO_INTERCEPT = remoteScriptToIntercept;
|
|
96
|
+
const REMOTE_STYLESHEET_TO_INTERCEPT = remoteStylesheetToIntercept;
|
|
97
|
+
const LOCAL_BUNDLE_PATH = path_1.default.resolve(localBundlePath);
|
|
98
|
+
const LOCAL_CSS_PATH = path_1.default.resolve(localCssPath);
|
|
99
|
+
// Debug logging for URL construction
|
|
100
|
+
color_logger_1.default.debug('š Debug - Final URLs:');
|
|
101
|
+
color_logger_1.default.debug(` Remote Environment: ${REMOTE_ENVIRONMENT_URL}`);
|
|
102
|
+
color_logger_1.default.debug(` Script to intercept: ${REMOTE_SCRIPT_TO_INTERCEPT}`);
|
|
103
|
+
color_logger_1.default.debug(` CSS to intercept: ${REMOTE_STYLESHEET_TO_INTERCEPT}`);
|
|
104
|
+
color_logger_1.default.debug(` Local bundle path: ${LOCAL_BUNDLE_PATH}`);
|
|
105
|
+
color_logger_1.default.debug(` Local CSS path: ${LOCAL_CSS_PATH}`);
|
|
106
|
+
color_logger_1.default.debug('');
|
|
107
|
+
// Path to store your session cookies
|
|
108
|
+
const AUTH_DIR = path_1.default.join(__dirname, '.auth');
|
|
109
|
+
const STATE_FILE = path_1.default.join(AUTH_DIR, 'state.json');
|
|
110
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
color_logger_1.default.log('š Starting ephemeral browser session...');
|
|
112
|
+
// 1. Prepare context options (load session if it exists)
|
|
113
|
+
let contextOptions = {};
|
|
114
|
+
if (fs_1.default.existsSync(STATE_FILE)) {
|
|
115
|
+
color_logger_1.default.log('š Loading previous login session...');
|
|
116
|
+
contextOptions.storageState = STATE_FILE;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
color_logger_1.default.log('ā ļø No previous session found. You may need to log in.');
|
|
120
|
+
}
|
|
121
|
+
// 2. Launch browser and apply context
|
|
122
|
+
const browser = yield playwright_1.chromium.launch({ headless: false });
|
|
123
|
+
const context = yield browser.newContext(Object.assign(Object.assign({}, contextOptions), { viewport: null // Use the actual browser window size
|
|
124
|
+
}));
|
|
125
|
+
// Shared cleanup function to save state and close browser
|
|
126
|
+
const cleanup = (...args_1) => __awaiter(this, [...args_1], void 0, function* (reason = 'unknown') {
|
|
127
|
+
try {
|
|
128
|
+
color_logger_1.default.log(`š¾ Saving session state (${reason})...`);
|
|
129
|
+
// Ensure the .auth directory exists before saving
|
|
130
|
+
if (!fs_1.default.existsSync(AUTH_DIR)) {
|
|
131
|
+
fs_1.default.mkdirSync(AUTH_DIR, { recursive: true });
|
|
132
|
+
}
|
|
133
|
+
if (!browser.isConnected()) {
|
|
134
|
+
color_logger_1.default.log('Browser already disconnected.');
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// Save the cookies and local storage to the JSON file
|
|
138
|
+
yield context.storageState({ path: STATE_FILE });
|
|
139
|
+
color_logger_1.default.log('š Tearing down rules and session.');
|
|
140
|
+
yield browser.close();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
color_logger_1.default.error('Error during cleanup:', error);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
// Handle process exit signals
|
|
148
|
+
process.on('SIGINT', () => __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
yield cleanup('SIGINT');
|
|
150
|
+
process.exit(0);
|
|
151
|
+
}));
|
|
152
|
+
process.on('SIGTERM', () => __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
yield cleanup('SIGTERM');
|
|
154
|
+
process.exit(0);
|
|
155
|
+
}));
|
|
156
|
+
process.on('beforeExit', () => __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
yield cleanup('beforeExit');
|
|
158
|
+
}));
|
|
159
|
+
// Handle uncaught exceptions
|
|
160
|
+
process.on('uncaughtException', (error) => __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
color_logger_1.default.error('Uncaught exception:', error);
|
|
162
|
+
yield cleanup('uncaughtException');
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}));
|
|
165
|
+
process.on('unhandledRejection', (reason) => __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
color_logger_1.default.error('Unhandled promise rejection:', reason);
|
|
167
|
+
yield cleanup('unhandledRejection');
|
|
168
|
+
process.exit(1);
|
|
169
|
+
}));
|
|
170
|
+
// Handle browser disconnect
|
|
171
|
+
browser.on('disconnected', () => __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
color_logger_1.default.log('Browser disconnected');
|
|
173
|
+
yield cleanup('browser disconnected');
|
|
174
|
+
}));
|
|
175
|
+
// Handle context close (when all pages in context are closed)
|
|
176
|
+
context.on('close', () => __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
color_logger_1.default.log('Browser context closed');
|
|
178
|
+
yield cleanup('context closed');
|
|
179
|
+
process.exit(0);
|
|
180
|
+
}));
|
|
181
|
+
// 3. Programmatically apply your network interception rule with pattern matching
|
|
182
|
+
// Handle dynamic version segments in CRM URLs like /version?/webresources/...
|
|
183
|
+
const scriptPattern = REMOTE_SCRIPT_TO_INTERCEPT.replace(/^https?:\/\/[^\/]+/, '');
|
|
184
|
+
const stylesheetPattern = REMOTE_STYLESHEET_TO_INTERCEPT.replace(/^https?:\/\/[^\/]+/, '');
|
|
185
|
+
color_logger_1.default.debug(`š” Setting up interception patterns:`);
|
|
186
|
+
color_logger_1.default.debug(` Script pattern: **${scriptPattern}`);
|
|
187
|
+
color_logger_1.default.debug(` CSS pattern: **${stylesheetPattern}`);
|
|
188
|
+
yield context.route(route => {
|
|
189
|
+
if (!route.href) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
// Match script URLs that end with the same path structure
|
|
193
|
+
return route.href.includes(scriptPattern) && route.href.includes('bundle.js');
|
|
194
|
+
}, (route) => __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
color_logger_1.default.log(`ā
Intercepted script request: ${route.request().url()}`);
|
|
196
|
+
color_logger_1.default.log(` Serving local file: ${LOCAL_BUNDLE_PATH}`);
|
|
197
|
+
route.fulfill({
|
|
198
|
+
status: 200,
|
|
199
|
+
contentType: 'application/javascript',
|
|
200
|
+
body: fs_1.default.readFileSync(LOCAL_BUNDLE_PATH)
|
|
201
|
+
});
|
|
202
|
+
}));
|
|
203
|
+
yield context.route(route => {
|
|
204
|
+
if (!route.href) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
// Match CSS URLs that end with the same path structure
|
|
208
|
+
return route.href.includes(stylesheetPattern) && route.href.includes('ItemDescriptionPCF.css');
|
|
209
|
+
}, (route) => __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
color_logger_1.default.log(`ā
Intercepted CSS request: ${route.request().url()}`);
|
|
211
|
+
color_logger_1.default.log(` Serving local file: ${LOCAL_CSS_PATH}`);
|
|
212
|
+
route.fulfill({
|
|
213
|
+
status: 200,
|
|
214
|
+
contentType: 'text/css',
|
|
215
|
+
body: fs_1.default.readFileSync(LOCAL_CSS_PATH)
|
|
216
|
+
});
|
|
217
|
+
}));
|
|
218
|
+
// 4. Open a new tab and navigate to your remote environment
|
|
219
|
+
const page = yield context.newPage();
|
|
220
|
+
yield page.goto(REMOTE_ENVIRONMENT_URL);
|
|
221
|
+
// 5. Clean up and save state when the page is closed (but others may still be open)
|
|
222
|
+
page.on('close', () => __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
const pages = context.pages();
|
|
224
|
+
if (pages.length <= 1) {
|
|
225
|
+
// This was the last page, trigger full cleanup
|
|
226
|
+
yield cleanup('last page closed');
|
|
227
|
+
process.exit(0);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
color_logger_1.default.debug(`Page closed, but ${pages.length - 1} pages still open. Keeping session alive.`);
|
|
231
|
+
}
|
|
232
|
+
}));
|
|
233
|
+
// 6. Watch the local bundle for changes and auto-reload
|
|
234
|
+
let reloadTimeout;
|
|
235
|
+
fs_1.default.watch(LOCAL_BUNDLE_PATH, (eventType) => {
|
|
236
|
+
if (eventType === 'change') {
|
|
237
|
+
// Clear the previous timer if the file changes again quickly
|
|
238
|
+
clearTimeout(reloadTimeout);
|
|
239
|
+
// Wait 300ms for the bundler to finish writing the file before reloading
|
|
240
|
+
reloadTimeout = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
color_logger_1.default.log(`\nš Local bundle updated! Reloading the page...`);
|
|
242
|
+
try {
|
|
243
|
+
yield page.reload();
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
color_logger_1.default.error('ā ļø Could not reload page (browser might be closed).', err);
|
|
247
|
+
}
|
|
248
|
+
}), 300);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}))();
|
|
252
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tywalk/pcf-helper",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.26",
|
|
4
4
|
"description": "Command line helper for building and publishing PCF controls to Dataverse.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "./types/",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"pcf-helper-build": "dist/bin/build.js",
|
|
27
27
|
"pcf-helper-import": "dist/bin/import.js",
|
|
28
28
|
"pcf-helper-deploy": "dist/bin/deploy.js",
|
|
29
|
-
"pcf-helper-init": "dist/bin/init.js"
|
|
29
|
+
"pcf-helper-init": "dist/bin/init.js",
|
|
30
|
+
"pcf-helper-session": "dist/bin/session.js"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@types/jest": "^29.5.14",
|
|
@@ -36,6 +37,8 @@
|
|
|
36
37
|
"typescript": "^5.8.2"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@tywalk/color-logger": "^1.0.3"
|
|
40
|
+
"@tywalk/color-logger": "^1.0.3",
|
|
41
|
+
"commander": "^14.0.3",
|
|
42
|
+
"playwright": "^1.58.2"
|
|
40
43
|
}
|
|
41
44
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/types/tasks/index.d.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare function loadConfig(): {
|
|
2
|
+
remoteEnvironmentUrl: any;
|
|
3
|
+
remoteScriptToIntercept: any;
|
|
4
|
+
remoteStylesheetToIntercept: any;
|
|
5
|
+
localCssPath: any;
|
|
6
|
+
localBundlePath: any;
|
|
7
|
+
};
|
|
8
|
+
declare function runSession(remoteEnvironmentUrl: string, remoteScriptToIntercept: string, remoteStylesheetToIntercept: string, localBundlePath: string, localCssPath: string): void;
|
|
9
|
+
export { runSession, loadConfig };
|