mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-16 05:03:11 +08:00
# Conflicts: # addons/a11y/package.json # addons/actions/package.json # addons/backgrounds/package.json # addons/controls/package.json # addons/docs/package.json # addons/essentials/package.json # addons/interactions/package.json # addons/jest/package.json # addons/links/package.json # addons/measure/package.json # addons/outline/package.json # addons/storyshots/storyshots-core/package.json # addons/storysource/package.json # addons/toolbars/package.json # addons/viewport/package.json # docs/faq.md # examples/angular-cli/.storybook/main.js # examples/angular-cli/package.json # examples/cra-kitchen-sink/.storybook/main.js # examples/cra-kitchen-sink/package.json # examples/cra-react15/.storybook/main.js # examples/cra-react15/package.json # examples/cra-ts-essentials/.storybook/main.ts # examples/cra-ts-essentials/package.json # examples/cra-ts-kitchen-sink/.storybook/main.ts # examples/cra-ts-kitchen-sink/package.json # examples/ember-cli/.storybook/main.js # examples/ember-cli/package.json # examples/external-docs/package.json # examples/html-kitchen-sink/.storybook/main.js # examples/html-kitchen-sink/package.json # examples/official-storybook/main.ts # examples/official-storybook/package.json # examples/preact-kitchen-sink/.storybook/main.js # examples/preact-kitchen-sink/package.json # examples/react-ts-webpack4/package.json # examples/react-ts/package.json # examples/server-kitchen-sink/package.json # examples/standalone-preview/package.json # examples/svelte-kitchen-sink/.storybook/main.js # examples/svelte-kitchen-sink/package.json # examples/vue-3-cli/.storybook/main.js # examples/vue-3-cli/package.json # examples/vue-cli/.storybook/main.js # examples/vue-cli/package.json # examples/vue-kitchen-sink/.storybook/main.js # examples/vue-kitchen-sink/package.json # examples/web-components-kitchen-sink/.storybook/main.js # frameworks/angular/package.json # frameworks/ember/package.json # frameworks/preact-webpack5/package.json # frameworks/vue-webpack5/package.json # frameworks/vue3-webpack5/package.json # lib/addons/package.json # lib/api/package.json # lib/builder-webpack4/package.json # lib/builder-webpack5/package.json # lib/channel-postmessage/package.json # lib/channel-websocket/package.json # lib/channels/package.json # lib/cli/package.json # lib/cli/src/automigrate/fixes/angular12.test.ts # lib/cli/src/automigrate/index.ts # lib/cli/src/versions.ts # lib/client-api/package.json # lib/client-logger/package.json # lib/codemod/package.json # lib/components/package.json # lib/core-client/package.json # lib/core-common/package.json # lib/core-events/package.json # lib/core-server/package.json # lib/core-server/src/__snapshots__/vue-3-cli_preview-dev-posix # lib/core-server/src/__snapshots__/vue-3-cli_preview-prod-posix # lib/core-vite/package.json # lib/csf-tools/package.json # lib/docs-tools/package.json # lib/instrumenter/package.json # lib/manager-webpack4/package.json # lib/manager-webpack5/package.json # lib/node-logger/package.json # lib/postinstall/package.json # lib/preview-web/package.json # lib/router/package.json # lib/source-loader/package.json # lib/store/package.json # lib/telemetry/package.json # lib/theming/package.json # lib/ui/package.json # presets/server-webpack/package.json # renderers/html/package.json # renderers/react/package.json # renderers/svelte/package.json # renderers/web-components/package.json # scripts/build-package.js # scripts/bundle-package.ts # yarn.lock
120 lines
3.4 KiB
JavaScript
120 lines
3.4 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/* eslint-disable global-require */
|
|
const { resolve } = require('path');
|
|
const { readJSON } = require('fs-extra');
|
|
|
|
const getStorybookPackages = async () => {
|
|
const workspaceJSON = await readJSON(resolve(__dirname, '..', 'workspace.json'));
|
|
return Object.entries(workspaceJSON.projects).map(([k, v]) => ({ location: v.root, name: k }));
|
|
};
|
|
|
|
async function run() {
|
|
const prompts = require('prompts');
|
|
const program = require('commander');
|
|
const chalk = require('chalk');
|
|
|
|
const packages = await getStorybookPackages();
|
|
const packageTasks = packages
|
|
.map((package) => {
|
|
return {
|
|
...package,
|
|
suffix: package.name.replace('@storybook/', ''),
|
|
defaultValue: false,
|
|
helpText: `build only the ${package.name} package`,
|
|
};
|
|
})
|
|
.reduce((acc, next) => {
|
|
acc[next.name] = next;
|
|
return acc;
|
|
}, {});
|
|
|
|
const tasks = {
|
|
watch: {
|
|
name: `watch`,
|
|
defaultValue: false,
|
|
suffix: '--watch',
|
|
helpText: 'build on watch mode',
|
|
},
|
|
...packageTasks,
|
|
};
|
|
|
|
const main = program.version('5.0.0').option('--all', `build everything ${chalk.gray('(all)')}`);
|
|
|
|
Object.keys(tasks)
|
|
.reduce((acc, key) => acc.option(tasks[key].suffix, tasks[key].helpText), main)
|
|
.parse(process.argv);
|
|
|
|
Object.keys(tasks).forEach((key) => {
|
|
// checks if a flag is passed e.g. yarn build --@storybook/addon-docs --watch
|
|
const containsFlag = program.rawArgs.includes(tasks[key].suffix);
|
|
tasks[key].value = containsFlag || program.all;
|
|
});
|
|
|
|
let selection;
|
|
let watchMode = false;
|
|
if (
|
|
!Object.keys(tasks)
|
|
.map((key) => tasks[key].value)
|
|
.filter(Boolean).length
|
|
) {
|
|
selection = await prompts([
|
|
{
|
|
type: 'toggle',
|
|
name: 'mode',
|
|
message: 'Start in watch mode',
|
|
initial: false,
|
|
active: 'yes',
|
|
inactive: 'no',
|
|
},
|
|
{
|
|
type: 'autocompleteMultiselect',
|
|
message: 'Select the packages to build',
|
|
name: 'todo',
|
|
min: 1,
|
|
hint: 'You can also run directly with package name like `yarn build core`, or `yarn build --all` for all packages!',
|
|
optionsPerPage: require('window-size').height - 3, // 3 lines for extra info
|
|
choices: packages.map(({ name: key }) => ({
|
|
value: key,
|
|
title: tasks[key].name || key,
|
|
selected: (tasks[key] && tasks[key].defaultValue) || false,
|
|
})),
|
|
},
|
|
]).then(({ mode, todo }) => {
|
|
watchMode = mode;
|
|
return todo?.map((key) => tasks[key]);
|
|
});
|
|
} else {
|
|
// hits here when running yarn build --packagename
|
|
watchMode = process.argv.includes('--watch');
|
|
selection = Object.keys(tasks)
|
|
.map((key) => tasks[key])
|
|
.filter((item) => item.name !== 'watch' && item.value === true);
|
|
}
|
|
|
|
selection?.filter(Boolean).forEach(async (v) => {
|
|
const commmand = (await readJSON(resolve(v.location, 'package.json'))).scripts.prepare;
|
|
const cwd = resolve(__dirname, '..', v.location);
|
|
const sub = require('execa').command(`yarn ${commmand}${watchMode ? ' --watch' : ''}`, {
|
|
cwd,
|
|
buffer: false,
|
|
shell: true,
|
|
env: {
|
|
NODE_ENV: 'production',
|
|
},
|
|
});
|
|
|
|
sub.stdout.on('data', (data) => {
|
|
process.stdout.write(`${chalk.cyan(v.name)}:\n${data}`);
|
|
});
|
|
sub.stderr.on('data', (data) => {
|
|
process.stderr.write(`${chalk.red(v.name)}:\n${data}`);
|
|
});
|
|
});
|
|
}
|
|
|
|
run().catch((e) => {
|
|
console.log(e);
|
|
process.exit(1);
|
|
});
|