|
1 | 1 | /** |
2 | 2 | * This is used solely for V8 release. |
3 | | - * @see {@link ../../azure-pipelines.release.yml} |
| 3 | + * {@link file://./../../azure-pipelines.release.yml} |
4 | 4 | */ |
5 | 5 |
|
| 6 | +const fs = require('fs'); |
6 | 7 | const path = require('path'); |
7 | | -const fs = require('fs-extra'); |
| 8 | + |
| 9 | +const { getAllPackageInfo, workspaceRoot } = require('@fluentui/scripts-monorepo'); |
8 | 10 | const semver = require('semver'); |
9 | | -const { getAllPackageInfo, findGitRoot } = require('@fluentui/scripts-monorepo'); |
10 | 11 |
|
11 | | -// Generate "manifest" file with package.jsons of all the monorepo packages (mainly for ODSP) |
| 12 | +main('v8', path.join(workspaceRoot, 'package-manifest'), '@fluentui/react'); |
| 13 | + |
| 14 | +/** |
| 15 | + * Generate "manifest" JSON file with map of package.json of monorepo packages that belong under provided tag group |
| 16 | + * @remarks This is mainly/only for ODSP |
| 17 | + * @param {string} tag - based on this only project containing this tag will be processed |
| 18 | + * @param {string} manifestRoot - directory path where it should be generated |
| 19 | + * @param {string} rootPackage |
| 20 | + */ |
| 21 | +function main(tag, manifestRoot, rootPackage) { |
| 22 | + const allPackageInfo = getAllPackageInfo(); |
| 23 | + |
| 24 | + const filteredPackages = Object.entries(allPackageInfo).reduce((acc, curr) => { |
| 25 | + const projectJsonPath = path.join(curr[1].packagePath, 'project.json'); |
| 26 | + /** @type {import('@nx/devkit').ProjectConfiguration} */ |
| 27 | + const projectJson = JSON.parse(fs.readFileSync(projectJsonPath, 'utf-8')); |
| 28 | + const { tags = [], projectType } = projectJson; |
12 | 29 |
|
13 | | -const ommittedPackagePaths = ['react-components', 'packages/fluentui', 'web-components', 'apps/']; |
| 30 | + if (projectType === 'application') { |
| 31 | + return acc; |
| 32 | + } |
14 | 33 |
|
15 | | -const allPackageInfo = getAllPackageInfo(); |
| 34 | + if (tags.length === 0) { |
| 35 | + return acc; |
| 36 | + } |
16 | 37 |
|
17 | | -// eslint-disable-next-line guard-for-in |
18 | | -for (const key in allPackageInfo) { |
19 | | - const normalizedPath = allPackageInfo[key]?.packagePath.split('\\').join('/'); |
20 | | - ommittedPackagePaths.forEach(omittedPath => { |
21 | | - if (normalizedPath.includes(omittedPath)) { |
22 | | - delete allPackageInfo[key]; |
23 | | - return; |
| 38 | + if (tags.indexOf(tag) !== -1) { |
| 39 | + acc[curr[0]] = curr[1]; |
24 | 40 | } |
25 | | - }); |
| 41 | + |
| 42 | + return acc; |
| 43 | + }, /** @type {typeof allPackageInfo} */ ({})); |
| 44 | + |
| 45 | + const rootPackageVersion = filteredPackages[rootPackage].packageJson.version; |
| 46 | + const packageInfoString = JSON.stringify(filteredPackages, null, 2); |
| 47 | + |
| 48 | + const dests = [rootPackageVersion, path.join('latest', String(semver.major(rootPackageVersion)))]; |
| 49 | + |
| 50 | + for (const dest of dests) { |
| 51 | + const destFolder = path.join(manifestRoot, dest); |
| 52 | + fs.mkdirSync(destFolder, { recursive: true }); |
| 53 | + fs.writeFileSync(path.join(destFolder, 'package-manifest.json'), packageInfoString, 'utf8'); |
| 54 | + } |
| 55 | + |
| 56 | + console.log('Manifest generated:\n'); |
| 57 | + console.log(getFileList(manifestRoot).join('\n')); |
26 | 58 | } |
27 | | -const fuirVersion = allPackageInfo['@fluentui/react'].packageJson.version; |
28 | | -const packageInfoString = JSON.stringify(allPackageInfo, null, 2); |
29 | 59 |
|
30 | | -const manifestRoot = path.join(findGitRoot(), 'package-manifest'); |
31 | | -const dests = [fuirVersion, path.join('latest', String(semver.major(fuirVersion)))]; |
| 60 | +/** |
| 61 | + * @param {string} dirName |
| 62 | + */ |
| 63 | +function getFileList(dirName) { |
| 64 | + /** @type {string[]} */ |
| 65 | + let files = []; |
| 66 | + const items = fs.readdirSync(dirName, { withFileTypes: true }); |
| 67 | + |
| 68 | + for (const item of items) { |
| 69 | + if (item.isDirectory()) { |
| 70 | + files = [...files, ...getFileList(`${dirName}/${item.name}`)]; |
| 71 | + } else { |
| 72 | + files.push(`${dirName}/${item.name}`); |
| 73 | + } |
| 74 | + } |
32 | 75 |
|
33 | | -for (const dest of dests) { |
34 | | - const destFolder = path.join(manifestRoot, dest); |
35 | | - fs.mkdirpSync(destFolder); |
36 | | - fs.writeFileSync(path.join(destFolder, 'package-manifest.json'), packageInfoString); |
| 76 | + return files; |
37 | 77 | } |
0 commit comments