Skip to content

Commit

Permalink
Merge pull request #94 from ckeditor/i/76
Browse files Browse the repository at this point in the history
Other (tools): Aligned the translations tools to the new API exported by the `@ckeditor/ckeditor5-dev-env` package. Closes #71.

MAJOR BREAKING CHANGES (tools): The `-- transifex [API end-point]` option is no longer supported. Use the following options: `--organization [organization name]` and `--project [project name]` instead.
  • Loading branch information
pomek committed Mar 18, 2022
2 parents d4976bf + 83e656d commit 2817b21
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 27 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"license": "MIT",
"homepage": "https://ckeditor.com/ckeditor-5",
"devDependencies": {
"@ckeditor/ckeditor5-dev-docs": "^27.4.0",
"@ckeditor/ckeditor5-dev-env": "^27.4.0",
"@ckeditor/ckeditor5-dev-docs": "^29.0.0",
"@ckeditor/ckeditor5-dev-env": "^29.0.0",
"chalk": "^4.1.2",
"eslint": "^7.32.0",
"eslint-config-ckeditor5": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-package-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"node": ">=14.0.0"
},
"dependencies": {
"@ckeditor/ckeditor5-dev-utils": "^27.3.0",
"@ckeditor/ckeditor5-dev-utils": "^29.0.0",
"chalk": "^4.1.2",
"commander": "^8.1.0",
"glob": "^7.1.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@
const path = require( 'path' );

module.exports = async options => {
if ( !options.transifex ) {
throw new Error( 'The URL to the Transifex API is required. Use --transifex [API end-point] to provide the value.' );
if ( !options.organization ) {
throw new Error( 'The organization name is required. Use --organization [organization name] to provide the value.' );
}

if ( !options.project ) {
throw new Error( 'The project name is required. Use --project [project name] to provide the value.' );
}

if ( options.transifex ) {
throw new Error( 'The --transifex [API end-point] option is no longer supported. Use `--organization` and `--project` instead.' );
}

const getToken = require( '@ckeditor/ckeditor5-dev-env/lib/translations/gettoken' );
Expand All @@ -26,8 +34,9 @@ module.exports = async options => {
[ packageName, '.' ]
] ),

// End-point API URL to the Transifex service.
url: options.transifex,
// Transifex project details.
organizationName: options.organization,
projectName: options.project,

// An absolute path to the package.
cwd: options.cwd,
Expand Down
29 changes: 23 additions & 6 deletions packages/ckeditor5-package-tools/lib/tasks/translations-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,37 @@
const path = require( 'path' );

module.exports = async options => {
if ( !options.transifex ) {
throw new Error( 'The URL to the Transifex API is required. Use --transifex [API end-point] to provide the value.' );
if ( !options.organization ) {
throw new Error( 'The organization name is required. Use --organization [organization name] to provide the value.' );
}

if ( !options.project ) {
throw new Error( 'The project name is required. Use --project [project name] to provide the value.' );
}

if ( options.transifex ) {
throw new Error( 'The --transifex [API end-point] option is no longer supported. Use `--organization` and `--project` instead.' );
}

const getToken = require( '@ckeditor/ckeditor5-dev-env/lib/translations/gettoken' );

const pkgJson = require( path.join( options.cwd, 'package.json' ) );
const packageName = pkgJson.name.split( '/' ).pop();

return require( '@ckeditor/ckeditor5-dev-env' ).uploadPotFiles( {
// Token used for authentication with the Transifex service.
token: await getToken(),

// End-point API URL to the Transifex service.
url: options.transifex,
// Transifex project details.
organizationName: options.organization,
projectName: options.project,

// List of packages that will be processed.
packages: new Map( [
[ packageName, path.join( 'tmp', '.transifex', packageName ) ]
] ),

// Where to look for the saved translation files.
translationsDirectory: path.join( options.cwd, 'tmp', '.transifex' )
// An absolute path to the package.
cwd: options.cwd
} );
};
10 changes: 8 additions & 2 deletions packages/ckeditor5-package-tools/lib/utils/parse-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const minimist = require( 'minimist' );

module.exports = args => {
const config = {
string: [
'organization',
'project'
],

boolean: [
'coverage',
'open',
Expand All @@ -30,10 +35,11 @@ module.exports = args => {
open: true,
language: 'en',
verbose: false,
organization: null,
production: false,
project: null,
watch: false,
'source-map': false,
transifex: null
'source-map': false
}
};

Expand Down
6 changes: 3 additions & 3 deletions packages/ckeditor5-package-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
],
"main": "lib/index.js",
"dependencies": {
"@ckeditor/ckeditor5-dev-utils": "^27.3.0",
"@ckeditor/ckeditor5-dev-env": "^27.3.0",
"@ckeditor/ckeditor5-dev-webpack-plugin": "^27.3.0",
"@ckeditor/ckeditor5-dev-utils": "^29.0.0",
"@ckeditor/ckeditor5-dev-env": "^29.0.0",
"@ckeditor/ckeditor5-dev-webpack-plugin": "^29.0.0",
"buffer": "^6.0.3",
"chai": "^4.3.4",
"css-loader": "^5.2.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ describe( 'lib/tasks/translations-download', () => {

const results = await translationsDownload( {
cwd: '/workspace',
transifex: 'https://api.example.com'
organization: 'foo',
project: 'bar'
} );

expect( results ).to.equal( 'OK' );

expect( stubs.devEnv.downloadTranslations.calledOnce ).to.equal( true );
expect( stubs.devEnv.downloadTranslations.firstCall.firstArg ).to.deep.equal( {
token: 'secretToken',
url: 'https://api.example.com',
organizationName: 'foo',
projectName: 'bar',
cwd: '/workspace',
packages: new Map( [
[ 'ckeditor5-foo', '.' ]
Expand All @@ -72,14 +74,42 @@ describe( 'lib/tasks/translations-download', () => {
} );
} );

it( 'throws an error if the "transifex" option is not specified', async () => {
it( 'throws an error if the "organization" option is not specified', async () => {
try {
await translationsDownload( {
cwd: '/workspace'
} );
} catch ( err ) {
expect( err.message ).to.equal(
'The URL to the Transifex API is required. Use --transifex [API end-point] to provide the value.'
'The organization name is required. Use --organization [organization name] to provide the value.'
);
}
} );

it( 'throws an error if the "project" option is not specified', async () => {
try {
await translationsDownload( {
cwd: '/workspace',
organization: 'foo'
} );
} catch ( err ) {
expect( err.message ).to.equal(
'The project name is required. Use --project [project name] to provide the value.'
);
}
} );

it( 'throws an error if the "transifex" option is specified', async () => {
try {
await translationsDownload( {
cwd: '/workspace',
organization: 'foo',
project: 'bar',
transifex: 'https://api.example.com'
} );
} catch ( err ) {
expect( err.message ).to.equal(
'The --transifex [API end-point] option is no longer supported. Use `--organization` and `--project` instead.'
);
}
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ describe( 'lib/tasks/translations-upload', () => {

mockery.registerMock( 'path', stubs.path );
mockery.registerMock( 'glob', stubs.glob );
mockery.registerMock( '/workspace/package.json', {
name: '@ckeditor/ckeditor5-foo'
} );
mockery.registerMock( '@ckeditor/ckeditor5-dev-env', stubs.devEnv );
mockery.registerMock( '@ckeditor/ckeditor5-dev-env/lib/translations/gettoken', stubs.getToken );

Expand All @@ -52,27 +55,60 @@ describe( 'lib/tasks/translations-upload', () => {

const results = await translationsUpload( {
cwd: '/workspace',
transifex: 'https://api.example.com'
organization: 'foo',
project: 'bar'
} );

expect( results ).to.equal( 'OK' );

expect( stubs.devEnv.uploadPotFiles.calledOnce ).to.equal( true );
expect( stubs.devEnv.uploadPotFiles.firstCall.firstArg ).to.deep.equal( {
token: 'secretToken',
translationsDirectory: '/workspace/tmp/.transifex',
url: 'https://api.example.com'
cwd: '/workspace',
organizationName: 'foo',
packages: new Map( [
[ 'ckeditor5-foo', 'tmp/.transifex/ckeditor5-foo' ]
] ),
projectName: 'bar'
} );
} );

it( 'throws an error if the "transifex" option is not specified', async () => {
it( 'throws an error if the "organization" option is not specified', async () => {
try {
await translationsUpload( {
cwd: '/workspace'
} );
} catch ( err ) {
expect( err.message ).to.equal(
'The URL to the Transifex API is required. Use --transifex [API end-point] to provide the value.'
'The organization name is required. Use --organization [organization name] to provide the value.'
);
}
} );

it( 'throws an error if the "project" option is not specified', async () => {
try {
await translationsUpload( {
cwd: '/workspace',
organization: 'foo'
} );
} catch ( err ) {
expect( err.message ).to.equal(
'The project name is required. Use --project [project name] to provide the value.'
);
}
} );

it( 'throws an error if the "transifex" option is specified', async () => {
try {
await translationsUpload( {
cwd: '/workspace',
organization: 'foo',
project: 'bar',
transifex: 'https://api.example.com'
} );
} catch ( err ) {
expect( err.message ).to.equal(
'The --transifex [API end-point] option is no longer supported. Use `--organization` and `--project` instead.'
);
}
} );
Expand Down
15 changes: 15 additions & 0 deletions packages/ckeditor5-package-tools/tests/utils/parse-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ describe( 'lib/utils/parse-arguments', () => {
expect( options.watch ).to.equal( false );
expect( options.open ).to.equal( true );
expect( options.language ).to.equal( 'en' );
expect( options.organization ).to.equal( null );
expect( options.project ).to.equal( null );
expect( options.transifex ).to.equal( undefined );
} );

it( 'assigns the current work directory as the "#cwd" property', () => {
Expand Down Expand Up @@ -131,4 +134,16 @@ describe( 'lib/utils/parse-arguments', () => {

expect( options.language ).to.equal( 'pl' );
} );

it( 'allows specifying the organization option', () => {
const options = parseArguments( [ 'task-to-execute', '--organization', 'bar' ] );

expect( options.organization ).to.equal( 'bar' );
} );

it( 'allows specifying the project option', () => {
const options = parseArguments( [ 'task-to-execute', '--project', 'foo' ] );

expect( options.project ).to.equal( 'foo' );
} );
} );

0 comments on commit 2817b21

Please sign in to comment.