Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 62 additions & 22 deletions scripts/generators/generate-package-manifest.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,77 @@
/**
* This is used solely for V8 release.
* @see {@link ../../azure-pipelines.release.yml}
* {@link file://./../../azure-pipelines.release.yml}
*/

const fs = require('fs');
const path = require('path');
const fs = require('fs-extra');

const { getAllPackageInfo, workspaceRoot } = require('@fluentui/scripts-monorepo');
const semver = require('semver');
const { getAllPackageInfo, findGitRoot } = require('@fluentui/scripts-monorepo');

// Generate "manifest" file with package.jsons of all the monorepo packages (mainly for ODSP)
main('v8', path.join(workspaceRoot, 'package-manifest'), '@fluentui/react');

/**
* Generate "manifest" JSON file with map of package.json of monorepo packages that belong under provided tag group
* @remarks This is mainly/only for ODSP
* @param {string} tag - based on this only project containing this tag will be processed
* @param {string} manifestRoot - directory path where it should be generated
* @param {string} rootPackage
*/
function main(tag, manifestRoot, rootPackage) {
const allPackageInfo = getAllPackageInfo();

const filteredPackages = Object.entries(allPackageInfo).reduce((acc, curr) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might be easier to call Object.fromEntries after filtering by the object entries

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you elaborate a bit more ?

You mean using following ?

Object.fromEntries(Object.entries(allPackageInfo).map(...)) ?

if that's the case I dont think its more readable/faster than reduce

const projectJsonPath = path.join(curr[1].packagePath, 'project.json');
/** @type {import('@nx/devkit').ProjectConfiguration} */
const projectJson = JSON.parse(fs.readFileSync(projectJsonPath, 'utf-8'));
const { tags = [], projectType } = projectJson;

const ommittedPackagePaths = ['react-components', 'packages/fluentui', 'web-components', 'apps/'];
if (projectType === 'application') {
return acc;
}

const allPackageInfo = getAllPackageInfo();
if (tags.length === 0) {
return acc;
}

// eslint-disable-next-line guard-for-in
for (const key in allPackageInfo) {
const normalizedPath = allPackageInfo[key]?.packagePath.split('\\').join('/');
ommittedPackagePaths.forEach(omittedPath => {
if (normalizedPath.includes(omittedPath)) {
delete allPackageInfo[key];
return;
if (tags.indexOf(tag) !== -1) {
acc[curr[0]] = curr[1];
}
});

return acc;
}, /** @type {typeof allPackageInfo} */ ({}));

const rootPackageVersion = filteredPackages[rootPackage].packageJson.version;
const packageInfoString = JSON.stringify(filteredPackages, null, 2);

const dests = [rootPackageVersion, path.join('latest', String(semver.major(rootPackageVersion)))];

for (const dest of dests) {
const destFolder = path.join(manifestRoot, dest);
fs.mkdirSync(destFolder, { recursive: true });
fs.writeFileSync(path.join(destFolder, 'package-manifest.json'), packageInfoString, 'utf8');
}

console.log('Manifest generated:\n');
console.log(getFileList(manifestRoot).join('\n'));
}
const fuirVersion = allPackageInfo['@fluentui/react'].packageJson.version;
const packageInfoString = JSON.stringify(allPackageInfo, null, 2);

const manifestRoot = path.join(findGitRoot(), 'package-manifest');
const dests = [fuirVersion, path.join('latest', String(semver.major(fuirVersion)))];
/**
* @param {string} dirName
*/
function getFileList(dirName) {
/** @type {string[]} */
let files = [];
const items = fs.readdirSync(dirName, { withFileTypes: true });

for (const item of items) {
if (item.isDirectory()) {
files = [...files, ...getFileList(`${dirName}/${item.name}`)];
} else {
files.push(`${dirName}/${item.name}`);
}
}

for (const dest of dests) {
const destFolder = path.join(manifestRoot, dest);
fs.mkdirpSync(destFolder);
fs.writeFileSync(path.join(destFolder, 'package-manifest.json'), packageInfoString);
return files;
}