From ea2fffc963faea66f1b7f289a4afad4dcff8976d Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 27 Jul 2022 20:37:20 +0200 Subject: [PATCH 01/12] add command to publish repos + GH action --- .github/workflows/generate-next-repros.yml | 30 +++++ code/package.json | 1 + .../publish-to-repository/fs-helper.mts | 12 ++ .../publish-to-repository/git-helper.mts | 21 ++++ .../publish-to-repository/index.mts | 103 ++++++++++++++++++ .../templates/main/.stackblitzrc | 4 + .../templates/main/README.md | 11 ++ .../templates/next/.stackblitzrc | 4 + .../templates/next/README.md | 10 ++ 9 files changed, 196 insertions(+) create mode 100644 .github/workflows/generate-next-repros.yml create mode 100644 scripts/next-repro-generators/publish-to-repository/fs-helper.mts create mode 100644 scripts/next-repro-generators/publish-to-repository/git-helper.mts create mode 100755 scripts/next-repro-generators/publish-to-repository/index.mts create mode 100644 scripts/next-repro-generators/publish-to-repository/templates/main/.stackblitzrc create mode 100644 scripts/next-repro-generators/publish-to-repository/templates/main/README.md create mode 100644 scripts/next-repro-generators/publish-to-repository/templates/next/.stackblitzrc create mode 100644 scripts/next-repro-generators/publish-to-repository/templates/next/README.md diff --git a/.github/workflows/generate-next-repros.yml b/.github/workflows/generate-next-repros.yml new file mode 100644 index 000000000000..006ce482dfa4 --- /dev/null +++ b/.github/workflows/generate-next-repros.yml @@ -0,0 +1,30 @@ +name: Generate And Push Repros + +on: + schedule: + - cron: '2 2 */1 * *' + workflow_dispatch: + # To remove when the branch will be merged + push: + branches: + - yann/sb-509-create-github-action + +jobs: + update: + runs-on: ubuntu-latest + env: + YARN_ENABLE_IMMUTABLE_INSTALLS: false + steps: + - uses: actions/checkout@v2 + - name: Setup git user + run: | + git config --global user.name "Storybook Bot" + git config --global user.email "bot@storybook.js.org" + - name: Install dependencies + run: node ./scripts/check-dependencies.js + - name: Change directory + run: cd code + - name: Generate repros + run: yarn next-repro + - name: Publish repros + run: yarn publish-repros --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/repro-templates-temp.git --push --force-push diff --git a/code/package.json b/code/package.json index cd658ab6d4e8..cb9e4b0f9a85 100644 --- a/code/package.json +++ b/code/package.json @@ -74,6 +74,7 @@ "lint:package": "sort-package-json", "local-registry": "ts-node --project=../scripts/tsconfig.json ../scripts/run-registry.ts --port 6000", "next-repro": "ts-node ../scripts/next-repro-generators/index.ts", + "publish-repros": "node --loader ts-node/esm ../scripts/next-repro-generators/publish-to-repository/index.mts", "publish:debug": "npm run publish:latest -- --npm-tag=debug --no-push", "publish:latest": "lerna publish --exact --concurrency 1 --force-publish", "publish:next": "npm run publish:latest -- --npm-tag=next", diff --git a/scripts/next-repro-generators/publish-to-repository/fs-helper.mts b/scripts/next-repro-generators/publish-to-repository/fs-helper.mts new file mode 100644 index 000000000000..1468c520103a --- /dev/null +++ b/scripts/next-repro-generators/publish-to-repository/fs-helper.mts @@ -0,0 +1,12 @@ +import { $ } from 'zx'; + +/** + * Create a tmp directory using `mktemp` command and return the result + */ +export async function createTmpDir() { + return (await $`mktemp -d`).toString().replace('\n', ''); +} + +export async function copy(sourceFile: string, targetDirectory: string) { + return $`cp ${sourceFile} ${targetDirectory}`; +} diff --git a/scripts/next-repro-generators/publish-to-repository/git-helper.mts b/scripts/next-repro-generators/publish-to-repository/git-helper.mts new file mode 100644 index 000000000000..a87efc543a88 --- /dev/null +++ b/scripts/next-repro-generators/publish-to-repository/git-helper.mts @@ -0,0 +1,21 @@ +import { $ } from 'zx'; + +/** + * Git add everything in the directory this method is called and commit all the files + */ +export async function commitEverythingInDirectory(commitMessage: string) { + await $`git add .`; + + try { + await $`git commit -m ${commitMessage}`; + } catch (e) { + console.log(`Nothing to commit ๐Ÿคท`); + } +} + +/** + * Init a Git repository with initial branch named with input string + */ +export async function initRepo(branch: string) { + await $`git init --initial-branch ${branch}`; +} diff --git a/scripts/next-repro-generators/publish-to-repository/index.mts b/scripts/next-repro-generators/publish-to-repository/index.mts new file mode 100755 index 000000000000..03848394eeba --- /dev/null +++ b/scripts/next-repro-generators/publish-to-repository/index.mts @@ -0,0 +1,103 @@ +import { $, cd } from 'zx'; +import { commitEverythingInDirectory, initRepo } from './git-helper.mjs'; +import { copy, createTmpDir } from './fs-helper.mjs'; +import program from 'commander'; +import { dirname, join } from 'path'; +import { existsSync } from 'fs'; +import { fileURLToPath } from 'url'; +import { remove } from 'fs-extra'; + +// @ts-ignore +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const logger = console; + +const REPROS_DIRECTORY = join(__dirname, '..', '..', '..', 'repros'); + +interface PublishOptions { + remote?: string; + push?: boolean; + next?: boolean; + forcePush?: boolean; +} + +let tmpFolder: string; + +const publish = async (options: PublishOptions) => { + if (!existsSync(REPROS_DIRECTORY)) { + throw Error("Can't find repros directory. Did you forget to run generate-repros?"); + } + + const { next: useNextVersion, remote, push, forcePush } = options; + + tmpFolder = await createTmpDir(); + const scriptPath = __dirname; + const templatesFolderPath = join(scriptPath, 'templates'); + const gitBranch = useNextVersion ? 'next' : 'main'; + + cd(tmpFolder); + + await initRepo(gitBranch); + await copy(`${templatesFolderPath}/${gitBranch}/README.md`, tmpFolder); + + await $`cp -r ${REPROS_DIRECTORY}/* ${tmpFolder}`; + + const commitMessage = `Storybook Examples - ${new Date().toDateString()}`; + await commitEverythingInDirectory(commitMessage); + + logger.info(` + All the examples were bootstrapped: + - in ${tmpFolder} + - using the '${gitBranch}' version of Storybook CLI + - and committed on the '${gitBranch}' branch of a local Git repository + + Also all the files in the 'templates' folder were copied at the root of the Git repository. + `); + + try { + if (remote) { + await $`git remote add origin ${remote}`; + + if (push) { + await $`git push --set-upstream origin ${gitBranch} ${forcePush ? '--force' : ''}`; + const remoteRepoUrl = `${remote.replace('.git', '')}/tree/${gitBranch}`; + logger.info(`๐Ÿš€ Everything was pushed on ${remoteRepoUrl}`); + } else { + logger.info(` + To publish these examples you just need to: + - push the branch: 'git push --set-upstream origin ${gitBranch}' (you might need '--force' option ;)) + `); + } + } else { + logger.info(` + To publish these examples you just need to: + - add a remote Git repository: 'git remote add origin XXXXXXX' + - push the branch: 'git push --set-upstream origin ${gitBranch}' (you might need '--force' option ;)) + `); + } + } catch (e) { + logger.error(e); + } +}; + +program + .description('Create a reproduction from a set of possible templates') + .option('--remote ', 'Choose the remote to push the contents to') + .option('--next', 'Whether to use the next version of Storybook CLI', true) + .option('--push', 'Whether to push the contents to the remote', false) + .option('--force-push', 'Whether to force push the changes into the repros repository', false); + +program.parse(process.argv); + +const options = program.opts() as PublishOptions; + +publish(options).catch(async (e) => { + console.error(e); + + if (existsSync(tmpFolder)) { + console.log('removing the temporary folder..'); + await remove(tmpFolder); + } + process.exit(1); +}); diff --git a/scripts/next-repro-generators/publish-to-repository/templates/main/.stackblitzrc b/scripts/next-repro-generators/publish-to-repository/templates/main/.stackblitzrc new file mode 100644 index 000000000000..58bd8bde3389 --- /dev/null +++ b/scripts/next-repro-generators/publish-to-repository/templates/main/.stackblitzrc @@ -0,0 +1,4 @@ +{ + "installDependencies": true, + "startCommand": "yarn storybook" +} diff --git a/scripts/next-repro-generators/publish-to-repository/templates/main/README.md b/scripts/next-repro-generators/publish-to-repository/templates/main/README.md new file mode 100644 index 000000000000..dc23ce78441f --- /dev/null +++ b/scripts/next-repro-generators/publish-to-repository/templates/main/README.md @@ -0,0 +1,11 @@ +# Storybook Reproduction Templates + +![Storybook Latest Badge](https://img.shields.io/npm/v/@storybook/react/latest) + +The repros have been generated with the latest stable version of Storybook. +If you want to try the cutting edge version go on the `next` branch. + +Preview any repro live on [StackBlitz](http://stackblitz.com/): + +- [Create React App](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/cra/default-js/after-storybook?preset=node) +- [Create React App + TypeScript](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/cra/default-ts/after-storybook?preset=node) \ No newline at end of file diff --git a/scripts/next-repro-generators/publish-to-repository/templates/next/.stackblitzrc b/scripts/next-repro-generators/publish-to-repository/templates/next/.stackblitzrc new file mode 100644 index 000000000000..58bd8bde3389 --- /dev/null +++ b/scripts/next-repro-generators/publish-to-repository/templates/next/.stackblitzrc @@ -0,0 +1,4 @@ +{ + "installDependencies": true, + "startCommand": "yarn storybook" +} diff --git a/scripts/next-repro-generators/publish-to-repository/templates/next/README.md b/scripts/next-repro-generators/publish-to-repository/templates/next/README.md new file mode 100644 index 000000000000..7e138f3d87b8 --- /dev/null +++ b/scripts/next-repro-generators/publish-to-repository/templates/next/README.md @@ -0,0 +1,10 @@ +# Storybook Reproduction Templates + +![Storybook Latest Badge](https://img.shields.io/npm/v/@storybook/react/next) + +The repros have been generated with the latest stable version of Storybook + +Preview any repro live on [StackBlitz](http://stackblitz.com/): + +- [Create React App](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/cra/default-js/after-storybook?preset=node) +- [Create React App + TypeScript](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/cra/default-ts/after-storybook?preset=node) \ No newline at end of file From a2f1baefaa1725f9ab5c7c0469bd8caf7c03aa37 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 27 Jul 2022 20:46:14 +0200 Subject: [PATCH 02/12] update action --- .github/workflows/generate-next-repros.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/generate-next-repros.yml b/.github/workflows/generate-next-repros.yml index 006ce482dfa4..974cf24cf6f5 100644 --- a/.github/workflows/generate-next-repros.yml +++ b/.github/workflows/generate-next-repros.yml @@ -22,9 +22,11 @@ jobs: git config --global user.email "bot@storybook.js.org" - name: Install dependencies run: node ./scripts/check-dependencies.js - - name: Change directory - run: cd code - name: Generate repros - run: yarn next-repro + run: | + pwd + yarn next-repro + working-directory: ./code - name: Publish repros run: yarn publish-repros --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/repro-templates-temp.git --push --force-push + working-directory: ./code From 113edf02ad8eede13516a56df16f469a8926ff01 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 27 Jul 2022 20:53:44 +0200 Subject: [PATCH 03/12] switch to npx --- scripts/next-repro-generators/repro-config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/next-repro-generators/repro-config.yml b/scripts/next-repro-generators/repro-config.yml index 853ec5d464b2..2112cd37c86b 100644 --- a/scripts/next-repro-generators/repro-config.yml +++ b/scripts/next-repro-generators/repro-config.yml @@ -1,13 +1,13 @@ # group-name/instance-name. Should always be two levels deep. cra/default-js: - script: "yarn create react-app ." + script: "npx create-react-app ." expected: framework: "@storybook/cra" renderer: "@storybook/react" builder: "@storybook/builder-webpack5" cra/default-ts: - script: "yarn create react-app . --template typescript" + script: "npx create-react-app . --template typescript" expected: framework: "@storybook/cra" renderer: "@storybook/react" From a2c7b7149502cd63d39bc00a9237859c5514c37d Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 27 Jul 2022 20:59:25 +0200 Subject: [PATCH 04/12] update action --- .github/workflows/generate-next-repros.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate-next-repros.yml b/.github/workflows/generate-next-repros.yml index 974cf24cf6f5..a91599a49ef5 100644 --- a/.github/workflows/generate-next-repros.yml +++ b/.github/workflows/generate-next-repros.yml @@ -24,7 +24,7 @@ jobs: run: node ./scripts/check-dependencies.js - name: Generate repros run: | - pwd + yarn bootstrap --prep yarn next-repro working-directory: ./code - name: Publish repros From ae6c332c94ae302c9f2d0223b43bbf1c7d1cbc70 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 27 Jul 2022 21:21:09 +0200 Subject: [PATCH 05/12] update action --- .github/workflows/generate-next-repros.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/generate-next-repros.yml b/.github/workflows/generate-next-repros.yml index a91599a49ef5..fe22102c9f7f 100644 --- a/.github/workflows/generate-next-repros.yml +++ b/.github/workflows/generate-next-repros.yml @@ -22,10 +22,11 @@ jobs: git config --global user.email "bot@storybook.js.org" - name: Install dependencies run: node ./scripts/check-dependencies.js + - name: Bootstrap Storybook libraries + run: yarn bootstrap --prep + working-directory: ./code - name: Generate repros - run: | - yarn bootstrap --prep - yarn next-repro + run: yarn next-repro working-directory: ./code - name: Publish repros run: yarn publish-repros --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/repro-templates-temp.git --push --force-push From 37075f3da9cb581fc64bcd8be735e09201c70e39 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Fri, 29 Jul 2022 10:59:30 +0200 Subject: [PATCH 06/12] rename next-repros action --- .../{generate-next-repros.yml => generate-repros-next.yml} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{generate-next-repros.yml => generate-repros-next.yml} (90%) diff --git a/.github/workflows/generate-next-repros.yml b/.github/workflows/generate-repros-next.yml similarity index 90% rename from .github/workflows/generate-next-repros.yml rename to .github/workflows/generate-repros-next.yml index fe22102c9f7f..38a6fd377816 100644 --- a/.github/workflows/generate-next-repros.yml +++ b/.github/workflows/generate-repros-next.yml @@ -1,4 +1,4 @@ -name: Generate And Push Repros +name: Generate and push repros to the next branch on: schedule: @@ -10,7 +10,7 @@ on: - yann/sb-509-create-github-action jobs: - update: + generate: runs-on: ubuntu-latest env: YARN_ENABLE_IMMUTABLE_INSTALLS: false @@ -28,6 +28,6 @@ jobs: - name: Generate repros run: yarn next-repro working-directory: ./code - - name: Publish repros + - name: Publish repros to GitHub run: yarn publish-repros --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/repro-templates-temp.git --push --force-push working-directory: ./code From de83f4f70d671e8d322b1d5c43942d34fe983db7 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Fri, 29 Jul 2022 12:39:01 +0200 Subject: [PATCH 07/12] replace zx with execa and fs-extra commands --- .../publish-to-repository/fs-helper.mts | 12 ---- .../publish-to-repository/git-helper.mts | 21 ------- .../publish-to-repository/index.mts | 56 ++++++++++++------ .../templates/main/.stackblitzrc | 4 -- .../templates/main/README.md | 3 +- .../templates/next/.stackblitzrc | 4 -- .../templates/next/README.md | 7 ++- scripts/package.json | 1 + scripts/yarn.lock | 59 +++++++++++++++++++ 9 files changed, 104 insertions(+), 63 deletions(-) delete mode 100644 scripts/next-repro-generators/publish-to-repository/fs-helper.mts delete mode 100644 scripts/next-repro-generators/publish-to-repository/git-helper.mts delete mode 100644 scripts/next-repro-generators/publish-to-repository/templates/main/.stackblitzrc delete mode 100644 scripts/next-repro-generators/publish-to-repository/templates/next/.stackblitzrc diff --git a/scripts/next-repro-generators/publish-to-repository/fs-helper.mts b/scripts/next-repro-generators/publish-to-repository/fs-helper.mts deleted file mode 100644 index 1468c520103a..000000000000 --- a/scripts/next-repro-generators/publish-to-repository/fs-helper.mts +++ /dev/null @@ -1,12 +0,0 @@ -import { $ } from 'zx'; - -/** - * Create a tmp directory using `mktemp` command and return the result - */ -export async function createTmpDir() { - return (await $`mktemp -d`).toString().replace('\n', ''); -} - -export async function copy(sourceFile: string, targetDirectory: string) { - return $`cp ${sourceFile} ${targetDirectory}`; -} diff --git a/scripts/next-repro-generators/publish-to-repository/git-helper.mts b/scripts/next-repro-generators/publish-to-repository/git-helper.mts deleted file mode 100644 index a87efc543a88..000000000000 --- a/scripts/next-repro-generators/publish-to-repository/git-helper.mts +++ /dev/null @@ -1,21 +0,0 @@ -import { $ } from 'zx'; - -/** - * Git add everything in the directory this method is called and commit all the files - */ -export async function commitEverythingInDirectory(commitMessage: string) { - await $`git add .`; - - try { - await $`git commit -m ${commitMessage}`; - } catch (e) { - console.log(`Nothing to commit ๐Ÿคท`); - } -} - -/** - * Init a Git repository with initial branch named with input string - */ -export async function initRepo(branch: string) { - await $`git init --initial-branch ${branch}`; -} diff --git a/scripts/next-repro-generators/publish-to-repository/index.mts b/scripts/next-repro-generators/publish-to-repository/index.mts index 03848394eeba..93276ae93325 100755 --- a/scripts/next-repro-generators/publish-to-repository/index.mts +++ b/scripts/next-repro-generators/publish-to-repository/index.mts @@ -1,18 +1,18 @@ -import { $, cd } from 'zx'; -import { commitEverythingInDirectory, initRepo } from './git-helper.mjs'; -import { copy, createTmpDir } from './fs-helper.mjs'; +/* eslint-disable no-underscore-dangle */ import program from 'commander'; import { dirname, join } from 'path'; import { existsSync } from 'fs'; +import { command } from 'execa'; +import { temporaryDirectory } from 'tempy'; +import { remove, copy } from 'fs-extra'; import { fileURLToPath } from 'url'; -import { remove } from 'fs-extra'; + +const logger = console; // @ts-ignore const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -const logger = console; - const REPROS_DIRECTORY = join(__dirname, '..', '..', '..', 'repros'); interface PublishOptions { @@ -31,20 +31,38 @@ const publish = async (options: PublishOptions) => { const { next: useNextVersion, remote, push, forcePush } = options; - tmpFolder = await createTmpDir(); + tmpFolder = temporaryDirectory(); + + logger.log(`Created tmp folder: ${tmpFolder}`); + const scriptPath = __dirname; const templatesFolderPath = join(scriptPath, 'templates'); const gitBranch = useNextVersion ? 'next' : 'main'; - cd(tmpFolder); + logger.log(`Cloning the repository ${remote} in branch ${gitBranch}`); + await command(`git clone ${remote} .`, { cwd: tmpFolder }); + await command(`git checkout ${gitBranch}`, { cwd: tmpFolder }); - await initRepo(gitBranch); - await copy(`${templatesFolderPath}/${gitBranch}/README.md`, tmpFolder); + logger.log(`Moving template files into the repository`); + await copy(join(templatesFolderPath, gitBranch), tmpFolder, { overwrite: true }); - await $`cp -r ${REPROS_DIRECTORY}/* ${tmpFolder}`; + logger.log(`Moving all the repros into the repository`); + await copy(join(REPROS_DIRECTORY), tmpFolder); - const commitMessage = `Storybook Examples - ${new Date().toDateString()}`; - await commitEverythingInDirectory(commitMessage); + try { + logger.log(`Committing everything to the repository`); + + await command('git add .', { cwd: tmpFolder }); + + const currentCommitSHA = command('git rev-parse HEAD'); + await command( + `git commit -m Update Storybook Examples - ${new Date().toDateString()} - ${currentCommitSHA}` + ); + } catch (e) { + logger.log( + `Git found no changes between previous versions so there is nothing to commit. Skipping publish!` + ); + } logger.info(` All the examples were bootstrapped: @@ -57,10 +75,12 @@ const publish = async (options: PublishOptions) => { try { if (remote) { - await $`git remote add origin ${remote}`; + await command(`git remote add origin ${remote}`, { cwd: tmpFolder }); if (push) { - await $`git push --set-upstream origin ${gitBranch} ${forcePush ? '--force' : ''}`; + await command(`git push --set-upstream origin ${gitBranch} ${forcePush ? '--force' : ''}`, { + cwd: tmpFolder, + }); const remoteRepoUrl = `${remote.replace('.git', '')}/tree/${gitBranch}`; logger.info(`๐Ÿš€ Everything was pushed on ${remoteRepoUrl}`); } else { @@ -93,11 +113,11 @@ program.parse(process.argv); const options = program.opts() as PublishOptions; publish(options).catch(async (e) => { - console.error(e); + logger.error(e); if (existsSync(tmpFolder)) { - console.log('removing the temporary folder..'); - await remove(tmpFolder); + // logger.log('removing the temporary folder..'); + // await remove(tmpFolder); } process.exit(1); }); diff --git a/scripts/next-repro-generators/publish-to-repository/templates/main/.stackblitzrc b/scripts/next-repro-generators/publish-to-repository/templates/main/.stackblitzrc deleted file mode 100644 index 58bd8bde3389..000000000000 --- a/scripts/next-repro-generators/publish-to-repository/templates/main/.stackblitzrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "installDependencies": true, - "startCommand": "yarn storybook" -} diff --git a/scripts/next-repro-generators/publish-to-repository/templates/main/README.md b/scripts/next-repro-generators/publish-to-repository/templates/main/README.md index dc23ce78441f..c08c1d9c5c2b 100644 --- a/scripts/next-repro-generators/publish-to-repository/templates/main/README.md +++ b/scripts/next-repro-generators/publish-to-repository/templates/main/README.md @@ -1,3 +1,4 @@ + # Storybook Reproduction Templates ![Storybook Latest Badge](https://img.shields.io/npm/v/@storybook/react/latest) @@ -8,4 +9,4 @@ If you want to try the cutting edge version go on the `next` branch. Preview any repro live on [StackBlitz](http://stackblitz.com/): - [Create React App](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/cra/default-js/after-storybook?preset=node) -- [Create React App + TypeScript](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/cra/default-ts/after-storybook?preset=node) \ No newline at end of file +- [Create React App + TypeScript](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/cra/default-ts/after-storybook?preset=node) diff --git a/scripts/next-repro-generators/publish-to-repository/templates/next/.stackblitzrc b/scripts/next-repro-generators/publish-to-repository/templates/next/.stackblitzrc deleted file mode 100644 index 58bd8bde3389..000000000000 --- a/scripts/next-repro-generators/publish-to-repository/templates/next/.stackblitzrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "installDependencies": true, - "startCommand": "yarn storybook" -} diff --git a/scripts/next-repro-generators/publish-to-repository/templates/next/README.md b/scripts/next-repro-generators/publish-to-repository/templates/next/README.md index 7e138f3d87b8..215d3ee54621 100644 --- a/scripts/next-repro-generators/publish-to-repository/templates/next/README.md +++ b/scripts/next-repro-generators/publish-to-repository/templates/next/README.md @@ -1,10 +1,11 @@ + # Storybook Reproduction Templates -![Storybook Latest Badge](https://img.shields.io/npm/v/@storybook/react/next) +![Storybook Next Badge](https://img.shields.io/npm/v/@storybook/react/next) The repros have been generated with the latest stable version of Storybook Preview any repro live on [StackBlitz](http://stackblitz.com/): -- [Create React App](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/cra/default-js/after-storybook?preset=node) -- [Create React App + TypeScript](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/cra/default-ts/after-storybook?preset=node) \ No newline at end of file +- [Create React App](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/next/cra/default-js/after-storybook?preset=node) +- [Create React App + TypeScript](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/next/cra/default-ts/after-storybook?preset=node) \ No newline at end of file diff --git a/scripts/package.json b/scripts/package.json index 3f0af3afbd6d..89a2c407424d 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -167,6 +167,7 @@ "shx": "^0.3.2", "slash": "^3.0.0", "sort-package-json": "^1.48.1", + "tempy": "^3.0.0", "trash": "^7.0.0", "ts-dedent": "^2.0.0", "ts-jest": "^26.4.4", diff --git a/scripts/yarn.lock b/scripts/yarn.lock index 7ebe87564f9f..84313cf6c240 100644 --- a/scripts/yarn.lock +++ b/scripts/yarn.lock @@ -3355,6 +3355,7 @@ __metadata: shx: ^0.3.2 slash: ^3.0.0 sort-package-json: ^1.48.1 + tempy: ^3.0.0 trash: ^7.0.0 ts-dedent: ^2.0.0 ts-jest: ^26.4.4 @@ -6831,6 +6832,15 @@ __metadata: languageName: node linkType: hard +"crypto-random-string@npm:^4.0.0": + version: 4.0.0 + resolution: "crypto-random-string@npm:4.0.0" + dependencies: + type-fest: ^1.0.1 + checksum: 16e11a3c8140398f5408b7fded35a961b9423c5dac39a60cbbd08bd3f0e07d7de130e87262adea7db03ec1a7a4b7551054e0db07ee5408b012bac5400cfc07a5 + languageName: node + linkType: hard + "css-select@npm:^5.1.0": version: 5.1.0 resolution: "css-select@npm:5.1.0" @@ -11457,6 +11467,13 @@ __metadata: languageName: node linkType: hard +"is-stream@npm:^3.0.0": + version: 3.0.0 + resolution: "is-stream@npm:3.0.0" + checksum: eb2f7127af02ee9aa2a0237b730e47ac2de0d4e76a4a905a50a11557f2339df5765eaea4ceb8029f1efa978586abe776908720bfcb1900c20c6ec5145f6f29d8 + languageName: node + linkType: hard + "is-string@npm:^1.0.5, is-string@npm:^1.0.7": version: 1.0.7 resolution: "is-string@npm:1.0.7" @@ -18523,6 +18540,25 @@ __metadata: languageName: node linkType: hard +"temp-dir@npm:^2.0.0": + version: 2.0.0 + resolution: "temp-dir@npm:2.0.0" + checksum: b1df969e3f3f7903f3426861887ed76ba3b495f63f6d0c8e1ce22588679d9384d336df6064210fda14e640ed422e2a17d5c40d901f60e161c99482d723f4d309 + languageName: node + linkType: hard + +"tempy@npm:^3.0.0": + version: 3.0.0 + resolution: "tempy@npm:3.0.0" + dependencies: + is-stream: ^3.0.0 + temp-dir: ^2.0.0 + type-fest: ^2.12.2 + unique-string: ^3.0.0 + checksum: 281797a81417fc04b07ef77dc9d9870624b83980b6c6d0d9075f265f2617da04b83850f4c1c68ffa2904a0c50fc22790c104b923243a57885cd84a1379b6ce0e + languageName: node + linkType: hard + "terminal-link@npm:^2.0.0": version: 2.1.1 resolution: "terminal-link@npm:2.1.1" @@ -19103,6 +19139,20 @@ __metadata: languageName: node linkType: hard +"type-fest@npm:^1.0.1": + version: 1.4.0 + resolution: "type-fest@npm:1.4.0" + checksum: a3c0f4ee28ff6ddf800d769eafafcdeab32efa38763c1a1b8daeae681920f6e345d7920bf277245235561d8117dab765cb5f829c76b713b4c9de0998a5397141 + languageName: node + linkType: hard + +"type-fest@npm:^2.12.2": + version: 2.17.0 + resolution: "type-fest@npm:2.17.0" + checksum: e7707e5c27213919483011d127f333432d82d06b697ca0577cc828b53d384372b4308d3294e849b0111a34fdc7adf5bdef58c5ffa80aa36d19e9851b2a8d9970 + languageName: node + linkType: hard + "type-is@npm:~1.6.17, type-is@npm:~1.6.18": version: 1.6.18 resolution: "type-is@npm:1.6.18" @@ -19365,6 +19415,15 @@ __metadata: languageName: node linkType: hard +"unique-string@npm:^3.0.0": + version: 3.0.0 + resolution: "unique-string@npm:3.0.0" + dependencies: + crypto-random-string: ^4.0.0 + checksum: b35ea034b161b2a573666ec16c93076b4b6106b8b16c2415808d747ab3a0566b5db0c4be231d4b11cfbc16d7fd915c9d8a45884bff0e2db11b799775b2e1e017 + languageName: node + linkType: hard + "unist-util-generated@npm:^1.0.0, unist-util-generated@npm:^1.1.0": version: 1.1.6 resolution: "unist-util-generated@npm:1.1.6" From f4020949d61da71a64ea0ab1ab950bde842838b0 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Fri, 29 Jul 2022 14:29:13 +0200 Subject: [PATCH 08/12] make it dynamic form a template --- .../publish-to-repository/index.mts | 6 +++-- .../publish-to-repository/templates/item.ejs | 1 + .../publish-to-repository/templates/root.ejs | 26 +++++++++++++++++++ scripts/package.json | 2 ++ scripts/yarn.lock | 11 +++++++- 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 scripts/next-repro-generators/publish-to-repository/templates/item.ejs create mode 100644 scripts/next-repro-generators/publish-to-repository/templates/root.ejs diff --git a/scripts/next-repro-generators/publish-to-repository/index.mts b/scripts/next-repro-generators/publish-to-repository/index.mts index 93276ae93325..3b2053936e68 100755 --- a/scripts/next-repro-generators/publish-to-repository/index.mts +++ b/scripts/next-repro-generators/publish-to-repository/index.mts @@ -4,7 +4,8 @@ import { dirname, join } from 'path'; import { existsSync } from 'fs'; import { command } from 'execa'; import { temporaryDirectory } from 'tempy'; -import { remove, copy } from 'fs-extra'; +import { render } from 'ejs'; +import { copy, writeFile } from 'fs-extra'; import { fileURLToPath } from 'url'; const logger = console; @@ -44,7 +45,8 @@ const publish = async (options: PublishOptions) => { await command(`git checkout ${gitBranch}`, { cwd: tmpFolder }); logger.log(`Moving template files into the repository`); - await copy(join(templatesFolderPath, gitBranch), tmpFolder, { overwrite: true }); + await writeFile(join(tmpFolder, 'README.md'), render(join(templatesFolderPath, 'root.ejs'), { data: {} })); + // await copy(join(templatesFolderPath, gitBranch), tmpFolder, { overwrite: true }); logger.log(`Moving all the repros into the repository`); await copy(join(REPROS_DIRECTORY), tmpFolder); diff --git a/scripts/next-repro-generators/publish-to-repository/templates/item.ejs b/scripts/next-repro-generators/publish-to-repository/templates/item.ejs new file mode 100644 index 000000000000..bc33fe60ccb8 --- /dev/null +++ b/scripts/next-repro-generators/publish-to-repository/templates/item.ejs @@ -0,0 +1 @@ +

