Skip to content
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

refactor(scripts): move executors from /monorepo to proper domain #26345

Merged
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"buildci": "lage build test lint type-check --verbose",
"builddemo": "yarn build --to public-docsite-resources",
"buildto": "lage build --verbose --to",
"buildto:lerna": "node ./scripts/monorepo/src/buildTo.js",
"buildto:lerna": "node ./scripts/executors/buildTo.js",
"bundle": "lage bundle --verbose",
"bundlesizecollect": "node ./scripts/generators/bundle-size-collect",
"change": "beachball change --no-commit",
"check:change": "beachball check",
"check:modified-files": "node -r ./scripts/ts-node/register ./scripts/executors/check-for-modified-files",
"check:affected-package": "node ./scripts/monorepo/src/checkIfPackagesAffected.js",
"check:affected-package": "node ./scripts/executors/checkIfPackagesAffected.js",
"check:installed-dependencies-versions": "satisfied --skip-invalid --ignore \"prettier|angular|lit|sass|@storybook/html|@storybook/mdx2-csf|svelte|@testing-library|vue|@cypress/react|cypress|@swc/wasm|@cactuslab/usepubsub|react-vis|@microsoft/load-themed-styles\"",
"clean": "lage clean --verbose",
"code-style": "lage code-style --verbose",
Expand All @@ -50,8 +50,8 @@
"release:fluentui:patch": "node -r ./scripts/ts-node/register ./scripts/fluentui-publish publish-patch",
"release:fluentui:post-validation": "node -r ./scripts/ts-node/register ./scripts/fluentui-publish post-publish",
"rename-package": "node -r ./scripts/ts-node/register ./scripts/generators/rename-package.ts",
"run:published": "node ./scripts/monorepo/src/runPublished.js",
"runto:lerna": "node ./scripts/monorepo/src/runTo.js",
"run:published": "node ./scripts/executors/runPublished.js",
"runto:lerna": "node ./scripts/executors/runTo.js",
"scrub": "node ./scripts/executors/scrub.js",
"start": "node ./scripts/executors/start.js",
"start:northstar": "yarn workspace @fluentui/docs start",
Expand Down
31 changes: 31 additions & 0 deletions scripts/executors/buildTo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { runTo } = require('./runTo');

const isExecutedFromCli = require.main === module;

function main() {
const argv = process.argv.slice(2);

// Display a usage message when there are no projects specified
if (argv.length < 1) {
console.log(`Usage:

yarn buildto <packagename1> [<packagename2> ...] [<args>]

This command builds all packages up to and including "packagename1" (and "packagename2" etc).
The package name can be a substring.
If multiple packages match a pattern, they will all be built (along with their dependencies).
`);

process.exit(0);
}

const restIndex = argv.findIndex(arg => arg.startsWith('--'));
const projects = restIndex === -1 ? argv : argv.slice(0, restIndex);
const rest = restIndex === -1 ? [] : argv.slice(argv[restIndex] === '--' ? restIndex + 1 : restIndex);

runTo('build', projects, rest);
}

