2019-07-17 08:14:56 +00:00
|
|
|
import is from '@sindresorhus/is';
|
2019-07-25 06:17:19 +00:00
|
|
|
import yaml from 'js-yaml';
|
|
|
|
import { PackageFile, PackageDependency } from '../common';
|
2019-07-27 06:28:48 +00:00
|
|
|
import { logger } from '../../logger';
|
2019-07-17 08:14:56 +00:00
|
|
|
|
2019-07-25 06:17:19 +00:00
|
|
|
export function extractPackageFile(content: string): PackageFile {
|
2019-07-27 06:28:48 +00:00
|
|
|
let doc;
|
|
|
|
try {
|
|
|
|
doc = yaml.safeLoad(content);
|
|
|
|
} catch (err) {
|
|
|
|
logger.warn({ err, content }, 'Failed to parse .travis.yml file.');
|
|
|
|
return null;
|
|
|
|
}
|
2019-07-25 06:17:19 +00:00
|
|
|
let deps: PackageDependency[] = [];
|
2018-06-04 18:07:22 +00:00
|
|
|
if (doc && is.array(doc.node_js)) {
|
2018-05-03 16:09:18 +00:00
|
|
|
deps = [
|
2018-03-03 19:53:54 +00:00
|
|
|
{
|
|
|
|
depName: 'node',
|
2018-06-04 03:48:20 +00:00
|
|
|
currentValue: doc.node_js,
|
2018-03-03 19:53:54 +00:00
|
|
|
},
|
|
|
|
];
|
2017-12-05 06:50:16 +00:00
|
|
|
}
|
2018-05-03 16:09:18 +00:00
|
|
|
if (!deps.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return { deps };
|
2017-12-05 06:50:16 +00:00
|
|
|
}
|