@aurelia/storybook 0.1.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +47 -22
  3. package/__tests__/preset.test.ts +49 -0
  4. package/__tests__/preview.test.ts +139 -0
  5. package/__tests__/render.test.ts +1 -2
  6. package/__tests__/webpack.test.ts +21 -0
  7. package/apps/hello-world/.storybook/main.ts +28 -0
  8. package/apps/hello-world/.storybook/preview.ts +1 -0
  9. package/apps/hello-world/.stylelintrc.json +5 -0
  10. package/apps/hello-world/.yarnrc.yml +2 -0
  11. package/apps/hello-world/README.md +28 -0
  12. package/apps/hello-world/eslint.config.mjs +25 -0
  13. package/apps/hello-world/favicon.ico +0 -0
  14. package/apps/hello-world/index.html +17 -0
  15. package/apps/hello-world/package-lock.json +10141 -0
  16. package/apps/hello-world/package.json +61 -0
  17. package/apps/hello-world/src/hello-world.html +6 -0
  18. package/apps/hello-world/src/hello-world.ts +17 -0
  19. package/apps/hello-world/src/main.ts +6 -0
  20. package/apps/hello-world/src/my-app.html +1 -0
  21. package/apps/hello-world/src/my-app.ts +3 -0
  22. package/apps/hello-world/src/resource.d.ts +15 -0
  23. package/apps/hello-world/src/stories/hello-world.stories.ts +54 -0
  24. package/apps/hello-world/test/my-app.spec.ts +15 -0
  25. package/apps/hello-world/test/setup.ts +29 -0
  26. package/apps/hello-world/tsconfig.json +18 -0
  27. package/apps/hello-world/tsconfig.vitest.json +11 -0
  28. package/apps/hello-world/vite.config.ts +19 -0
  29. package/apps/hello-world/vitest.config.ts +15 -0
  30. package/apps/hello-world-webpack/.env.development +0 -0
  31. package/apps/hello-world-webpack/.storybook/main.ts +16 -0
  32. package/apps/hello-world-webpack/.storybook/preview.ts +3 -0
  33. package/apps/hello-world-webpack/.stylelintrc.json +5 -0
  34. package/apps/hello-world-webpack/.yarnrc.yml +2 -0
  35. package/apps/hello-world-webpack/README.md +29 -0
  36. package/apps/hello-world-webpack/eslint.config.mjs +25 -0
  37. package/apps/hello-world-webpack/favicon.ico +0 -0
  38. package/apps/hello-world-webpack/index.html +15 -0
  39. package/apps/hello-world-webpack/package-lock.json +8856 -0
  40. package/apps/hello-world-webpack/package.json +53 -0
  41. package/apps/hello-world-webpack/src/main.ts +6 -0
  42. package/apps/hello-world-webpack/src/my-app.css +3 -0
  43. package/apps/hello-world-webpack/src/my-app.html +1 -0
  44. package/apps/hello-world-webpack/src/my-app.stories.ts +12 -0
  45. package/apps/hello-world-webpack/src/my-app.ts +3 -0
  46. package/apps/hello-world-webpack/src/resource.d.ts +13 -0
  47. package/apps/hello-world-webpack/tsconfig.json +18 -0
  48. package/apps/hello-world-webpack/webpack.config.js +111 -0
  49. package/dist/index.js +79 -3
  50. package/dist/index.js.map +1 -1
  51. package/dist/index.mjs +79 -3
  52. package/dist/index.mjs.map +1 -1
  53. package/dist/preset.js +35 -1
  54. package/dist/preset.js.map +1 -1
  55. package/dist/preset.mjs +34 -2
  56. package/dist/preset.mjs.map +1 -1
  57. package/dist/preview/render.js +79 -3
  58. package/dist/preview/render.js.map +1 -1
  59. package/dist/preview/render.mjs +79 -3
  60. package/dist/preview/render.mjs.map +1 -1
  61. package/dist/preview.js +74 -0
  62. package/dist/preview.js.map +1 -0
  63. package/dist/preview.mjs +72 -0
  64. package/dist/preview.mjs.map +1 -0
  65. package/dist/webpack.js +23 -0
  66. package/dist/webpack.js.map +1 -0
  67. package/dist/webpack.mjs +21 -0
  68. package/dist/webpack.mjs.map +1 -0
  69. package/jest.config.js +1 -1
  70. package/package.json +23 -24
  71. package/rollup.config.mjs +0 -3
  72. package/src/preset.ts +22 -5
  73. package/src/preview/render.ts +2 -2
  74. package/src/preview/types.ts +1 -1
  75. package/src/preview.ts +50 -0
  76. package/src/webpack.ts +21 -0
  77. package/__tests__/render.test.d.ts +0 -1
  78. package/dist/index.d.ts +0 -3
  79. package/dist/preset.d.ts +0 -8
  80. package/dist/preview/render.d.ts +0 -17
  81. package/dist/preview/types.d.ts +0 -5
