Skip to content

Commit 83d5a37

Browse files
fix(cc-widgets): ship-all-widgets-together (#345)
Co-authored-by: Shreyas Sharma <shreysh2@cisco.com>
1 parent 60b4f65 commit 83d5a37

File tree

22 files changed

+309
-107
lines changed

22 files changed

+309
-107
lines changed

docs/react-samples/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
"@babel/preset-env": "^7.25.4",
1414
"@babel/preset-react": "^7.24.7",
1515
"@babel/preset-typescript": "^7.25.9",
16-
"@r2wc/react-to-web-component": "^2.0.3",
17-
"@webex/cc-station-login": "workspace:*",
18-
"@webex/cc-user-state": "workspace:*",
16+
"@webex/cc-widgets": "workspace:*",
1917
"babel-loader": "^9.2.1",
2018
"file-loader": "^6.2.0",
2119
"html-webpack-plugin": "^5.6.3",

docs/react-samples/src/App.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import React, { useEffect, useState } from 'react';
2-
import store from '@webex/cc-store'
3-
import {StationLogin} from '@webex/cc-station-login';
4-
import {UserState} from '@webex/cc-user-state';
1+
import React, { useState } from 'react';
2+
import {StationLogin, UserState, store} from '@webex/cc-widgets'
53

64
function App() {
75
const [isSdkReady, setIsSdkReady] = useState(false);

docs/web-component-samples/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"version": "1.0.0",
44
"main": "dist/index.js",
55
"dependencies": {
6-
"@webex/cc-station-login": "workspace:*",
7-
"@webex/cc-user-state": "workspace:*",
6+
"@webex/cc-widgets": "workspace:*",
87
"html-webpack-plugin": "^5.6.3",
98
"ts-loader": "^9.5.1",
109
"typescript": "^5.6.3",
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import store from '@webex/cc-store';
2-
import '@webex/cc-station-login';
3-
import '@webex/cc-user-state';
4-
5-
// @ts-ignore
6-
window.store = store;
1+
import {store} from '@webex/cc-widgets/wc';
2+
// @ts-ignore
3+
window.store = store;

docs/web-component-samples/tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"compilerOptions": {
44
"outDir": "./dist",
55
"declaration": false,
6-
"declarationDir": null
6+
"declarationDir": null,
7+
"moduleResolution": "NodeNext",
8+
"module": "NodeNext"
79
},
810
"include": [
911
"./src"
10-
]
12+
],
1113
}

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@
3535
"scripts": {
3636
"test:unit": "yarn run test:tooling && yarn run test:cc-widgets",
3737
"test:tooling": "jest --coverage",
38-
"test:cc-widgets": "yarn run test:store && yarn run test:widgets",
39-
"test:store": "yarn workspace @webex/cc-store test:unit",
40-
"test:widgets": "yarn workspace @webex/cc-station-login test:unit && yarn workspace @webex/cc-user-state test:unit",
41-
"build": "yarn run build:store && yarn run build:widgets",
42-
"build:store": "yarn workspace @webex/cc-store build:src",
43-
"build:widgets": "yarn workspace @webex/cc-station-login build:src && yarn workspace @webex/cc-user-state build:src",
38+
"test:cc-widgets": "yarn workspaces foreach --all --parallel --exclude webex-widgets --exclude @webex/web-component-samples-app --exclude @webex/react-samples-app run test:unit",
39+
"build": "yarn workspaces foreach --all --topological --parallel --exclude webex-widgets --exclude @webex/web-component-samples-app --exclude @webex/react-samples-app run build:src",
4440
"samples:build": "yarn workspace @webex/react-samples-app build:src && yarn workspace @webex/web-component-samples-app build:src",
4541
"samples:serve": "open docs/index.html && yarn workspace @webex/react-samples-app serve",
4642
"samples:serve-react": "yarn workspace @webex/react-samples-app serve",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('../../../.babelrc');
2+
3+
module.exports = baseConfig;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"name": "@webex/cc-widgets",
3+
"description": "Webex Contact Center Widgets",
4+
"version": "1.0.0",
5+
"main": "dist/index.js",
6+
"publishConfig": {
7+
"access": "public"
8+
},
9+
"files": [
10+
"dist/",
11+
"package.json"
12+
],
13+
"exports": {
14+
".": "./dist/index.js",
15+
"./wc": "./dist/wc.js"
16+
},
17+
"scripts": {
18+
"build": "yarn run -T tsc",
19+
"build:src": "webpack && yarn run build",
20+
"build:watch": "webpack --watch",
21+
"test:unit": "jest"
22+
},
23+
"dependencies": {
24+
"@r2wc/react-to-web-component": "2.0.3",
25+
"@webex/cc-station-login": "workspace:*",
26+
"@webex/cc-store": "workspace:*",
27+
"@webex/cc-user-state": "workspace:*"
28+
},
29+
"devDependencies": {
30+
"@babel/core": "7.25.2",
31+
"@babel/preset-env": "7.25.4",
32+
"@babel/preset-react": "7.24.7",
33+
"@babel/preset-typescript": "7.25.9",
34+
"@testing-library/dom": "10.4.0",
35+
"@testing-library/jest-dom": "6.6.2",
36+
"@testing-library/react": "16.0.1",
37+
"@types/jest": "29.5.14",
38+
"@types/react-test-renderer": "18",
39+
"babel-jest": "29.7.0",
40+
"babel-loader": "9.2.1",
41+
"crypto-browserify": "^3.12.1",
42+
"file-loader": "6.2.0",
43+
"jest": "29.7.0",
44+
"jest-environment-jsdom": "29.7.0",
45+
"mobx-react": "9.1.1",
46+
"os-browserify": "^0.3.0",
47+
"process": "^0.11.10",
48+
"querystring-es3": "^0.2.1",
49+
"react": "18.3.1",
50+
"react-dom": "18.3.1",
51+
"stream-browserify": "^3.0.0",
52+
"ts-loader": "9.5.1",
53+
"typescript": "5.6.3",
54+
"url": "^0.11.4",
55+
"util": "^0.12.5",
56+
"vm-browserify": "^1.1.2",
57+
"webpack": "5.94.0",
58+
"webpack-cli": "5.1.4",
59+
"webpack-merge": "6.0.1"
60+
},
61+
"jest": {
62+
"testEnvironment": "jsdom",
63+
"//": "We can remove this when we have tests",
64+
"passWithNoTests": true,
65+
"testMatch": [
66+
"**/tests/**/*.ts",
67+
"**/tests/**/*.tsx"
68+
]
69+
}
70+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {StationLogin} from '@webex/cc-station-login';
2+
import {UserState} from '@webex/cc-user-state';
3+
import store from '@webex/cc-store';
4+
5+
export {StationLogin, UserState, store};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import r2wc from '@r2wc/react-to-web-component';
2+
import {StationLogin} from '@webex/cc-station-login';
3+
import {UserState} from '@webex/cc-user-state';
4+
import store from '@webex/cc-store';
5+
6+
const WebUserState = r2wc(UserState);
7+
8+
const WebStationLogin = r2wc(StationLogin, {
9+
props: {
10+
onLogin: 'function',
11+
onLogout: 'function',
12+
},
13+
});
14+
15+
if (!customElements.get('widget-cc-user-state')) {
16+
customElements.define('widget-cc-user-state', WebUserState);
17+
}
18+
19+
if (!customElements.get('widget-cc-station-login')) {
20+
customElements.define('widget-cc-station-login', WebStationLogin);
21+
}
22+
23+
export {store};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../../../tsconfig.json",
3+
"include": [
4+
"./src"
5+
],
6+
"compilerOptions": {
7+
"outDir": "./dist",
8+
"declaration": true,
9+
"declarationDir": "./dist/types"
10+
},
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const {merge} = require('webpack-merge');
2+
const path = require('path');
3+
4+
const baseConfig = require('../../../webpack.config');
5+
6+
module.exports = merge(baseConfig, {
7+
output: {
8+
path: path.resolve(__dirname, 'dist'),
9+
filename: 'index.js', // Set the output filename to index.js
10+
libraryTarget: 'commonjs2',
11+
},
12+
});

packages/contact-center/station-login/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"test:unit": "jest"
1818
},
1919
"dependencies": {
20-
"@r2wc/react-to-web-component": "2.0.3",
2120
"@webex/cc-store": "workspace:*",
2221
"mobx-react": "9.1.1",
2322
"react": "18.3.1",
@@ -49,7 +48,8 @@
4948
"testMatch": [
5049
"**/tests/**/*.ts",
5150
"**/tests/**/*.tsx"
52-
]
51+
],
52+
"verbose": true
5353
},
5454
"stableVersion": "1.28.0-ccwidgets.2"
5555
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import {StationLogin, WebStationLogin} from './station-login';
1+
import {StationLogin} from './station-login';
22

