Skip to content

Commit f8fdbc5

Browse files
authored
feat: Automation script for updating dependencies in angular-sdk (#384)
* feat: Automation script for updating dependencies in angular-sdk * fix: corrected import of componentMapper
1 parent 5135a10 commit f8fdbc5

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"build-angular-sdk-components": "ng build angular-sdk-components && node scripts/copy-map.js && node ./scripts/copy-npm-assets-to-components.js",
5050
"prod-build-angularsdk": "shx rm -rf ./dist && npm run prod-build && npm run copy-index && npm run make-mashup-dir && npm run compress-angularsdk",
5151
"start": "npm run ng serve",
52+
"create_and_install_sdk_packages": "node scripts/update-dependencies.js",
5253
"_comment_2": "Commands related to running tests against the Angular SDK",
5354
"test": "node ./scripts/playwright-message.js && playwright test --project=chromium MediaCo/portal MediaCo/embedded",
5455
"test:headed": "playwright test --headed --project=chromium MediaCo/portal MediaCo/embedded",

packages/angular-sdk-components/src/lib/_components/field/cancel-alert/cancel-alert.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CommonModule } from '@angular/common';
33
import { MatButtonModule } from '@angular/material/button';
44
import { MatGridListModule } from '@angular/material/grid-list';
55
import { ProgressSpinnerService } from '../../../_messages/progress-spinner.service';
6-
import { ComponentMapperComponent } from 'packages/angular-sdk-components/src/public-api';
6+
import { ComponentMapperComponent } from '../../../_bridge/component-mapper/component-mapper.component';
77

