@ms-cloudpack/storybook-builder 0.5.21 → 0.6.0

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/index.js CHANGED
@@ -33,7 +33,7 @@ export const bail = async (error) => {
33
33
  }
34
34
  }));
35
35
  };
36
- export const start = async ({ options, startTime, router, server: devServer }) => {
36
+ export const start = async ({ options, startTime, router, server: expressServer }) => {
37
37
  const previewResolvedDir = await resolve('@storybook/preview', currentDir);
38
38
  if (!previewResolvedDir) {
39
39
  throw new Error(`Could not resolve @storybook/preview from ${currentDir}`);
@@ -105,7 +105,7 @@ export const start = async ({ options, startTime, router, server: devServer }) =
105
105
  // Start bundle and app servers for hosting the app.
106
106
  const { appServer, bundleServer } = await startServers({
107
107
  definition: appDefinition,
108
- server: devServer,
108
+ expressServer,
109
109
  // TODO: Get options and enable this.
110
110
  bundleServerOptions: { disableCache: false },
111
111
  }, apiContext);
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,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACzF,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,O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AAK,GAA8B,GAAG,EAAE;IACnD,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;IACjE,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 { resolve } from '@ms-cloudpack/package-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { findPackageRoot, normalizedPathRelativeTo } from '@ms-cloudpack/path-utilities';\nimport { loadPreviewOrConfigFile } from '@storybook/core-common';\nimport type { Builder, Options } from '@storybook/types';\nimport fsExtra from 'fs-extra';\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: devServer }) => {\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 fsExtra.ensureDir(cachePath);\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 server: devServer,\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 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,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACzF,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,O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AAO,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,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 { resolve } from '@ms-cloudpack/package-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { findPackageRoot, normalizedPathRelativeTo } from '@ms-cloudpack/path-utilities';\nimport { loadPreviewOrConfigFile } from '@storybook/core-common';\nimport type { Builder, Options } from '@storybook/types';\nimport fsExtra from 'fs-extra';\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 fsExtra.ensureDir(cachePath);\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 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.5.21",
3
+ "version": "0.6.0",
4
4
  "description": "A tool for building storybook bundles for the cloudpack ecosystem.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,17 +22,17 @@
22
22
  "lint": "cloudpack-scripts lint"
23
23
  },
24
24
  "dependencies": {
25
- "@ms-cloudpack/api-server": "^0.52.3",
26
- "@ms-cloudpack/app-server": "^0.15.18",
27
- "@ms-cloudpack/common-types": "^0.20.0",
28
- "@ms-cloudpack/config": "^0.29.2",
29
- "@ms-cloudpack/create-express-app": "^1.9.1",
30
- "@ms-cloudpack/overlay": "^0.17.71",
31
- "@ms-cloudpack/package-utilities": "^10.1.2",
25
+ "@ms-cloudpack/api-server": "^0.53.0",
26
+ "@ms-cloudpack/app-server": "^0.16.0",
27
+ "@ms-cloudpack/common-types": "^0.21.0",
28
+ "@ms-cloudpack/config": "^0.30.0",
29
+ "@ms-cloudpack/create-express-app": "^1.9.2",
30
+ "@ms-cloudpack/overlay": "^0.17.72",
31
+ "@ms-cloudpack/package-utilities": "^10.1.3",
32
32
  "@ms-cloudpack/path-string-parsing": "^1.2.4",
33
- "@ms-cloudpack/path-utilities": "^2.7.45",
33
+ "@ms-cloudpack/path-utilities": "^2.7.46",
34
34
  "@ms-cloudpack/task-reporter": "^0.14.5",
35
- "@ms-cloudpack/telemetry": "^0.6.2",
35
+ "@ms-cloudpack/telemetry": "^0.6.3",
36
36
  "@storybook/core-common": "^7.0.0",
37
37
  "@storybook/node-logger": "^7.0.0",
38
38
  "@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.20.0",
45
+ "@ms-cloudpack/common-types": "^0.21.0",
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"