3-
export {StationLogin, WebStationLogin};
3+
export {StationLogin};
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React from 'react';
2-
import r2wc from '@r2wc/react-to-web-component';
32
import store from '@webex/cc-store';
43
import {observer} from 'mobx-react';
54

65
import StationLoginPresentational from './station-login.presentational';
76
import {useStationLogin} from '../helper';
8-
import { StationLoginProps } from './station-login.types';
7+
import {StationLoginProps} from './station-login.types';
98

109
const StationLogin: React.FunctionComponent<StationLoginProps> = observer(({onLogin, onLogout}) => {
1110
const {cc, teams, loginOptions} = store;
@@ -14,20 +13,9 @@ const StationLogin: React.FunctionComponent<StationLoginProps> = observer(({onLo
1413
const props = {
1514
...result,
1615
teams,
17-
loginOptions
16+
loginOptions,
1817
};
1918
return <StationLoginPresentational {...props} />;
2019
});
2120

22-
const WebStationLogin = r2wc(StationLogin, {
23-
props: {
24-
onLogin: "function",
25-
onLogout: "function"
26-
}
27-
});
28-
29-
if (!customElements.get('widget-cc-station-login')) {
30-
customElements.define('widget-cc-station-login', WebStationLogin);
31-
}
32-
33-
export {StationLogin, WebStationLogin};
21+
export {StationLogin};

packages/contact-center/user-state/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"test:unit": "jest"
1818
},
1919
"dependencies": {
20-
"@r2wc/react-to-web-component": "2.0.3",
2120
"@webex/cc-store": "workspace:*",
2221
"mobx-react": "9.1.1",
2322
"react": "18.3.1",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import {UserState, WebUserState} from './user-state/index';
1+
import {UserState} from './user-state/index';
22

3-
export {UserState, WebUserState};
3+
export {UserState};

packages/contact-center/user-state/src/user-state/index.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import store from '@webex/cc-store';
33
import {observer} from 'mobx-react';
4-
import r2wc from '@r2wc/react-to-web-component';
54

65
import {useUserState} from '../helper';
76
import UserStatePresentational from './user-state.presentational';
@@ -18,10 +17,4 @@ const UserState: React.FunctionComponent = observer(() => {
1817
return <UserStatePresentational {...props} />;
1918
});
2019

21-
const WebUserState = r2wc(UserState);
22-
23-
if (!customElements.get('widget-cc-user-state')) {
24-
customElements.define('widget-cc-user-state', WebUserState);
25-
}
26-
27-
export {UserState, WebUserState};
20+
export {UserState};

tooling/src/publish.js

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function removeStableVersion(packageJsonPath, packageData) {
1313
console.log("'stableVersion' key does not exist in package.json.");
1414
}
1515
} catch (error) {
16-
throw new Error("An error occurred while removing 'stableVersion':", error.message);
16+
throw new Error(`An error occurred while removing 'stableVersion': ${error.message}`);
1717
}
1818
}
1919

@@ -28,46 +28,42 @@ function versionAndPublish() {
2828
process.exit(1);
2929
}
3030
const contactCenterPath = './packages/contact-center';
31-
const dependencies = ['@webex/cc-store'];
3231

3332
try {
34-
const ccFolder = fs
33+
const workspaceData = fs
3534
.readdirSync(contactCenterPath, {withFileTypes: true})
36-
.filter((dirent) => {
37-
return dirent.isDirectory();
38-
})
35+
.filter((dirent) => dirent.isDirectory())
3936
.map((dirent) => {
40-
try {
41-
const packageJsonPath = path.join(contactCenterPath, dirent.name, 'package.json');
42-
const packageData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
43-
44-
console.log(`Removing stable version from package.json for ${dirent.name}`);
45-
removeStableVersion(packageJsonPath, packageData);
46-
return packageData.name;
47-
} catch (error) {
48-
throw new Error(`Error reading package.json in ${dirent.name}`, error);
37+
const packageJsonPath = path.join(contactCenterPath, dirent.name, 'package.json');
38+
if (!fs.existsSync(packageJsonPath)) {
39+
throw new Error(`package.json not found in ${dirent.name}`);
4940
}
50-
});
51-
// Separate dependency workspaces and other workspaces
52-
const dependencyWorkspaces = ccFolder.filter((fileName) => dependencies.includes(fileName));
41+
const packageData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
5342

54-
const otherWorkspaces = ccFolder.filter((fileName) => !dependencies.includes(fileName));
55-
56-
const publishWorkspace = (workspaceName) => {
57-
console.log(`Publishing new version for ${workspaceName}: ${newVersion}`);
43+
console.log(`Removing stable version from package.json for ${dirent.name}`);
44+
removeStableVersion(packageJsonPath, packageData); // Assuming this function is defined elsewhere
45+
return packageData.name;
46+
});
5847

59-
// Update version in the workspace
60-
execSync(`yarn workspace ${workspaceName} version ${newVersion}`, {stdio: 'inherit'});
48+
// Update version in the workspace
49+
const updateVersions = (workspace) => {
50+
console.log(`Publishing new version for ${workspace}: ${newVersion}`);
51+
execSync(`yarn workspace ${workspace} version ${newVersion}`, {stdio: 'inherit'});
52+
};
6153

62-
// Publish the package
63-
execSync(`yarn workspace ${workspaceName} npm publish --tag ${branchName}`, {stdio: 'inherit'});
54+
// Publish the package
55+
const publishWorkspace = (workspace) => {
56+
console.log(`Updating version for ${workspace}: ${newVersion}`);
57+
execSync(`yarn workspace ${workspace} npm publish --tag ${branchName}`, {stdio: 'inherit'});
6458
};
6559

66-
// Publish dependencies first
67-
dependencyWorkspaces.forEach(publishWorkspace);
60+
for (const workspace of workspaceData) {
61+
updateVersions(workspace);
62+
}
6863

69-
// Publish other packages
70-
otherWorkspaces.forEach(publishWorkspace);
64+
for (const workspace of workspaceData) {
65+
publishWorkspace(workspace);
66+
}
7167
} catch (error) {
7268
console.error(`Failed to process workspaces:`, error.message);
7369
process.exit(1);

0 commit comments

Comments
 (0)