Skip to content

Commit d16413c

Browse files
committed
chore: Exposes more design tokens to be used by charts
1 parent 8ec9c2d commit d16413c

File tree

11 files changed

+1056
-6
lines changed

11 files changed

+1056
-6
lines changed

package-lock.json

Lines changed: 155 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"start:watch": "gulp watch",
2323
"start:dev": "cross-env NODE_ENV=development webpack serve --config pages/webpack.config.js",
2424
"start:integ": "cross-env NODE_ENV=development webpack serve --config pages/webpack.config.integ.js",
25-
"prepare": "husky"
25+
"prepare": "husky",
26+
"postinstall": "node ./scripts/install-peer-dependency.js theming-core:expose-size-tokens"
2627
},
2728
"dependencies": {
2829
"@cloudscape-design/collection-hooks": "^1.0.0",

scripts/install-peer-dependency.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env node
2+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// Can be used in postinstall script like so:
6+
// "postinstall": "node ./scripts/install-peer-dependency.js collection-hooks:property-filter-token-groups"
7+
// where "collection-hooks" is the package to fetch and "property-filter-token-groups" is the branch name in GitHub.
8+
9+
const { execSync } = require('child_process');
10+
const os = require('os');
11+
const path = require('path');
12+
13+
const getModules = packageName => {
14+
switch (packageName) {
15+
case 'components':
16+
return ['components', 'design-tokens'];
17+
case 'theming-core':
18+
return ['theming-build', 'theming-runtime'];
19+
default:
20+
return [packageName];
21+
}
22+
};
23+
24+
const getArtifactPath = moduleName => {
25+
switch (moduleName) {
26+
case 'components':
27+
return '/lib/components/*';
28+
case 'design-tokens':
29+
return '/lib/design-tokens/*';
30+
case 'board-components':
31+
return '/lib/components/*';
32+
case 'theming-build':
33+
return '/lib/node/*';
34+
case 'theming-runtime':
35+
return '/lib/browser/*';
36+
default:
37+
return '/lib/*';
38+
}
39+
};
40+
41+
const args = process.argv.slice(2);
42+
if (args.length < 1) {
43+
console.error('Usage: install-peer-dependency.js <package-name>:<target-branch>');
44+
process.exit(1);
45+
}
46+
const [packageName, targetBranch] = args[0].split(':');
47+
const targetRepository = `https://github.com/cloudscape-design/${packageName}.git`;
48+
const nodeModulesPath = path.join(process.cwd(), 'node_modules', '@cloudscape-design');
49+
const tempDir = path.join(os.tmpdir(), `temp-${packageName}`);
50+
51+
// Clone the repository and checkout the branch
52+
console.log(`Cloning ${packageName}:${targetBranch}...`);
53+
execCommand(`git clone ${targetRepository} ${tempDir}`);
54+
process.chdir(tempDir);
55+
execCommand(`git checkout ${targetBranch}`);
56+
57+
// Install dependencies and build
58+
console.log(`Installing dependencies and building ${packageName}...`);
59+
execCommand('npm install');
60+
execCommand('npm run build');
61+
62+
// Remove existing peer dependency in node_modules
63+
for (const moduleName of getModules(packageName)) {
64+
const modulePath = path.join(nodeModulesPath, moduleName);
65+
const artifactPath = getArtifactPath(moduleName);
66+
67+
console.log(`Removing existing ${moduleName} from node_modules...`, modulePath);
68+
execCommand(`rm -rf ${modulePath}`);
69+
70+
// Copy built peer dependency to node_modules
71+
console.log(`Copying built ${moduleName} to node_modules...`, modulePath, `${tempDir}${artifactPath}`);
72+
execCommand(`mkdir -p ${modulePath}`);
73+
execCommand(`cp -R ${tempDir}${artifactPath} ${modulePath}`);
74+
}
75+
76+
// Clean up
77+
console.log('Cleaning up...');
78+
execCommand(`rm -rf ${tempDir}`);
79+
80+
console.log(`${packageName} has been successfully installed from branch ${targetBranch}!`);
81+
82+
function execCommand(command, options = {}) {
83+
try {
84+
execSync(command, { stdio: 'inherit', ...options });
85+
} catch (error) {
86+
console.error(`Error executing command: ${command}`);
87+
console.error(`Error message: ${error.message}`);
88+
console.error(`Stdout: ${error.stdout && error.stdout.toString()}`);
89+
console.error(`Stderr: ${error.stderr && error.stderr.toString()}`);
90+
throw error;
91+
}
92+
}

0 commit comments

Comments
 (0)