Skip to content

Commit

Permalink
fix: exclude draft documents from store
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jul 15, 2020
1 parent 39ac529 commit 6390350
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
6 changes: 4 additions & 2 deletions core/instrument/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ const parseSource = async (
}
if (store.doc) {
const doc = store.doc;
if (doc.draft === true && process.env.NODE_ENV === 'production') {
return undefined;
if (doc.draft === true) {
if (process.env.NODE_ENV !== 'development') {
return undefined;
}
}

if (options.stories.storeSourceFile) {
Expand Down
30 changes: 15 additions & 15 deletions core/loader/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
parseStories,
} from '@component-controls/instrument';

import { addStoriesDoc } from './store';
import { addStoriesDoc, removeStoriesDoc } from './store';

module.exports.pitch = async function() {
const options: InstrumentOptions = getOptions(this) || {};
Expand All @@ -18,21 +18,21 @@ module.exports.pitch = async function() {
filePath,
options,
);
if (store) {
if (store.doc) {
console.log(chalk.bgRgb(244, 147, 66)('@loaded: '), filePath);
if (store.stories && store.components && store.packages) {
addStoriesDoc(filePath, {
stories: store.stories,
components: store.components,
packages: store.packages,
doc: {
...store.doc,
fileName: filePath,
},
});
}
if (store?.doc) {
console.log(chalk.bgRgb(244, 147, 66)('@loaded: '), filePath);
if (store.stories && store.components && store.packages) {
addStoriesDoc(filePath, {
stories: store.stories,
components: store.components,
packages: store.packages,
doc: {
...store.doc,
fileName: filePath,
},
});
}
} else {
removeStoriesDoc(filePath);
}
return transformed;
};
3 changes: 3 additions & 0 deletions core/loader/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ export const reserveStories = (filePaths: string[]) => {
filePaths.forEach(filePath => store.stores.push({ filePath }));
}
};
export const removeStoriesDoc = (filePath: string) => {
store.stores = store.stores.filter(s => s.filePath !== filePath);
};
export const addStoriesDoc = (filePath: string, added: LoadingDocStore) => {
const { components, packages, stories, doc } = added;
if (!doc) {
Expand Down
6 changes: 6 additions & 0 deletions core/webpack-compile/src/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as webpack from 'webpack';
import * as path from 'path';
const chalk = require('chalk');
import LoaderPlugin from '@component-controls/loader/plugin';
import {
mergeWebpackConfig,
Expand Down Expand Up @@ -95,6 +96,11 @@ export const runCompiler = (
return reject(error);
}
const { store } = require('@component-controls/loader/store');
console.log(
chalk.bgRgb(244, 147, 66)('@end compilation'),
`${store.stores.length} documents compiled`,
);

resolve({ store, stats });
});
});
Expand Down

0 comments on commit 6390350

Please sign in to comment.