1 | "use strict";
|
2 |
|
3 | require("core-js/modules/es.symbol.description.js");
|
4 |
|
5 | var _commander = _interopRequireDefault(require("commander"));
|
6 |
|
7 | var _path = _interopRequireDefault(require("path"));
|
8 |
|
9 | var _chalk = _interopRequireDefault(require("chalk"));
|
10 |
|
11 | var _envinfo = _interopRequireDefault(require("envinfo"));
|
12 |
|
13 | var _leven = _interopRequireDefault(require("leven"));
|
14 |
|
15 | var _readPkgUp = require("read-pkg-up");
|
16 |
|
17 | var _initiate = require("./initiate");
|
18 |
|
19 | var _add = require("./add");
|
20 |
|
21 | var _migrate = require("./migrate");
|
22 |
|
23 | var _extract = require("./extract");
|
24 |
|
25 | var _upgrade = require("./upgrade");
|
26 |
|
27 | var _repro = require("./repro");
|
28 |
|
29 | var _link = require("./link");
|
30 |
|
31 | var _automigrate = require("./automigrate");
|
32 |
|
33 | var _babelConfig = require("./babel-config");
|
34 |
|
35 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
36 |
|
37 | const pkg = (0, _readPkgUp.sync)({
|
38 | cwd: __dirname
|
39 | }).packageJson;
|
40 | const logger = console;
|
41 |
|
42 | _commander.default.option('--disable-telemetry', 'disable sending telemetry data',
|
43 | process.env.STORYBOOK_DISABLE_TELEMETRY && process.env.STORYBOOK_DISABLE_TELEMETRY !== 'false');
|
44 |
|
45 | _commander.default.option('--enable-crash-reports', 'enable sending crash reports to telemetry data');
|
46 |
|
47 | _commander.default.command('init').description('Initialize Storybook into your project.').option('-f --force', 'Force add Storybook').option('-s --skip-install', 'Skip installing deps').option('-N --use-npm', 'Use npm to install deps').option('-p --parser <babel | babylon | flow | ts | tsx>', 'jscodeshift parser').option('-t --type <type>', 'Add Storybook for a specific project type').option('-y --yes', 'Answer yes to all prompts').option('-b --builder <builder>', 'Builder library').option('-l --linkable', 'Prepare installation for link (contributor helper)').action(options => (0, _initiate.initiate)(options, pkg).catch(err => {
|
48 | logger.error(err);
|
49 | process.exit(1);
|
50 | }));
|
51 |
|
52 | _commander.default.command('add <addon>').description('Add an addon to your Storybook').option('-N --use-npm', 'Use NPM to build the Storybook server').option('-s --skip-postinstall', 'Skip package specific postinstall config modifications').action((addonName, options) => (0, _add.add)(addonName, options));
|
53 |
|
54 | _commander.default.command('babelrc').description('generate the default storybook babel config into your current working directory').action(() => (0, _babelConfig.generateStorybookBabelConfigInCWD)());
|
55 |
|
56 | _commander.default.command('upgrade').description('Upgrade your Storybook packages to the latest').option('-N --use-npm', 'Use NPM to build the Storybook server').option('-y --yes', 'Skip prompting the user').option('-n --dry-run', 'Only check for upgrades, do not install').option('-p --prerelease', 'Upgrade to the pre-release packages').option('-s --skip-check', 'Skip postinstall version and automigration checks').action(options => (0, _upgrade.upgrade)(options));
|
57 |
|
58 | _commander.default.command('info').description('Prints debugging information about the local environment').action(() => {
|
59 | logger.log(_chalk.default.bold('\nEnvironment Info:'));
|
60 |
|
61 | _envinfo.default.run({
|
62 | System: ['OS', 'CPU'],
|
63 | Binaries: ['Node', 'Yarn', 'npm'],
|
64 | Browsers: ['Chrome', 'Edge', 'Firefox', 'Safari'],
|
65 | npmPackages: '@storybook/*',
|
66 | npmGlobalPackages: '@storybook/*'
|
67 | }).then(logger.log);
|
68 | });
|
69 |
|
70 | _commander.default.command('migrate [migration]').description('Run a Storybook codemod migration on your source files').option('-l --list', 'List available migrations').option('-g --glob <glob>', 'Glob for files upon which to apply the migration', '**/*.js').option('-p --parser <babel | babylon | flow | ts | tsx>', 'jscodeshift parser').option('-n --dry-run', 'Dry run: verify the migration exists and show the files to which it will be applied').option('-r --rename <from-to>', 'Rename suffix of matching files after codemod has been applied, e.g. ".js:.ts"').action((migration, {
|
71 | configDir,
|
72 | glob,
|
73 | dryRun,
|
74 | list,
|
75 | rename,
|
76 | parser
|
77 | }) => {
|
78 | (0, _migrate.migrate)(migration, {
|
79 | configDir,
|
80 | glob,
|
81 | dryRun,
|
82 | list,
|
83 | rename,
|
84 | parser,
|
85 | logger
|
86 | }).catch(err => {
|
87 | logger.error(err);
|
88 | process.exit(1);
|
89 | });
|
90 | });
|
91 |
|
92 | _commander.default.command('extract [location] [output]').description('extract stories.json from a built version').action((location = 'storybook-static', output = _path.default.join(location, 'stories.json')) => (0, _extract.extract)(location, output).catch(e => {
|
93 | logger.error(e);
|
94 | process.exit(1);
|
95 | }));
|
96 |
|
97 | _commander.default.command('repro [outputDirectory]').description('Create a reproduction from a set of possible templates').option('-f --framework <framework>', 'Filter on given framework').option('-t --template <template>', 'Use the given template').option('-l --list', 'List available templates').option('-g --generator <generator>', 'Use custom generator command').option('--pnp', "Use Yarn Plug'n'Play mode instead of node_modules one").option('--e2e', 'Used in e2e context').action((outputDirectory, {
|
98 | framework,
|
99 | template,
|
100 | list,
|
101 | e2e,
|
102 | generator,
|
103 | pnp
|
104 | }) => (0, _repro.repro)({
|
105 | outputDirectory,
|
106 | framework,
|
107 | template,
|
108 | list,
|
109 | e2e,
|
110 | generator,
|
111 | pnp
|
112 | }).catch(e => {
|
113 | logger.error(e);
|
114 | process.exit(1);
|
115 | }));
|
116 |
|
117 | _commander.default.command('link <repo-url-or-directory>').description('Pull down a repro from a URL (or a local directory), link it, and run storybook').option('--local', 'Link a local directory already in your file system').action((target, {
|
118 | local
|
119 | }) => (0, _link.link)({
|
120 | target,
|
121 | local
|
122 | }).catch(e => {
|
123 | logger.error(e);
|
124 | process.exit(1);
|
125 | }));
|
126 |
|
127 | _commander.default.command('automigrate [fixId]').description('Check storybook for known problems or migrations and apply fixes').option('-y --yes', 'Skip prompting the user').option('-n --dry-run', 'Only check for fixes, do not actually run them').action((fixId, options) => (0, _automigrate.automigrate)(Object.assign({
|
128 | fixId
|
129 | }, options)).catch(e => {
|
130 | logger.error(e);
|
131 | process.exit(1);
|
132 | }));
|
133 |
|
134 | _commander.default.on('command:*', ([invalidCmd]) => {
|
135 | logger.error(' Invalid command: %s.\n See --help for a list of available commands.', invalidCmd);
|
136 |
|
137 | const availableCommands = _commander.default.commands.map(cmd => cmd._name);
|
138 |
|
139 | const suggestion = availableCommands.find(cmd => (0, _leven.default)(cmd, invalidCmd) < 3);
|
140 |
|
141 | if (suggestion) {
|
142 | logger.log(`\n Did you mean ${suggestion}?`);
|
143 | }
|
144 |
|
145 | process.exit(1);
|
146 | });
|
147 |
|
148 | _commander.default.usage('<command> [options]').version(pkg.version).parse(process.argv); |
\ | No newline at end of file |