71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import * as process from "process";
|
|
import {error} from "ng-packagr/lib/utils/log";
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
type Dependency = 'version-update';
|
|
|
|
/** Add the dependencies you want to add to your projects */
|
|
let dependencies: Dependency[] = ['version-update'];
|
|
const repository: string = 'openaire-libraries';
|
|
const gitURL: string = `https://code-repo.d4science.org/MaDgIK/${repository}.git`;
|
|
|
|
console.log('Cloning ' + repository);
|
|
|
|
function installDependency(index: number) {
|
|
if(index < dependencies.length) {
|
|
exec(`npm run build-lib --lib=${dependencies[index]}`, (error:string) => {
|
|
if(error) {
|
|
console.error(`Error packaging ${dependencies[index]}: ${error}`);
|
|
clean();
|
|
return;
|
|
}
|
|
process.chdir('../');
|
|
exec(`npm install --no-save ./${repository}/projects/${dependencies[index]}`, (installError: string) => {
|
|
if(error) {
|
|
console.error(`Error installing ${dependencies[index]}: ${installError}`);
|
|
clean();
|
|
return;
|
|
}
|
|
process.chdir(repository);
|
|
installDependency(index + 1);
|
|
});
|
|
});
|
|
} else {
|
|
clean();
|
|
}
|
|
}
|
|
|
|
function clean() {
|
|
/** Clean files after packaging */
|
|
console.log('Cleaning files')
|
|
process.chdir('../')
|
|
exec(`rm -rf ${repository} package.js`, (error: string) => {
|
|
if(error) {
|
|
console.error(`Error cleaning files: ${error}`);
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Clone ${repository}
|
|
* */
|
|
exec(`git clone ${gitURL}`, (cloneError: string) => {
|
|
if(cloneError) {
|
|
console.error(`Error cloning the ${repository}: ${cloneError}`);
|
|
return;
|
|
}
|
|
console.log(`${repository} cloned successfully.`);
|
|
process.chdir(repository);
|
|
/** Installing node modules */
|
|
exec(`npm install`, (npmError: string) => {
|
|
if(npmError) {
|
|
console.error(`Error installing node modules: ${npmError}`);
|
|
return;
|
|
}
|
|
installDependency(0);
|
|
});
|
|
})
|