storybook-onbook-plugin 0.2.3 → 0.2.5
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/dist/cli/index.js +10 -26
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { command, string, run } from '@drizzle-team/brocli';
|
|
|
3
3
|
import { spawn } from 'child_process';
|
|
4
4
|
import path, { resolve, join, dirname } from 'path';
|
|
5
5
|
import crypto from 'crypto';
|
|
6
|
-
import fs, { existsSync
|
|
6
|
+
import fs, { existsSync } from 'fs';
|
|
7
7
|
import { chromium } from 'playwright';
|
|
8
8
|
|
|
9
9
|
var CACHE_DIR = path.join(process.cwd(), ".storybook-cache");
|
|
@@ -237,30 +237,18 @@ function detectPackageManager(repoRoot) {
|
|
|
237
237
|
}
|
|
238
238
|
return "npm";
|
|
239
239
|
}
|
|
240
|
-
function getStorybookScript(storybookDir) {
|
|
241
|
-
const packageJsonPath = join(storybookDir, "package.json");
|
|
242
|
-
if (!existsSync(packageJsonPath)) {
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
246
|
-
return packageJson.scripts?.storybook ?? null;
|
|
247
|
-
}
|
|
248
240
|
|
|
249
241
|
// src/cli/generate-screenshots/generate-screenshots.ts
|
|
250
242
|
function getStorybookCommand(storybookDir) {
|
|
251
|
-
const script = getStorybookScript(storybookDir);
|
|
252
|
-
if (script === null) {
|
|
253
|
-
const packageJsonPath = join(storybookDir, "package.json");
|
|
254
|
-
throw new Error(
|
|
255
|
-
`No "storybook" script found in ${packageJsonPath}. Use --storybook-dir to specify the correct directory or add a storybook script.`
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
243
|
const repoRoot = findRepoRoot(storybookDir);
|
|
259
244
|
const pm = repoRoot ? detectPackageManager(repoRoot) : "npm";
|
|
260
245
|
console.log(
|
|
261
246
|
`\u{1F4E6} Detected package manager: ${pm}${repoRoot ? ` (from ${repoRoot})` : ""}`
|
|
262
247
|
);
|
|
263
|
-
return
|
|
248
|
+
return {
|
|
249
|
+
command: "storybook",
|
|
250
|
+
args: ["dev", "-p", "6006", "--no-open"]
|
|
251
|
+
};
|
|
264
252
|
}
|
|
265
253
|
async function isStorybookRunning(url) {
|
|
266
254
|
try {
|
|
@@ -281,13 +269,9 @@ async function fetchStoryIndex(url) {
|
|
|
281
269
|
const data = await response.json();
|
|
282
270
|
return Object.values(data.entries);
|
|
283
271
|
}
|
|
284
|
-
async function startStorybook(
|
|
285
|
-
console.log(`\u{1F680} Starting Storybook with: ${
|
|
286
|
-
const
|
|
287
|
-
if (!command2) {
|
|
288
|
-
throw new Error("Invalid storybook command");
|
|
289
|
-
}
|
|
290
|
-
const storybookProcess = spawn(command2, [...args, "--", "--no-open"], {
|
|
272
|
+
async function startStorybook(command2, args, storybookDir) {
|
|
273
|
+
console.log(`\u{1F680} Starting Storybook with: ${command2} ${args.join(" ")} (in ${storybookDir})`);
|
|
274
|
+
const storybookProcess = spawn(command2, args, {
|
|
291
275
|
cwd: storybookDir,
|
|
292
276
|
stdio: "pipe",
|
|
293
277
|
shell: true
|
|
@@ -351,8 +335,8 @@ async function generateScreenshots(options = {}) {
|
|
|
351
335
|
if (alreadyRunning) {
|
|
352
336
|
console.log("\u2705 Storybook is already running");
|
|
353
337
|
} else {
|
|
354
|
-
const
|
|
355
|
-
storybookProcess = await startStorybook(
|
|
338
|
+
const { command: command2, args } = getStorybookCommand(storybookDir);
|
|
339
|
+
storybookProcess = await startStorybook(command2, args, storybookDir);
|
|
356
340
|
weStartedStorybook = true;
|
|
357
341
|
}
|
|
358
342
|
const stories = await fetchStoryIndex(url);
|