Skip to content

Commit

Permalink
[i18n] NPM publish i18ntokens.json (#4771)
Browse files Browse the repository at this point in the history
* [i18n] NPM publish `i18ntokens.json`

* Add entry in changelog

* Fix missing await

* Update CHANGELOG.md

Co-authored-by: Greg Thompson <thompson.glowe@gmail.com>

Co-authored-by: Greg Thompson <thompson.glowe@gmail.com>
  • Loading branch information
2 people authored and cchaos committed May 4, 2021
1 parent 2e721df commit 0ac8774
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 72 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Added `inherit` color option to `EuiIcon` to force two-tone (app) icons to inherit their parent's color ([#4760](https://github.com/elastic/eui/pull/4760))
- Updated `EuiBetaBadge, EuiBadge, EuiButtonIcon, EuiButtonContent, EuiCallOut, EuiContextMenuItem, EuiListGroupItem` icon usage to inherit their parent's color ([#4760](https://github.com/elastic/eui/pull/4760))
- Added `iconProps` prop to `EuiListGroupItem` ([#4760](https://github.com/elastic/eui/pull/4760))
- Added `i18ntokens.json` to published package ([#4771](https://github.com/elastic/eui/pull/4771))

**Bug fixes**

Expand Down
70 changes: 11 additions & 59 deletions src-docs/src/i18ntokens.json → i18ntokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@
"highlighting": "string",
"loc": {
"start": {
"line": 1166,
"line": 1168,
"column": 8
},
"end": {
"line": 1166,
"line": 1168,
"column": 79
}
},
Expand All @@ -117,11 +117,11 @@
"highlighting": "string",
"loc": {
"start": {
"line": 1387,
"line": 1389,
"column": 10
},
"end": {
"line": 1391,
"line": 1393,
"column": 12
}
},
Expand Down Expand Up @@ -2901,11 +2901,11 @@
"highlighting": "string",
"loc": {
"start": {
"line": 742,
"line": 754,
"column": 14
},
"end": {
"line": 745,
"line": 757,
"column": 16
}
},
Expand Down Expand Up @@ -3440,65 +3440,17 @@
"filepath": "src/components/table/mobile/table_sort_mobile.tsx"
},
{
"token": "euiTableHeaderCell.clickForDescending",
"defString": "Click to sort in descending order",
"token": "euiTableHeaderCell.titleTextWithDesc",
"defString": "{innerText}; {description}",
"highlighting": "string",
"loc": {
"start": {
"line": 135,
"column": 10
},
"end": {
"line": 138,
"column": 12
}
},
"filepath": "src/components/table/table_header_cell.tsx"
},
{
"token": "euiTableHeaderCell.clickForUnsort",
"defString": "Click to unsort",
"highlighting": "string",
"loc": {
"start": {
"line": 144,
"column": 10
},
"end": {
"line": 147,
"column": 12
}
},
"filepath": "src/components/table/table_header_cell.tsx"
},
{
"token": "euiTableHeaderCell.clickForAscending",
"defString": "Click to sort in ascending order",
"highlighting": "string",
"loc": {
"start": {
"line": 152,
"column": 8
},
"end": {
"line": 155,
"line": 103,
"column": 10
}
},
"filepath": "src/components/table/table_header_cell.tsx"
},
{
"token": "euiTableHeaderCell.titleTextWithSort",
"defString": "{innerText}; Sorted in {ariaSortValue} order",
"highlighting": "string",
"loc": {
"start": {
"line": 163,
"column": 12
},
"end": {
"line": 166,
"column": 52
"line": 106,
"column": 48
}
},
"filepath": "src/components/table/table_header_cell.tsx"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/babel/fetch-i18n-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,6 @@ tokenMappings.reduce(
);

fs.writeFileSync(
join(rootDir, 'src-docs', 'src', 'i18ntokens.json'),
join(rootDir, 'i18ntokens.json'),
JSON.stringify(tokenMappings, null, 2)
);
6 changes: 3 additions & 3 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ if (args.dry_run) {
execSync('npm run build', execOptions);
}


if (args.steps.indexOf('version') > -1) {
// prompt user for what type of version bump to make (major|minor|patch)
const versionTarget = await getVersionTypeFromChangelog();

// build may have generated a new src-docs/src/i18ntokens.json file, dirtying the git workspace
// build may have generated a new i18ntokens.json file, dirtying the git workspace
// it's important to track those changes with this release, so determine the changes and write them
// to src-docs/src/i18ntokens_changelog.json, comitting both to the workspace before running `npm version`
// to i18ntokens_changelog.json, comitting both to the workspace before running `npm version`
execSync(`npm run update-token-changelog -- ${versionTarget}`, execOptions);

// update package.json & package-lock.json version, git commit, git tag
Expand Down
30 changes: 23 additions & 7 deletions scripts/update-token-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const semver = require('semver');

const repoDir = path.resolve(__dirname, '..');
const packagePath = path.resolve(repoDir, 'package.json');
const tokensPath = path.resolve(repoDir, 'src-docs', 'src', 'i18ntokens.json');
const tokensChangelogPath = path.resolve(repoDir, 'src-docs', 'src', 'i18ntokens_changelog.json');
const tokensPath = path.resolve(repoDir, 'i18ntokens.json');
const tokensChangelogPath = path.resolve(repoDir, 'i18ntokens_changelog.json');

const validVersionTypes = new Set(['patch', 'minor', 'major']);
const [, , versionIncrementType] = process.argv;
Expand Down Expand Up @@ -101,14 +101,14 @@ async function commitTokenChanges(repo) {

const index = await repo.refreshIndex();

if (dirtyFiles.has('src-docs/src/i18ntokens.json')) {
if (dirtyFiles.has('i18ntokens.json')) {
createCommit = true;
await index.addByPath('src-docs/src/i18ntokens.json');
await index.addByPath('i18ntokens.json');
}

if (dirtyFiles.has('src-docs/src/i18ntokens_changelog.json')) {
if (dirtyFiles.has('i18ntokens_changelog.json')) {
createCommit = true;
await index.addByPath('src-docs/src/i18ntokens_changelog.json');
await index.addByPath('i18ntokens_changelog.json');
}

if (createCommit) {
Expand All @@ -128,12 +128,28 @@ async function getCommitForTagName(repo, tagname) {
return git.Commit.lookup(repo, tag.targetId());
}

async function getPreviousI18nTokens(previousVersionCommit) {
try {
return JSON.parse(
await getFileContentsFromCommit(previousVersionCommit, 'i18ntokens.json')
);
} catch (err) {
// If failed, try with the previous path where it used to exist
return JSON.parse(
await getFileContentsFromCommit(
previousVersionCommit,
'src-docs/src/i18ntokens.json'
)
);
}
}

async function main() {
const repo = await git.Repository.open(repoDir);
const previousVersionCommit = await getCommitForTagName(repo, `v${oldPackageVersion}`);

// check for i18n token differences between the current file & the most recent EUI version
const originalTokens = JSON.parse(await getFileContentsFromCommit(previousVersionCommit, 'src-docs/src/i18ntokens.json'));
const originalTokens = await getPreviousI18nTokens(previousVersionCommit);
const newTokens = require(tokensPath);

const changes = getTokenChanges(originalTokens, newTokens);
Expand Down
4 changes: 2 additions & 2 deletions src-docs/src/views/package/i18n_tokens.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import tokens from '../../i18ntokens';
import tokenChangelog from '../../i18ntokens_changelog';
import tokens from '../../../../i18ntokens.json';
import tokenChangelog from '../../../../i18ntokens_changelog.json';

import {
EuiAccordion,
Expand Down

0 comments on commit 0ac8774

Please sign in to comment.