Skip to content

Commit 112b41b

Browse files
committed
feat: allow consuming permutations view from build-tools
1 parent 0f8232f commit 112b41b

4 files changed

Lines changed: 44 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ vendor/generated-*.txt
1515
.vscode
1616
# System
1717
.DS_Store
18+
shared/

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"start:integ": "cross-env NODE_ENV=development webpack serve --config pages/webpack.config.integ.cjs",
2626
"start:react18": "npm-run-all --parallel start:watch start:react18:dev",
2727
"start:react18:dev": "cross-env NODE_ENV=development REACT_VERSION=18 webpack serve --config pages/webpack.config.cjs",
28-
"prepare": "husky"
28+
"prepare": "husky",
29+
"preinstall": "node ./scripts/setup-build-tools"
2930
},
3031
"dependencies": {
3132
"@cloudscape-design/collection-hooks": "^1.0.0",
@@ -53,7 +54,8 @@
5354
"@babel/core": "^7.23.7",
5455
"@babel/plugin-syntax-typescript": "^7.23.3",
5556
"@cloudscape-design/browser-test-tools": "^3.0.0",
56-
"@cloudscape-design/build-tools": "github:cloudscape-design/build-tools#main",
57+
"@cloudscape-design/build-tools-repo": "github:cloudscape-design/build-tools#add-test-pages-util-permutation-view",
58+
"@cloudscape-design/build-tools": "file:./shared/build-tools",
5759
"@cloudscape-design/documenter": "^1.0.0",
5860
"@cloudscape-design/global-styles": "^1.0.0",
5961
"@cloudscape-design/jest-preset": "^2.0.0",

pages/alert/permutations.page.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import React from 'react';
44

5+
import { createPermutations, PermutationsView } from '@cloudscape-design/build-tools/lib/dev-pages-utils';
6+
57
import Alert, { AlertProps } from '~components/alert';
68
import Button from '~components/button';
79
import ExpandableSection from '~components/expandable-section';
810
import Link from '~components/link';
911

10-
import createPermutations from '../utils/permutations';
11-
import PermutationsView from '../utils/permutations-view';
1212
import ScreenshotArea from '../utils/screenshot-area';
1313
import { i18nStrings } from './common';
1414

@@ -111,7 +111,10 @@ export default function AlertScenario() {
111111
<article>
112112
<h1>Alert permutations</h1>
113113
<ScreenshotArea>
114-
<PermutationsView permutations={permutations} render={permutation => <Alert {...permutation} />} />
114+
<PermutationsView
115+
permutations={permutations}
116+
render={(permutation: AlertProps) => <Alert {...permutation} />}
117+
/>
115118
</ScreenshotArea>
116119
</article>
117120
);

scripts/setup-build-tools.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
import { execSync } from 'child_process';
10+
import process from 'node:process';
11+
import path from 'path';
12+
13+
const branch = 'add-test-pages-util-permutation-view';
14+
const packageName = 'build-tools';
15+
const targetRepository = `https://github.com/cloudscape-design/${packageName}.git`;
16+
const copyBuildToolsPath = path.join(process.cwd(), 'shared', 'build-tools');
17+
execCommand(`mkdir -p ${copyBuildToolsPath}`);
18+
execCommand(`rm -rf ${copyBuildToolsPath}`);
19+
execCommand(`git clone --branch ${branch} --single-branch ${targetRepository} ${copyBuildToolsPath}`);
20+
21+
console.log(`build-tools has been successfully installed!`);
22+
23+
function execCommand(command, options = {}) {
24+
try {
25+
execSync(command, { stdio: 'inherit', ...options });
26+
} catch (error) {
27+
console.error(`Error executing command: ${command}`);
28+
console.error(`Error message: ${error.message}`);
29+
console.error(`Stdout: ${error.stdout && error.stdout.toString()}`);
30+
console.error(`Stderr: ${error.stderr && error.stderr.toString()}`);
31+
throw error;
32+
}
33+
}

0 commit comments

Comments
 (0)