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

Display suggested global name for UMD build from the plugin name #211

Merged
merged 1 commit into from
Dec 31, 2024
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
5 changes: 4 additions & 1 deletion packages/ckeditor5-package-generator/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export default async function init( packageName, options ) {
const packageManager = await choosePackageManager( useNpm, useYarn );
const programmingLanguage = await chooseProgrammingLanguage( logger, lang );
const installationMethodOfPackage = await chooseInstallationMethods( logger, installationMethods );
const validatedGlobalName = await setGlobalName( logger, globalName );

const defaultGlobalName = 'CK' + formattedNames.plugin.pascalCase;
const validatedGlobalName = await setGlobalName( logger, globalName, defaultGlobalName );

const packageVersions = getDependenciesVersions( logger, dev );

copyFiles( logger, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import validateGlobalName from './validate-global-name.js';
*
* @param {Logger} logger
* @param {String} globalName
* @param {String} defaultGlobalName
* @returns {Promise.<String>}
*/
export default async function setGlobalName( logger, globalName ) {
export default async function setGlobalName( logger, globalName, defaultGlobalName ) {
if ( globalName ) {
if ( validateGlobalName( logger, globalName ) ) {
return globalName;
Expand All @@ -28,10 +29,11 @@ export default async function setGlobalName( logger, globalName ) {

const globalNameFromInput = await inquirer.prompt( {
required: true,
message: 'Enter the global name for plugin for UMD build',
message: 'Enter the global name for UMD build:',
type: 'input',
name: 'globalName',
validate: validateGlobalName.bind( this, logger )
validate: validateGlobalName.bind( this, logger ),
default: defaultGlobalName
} );

return globalNameFromInput.globalName;
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-package-generator/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe( 'lib/index', () => {
await index( packageName, options );

expect( setGlobalName ).toHaveBeenCalledTimes( 1 );
expect( setGlobalName ).toHaveBeenCalledWith( expect.any( Logger ), 'GLOBAL' );
expect( setGlobalName ).toHaveBeenCalledWith( expect.any( Logger ), 'GLOBAL', 'CKBarBaz' );
} );

it( 'gets the versions of the dependencies', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ describe( 'lib/utils/set-global-name', () => {
} );

it( 'calls prompt() with correct arguments', async () => {
await setGlobalName( stubs.logger );
await setGlobalName( stubs.logger, '', 'CKCustomPlugin' );

expect( inquirer.prompt ).toHaveBeenCalledTimes( 1 );
expect( inquirer.prompt ).toHaveBeenCalledWith( {
required: true,
message: 'Enter the global name for plugin for UMD build',
message: 'Enter the global name for UMD build:',
type: 'input',
name: 'globalName',
validate: expect.any( Function )
validate: expect.any( Function ),
default: 'CKCustomPlugin'
} );
} );

Expand Down
Loading