@axway/axway-central-cli
Version:
Manage APIs, services and publish to the Amplify Marketplace
55 lines (46 loc) • 1.52 kB
JavaScript
/**
* Post-install script to overwrite environment.js files
* This is done to add pre-prod support as Axway CLI changes cannot be added as dependency,
* as the v4 Axway CLI is ES Module dependent.
*/
const fs = require('fs');
const path = require('path');
const filesToOverwrite = [
{
source: path.join(__dirname, 'resources', 'amplify-cli-utils-envs.js'),
target: path.join(__dirname, '..', '..', 'node_modules', '@axway', 'amplify-cli-utils', 'dist', 'environments.js'),
name: 'amplify-cli-utils'
},
{
source: path.join(__dirname, 'resources', 'amplify-sdk-envs.js'),
target: path.join(__dirname, '..', '..', 'node_modules', '@axway', 'amplify-sdk', 'dist', 'environments.js'),
name: 'amplify-sdk'
}
];
let hasError = false;
for (const file of filesToOverwrite) {
try {
// Check if source file exists
if (!fs.existsSync(file.source)) {
console.error(`Error: Source file not found: ${file.source}`);
hasError = true;
continue;
}
// Check if target directory exists
const targetDir = path.dirname(file.target);
if (!fs.existsSync(targetDir)) {
console.warn(`Warning: Target directory not found for ${file.name}: ${targetDir}`);
console.warn('Skipping this file. This is normal during initial installation.');
continue;
}
// Copy the file
fs.copyFileSync(file.source, file.target);
} catch (error) {
console.error(`Failed to execute post install action`, error.message);
hasError = true;
}
}
if (hasError) {
process.exit(1);
}