if (isExecutedFromCli) {
main();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const getAffectedPackages = require('./getAffectedPackages');
const getNthCommit = require('./getNthCommit');
const { getAffectedPackages, getNthCommit } = require('@fluentui/scripts-monorepo');
const yargs = require('yargs');

const args = yargs
Expand Down Expand Up @@ -39,8 +38,12 @@ const isPackageAffected = () => {
return false;
};

/**
* In order for pipeline to capture and save the return value from a node script,
* the output needs to be printed.
*/
console.log(isPackageAffected());
function main() {
/**
* In order for pipeline to capture and save the return value from a node script,
* the output needs to be printed.
*/
console.log(isPackageAffected());
}

main();
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { spawnSync } = require('child_process');
const getAllPackageInfo = require('./getAllPackageInfo');
const isConvergedPackage = require('./isConvergedPackage');

const { getAllPackageInfo, isConvergedPackage } = require('@fluentui/scripts-monorepo');
const lageBin = require.resolve('lage/bin/lage.js');

/**
Expand Down
57 changes: 32 additions & 25 deletions scripts/monorepo/src/runTo.js → scripts/executors/runTo.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
const { spawnSync } = require('child_process');
const lernaBin = require.resolve('lerna/cli.js');
const getAllPackageInfo = require('./getAllPackageInfo');
const os = require('os');

const argv = process.argv.slice(2);
const { getAllPackageInfo } = require('@fluentui/scripts-monorepo');

if (require.main === module) {
// Display a usage message when there are no projects specified
if (argv.length < 2) {
console.log(`Usage:

yarn runto <script> <packagename1> [<packagename2> ...] [<args>]

This command runs <script> for all packages up to and including "packagename1" (and "packagename2" etc).
The package name can be a substring.
If multiple packages match a pattern, they will all be built (along with their dependencies).
`);

process.exit(0);
}

const restIndex = argv.findIndex(arg => arg.startsWith('--'));
const script = argv[0];
const projects = restIndex === -1 ? argv.slice(1) : argv.slice(1, restIndex);
const rest = restIndex === -1 ? [] : argv.slice(argv[restIndex] === '--' ? restIndex + 1 : restIndex);

runTo(script, projects, rest);
}
const isExecutedFromCli = require.main === module;

/**
* @param {string} script - Script to run
* @param {string[]} projects - Projects to run in
* @param {string[]} rest - Args to pass on
* @returns {void}
*/
function runTo(script, projects, rest) {
// This script matches substrings of the input for one more many projects
Expand Down Expand Up @@ -91,4 +70,32 @@ function runTo(script, projects, rest) {
}
}

module.exports = runTo;
function main() {
const argv = process.argv.slice(2);
// Display a usage message when there are no projects specified
if (argv.length < 2) {
console.log(`Usage:

yarn runto <script> <packagename1> [<packagename2> ...] [<args>]

This command runs <script> for all packages up to and including "packagename1" (and "packagename2" etc).
The package name can be a substring.
If multiple packages match a pattern, they will all be built (along with their dependencies).
`);

process.exit(0);
}

const restIndex = argv.findIndex(arg => arg.startsWith('--'));
const script = argv[0];
const projects = restIndex === -1 ? argv.slice(1) : argv.slice(1, restIndex);
const rest = restIndex === -1 ? [] : argv.slice(argv[restIndex] === '--' ? restIndex + 1 : restIndex);

runTo(script, projects, rest);
}

if (isExecutedFromCli) {
main();
}

exports.runTo = runTo;
23 changes: 0 additions & 23 deletions scripts/monorepo/src/buildTo.js

This file was deleted.

3 changes: 2 additions & 1 deletion scripts/monorepo/src/getAffectedPackages.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { spawnSync } = require('child_process');

const findGitRoot = require('./findGitRoot');

/**
Expand Down Expand Up @@ -27,4 +28,4 @@ function getAffectedPackages(since = 'origin/master') {
return new Set(info.scope);
}

module.exports = getAffectedPackages;
exports.getAffectedPackages = getAffectedPackages;
4 changes: 2 additions & 2 deletions scripts/monorepo/src/getNthCommit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const execSync = require('child_process').execSync;
const { execSync } = require('child_process');

/**
* Returns SHA for the nth commit from a reference descending from the latest commit
Expand All @@ -12,4 +12,4 @@ function getNthCommit(n = 1, ref = 'HEAD') {
return commitSha;
}

module.exports = getNthCommit;
exports.getNthCommit = getNthCommit;
3 changes: 2 additions & 1 deletion scripts/monorepo/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export { default as findGitRoot } from './findGitRoot';
export { default as findRepoDeps } from './findRepoDeps';
export { default as getAllPackageInfo } from './getAllPackageInfo';
export { default as isConvergedPackage } from './isConvergedPackage';
export { default as getAffectedPackages } from './getAffectedPackages';
export { getAffectedPackages } from './getAffectedPackages';
export { getLernaAliases } from './get-lerna-aliases';
export { getDefaultEnvironmentVars } from './getDefaultEnvironmentVars';
export { getProjectMetadata, workspaceRoot } from './utils';
export * as eslintConstants from './eslint-constants';
export { getNthCommit } from './getNthCommit';
3 changes: 2 additions & 1 deletion scripts/monorepo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module.exports = {
findRepoDeps: require('./findRepoDeps'),
getAllPackageInfo: require('./getAllPackageInfo'),
isConvergedPackage: require('./isConvergedPackage'),
getAffectedPackages: require('./getAffectedPackages'),
eslintConstants: require('./eslint-constants'),
...require('./getAffectedPackages'),
...require('./getNthCommit'),
...require('./getDefaultEnvironmentVars'),
...require('./get-lerna-aliases'),
...require('./utils'),
Expand Down