package/jest.config.js CHANGED
@@ -5,5 +5,5 @@ module.exports = {
5
5
  transform: {
6
6
  "^.+\\.tsx?$": ["ts-jest"],
7
7
  },
8
- testMatch: ["**/?(*.)+(spec|test).ts?(x)"]
8
+ testMatch: ["**/__tests__/**/*.test.ts?(x)"]
9
9
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aurelia/storybook",
3
- "version": "0.1.1",
4
- "description": "A Storybook plugin to render Aurelia 2 components using Vite",
3
+ "version": "1.0.1",
4
+ "description": "A Storybook plugin to render Aurelia 2 components using Vite or Webpack",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "module": "dist/index.mjs",
@@ -12,32 +12,31 @@
12
12
  "build": "rollup -c",
13
13
  "build:types": "tsc --project tsconfig.build.json --emitDeclarationOnly",
14
14
  "watch": "rollup -c -w",
15
- "test": "jest"
15
+ "test": "NODE_OPTIONS=--no-deprecation jest"
16
16
  },
17
17
  "peerDependencies": {
18
- "@aurelia/runtime-html": "^2.0.0-beta.23",
19
- "@aurelia/vite-plugin": "^2.0.0-beta.23",
20
- "@storybook/addons": "^7.6.17",
21
- "@storybook/builder-vite": "^8.5.3",
22
- "@storybook/core-common": "^8.5.3",
23
- "@storybook/core-events": "^8.5.3",
24
- "aurelia": "^2.0.0-beta.23"
18
+ "@aurelia/runtime-html": "^2.0.0-beta.24",
19
+ "@aurelia/vite-plugin": "^2.0.0-beta.24",
20
+ "@storybook/builder-vite": "^9.0.0",
21
+ "@storybook/builder-webpack5": "^9.0.0",
22
+ "aurelia": "^2.0.0-beta.24",
23
+ "storybook": "^9.0.0"
25
24
  },
26
25
  "devDependencies": {
27
- "@rollup/plugin-commonjs": "^28.0.2",
28
- "@rollup/plugin-node-resolve": "^16.0.0",
29
- "@rollup/plugin-typescript": "^12.1.2",
30
- "@storybook/builder-vite": "^8.5.3",
31
- "@storybook/core-common": "^8.5.3",
32
- "@storybook/preview-api": "^8.5.3",
33
- "@storybook/types": "^8.5.3",
34
- "@types/jest": "^29.5.14",
35
- "glob": "^11.0.1",
36
- "jest": "^29.7.0",
37
- "jest-environment-jsdom": "^29.7.0",
38
- "rollup": "^4.34.2",
39
- "ts-jest": "^29.2.5",
40
- "typescript": "^5.7.3"
26
+ "@aurelia/webpack-loader": "^2.0.0-beta.24",
27
+ "@rollup/plugin-commonjs": "^28.0.6",
28
+ "@rollup/plugin-node-resolve": "^16.0.1",
29
+ "@rollup/plugin-typescript": "^12.1.3",
30
+ "@storybook/builder-vite": "^9.0.12",
31
+ "storybook": "^9.0.12",
32
+ "@types/jest": "^30.0.0",
33
+ "glob": "^11.0.3",
34
+ "jest": "^30.0.2",
35
+ "jest-environment-jsdom": "^30.0.2",
36
+ "rollup": "^4.44.0",
37
+ "ts-jest": "^29.4.0",
38
+ "ts-loader": "^9.5.2",
39
+ "typescript": "^5.8.3"
41
40
  },
