Skip to content

Commit

Permalink
Run command in shell for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun Lloyd committed Sep 29, 2023
1 parent c40cf15 commit 0e159cd
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,38 @@ const PACKAGE_MANAGER_TO_COMMAND: Record<PackageManagers, string> = {
yarn2: "yarn dlx",
};

const selectPackageManagerCommand = (packageManager: PackageManagers): string =>
PACKAGE_MANAGER_TO_COMMAND[packageManager];

const spawnPackageManagerScript = async (
packageManager: PackageManagers,
args: string[]
) => {
const command = selectPackageManagerCommand(packageManager);

const [pm, ...rest] = command.split(" ");

await spawn(pm, [...rest, ...args], {
stdio: "inherit",
cwd: process.cwd(),
shell: true,
});
};

const automigrate = async ({
packageManager,
packageManager = "npm",
}: {
packageManager: PackageManagers;
}) => {
const command = PACKAGE_MANAGER_TO_COMMAND[packageManager];
await spawn(command, ["@storybook/auto-config", "styling"], {
stdio: "inherit",
cwd: process.cwd(),
});
try {
await spawnPackageManagerScript(packageManager, [
"@storybook/auto-config",
"styling",
]);
} catch (e) {
console.error(e);
process.exit(1);
}
};

export default automigrate;

0 comments on commit 0e159cd

Please sign in to comment.