Skip to content

refactor(nestedpatterns): trigger warning message only after checking for whether it's actually a pattern file #1311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2021
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
25 changes: 13 additions & 12 deletions packages/core/src/lib/loadPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ let fs = require('fs-extra'); //eslint-disable-line prefer-const
// loads a pattern from disk, creates a Pattern object from it and
// all its associated files, and records it in patternlab.patterns[]
module.exports = function(relPath, patternlab) {
const fileObject = path.parse(relPath);

//extract some information
const filename = fileObject.base;
const ext = fileObject.ext;
const patternsPath = patternlab.config.paths.source.patterns;

// skip non-pattern files
if (!patternEngines.isPatternFile(filename, patternlab)) {
return null;
}

// Determine patterns nested too deep and show a warning
const relativeDepth = (relPath.match(/\w(?=\\)|\w(?=\/)/g) || []).length;
if (relativeDepth > 3) {
logger.warning('');
Expand Down Expand Up @@ -51,18 +64,6 @@ module.exports = function(relPath, patternlab) {
logger.warning('');
}

const fileObject = path.parse(relPath);

//extract some information
const filename = fileObject.base;
const ext = fileObject.ext;
const patternsPath = patternlab.config.paths.source.patterns;

// skip non-pattern files
if (!patternEngines.isPatternFile(filename, patternlab)) {
return null;
}

//make a new Pattern Object
const currentPattern = new Pattern(relPath, null, patternlab);

Expand Down