Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikPieper committed Dec 6, 2024
1 parent 0d18fca commit e31f283
Show file tree
Hide file tree
Showing 72 changed files with 115 additions and 195 deletions.
48 changes: 44 additions & 4 deletions code/frameworks/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,66 @@
"@storybook/components": "workspace:*",
"@storybook/core-webpack": "workspace:*",
"@storybook/global": "^5.0.0",
"@storybook/preset-angular-webpack": "workspace:*",
"@storybook/manager-api": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/theming": "workspace:*",
"@types/node": "^22.0.0",
"@types/react": "^18.0.37",
"@types/react-dom": "^18.0.11",
"@types/semver": "^7.3.4",
"@types/webpack-env": "^1.18.0",
"fd-package-json": "^1.2.0",
"find-up": "^5.0.0",
"semver": "^7.3.7",
"telejson": "^7.2.0",
"ts-dedent": "^2.0.0",
"tsconfig-paths-webpack-plugin": "^4.0.1",
"util-deprecate": "^1.0.2",
"webpack": "5"
},
"devDependencies": {
"@analogjs/vite-plugin-angular": "^0.2.24",
"typescript": "^5.3.2"
"@angular-devkit/architect": "^0.1703.0",
"@angular-devkit/build-angular": "^17.3.0",
"@angular-devkit/core": "^17.3.0",
"@angular/animations": "^17.3.0",
"@angular/cli": "^17.3.0",
"@angular/common": "^17.3.0",
"@angular/compiler": "^17.3.0",
"@angular/compiler-cli": "^17.3.0",
"@angular/core": "^17.3.0",
"@angular/forms": "^17.3.0",
"@angular/platform-browser": "^17.3.0",
"@angular/platform-browser-dynamic": "^17.3.0",
"@types/cross-spawn": "^6.0.2",
"@types/tmp": "^0.2.3",
"cross-spawn": "^7.0.3",
"tmp": "^0.2.1",
"typescript": "^5.3.2",
"webpack": "5",
"zone.js": "^0.14.2"
},
"peerDependencies": {
"@angular-devkit/architect": ">=0.1500.0 < 0.2000.0",
"@angular-devkit/build-angular": ">=15.0.0 < 20.0.0",
"@angular-devkit/core": ">=15.0.0 < 20.0.0",
"@angular/cli": ">=15.0.0 < 20.0.0",
"@angular/common": ">=15.0.0 < 20.0.0",
"@angular/compiler": ">=15.0.0 < 20.0.0",
"@angular/compiler-cli": ">=15.0.0 < 20.0.0",
"@angular/core": ">=15.0.0 < 20.0.0",
"@angular/forms": ">=15.0.0 < 20.0.0",
"@angular/platform-browser": ">=15.0.0 < 20.0.0",
"@angular/platform-browser-dynamic": ">=15.0.0 < 20.0.0",
"rxjs": "^6.0.0 || ^7.4.0",
"storybook": "workspace:^",
"typescript": "^4.0.0 || ^5.0.0"
"typescript": "^4.0.0 || ^5.0.0",
"zone.js": ">= 0.11.1 < 1.0.0"
},
"peerDependenciesMeta": {
"@angular/cli": {
"optional": true
}
},
"engines": {
"node": ">=18.0.0"
Expand All @@ -92,7 +129,10 @@
"./src/index.ts",
"./src/preset.ts",
"./src/builders/build-storybook/index.ts",
"./src/builders/start-storybook/index.ts"
"./src/builders/start-storybook/index.ts",
"./src/server/framework-preset-angular-cli.ts",
"./src/server/framework-preset-angular-ivy.ts",
"./src/server/framework-preset-angular-docs.ts"
],
"post": "./scripts/postbuild.js",
"platform": "node"
Expand Down
13 changes: 12 additions & 1 deletion code/frameworks/angular/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
// For backwarts compatibility
export * from '@storybook/angular-renderer';
export * from '@storybook/preset-angular-webpack';
export * from './types';

/*
* ATTENTION:
* - moduleMetadata
* - NgModuleMetadata
* - ICollection
*
* These typings are coped out of decorators.d.ts and types.d.ts in order to fix a bug with tsc
* It was imported out of dist before which was not the proper way of exporting public API
*
* This can be fixed by migrating app/angular to typescript
*/
13 changes: 11 additions & 2 deletions code/frameworks/angular/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { PresetProperty } from 'storybook/internal/types';

import { dirname, join } from 'node:path';
import { StorybookConfig } from './types';

const getAbsolutePath = <I extends string>(input: I): I =>
dirname(require.resolve(join(input, 'package.json'))) as any;

export const addons: PresetProperty<'addons'> = [
getAbsolutePath('@storybook/preset-angular-webpack'),
require.resolve('./server/framework-preset-angular-cli'),
require.resolve('./server/framework-preset-angular-ivy'),
require.resolve('./server/framework-preset-angular-docs'),
];

export const typescript: PresetProperty<'typescript'> = async (config) => {
return {
...config,
skipCompiler: true,
};
};

