Skip to content

Commit

Permalink
Fix extract source path.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Apr 20, 2022
1 parent d949e7a commit 03e4c19
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions dash/extract-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,32 +141,40 @@ function gatherComponents(sources, components = {}) {
const names = [];
const filepaths = [];

sources.forEach(sourceDirectory =>
fs.readdirSync(sourceDirectory).forEach(f => {
const filepath = path.join(sourceDirectory, f);
if (fs.lstatSync(filepath).isDirectory()) {
gatherComponents(f, components);
} else {
if (ignorePattern && ignorePattern.test(filepath)) {
return;
}
const extension = path.extname(filepath);
if (['.jsx', '.js'].includes(extension)) {
components[cleanPath(filepath)] = parseJSX(filepath);
} else if (filepath.endsWith('.tsx')) {
try {
const name = /(.*)\.tsx/.exec(f)[1];
filepaths.push(filepath);
names.push(name);
} catch (err) {
process.stderr.write(
`ERROR: Invalid component file ${filepath}: ${err}`
);
}
}
const gather = filepath => {
if (ignorePattern && ignorePattern.test(filepath)) {
return;
}
const extension = path.extname(filepath);
if (['.jsx', '.js'].includes(extension)) {
components[cleanPath(filepath)] = parseJSX(filepath);
} else if (filepath.endsWith('.tsx')) {
try {
const name = /(.*)\.tsx/.exec(path.basename(filepath))[1];
filepaths.push(filepath);
names.push(name);
} catch (err) {
process.stderr.write(
`ERROR: Invalid component file ${filepath}: ${err}`
);
}
})
);
}
};

sources.forEach(sourcePath => {
if (fs.lstatSync(sourcePath).isDirectory()) {
fs.readdirSync(sourcePath).forEach(f => {
const filepath = path.join(sourcePath, f);
if (fs.lstatSync(filepath).isDirectory()) {
gatherComponents([filepath], components);
} else {
gather(filepath);
}
});
} else {
gather(sourcePath);
}
});

if (!tsEnabled) {
return components;
Expand Down Expand Up @@ -720,7 +728,7 @@ function gatherComponents(sources, components = {}) {
return components;
}

const metadata = gatherComponents(src);
const metadata = gatherComponents(Array.isArray(src) ? src : [src]);
if (!failedBuild) {
process.stdout.write(JSON.stringify(metadata, null, 2));
} else {
Expand Down

0 comments on commit 03e4c19

Please sign in to comment.