awesome-cordova-plugins/scripts/ci-tests.js

72 lines
1.8 KiB
JavaScript
Raw Normal View History

const exec = require('child-process-promise').exec;
let diff;
exec(`git branch | grep \\* | cut -d ' ' -f2`)
.then(output => {
if (output.stderr) {
return Promise.reject(output.stderr);
}
const branch = output.stdout.trim();
if (branch !== 'master') {
console.log('Merging master branch in ...');
// not on master branch
// let's test the changes that were made
return exec(`git merge origin master`);
}
})
2018-08-17 04:23:03 +08:00
.then(output => {
2017-05-14 15:26:11 +08:00
if (output && output.stderr) {
return Promise.reject(output.stderr);
}
console.log('Checking for differences ...');
2018-08-17 04:23:03 +08:00
return exec(`git diff --name-status origin master`);
})
2018-08-17 04:23:03 +08:00
.then(output => {
2017-05-14 15:26:11 +08:00
if (output && output.stderr) {
return Promise.reject(output.stderr);
}
diff = output.stdout;
diff = diff.replace(/A\s+/g, '');
2018-08-17 04:23:03 +08:00
diff = diff.match(
/src\/@ionic-native\/plugins\/([a-zA-Z0-9\-]+)\/index\.ts/g
);
if (!diff) process.exit();
2018-08-17 04:23:03 +08:00
console.log(
`${
diff.length
} plugins were modified. We will now build them to verify they still work.`
);
return exec('npm run build:core --silent');
})
2018-08-17 04:23:03 +08:00
.then(output => {
2017-05-14 15:26:11 +08:00
if (output && output.stderr) {
return Promise.reject(output.stderr);
}
console.log('Built core library successfully ...');
console.log('Building plugins ...');
2018-08-17 04:23:03 +08:00
diff = diff.map(text =>
text.replace('src/@ionic-native/plugins/', '').replace('/index.ts', '')
);
return exec(`npm run build:modules ${diff.join(' ')} --silent`);
})
2018-08-17 04:23:03 +08:00
.then(output => {
2017-05-14 15:26:11 +08:00
if (output && output.stderr) {
console.log(output.stderr);
process.exit(1);
}
console.log(output.stdout);
process.exit();
})
.catch(e => {
console.log(e.message || e);
process.exit(1);
});