Skip to content

Commit c2f952e

Browse files
author
Adrian Zhang
committed
chore: support user to define the location of assets folder when init a new subspace beside the default rush-init/assets folder
1 parent e02148a commit c2f952e

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "suport users to provide their own assets when init a new subspace instead of always using the default one",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush"
10+
}

libraries/rush-lib/assets/rush-init/common/config/rush/subspaces.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
*/
1212
"subspacesEnabled": false,
1313

14+
/**
15+
* the starting assets folder you want to use when init a subspace
16+
*/
17+
// "subspaceInitAssetsFolder": "",
18+
1419
/**
1520
* (DEPRECATED) This is a temporary workaround for migrating from an earlier prototype
1621
* of this feature: https://github.com/microsoft/rushstack/pull/3481

libraries/rush-lib/src/api/SubspacesConfiguration.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface ISubspacesConfigurationJson {
2525
splitWorkspaceCompatibility?: boolean;
2626
preventSelectingAllSubspaces?: boolean;
2727
subspaceNames: string[];
28+
subspaceInitAssetsFolder?: string;
2829
}
2930

3031
/**
@@ -60,11 +61,17 @@ export class SubspacesConfiguration {
6061
*/
6162
public readonly subspaceNames: ReadonlySet<string>;
6263

64+
/**
65+
* rush-init Subspace assets location used during `rush init-subspace`
66+
*/
67+
public readonly subspaceInitAssetsFolder?: string;
68+
6369
private constructor(configuration: Readonly<ISubspacesConfigurationJson>, subspaceJsonFilePath: string) {
6470
this.subspaceJsonFilePath = subspaceJsonFilePath;
6571
this.subspacesEnabled = configuration.subspacesEnabled;
6672
this.splitWorkspaceCompatibility = !!configuration.splitWorkspaceCompatibility;
6773
this.preventSelectingAllSubspaces = !!configuration.preventSelectingAllSubspaces;
74+
this.subspaceInitAssetsFolder = configuration.subspaceInitAssetsFolder;
6875
const subspaceNames: Set<string> = new Set();
6976
for (const subspaceName of configuration.subspaceNames) {
7077
SubspacesConfiguration.requireValidSubspaceName(subspaceName, this.splitWorkspaceCompatibility);

libraries/rush-lib/src/cli/actions/InitSubspaceAction.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { type ISubspacesConfigurationJson, SubspacesConfiguration } from '../../
99
import { Async, FileSystem, JsonFile } from '@rushstack/node-core-library';
1010
import { ConsoleTerminalProvider, Terminal } from '@rushstack/terminal';
1111
import { copyTemplateFileAsync } from '../../utilities/templateUtilities';
12+
import * as path from 'path';
1213

1314
export class InitSubspaceAction extends BaseRushAction {
1415
private readonly _subspaceNameParameter: IRequiredCommandLineStringParameter;
@@ -58,7 +59,10 @@ export class InitSubspaceAction extends BaseRushAction {
5859
}
5960

6061
const subspaceConfigPath: string = `${this.rushConfiguration.commonFolder}/config/subspaces/${newSubspaceName}`;
61-
const assetsSubfolder: string = `${assetsFolderPath}/rush-init`;
62+
const defaultAssetsSubfolder: string = `${assetsFolderPath}/rush-init`;
63+
const userDefinedAssetsFolder: string | undefined = subspacesConfiguration.subspaceInitAssetsFolder
64+
? path.join(this.rushConfiguration.rushJsonFolder, subspacesConfiguration.subspaceInitAssetsFolder)
65+
: undefined;
6266
const templateFilePaths: string[] = [
6367
'[dot]npmrc',
6468
'.pnpmfile.cjs',
@@ -70,9 +74,14 @@ export class InitSubspaceAction extends BaseRushAction {
7074
await Async.forEachAsync(
7175
templateFilePaths,
7276
async (templateFilePath) => {
73-
const sourcePath: string = `${assetsSubfolder}/common/config/rush/${templateFilePath}`;
77+
const defaultAssetSourcePath: string = `${defaultAssetsSubfolder}/common/config/rush/${templateFilePath}`;
7478
const destinationPath: string = `${subspaceConfigPath}/${templateFilePath.replace('[dot]', '.')}`;
75-
await copyTemplateFileAsync(sourcePath, destinationPath, true);
79+
await copyTemplateFileAsync(defaultAssetSourcePath, destinationPath, true);
80+
if (userDefinedAssetsFolder) {
81+
// if user provided their own assets file for subspace initiation
82+
// we just copy and overwrite the default files
83+
await copyTemplateFileAsync(userDefinedAssetsFolder, destinationPath, true);
84+
}
7685
},
7786
{ concurrency: 10 }
7887
);

libraries/rush-lib/src/schemas/subspaces.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
"items": {
2828
"type": "string"
2929
}
30+
},
31+
"subspaceInitAssetsFolder": {
32+
"description": "Where assets located for init a new subspace",
33+
"type": "string"
3034
}
3135
}
3236
}

0 commit comments

Comments
 (0)