Skip to content

Commit c398e88

Browse files
committed
types & package.json script
1 parent fe04c6b commit c398e88

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"postinstall": "husky && yarn setup",
3333
"create-cypress-commands-docs": "documentation build ./packages/cypress-commands/src/commands.ts -f json -o ./packages/cypress-commands/api-commands.json && documentation build ./packages/cypress-commands/src/queries.ts -f json -o ./packages/cypress-commands/api-queries.json",
3434
"sb:prepare-cem": "node packages/cli/dist/bin/index.js resolve-cem --packageName @ui5/webcomponents --out ./.storybook/custom-element-manifests/main.json && node packages/cli/dist/bin/index.js resolve-cem --packageName @ui5/webcomponents-fiori --out ./.storybook/custom-element-manifests/fiori.json && node packages/cli/dist/bin/index.js resolve-cem --packageName @ui5/webcomponents-ai --out ./.storybook/custom-element-manifests/ai.json",
35-
"create-theming-parameters": "node scripts/generate-theming-parameters.js"
35+
"create-theming-parameters": "node scripts/generate-theming-parameters.js",
36+
"create-exports": "node --experimental-strip-types scripts/create-export-paths.ts"
3637
},
3738
"dependencies": {
3839
"@stackblitz/sdk": "1.11.0",

scripts/create-export-paths.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,31 @@ import fs from 'fs';
33
import path from 'path';
44
import PATHS from '../config/paths.js';
55

6-
const TARGET_PACKAGES = ['ai', 'charts', 'compat', 'main'];
6+
const TARGET_PACKAGES = ['ai', 'charts', 'compat', 'main'] as const;
77
const INTERNAL_COMPONENTS = new Set(['ObjectPageAnchorBar', 'Splitter']);
88

9-
function getComponentExports(distDir, componentDir) {
9+
interface ExportEntry {
10+
types: string;
11+
default: string;
12+
}
13+
14+
interface ExportsObject {
15+
[key: string]: ExportEntry;
16+
}
17+
18+
function getComponentExports(distDir: string, componentDir: string): ExportsObject {
1019
const dir = path.join(distDir, componentDir);
1120
if (!fs.existsSync(dir)) return {};
1221

1322
const entries = fs.readdirSync(dir, { withFileTypes: true });
14-
const exportsObj = {};
23+
const exportsObj: ExportsObject = {};
1524

1625
entries.forEach((entry) => {
1726
if (entry.isDirectory()) {
1827
if (INTERNAL_COMPONENTS.has(entry.name)) {
1928
return;
2029
}
30+
2131
const jsPath = path.join(dir, entry.name, 'index.js');
2232
const dtsPath = path.join(dir, entry.name, 'index.d.ts');
2333

@@ -43,10 +53,11 @@ function getComponentExports(distDir, componentDir) {
4353

4454
return exportsObj;
4555
}
56+
4657
/**
4758
* Update the package.json of a given package
4859
*/
49-
function updatePackageJson(pkgPath) {
60+
function updatePackageJson(pkgPath: string): void {
5061
const packageJsonPath = path.join(pkgPath, 'package.json');
5162
const distDir = path.join(pkgPath, 'dist');
5263

@@ -55,14 +66,14 @@ function updatePackageJson(pkgPath) {
5566
return;
5667
}
5768

58-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
69+
const packageJson: Record<string, any> = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
5970
packageJson.exports = packageJson.exports || {};
6071

6172
// collect exports from "components" and "webComponents"
6273
const componentExports = getComponentExports(distDir, 'components');
6374
const webComponentExports = getComponentExports(distDir, 'webComponents');
6475

65-
const newExports = {
76+
const newExports: ExportsObject = {
6677
...componentExports,
6778
...webComponentExports,
6879
};
@@ -75,7 +86,8 @@ function updatePackageJson(pkgPath) {
7586
console.log(`✅ Updated exports in ${packageJsonPath}`);
7687
}
7788

89+
console.log('ℹ️ Make sure all packages are built before running this script!');
7890
TARGET_PACKAGES.forEach((pkg) => {
79-
const pkgPath = PATHS[pkg];
91+
const pkgPath = PATHS[pkg as keyof typeof PATHS];
8092
updatePackageJson(pkgPath);
8193
});

0 commit comments

Comments
 (0)