Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Nov 19, 2018
1 parent 9baf6f9 commit 422a651
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 55 deletions.
29 changes: 20 additions & 9 deletions packages/kbn-interpreter/server/get_plugin_paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,33 @@ import { promisify } from 'util';
import { flatten } from 'lodash';
import { pathsRegistry } from '../common/lib/paths_registry';

const lstat = promisify(fs.lstat);
const readdir = promisify(fs.readdir);

const isDirectory = path =>
lstat(path)
.then(stat => stat.isDirectory())
.catch(() => false);

export const getPluginPaths = type => {
const typePaths = pathsRegistry.get(type);
if (!typePaths) {
throw new Error(`Unknown type: ${type}`);
}

return Promise.all(typePaths.map(path => {

// Get the full path of all files in the directory
return readdir(path).then(files => files.map(file => {
if (!file.endsWith('.js')) {
return;
}
return resolve(path, file);
}).filter(path => path)).catch();
return Promise.all(typePaths.map(async path => {
const isDir = await isDirectory(path);
if (!isDir) {
return;
}
// Get the full path of all js files in the directory
return readdir(path).then(files => {
return files.reduce((acc, file) => {
if (file.endsWith('.js')) {
acc.push(resolve(path, file));
}
return acc;
}, []);
}).catch();
})).then(flatten);
};
22 changes: 0 additions & 22 deletions packages/kbn-interpreter/server/index.js

This file was deleted.

36 changes: 12 additions & 24 deletions packages/kbn-interpreter/tasks/webpack.plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {

resolve: {
extensions: ['.js', '.json'],
mainFields: ['browser', 'main'],
},

plugins: [
Expand All @@ -51,12 +52,15 @@ module.exports = {
});

this.plugin('done', function (stats) {
if (stats.compilation.errors && stats.compilation.errors.length) {
if (isWatch) {
console.error(stats.compilation.errors[0]);
} else {
throw stats.compilation.errors[0];
}
if (!stats.hasErrors()) {
return;
}
const errorMessage = stats.toString('errors-only');
if (isWatch) {
console.error(errorMessage);
}
else {
throw new Error(errorMessage);
}
});
},
Expand All @@ -66,28 +70,12 @@ module.exports = {
rules: [
{
test: /\.js$/,
exclude: [/node_modules/],
loaders: 'babel-loader',
options: {
babelrc: false,
plugins: [
'transform-object-rest-spread',
'transform-async-to-generator',
'transform-class-properties',
],
presets: [
'es2015',
'react',
[
'env',
{
targets: {
node: 'current',
},
},
],
],
presets: [require.resolve('@kbn/babel-preset/webpack_preset')],
},
exclude: [/node_modules/],
},
{
test: /\.(png|jpg|gif|jpeg|svg)$/,
Expand Down

0 comments on commit 422a651

Please sign in to comment.