提交 60531dd2 编写于 作者: M Michel Kaporin

Reverted typings folder refactoring. Made build pipeline to break on failures...

Reverted typings folder refactoring. Made build pipeline to break on failures in parsing or in communication with Transifex.
上级 20fe186d
......@@ -141,7 +141,7 @@ var XLF = (function () {
};
XLF.prototype.addStringItem = function (item) {
if (!item.id || !item.message) {
//throw new Error('No item ID or value specified.');
throw new Error('No item ID or value specified.');
}
this.appendNewLine("<trans-unit id=\"" + item.id + "\">", 4);
this.appendNewLine("<source xml:lang=\"en\">" + item.message + "</source>", 6);
......@@ -542,7 +542,7 @@ function importBundleJson(file, json, stream) {
var keys = json.keys[source];
var messages = json.messages[source];
if (keys.length !== messages.length) {
log('Error:', "There is a mismatch between keys and messages in " + file.relative);
throw new Error("There is a mismatch between keys and messages in " + file.relative);
}
var xlf = bundleXlfs[resource] ? bundleXlfs[resource] : bundleXlfs[resource] = new XLF(project);
xlf.addFile('src/' + source, keys, messages);
......@@ -557,7 +557,7 @@ function importBundleJson(file, json, stream) {
var extensions = Object.create(null);
function importModuleOrPackageJson(file, json, projectName, stream, extensionName) {
if (ModuleJsonFormat.is(json) && json['keys'].length !== json['messages'].length) {
log('Error:', "There is a mismatch between keys and messages in " + file.relative);
throw new Error("There is a mismatch between keys and messages in " + file.relative);
}
// Prepare the source path for <original/> attribute in XLF & extract messages from JSON
var formattedSourcePath = file.relative.replace(/\\/g, '/');
......@@ -615,7 +615,7 @@ function importIsl(file, stream) {
}
var sections = line.split('=');
if (sections.length !== 2) {
log('Error:', "Badly formatted message found: " + line);
throw new Error("Badly formatted message found: " + line);
}
else {
var key = sections[0];
......@@ -654,8 +654,6 @@ function pushXlfFiles(apiHostname, username, password) {
promise = createResource(project, slug, file, apiHostname, credentials);
}
updateCreatePromises.push(promise);
}).catch(function (reason) {
log('Error:', reason);
});
}, function () {
var _this = this;
......@@ -663,8 +661,8 @@ function pushXlfFiles(apiHostname, username, password) {
Promise.all(tryGetPromises).then(function () {
Promise.all(updateCreatePromises).then(function () {
_this.emit('end');
}).catch(function (reason) { return log('Error:', reason); });
}).catch(function (reason) { return log('Error:', reason); });
}).catch(function (reason) { throw new Error(reason); });
}).catch(function (reason) { throw new Error(reason); });
});
}
exports.pushXlfFiles = pushXlfFiles;
......@@ -686,7 +684,8 @@ function tryGetResource(project, slug, apiHostname, credentials) {
else {
reject("Failed to query resource " + project + "/" + slug + ". Response: " + response.statusCode + " " + response.statusMessage);
}
}).on('error', function (err) {
});
request.on('error', function (err) {
reject("Failed to get " + project + "/" + slug + " on Transifex: " + err);
});
request.end();
......@@ -717,7 +716,8 @@ function createResource(project, slug, xlfFile, apiHostname, credentials) {
else {
reject("Something went wrong in the request creating " + slug + " in " + project + ". " + res.statusCode);
}
}).on('error', function (err) {
});
request.on('error', function (err) {
reject("Failed to create " + project + "/" + slug + " on Transifex: " + err);
});
request.write(data);
......@@ -757,7 +757,8 @@ function updateResource(project, slug, xlfFile, apiHostname, credentials) {
else {
reject("Something went wrong in the request updating " + slug + " in " + project + ". " + res.statusCode);
}
}).on('error', function (err) {
});
request.on('error', function (err) {
reject("Failed to update " + project + "/" + slug + " on Transifex: " + err);
});
request.write(data);
......@@ -835,12 +836,13 @@ function pullXlfFiles(projectName, apiHostname, username, password, resources) {
stream_1.emit('data', new File({ contents: new Buffer(xlfBuffer) }));
}
else {
log('Error:', slug + " in " + project + " returned no data. Response code: " + res.statusCode + ".");
throw new Error(slug + " in " + project + " returned no data. Response code: " + res.statusCode + ".");
}
translationsRetrieved++;
});
}).on('error', function (err) {
log('Error:', "Failed to query resource " + slug + " with the following error: " + err);
});
request.on('error', function (err) {
throw new Error("Failed to query resource " + slug + " with the following error: " + err);
});
request.end();
});
......@@ -870,7 +872,7 @@ function prepareJsonFiles() {
stream.emit('data', translatedFile);
});
}, function (rejectReason) {
log('Error:', rejectReason);
throw new Error("XLF parsing error: " + rejectReason);
});
});
}
......
......@@ -186,7 +186,7 @@ export class XLF {
private addStringItem(item: Item): void {
if (!item.id || !item.message) {
//throw new Error('No item ID or value specified.');
throw new Error('No item ID or value specified.');
}
this.appendNewLine(`<trans-unit id="${item.id}">`, 4);
......@@ -609,7 +609,7 @@ function importBundleJson(file: File, json: BundledFormat, stream: ThroughStream
const keys = json.keys[source];
const messages = json.messages[source];
if (keys.length !== messages.length) {
log('Error:', `There is a mismatch between keys and messages in ${file.relative}`);
throw new Error(`There is a mismatch between keys and messages in ${file.relative}`);
}
let xlf = bundleXlfs[resource] ? bundleXlfs[resource] : bundleXlfs[resource] = new XLF(project);
......@@ -627,7 +627,7 @@ function importBundleJson(file: File, json: BundledFormat, stream: ThroughStream
var extensions: Map<{ xlf: XLF, processed: number }> = Object.create(null);
function importModuleOrPackageJson(file: File, json: ModuleJsonFormat | PackageJsonFormat, projectName: string, stream: ThroughStream, extensionName?: string): void {
if (ModuleJsonFormat.is(json) && json['keys'].length !== json['messages'].length) {
log('Error:', `There is a mismatch between keys and messages in ${file.relative}`);
throw new Error(`There is a mismatch between keys and messages in ${file.relative}`);
}
// Prepare the source path for <original/> attribute in XLF & extract messages from JSON
......@@ -696,7 +696,7 @@ function importIsl(file: File, stream: ThroughStream) {
}
let sections: string[] = line.split('=');
if (sections.length !== 2) {
log('Error:', `Badly formatted message found: ${line}`);
throw new Error(`Badly formatted message found: ${line}`);
} else {
let key = sections[0];
let value = sections[1];
......@@ -738,8 +738,6 @@ export function pushXlfFiles(apiHostname: string, username: string, password: st
promise = createResource(project, slug, file, apiHostname, credentials);
}
updateCreatePromises.push(promise);
}).catch((reason) => {
log('Error:', reason);
});
}, function() {
......@@ -747,8 +745,8 @@ export function pushXlfFiles(apiHostname: string, username: string, password: st
Promise.all(tryGetPromises).then(() => {
Promise.all(updateCreatePromises).then(() => {
this.emit('end');
}).catch((reason) => log('Error:', reason));
}).catch((reason) => log('Error:', reason));
}).catch((reason) => { throw new Error(reason); });
}).catch((reason) => { throw new Error(reason); });
});
}
......@@ -769,7 +767,8 @@ function tryGetResource(project: string, slug: string, apiHostname: string, cred
} else {
reject(`Failed to query resource ${project}/${slug}. Response: ${response.statusCode} ${response.statusMessage}`);
}
}).on('error', (err) => {
});
request.on('error', (err) => {
reject(`Failed to get ${project}/${slug} on Transifex: ${err}`);
});
......@@ -802,7 +801,8 @@ function createResource(project: string, slug: string, xlfFile: File, apiHostnam
} else {
reject(`Something went wrong in the request creating ${slug} in ${project}. ${res.statusCode}`);
}
}).on('error', (err) => {
});
request.on('error', (err) => {
reject(`Failed to create ${project}/${slug} on Transifex: ${err}`);
});
......@@ -845,7 +845,8 @@ function updateResource(project: string, slug: string, xlfFile: File, apiHostnam
} else {
reject(`Something went wrong in the request updating ${slug} in ${project}. ${res.statusCode}`);
}
}).on('error', (err) => {
});
request.on('error', (err) => {
reject(`Failed to update ${project}/${slug} on Transifex: ${err}`);
});
......@@ -914,7 +915,7 @@ export function pullXlfFiles(projectName: string, apiHostname: string, username:
const stream = this;
vscodeLanguages.map(function(language) {
resources.map(function (resource) {
resources.map(function(resource) {
const slug = resource.name.replace(/\//g, '_');
const project = resource.project;
const iso639 = iso639_3_to_2[language];
......@@ -932,12 +933,13 @@ export function pullXlfFiles(projectName: string, apiHostname: string, username:
if (res.statusCode === 200) {
stream.emit('data', new File({ contents: new Buffer(xlfBuffer) }));
} else {
log('Error:', `${slug} in ${project} returned no data. Response code: ${res.statusCode}.`);
throw new Error(`${slug} in ${project} returned no data. Response code: ${res.statusCode}.`);
}
translationsRetrieved++;
});
}).on('error', (err) => {
log('Error:', `Failed to query resource ${slug} with the following error: ${err}`);
});
request.on('error', (err) => {
throw new Error(`Failed to query resource ${slug} with the following error: ${err}`);
});
request.end();
});
......@@ -973,7 +975,7 @@ export function prepareJsonFiles(): ThroughStream {
});
},
function(rejectReason) {
log('Error:', rejectReason);
throw new Error(`XLF parsing error: ${rejectReason}`);
}
);
});
......
// Type definitions for through
// Project: https://github.com/dominictarr/through
// Definitions by: Andrew Gaspar <https://github.com/AndrewGaspar/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "through" {
import stream = require("stream");
function through(write?: (data:any) => void,
end?: () => void,
opts?: {
autoDestroy: boolean;
}): through.ThroughStream;
module through {
export interface ThroughStream extends stream.Transform {
autoDestroy: boolean;
}
}
export = through;
}
\ No newline at end of file
......@@ -35,6 +35,4 @@ const extensions = [
'gulp'
];
extensions.forEach(extension => npmInstall(`extensions/${extension}`));
npmInstall('build'); // typings used in the build folder
\ No newline at end of file
extensions.forEach(extension => npmInstall(`extensions/${extension}`));
\ No newline at end of file
{
"name": "build",
"version": "1.0.0",
"author": "Microsoft Corporation",
"devDependencies": {
"@types/xml2js": "^0.0.33"
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册