todo

; diff --git a/scripts/next-repro-generators/publish-to-repository/templates/root.ejs b/scripts/next-repro-generators/publish-to-repository/templates/root.ejs new file mode 100644 index 000000000000..3276a7bb8183 --- /dev/null +++ b/scripts/next-repro-generators/publish-to-repository/templates/root.ejs @@ -0,0 +1,26 @@ +

Storybook Reproduction Templates

+ +Storybook Latest Badge + +

The repros have been generated with the latest stable version of Storybook.

+ +<% if (typeof data !== 'undefined' && Object.keys(data).length) { %> +

Preview any repro live on [StackBlitz](http://stackblitz.com/):

+ <% for (var groupName in data) { %> + <% if (data[groupName] !== undefined) { %> +

<%- (groupName) %>

+
    + <% for (var exampleName in data[groupName]) { %> + <% if (data[groupName][exampleName] !== undefined) { %> +
  • + + <%=groupName['name']%> + +
  • + <% } %> + <% } %> +
+ <% } %> + <% } %> + +<% } %> diff --git a/scripts/package.json b/scripts/package.json index 89a2c407424d..3f421a0cc201 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -77,6 +77,7 @@ "@testing-library/user-event": "^13.2.1", "@types/detect-port": "^1.3.2", "@types/doctrine": "^0.0.3", + "@types/ejs": "^3.1.1", "@types/enzyme": "^3.10.8", "@types/escodegen": "^0.0.6", "@types/express": "^4.17.11", @@ -110,6 +111,7 @@ "danger": "^10.6.2", "detect-port": "^1.3.0", "dts-bundle-generator": "^6.2.0", + "ejs": "^3.1.8", "enzyme": "^3.11.0", "enzyme-adapter-react-16": "^1.15.5", "esbuild": "^0.14.48", diff --git a/scripts/yarn.lock b/scripts/yarn.lock index 84313cf6c240..0b0a6c69bd99 100644 --- a/scripts/yarn.lock +++ b/scripts/yarn.lock @@ -3263,6 +3263,7 @@ __metadata: "@testing-library/user-event": ^13.2.1 "@types/detect-port": ^1.3.2 "@types/doctrine": ^0.0.3 + "@types/ejs": ^3.1.1 "@types/enzyme": ^3.10.8 "@types/escodegen": ^0.0.6 "@types/express": ^4.17.11 @@ -3297,6 +3298,7 @@ __metadata: danger: ^10.6.2 detect-port: ^1.3.0 dts-bundle-generator: ^6.2.0 + ejs: ^3.1.8 enzyme: ^3.11.0 enzyme-adapter-react-16: ^1.15.5 esbuild: ^0.14.48 @@ -3650,6 +3652,13 @@ __metadata: languageName: node linkType: hard +"@types/ejs@npm:^3.1.1": + version: 3.1.1 + resolution: "@types/ejs@npm:3.1.1" + checksum: 922083d5bb5ae290856ea334d85e20765b588987bcdf3a2e81aa724503cb127acb2bd63fddf91bdafa24b46768fe402a6acaa47ab7a4ae520efb162a5757abca + languageName: node + linkType: hard + "@types/enzyme@npm:^3.10.8": version: 3.10.12 resolution: "@types/enzyme@npm:3.10.12" @@ -7695,7 +7704,7 @@ __metadata: languageName: node linkType: hard -"ejs@npm:^3.1.5": +"ejs@npm:^3.1.5, ejs@npm:^3.1.8": version: 3.1.8 resolution: "ejs@npm:3.1.8" dependencies: From fd4bfe00b12ba857809bdf920def51567c5b5582 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Fri, 29 Jul 2022 16:38:03 +0200 Subject: [PATCH 09/12] refactor and improve repro generate and publish scripts --- .github/workflows/generate-repros-next.yml | 2 +- .vscode/settings.json | 7 +- code/package.json | 4 +- generate-repros.sh | 2 +- .../{index.ts => generate.ts} | 11 +- .../publish-to-repository/index.mts | 125 ------------------ .../publish-to-repository/templates/item.ejs | 1 - .../templates/main/README.md | 12 -- .../templates/next/README.md | 11 -- .../publish-to-repository/templates/root.ejs | 26 ---- scripts/next-repro-generators/publish.ts | 95 +++++++++++++ .../next-repro-generators/repro-config.yml | 2 + .../next-repro-generators/templates/item.ejs | 18 +++ .../next-repro-generators/templates/root.ejs | 27 ++++ scripts/next-repro-generators/utils/git.ts | 25 ++++ .../next-repro-generators/utils/template.ts | 47 +++++++ scripts/next-repro-generators/utils/types.ts | 4 + scripts/next-repro-generators/utils/yarn.ts | 2 +- scripts/package.json | 2 +- scripts/yarn.lock | 90 +++++++------ 20 files changed, 280 insertions(+), 233 deletions(-) rename scripts/next-repro-generators/{index.ts => generate.ts} (95%) delete mode 100755 scripts/next-repro-generators/publish-to-repository/index.mts delete mode 100644 scripts/next-repro-generators/publish-to-repository/templates/item.ejs delete mode 100644 scripts/next-repro-generators/publish-to-repository/templates/main/README.md delete mode 100644 scripts/next-repro-generators/publish-to-repository/templates/next/README.md delete mode 100644 scripts/next-repro-generators/publish-to-repository/templates/root.ejs create mode 100755 scripts/next-repro-generators/publish.ts create mode 100644 scripts/next-repro-generators/templates/item.ejs create mode 100644 scripts/next-repro-generators/templates/root.ejs create mode 100644 scripts/next-repro-generators/utils/git.ts create mode 100644 scripts/next-repro-generators/utils/template.ts create mode 100644 scripts/next-repro-generators/utils/types.ts diff --git a/.github/workflows/generate-repros-next.yml b/.github/workflows/generate-repros-next.yml index 38a6fd377816..6e2adcf7f657 100644 --- a/.github/workflows/generate-repros-next.yml +++ b/.github/workflows/generate-repros-next.yml @@ -29,5 +29,5 @@ jobs: run: yarn next-repro working-directory: ./code - name: Publish repros to GitHub - run: yarn publish-repros --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/repro-templates-temp.git --push --force-push + run: yarn publish-repros --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/repro-templates-temp.git --push working-directory: ./code diff --git a/.vscode/settings.json b/.vscode/settings.json index 6534f373734d..3a1293aae8fb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,8 @@ { - "deepscan.enable": true + "deepscan.enable": true, + "workbench.colorCustomizations": { + "activityBar.background": "#263108", + "titleBar.activeBackground": "#35450C", + "titleBar.activeForeground": "#F8FCED" + } } diff --git a/code/package.json b/code/package.json index cb9e4b0f9a85..17fac3e390db 100644 --- a/code/package.json +++ b/code/package.json @@ -73,8 +73,8 @@ "lint:other": "prettier --write '**/*.{css,html,json,md,yml}'", "lint:package": "sort-package-json", "local-registry": "ts-node --project=../scripts/tsconfig.json ../scripts/run-registry.ts --port 6000", - "next-repro": "ts-node ../scripts/next-repro-generators/index.ts", - "publish-repros": "node --loader ts-node/esm ../scripts/next-repro-generators/publish-to-repository/index.mts", + "next-repro": "ts-node ../scripts/next-repro-generators/generate.ts", + "publish-repros": "ts-node ../scripts/next-repro-generators/publish.ts", "publish:debug": "npm run publish:latest -- --npm-tag=debug --no-push", "publish:latest": "lerna publish --exact --concurrency 1 --force-publish", "publish:next": "npm run publish:latest -- --npm-tag=next", diff --git a/generate-repros.sh b/generate-repros.sh index 9bd70ba2dc7b..59bf9eee663d 100755 --- a/generate-repros.sh +++ b/generate-repros.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -./scripts/node_modules/.bin/ts-node ./scripts/next-repro-generators/index.ts \ No newline at end of file +./scripts/node_modules/.bin/ts-node ./scripts/next-repro-generators/generate.ts \ No newline at end of file diff --git a/scripts/next-repro-generators/index.ts b/scripts/next-repro-generators/generate.ts similarity index 95% rename from scripts/next-repro-generators/index.ts rename to scripts/next-repro-generators/generate.ts index 55fc5f266de4..0a86652a0c5e 100755 --- a/scripts/next-repro-generators/index.ts +++ b/scripts/next-repro-generators/generate.ts @@ -11,16 +11,7 @@ import { copy, emptyDir, ensureDir, readFile, rename } from 'fs-extra'; import { maxConcurrentTasks } from '../utils/concurrency'; import { localizeYarnConfigFiles, setupYarn } from './utils/yarn'; - -type GeneratorConfig = { - name: string; - script: string; - // expected?: { - // framework?: string; - // renderer?: string; - // builder?: string; - // }; -}; +import { GeneratorConfig } from './utils/types'; type DataEntry = { script: string; diff --git a/scripts/next-repro-generators/publish-to-repository/index.mts b/scripts/next-repro-generators/publish-to-repository/index.mts deleted file mode 100755 index 3b2053936e68..000000000000 --- a/scripts/next-repro-generators/publish-to-repository/index.mts +++ /dev/null @@ -1,125 +0,0 @@ -/* eslint-disable no-underscore-dangle */ -import program from 'commander'; -import { dirname, join } from 'path'; -import { existsSync } from 'fs'; -import { command } from 'execa'; -import { temporaryDirectory } from 'tempy'; -import { render } from 'ejs'; -import { copy, writeFile } from 'fs-extra'; -import { fileURLToPath } from 'url'; - -const logger = console; - -// @ts-ignore -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); - -const REPROS_DIRECTORY = join(__dirname, '..', '..', '..', 'repros'); - -interface PublishOptions { - remote?: string; - push?: boolean; - next?: boolean; - forcePush?: boolean; -} - -let tmpFolder: string; - -const publish = async (options: PublishOptions) => { - if (!existsSync(REPROS_DIRECTORY)) { - throw Error("Can't find repros directory. Did you forget to run generate-repros?"); - } - - const { next: useNextVersion, remote, push, forcePush } = options; - - tmpFolder = temporaryDirectory(); - - logger.log(`Created tmp folder: ${tmpFolder}`); - - const scriptPath = __dirname; - const templatesFolderPath = join(scriptPath, 'templates'); - const gitBranch = useNextVersion ? 'next' : 'main'; - - logger.log(`Cloning the repository ${remote} in branch ${gitBranch}`); - await command(`git clone ${remote} .`, { cwd: tmpFolder }); - await command(`git checkout ${gitBranch}`, { cwd: tmpFolder }); - - logger.log(`Moving template files into the repository`); - await writeFile(join(tmpFolder, 'README.md'), render(join(templatesFolderPath, 'root.ejs'), { data: {} })); - // await copy(join(templatesFolderPath, gitBranch), tmpFolder, { overwrite: true }); - - logger.log(`Moving all the repros into the repository`); - await copy(join(REPROS_DIRECTORY), tmpFolder); - - try { - logger.log(`Committing everything to the repository`); - - await command('git add .', { cwd: tmpFolder }); - - const currentCommitSHA = command('git rev-parse HEAD'); - await command( - `git commit -m Update Storybook Examples - ${new Date().toDateString()} - ${currentCommitSHA}` - ); - } catch (e) { - logger.log( - `Git found no changes between previous versions so there is nothing to commit. Skipping publish!` - ); - } - - logger.info(` - All the examples were bootstrapped: - - in ${tmpFolder} - - using the '${gitBranch}' version of Storybook CLI - - and committed on the '${gitBranch}' branch of a local Git repository - - Also all the files in the 'templates' folder were copied at the root of the Git repository. - `); - - try { - if (remote) { - await command(`git remote add origin ${remote}`, { cwd: tmpFolder }); - - if (push) { - await command(`git push --set-upstream origin ${gitBranch} ${forcePush ? '--force' : ''}`, { - cwd: tmpFolder, - }); - const remoteRepoUrl = `${remote.replace('.git', '')}/tree/${gitBranch}`; - logger.info(`๐Ÿš€ Everything was pushed on ${remoteRepoUrl}`); - } else { - logger.info(` - To publish these examples you just need to: - - push the branch: 'git push --set-upstream origin ${gitBranch}' (you might need '--force' option ;)) - `); - } - } else { - logger.info(` - To publish these examples you just need to: - - add a remote Git repository: 'git remote add origin XXXXXXX' - - push the branch: 'git push --set-upstream origin ${gitBranch}' (you might need '--force' option ;)) - `); - } - } catch (e) { - logger.error(e); - } -}; - -program - .description('Create a reproduction from a set of possible templates') - .option('--remote ', 'Choose the remote to push the contents to') - .option('--next', 'Whether to use the next version of Storybook CLI', true) - .option('--push', 'Whether to push the contents to the remote', false) - .option('--force-push', 'Whether to force push the changes into the repros repository', false); - -program.parse(process.argv); - -const options = program.opts() as PublishOptions; - -publish(options).catch(async (e) => { - logger.error(e); - - if (existsSync(tmpFolder)) { - // logger.log('removing the temporary folder..'); - // await remove(tmpFolder); - } - process.exit(1); -}); diff --git a/scripts/next-repro-generators/publish-to-repository/templates/item.ejs b/scripts/next-repro-generators/publish-to-repository/templates/item.ejs deleted file mode 100644 index bc33fe60ccb8..000000000000 --- a/scripts/next-repro-generators/publish-to-repository/templates/item.ejs +++ /dev/null @@ -1 +0,0 @@ -

todo

; diff --git a/scripts/next-repro-generators/publish-to-repository/templates/main/README.md b/scripts/next-repro-generators/publish-to-repository/templates/main/README.md deleted file mode 100644 index c08c1d9c5c2b..000000000000 --- a/scripts/next-repro-generators/publish-to-repository/templates/main/README.md +++ /dev/null @@ -1,12 +0,0 @@ - -# Storybook Reproduction Templates - -![Storybook Latest Badge](https://img.shields.io/npm/v/@storybook/react/latest) - -The repros have been generated with the latest stable version of Storybook. -If you want to try the cutting edge version go on the `next` branch. - -Preview any repro live on [StackBlitz](http://stackblitz.com/): - -- [Create React App](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/cra/default-js/after-storybook?preset=node) -- [Create React App + TypeScript](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/cra/default-ts/after-storybook?preset=node) diff --git a/scripts/next-repro-generators/publish-to-repository/templates/next/README.md b/scripts/next-repro-generators/publish-to-repository/templates/next/README.md deleted file mode 100644 index 215d3ee54621..000000000000 --- a/scripts/next-repro-generators/publish-to-repository/templates/next/README.md +++ /dev/null @@ -1,11 +0,0 @@ - -# Storybook Reproduction Templates - -![Storybook Next Badge](https://img.shields.io/npm/v/@storybook/react/next) - -The repros have been generated with the latest stable version of Storybook - -Preview any repro live on [StackBlitz](http://stackblitz.com/): - -- [Create React App](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/next/cra/default-js/after-storybook?preset=node) -- [Create React App + TypeScript](https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/next/cra/default-ts/after-storybook?preset=node) \ No newline at end of file diff --git a/scripts/next-repro-generators/publish-to-repository/templates/root.ejs b/scripts/next-repro-generators/publish-to-repository/templates/root.ejs deleted file mode 100644 index 3276a7bb8183..000000000000 --- a/scripts/next-repro-generators/publish-to-repository/templates/root.ejs +++ /dev/null @@ -1,26 +0,0 @@ -

Storybook Reproduction Templates

- -Storybook Latest Badge - -

The repros have been generated with the latest stable version of Storybook.

- -<% if (typeof data !== 'undefined' && Object.keys(data).length) { %> -

Preview any repro live on [StackBlitz](http://stackblitz.com/):

- <% for (var groupName in data) { %> - <% if (data[groupName] !== undefined) { %> -

<%- (groupName) %>

-
    - <% for (var exampleName in data[groupName]) { %> - <% if (data[groupName][exampleName] !== undefined) { %> -
  • - - <%=groupName['name']%> - -
  • - <% } %> - <% } %> -
- <% } %> - <% } %> - -<% } %> diff --git a/scripts/next-repro-generators/publish.ts b/scripts/next-repro-generators/publish.ts new file mode 100755 index 000000000000..1e5c5023b93c --- /dev/null +++ b/scripts/next-repro-generators/publish.ts @@ -0,0 +1,95 @@ +import program from 'commander'; +import { join } from 'path'; +import { existsSync } from 'fs'; +import { command } from 'execa'; +import * as tempy from 'tempy'; +import { copy, remove, writeFile } from 'fs-extra'; + +import { getTemplatesData, renderTemplate } from './utils/template'; +import { commitAllToGit } from './utils/git'; + +export const logger = console; + +const REPROS_DIRECTORY = join(__dirname, '..', '..', '..', 'repros'); + +interface PublishOptions { + remote?: string; + push?: boolean; + next?: boolean; +} + +const publish = async (options: PublishOptions & { tmpFolder: string }) => { + if (!existsSync(REPROS_DIRECTORY)) { + throw Error("Can't find repros directory. Did you forget to run generate-repros?"); + } + + const { next: useNextVersion, remote, push, tmpFolder } = options; + + const scriptPath = __dirname; + const gitBranch = useNextVersion ? 'next' : 'main'; + + const templatesData = await getTemplatesData(join(scriptPath, '..', 'repro-config.yml')); + + logger.log(`๐Ÿ‘ฏโ€โ™‚๏ธ Cloning the repository ${remote} in branch ${gitBranch}`); + await command(`git clone ${remote} .`, { cwd: tmpFolder }); + await command(`git checkout ${gitBranch}`, { cwd: tmpFolder }); + + logger.log(`๐Ÿšš Moving template files into the repository`); + + const templatePath = join(scriptPath, 'templates', 'root.ejs'); + const templateData = { data: templatesData, version: gitBranch }; + + const output = await renderTemplate(templatePath, templateData); + + await writeFile(join(tmpFolder, 'README.md'), output); + + logger.log(`๐Ÿš› Moving all the repros into the repository`); + await copy(join(REPROS_DIRECTORY), tmpFolder); + + await commitAllToGit(tmpFolder); + + logger.info(` + ๐Ÿ™Œ All the examples were bootstrapped: + - in ${tmpFolder} + - using the '${gitBranch}' version of Storybook CLI + - and committed on the '${gitBranch}' branch of a local Git repository + + Also all the files in the 'templates' folder were copied at the root of the Git repository. + `); + + if (push) { + await command(`git push --set-upstream origin ${gitBranch}`, { + cwd: tmpFolder, + }); + const remoteRepoUrl = `${remote.replace('.git', '')}/tree/${gitBranch}`; + logger.info(`๐Ÿš€ Everything was pushed on ${remoteRepoUrl}`); + } else { + logger.info(` + To publish these examples you just need to: + - push the branch: 'git push --set-upstream origin ${gitBranch} + `); + } +}; + +program + .description('Create a reproduction from a set of possible templates') + .option('--remote ', 'Choose the remote to push the contents to') + .option('--next', 'Whether to use the next version of Storybook CLI', true) + .option('--push', 'Whether to push the contents to the remote', false) + .option('--force-push', 'Whether to force push the changes into the repros repository', false); + +program.parse(process.argv); +const tmpFolder = tempy.directory(); +logger.log(`โฑ Created tmp folder: ${tmpFolder}`); + +const options = program.opts() as PublishOptions; + +publish({ ...options, tmpFolder }).catch(async (e) => { + logger.error(e); + + if (existsSync(tmpFolder)) { + logger.log('๐Ÿšฎ Removing the temporary folder..'); + await remove(tmpFolder); + } + process.exit(1); +}); diff --git a/scripts/next-repro-generators/repro-config.yml b/scripts/next-repro-generators/repro-config.yml index 2112cd37c86b..ae5ce55b4b9c 100644 --- a/scripts/next-repro-generators/repro-config.yml +++ b/scripts/next-repro-generators/repro-config.yml @@ -1,5 +1,6 @@ # group-name/instance-name. Should always be two levels deep. cra/default-js: + name: "Create React App (Javascript)" script: "npx create-react-app ." expected: framework: "@storybook/cra" @@ -7,6 +8,7 @@ cra/default-js: builder: "@storybook/builder-webpack5" cra/default-ts: + name: "Create React App (Typescript)" script: "npx create-react-app . --template typescript" expected: framework: "@storybook/cra" diff --git a/scripts/next-repro-generators/templates/item.ejs b/scripts/next-repro-generators/templates/item.ejs new file mode 100644 index 000000000000..f100cd3bb8a5 --- /dev/null +++ b/scripts/next-repro-generators/templates/item.ejs @@ -0,0 +1,18 @@ +

<%= name %>

+ +

Small introduction

+ +View it in Stackblitz + +

Testing instructions

+ +

Install dependencies:

+
+  yarn
+
+ +

Run Storybook:

+
+  yarn storybook
+
+ diff --git a/scripts/next-repro-generators/templates/root.ejs b/scripts/next-repro-generators/templates/root.ejs new file mode 100644 index 000000000000..4934d0e0f47d --- /dev/null +++ b/scripts/next-repro-generators/templates/root.ejs @@ -0,0 +1,27 @@ +

Storybook Reproduction Templates

+ +Storybook <%= version %> Badge + +

The following repros have been generated with the `<%= version %>` version of Storybook.

+ +<% if (typeof data !== 'undefined' && Object.keys(data).length) { %> +

Preview any repro live on StackBlitz:

+ <% for (var groupName in data) { %> + <% if (data[groupName] !== undefined) { %> +
+ <%- (groupName) %> + +
+ <% } %> + <% } %> +<% } %> diff --git a/scripts/next-repro-generators/utils/git.ts b/scripts/next-repro-generators/utils/git.ts new file mode 100644 index 000000000000..728034765652 --- /dev/null +++ b/scripts/next-repro-generators/utils/git.ts @@ -0,0 +1,25 @@ +import { command } from 'execa'; +import { logger } from '../publish'; + +export async function commitAllToGit(cwd: string) { + try { + logger.log(`๐Ÿ’ช Committing everything to the repository`); + + await command('git add .', { cwd }); + + const currentCommitSHA = await command('git rev-parse HEAD'); + await command( + `git commit -m "Update examples - ${new Date().toDateString()} - ${currentCommitSHA.stdout + .toString() + .slice(0, 12)}"`, + { + shell: true, + cwd, + } + ); + } catch (e) { + logger.log( + `๐Ÿคท Git found no changes between previous versions so there is nothing to commit. Skipping publish!` + ); + } +} diff --git a/scripts/next-repro-generators/utils/template.ts b/scripts/next-repro-generators/utils/template.ts new file mode 100644 index 000000000000..472d7f451c49 --- /dev/null +++ b/scripts/next-repro-generators/utils/template.ts @@ -0,0 +1,47 @@ +import { render } from 'ejs'; +import { readFile } from 'fs-extra'; +import yml from 'js-yaml'; +import { format } from 'prettier'; +import { GeneratorConfig } from './types'; + +export async function renderTemplate(templatePath: string, templateData: Record) { + const template = await readFile(templatePath, 'utf8'); + + const output = format(render(template, templateData), { + parser: 'html', + }).replace(new RegExp('\\n\\n', 'g'), '\n'); + return output; +} + +export async function getTemplatesData(filePath: string) { + const configContents = await readFile(filePath, 'utf8'); + const ymlData: Record = yml.load(configContents); + + const getStackblitzUrl = (path: string) => { + return `https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/${path}/after-storybook?preset=node`; + }; + + type TemplatesData = Record< + string, + Record< + string, + GeneratorConfig & { + stackblitzUrl: string; + } + > + >; + + const templatesData = Object.keys(ymlData).reduce((acc, next) => { + const [dirName, templateName] = next.split('/'); + const groupName = + dirName === 'cra' ? 'CRA' : dirName.slice(0, 1).toUpperCase() + dirName.slice(1); + const generatorData = ymlData[next]; + acc[groupName] = acc[groupName] || {}; + acc[groupName][templateName] = { + ...generatorData, + stackblitzUrl: getStackblitzUrl(next), + }; + return acc; + }, {}); + return templatesData; +} diff --git a/scripts/next-repro-generators/utils/types.ts b/scripts/next-repro-generators/utils/types.ts new file mode 100644 index 000000000000..12e37c89f294 --- /dev/null +++ b/scripts/next-repro-generators/utils/types.ts @@ -0,0 +1,4 @@ +export type GeneratorConfig = { + name: string; + script: string; +}; diff --git a/scripts/next-repro-generators/utils/yarn.ts b/scripts/next-repro-generators/utils/yarn.ts index 26648979a596..4ece51f1e4ac 100644 --- a/scripts/next-repro-generators/utils/yarn.ts +++ b/scripts/next-repro-generators/utils/yarn.ts @@ -1,6 +1,6 @@ import { join } from 'path'; import { move, remove } from 'fs-extra'; -import { runCommand } from '../index'; +import { runCommand } from '../generate'; interface SetupYarnOptions { cwd: string; diff --git a/scripts/package.json b/scripts/package.json index 3f421a0cc201..9a87f7438aa4 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -169,7 +169,7 @@ "shx": "^0.3.2", "slash": "^3.0.0", "sort-package-json": "^1.48.1", - "tempy": "^3.0.0", + "tempy": "^1.0.0", "trash": "^7.0.0", "ts-dedent": "^2.0.0", "ts-jest": "^26.4.4", diff --git a/scripts/yarn.lock b/scripts/yarn.lock index 0b0a6c69bd99..0c4f6168aae2 100644 --- a/scripts/yarn.lock +++ b/scripts/yarn.lock @@ -3357,7 +3357,7 @@ __metadata: shx: ^0.3.2 slash: ^3.0.0 sort-package-json: ^1.48.1 - tempy: ^3.0.0 + tempy: ^1.0.0 trash: ^7.0.0 ts-dedent: ^2.0.0 ts-jest: ^26.4.4 @@ -6841,12 +6841,10 @@ __metadata: languageName: node linkType: hard -"crypto-random-string@npm:^4.0.0": - version: 4.0.0 - resolution: "crypto-random-string@npm:4.0.0" - dependencies: - type-fest: ^1.0.1 - checksum: 16e11a3c8140398f5408b7fded35a961b9423c5dac39a60cbbd08bd3f0e07d7de130e87262adea7db03ec1a7a4b7551054e0db07ee5408b012bac5400cfc07a5 +"crypto-random-string@npm:^2.0.0": + version: 2.0.0 + resolution: "crypto-random-string@npm:2.0.0" + checksum: 288589b2484fe787f9e146f56c4be90b940018f17af1b152e4dde12309042ff5a2bf69e949aab8b8ac253948381529cc6f3e5a2427b73643a71ff177fa122b37 languageName: node linkType: hard @@ -7293,6 +7291,22 @@ __metadata: languageName: node linkType: hard +"del@npm:^6.0.0": + version: 6.1.1 + resolution: "del@npm:6.1.1" + dependencies: + globby: ^11.0.1 + graceful-fs: ^4.2.4 + is-glob: ^4.0.1 + is-path-cwd: ^2.2.0 + is-path-inside: ^3.0.2 + p-map: ^4.0.0 + rimraf: ^3.0.2 + slash: ^3.0.0 + checksum: 8a095c5ccade42c867a60252914ae485ec90da243d735d1f63ec1e64c1cfbc2b8810ad69a29ab6326d159d4fddaa2f5bad067808c42072351ec458efff86708f + languageName: node + linkType: hard + "delayed-stream@npm:~1.0.0": version: 1.0.0 resolution: "delayed-stream@npm:1.0.0" @@ -10174,7 +10188,7 @@ __metadata: languageName: node linkType: hard -"globby@npm:^11.0.3, globby@npm:^11.0.4, globby@npm:^11.1.0": +"globby@npm:^11.0.1, globby@npm:^11.0.3, globby@npm:^11.0.4, globby@npm:^11.1.0": version: 11.1.0 resolution: "globby@npm:11.1.0" dependencies: @@ -11390,6 +11404,13 @@ __metadata: languageName: node linkType: hard +"is-path-cwd@npm:^2.2.0": + version: 2.2.0 + resolution: "is-path-cwd@npm:2.2.0" + checksum: afce71533a427a759cd0329301c18950333d7589533c2c90205bd3fdcf7b91eb92d1940493190567a433134d2128ec9325de2fd281e05be1920fbee9edd22e0a + languageName: node + linkType: hard + "is-path-inside@npm:^3.0.2": version: 3.0.3 resolution: "is-path-inside@npm:3.0.3" @@ -11476,13 +11497,6 @@ __metadata: languageName: node linkType: hard -"is-stream@npm:^3.0.0": - version: 3.0.0 - resolution: "is-stream@npm:3.0.0" - checksum: eb2f7127af02ee9aa2a0237b730e47ac2de0d4e76a4a905a50a11557f2339df5765eaea4ceb8029f1efa978586abe776908720bfcb1900c20c6ec5145f6f29d8 - languageName: node - linkType: hard - "is-string@npm:^1.0.5, is-string@npm:^1.0.7": version: 1.0.7 resolution: "is-string@npm:1.0.7" @@ -18556,15 +18570,16 @@ __metadata: languageName: node linkType: hard -"tempy@npm:^3.0.0": - version: 3.0.0 - resolution: "tempy@npm:3.0.0" +"tempy@npm:^1.0.0": + version: 1.0.1 + resolution: "tempy@npm:1.0.1" dependencies: - is-stream: ^3.0.0 + del: ^6.0.0 + is-stream: ^2.0.0 temp-dir: ^2.0.0 - type-fest: ^2.12.2 - unique-string: ^3.0.0 - checksum: 281797a81417fc04b07ef77dc9d9870624b83980b6c6d0d9075f265f2617da04b83850f4c1c68ffa2904a0c50fc22790c104b923243a57885cd84a1379b6ce0e + type-fest: ^0.16.0 + unique-string: ^2.0.0 + checksum: 864a1cf1b5536dc21e84ae45dbbc3ba4dd2c7ec1674d895f99c349cf209df959a53d797ca38d0b2cf69c7684d565fde5cfc67faaa63b7208ffb21d454b957472 languageName: node linkType: hard @@ -19120,6 +19135,13 @@ __metadata: languageName: node linkType: hard +"type-fest@npm:^0.16.0": + version: 0.16.0 + resolution: "type-fest@npm:0.16.0" + checksum: 6b4d846534e7bcb49a6160b068ffaed2b62570d989d909ac3f29df5ef1e993859f890a4242eebe023c9e923f96adbcb3b3e88a198c35a1ee9a731e147a6839c3 + languageName: node + linkType: hard + "type-fest@npm:^0.20.2": version: 0.20.2 resolution: "type-fest@npm:0.20.2" @@ -19148,20 +19170,6 @@ __metadata: languageName: node linkType: hard -"type-fest@npm:^1.0.1": - version: 1.4.0 - resolution: "type-fest@npm:1.4.0" - checksum: a3c0f4ee28ff6ddf800d769eafafcdeab32efa38763c1a1b8daeae681920f6e345d7920bf277245235561d8117dab765cb5f829c76b713b4c9de0998a5397141 - languageName: node - linkType: hard - -"type-fest@npm:^2.12.2": - version: 2.17.0 - resolution: "type-fest@npm:2.17.0" - checksum: e7707e5c27213919483011d127f333432d82d06b697ca0577cc828b53d384372b4308d3294e849b0111a34fdc7adf5bdef58c5ffa80aa36d19e9851b2a8d9970 - languageName: node - linkType: hard - "type-is@npm:~1.6.17, type-is@npm:~1.6.18": version: 1.6.18 resolution: "type-is@npm:1.6.18" @@ -19424,12 +19432,12 @@ __metadata: languageName: node linkType: hard -"unique-string@npm:^3.0.0": - version: 3.0.0 - resolution: "unique-string@npm:3.0.0" +"unique-string@npm:^2.0.0": + version: 2.0.0 + resolution: "unique-string@npm:2.0.0" dependencies: - crypto-random-string: ^4.0.0 - checksum: b35ea034b161b2a573666ec16c93076b4b6106b8b16c2415808d747ab3a0566b5db0c4be231d4b11cfbc16d7fd915c9d8a45884bff0e2db11b799775b2e1e017 + crypto-random-string: ^2.0.0 + checksum: 11820db0a4ba069d174bedfa96c588fc2c96b083066fafa186851e563951d0de78181ac79c744c1ed28b51f9d82ac5b8196ff3e4560d0178046ef455d8c2244b languageName: node linkType: hard From 649a92edbfc2f338b391228e69cff42e0737ae56 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Fri, 29 Jul 2022 17:22:12 +0200 Subject: [PATCH 10/12] add documentation per repro --- scripts/next-repro-generators/generate.ts | 48 +++++++++++++------ .../templates/.stackblitzrc | 4 ++ .../next-repro-generators/templates/item.ejs | 2 +- .../next-repro-generators/utils/template.ts | 8 ++-- 4 files changed, 42 insertions(+), 20 deletions(-) create mode 100644 scripts/next-repro-generators/templates/.stackblitzrc diff --git a/scripts/next-repro-generators/generate.ts b/scripts/next-repro-generators/generate.ts index 0a86652a0c5e..30ebb4bf4f6b 100755 --- a/scripts/next-repro-generators/generate.ts +++ b/scripts/next-repro-generators/generate.ts @@ -6,16 +6,13 @@ import type { Options as ExecaOptions } from 'execa'; import yaml from 'js-yaml'; import pLimit from 'p-limit'; import prettyTime from 'pretty-hrtime'; -import { copy, emptyDir, ensureDir, readFile, rename } from 'fs-extra'; +import { copy, emptyDir, ensureDir, readFile, rename, writeFile } from 'fs-extra'; // @ts-ignore import { maxConcurrentTasks } from '../utils/concurrency'; import { localizeYarnConfigFiles, setupYarn } from './utils/yarn'; import { GeneratorConfig } from './utils/types'; - -type DataEntry = { - script: string; -}; +import { getStackblitzUrl, renderTemplate } from './utils/template'; const OUTPUT_DIRECTORY = join(__dirname, '..', '..', 'repros'); const BEFORE_DIR_NAME = 'before-storybook'; @@ -52,18 +49,36 @@ export const runCommand = async (script: string, options: ExecaOptions) => { return command(script, { stdout: shouldDebug ? 'inherit' : 'ignore', ...options }); }; -const runGenerators = async (generators: GeneratorConfig[]) => { +const addDocumentation = async ( + baseDir: string, + { name, dirName }: { name: string; dirName: string } +) => { + const afterDir = join(baseDir, AFTER_DIR_NAME); + const stackblitzConfigPath = join(__dirname, 'templates', '.stackblitzrc'); + const readmePath = join(__dirname, 'templates', 'item.ejs'); + + await copy(stackblitzConfigPath, join(afterDir, '.stackblitzrc')); + + const stackblitzUrl = getStackblitzUrl(dirName); + const contents = await renderTemplate(readmePath, { + name, + stackblitzUrl, + }); + await writeFile(join(afterDir, 'README.md'), contents); +}; + +const runGenerators = async (generators: (GeneratorConfig & { dirName: string })[]) => { console.log(`๐Ÿคนโ€โ™‚๏ธ Generating repros with a concurrency of ${maxConcurrentTasks}`); const limit = pLimit(maxConcurrentTasks); return Promise.all( - generators.map(({ name, script }) => + generators.map(({ dirName, name, script }) => limit(async () => { const time = process.hrtime(); console.log(`๐Ÿงฌ generating ${name}`); - const baseDir = join(OUTPUT_DIRECTORY, name); + const baseDir = join(OUTPUT_DIRECTORY, dirName); const beforeDir = join(baseDir, BEFORE_DIR_NAME); await emptyDir(baseDir); @@ -77,10 +92,13 @@ const runGenerators = async (generators: GeneratorConfig[]) => { await addStorybook(baseDir); + await addDocumentation(baseDir, { name, dirName }); + console.log( - `โœ… Created ${name} in ./${relative(process.cwd(), baseDir)} successfully in ${prettyTime( - process.hrtime(time) - )}` + `โœ… Created ${dirName} in ./${relative( + process.cwd(), + baseDir + )} successfully in ${prettyTime(process.hrtime(time))}` ); }) ) @@ -89,12 +107,12 @@ const runGenerators = async (generators: GeneratorConfig[]) => { const generate = async ({ config }: { config: string }) => { const configContents = await readFile(config, 'utf8'); - const data: Record = yaml.load(configContents); + const data: Record = yaml.load(configContents); runGenerators( - Object.entries(data).map(([name, configuration]) => ({ - name, - script: configuration.script, + Object.entries(data).map(([dirName, configuration]) => ({ + dirName, + ...configuration, })) ); }; diff --git a/scripts/next-repro-generators/templates/.stackblitzrc b/scripts/next-repro-generators/templates/.stackblitzrc new file mode 100644 index 000000000000..cb2783501a98 --- /dev/null +++ b/scripts/next-repro-generators/templates/.stackblitzrc @@ -0,0 +1,4 @@ +{ + "installDependencies": true, + "startCommand": "yarn storybook" +} \ No newline at end of file diff --git a/scripts/next-repro-generators/templates/item.ejs b/scripts/next-repro-generators/templates/item.ejs index f100cd3bb8a5..fdea04cfa699 100644 --- a/scripts/next-repro-generators/templates/item.ejs +++ b/scripts/next-repro-generators/templates/item.ejs @@ -1,6 +1,6 @@

<%= name %>

-

Small introduction

+

This is project generated to serve as a reproduction starter for Storybook.

View it in Stackblitz diff --git a/scripts/next-repro-generators/utils/template.ts b/scripts/next-repro-generators/utils/template.ts index 472d7f451c49..ffeee660fe17 100644 --- a/scripts/next-repro-generators/utils/template.ts +++ b/scripts/next-repro-generators/utils/template.ts @@ -13,14 +13,14 @@ export async function renderTemplate(templatePath: string, templateData: Record< return output; } +export const getStackblitzUrl = (path: string) => { + return `https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/${path}/after-storybook?preset=node`; +}; + export async function getTemplatesData(filePath: string) { const configContents = await readFile(filePath, 'utf8'); const ymlData: Record = yml.load(configContents); - const getStackblitzUrl = (path: string) => { - return `https://stackblitz.com/github/storybookjs/repro-templates-temp/tree/main/${path}/after-storybook?preset=node`; - }; - type TemplatesData = Record< string, Record< From b962cf3333749536af5a7ac2df606e6377fee695 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Fri, 29 Jul 2022 17:38:06 +0200 Subject: [PATCH 11/12] rename tmp folder --- scripts/next-repro-generators/generate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/next-repro-generators/generate.ts b/scripts/next-repro-generators/generate.ts index 30ebb4bf4f6b..50b9f3d0b5aa 100755 --- a/scripts/next-repro-generators/generate.ts +++ b/scripts/next-repro-generators/generate.ts @@ -21,7 +21,7 @@ const AFTER_DIR_NAME = 'after-storybook'; const addStorybook = async (baseDir: string) => { const beforeDir = join(baseDir, BEFORE_DIR_NAME); const afterDir = join(baseDir, AFTER_DIR_NAME); - const tmpDir = join(baseDir, '.tmp'); + const tmpDir = join(baseDir, 'tmp'); await ensureDir(tmpDir); await emptyDir(tmpDir); From ce84ddb39220c42fe5da3a3c11d2782e9072bf5c Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Fri, 29 Jul 2022 18:01:40 +0200 Subject: [PATCH 12/12] change paths after refactor --- scripts/next-repro-generators/publish.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/next-repro-generators/publish.ts b/scripts/next-repro-generators/publish.ts index 1e5c5023b93c..f1a9cba08cdd 100755 --- a/scripts/next-repro-generators/publish.ts +++ b/scripts/next-repro-generators/publish.ts @@ -10,7 +10,7 @@ import { commitAllToGit } from './utils/git'; export const logger = console; -const REPROS_DIRECTORY = join(__dirname, '..', '..', '..', 'repros'); +const REPROS_DIRECTORY = join(__dirname, '..', '..', 'repros'); interface PublishOptions { remote?: string; @@ -19,16 +19,12 @@ interface PublishOptions { } const publish = async (options: PublishOptions & { tmpFolder: string }) => { - if (!existsSync(REPROS_DIRECTORY)) { - throw Error("Can't find repros directory. Did you forget to run generate-repros?"); - } - const { next: useNextVersion, remote, push, tmpFolder } = options; const scriptPath = __dirname; const gitBranch = useNextVersion ? 'next' : 'main'; - const templatesData = await getTemplatesData(join(scriptPath, '..', 'repro-config.yml')); + const templatesData = await getTemplatesData(join(scriptPath, 'repro-config.yml')); logger.log(`๐Ÿ‘ฏโ€โ™‚๏ธ Cloning the repository ${remote} in branch ${gitBranch}`); await command(`git clone ${remote} .`, { cwd: tmpFolder }); @@ -79,6 +75,11 @@ program .option('--force-push', 'Whether to force push the changes into the repros repository', false); program.parse(process.argv); + +if (!existsSync(REPROS_DIRECTORY)) { + throw Error("Can't find repros directory. Did you forget to run generate-repros?"); +} + const tmpFolder = tempy.directory(); logger.log(`โฑ Created tmp folder: ${tmpFolder}`);