|
| 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