42
41
  "exports": {
43
42
  ".": {
package/rollup.config.mjs CHANGED
@@ -6,10 +6,7 @@ import { glob } from 'glob';
6
6
  const external = [
7
7
  '@aurelia/runtime-html',
8
8
  '@aurelia/vite-plugin',
9
- '@storybook/addons',
10
9
  '@storybook/builder-vite',
11
- '@storybook/core-common',
12
- '@storybook/core-events',
13
10
  'aurelia'
14
11
  ];
15
12
 
package/src/preset.ts CHANGED
@@ -1,14 +1,31 @@
1
1
  // src/preset.ts
2
2
  // Minimal preset for Storybook-Aurelia2
3
3
 
4
+ import { getRules } from './webpack';
5
+
4
6
  /**
5
7
  * Optionally adjust the Vite configuration.
6
8
  */
7
9
  export async function viteFinal(config: any): Promise<any> {
8
10
  // For now, return the config unchanged.
9
11
  return config;
10
- }
11
-
12
- // Export a default for compatibility.
13
- export default { viteFinal };
14
-
12
+ }
13
+
14
+ /**
15
+ * A function to configure webpack.
16
+ * @param config
17
+ * @returns
18
+ */
19
+ export async function webpackFinal(config: any): Promise<any> {
20
+ const rules = config.module?.rules;
21
+ if (rules) {
22
+ rules.push(...getRules());
23
+ }
24
+
25
+ return config;
26
+ }
27
+
28
+ // Export a default for compatibility.
29
+ export default { viteFinal, webpackFinal };
30
+
31
+ export const previewAnnotations = [require.resolve('./preview')];
@@ -1,5 +1,5 @@
1
- import { STORY_CHANGED } from '@storybook/core-events';
2
- import type { RenderContext, ArgsStoryFn } from '@storybook/types';
1
+ import { STORY_CHANGED } from 'storybook/internal/core-events';
2
+ import type { RenderContext, ArgsStoryFn } from 'storybook/internal/types';
3
3
  import type { AureliaRenderer } from './types';
4
4
  import Aurelia, { Constructable, CustomElement } from 'aurelia';
5
5
 
@@ -1,4 +1,4 @@
1
- import type { Renderer } from '@storybook/types';
1
+ import type { Renderer } from 'storybook/internal/types';
2
2
 
3
3
  export interface AureliaRenderer extends Renderer {
4
4
  /** The DOM element in which the story is rendered */
package/src/preview.ts ADDED
@@ -0,0 +1,50 @@
1
+ import { renderToCanvas, bootstrapAureliaApp } from './preview/render';
2
+ import Aurelia from 'aurelia';
3
+
4
+ // Track the current story's cleanup function
5
+ let currentCleanup: (() => void) | null = null;
6
+
7
+ export const render = (args: any, context: any) => {
8
+ // Clean up previous story if exists
9
+ if (currentCleanup) {
10
+ currentCleanup();
11
+ currentCleanup = null;
12
+ }
13
+
14
+ // Create a container element
15
+ const container = document.createElement('div');
16
+
17
+ // Get the story function result
18
+ const story = context.storyFn();
19
+
20
+ // Bootstrap Aurelia app immediately
21
+ if (story && (story.Component || story.template)) {
22
+ const app = bootstrapAureliaApp(
23
+ story,
24
+ args,
25
+ container,
26
+ story.Component || context.component
27
+ ) as Aurelia;
28
+
29
+ // Start the app asynchronously
30
+ const startPromise = app.start();
31
+ if (startPromise && typeof startPromise.catch === 'function') {
32
+ startPromise.catch((error: any) => {
33
+ console.error('Failed to start Aurelia app:', error);
34
+ });
35
+ }
36
+
37
+ // Set cleanup function
38
+ currentCleanup = () => {
39
+ const stopPromise = app.stop();
40
+ if (stopPromise && typeof stopPromise.catch === 'function') {
41
+ stopPromise.catch((error: any) => {
42
+ console.error('Failed to stop Aurelia app:', error);
43
+ });
44
+ }
45
+ };
46
+ }
47
+
48
+ // Return the container element immediately
49
+ return container;
50
+ };
package/src/webpack.ts ADDED
@@ -0,0 +1,21 @@
1
+ // src/webpack.ts
2
+ import type { RuleSetRule } from 'webpack';
3
+
4
+ /**
5
+ * A set of rules to be added to the webpack configuration.
6
+ * @returns
7
+ */
8
+ export function getRules(): RuleSetRule[] {
9
+ return [
10
+ {
11
+ test: /\.ts$/i,
12
+ use: ['ts-loader', '@aurelia/webpack-loader'],
13
+ exclude: /node_modules/,
14
+ },
15
+ {
16
+ test: /\.html$/i,
17
+ use: '@aurelia/webpack-loader',
18
+ exclude: /node_modules/,
19
+ },
20
+ ];
21
+ }
@@ -1 +0,0 @@
1
- export {};
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { renderToCanvas } from './preview/render';
2
- export { renderToCanvas };
3
- export declare const render: typeof renderToCanvas;
package/dist/preset.d.ts DELETED
@@ -1,8 +0,0 @@
1
- /**
2
- * Optionally adjust the Vite configuration.
3
- */
4
- export declare function viteFinal(config: any): Promise<any>;
5
- declare const _default: {
6
- viteFinal: typeof viteFinal;
7
- };
8
- export default _default;
@@ -1,17 +0,0 @@
1
- import type { RenderContext, ArgsStoryFn } from '@storybook/types';
2
- import type { AureliaRenderer } from './types';
3
- import Aurelia, { Constructable } from 'aurelia';
4
- interface AureliaStoryResult {
5
- template: string;
6
- components?: unknown[];
7
- Component?: unknown;
8
- container?: any;
9
- items?: unknown[];
10
- innerHtml?: string;
11
- props?: Record<string, any>;
12
- }
13
- export declare const render: ArgsStoryFn<AureliaRenderer>;
14
- export declare function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }: RenderContext<AureliaRenderer>, canvasElement: HTMLElement, bootstrapAppFn?: typeof bootstrapAureliaApp): Promise<() => void>;
15
- export declare function bootstrapAureliaApp(story: AureliaStoryResult, args: Record<string, any>, domElement: HTMLElement, component?: Constructable): Omit<Aurelia, "enhance" | "register" | "app">;
16
- export declare function createComponentTemplate(component: Constructable, innerHtml?: string): string;
17
- export {};
@@ -1,5 +0,0 @@
1
- import type { Renderer } from '@storybook/types';
2
- export interface AureliaRenderer extends Renderer {
3
- /** The DOM element in which the story is rendered */
4
- canvasElement: HTMLElement;
5
- }