-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Include localized diagnostics #18702
Changes from 9 commits
c5cb07e
a622648
96d748b
9e3a30f
74d5e80
e7f730a
a241854
538cbe0
89b0d56
1bf2179
10f5acc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ var libraryDirectory = "src/lib/"; | |
var scriptsDirectory = "scripts/"; | ||
var unittestsDirectory = "src/harness/unittests/"; | ||
var docDirectory = "doc/"; | ||
var lclDirectory = "src/loc/lcl"; | ||
|
||
var builtDirectory = "built/"; | ||
var builtLocalDirectory = "built/local/"; | ||
|
@@ -424,7 +425,40 @@ compileFile(processDiagnosticMessagesJs, | |
[processDiagnosticMessagesTs], | ||
[processDiagnosticMessagesTs], | ||
[], | ||
/*useBuiltCompiler*/ false); | ||
/*useBuiltCompiler*/ false); | ||
|
||
// Localize diagnostics script | ||
var generateLocalizedDiagnosticMessagesJs = path.join(scriptsDirectory, "generateLocalizedDiagnosticMessages.js"); | ||
var generateLocalizedDiagnosticMessagesTs = path.join(scriptsDirectory, "generateLocalizedDiagnosticMessages.ts"); | ||
|
||
file(generateLocalizedDiagnosticMessagesTs); | ||
|
||
compileFile(generateLocalizedDiagnosticMessagesJs, | ||
[generateLocalizedDiagnosticMessagesTs], | ||
[generateLocalizedDiagnosticMessagesTs], | ||
[], | ||
/*useBuiltCompiler*/ false, { noOutFile: true, types: ["node", "xml2js"] }); | ||
|
||
// Localize diagnostics | ||
var generatedLCGFile = path.join(builtLocalDirectory, "enu", "diagnosticMessages.generated.json.lcg"); | ||
file(generatedLCGFile, [generateLocalizedDiagnosticMessagesJs, diagnosticInfoMapTs, generatedDiagnosticMessagesJSON], function () { | ||
var cmd = host + " " + generateLocalizedDiagnosticMessagesJs + " " + lclDirectory + " " + builtLocalDirectory + " " + generatedDiagnosticMessagesJSON; | ||
console.log(cmd); | ||
var ex = jake.createExec([cmd]); | ||
// Add listeners for output and error | ||
ex.addListener("stdout", function (output) { | ||
process.stdout.write(output); | ||
}); | ||
ex.addListener("stderr", function (error) { | ||
process.stderr.write(error); | ||
}); | ||
ex.addListener("cmdEnd", function () { | ||
complete(); | ||
}); | ||
ex.run(); | ||
}, { async: true }); | ||
|
||
task("localize", [generatedLCGFile]); | ||
|
||
var buildProtocolTs = path.join(scriptsDirectory, "buildProtocol.ts"); | ||
var buildProtocolJs = path.join(scriptsDirectory, "buildProtocol.js"); | ||
|
@@ -641,7 +675,7 @@ task("build-fold-end", [], function () { | |
|
||
// Local target to build the compiler and services | ||
desc("Builds the full compiler and services"); | ||
task("local", ["build-fold-start", "generate-diagnostics", "lib", tscFile, servicesFile, nodeDefinitionsFile, serverFile, buildProtocolDts, builtGeneratedDiagnosticMessagesJSON, "lssl", "build-fold-end"]); | ||
task("local", ["build-fold-start", "generate-diagnostics", "lib", tscFile, servicesFile, nodeDefinitionsFile, serverFile, buildProtocolDts, builtGeneratedDiagnosticMessagesJSON, "lssl", "build-fold-end", "localize"]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// Local target to build only tsc.js | ||
desc("Builds only the compiler"); | ||
|
@@ -696,7 +730,10 @@ task("generate-spec", [specMd]); | |
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory | ||
desc("Makes a new LKG out of the built js files"); | ||
task("LKG", ["clean", "release", "local"].concat(libraryTargets), function () { | ||
var expectedFiles = [tscFile, servicesFile, serverFile, nodePackageFile, nodeDefinitionsFile, standaloneDefinitionsFile, tsserverLibraryFile, tsserverLibraryDefinitionFile, cancellationTokenFile, typingsInstallerFile, buildProtocolDts, watchGuardFile].concat(libraryTargets); | ||
var expectedFiles = [tscFile, servicesFile, serverFile, nodePackageFile, nodeDefinitionsFile, standaloneDefinitionsFile, tsserverLibraryFile, tsserverLibraryDefinitionFile, cancellationTokenFile, typingsInstallerFile, buildProtocolDts, watchGuardFile]. | ||
concat(libraryTargets). | ||
concat(fs.readdirSync(lclDirectory).map(function (d) { return path.join(builtLocalDirectory, d) })). | ||
concat(path.dirname(generatedLCGFile)); | ||
var missingFiles = expectedFiles.filter(function (f) { | ||
return !fs.existsSync(f); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,8 @@ | |
"@types/q": "latest", | ||
"@types/run-sequence": "latest", | ||
"@types/through2": "latest", | ||
"@types/xml2js": "^0.4.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be |
||
"xml2js": "^0.4.19", | ||
"browser-resolve": "^1.11.2", | ||
"browserify": "latest", | ||
"chai": "latest", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import * as xml2js from "xml2js"; | ||
|
||
function main(): void { | ||
const args = process.argv.slice(2); | ||
if (args.length != 3) { | ||
console.log("Usage:") | ||
console.log("\tnode generateLocalizedDiagnosticMessages.js <lcl source directory> <output directory> <generated diagnostics map file>"); | ||
return; | ||
} | ||
|
||
const inputPath = args[0]; | ||
const outputPath = args[1]; | ||
const diagnosticsMapFilePath = args[2]; | ||
|
||
// generate the lcg file for enu | ||
generateLCGFile(); | ||
|
||
// generate other langs | ||
fs.readdir(inputPath, (err, files) => { | ||
handelError(err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. handle :) |
||
files.forEach(visitDirectory); | ||
}); | ||
|
||
return; | ||
|
||
function visitDirectory(name: string) { | ||
const inputFilePath = path.join(inputPath, name, "diagnosticMessages", "diagnosticMessages.generated.json.lcl"); | ||
const outputFilePath = path.join(outputPath, name, "diagnosticMessages.generated.json"); | ||
fs.readFile(inputFilePath, (err, data) => { | ||
handelError(err); | ||
xml2js.parseString(data.toString(), (err, result) => { | ||
handelError(err); | ||
writeFile(outputFilePath, xmlObjectToString(result)); | ||
}); | ||
}); | ||
} | ||
|
||
function handelError(err: null | object) { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
function xmlObjectToString(o: any) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment here what we expect the incoming XML to look like |
||
const out: any = {}; | ||
for (const item of o["LCX"]["Item"][0]["Item"][0]["Item"]) { | ||
let ItemId = item["$"]["ItemId"]; | ||
let Val = item["Str"][0]["Tgt"] ? item["Str"][0]["Tgt"][0]["Val"][0] : item["Str"][0]["Val"][0]; | ||
|
||
if (typeof ItemId !== "string" || typeof Val !== "string") { | ||
console.error("Unexpected XML file structure"); | ||
process.exit(1); | ||
} | ||
|
||
if (ItemId.charAt(0) === ";") { | ||
ItemId = ItemId.slice(1); // remove leading semicolon | ||
} | ||
|
||
Val = Val.replace(/]5D;/, "]"); // unescape `]` | ||
out[ItemId] = Val; | ||
} | ||
return JSON.stringify(out, undefined, 2); | ||
} | ||
|
||
|
||
function ensureDirectoryExists(directoryPath: string, action: () => void) { | ||
fs.exists(directoryPath, exists => { | ||
if (!exists) { | ||
const basePath = path.dirname(directoryPath); | ||
if (basePath !== directoryPath) { | ||
return ensureDirectoryExists(basePath, () => fs.mkdir(directoryPath, action)); | ||
} | ||
} | ||
action(); | ||
}); | ||
} | ||
|
||
function writeFile(fileName: string, contents: string) { | ||
ensureDirectoryExists(path.dirname(fileName), () => { | ||
fs.writeFile(fileName, contents, handelError); | ||
}); | ||
} | ||
|
||
function objectToList(o: Record<string, string>) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're assuming an ES2015 runtime, you can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to http://node.green/, node |
||
let list: { key: string, value: string }[] = []; | ||
for (const key in o) { | ||
list.push({ key, value: o[key] }); | ||
} | ||
return list; | ||
} | ||
|
||
function generateLCGFile() { | ||
return fs.readFile(diagnosticsMapFilePath, (err, data) => { | ||
handelError(err); | ||
writeFile( | ||
path.join(outputPath, "enu", "diagnosticMessages.generated.json.lcg"), | ||
getLCGFileXML( | ||
objectToList(JSON.parse(data.toString())) | ||
.sort((a, b) => a.key > b.key ? 1 : -1) // lcg sorted by property keys | ||
.reduce((s, { key, value }) => s + getItemXML(key, value), "") | ||
)); | ||
}); | ||
|
||
function getItemXML(key: string, value: string) { | ||
// escape entrt value | ||
value = value.replace(/]/, "]5D;"); | ||
|
||
return ` | ||
<Item ItemId=";${key}" ItemType="0" PsrId="306" Leaf="true"> | ||
<Str Cat="Text"> | ||
<Val><![CDATA[${value}]]></Val> | ||
</Str> | ||
<Disp Icon="Str" /> | ||
</Item>` | ||
} | ||
|
||
function getLCGFileXML(items: string) { | ||
return `<?xml version="1.0" encoding="utf-8"?> | ||
<LCX SchemaVersion="6.0" Name="diagnosticMessages.generated.json" PsrId="306" FileType="1" SrcCul="en-US" xmlns="http://schemas.microsoft.com/locstudio/2006/6/lcx"> | ||
<OwnedComments> | ||
<Cmt Name="Dev" /> | ||
<Cmt Name="LcxAdmin" /> | ||
<Cmt Name="Rccx" /> | ||
</OwnedComments> | ||
<Item ItemId=";String Table" ItemType="0" PsrId="306" Leaf="false"> | ||
<Disp Icon="Expand" Expand="true" Disp="true" LocTbl="false" /> | ||
<Item ItemId=";Strings" ItemType="0" PsrId="306" Leaf="false"> | ||
<Disp Icon="Str" Disp="true" LocTbl="false" />${items} | ||
</Item> | ||
</Item> | ||
</LCX>`; | ||
} | ||
} | ||
} | ||
|
||
main(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than building the script in the gulpfile, can we just
import
the typescript directly, and call a function it exports (instead of shelling out)? We could do this with our other scripts in theGulpfile
to cut away some cruft, too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we doing this anywhere else in gulpFile? i tried to stay close to the Jake file really. i am not a gulp user :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were doing it for the old parallel runner, though I've removed it since it's in the harness now. It's no big deal; could just be a little cleaner-feeling, since then there'd be no (visible) compilation step for the script. Doesn't matter much, since we need to keep the compilation step in the
Jakefile
anyway.