align to one format and include headers for extensions

This commit is contained in:
Tyler Leonhardt 2021-09-16 13:47:00 -07:00
parent e4989e2e30
commit 7cb531e421
No known key found for this signature in database
GPG key ID: 1BC2B6244363E77E
3 changed files with 91 additions and 33 deletions

View file

@ -18,25 +18,40 @@ function main() {
fileName: 'combined.nls.metadata.json',
edit: (parsedJson, file) => {
let key;
console.log(file.path);
if (file.base === 'out-vscode-min') {
key = 'vscode';
return { vscode: parsedJson };
}
else {
if (file.relative.endsWith('package.nls.json')) {
// put package.nls.json content in ExtensionNlsMetadata format
const convertedJson = {
messages: [],
keys: []
// Handle extensions and follow the same structure as the Core nls file.
switch (file.basename) {
case 'package.nls.json':
// put package.nls.json content in Core NlsMetadata format
parsedJson = {
messages: {
'package.nls.json': Object.values(parsedJson)
},
keys: {
'package.nls.json': Object.keys(parsedJson)
}
};
for (const key of Object.keys(parsedJson)) {
convertedJson.keys.push(key);
convertedJson.messages.push(parsedJson[key]);
break;
case 'nls.metadata.header.json':
parsedJson = { header: parsedJson };
break;
case 'nls.metadata.json':
// put nls.metadata.json content in Core NlsMetadata format
const modules = Object.keys(parsedJson);
const json = {
keys: {},
messages: {}
};
for (const module of modules) {
json.messages[module] = parsedJson[module].messages;
json.keys[module] = parsedJson[module].keys;
}
parsedJson = { package: convertedJson };
}
key = 'vscode.' + file.relative.split('/')[0];
parsedJson = json;
break;
}
key = 'vscode.' + file.relative.split('/')[0];
return { [key]: parsedJson };
},
}))

View file

@ -28,26 +28,46 @@ function main() {
vfs.src('.build/extensions/**/package.nls.json', { base: '.build/extensions' }))
.pipe(merge({
fileName: 'combined.nls.metadata.json',
edit: (parsedJson: any, file: any) => {
let key: string;
console.log(file.path);
edit: (parsedJson, file) => {
let key;
if (file.base === 'out-vscode-min') {
key = 'vscode';
} else {
if (file.relative.endsWith('package.nls.json')) {
// put package.nls.json content in ExtensionNlsMetadata format
const convertedJson: PackageNlsJson = {
messages: [],
keys: []
};
for (const key of Object.keys(parsedJson)) {
convertedJson.keys.push(key);
convertedJson.messages.push(parsedJson[key]);
}
parsedJson = { package: convertedJson };
}
key = 'vscode.' + file.relative.split('/')[0];
return { vscode: parsedJson };
}
// Handle extensions and follow the same structure as the Core nls file.
switch (file.basename) {
case 'package.nls.json':
// put package.nls.json content in Core NlsMetadata format
parsedJson = {
messages: {
'package.nls.json': Object.values(parsedJson)
},
keys: {
'package.nls.json': Object.keys(parsedJson)
}
};
break;
case 'nls.metadata.header.json':
parsedJson = { header: parsedJson };
break;
case 'nls.metadata.json':
// put nls.metadata.json content in Core NlsMetadata format
const modules = Object.keys(parsedJson);
const json: { keys: { [module: string]: string }, messages: { [module: string]: string } } = {
keys: {},
messages: {}
};
for (const module of modules) {
json.messages[module] = parsedJson[module].messages;
json.keys[module] = parsedJson[module].keys;
}
parsedJson = json;
break;
}
key = 'vscode.' + file.relative.split('/')[0];
return { [key]: parsedJson };
},
}))

View file

@ -47,6 +47,29 @@ declare module "vinyl" {
* Used for relative pathing. Typically where a glob starts.
*/
public base: string;
/**
* Gets and sets the basename of `file.path`.
*
* Throws when `file.path` is not set.
*
* Example:
*
* ```js
* var file = new File({
* cwd: '/',
* base: '/test/',
* path: '/test/file.js'
* });
*
* console.log(file.basename); // file.js
*
* file.basename = 'file.txt';
*
* console.log(file.basename); // file.txt
* console.log(file.path); // /test/file.txt
* ```
*/
basename: string;
/**
* Full path to the file.
*/
@ -105,7 +128,7 @@ declare module "vinyl" {
* This is required as per:
* https://github.com/microsoft/TypeScript/issues/5073
*/
namespace File {}
namespace File { }
export = File;