export const core: PresetProperty<'core'> = async (config, options) => {
const framework = await options.presets.apply('framework');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { logger } from 'storybook/internal/node-logger';
import { AngularLegacyBuildOptionsError } from 'storybook/internal/server-errors';

import type { BuilderContext } from '@angular-devkit/architect';
import { targetFromTargetString } from '@angular-devkit/architect';
import type { JsonObject } from '@angular-devkit/core';
import { logging } from '@angular-devkit/core';
import { BuilderContext, targetFromTargetString } from '@angular-devkit/architect';
import { JsonObject, logging } from '@angular-devkit/core';
import { sync as findUpSync } from 'find-up';
import type { Configuration } from 'webpack';
import webpack from 'webpack';

import { getWebpackConfig as getCustomWebpackConfig } from './angular-cli-webpack';
import type { PresetOptions } from './preset-options';
import { PresetOptions } from './preset-options';
import { moduleIsAvailable } from './utils/module-is-available';

export const webpackFinal = async (baseConfig: Configuration, options: PresetOptions) => {
export async function webpackFinal(baseConfig: webpack.Configuration, options: PresetOptions) {
if (!moduleIsAvailable('@angular-devkit/build-angular')) {
logger.info('=> Using base config because "@angular-devkit/build-angular" is not installed');
return baseConfig;
Expand All @@ -30,7 +28,7 @@ export const webpackFinal = async (baseConfig: Configuration, options: PresetOpt
},
builderContext,
});
};
}

/** Get Builder Context If storybook is not start by angular builder create dumb BuilderContext */
function getBuilderContext(options: PresetOptions): BuilderContext {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { hasDocsOrControls } from 'storybook/internal/docs-tools';
import type { PresetProperty } from 'storybook/internal/types';
import { PresetProperty } from 'storybook/internal/types';

export const previewAnnotations: PresetProperty<'previewAnnotations'> = (entry = [], options) => {
if (!hasDocsOrControls(options)) {
return entry;
}
if (!hasDocsOrControls(options)) return entry;
return [...entry, require.resolve('@storybook/angular-renderer/client/docs/config')];
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { readFileSync } from 'node:fs';
import { join } from 'node:path';

import type { Preset } from 'storybook/internal/types';
import { Preset } from 'storybook/internal/types';

import type { Configuration } from 'webpack';
import { Configuration } from 'webpack';

import type { AngularOptions } from '../types';
import type { PresetOptions } from './preset-options';
import { AngularOptions } from '../types';
import { PresetOptions } from './preset-options';

/**
* Source :
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Options as CoreOptions } from 'storybook/internal/types';
import { Options as CoreOptions } from 'storybook/internal/types';

import type { BuilderContext } from '@angular-devkit/architect';
import type { StylePreprocessorOptions } from '@angular-devkit/build-angular';
import type { StyleElement } from '@angular-devkit/build-angular/src/builders/browser/schema';
import { BuilderContext } from '@angular-devkit/architect';
import { StylePreprocessorOptions } from '@angular-devkit/build-angular';
import { StyleElement } from '@angular-devkit/build-angular/src/builders/browser/schema';

export type PresetOptions = CoreOptions & {
/* Allow to get the options of a targeted "browser builder" */
Expand Down
6 changes: 5 additions & 1 deletion code/frameworks/angular/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
StorybookConfig as StorybookConfigBase,
TypescriptOptions as TypescriptOptionsReact,
} from '@storybook/core-webpack';
import { AngularOptions } from '@storybook/preset-angular-webpack';

type FrameworkName = CompatibleString<'@storybook/angular'>;
type BuilderName = CompatibleString<'@storybook/builder-webpack5'>;
Expand Down Expand Up @@ -44,3 +43,8 @@ export type StorybookConfig = Omit<
> &
StorybookConfigWebpack &
StorybookConfigFramework;

export interface AngularOptions {
enableIvy?: boolean;
enableNgcc?: boolean;
}
2 changes: 1 addition & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
"@storybook/preact": "workspace:*",
"@storybook/preact-vite": "workspace:*",
"@storybook/preact-webpack5": "workspace:*",
"@storybook/preset-angular-webpack": "workspace:*",
"@storybook/preset-create-react-app": "workspace:*",
"@storybook/preset-html-webpack": "workspace:*",
"@storybook/preset-preact-webpack": "workspace:*",
Expand Down Expand Up @@ -201,6 +200,7 @@
"happy-dom": "^14.12.0",
"http-server": "^14.1.1",
"husky": "^4.3.7",
"jiti": "^2.4.1",
"lint-staged": "^13.2.2",
"mock-require": "^3.0.3",
"nx": "18.0.6",
Expand Down
6 changes: 0 additions & 6 deletions code/presets/angular-webpack/README.md

This file was deleted.

131 changes: 0 additions & 131 deletions code/presets/angular-webpack/package.json

This file was deleted.

1 change: 0 additions & 1 deletion code/presets/angular-webpack/preset.js

This file was deleted.

8 changes: 0 additions & 8 deletions code/presets/angular-webpack/project.json

This file was deleted.

9 changes: 0 additions & 9 deletions code/presets/angular-webpack/src/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions code/presets/angular-webpack/src/types.ts

This file was deleted.

Loading

0 comments on commit e31f283

Please sign in to comment.