Skip to content

Commit 7551afc

Browse files
committed
Fix extract source path.
1 parent e51cc78 commit 7551afc

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

Diff for: dash/extract-meta.js

+34-26
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,40 @@ function gatherComponents(sources, components = {}) {
141141
const names = [];
142142
const filepaths = [];
143143

144-
sources.forEach(sourceDirectory =>
145-
fs.readdirSync(sourceDirectory).forEach(f => {
146-
const filepath = path.join(sourceDirectory, f);
147-
if (fs.lstatSync(filepath).isDirectory()) {
148-
gatherComponents(f, components);
149-
} else {
150-
if (ignorePattern && ignorePattern.test(filepath)) {
151-
return;
152-
}
153-
const extension = path.extname(filepath);
154-
if (['.jsx', '.js'].includes(extension)) {
155-
components[cleanPath(filepath)] = parseJSX(filepath);
156-
} else if (filepath.endsWith('.tsx')) {
157-
try {
158-
const name = /(.*)\.tsx/.exec(f)[1];
159-
filepaths.push(filepath);
160-
names.push(name);
161-
} catch (err) {
162-
process.stderr.write(
163-
`ERROR: Invalid component file ${filepath}: ${err}`
164-
);
165-
}
166-
}
144+
const gather = filepath => {
145+
if (ignorePattern && ignorePattern.test(filepath)) {
146+
return;
147+
}
148+
const extension = path.extname(filepath);
149+
if (['.jsx', '.js'].includes(extension)) {
150+
components[cleanPath(filepath)] = parseJSX(filepath);
151+
} else if (filepath.endsWith('.tsx')) {
152+
try {
153+
const name = /(.*)\.tsx/.exec(path.basename(filepath))[1];
154+
filepaths.push(filepath);
155+
names.push(name);
156+
} catch (err) {
157+
process.stderr.write(
158+
`ERROR: Invalid component file ${filepath}: ${err}`
159+
);
167160
}
168-
})
169-
);
161+
}
162+
};
163+
164+
sources.forEach(sourcePath => {
165+
if (fs.lstatSync(sourcePath).isDirectory()) {
166+
fs.readdirSync(sourcePath).forEach(f => {
167+
const filepath = path.join(sourcePath, f);
168+
if (fs.lstatSync(filepath).isDirectory()) {
169+
gatherComponents([filepath], components);
170+
} else {
171+
gather(filepath);
172+
}
173+
});
174+
} else {
175+
gather(sourcePath);
176+
}
177+
});
170178

171179
if (!tsEnabled) {
172180
return components;
@@ -720,7 +728,7 @@ function gatherComponents(sources, components = {}) {
720728
return components;
721729
}
722730

723-
const metadata = gatherComponents(src);
731+
const metadata = gatherComponents(Array.isArray(src) ? src : [src]);
724732
if (!failedBuild) {
725733
process.stdout.write(JSON.stringify(metadata, null, 2));
726734
} else {

0 commit comments

Comments
 (0)