Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular: Add styles and stylePreprocessorOptions to angular builder #16675

Merged
merged 11 commits into from Nov 26, 2021
Merged
29 changes: 26 additions & 3 deletions app/angular/src/builders/build-storybook/index.ts
Expand Up @@ -12,7 +12,11 @@ import { catchError, map, mapTo, switchMap } from 'rxjs/operators';

// eslint-disable-next-line import/no-extraneous-dependencies
import buildStandalone, { StandaloneOptions } from '@storybook/angular/standalone';
import { BrowserBuilderOptions } from '@angular-devkit/build-angular';
import {
BrowserBuilderOptions,
ExtraEntryPoint,
StylePreprocessorOptions,
} from '@angular-devkit/build-angular';
import { runCompodoc } from '../utils/run-compodoc';
import { buildStandaloneErrorHandler } from '../utils/build-standalone-errors-handler';

Expand All @@ -21,6 +25,8 @@ export type StorybookBuilderOptions = JsonObject & {
tsConfig?: string;
compodoc: boolean;
compodocArgs: string[];
styles?: ExtraEntryPoint[];
stylePreprocessorOptions?: StylePreprocessorOptions;
} & Pick<
// makes sure the option exists
CLIOptions,
Expand All @@ -46,12 +52,29 @@ function commandBuilder(
return runCompodoc$.pipe(mapTo({ tsConfig }));
}),
map(({ tsConfig }) => {
const { browserTarget, ...otherOptions } = options;
const {
browserTarget,
stylePreprocessorOptions,
styles,
configDir,
docs,
loglevel,
outputDir,
quiet,
} = options;

const standaloneOptions: StandaloneOptions = {
...otherOptions,
configDir,
docs,
loglevel,
outputDir,
quiet,
angularBrowserTarget: browserTarget,
angularBuilderContext: context,
angularBuilderOptions: {
stylePreprocessorOptions,
styles,
},
tsConfig,
};
return standaloneOptions;
Expand Down
59 changes: 52 additions & 7 deletions app/angular/src/builders/build-storybook/schema.json
Expand Up @@ -51,15 +51,60 @@
"items": {
"type": "string"
}
},
"styles": {
"type": "array",
"description": "Global styles to be included in the build.",
"items": {
"$ref": "#/definitions/extraEntryPoint"
}
},
"stylePreprocessorOptions": {
"description": "Options to pass to style preprocessors.",
"type": "object",
"properties": {
"includePaths": {
"description": "Paths to include. Paths will be resolved to workspace root.",
"type": "array",
"items": {
"type": "string"
},
"default": []
}
},
"additionalProperties": false
}
},
"additionalProperties": false,
"oneOf": [
{
"required": ["browserTarget"]
},
{
"required": ["tsConfig"]
"definitions": {
"extraEntryPoint": {
"oneOf": [
{
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The file to include."
},
"bundleName": {
"type": "string",
"pattern": "^[\\w\\-.]*$",
"description": "The bundle name for this extra entry point."
},
"inject": {
"type": "boolean",
"description": "If the bundle will be referenced in the HTML file.",
"default": true
}
},
"additionalProperties": false,
"required": ["input"]
},
{
"type": "string",
"description": "The file to include."
}
]
}
]
}
}
41 changes: 38 additions & 3 deletions app/angular/src/builders/start-storybook/index.ts
Expand Up @@ -6,7 +6,11 @@ import {
Target,
} from '@angular-devkit/architect';
import { JsonObject } from '@angular-devkit/core';
import { BrowserBuilderOptions } from '@angular-devkit/build-angular';
import {
BrowserBuilderOptions,
ExtraEntryPoint,
StylePreprocessorOptions,
} from '@angular-devkit/build-angular';
import { from, Observable, of } from 'rxjs';
import { CLIOptions } from '@storybook/core-common';
import { map, switchMap, mapTo } from 'rxjs/operators';
Expand All @@ -21,6 +25,8 @@ export type StorybookBuilderOptions = JsonObject & {
tsConfig?: string;
compodoc: boolean;
compodocArgs: string[];
styles?: ExtraEntryPoint[];
stylePreprocessorOptions?: StylePreprocessorOptions;
} & Pick<
// makes sure the option exists
CLIOptions,
Expand Down Expand Up @@ -56,12 +62,41 @@ function commandBuilder(
return runCompodoc$.pipe(mapTo({ tsConfig }));
}),
map(({ tsConfig }) => {
const { browserTarget, ...otherOptions } = options;
const {
browserTarget,
stylePreprocessorOptions,
styles,
ci,
configDir,
docs,
host,
https,
port,
quiet,
smokeTest,
sslCa,
sslCert,
sslKey,
} = options;

const standaloneOptions: StandaloneOptions = {
...otherOptions,
ci,
configDir,
docs,
host,
https,
port,
quiet,
smokeTest,
sslCa,
sslCert,
sslKey,
angularBrowserTarget: browserTarget,
angularBuilderContext: context,
angularBuilderOptions: {
stylePreprocessorOptions,
styles,
},
tsConfig,
};

Expand Down
55 changes: 54 additions & 1 deletion app/angular/src/builders/start-storybook/schema.json
Expand Up @@ -78,7 +78,60 @@
"items": {
"type": "string"
}
},
"styles": {
"type": "array",
"description": "Global styles to be included in the build.",
"items": {
"$ref": "#/definitions/extraEntryPoint"
}
},
"stylePreprocessorOptions": {
"description": "Options to pass to style preprocessors.",
"type": "object",
"properties": {
"includePaths": {
"description": "Paths to include. Paths will be resolved to workspace root.",
"type": "array",
"items": {
"type": "string"
},
"default": []
}
},
"additionalProperties": false
}
},
"additionalProperties": false
"additionalProperties": false,
"definitions": {
"extraEntryPoint": {
"oneOf": [
{
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The file to include."
},
"bundleName": {
"type": "string",
"pattern": "^[\\w\\-.]*$",
"description": "The bundle name for this extra entry point."
},
"inject": {
"type": "boolean",
"description": "If the bundle will be referenced in the HTML file.",
"default": true
}
},
"additionalProperties": false,
"required": ["input"]
},
{
"type": "string",
"description": "The file to include."
}
]
}
}
}
3 changes: 1 addition & 2 deletions app/angular/src/server/framework-preset-angular-cli.ts
Expand Up @@ -115,10 +115,9 @@ async function getBuilderOptions(
*/
const builderOptions = {
...browserTargetOptions,
...options.angularBuilderOptions,
...(options.angularBuilderOptions as JsonObject),
tsConfig:
options.tsConfig ??
options.angularBuilderOptions?.tsConfig ??
browserTargetOptions.tsConfig ??
findUpSync('tsconfig.json', { cwd: options.configDir }),
};
Expand Down
8 changes: 6 additions & 2 deletions app/angular/src/server/options.ts
Expand Up @@ -2,13 +2,17 @@ import { sync } from 'read-pkg-up';
import { LoadOptions, Options as CoreOptions } from '@storybook/core-common';

import { BuilderContext } from '@angular-devkit/architect';
import { JsonObject } from '@angular-devkit/core';
import { ExtraEntryPoint, StylePreprocessorOptions } from '@angular-devkit/build-angular';
import { JsonValue } from '@angular-devkit/core';

export type PresetOptions = CoreOptions & {
/* Allow to get the options of a targeted "browser builder" */
angularBrowserTarget?: string | null;
/* Defined set of options. These will take over priority from angularBrowserTarget options */
angularBuilderOptions?: JsonObject | null;
angularBuilderOptions?: {
styles?: ExtraEntryPoint[];
stylePreprocessorOptions?: StylePreprocessorOptions;
};
/* Angular context from builder */
angularBuilderContext?: BuilderContext | null;
tsConfig?: string;
Expand Down
8 changes: 6 additions & 2 deletions app/angular/standalone.d.ts
@@ -1,14 +1,18 @@
import { CLIOptions, LoadOptions, BuilderOptions } from '@storybook/core-common';
import { BuilderContext } from '@angular-devkit/architect';
import { JsonObject } from '@angular-devkit/core';
import { JsonValue } from '@angular-devkit/core';
import { JsonSchema } from '@angular-devkit/core/src/json/schema';

export type StandaloneOptions = Partial<
CLIOptions &
LoadOptions &
BuilderOptions & {
mode?: 'static' | 'dev';
angularBrowserTarget?: string | null;
angularBuilderOptions?: JsonObject;
angularBuilderOptions?: JsonObject & {
styles?: ExtraEntryPoint[];
stylePreprocessorOptions?: StylePreprocessorOptions;
};
angularBuilderContext?: BuilderContext | null;
tsConfig?: string;
}
Expand Down