Skip to content

Commit c40d94b

Browse files
authored
Merge pull request #981 from bryce-gilhome-cp/feature/pseudohunter-add-yml
Feature/pseudohunter add yml
2 parents 1ef183b + 8658a53 commit c40d94b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

packages/core/src/lib/pseudopattern_hunter.js

Lines changed: 14 additions & 4 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

@@ -22,9 +23,12 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function(
2223
const paths = patternlab.config.paths;
2324

2425
//look for a pseudo pattern by checking if there is a file containing same
25-
//name, with ~ in it, ending in .json
26+
//name, with ~ in it, ending in .json, .yml or .yaml
2627
const needle =
27-
currentPattern.subdir + '/' + currentPattern.fileName + '~*.json';
28+
currentPattern.subdir +
29+
'/' +
30+
currentPattern.fileName +
31+
'~*.{json,yml,yaml}';
2832
const pseudoPatterns = glob.sync(needle, {
2933
cwd: paths.source.patterns,
3034
debug: false,
@@ -45,7 +49,9 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function(
4549
paths.source.patterns,
4650
pseudoPatterns[i]
4751
);
48-
variantFileData = fs.readJSONSync(variantFileFullPath);
52+
variantFileData = yaml.safeLoad(
53+
fs.readFileSync(variantFileFullPath, 'utf8')
54+
);
4955
} catch (err) {
5056
logger.warning(
5157
`There was an error parsing pseudopattern JSON for ${
@@ -65,9 +71,13 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function(
6571
const variantName = pseudoPatterns[i]
6672
.substring(pseudoPatterns[i].indexOf('~') + 1)
6773
.split('.')[0];
74+
const variantExtension = pseudoPatterns[i]
75+
.split('.')
76+
.slice(-1)
77+
.pop();
6878
const variantFilePath = path.join(
6979
currentPattern.subdir,
70-
currentPattern.fileName + '~' + variantName + '.json'
80+
currentPattern.fileName + '~' + variantName + '.' + variantExtension
7181
);
7282
const lm = fs.statSync(variantFileFullPath);
7383
const patternVariant = Pattern.create(

0 commit comments

Comments
 (0)