-
Notifications
You must be signed in to change notification settings - Fork 201
chore(storybook): add migrated components list #3745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: spectrum-two
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"total": 85, | ||
"migrated": 49, | ||
"components": [ | ||
"actionbar", | ||
"actionbutton", | ||
"actiongroup", | ||
"alertbanner", | ||
"avatar", | ||
"breadcrumb", | ||
"button", | ||
"buttongroup", | ||
"checkbox", | ||
"closebutton", | ||
"coachmark", | ||
"colorarea", | ||
"colorhandle", | ||
"colorloupe", | ||
"colorslider", | ||
"colorwheel", | ||
"dial", | ||
"dialog", | ||
"divider", | ||
"dropzone", | ||
"fieldgroup", | ||
"fieldlabel", | ||
"form", | ||
"helptext", | ||
"icon", | ||
"illustratedmessage", | ||
"infieldbutton", | ||
"infieldprogresscircle", | ||
"inlinealert", | ||
"link", | ||
"opacitycheckerboard", | ||
"pagination", | ||
"picker", | ||
"popover", | ||
"progressbar", | ||
"progresscircle", | ||
"radio", | ||
"rating", | ||
"search", | ||
"statuslight", | ||
"stepper", | ||
"swatch", | ||
"swatchgroup", | ||
"switch", | ||
"tag", | ||
"textfield", | ||
"thumbnail", | ||
"toast", | ||
"tooltip" | ||
], | ||
"generatedAt": "2025-05-15T21:09:40.681Z" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
"scripts": { | ||
"build": "yarn builder tag:component,ui-icons", | ||
"build:docs": "yarn build:preview --output-dir ../dist/", | ||
"build:preview": "yarn report && nx build storybook", | ||
"build:preview": "yarn report && yarn component:data && nx build storybook", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there's a way to include this task as a storybook report. In the storybook project.json, if we use this script as the report, would it get run automatically with the others? What's the downside of doing that, maybe it's run more than it needs to be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm picturing you could run it like |
||
"builder": "nx run-many --target build report --projects", | ||
"bundle": "nx build bundle", | ||
"changeset": "changeset", | ||
|
@@ -31,7 +31,9 @@ | |
"component:build": "node --no-warnings ./tasks/component-builder.js", | ||
"component:compare": "node --no-warnings ./tasks/component-compare.js", | ||
"component:report": "node --no-warnings ./tasks/component-reporter.js", | ||
"dev": "cross-env NODE_ENV=development nx run storybook:build:docs", | ||
"component:data": "node --no-warnings ./tasks/migrated-component-scanner.js --output=.storybook/data/migrated-components.json", | ||
"component:migrated": "node --no-warnings ./tasks/migrated-component-scanner.js", | ||
"dev": "cross-env NODE_ENV=development yarn component:data && nx run storybook:build:docs", | ||
"docs:report": "yarn report", | ||
"format": "yarn formatter tag:component", | ||
"formatter": "nx run-many --target format --projects", | ||
|
@@ -47,7 +49,7 @@ | |
"release": "yarn ci && changeset publish", | ||
"report": "yarn reporter tag:component", | ||
"reporter": "nx run-many --target report --projects", | ||
"start": "cross-env NODE_ENV=development nx start storybook", | ||
"start": "cross-env NODE_ENV=development yarn component:data && nx start storybook", | ||
"test": "cross-env NODE_ENV=development nx test storybook", | ||
"test:plugins": "cross-env NODE_ENV=production nx run-many --target test --projects tag:plugin", | ||
"tester": "cross-env NODE_ENV=development nx run storybook:test:scope", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#!/usr/bin/env node | ||
|
||
/*! | ||
* Copyright 2025 Adobe. All rights reserved. | ||
* | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at <http://www.apache.org/licenses/LICENSE-2.0> | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
/* eslint-disable no-console */ | ||
|
||
/** | ||
* This script scans the components directory and generates a list of components | ||
* with a migrated status. The output can be saved to a JSON file or printed to console. | ||
* | ||
* Usage: | ||
* node tasks/migrated-component-scanner.js [--output=path/to/output.json] | ||
*/ | ||
|
||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
/** | ||
* Gets all component directory names from the components folder | ||
* @returns {string[]} Array of component directory names | ||
*/ | ||
function getAllComponentDirectories() { | ||
try { | ||
// Get the absolute path to the components directory | ||
const componentsDir = path.resolve(process.cwd(), "components"); | ||
|
||
// Read all directories in the components folder | ||
const directories = fs.readdirSync(componentsDir, { withFileTypes: true }) | ||
.filter(dirent => dirent.isDirectory()) | ||
.map(dirent => dirent.name) | ||
.sort(); | ||
|
||
return directories; | ||
} catch (error) { | ||
console.error("Error getting component directories:", error); | ||
return []; | ||
} | ||
} | ||
|
||
/** | ||
* Gets all component directories that have a specific status | ||
* @param {string} statusType Status type to filter by (e.g., 'migrated') | ||
* @returns {string[]} Array of matching component directory names | ||
*/ | ||
function getComponentsByStatus(statusType) { | ||
try { | ||
const componentsDir = path.resolve(process.cwd(), "components"); | ||
const directories = getAllComponentDirectories(); | ||
|
||
if (!statusType) return directories; | ||
|
||
// Filter directories that have status type in their stories | ||
const matchingComponents = directories.filter(dir => { | ||
const storiesDir = path.join(componentsDir, dir, "stories"); | ||
|
||
// Check if stories directory exists | ||
if (!fs.existsSync(storiesDir)) return false; | ||
|
||
// Get all story files | ||
const storyFiles = fs.readdirSync(storiesDir) | ||
.filter(file => file.endsWith(".stories.js")); | ||
|
||
// Check each story file for status type | ||
return storyFiles.some(file => { | ||
const storyContent = fs.readFileSync(path.join(storiesDir, file), "utf8"); | ||
return storyContent.includes(`type: "${statusType}"`); | ||
}); | ||
}); | ||
|
||
return matchingComponents; | ||
} catch (error) { | ||
console.error(`Error getting components with status ${statusType}:`, error); | ||
return []; | ||
} | ||
} | ||
|
||
/** | ||
* Generates a list of migrated components | ||
* @returns {Object} Information about migrated components | ||
*/ | ||
function generateMigratedComponentsReport() { | ||
const allComponents = getAllComponentDirectories(); | ||
const migratedComponents = getComponentsByStatus("migrated"); | ||
|
||
return { | ||
total: allComponents.length, | ||
migrated: migratedComponents.length, | ||
components: migratedComponents, | ||
generatedAt: new Date().toISOString() | ||
}; | ||
} | ||
|
||
// Export the functions for use in other modules | ||
module.exports = { | ||
getAllComponentDirectories, | ||
getComponentsByStatus, | ||
generateMigratedComponentsReport | ||
}; | ||
|
||
// Main execution - only runs when script is executed directly in the terminal | ||
if (require.main === module) { | ||
(async () => { | ||
const args = process.argv.slice(2); | ||
const outputArg = args.find(arg => arg.startsWith("--output=")); | ||
const outputPath = outputArg ? outputArg.split("=")[1] : null; | ||
|
||
console.log("Scanning for migrated components..."); | ||
const report = generateMigratedComponentsReport(); | ||
|
||
if (outputPath) { | ||
const outputDir = path.dirname(outputPath); | ||
if (!fs.existsSync(outputDir)) { | ||
fs.mkdirSync(outputDir, { recursive: true }); | ||
} | ||
|
||
fs.writeFileSync(outputPath, JSON.stringify(report, null, 2)); | ||
console.log(`Report saved to ${outputPath}`); | ||
console.log(`Found ${report.migrated} migrated components out of ${report.total} total components.`); | ||
} else { | ||
console.log("Migrated Components:"); | ||
console.log(report.components.join(", ")); | ||
console.log(`\nTotal: ${report.migrated} out of ${report.total} components are migrated.`); | ||
} | ||
})(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