Skip to content

Commit

Permalink
chore: Configs extend root config
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Mann committed Aug 16, 2019
1 parent 9893fc1 commit 858ba16
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 6 deletions.
28 changes: 23 additions & 5 deletions packages/storybook/src/schematics/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import {
schematic,
SchematicContext,
Tree,
url
url,
template
} from '@angular-devkit/schematics';
import {
getProjectConfig,
updateWorkspace,
addPackageWithNgAdd
addPackageWithNgAdd,
offsetFromRoot
} from '@nrwl/workspace';
import { StorybookStoriesSchema } from '../../../../angular/src/schematics/stories/stories';
import { parseJsonAtPath } from '../../utils/utils';
Expand All @@ -23,7 +25,8 @@ import { StorybookConfigureSchema } from './schema';
export default function(schema: StorybookConfigureSchema): Rule {
return chain([
schematic('ng-add', {}),
createStorybookDir(schema.name),
createRootStorybookDir(),
createLibStorybookDir(schema.name),
configureTsConfig(schema.name),
addStorybookTask(schema.name),
schema.configureCypress
Expand All @@ -41,13 +44,28 @@ export default function(schema: StorybookConfigureSchema): Rule {
]);
}

function createStorybookDir(projectName: string): Rule {
function createRootStorybookDir(): Rule {
return (tree: Tree, context: SchematicContext) => {
context.logger.debug('adding .storybook folder to lib');

return chain([mergeWith(apply(url('./root-files'), []))])(tree, context);
};
}

function createLibStorybookDir(projectName: string): Rule {
return (tree: Tree, context: SchematicContext) => {
context.logger.debug('adding .storybook folder to lib');
const projectConfig = getProjectConfig(tree, projectName);

return chain([
mergeWith(
apply(url('./files'), [move(getProjectConfig(tree, projectName).root)])
apply(url('./lib-files'), [
template({
tmpl: '',
offsetFromRoot: offsetFromRoot(projectConfig.root)
}),
move(projectConfig.root)
])
)
])(tree, context);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '<%= offsetFromRoot %>../.storybook/addons';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { configure } from '<%= offsetFromRoot %>../.storybook/config';

function loadStories() {
const req = require.context('../src/lib', true, /\.stories\.ts$/);
req.keys().forEach(filename => req(filename));
}

configure(loadStories, module);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const rootWebpackConfig = require('<%= offsetFromRoot %>../.storybook/webpack.config');
// Export a function. Accept the base config as the only param.
module.exports = async ({ config, mode }) => {
config = await rootWebpackConfig({ config, mode });
return config;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { configure, addDecorator } from '@storybook/angular';
import { withKnobs } from '@storybook/addon-knobs';

function loadStories() {
const req = require.context('../src/lib', true, /\.stories\.ts$/);
const req = require.context('..', true, /\.stories\.ts$/);
req.keys().forEach(filename => req(filename));
}

addDecorator(withKnobs);

configure(loadStories, module);

export { configure };
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../tsconfig.json",
"exclude": ["../**/test.ts", "../**/*.spec.ts"],
"include": ["../**/*"]
}

0 comments on commit 858ba16

Please sign in to comment.