Skip to content

Commit 1da5be6

Browse files
authored
Refactor localization extraction logic for pre-commit to streamline input handling (#22077)
1 parent bd2a245 commit 1da5be6

1 file changed

Lines changed: 15 additions & 21 deletions

File tree

scripts/localization-extract.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,18 @@ const EXTENSION_CONFIG = {
2020
"data-workspace": "data-workspace",
2121
};
2222

23-
const EXTENSION_INPUTS = {
24-
mssql: ["extensions/mssql/src/", "extensions/mssql/package.nls.json"],
25-
"sql-database-projects": [
26-
"extensions/sql-database-projects/src/",
27-
"extensions/sql-database-projects/package.nls.json",
28-
],
29-
"data-workspace": [
30-
"extensions/data-workspace/src/",
31-
"extensions/data-workspace/package.nls.json",
32-
],
33-
};
34-
35-
const LOCALIZATION_SCRIPT_INPUTS = [
23+
const PRECOMMIT_FULL_EXTRACTION_INPUTS = [
24+
"package.json",
25+
"package-lock.json",
3626
"scripts/localization-extract.js",
3727
"scripts/file-utils.js",
3828
"scripts/terminal-logger.js",
3929
];
4030

31+
function getExtensionInputs(extensionDir) {
32+
return [`extensions/${extensionDir}/src/`, `extensions/${extensionDir}/package.nls.json`];
33+
}
34+
4135
function getStagedFiles() {
4236
const output = execFileSync(
4337
"git",
@@ -48,7 +42,7 @@ function getStagedFiles() {
4842
return output
4943
.toString("utf8")
5044
.split("\0")
51-
.map((file) => file.replace(/\\/g, "/").trim())
45+
.map((file) => file.replace(/\\/g, "/"))
5246
.filter(Boolean);
5347
}
5448

@@ -59,15 +53,15 @@ function matchesInput(file, input) {
5953
function getAffectedExtensionsForPrecommit() {
6054
const stagedFiles = getStagedFiles();
6155

62-
if (stagedFiles.some((file) => LOCALIZATION_SCRIPT_INPUTS.includes(file))) {
56+
if (stagedFiles.some((file) => PRECOMMIT_FULL_EXTRACTION_INPUTS.includes(file))) {
6357
return Object.keys(EXTENSION_CONFIG);
6458
}
6559

66-
return Object.entries(EXTENSION_INPUTS)
67-
.filter(([, inputs]) =>
68-
stagedFiles.some((file) => inputs.some((input) => matchesInput(file, input))),
69-
)
70-
.map(([extension]) => extension);
60+
return Object.keys(EXTENSION_CONFIG).filter((extensionDir) =>
61+
stagedFiles.some((file) =>
62+
getExtensionInputs(extensionDir).some((input) => matchesInput(file, input)),
63+
),
64+
);
7165
}
7266

7367
/**
@@ -227,7 +221,7 @@ async function extractLocalizationStrings() {
227221
async function extractLocalizationForPrecommit() {
228222
const affectedExtensions = getAffectedExtensionsForPrecommit();
229223
if (!affectedExtensions.length) {
230-
console.log("No staged localization inputs; skipping localization extraction.");
224+
logger.info("No staged localization inputs; skipping localization extraction.");
231225
return;
232226
}
233227

0 commit comments

Comments
 (0)