@atlaskit/build-utils
Version:
Collection of utilities to used during the release process of Atlaskit
35 lines (32 loc) • 952 B
JavaScript
//@flow
/*
* Utilities helper to return all the examples and filter them by packages
*/
const boltQuery = require('bolt-query');
const path = require('path');
// Get all examples for a specified package using Bolt-Query
async function getExamplesFor(
pkgName /*: string */,
) /*: Promise<Array<string>> */ {
const project /*: any */ = await boltQuery({
cwd: path.join(__dirname, '..'),
workspaceFiles: {
examples: 'examples/*.+(js|ts|tsx)',
},
});
const examplesArr = [];
project.workspaces.forEach(workspace => {
if (workspace.pkg) {
if (
// compare like for like if pkgName includes scope
(pkgName[0] === '@' && workspace.pkg.name === pkgName) ||
// otherwise compare text after scope
workspace.pkg.name.split('/')[1] === pkgName
) {
examplesArr.push(...workspace.files.examples);
}
}
});
return examplesArr;
}
module.exports = { getExamplesFor };