Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/core/src/lib/pseudopattern_hunter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const logger = require('./log');
const readDocumentation = require('./readDocumentation');
const lineage_hunter = new lh();
const changes_hunter = new ch();
const yaml = require('js-yaml');

const pseudopattern_hunter = function() {};

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

//look for a pseudo pattern by checking if there is a file containing same
//name, with ~ in it, ending in .json
//name, with ~ in it, ending in .json, .yml or .yaml
const needle =
currentPattern.subdir + '/' + currentPattern.fileName + '~*.json';
currentPattern.subdir +
'/' +
currentPattern.fileName +
'~*.{json,yml,yaml}';
const pseudoPatterns = glob.sync(needle, {
cwd: paths.source.patterns,
debug: false,
Expand All @@ -45,7 +49,9 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function(
paths.source.patterns,
pseudoPatterns[i]
);
variantFileData = fs.readJSONSync(variantFileFullPath);
variantFileData = yaml.safeLoad(
fs.readFileSync(variantFileFullPath, 'utf8')
);
} catch (err) {
logger.warning(
`There was an error parsing pseudopattern JSON for ${
Expand All @@ -65,9 +71,13 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function(
const variantName = pseudoPatterns[i]
.substring(pseudoPatterns[i].indexOf('~') + 1)
.split('.')[0];
const variantExtension = pseudoPatterns[i]
.split('.')
.slice(-1)
.pop();
const variantFilePath = path.join(
currentPattern.subdir,
currentPattern.fileName + '~' + variantName + '.json'
currentPattern.fileName + '~' + variantName + '.' + variantExtension
);
const lm = fs.statSync(variantFileFullPath);
const patternVariant = Pattern.create(
Expand Down