-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'GoogleChrome:main' into offscreen-user-media-sample
- Loading branch information
Showing
154 changed files
with
19,821 additions
and
3,185 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
- package-ecosystem: "npm" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,44 @@ | ||
import fs from 'fs/promises'; | ||
import { ManifestData } from '../types'; | ||
import { dirname } from 'path'; | ||
import { ManifestData, LocaleData } from '../types'; | ||
const localeRegex = /__MSG_([^_]*)__/ | ||
|
||
function usesLocaleFiles(obj: object): boolean { | ||
// recursively check if any value in a supplied object | ||
// is a string that starts with __MSG_. If found, it | ||
// means that the extension uses locale files. | ||
return Object.values(obj).some((value) => { | ||
if (Object.prototype.toString.call(value) === '[object Object]') { | ||
return usesLocaleFiles(value); | ||
} | ||
return typeof value === 'string' && value.startsWith('__MSG_') | ||
}); | ||
} | ||
|
||
export const getManifest = async ( | ||
manifestPath: string | ||
): Promise<ManifestData> => { | ||
const manifest = await fs.readFile(manifestPath, 'utf8'); | ||
const parsedManifest = JSON.parse(manifest); | ||
|
||
if (usesLocaleFiles(parsedManifest)) { | ||
const directory = dirname(manifestPath); | ||
const localeFile: string = await fs.readFile(`${directory}/_locales/en/messages.json`, 'utf8') | ||
const localeData: LocaleData = JSON.parse(localeFile); | ||
|
||
for (const [key, value] of Object.entries(parsedManifest)) { | ||
if (typeof value === 'string' && value.startsWith('__MSG_')) { | ||
const localeKey: string | undefined = value.match(localeRegex)?.[1]; | ||
|
||
if (localeKey) { | ||
const localeKeyData = localeData[localeKey] | ||
const localeMessage: string = localeKeyData?.message; | ||
|
||
parsedManifest[key] = localeMessage; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return parsedManifest; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.