Skip to content

Commit 7ed0c99

Browse files
committed
Allow the pseudo data read code to handle yaml. Get the pseudo data file extension dynamically.
1 parent 78633fb commit 7ed0c99

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/core/src/lib/pseudopattern_hunter.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const logger = require('./log');
1212
const readDocumentation = require('./readDocumentation');
1313
const lineage_hunter = new lh();
1414
const changes_hunter = new ch();
15+
const yaml = require('js-yaml');
1516

1617
const pseudopattern_hunter = function() {};
1718

@@ -24,7 +25,7 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function(
2425
//look for a pseudo pattern by checking if there is a file containing same
2526
//name, with ~ in it, ending in .json, .yml or .yaml
2627
const needle =
27-
currentPattern.subdir + '/' + currentPattern.fileName + '~*.(json|yml|yaml)';
28+
currentPattern.subdir + '/' + currentPattern.fileName + '~*.{json,yml,yaml}';
2829
const pseudoPatterns = glob.sync(needle, {
2930
cwd: paths.source.patterns,
3031
debug: false,
@@ -45,7 +46,9 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function(
4546
paths.source.patterns,
4647
pseudoPatterns[i]
4748
);
48-
variantFileData = fs.readJSONSync(variantFileFullPath);
49+
variantFileData = yaml.safeLoad(
50+
fs.readFileSync(variantFileFullPath, 'utf8')
51+
);
4952
} catch (err) {
5053
logger.warning(
5154
`There was an error parsing pseudopattern JSON for ${
@@ -65,9 +68,10 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function(
6568
const variantName = pseudoPatterns[i]
6669
.substring(pseudoPatterns[i].indexOf('~') + 1)
6770
.split('.')[0];
71+
const variantExtension = pseudoPatterns[i].split('.').slice(-1).pop();
6872
const variantFilePath = path.join(
6973
currentPattern.subdir,
70-
currentPattern.fileName + '~' + variantName + '.json'
74+
currentPattern.fileName + '~' + variantName + '.' + variantExtension
7175
);
7276
const lm = fs.statSync(variantFileFullPath);
7377
const patternVariant = Pattern.create(

0 commit comments

Comments
 (0)