-
Notifications
You must be signed in to change notification settings - Fork 653
[rush-lib] support users to provide their own assets file for init subspace #5134
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
base: main
Are you sure you want to change the base?
Changes from all commits
a8edb30
b9e9100
30413bd
ccbaf8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@microsoft/rush", | ||
| "comment": "Allow a monorepo to provide custom config file templates for the `rush init-subspace` command", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@microsoft/rush" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import { type ISubspacesConfigurationJson, SubspacesConfiguration } from '../../ | |
| import { Async, FileSystem, JsonFile } from '@rushstack/node-core-library'; | ||
| import { ConsoleTerminalProvider, Terminal } from '@rushstack/terminal'; | ||
| import { copyTemplateFileAsync } from '../../utilities/templateUtilities'; | ||
| import * as path from 'path'; | ||
|
|
||
| export class InitSubspaceAction extends BaseRushAction { | ||
| private readonly _subspaceNameParameter: IRequiredCommandLineStringParameter; | ||
|
|
@@ -58,7 +59,10 @@ export class InitSubspaceAction extends BaseRushAction { | |
| } | ||
|
|
||
| const subspaceConfigPath: string = `${this.rushConfiguration.commonFolder}/config/subspaces/${newSubspaceName}`; | ||
| const assetsSubfolder: string = `${assetsFolderPath}/rush-init`; | ||
| const defaultAssetsSubfolder: string = `${assetsFolderPath}/rush-init`; | ||
| const userDefinedAssetsFolder: string | undefined = subspacesConfiguration.subspaceInitAssetsFolder | ||
| ? `${this.rushConfiguration.rushJsonFolder}/${subspacesConfiguration.subspaceInitAssetsFolder}` | ||
| : undefined; | ||
| const templateFilePaths: string[] = [ | ||
| '[dot]npmrc', | ||
| '.pnpmfile.cjs', | ||
|
|
@@ -70,9 +74,14 @@ export class InitSubspaceAction extends BaseRushAction { | |
| await Async.forEachAsync( | ||
| templateFilePaths, | ||
| async (templateFilePath) => { | ||
| const sourcePath: string = `${assetsSubfolder}/common/config/rush/${templateFilePath}`; | ||
| const defaultAssetSourcePath: string = `${defaultAssetsSubfolder}/common/config/rush/${templateFilePath}`; | ||
| const destinationPath: string = `${subspaceConfigPath}/${templateFilePath.replace('[dot]', '.')}`; | ||
| await copyTemplateFileAsync(sourcePath, destinationPath, true); | ||
| await copyTemplateFileAsync(defaultAssetSourcePath, destinationPath, true); | ||
| if (userDefinedAssetsFolder) { | ||
| // if user provided their own assets file for subspace initiation | ||
| // we just copy and overwrite the default files | ||
| await copyTemplateFileAsync(userDefinedAssetsFolder, destinationPath, true); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This approach seems like it will (1) try to copy a file that doesn't exist and (2) print a notice like Both issues could be avoided using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, Please fill out the How it was tested PR notes 😸 |
||
| } | ||
| }, | ||
| { concurrency: 10 } | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this design, it seems that a given monorepo can have at most one set of custom file templates to use with
rush init-subspace. Therefore, why do we need to configure its location?We could instead designate a standard location, e.g.
common/config-templates/rush-init-subspace. Then everyone will know that is where to find it, without having to read subspaces.json to find the particular location for a particular repo.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks! I’ll update it accordingly.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe
common/templates/config. We could eventually have other kinds of templates (project templates?)