-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fixed invalid type placeholder - added stories-check - added support for Provider type overriding
- Loading branch information
1 parent
883ed6f
commit 97d6c52
Showing
17 changed files
with
10,842 additions
and
565 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Stories check | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
checkScreenshots: | ||
name: Stories check | ||
|
||
runs-on: windows-2022 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js 16.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "16.x" | ||
cache: "yarn" | ||
|
||
- name: Yarn install | ||
run: yarn install --network-timeout 1000000 | ||
|
||
- name: Run stories-check | ||
id: storiesCheck | ||
continue-on-error: true | ||
run: yarn stories-check | ||
|
||
- name: Commit story changes | ||
id: csc | ||
if: steps.storiesCheck.outcome == 'failure' | ||
uses: EndBug/add-and-commit@v8 | ||
with: | ||
add: ".stories-approved" | ||
message: "[skip ci] [stories-check] Automated story changes" | ||
new_branch: ${{ github.head_ref }} | ||
default_author: github_actions | ||
|
||
- name: Run cypress-check | ||
id: cypressCheck | ||
continue-on-error: true | ||
run: yarn cypress-check | ||
|
||
- name: Commit cypress changes | ||
id: ccc | ||
if: steps.cypressCheck.outcome == 'failure' | ||
uses: EndBug/add-and-commit@v8 | ||
with: | ||
add: ".cypress-approved" | ||
message: "[skip ci] [cypress-check] Automated cypress changes" | ||
new_branch: ${{ github.head_ref }} | ||
default_author: github_actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
stories: [ | ||
"../src/**/*.stories.mdx", | ||
"../src/**/*.stories.@(js|jsx|ts|tsx)" | ||
], | ||
addons: [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"storycap" | ||
], | ||
framework: "@storybook/react", | ||
core: { | ||
"builder": "webpack5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const parameters = { | ||
actions: { argTypesRegex: "^on[A-Z].*" }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/, | ||
}, | ||
}, | ||
layout: 'centered' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// General import | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
const { stdout } = require('process'); | ||
|
||
/** | ||
* Gets all the file paths from the selected directory recursively. | ||
* | ||
* @param {string} directory Path to the directory from which to read the files. | ||
* @returns Array of file paths in the selected directory | ||
*/ | ||
module.exports.getFilesRecursively = (directory) => { | ||
const files = []; | ||
|
||
const filesInDirectory = fs.readdirSync(directory); | ||
|
||
filesInDirectory.forEach((file) => { | ||
const absolute = path.join(directory, file); | ||
|
||
if (fs.lstatSync(absolute).isDirectory()) { | ||
files.push(...this.getFilesRecursively(absolute)); | ||
} else { | ||
files.push(absolute); | ||
} | ||
}); | ||
|
||
return files; | ||
}; | ||
|
||
/** | ||
* Prints the information about starting the task and its completion to the console. | ||
* | ||
* @param {string} message Message to output before starting the process. | ||
* @param {Function} taskToRun Function to invoke. | ||
* @returns Value that the function returns | ||
*/ | ||
module.exports.logProcess = (message, taskToRun) => { | ||
try { | ||
stdout.write(message); | ||
const valueToReturn = taskToRun(); | ||
stdout.write(`${chalk.green(' DONE ✔')}\n`); | ||
|
||
return valueToReturn; | ||
} catch (error) { | ||
stdout.write(`${chalk.red(' ERROR X')}\n`); | ||
|
||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// General imports | ||
const fs = require('fs-extra'); | ||
const chalk = require('chalk'); | ||
|
||
// Node helpers import | ||
const { getFilesRecursively, logProcess } = require('./NodeHelpers'); | ||
|
||
/** | ||
* Scripts main function. | ||
* | ||
* @param {string} approvedPath Path to the approved screenshots directory | ||
* @param {string} pendingPath Path to the pending screenshots directory | ||
* @param {string} approvedDirName Name of the approved screenshots directory | ||
* @param {string} pendingDirName Name of the pending screenshots directory | ||
*/ | ||
const compare = (approvedPath, pendingPath, approvedDirName, pendingDirName) => { | ||
try { | ||
let numberOfChanges = 0; | ||
|
||
// Ensure the approved directory exists. | ||
fs.ensureDirSync(approvedPath); | ||
|
||
// Get all the approved files. | ||
const approvedFiles = logProcess('Fetching approved files...', () => getFilesRecursively(approvedPath)); | ||
|
||
// Get all the pending files. | ||
const pendingFiles = logProcess('Fetching pending files...', () => getFilesRecursively(pendingPath)); | ||
|
||
// Iterate all the approved files. | ||
approvedFiles.forEach((approvedFile) => { | ||
const approvedFileShort = approvedFile.substring(approvedFile.indexOf(approvedDirName) + approvedDirName.length + 1); | ||
const possiblePending = approvedFile.replace(approvedDirName, pendingDirName); | ||
|
||
// If the approved file is an old one (does not exist in the pending folder) | ||
// delete it from the approved folder. | ||
if (!pendingFiles.includes(possiblePending)) { | ||
logProcess(`\t${chalk.red(`[-] ${approvedFileShort}`)}`, () => fs.removeSync(approvedFile)); | ||
numberOfChanges++; | ||
} | ||
}); | ||
|
||
// Iterate all the files that are pending for approval. | ||
pendingFiles.forEach((pendingFile) => { | ||
const possibleNew = pendingFile.replace(pendingDirName, approvedDirName); | ||
const possibleNewShort = possibleNew.substring(possibleNew.indexOf(approvedDirName) + approvedDirName.length + 1); | ||
|
||
// If the pending file is a new one (does not exist in the approved folder) | ||
// move it to the approved folder. | ||
if (!approvedFiles.includes(possibleNew)) { | ||
logProcess(`\t${chalk.green(`[+] ${possibleNewShort}`)}`, () => fs.moveSync(pendingFile, possibleNew, { overwrite: true })); | ||
numberOfChanges++; | ||
} else { | ||
const pendingFileBytes = fs.readFileSync(pendingFile); | ||
const approvedFileBytes = fs.readFileSync(possibleNew); | ||
|
||
// If the files are not the same, overwrite it. | ||
if (!pendingFileBytes.equals(approvedFileBytes)) { | ||
logProcess(`\t${chalk.yellow(`[≠] ${possibleNewShort}`)}`, () => fs.moveSync(pendingFile, possibleNew, { overwrite: true })); | ||
numberOfChanges++; | ||
} else { | ||
console.log(`\t${chalk.white(`[=] ${possibleNewShort}`)}`); | ||
} | ||
} | ||
}); | ||
|
||
console.log(`Detected changes: ${numberOfChanges}`); | ||
|
||
if (numberOfChanges) process.exit(1); | ||
} catch (error) { | ||
console.error(chalk.red('Error occurred while running the script:')); | ||
console.error(chalk.red(error)); | ||
process.exit(2); | ||
} | ||
}; | ||
|
||
module.exports = { compare }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// General imports | ||
const path = require('path'); | ||
|
||
// Compare script import | ||
const { compare } = require('./ScreenshotsCompare'); | ||
|
||
// Directory paths | ||
const APPROVED_DIR_NAME = '.stories-approved'; | ||
const PENDING_DIR_NAME = '.stories-pending'; | ||
|
||
const APPROVED_STORIES = path.join(__dirname, `../../${APPROVED_DIR_NAME}`); | ||
const PENDING_STORIES = path.join(__dirname, `../../${PENDING_DIR_NAME}`); | ||
|
||
/** | ||
* Running the script with the storybook stories parameters. | ||
* | ||
* @param {string} approvedStories Path to the approved stories directory | ||
* @param {string} pendingStories Path to the pending stories directory | ||
* @param {string} approvedDirName Name of the approved stories directory | ||
* @param {string} pendingDirName Name of the pending stories directory | ||
*/ | ||
const run = ( | ||
approvedStories = APPROVED_STORIES, | ||
pendingStories = PENDING_STORIES, | ||
approvedDirName = APPROVED_DIR_NAME, | ||
pendingDirName = PENDING_DIR_NAME | ||
) => compare(approvedStories, pendingStories, approvedDirName, pendingDirName); | ||
|
||
module.exports = { run }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
|
||
export default function InvalidPlaceholder({ fieldName }: { fieldName: string; }) { | ||
return ( | ||
<div style={{ | ||
color: '#FF8080', | ||
padding: '12px', | ||
backgroundColor: '#290000', | ||
borderRadius: 8 | ||
}}>{`Invalid: "${fieldName}"`}</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.