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

misc: refactor collect-strings.js to use glob and work on windows #9406

Merged
merged 17 commits into from
Jul 26, 2019
13 changes: 8 additions & 5 deletions lighthouse-core/scripts/i18n/collect-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const UISTRINGS_REGEX = /UIStrings = (.|\s)*?\};\n/im;
*/

const ignoredPathComponents = [
'/.git',
'/scripts',
'/node_modules',
'/test/',
`${path.sep}.git`,
`${path.sep}scripts`,
`${path.sep}node_modules`,
`${path.sep}test${path.sep}`,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i kinda hate this, wb this instead

[
  '/.git',
  '/scripts',
  '/node_modules',
  '/test/',
  '-test.js',
  '-renderer.js',
].map(str => str.replace(/\//g, path.sep));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, this seems even more obtuse imo.

Copy link
Collaborator

@patrickhulce patrickhulce Jul 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like @connorjclark's suggestion, the readability of the paths is the important thing IMO, the fact that we want to support multiple OS is the secondary concern, maybe just add the

// Ensure we use the OS-specific path separator comment to the map line?

'-test.js',
'-renderer.js',
];
Expand Down Expand Up @@ -86,7 +86,10 @@ function collectAllStringsInDir(dir, strings = {}) {
const key = property.key.name;
const message = exportVars.UIStrings[key];
const description = computeDescription(ast, property, lastPropertyEndIndex);
strings[`${relativePath} | ${key}`] = {message, description};
const pathKey = relativePath
// Windows compat.
.replace(/\\/g, '/');
strings[`${pathKey} | ${key}`] = {message, description};
lastPropertyEndIndex = property.range[1];
}
}
Expand Down