@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.
- package/LICENSE +1 -1
- package/README.md +47 -22
- package/__tests__/preset.test.ts +49 -0
- package/__tests__/preview.test.ts +139 -0
- package/__tests__/render.test.ts +1 -2
- package/__tests__/webpack.test.ts +21 -0
- package/apps/hello-world/.storybook/main.ts +28 -0
- package/apps/hello-world/.storybook/preview.ts +1 -0
- package/apps/hello-world/.stylelintrc.json +5 -0
- package/apps/hello-world/.yarnrc.yml +2 -0
- package/apps/hello-world/README.md +28 -0
- package/apps/hello-world/eslint.config.mjs +25 -0
- package/apps/hello-world/favicon.ico +0 -0
- package/apps/hello-world/index.html +17 -0
- package/apps/hello-world/package-lock.json +10141 -0
- package/apps/hello-world/package.json +61 -0
- package/apps/hello-world/src/hello-world.html +6 -0
- package/apps/hello-world/src/hello-world.ts +17 -0
- package/apps/hello-world/src/main.ts +6 -0
- package/apps/hello-world/src/my-app.html +1 -0
- package/apps/hello-world/src/my-app.ts +3 -0
- package/apps/hello-world/src/resource.d.ts +15 -0
- package/apps/hello-world/src/stories/hello-world.stories.ts +54 -0
- package/apps/hello-world/test/my-app.spec.ts +15 -0
- package/apps/hello-world/test/setup.ts +29 -0
- package/apps/hello-world/tsconfig.json +18 -0
- package/apps/hello-world/tsconfig.vitest.json +11 -0
- package/apps/hello-world/vite.config.ts +19 -0
- package/apps/hello-world/vitest.config.ts +15 -0
- package/apps/hello-world-webpack/.env.development +0 -0
- package/apps/hello-world-webpack/.storybook/main.ts +16 -0
- package/apps/hello-world-webpack/.storybook/preview.ts +3 -0
- package/apps/hello-world-webpack/.stylelintrc.json +5 -0
- package/apps/hello-world-webpack/.yarnrc.yml +2 -0
- package/apps/hello-world-webpack/README.md +29 -0
- package/apps/hello-world-webpack/eslint.config.mjs +25 -0
- package/apps/hello-world-webpack/favicon.ico +0 -0
- package/apps/hello-world-webpack/index.html +15 -0
- package/apps/hello-world-webpack/package-lock.json +8856 -0
- package/apps/hello-world-webpack/package.json +53 -0
- package/apps/hello-world-webpack/src/main.ts +6 -0
- package/apps/hello-world-webpack/src/my-app.css +3 -0
- package/apps/hello-world-webpack/src/my-app.html +1 -0
- package/apps/hello-world-webpack/src/my-app.stories.ts +12 -0
- package/apps/hello-world-webpack/src/my-app.ts +3 -0
- package/apps/hello-world-webpack/src/resource.d.ts +13 -0
- package/apps/hello-world-webpack/tsconfig.json +18 -0
- package/apps/hello-world-webpack/webpack.config.js +111 -0
- package/dist/index.js +79 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -3
- package/dist/index.mjs.map +1 -1
- package/dist/preset.js +35 -1
- package/dist/preset.js.map +1 -1
- package/dist/preset.mjs +34 -2
- package/dist/preset.mjs.map +1 -1
- package/dist/preview/render.js +79 -3
- package/dist/preview/render.js.map +1 -1
- package/dist/preview/render.mjs +79 -3
- package/dist/preview/render.mjs.map +1 -1
- package/dist/preview.js +74 -0
- package/dist/preview.js.map +1 -0
- package/dist/preview.mjs +72 -0
- package/dist/preview.mjs.map +1 -0
- package/dist/webpack.js +23 -0
- package/dist/webpack.js.map +1 -0
- package/dist/webpack.mjs +21 -0
- package/dist/webpack.mjs.map +1 -0
- package/jest.config.js +1 -1
- package/package.json +23 -24
- package/rollup.config.mjs +0 -3
- package/src/preset.ts +22 -5
- package/src/preview/render.ts +2 -2
- package/src/preview/types.ts +1 -1
- package/src/preview.ts +50 -0
- package/src/webpack.ts +21 -0
- package/__tests__/render.test.d.ts +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/preset.d.ts +0 -8
- package/dist/preview/render.d.ts +0 -17
- package/dist/preview/types.d.ts +0 -5
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aurelia/storybook",
|
|
3
|
-
"version": "0.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.
|
|
19
|
-
"@aurelia/vite-plugin": "^2.0.0-beta.
|
|
20
|
-
"@storybook/
|
|
21
|
-
"@storybook/builder-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
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
|
-
"@
|
|
28
|
-
"@rollup/plugin-
|
|
29
|
-
"@rollup/plugin-
|
|
30
|
-
"@
|
|
31
|
-
"@storybook/
|
|
32
|
-
"
|
|
33
|
-
"@
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"jest": "^
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"ts-
|
|
40
|
-
"typescript": "^5.
|
|
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
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
|
-
|
|
13
|
-
|
|
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')];
|
package/src/preview/render.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { STORY_CHANGED } from '
|
|
2
|
-
import type { RenderContext, ArgsStoryFn } from '
|
|
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
|
|
package/src/preview/types.ts
CHANGED
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
package/dist/preset.d.ts
DELETED
package/dist/preview/render.d.ts
DELETED
|
@@ -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 {};
|