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

Introduced the "overrideDirectoryNames" option in a config #98

Merged
merged 3 commits into from
Jun 6, 2019
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
4 changes: 2 additions & 2 deletions lib/commands/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ module.exports = {
.then( ( [ hashResponse, statusResponse ] ) => {
let packageName = data.packageName;

if ( data.mgitOptions.packagesPrefix ) {
packageName = packageName.replace( data.mgitOptions.packagesPrefix, '' );
for ( const packagePrefix of data.mgitOptions.packagesPrefix ) {
packageName = packageName.replace( new RegExp( '^' + packagePrefix ), '' );
}

const commandResponse = {
Expand Down
4 changes: 4 additions & 0 deletions lib/default-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module.exports = function resolver( packageName, options ) {
defaultBranch: options.resolverDefaultBranch
} );

if ( options.overrideDirectoryNames[ packageName ] ) {
repository.directory = options.overrideDirectoryNames[ packageName ];
}

if ( options.resolverTargetDirectory == 'npm' ) {
repository.directory = packageName;
}
Expand Down
13 changes: 12 additions & 1 deletion lib/utils/getoptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ module.exports = function cwdResolver( callOptions, cwd ) {
resolverTargetDirectory: 'git',
resolverDefaultBranch: 'master',
ignore: null,
scope: null
scope: null,
packagesPrefix: [],
overrideDirectoryNames: {}
};

if ( fs.existsSync( mgitJsonPath ) ) {
Expand All @@ -36,6 +38,10 @@ module.exports = function cwdResolver( callOptions, cwd ) {

options.packages = path.resolve( cwd, options.packages );

if ( !Array.isArray( options.packagesPrefix ) ) {
options.packagesPrefix = [ options.packagesPrefix ];
}

return options;
};

Expand Down Expand Up @@ -73,4 +79,9 @@ module.exports = function cwdResolver( callOptions, cwd ) {
* If a string: name of branch that should be created.
*
* @property {Boolean|undefined} [hash=undefined] Whether to use current commit hashes as an input data.
*
* @property {Object} [overrideDirectoryNames={}] A map that allows renaming directories where packages will be cloned.
*
* @property {String|Array.<String>} [packagesPrefix=[]] Prefix or prefixes which will be removed from packages' names during
* printing the summary of the "status" command.
*/
50 changes: 49 additions & 1 deletion tests/commands/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,56 @@ describe( 'commands/status', () => {
}
} );

it( 'modifies the package name if "packagesPrefix" is an array', () => {
commandData.mgitOptions.packagesPrefix = [
'@ckeditor/ckeditor-',
'@ckeditor/ckeditor5-',
];

stubs.execCommand.execute.onFirstCall().resolves( {
logs: {
info: [ '6bfd379a56a32c9f8b6e58bf08e39c124cdbae10' ]
}
} );
stubs.execCommand.execute.onSecondCall().resolves( {
logs: {
info: [ 'Response returned by "git status" command.' ]
}
} );

stubs.gitStatusParser.returns( { response: 'Parsed response.' } );

return statusCommand.execute( commandData )
.then( statusResponse => {
expect( stubs.execCommand.execute.calledTwice ).to.equal( true );
expect( stubs.execCommand.execute.firstCall.args[ 0 ] ).to.deep.equal(
getCommandArguments( 'git rev-parse HEAD' )
);
expect( stubs.execCommand.execute.secondCall.args[ 0 ] ).to.deep.equal(
getCommandArguments( 'git status --branch --porcelain' )
);

expect( stubs.gitStatusParser.calledOnce ).to.equal( true );
expect( stubs.gitStatusParser.firstCall.args[ 0 ] ).to.equal( 'Response returned by "git status" command.' );

expect( statusResponse.response ).to.deep.equal( {
packageName: 'test-package',
commit: '6bfd379',
status: { response: 'Parsed response.' },
mgitBranch: 'master'
} );
} );

function getCommandArguments( command ) {
return Object.assign( {}, commandData, {
arguments: [ command ]
} );
}
} );

it( 'does not modify the package name if "packagesPrefix" option is not specified', () => {
delete commandData.mgitOptions.packagesPrefix;
// Mgit resolves this option to be an empty array if it isn't specified.
commandData.mgitOptions.packagesPrefix = [];

stubs.execCommand.execute.onFirstCall().resolves( {
logs: {
Expand Down
24 changes: 24 additions & 0 deletions tests/default-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,28 @@ describe( 'default resolver()', () => {
} );
} );
} );

describe( 'with options.overrideDirectoryNames', () => {
it( 'returns package with modified directory', () => {
const options = getOptions( {}, cwd );

expect( resolver( 'override-directory', options ) ).to.deep.equal( {
url: 'git@github.com:foo/bar.git',
branch: 'master',
directory: 'custom-directory'
} );
} );

it( 'ignores modified directory if "resolverTargetDirectory" is set to "npm"', () => {
const options = getOptions( {
resolverTargetDirectory: 'npm'
}, cwd );

expect( resolver( 'override-directory', options ) ).to.deep.equal( {
url: 'git@github.com:foo/bar.git',
branch: 'master',
directory: 'override-directory'
} );
} );
} );
} );
6 changes: 5 additions & 1 deletion tests/fixtures/project-a/mgit.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"@scoped/package": "c/d",
"full-url-git": "git@github.com:cksource/mgit2.git",
"full-url-git-with-branch": "git@github.com:cksource/mgit2.git#xyz",
"full-url-https": "https://github.com/cksource/mgit2.git"
"full-url-https": "https://github.com/cksource/mgit2.git",
"override-directory": "foo/bar"
},
"overrideDirectoryNames": {
"override-directory": "custom-directory"
}
}
18 changes: 14 additions & 4 deletions tests/utils/getoptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ describe( 'utils', () => {
resolverTargetDirectory: 'git',
resolverDefaultBranch: 'master',
scope: null,
ignore: null
ignore: null,
packagesPrefix: [],
overrideDirectoryNames: {
'override-directory': 'custom-directory'
}
} );
} );

Expand All @@ -52,7 +56,9 @@ describe( 'utils', () => {
resolverTargetDirectory: 'git',
resolverDefaultBranch: 'master',
scope: null,
ignore: null
ignore: null,
packagesPrefix: [],
overrideDirectoryNames: {}
} );
} );

Expand All @@ -71,7 +77,9 @@ describe( 'utils', () => {
resolverTargetDirectory: 'git',
resolverDefaultBranch: 'master',
scope: null,
ignore: null
ignore: null,
packagesPrefix: [],
overrideDirectoryNames: {}
} );
} );

Expand All @@ -93,7 +101,9 @@ describe( 'utils', () => {
resolverTargetDirectory: 'git',
resolverDefaultBranch: 'master',
scope: null,
ignore: null
ignore: null,
packagesPrefix: [],
overrideDirectoryNames: {}
} );
} );
} );
Expand Down