vscode-nls-dev
Version:
Development time npm module to generate strings bundles from Javascript files
39 lines • 1.93 kB
JavaScript
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
;
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const lib_1 = require("./lib");
const path = require("path");
/**
* A [webpack loader](https://webpack.js.org/api/loaders/) that rewrite nls-calls.
*/
module.exports = function (content, map, meta) {
console.assert(this.query && typeof this.query.base === 'string', 'Expected {base: string} option');
const callback = this.async();
const relativePath = (0, path_1.relative)(this.query.base, this.resourcePath);
const result = (0, lib_1.processFile)(content, relativePath, this.target === 'webworker' || this.target === 'web' ? '/' : undefined, map);
if (result.errors && result.errors.length > 0) {
// error
callback(new Error(result.errors.join()));
return;
}
if (result.bundle) {
const ext = path.extname(relativePath);
const base = relativePath.substr(0, relativePath.length - ext.length);
const metaDataContent = Object.assign(Object.assign({}, result.bundle), { filePath: (0, lib_1.removePathPrefix)(base, this.query.base) });
// this.emitFile(`${base}.nls.json`, JSON.stringify(result.bundle.messages, null, '\t'), 'utf8');
this.emitFile(`${base}.nls.metadata.json`, JSON.stringify(metaDataContent, null, '\t'), 'utf8');
}
if (!result.contents) {
// nothing
callback(null, content, map, meta);
}
else {
// result
callback(null, result.contents, result.sourceMap, meta);
}
};
//# sourceMappingURL=webpack-loader.js.map