mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-05 08:01:20 +08:00
refactor: use getRunStorybookCommand
from package manager
It avoids to use a ternary expression to define the displayed string and encapsulate specific package managers behaviors in their own classes.
This commit is contained in:
parent
0334c801fe
commit
100ffac29c
@ -36,6 +36,7 @@ import preactGenerator from './generators/PREACT';
|
||||
import svelteGenerator from './generators/SVELTE';
|
||||
import raxGenerator from './generators/RAX';
|
||||
import { warn } from './warn';
|
||||
import { JsPackageManagerFactory } from './js-package-manager/JsPackageManagerFactory';
|
||||
|
||||
const logger = console;
|
||||
|
||||
@ -51,10 +52,10 @@ type CommandOptions = {
|
||||
};
|
||||
|
||||
const installStorybook = (projectType: ProjectType, options: CommandOptions): Promise<void> => {
|
||||
const useYarn = Boolean(options.useNpm !== true) && hasYarn();
|
||||
const packageManager = JsPackageManagerFactory.getPackageManager(options.useNpm);
|
||||
|
||||
const npmOptions = {
|
||||
useYarn,
|
||||
useYarn: Boolean(options.useNpm !== true) && hasYarn(),
|
||||
installAsDevDependencies: true,
|
||||
skipInstall: options.skipInstall,
|
||||
};
|
||||
@ -69,15 +70,13 @@ const installStorybook = (projectType: ProjectType, options: CommandOptions): Pr
|
||||
storyFormat: options.storyFormat || defaultStoryFormat,
|
||||
};
|
||||
|
||||
const runStorybookCommand = useYarn ? 'yarn storybook' : 'npm run storybook';
|
||||
|
||||
const end = () => {
|
||||
if (!options.skipInstall) {
|
||||
installDepsFromPackageJson(npmOptions);
|
||||
}
|
||||
|
||||
logger.log('\nTo run your storybook, type:\n');
|
||||
codeLog([runStorybookCommand]);
|
||||
codeLog([packageManager.getRunStorybookCommand()]);
|
||||
logger.log('\nFor more information visit:', chalk.cyan('https://storybook.js.org'));
|
||||
|
||||
// Add a new line for the clear visibility.
|
||||
|
@ -1,3 +1,5 @@
|
||||
export abstract class JsPackageManager {
|
||||
public abstract initPackageJson(): void;
|
||||
|
||||
public abstract getRunStorybookCommand(): string;
|
||||
}
|
||||
|
@ -11,4 +11,8 @@ export class NPMProxy extends JsPackageManager {
|
||||
});
|
||||
return results.stdout;
|
||||
}
|
||||
|
||||
getRunStorybookCommand(): string {
|
||||
return 'npm run storybook';
|
||||
}
|
||||
}
|
||||
|
@ -11,4 +11,8 @@ export class Yarn1Proxy extends JsPackageManager {
|
||||
});
|
||||
return results.stdout;
|
||||
}
|
||||
|
||||
getRunStorybookCommand(): string {
|
||||
return 'yarn storybook';
|
||||
}
|
||||
}
|
||||
|
@ -11,4 +11,8 @@ export class Yarn2Proxy extends JsPackageManager {
|
||||
});
|
||||
return results.stdout;
|
||||
}
|
||||
|
||||
getRunStorybookCommand(): string {
|
||||
return 'yarn storybook';
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user