@ms-cloudpack/storybook-builder 0.6.56 → 0.6.58
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/lib/{createApiContext.d.ts → createCloudpackContext.d.ts} +2 -2
- package/lib/createCloudpackContext.d.ts.map +1 -0
- package/lib/{createApiContext.js → createCloudpackContext.js} +5 -6
- package/lib/createCloudpackContext.js.map +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +19 -14
- package/lib/index.js.map +1 -1
- package/package.json +12 -12
- package/lib/createApiContext.d.ts.map +0 -1
- package/lib/createApiContext.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Context } from '@ms-cloudpack/api-server';
|
|
2
2
|
import type { Options } from '@storybook/types';
|
|
3
3
|
/** Create the Cloudpack context. */
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function createCloudpackContext(options: {
|
|
5
5
|
appPath: string;
|
|
6
6
|
storybookOptions: Options;
|
|
7
7
|
}): Promise<Context>;
|
|
8
|
-
//# sourceMappingURL=
|
|
8
|
+
//# sourceMappingURL=createCloudpackContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createCloudpackContext.d.ts","sourceRoot":"","sources":["../src/createCloudpackContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,OAAO,EAAE,MAAM,0BAA0B,CAAC;AActF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAMhD,oCAAoC;AACpC,wBAAsB,sBAAsB,CAAC,OAAO,EAAE;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,OAAO,CAAC;CAC3B,GAAG,OAAO,CAAC,OAAO,CAAC,CAoEnB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createApiContext, TaskRunner } from '@ms-cloudpack/api-server';
|
|
2
2
|
import { readConfig } from '@ms-cloudpack/config';
|
|
3
3
|
import { environmentInfo } from '@ms-cloudpack/environment';
|
|
4
4
|
import { getDisplayVersion, getVersion } from '@ms-cloudpack/package-utilities';
|
|
@@ -9,7 +9,7 @@ import path from 'path';
|
|
|
9
9
|
import { fileURLToPath } from 'url';
|
|
10
10
|
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
11
11
|
/** Create the Cloudpack context. */
|
|
12
|
-
export async function
|
|
12
|
+
export async function createCloudpackContext(options) {
|
|
13
13
|
const { appPath, storybookOptions } = options;
|
|
14
14
|
const { loglevel } = storybookOptions;
|
|
15
15
|
const config = await readConfig(appPath);
|
|
@@ -52,12 +52,11 @@ export async function createApiContext(options) {
|
|
|
52
52
|
if (overlayPath && !isExternalPackage(overlayPath)) {
|
|
53
53
|
overlayPath = path.resolve(currentDir, '../node_modules/@ms-cloudpack/overlay');
|
|
54
54
|
}
|
|
55
|
-
const apiContext = await
|
|
56
|
-
appPath,
|
|
55
|
+
const apiContext = await createApiContext({
|
|
57
56
|
config,
|
|
58
57
|
reporter,
|
|
59
58
|
telemetryClient,
|
|
60
|
-
|
|
59
|
+
taskRunner: new TaskRunner(),
|
|
61
60
|
overlayPath,
|
|
62
61
|
});
|
|
63
62
|
// TODO: Get options and enable this.
|
|
@@ -67,4 +66,4 @@ export async function createApiContext(options) {
|
|
|
67
66
|
// }
|
|
68
67
|
return apiContext;
|
|
69
68
|
}
|
|
70
|
-
//# sourceMappingURL=
|
|
69
|
+
//# sourceMappingURL=createCloudpackContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createCloudpackContext.js","sourceRoot":"","sources":["../src/createCloudpackContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAgB,MAAM,0BAA0B,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE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;IAEJ,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { createApiContext, TaskRunner, type Context } from '@ms-cloudpack/api-server';\nimport { readConfig } from '@ms-cloudpack/config';\nimport { environmentInfo } from '@ms-cloudpack/environment';\nimport { getDisplayVersion, getVersion } from '@ms-cloudpack/package-utilities';\nimport { isExternalPackage, resolve } from '@ms-cloudpack/path-utilities';\nimport {\n bold,\n debugLoggingConfig,\n defaultLoggingConfig,\n noLoggingConfig,\n TaskReporter,\n verboseLoggingConfig,\n} from '@ms-cloudpack/task-reporter';\nimport { createTelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { Options } from '@storybook/types';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nconst currentDir = path.dirname(fileURLToPath(import.meta.url));\n\n/** Create the Cloudpack context. */\nexport async function createCloudpackContext(options: {\n appPath: string;\n storybookOptions: Options;\n}): Promise<Context> {\n const { appPath, storybookOptions } = options;\n const { loglevel } = storybookOptions;\n\n const config = await readConfig(appPath);\n\n // TODO: Move to won package.\n // runPrerequisites(config, appPath);\n\n // This part should be almost identical to the cli start command.\n const reporter = new TaskReporter({\n productName: 'Storybook + Cloudpack',\n version: getDisplayVersion(import.meta.url),\n description: () => `Running \"${bold('storybook')}\"`,\n helpMessage: config.helpMessage,\n // TODO: Get options and enable this.\n plainTextMode: storybookOptions.ci,\n ...(loglevel === 'debug'\n ? debugLoggingConfig\n : loglevel === 'verbose'\n ? verboseLoggingConfig\n : storybookOptions.quiet || loglevel === 'quiet'\n ? noLoggingConfig\n : defaultLoggingConfig),\n });\n\n const connectionString = storybookOptions.disableTelemetry\n ? undefined\n : config.telemetry?.connectionString || environmentInfo.cloudpack.telemetryConnectionString;\n\n if (loglevel !== 'debug') {\n reporter.ignoreLogMessage('ApplicationInsights:');\n }\n\n const telemetryClient = await createTelemetryClient({\n productVersion: getVersion(import.meta.url),\n connectionString,\n logLevel: loglevel === 'verbose' ? 'VERBOSE' : loglevel === 'debug' ? 'DEBUG' : undefined,\n serviceNamespace: 'cloudpack',\n serviceName: 'storybook',\n });\n\n // Register performance observers to track performance metrics as events of CLI span.\n // registerPerformanceObservers(telemetryClient);\n\n let overlayPath = await resolve('@ms-cloudpack/overlay', currentDir);\n\n // If overlay is an internal package, resolve the overlay from the current package's linked node modules\n // to \"externalize\" it, so that we always use the bundled version of the overlay instead of the source.\n if (overlayPath && !isExternalPackage(overlayPath)) {\n overlayPath = path.resolve(currentDir, '../node_modules/@ms-cloudpack/overlay');\n }\n\n const apiContext = await createApiContext({\n config,\n reporter,\n telemetryClient,\n taskRunner: new TaskRunner(),\n overlayPath,\n });\n\n // TODO: Get options and enable this.\n // Increment the session version if caching is disabled.\n // if (options.cache === false) {\n // session.incrementSessionVersion();\n // }\n\n return apiContext;\n}\n"]}
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAUzD,KAAK,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAUzD,KAAK,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAwBzC,eAAO,MAAM,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAMzC,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAoH3C,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAI3C,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -10,16 +10,13 @@ import path from 'path';
|
|
|
10
10
|
import { fileURLToPath } from 'url';
|
|
11
11
|
import { generateIframeHtml } from './generateIFrameHtml.js';
|
|
12
12
|
import { listStories } from './listStories.js';
|
|
13
|
-
import {
|
|
13
|
+
import { createCloudpackContext } from './createCloudpackContext.js';
|
|
14
14
|
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
await Promise.all(Object.entries(servers).map(async ([name, server]) => {
|
|
21
|
-
if (!server)
|
|
22
|
-
return;
|
|
15
|
+
const disposables = [];
|
|
16
|
+
function addDisposableServer(server, name) {
|
|
17
|
+
if (!server)
|
|
18
|
+
return;
|
|
19
|
+
disposables.push(async () => {
|
|
23
20
|
const desc = `${name} (${server.url})`;
|
|
24
21
|
console.info(`Closing ${desc}`);
|
|
25
22
|
try {
|
|
@@ -29,7 +26,13 @@ export const bail = async (error) => {
|
|
|
29
26
|
catch (err) {
|
|
30
27
|
console.warn(`Error closing ${desc}:`, err);
|
|
31
28
|
}
|
|
32
|
-
})
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export const bail = async (error) => {
|
|
32
|
+
if (error) {
|
|
33
|
+
console.error('Error:', error);
|
|
34
|
+
}
|
|
35
|
+
await Promise.all(disposables.map((d) => d()));
|
|
33
36
|
};
|
|
34
37
|
export const start = async ({ options, startTime, router, server: expressServer }) => {
|
|
35
38
|
const previewResolvedDir = await resolve('@storybook/preview', currentDir);
|
|
@@ -46,7 +49,8 @@ export const start = async ({ options, startTime, router, server: expressServer
|
|
|
46
49
|
if (!appPath) {
|
|
47
50
|
throw new Error(`Could not find package.json relative to ${cwd}`);
|
|
48
51
|
}
|
|
49
|
-
const apiContext = await
|
|
52
|
+
const apiContext = await createCloudpackContext({ appPath, storybookOptions: options });
|
|
53
|
+
disposables.push(() => apiContext.dispose?.());
|
|
50
54
|
const { packages, session } = apiContext;
|
|
51
55
|
const { config } = session;
|
|
52
56
|
// Resolve the story files, and find the preview/config file.
|
|
@@ -94,7 +98,8 @@ export const start = async ({ options, startTime, router, server: expressServer
|
|
|
94
98
|
});
|
|
95
99
|
const { createCloudpackServer } = await import('@ms-cloudpack/api-server');
|
|
96
100
|
// Start api server for tracking status and handling remote requests.
|
|
97
|
-
|
|
101
|
+
const apiServer = await createCloudpackServer({}, apiContext);
|
|
102
|
+
addDisposableServer(apiServer, 'api server');
|
|
98
103
|
// Kick off bundling app package as soon as api server is ready.
|
|
99
104
|
void ensurePackageBundled({
|
|
100
105
|
input: { name: appDefinition.name, version: appDefinition.version },
|
|
@@ -107,8 +112,8 @@ export const start = async ({ options, startTime, router, server: expressServer
|
|
|
107
112
|
// TODO: Get options and enable this.
|
|
108
113
|
bundleServerOptions: { disableCache: false },
|
|
109
114
|
}, apiContext);
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
addDisposableServer(appServer, 'app server');
|
|
116
|
+
addDisposableServer(bundleServer, 'bundle server');
|
|
112
117
|
router.use(appServer.app);
|
|
113
118
|
// TODO: Figure out if it is possible to know when browser will open.
|
|
114
119
|
// performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,M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AC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAA8B,GAAG,EAAE;IACnD,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;IACjE,yEAAyE;IACzE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { ensurePackageBundled } from '@ms-cloudpack/api-server';\nimport { startServers } from '@ms-cloudpack/app-server';\nimport type { PackageJsonExportsObject } from '@ms-cloudpack/common-types';\nimport { getLocalCachePath } from '@ms-cloudpack/config';\nimport { express } from '@ms-cloudpack/create-express-app';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { findPackageRoot, normalizedPathRelativeTo, resolve } from '@ms-cloudpack/path-utilities';\nimport { loadPreviewOrConfigFile } from '@storybook/core-common';\nimport type { Builder, Options } from '@storybook/types';\nimport fsPromises from 'fs/promises';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { generateIframeHtml } from './generateIFrameHtml.js';\nimport { listStories } from './listStories.js';\nimport { createApiContext } from './createApiContext.js';\n\nconst currentDir = path.dirname(fileURLToPath(import.meta.url));\n\ntype CloudpackBuilder = Builder<Options>;\n\ntype ClosableServer = {\n close: () => Promise<void>;\n url: string;\n};\n\nconst servers: Record<string, ClosableServer | undefined> = {};\n\nexport const bail: CloudpackBuilder['bail'] = async (error) => {\n if (error) {\n console.error('Error:', error);\n }\n\n await Promise.all(\n Object.entries(servers).map(async ([name, server]) => {\n if (!server) return;\n\n const desc = `${name} (${server.url})`;\n console.info(`Closing ${desc}`);\n try {\n await server.close();\n console.info(`Closed ${desc}`);\n } catch (err) {\n console.warn(`Error closing ${desc}:`, err);\n }\n }),\n );\n};\n\nexport const start: CloudpackBuilder['start'] = async ({ options, startTime, router, server: expressServer }) => {\n const previewResolvedDir = await resolve('@storybook/preview', currentDir);\n if (!previewResolvedDir) {\n throw new Error(`Could not resolve @storybook/preview from ${currentDir}`);\n }\n const previewDirOrigin = path.join(previewResolvedDir, 'dist');\n\n router.use('/sb-preview', express.static(previewDirOrigin, { immutable: true, maxAge: '5m' }));\n\n // TODO: This might be useful later on.\n // const env = await options.presets.apply<Record<string, string>>('env');\n\n // eslint-disable-next-line no-restricted-properties -- this is where we find the appPath\n const cwd = process.cwd();\n const appPath = findPackageRoot(cwd);\n if (!appPath) {\n throw new Error(`Could not find package.json relative to ${cwd}`);\n }\n\n const apiContext = await createApiContext({ appPath, storybookOptions: options });\n const { packages, session } = apiContext;\n const { config } = session;\n\n // Resolve the story files, and find the preview/config file.\n const { storySpecifiers, resolvedStories } = await listStories({ storybookOptions: options, appPath });\n const previewOrConfigFile = loadPreviewOrConfigFile(options);\n\n // Overwrite the exports of the app package to just contain the stories and preview/config file.\n packages.registerTransform(() => ({ definition, packagePath }) => {\n if (slash(appPath) !== slash(packagePath)) {\n return;\n }\n\n // We just need a simple path mapping for the stories, so it's not necessary to use addExportsMapEntry.\n const exports: PackageJsonExportsObject = {};\n\n for (const story of resolvedStories) {\n if (!story.startsWith('./')) {\n // Not sure if this is even allowed by Storybook, but check just in case...\n // In theory we could handle this by either modifying the exports of the other package too,\n // or possibly by enabling autoUpdateEntries so the file will be bundled on import.\n throw new Error(`Cloudpack does not support stories outside of the package root: ${story}`);\n }\n exports[story] = story;\n }\n\n if (previewOrConfigFile) {\n const normalizedPreview = normalizedPathRelativeTo(appPath, previewOrConfigFile);\n if (!normalizedPreview.startsWith('./')) {\n // Not sure if this is allowed by storybook either\n throw new Error(\n `Cloudpack does not support preview/config files outside of the package root: ${previewOrConfigFile}`,\n );\n }\n exports[normalizedPreview] = normalizedPreview;\n }\n\n return { ...definition, exports };\n });\n\n const appDefinition = await packages.get(appPath);\n\n // Storybook set up is mostly done here.\n const generated = await generateIframeHtml(\n { storybookOptions: options, storySpecifiers, resolvedStories, appDefinition, previewOrConfigFile },\n apiContext,\n );\n\n // TODO: Currently saving it to disk as the config only accepts a path.\n const cachePath = getLocalCachePath(appPath);\n await fsPromises.mkdir(cachePath, { recursive: true });\n const iFramePath = path.join(cachePath, 'iframe.html');\n await fsPromises.writeFile(iFramePath, generated, { encoding: 'utf-8' });\n\n // iFrame script is required for storybook to work.\n config.routes ??= [];\n config.routes.push({\n match: '/iframe.html',\n renderScript: iFramePath,\n });\n\n const { createCloudpackServer } = await import('@ms-cloudpack/api-server');\n\n // Start api server for tracking status and handling remote requests.\n servers.apiServer = await createCloudpackServer({}, apiContext);\n\n // Kick off bundling app package as soon as api server is ready.\n void ensurePackageBundled({\n input: { name: appDefinition.name, version: appDefinition.version },\n ctx: apiContext,\n });\n\n // Start bundle and app servers for hosting the app.\n const { appServer, bundleServer } = await startServers(\n {\n definition: appDefinition,\n expressServer,\n // TODO: Get options and enable this.\n bundleServerOptions: { disableCache: false },\n },\n apiContext,\n );\n servers.appServer = appServer;\n servers.bundleServer = bundleServer;\n\n router.use(appServer.app);\n\n // TODO: Figure out if it is possible to know when browser will open.\n // performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);\n\n return {\n bail,\n totalTime: process.hrtime(startTime),\n };\n};\n\nexport const build: CloudpackBuilder['build'] = () => {\n console.log('Cloudpack Storybook build is not implemented yet.');\n // eslint-disable-next-line no-restricted-properties -- top level handler\n process.exit(1);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,C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U,CACX,CAAC;IACF,mBAAmB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAC7C,mBAAmB,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;IAEnD,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAE1B,qEAAqE;IACrE,uEAAuE;IAEvE,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;KACrC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAA8B,GAAG,EAAE;IACnD,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;IACjE,yEAAyE;IACzE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { ensurePackageBundled } from '@ms-cloudpack/api-server';\nimport { startServers } from '@ms-cloudpack/app-server';\nimport type { PackageJsonExportsObject } from '@ms-cloudpack/common-types';\nimport { getLocalCachePath } from '@ms-cloudpack/config';\nimport { express } from '@ms-cloudpack/create-express-app';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { findPackageRoot, normalizedPathRelativeTo, resolve } from '@ms-cloudpack/path-utilities';\nimport { loadPreviewOrConfigFile } from '@storybook/core-common';\nimport type { Builder, Options } from '@storybook/types';\nimport fsPromises from 'fs/promises';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { generateIframeHtml } from './generateIFrameHtml.js';\nimport { listStories } from './listStories.js';\nimport { createCloudpackContext } from './createCloudpackContext.js';\n\nconst currentDir = path.dirname(fileURLToPath(import.meta.url));\n\ntype CloudpackBuilder = Builder<Options>;\n\ntype ClosableServer = {\n close: () => Promise<void>;\n url: string;\n};\n\nconst disposables: Array<() => void | Promise<void>> = [];\n\nfunction addDisposableServer(server: ClosableServer | undefined, name: string) {\n if (!server) return;\n\n disposables.push(async () => {\n const desc = `${name} (${server.url})`;\n console.info(`Closing ${desc}`);\n try {\n await server.close();\n console.info(`Closed ${desc}`);\n } catch (err) {\n console.warn(`Error closing ${desc}:`, err);\n }\n });\n}\n\nexport const bail: CloudpackBuilder['bail'] = async (error) => {\n if (error) {\n console.error('Error:', error);\n }\n\n await Promise.all(disposables.map((d) => d()));\n};\n\nexport const start: CloudpackBuilder['start'] = async ({ options, startTime, router, server: expressServer }) => {\n const previewResolvedDir = await resolve('@storybook/preview', currentDir);\n if (!previewResolvedDir) {\n throw new Error(`Could not resolve @storybook/preview from ${currentDir}`);\n }\n const previewDirOrigin = path.join(previewResolvedDir, 'dist');\n\n router.use('/sb-preview', express.static(previewDirOrigin, { immutable: true, maxAge: '5m' }));\n\n // TODO: This might be useful later on.\n // const env = await options.presets.apply<Record<string, string>>('env');\n\n // eslint-disable-next-line no-restricted-properties -- this is where we find the appPath\n const cwd = process.cwd();\n const appPath = findPackageRoot(cwd);\n if (!appPath) {\n throw new Error(`Could not find package.json relative to ${cwd}`);\n }\n\n const apiContext = await createCloudpackContext({ appPath, storybookOptions: options });\n disposables.push(() => apiContext.dispose?.());\n const { packages, session } = apiContext;\n const { config } = session;\n\n // Resolve the story files, and find the preview/config file.\n const { storySpecifiers, resolvedStories } = await listStories({ storybookOptions: options, appPath });\n const previewOrConfigFile = loadPreviewOrConfigFile(options);\n\n // Overwrite the exports of the app package to just contain the stories and preview/config file.\n packages.registerTransform(() => ({ definition, packagePath }) => {\n if (slash(appPath) !== slash(packagePath)) {\n return;\n }\n\n // We just need a simple path mapping for the stories, so it's not necessary to use addExportsMapEntry.\n const exports: PackageJsonExportsObject = {};\n\n for (const story of resolvedStories) {\n if (!story.startsWith('./')) {\n // Not sure if this is even allowed by Storybook, but check just in case...\n // In theory we could handle this by either modifying the exports of the other package too,\n // or possibly by enabling autoUpdateEntries so the file will be bundled on import.\n throw new Error(`Cloudpack does not support stories outside of the package root: ${story}`);\n }\n exports[story] = story;\n }\n\n if (previewOrConfigFile) {\n const normalizedPreview = normalizedPathRelativeTo(appPath, previewOrConfigFile);\n if (!normalizedPreview.startsWith('./')) {\n // Not sure if this is allowed by storybook either\n throw new Error(\n `Cloudpack does not support preview/config files outside of the package root: ${previewOrConfigFile}`,\n );\n }\n exports[normalizedPreview] = normalizedPreview;\n }\n\n return { ...definition, exports };\n });\n\n const appDefinition = await packages.get(appPath);\n\n // Storybook set up is mostly done here.\n const generated = await generateIframeHtml(\n { storybookOptions: options, storySpecifiers, resolvedStories, appDefinition, previewOrConfigFile },\n apiContext,\n );\n\n // TODO: Currently saving it to disk as the config only accepts a path.\n const cachePath = getLocalCachePath(appPath);\n await fsPromises.mkdir(cachePath, { recursive: true });\n const iFramePath = path.join(cachePath, 'iframe.html');\n await fsPromises.writeFile(iFramePath, generated, { encoding: 'utf-8' });\n\n // iFrame script is required for storybook to work.\n config.routes ??= [];\n config.routes.push({\n match: '/iframe.html',\n renderScript: iFramePath,\n });\n\n const { createCloudpackServer } = await import('@ms-cloudpack/api-server');\n\n // Start api server for tracking status and handling remote requests.\n const apiServer = await createCloudpackServer({}, apiContext);\n addDisposableServer(apiServer, 'api server');\n\n // Kick off bundling app package as soon as api server is ready.\n void ensurePackageBundled({\n input: { name: appDefinition.name, version: appDefinition.version },\n ctx: apiContext,\n });\n\n // Start bundle and app servers for hosting the app.\n const { appServer, bundleServer } = await startServers(\n {\n definition: appDefinition,\n expressServer,\n // TODO: Get options and enable this.\n bundleServerOptions: { disableCache: false },\n },\n apiContext,\n );\n addDisposableServer(appServer, 'app server');\n addDisposableServer(bundleServer, 'bundle server');\n\n router.use(appServer.app);\n\n // TODO: Figure out if it is possible to know when browser will open.\n // performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);\n\n return {\n bail,\n totalTime: process.hrtime(startTime),\n };\n};\n\nexport const build: CloudpackBuilder['build'] = () => {\n console.log('Cloudpack Storybook build is not implemented yet.');\n // eslint-disable-next-line no-restricted-properties -- top level handler\n process.exit(1);\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/storybook-builder",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.58",
|
|
4
4
|
"description": "A tool for building storybook bundles for the cloudpack ecosystem.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,18 +22,18 @@
|
|
|
22
22
|
"lint": "cloudpack-scripts lint"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@ms-cloudpack/api-server": "^0.
|
|
26
|
-
"@ms-cloudpack/app-server": "^0.17.
|
|
27
|
-
"@ms-cloudpack/common-types": "^0.24.
|
|
28
|
-
"@ms-cloudpack/config": "^0.33.
|
|
29
|
-
"@ms-cloudpack/create-express-app": "^1.10.
|
|
25
|
+
"@ms-cloudpack/api-server": "^0.60.0",
|
|
26
|
+
"@ms-cloudpack/app-server": "^0.17.49",
|
|
27
|
+
"@ms-cloudpack/common-types": "^0.24.7",
|
|
28
|
+
"@ms-cloudpack/config": "^0.33.16",
|
|
29
|
+
"@ms-cloudpack/create-express-app": "^1.10.19",
|
|
30
30
|
"@ms-cloudpack/environment": "^0.1.1",
|
|
31
|
-
"@ms-cloudpack/overlay": "^0.17.
|
|
32
|
-
"@ms-cloudpack/package-utilities": "^11.3.
|
|
31
|
+
"@ms-cloudpack/overlay": "^0.17.130",
|
|
32
|
+
"@ms-cloudpack/package-utilities": "^11.3.4",
|
|
33
33
|
"@ms-cloudpack/path-string-parsing": "^1.2.6",
|
|
34
|
-
"@ms-cloudpack/path-utilities": "^3.0.
|
|
35
|
-
"@ms-cloudpack/task-reporter": "^0.15.
|
|
36
|
-
"@ms-cloudpack/telemetry": "^0.10.
|
|
34
|
+
"@ms-cloudpack/path-utilities": "^3.0.4",
|
|
35
|
+
"@ms-cloudpack/task-reporter": "^0.15.1",
|
|
36
|
+
"@ms-cloudpack/telemetry": "^0.10.14",
|
|
37
37
|
"@storybook/core-common": "^7.0.0",
|
|
38
38
|
"@storybook/node-logger": "^7.0.0",
|
|
39
39
|
"@storybook/preview": "^7.0.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"ts-dedent": "^2.2.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@ms-cloudpack/common-types": "^0.24.
|
|
45
|
+
"@ms-cloudpack/common-types": "^0.24.7",
|
|
46
46
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
47
47
|
"@ms-cloudpack/scripts": "^0.0.1",
|
|
48
48
|
"@storybook/types": "^7.0.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createApiContext.d.ts","sourceRoot":"","sources":["../src/createApiContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAcjF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAMhD,oCAAoC;AACpC,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAqEhH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createApiContext.js","sourceRoot":"","sources":["../src/createApiContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAgB,MAAM,0BAA0B,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EACL,IAAI,EACJ,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,oBAAoB,GACrB,MAAM,6BAA6B,C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,gBAAgB,IAAI,eAAe,CAAC,SAAS,CAAC,yBAAyB,CAAC;IAE9F,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,QAAQ,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,eAAe,GAAG,MAAM,qBAAqB,CAAC;QAClD,cAAc,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;QAC3C,gBAAgB;QAChB,QAAQ,EAAE,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;QACzF,gBAAgB,EAAE,WAAW;QAC7B,WAAW,EAAE,WAAW;KACzB,CAAC,CAAC;IAEH,qFAAqF;IACrF,iDAAiD;IAEjD,IAAI,WAAW,GAAG,MAAM,OAAO,CAAC,uBAAuB,EAAE,UAAU,CAAC,CAAC;IAErE,wGAAwG;IACxG,uGAAuG;IACvG,IAAI,WAAW,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,EAAE,CAAC;QACnD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,uCAAuC,CAAC,CAAC;IAClF,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,uBAAuB,CAAC;QAC/C,OAAO;QACP,MAAM;QACN,QAAQ;QACR,eAAe;QACf,KAAK,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,oBAAoB,EAAE,eAAe,CAAC;QACrG,WAAW;KACZ,CAAC,CAAC;IAEH,qCAAqC;IACrC,wDAAwD;IACxD,iCAAiC;IACjC,uCAAuC;IACvC,IAAI;IAEJ,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { createPartialApiContext, type Context } from '@ms-cloudpack/api-server';\nimport { readConfig } from '@ms-cloudpack/config';\nimport { environmentInfo } from '@ms-cloudpack/environment';\nimport { getDisplayVersion, getVersion } from '@ms-cloudpack/package-utilities';\nimport { isExternalPackage, resolve } from '@ms-cloudpack/path-utilities';\nimport {\n bold,\n debugLoggingConfig,\n defaultLoggingConfig,\n noLoggingConfig,\n TaskReporter,\n verboseLoggingConfig,\n} from '@ms-cloudpack/task-reporter';\nimport { createTelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { Options } from '@storybook/types';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nconst currentDir = path.dirname(fileURLToPath(import.meta.url));\n\n/** Create the Cloudpack context. */\nexport async function createApiContext(options: { appPath: string; storybookOptions: Options }): Promise<Context> {\n const { appPath, storybookOptions } = options;\n const { loglevel } = storybookOptions;\n\n const config = await readConfig(appPath);\n\n // TODO: Move to won package.\n // runPrerequisites(config, appPath);\n\n // This part should be almost identical to the cli start command.\n const reporter = new TaskReporter({\n productName: 'Storybook + Cloudpack',\n version: getDisplayVersion(import.meta.url),\n description: () => `Running \"${bold('storybook')}\"`,\n helpMessage: config.helpMessage,\n // TODO: Get options and enable this.\n plainTextMode: storybookOptions.ci,\n ...(loglevel === 'debug'\n ? debugLoggingConfig\n : loglevel === 'verbose'\n ? verboseLoggingConfig\n : storybookOptions.quiet || loglevel === 'quiet'\n ? noLoggingConfig\n : defaultLoggingConfig),\n });\n\n const connectionString = storybookOptions.disableTelemetry\n ? undefined\n : config.telemetry?.connectionString || environmentInfo.cloudpack.telemetryConnectionString;\n\n if (loglevel !== 'debug') {\n reporter.ignoreLogMessage('ApplicationInsights:');\n }\n\n const telemetryClient = await createTelemetryClient({\n productVersion: getVersion(import.meta.url),\n connectionString,\n logLevel: loglevel === 'verbose' ? 'VERBOSE' : loglevel === 'debug' ? 'DEBUG' : undefined,\n serviceNamespace: 'cloudpack',\n serviceName: 'storybook',\n });\n\n // Register performance observers to track performance metrics as events of CLI span.\n // registerPerformanceObservers(telemetryClient);\n\n let overlayPath = await resolve('@ms-cloudpack/overlay', currentDir);\n\n // If overlay is an internal package, resolve the overlay from the current package's linked node modules\n // to \"externalize\" it, so that we always use the bundled version of the overlay instead of the source.\n if (overlayPath && !isExternalPackage(overlayPath)) {\n overlayPath = path.resolve(currentDir, '../node_modules/@ms-cloudpack/overlay');\n }\n\n const apiContext = await createPartialApiContext({\n appPath,\n config,\n reporter,\n telemetryClient,\n items: ['bus', 'watcher', 'taskRunner', 'packages', 'session', 'packageImportPaths', 'packageHashes'],\n overlayPath,\n });\n\n // TODO: Get options and enable this.\n // Increment the session version if caching is disabled.\n // if (options.cache === false) {\n // session.incrementSessionVersion();\n // }\n\n return apiContext;\n}\n"]}
|