Skip to content

Commit

Permalink
Add ability to find SB config file
Browse files Browse the repository at this point in the history
  • Loading branch information
thafryer committed Dec 21, 2023
1 parent e12fe67 commit 8d9c4f6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
25 changes: 24 additions & 1 deletion bin-src/init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import boxen from "boxen";
import {writeFile} from 'jsonfile';
import { execaCommand } from 'execa';
import { findUp } from 'find-up';
import { writeFile } from 'jsonfile';
import prompts from 'prompts';
import readPkgUp from 'read-pkg-up';
import { getCliCommand, parseNi } from '@antfu/ni';

import type { Configuration } from "../node-src/types";
import noPackageJson from '../node-src/ui/messages/errors/noPackageJson';
Expand All @@ -12,6 +15,15 @@ const TestFrameworkType = {
CYPRESS: 'cypress'
};

const getPackageManagerInstallCommand = async (args: string[]) => {
return getCliCommand(parseNi, args, { programmatic: true });
};

const getSBConfigFilePath = async () => {
// Walks up directory tree to find nearest Storybook config file.
return await findUp(['.storybook/main.ts', '.storybook/main.js', '.storybook/main.tsx', '.storybook/main.jsx', '.storybook/main.mjs', '.storybook/main.cjs'])
}

const addChromaticScriptToPackageJson = async ({testFramework, packageJson, packagePath}) => {
try {
const json = {
Expand Down Expand Up @@ -85,4 +97,15 @@ export async function main() {
onlyChanged: true,
skip: "dependabot/**"
})
const sbConfigPath = await getSBConfigFilePath()
const e2eWithStorybookInstalled = await getPackageManagerInstallCommand(['-D', '@chromaui/test-archiver', '@chromaui/archive-storybook', '@storybook/server-webpack5@<version>'])
const e2eWithoutStorybookInstalled = await getPackageManagerInstallCommand(['-D', '@chromaui/test-archiver', '@chromaui/archive-storybook', '@storybook/cli', '@storybook/addon-essentials', '@storybook/server-webpack5', 'react', 'react-dom'])

if(sbConfigPath) {
await execaCommand(e2eWithStorybookInstalled)
console.log(e2eWithStorybookInstalled)
} else {
await execaCommand(e2eWithoutStorybookInstalled)
console.log(e2eWithoutStorybookInstalled)
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"execa": "^7.2.0",
"fake-tag": "^2.0.0",
"filesize": "^10.1.0",
"find-up": "^7.0.0",
"form-data": "^4.0.0",
"fs-extra": "^10.0.0",
"https-proxy-agent": "^7.0.2",
Expand Down
33 changes: 33 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7870,6 +7870,15 @@ find-up@^5.0.0:
locate-path "^6.0.0"
path-exists "^4.0.0"

find-up@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-7.0.0.tgz#e8dec1455f74f78d888ad65bf7ca13dd2b4e66fb"
integrity sha512-YyZM99iHrqLKjmt4LJDj58KI+fYyufRLBSYcqycxf//KpBk9FoewoGX0450m9nB44qrZnovzC2oeP5hUibxc/g==
dependencies:
locate-path "^7.2.0"
path-exists "^5.0.0"
unicorn-magic "^0.1.0"

flat-cache@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.0.4.tgz#61b0338302b2fe9f957dcc32fc2a87f1c3048b11"
Expand Down Expand Up @@ -10141,6 +10150,13 @@ locate-path@^6.0.0:
dependencies:
p-locate "^5.0.0"

locate-path@^7.2.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-7.2.0.tgz#69cb1779bd90b35ab1e771e1f2f89a202c2a8a8a"
integrity sha512-gvVijfZvn7R+2qyPX8mAuKcFGDf6Nc61GdvGafQsHL0sBIxfKzA+usWn4GFC/bk+QdwPUD4kWFJLhElipq+0VA==
dependencies:
p-locate "^6.0.0"

lodash.camelcase@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
Expand Down Expand Up @@ -11621,6 +11637,13 @@ p-locate@^5.0.0:
dependencies:
p-limit "^3.0.2"

p-locate@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-6.0.0.tgz#3da9a49d4934b901089dca3302fa65dc5a05c04f"
integrity sha512-wPrq66Llhl7/4AGC6I+cqxT07LhXvWL08LNXz1fENOw0Ap4sRZZ/gZpTTJ5jpurzzzfS2W/Ge9BY3LgLjCShcw==
dependencies:
p-limit "^4.0.0"

p-map@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/p-map/-/p-map-2.1.0.tgz#310928feef9c9ecc65b68b17693018a665cea175"
Expand Down Expand Up @@ -11806,6 +11829,11 @@ path-exists@^4.0.0:
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3"
integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==

path-exists@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-5.0.0.tgz#a6aad9489200b21fab31e49cf09277e5116fb9e7"
integrity sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==

path-is-absolute@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
Expand Down Expand Up @@ -15114,6 +15142,11 @@ unicode-property-aliases-ecmascript@^2.0.0:
resolved "https://registry.yarnpkg.com/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-2.0.0.tgz#0a36cb9a585c4f6abd51ad1deddb285c165297c8"
integrity sha512-5Zfuy9q/DFr4tfO7ZPeVXb1aPoeQSdeFMLpYuFebehDAhbuevLs5yxSZmIFN1tP5F9Wl4IpJrYojg85/zgyZHQ==

unicorn-magic@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/unicorn-magic/-/unicorn-magic-0.1.0.tgz#1bb9a51c823aaf9d73a8bfcd3d1a23dde94b0ce4"
integrity sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==

unified-args@^8.0.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/unified-args/-/unified-args-8.1.0.tgz#a27dbe996a49fbbf3d9f5c6a98008ab9b0ee6ae5"
Expand Down

0 comments on commit 8d9c4f6

Please sign in to comment.