|
| 1 | +const { execSync } = require('child_process'); |
| 2 | +const fs = require('fs'); |
| 3 | +const path = require('path'); |
| 4 | + |
| 5 | +// Define paths |
| 6 | +const repoUrl = 'https://github.com/use-ink/polkadot-js-api.git'; |
| 7 | +const cloneDir = path.resolve(__dirname, '../.polkadot-js-api'); // Clone to a local folder in project |
| 8 | +const packageBuildDir = path.resolve(cloneDir, 'packages/api-contract/build'); |
| 9 | + |
| 10 | +// Function to run shell commands |
| 11 | +function runCommand(command, cwd) { |
| 12 | + try { |
| 13 | + execSync(command, { cwd, stdio: 'inherit' }); |
| 14 | + } catch (error) { |
| 15 | + console.error(`Error executing command: ${command}`); |
| 16 | + process.exit(1); |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +// Check if the repo is already cloned |
| 21 | +if (!fs.existsSync(cloneDir)) { |
| 22 | + console.log(`Cloning repository from ${repoUrl}...`); |
| 23 | + runCommand(`git clone --branch peter/api-revive ${repoUrl} "${cloneDir}"`, __dirname); |
| 24 | +} else { |
| 25 | + console.log(`Repository already cloned at ${cloneDir}. Pulling latest changes...`); |
| 26 | + runCommand('git pull', cloneDir); |
| 27 | +} |
| 28 | + |
| 29 | +// Install dependencies and build |
| 30 | +console.log('Installing dependencies...'); |
| 31 | +runCommand('yarn install', cloneDir); |
| 32 | + |
| 33 | +console.log('Building @polkadot/api-contract...'); |
| 34 | +runCommand('yarn build', cloneDir); |
| 35 | + |
| 36 | +// Verify build output |
| 37 | +if (!fs.existsSync(packageBuildDir)) { |
| 38 | + console.error(`Build failed: ${packageBuildDir} does not exist.`); |
| 39 | + process.exit(1); |
| 40 | +} |
| 41 | + |
| 42 | +console.log(`Build completed successfully. Built files are in ${packageBuildDir}.`); |
0 commit comments