88
@Component({
99
selector: 'app-cancel-alert',

scripts/update-dependencies.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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 componentsInPackagePath = path.join(componentsProjectRootPath, 'packages', 'angular-sdk-components');
9+
const overridesPackagePath = path.join(componentsProjectRootPath, 'packages', 'angular-sdk-overrides');
10+
const distInComponentsPath = path.join(componentsProjectRootPath, 'dist');
11+
const componentsInDistPath = path.join(distInComponentsPath, 'angular-sdk-components');
12+
13+
/** Create readline interface to ask for angular-sdk project path */
14+
const readLineInterface = readline.createInterface({
15+
input: process.stdin,
16+
output: process.stdout
17+
});
18+
19+
readLineInterface.question('Please enter the absolute path of angular-sdk project: ', sdkProjectPathInput => {
20+
readLineInterface.close();
21+
const sdkProjectRootPath = path.resolve(sdkProjectPathInput);
22+
23+
/** Delete existing dist folder before build */
24+
if (fs.existsSync(distInComponentsPath)) {
25+
console.log(`---- Removing existing dist folder: ${distInComponentsPath} ----`);
26+
fs.rmSync(distInComponentsPath, { recursive: true, force: true });
27+
}
28+
29+
/** Build angular-sdk-components in packages folder */
30+
console.log(`---- Building angular-sdk-components at: ${componentsInPackagePath} ----`);
31+
execFileSync('ng', ['build', 'angular-sdk-components'], { cwd: componentsInPackagePath, stdio: 'inherit' });
32+
33+
/** Package angular-sdk-components in dist folder */
34+
console.log(`---- Packing npm package in: ${componentsInDistPath} ----`);
35+
execFileSync('npm', ['pack'], { cwd: componentsInDistPath, stdio: 'inherit' });
36+
37+
/** Find the generated 'angular-sdk-components' .tgz file */
38+
const componentsTgzFile = fs
39+
.readdirSync(componentsInDistPath)
40+
.find(file => file.endsWith('.tgz') && file.indexOf('pega-angular-sdk-components') > -1);
41+
if (!componentsTgzFile) {
42+
throw new Error('No .tgz file found in dist folder!');
43+
}
44+
45+
const componentsTgzPath = path.join(path.join(distInComponentsPath, 'angular-sdk-components'), componentsTgzFile);
46+
const componentTargetTgzPath = path.join(sdkProjectRootPath, componentsTgzFile);
47+
48+
/** Delete components .tgz file if exists in angular-sdk folder */
49+
const existingTgzInSDK = fs
50+
.readdirSync(sdkProjectRootPath)
51+
.find(file => file.endsWith('.tgz') && file.indexOf('pega-angular-sdk-components') > -1);
52+
if (existingTgzInSDK) {
53+
console.log(`---- Removing old package: ${existingTgzInSDK} ----`);
54+
fs.unlinkSync(path.join(sdkProjectRootPath, existingTgzInSDK));
55+
}
56+
57+
console.log(`---- Copying ${componentsTgzFile} to angular-sdk folder: ${sdkProjectRootPath} ----`);
58+
fs.copyFileSync(componentsTgzPath, componentTargetTgzPath);
59+
60+
/** Build and package 'angular-sdk-overrides' */
61+
62+
/** Delete existing .tgz file before building */
63+
const existingOverridesTgzInComponents = fs
64+
.readdirSync(overridesPackagePath)
65+
.find(file => file.endsWith('.tgz') && file.indexOf('pega-angular-sdk-overrides') > -1);
66+
if (existingOverridesTgzInComponents) {
67+
console.log(`---- Removing existing tgz: ${existingOverridesTgzInComponents} ----`);
68+
fs.unlinkSync(path.join(overridesPackagePath, existingOverridesTgzInComponents));
69+
}
70+
71+
console.log('Building angular-sdk-overrides.......');
72+
execFileSync('npm', ['run', 'build-sdk'], { cwd: componentsProjectRootPath, stdio: 'inherit' });
73+
execFileSync('npm', ['run', 'build-overrides'], { cwd: componentsProjectRootPath, stdio: 'inherit' });
74+
execFileSync('npm', ['pack'], { cwd: overridesPackagePath, stdio: 'inherit' });
75+
76+
const overridesTgzFile = fs
77+
.readdirSync(overridesPackagePath)
78+
.find(file => file.endsWith('.tgz') && file.indexOf('pega-angular-sdk-overrides') > -1);
79+
if (!overridesTgzFile) {
80+
throw new Error('No overrides .tgz file found');
81+
}
82+
83+
const overridesTgzPath = path.join(overridesPackagePath, overridesTgzFile);
84+
const overridesTargetTgzPath = path.join(sdkProjectRootPath, overridesTgzFile);
85+
86+
const existingOverridesTgzInSDK = fs
87+
.readdirSync(sdkProjectRootPath)
88+
.find(file => file.endsWith('.tgz') && file.indexOf('pega-angular-sdk-overrides') > -1);
89+
if (existingOverridesTgzInSDK) {
90+
console.log(`---- Removing old package: ${existingOverridesTgzInSDK} ----`);
91+
fs.unlinkSync(path.join(sdkProjectRootPath, existingOverridesTgzInSDK));
92+
}
93+
94+
console.log(`---- Copying ${overridesTgzFile} to angular-sdk folder: ${sdkProjectRootPath} ----`);
95+
fs.copyFileSync(overridesTgzPath, overridesTargetTgzPath);
96+
97+
/** Install the built packages in angular-sdk project */
98+
console.log(`---- Installing ${componentsTgzFile} in angular-sdk ----`);
99+
execFileSync('npm', ['install', `./${componentsTgzFile}`], { cwd: sdkProjectRootPath, stdio: 'inherit' });
100+
console.log("Done!!! 'angular-sdk' now uses local build of angular-sdk-components.");
101+
console.log(`---- Installing ${overridesTgzFile} in angular-sdk ----`);
102+
execFileSync('npm', ['install', `./${overridesTgzFile}`], { cwd: sdkProjectRootPath, stdio: 'inherit' });
103+
console.log("Done!!! 'angular-sdk' now uses local build of angular-sdk-overrides.");
104+
});
105+
} catch (error) {
106+
console.error('Error:', error.message);
107+
process.exit(1);
108+
}

0 commit comments

Comments
 (0)