Skip to content

Commit 1ad1b65

Browse files
Hotellq1b
authored andcommitted
refactor(scripts): move executors from monorepo to proper domain (microsoft#26345)
1 parent 5bcc898 commit 1ad1b65

11 files changed

+87
-66
lines changed

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
"buildci": "lage build test lint type-check --verbose",
1818
"builddemo": "yarn build --to public-docsite-resources",
1919
"buildto": "lage build --verbose --to",
20-
"buildto:lerna": "node ./scripts/monorepo/src/buildTo.js",
20+
"buildto:lerna": "node ./scripts/executors/buildTo.js",
2121
"bundle": "lage bundle --verbose",
2222
"bundlesizecollect": "node ./scripts/generators/bundle-size-collect",
2323
"change": "beachball change --no-commit",
2424
"check:change": "beachball check",
2525
"check:modified-files": "node -r ./scripts/ts-node/register ./scripts/executors/check-for-modified-files",
26-
"check:affected-package": "node ./scripts/monorepo/src/checkIfPackagesAffected.js",
26+
"check:affected-package": "node ./scripts/executors/checkIfPackagesAffected.js",
2727
"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\"",
2828
"clean": "lage clean --verbose",
2929
"code-style": "lage code-style --verbose",
@@ -50,8 +50,8 @@
5050
"release:fluentui:patch": "node -r ./scripts/ts-node/register ./scripts/fluentui-publish publish-patch",
5151
"release:fluentui:post-validation": "node -r ./scripts/ts-node/register ./scripts/fluentui-publish post-publish",
5252
"rename-package": "node -r ./scripts/ts-node/register ./scripts/generators/rename-package.ts",
53-
"run:published": "node ./scripts/monorepo/src/runPublished.js",
54-
"runto:lerna": "node ./scripts/monorepo/src/runTo.js",
53+
"run:published": "node ./scripts/executors/runPublished.js",
54+
"runto:lerna": "node ./scripts/executors/runTo.js",
5555
"scrub": "node ./scripts/executors/scrub.js",
5656
"start": "node ./scripts/executors/start.js",
5757
"start:northstar": "yarn workspace @fluentui/docs start",

scripts/executors/buildTo.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const { runTo } = require('./runTo');
2+
3+
const isExecutedFromCli = require.main === module;
4+
5+
function main() {
6+
const argv = process.argv.slice(2);
7+
8+
// Display a usage message when there are no projects specified
9+
if (argv.length < 1) {
10+
console.log(`Usage:
11+
12+
yarn buildto <packagename1> [<packagename2> ...] [<args>]
13+
14+
This command builds all packages up to and including "packagename1" (and "packagename2" etc).
15+
The package name can be a substring.
16+
If multiple packages match a pattern, they will all be built (along with their dependencies).
17+
`);
18+
19+
process.exit(0);
20+
}
21+
22+
const restIndex = argv.findIndex(arg => arg.startsWith('--'));
23+
const projects = restIndex === -1 ? argv : argv.slice(0, restIndex);
24+
const rest = restIndex === -1 ? [] : argv.slice(argv[restIndex] === '--' ? restIndex + 1 : restIndex);
25+
26+
runTo('build', projects, rest);
27+
}
28+
29+
if (isExecutedFromCli) {
30+
main();
31+
}

scripts/monorepo/src/checkIfPackagesAffected.js scripts/executors/checkIfPackagesAffected.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const getAffectedPackages = require('./getAffectedPackages');
2-
const getNthCommit = require('./getNthCommit');
1+
const { getAffectedPackages, getNthCommit } = require('@fluentui/scripts-monorepo');
32
const yargs = require('yargs');
43

54
const args = yargs
@@ -39,8 +38,12 @@ const isPackageAffected = () => {
3938
return false;
4039
};
4140

42-
/**
43-
* In order for pipeline to capture and save the return value from a node script,
44-
* the output needs to be printed.
45-
*/
46-
console.log(isPackageAffected());
41+
function main() {
42+
/**
43+
* In order for pipeline to capture and save the return value from a node script,
44+
* the output needs to be printed.
45+
*/
46+
console.log(isPackageAffected());
47+
}
48+
49+
main();

scripts/monorepo/src/runPublished.js scripts/executors/runPublished.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { spawnSync } = require('child_process');
2-
const getAllPackageInfo = require('./getAllPackageInfo');
3-
const isConvergedPackage = require('./isConvergedPackage');
2+
3+
const { getAllPackageInfo, isConvergedPackage } = require('@fluentui/scripts-monorepo');
44
const lageBin = require.resolve('lage/bin/lage.js');
55

66
/**

scripts/monorepo/src/runTo.js scripts/executors/runTo.js

+32-25
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,16 @@
11
const { spawnSync } = require('child_process');
22
const lernaBin = require.resolve('lerna/cli.js');
3-
const getAllPackageInfo = require('./getAllPackageInfo');
43
const os = require('os');
54

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

8-
if (require.main === module) {
9-
// Display a usage message when there are no projects specified
10-
if (argv.length < 2) {
11-
console.log(`Usage:
12-
13-
yarn runto <script> <packagename1> [<packagename2> ...] [<args>]
14-
15-
This command runs <script> for all packages up to and including "packagename1" (and "packagename2" etc).
16-
The package name can be a substring.
17-
If multiple packages match a pattern, they will all be built (along with their dependencies).
18-
`);
19-
20-
process.exit(0);
21-
}
22-
23-
const restIndex = argv.findIndex(arg => arg.startsWith('--'));
24-
const script = argv[0];
25-
const projects = restIndex === -1 ? argv.slice(1) : argv.slice(1, restIndex);
26-
const rest = restIndex === -1 ? [] : argv.slice(argv[restIndex] === '--' ? restIndex + 1 : restIndex);
27-
28-
runTo(script, projects, rest);
29-
}
7+
const isExecutedFromCli = require.main === module;
308

319
/**
3210
* @param {string} script - Script to run
3311
* @param {string[]} projects - Projects to run in
3412
* @param {string[]} rest - Args to pass on
13+
* @returns {void}
3514
*/
3615
function runTo(script, projects, rest) {
3716
// This script matches substrings of the input for one more many projects
@@ -91,4 +70,32 @@ function runTo(script, projects, rest) {
9170
}
9271
}
9372

94-
module.exports = runTo;
73+
function main() {
74+
const argv = process.argv.slice(2);
75+
// Display a usage message when there are no projects specified
76+
if (argv.length < 2) {
77+
console.log(`Usage:
78+
79+
yarn runto <script> <packagename1> [<packagename2> ...] [<args>]
80+
81+
This command runs <script> for all packages up to and including "packagename1" (and "packagename2" etc).
82+
The package name can be a substring.
83+
If multiple packages match a pattern, they will all be built (along with their dependencies).
84+
`);
85+
86+
process.exit(0);
87+
}
88+
89+
const restIndex = argv.findIndex(arg => arg.startsWith('--'));
90+
const script = argv[0];
91+
const projects = restIndex === -1 ? argv.slice(1) : argv.slice(1, restIndex);
92+
const rest = restIndex === -1 ? [] : argv.slice(argv[restIndex] === '--' ? restIndex + 1 : restIndex);
93+
94+
runTo(script, projects, rest);
95+
}
96+
97+
if (isExecutedFromCli) {
98+
main();
99+
}
100+
101+
exports.runTo = runTo;

scripts/monorepo/src/buildTo.js

-23
This file was deleted.

scripts/monorepo/src/getAffectedPackages.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { spawnSync } = require('child_process');
2+
23
const findGitRoot = require('./findGitRoot');
34

45
/**
@@ -27,4 +28,4 @@ function getAffectedPackages(since = 'origin/master') {
2728
return new Set(info.scope);
2829
}
2930

30-
module.exports = getAffectedPackages;
31+
exports.getAffectedPackages = getAffectedPackages;

scripts/monorepo/src/getNthCommit.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const execSync = require('child_process').execSync;
1+
const { execSync } = require('child_process');
22

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

15-
module.exports = getNthCommit;
15+
exports.getNthCommit = getNthCommit;

scripts/monorepo/src/index.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ export { default as findGitRoot } from './findGitRoot';
44
export { default as findRepoDeps } from './findRepoDeps';
55
export { default as getAllPackageInfo } from './getAllPackageInfo';
66
export { default as isConvergedPackage } from './isConvergedPackage';
7-
export { default as getAffectedPackages } from './getAffectedPackages';
7+
export { getAffectedPackages } from './getAffectedPackages';
88
export { getLernaAliases } from './get-lerna-aliases';
99
export { getDefaultEnvironmentVars } from './getDefaultEnvironmentVars';
1010
export { getProjectMetadata, workspaceRoot } from './utils';
1111
export * as eslintConstants from './eslint-constants';
12+
export { getNthCommit } from './getNthCommit';

scripts/monorepo/src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ module.exports = {
44
findRepoDeps: require('./findRepoDeps'),
55
getAllPackageInfo: require('./getAllPackageInfo'),
66
isConvergedPackage: require('./isConvergedPackage'),
7-
getAffectedPackages: require('./getAffectedPackages'),
87
eslintConstants: require('./eslint-constants'),
8+
...require('./getAffectedPackages'),
9+
...require('./getNthCommit'),
910
...require('./getDefaultEnvironmentVars'),
1011
...require('./get-lerna-aliases'),
1112
...require('./utils'),

0 commit comments

Comments
 (0)