Skip to content

Commit 72701b9

Browse files
authored
Added script to pack react-sdk-components and install in react-sdk repo (#565)
* Added script to pack react-sdk-components and install in react-sdk repo * lint fix
1 parent 3fc844c commit 72701b9

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"start-dev-https": "webpack serve --server-type https --mode=development",
4040
"start-prod": "http-server ./dist --port 3502 --ext html -c-1 --gzip --brotli --cors --proxy http://localhost:3502?",
4141
"start-prod-https": "http-server ./dist --port 3502 --ext html -c-1 --gzip --brotli --cors --ssl --cert ./keys/sdk-r.crt --key ./keys/sdk-r.key --proxy https://localhost:3502?",
42+
"create_and_install_sdk_packages": "node scripts/update-dependencies.js",
4243
"test": "node scripts/playwright-message.js && playwright test --project=chromium MediaCo/portal MediaCo/embedded",
4344
"test:headed": "playwright test --headed --project=chromium MediaCo/portal MediaCo/embedded",
4445
"test-report": "playwright show-report tests/playwright-report",

scripts/update-dependencies.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const { execFileSync } = require('child_process');
2+
const path = require('path');
3+
const fs = require('fs');
4+
const readline = require('readline');
5+
6+
try {
7+
const componentsProjectRootPath = process.cwd();
8+
const componentsPackagePath = path.join(componentsProjectRootPath, 'packages', 'react-sdk-components');
9+
10+
const readLineInterface = readline.createInterface({
11+
input: process.stdin,
12+
output: process.stdout
13+
});
14+
15+
readLineInterface.question('Please enter the absolute path of react-sdk project: ', sdkProjectPathInput => {
16+
readLineInterface.close();
17+
18+
const sdkProjectRootPath = path.resolve(sdkProjectPathInput.trim());
19+
20+
if (!fs.existsSync(sdkProjectRootPath)) {
21+
throw new Error(`Path does not exist: ${sdkProjectRootPath}`);
22+
}
23+
24+
if (!fs.existsSync(path.join(sdkProjectRootPath, 'package.json'))) {
25+
throw new Error(`No package.json found at: ${sdkProjectRootPath}`);
26+
}
27+
28+
const existingTgzInComponents = fs
29+
.readdirSync(componentsPackagePath)
30+
.find(file => file.endsWith('.tgz') && file.indexOf('pega-react-sdk-components') > -1);
31+
32+
if (existingTgzInComponents) {
33+
console.log(`---- Removing existing tgz: ${existingTgzInComponents} ----`);
34+
fs.unlinkSync(path.join(componentsPackagePath, existingTgzInComponents));
35+
}
36+
37+
console.log(`---- Building react-sdk-components at: ${componentsProjectRootPath} ----`);
38+
execFileSync('npm', ['run', 'build-sdk'], { cwd: componentsProjectRootPath, stdio: 'inherit' });
39+
40+
console.log(`---- Packing npm package in: ${componentsPackagePath} ----`);
41+
execFileSync('npm', ['pack'], { cwd: componentsPackagePath, stdio: 'inherit' });
42+
43+
const componentsTgzFile = fs
44+
.readdirSync(componentsPackagePath)
45+
.find(file => file.endsWith('.tgz') && file.indexOf('pega-react-sdk-components') > -1);
46+
47+
if (!componentsTgzFile) {
48+
throw new Error('No react-sdk-components .tgz file found after packing.');
49+
}
50+
51+
const componentsTgzPath = path.join(componentsPackagePath, componentsTgzFile);
52+
const componentTargetTgzPath = path.join(sdkProjectRootPath, componentsTgzFile);
53+
54+
const existingTgzInSDK = fs.readdirSync(sdkProjectRootPath).find(file => file.endsWith('.tgz') && file.indexOf('pega-react-sdk-components') > -1);
55+
56+
if (existingTgzInSDK) {
57+
console.log(`---- Removing old package: ${existingTgzInSDK} ----`);
58+
fs.unlinkSync(path.join(sdkProjectRootPath, existingTgzInSDK));
59+
}
60+
61+
console.log(`---- Copying ${componentsTgzFile} to react-sdk folder: ${sdkProjectRootPath} ----`);
62+
fs.copyFileSync(componentsTgzPath, componentTargetTgzPath);
63+
64+
console.log(`---- Installing ${componentsTgzFile} in react-sdk ----`);
65+
execFileSync('npm', ['install', `./${componentsTgzFile}`], { cwd: sdkProjectRootPath, stdio: 'inherit' });
66+
67+
console.log("Done!!! 'react-sdk' now uses local build of react-sdk-components.");
68+
});
69+
} catch (error) {
70+
console.error('Error:', error.message);
71+
process.exit(1);
72+
}

0 commit comments

Comments
 (0)