Skip to content

Commit

Permalink
Accept --changed and --compareBranch options
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristiano Belloni committed Nov 9, 2022
1 parent f79847a commit bc1019d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
23 changes: 19 additions & 4 deletions packages/modular-scripts/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,26 @@ async function buildStandalone(
);
}

async function build(
targets: string[],
async function build({
packagePaths: targets,
preserveModules = true,
includePrivate = false,
): Promise<void> {
private: includePrivate,
changed,
compareBranch,
}: {
packagePaths: string[];
preserveModules: boolean;
private: boolean;
changed: boolean;
compareBranch: string;
}): Promise<void> {
if (changed) {
console.log(
'TODO: implement selective build with changed and compareBranch',
changed,
compareBranch,
);
}
for (const target of targets) {
try {
const targetDirectory = await getLocation(target);
Expand Down
28 changes: 24 additions & 4 deletions packages/modular-scripts/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,42 @@ program
)
.option('--verbose', 'Run yarn commands with --verbose set')
.option('--private', 'Enable the building of private packages', false)
.option(
'--changed',
'Build only for workspaces that have changed compared to the branch specified in --compareBranch',
false,
)
.option(
'--compareBranch <branch>',
"Specifies the branch to use with the --changed flag. If not specified, Modular will use the repo's default branch",
)
.action(
async (
packagePaths: string[],
options: {
preserveModules: string;
private: boolean;
changed: boolean;
compareBranch?: string;
},
) => {
const { default: build } = await import('./build');
logger.log('building packages at:', packagePaths.join(', '));

await build(
if (options.compareBranch && !options.changed) {
process.stderr.write(
"Option --compareBranch doesn't make sense without option --changed\n",
);
process.exit(1);
}

await build({
packagePaths,
JSON.parse(options.preserveModules) as boolean,
options.private,
);
preserveModules: JSON.parse(options.preserveModules) as boolean,
private: options.private,
changed: options.changed,
compareBranch: options.compareBranch,
});
},
);

Expand Down

0 comments on commit bc1019d

Please sign in to comment.