Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/azure-pipelines/upload-nlsmetadata.ts
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import es from 'event-stream';
7
import Vinyl from 'vinyl';
8
import vfs from 'vinyl-fs';
9
import merge from 'gulp-merge-json';
10
import gzip from 'gulp-gzip';
11
import { ClientAssertionCredential } from '@azure/identity';
12
import path = require('path');
13
import { readFileSync } from 'fs';
14
const azure = require('gulp-azure-storage');
15
16
const commit = process.env['BUILD_SOURCEVERSION'];
17
const credential = new ClientAssertionCredential(process.env['AZURE_TENANT_ID']!, process.env['AZURE_CLIENT_ID']!, () => Promise.resolve(process.env['AZURE_ID_TOKEN']!));
18
19
interface NlsMetadata {
20
keys: { [module: string]: string };
21
messages: { [module: string]: string };
22
bundles: { [bundle: string]: string[] };
23
}
24
25
function main(): Promise<void> {
26
return new Promise((c, e) => {
27
const combinedMetadataJson = es.merge(
28
// vscode: we are not using `out-build/nls.metadata.json` here because
29
// it includes metadata for translators for `keys`. but for our purpose
30
// we want only the `keys` and `messages` as `string`.
31
es.merge(
32
vfs.src('out-build/nls.keys.json', { base: 'out-build' }),
33
vfs.src('out-build/nls.messages.json', { base: 'out-build' }))
34
.pipe(merge({
35
fileName: 'vscode.json',
36
jsonSpace: '',
37
concatArrays: true,
38
edit: (parsedJson, file) => {
39
if (file.base === 'out-build') {
40
if (file.basename === 'nls.keys.json') {
41
return { keys: parsedJson };
42
} else {
43
return { messages: parsedJson };
44
}
45
}
46
}
47
})),
48
49
// extensions
50
vfs.src('.build/extensions/**/nls.metadata.json', { base: '.build/extensions' }),
51
vfs.src('.build/extensions/**/nls.metadata.header.json', { base: '.build/extensions' }),
52
vfs.src('.build/extensions/**/package.nls.json', { base: '.build/extensions' })
53
).pipe(merge({
54
fileName: 'combined.nls.metadata.json',
55
jsonSpace: '',
56
concatArrays: true,
57
edit: (parsedJson, file) => {
58
if (file.basename === 'vscode.json') {
59
return { vscode: parsedJson };
60
}
61
62
// Handle extensions and follow the same structure as the Core nls file.
63
switch (file.basename) {
64
case 'package.nls.json':
65
// put package.nls.json content in Core NlsMetadata format
66
// language packs use the key "package" to specify that
67
// translations are for the package.json file
68
parsedJson = {
69
messages: {
70
package: Object.values(parsedJson)
71
},
72
keys: {
73
package: Object.keys(parsedJson)
74
},
75
bundles: {
76
main: ['package']
77
}
78
};
79
break;
80
81
case 'nls.metadata.header.json':
82
parsedJson = { header: parsedJson };
83
break;
84
85
case 'nls.metadata.json': {
86
// put nls.metadata.json content in Core NlsMetadata format
87
const modules = Object.keys(parsedJson);
88
89
const json: NlsMetadata = {
90
keys: {},
91
messages: {},
92
bundles: {
93
main: []
94
}
95
};
96
for (const module of modules) {
97
json.messages[module] = parsedJson[module].messages;
98
json.keys[module] = parsedJson[module].keys;
99
json.bundles.main.push(module);
100
}
101
parsedJson = json;
102
break;
103
}
104
}
105
106
// Get extension id and use that as the key
107
const folderPath = path.join(file.base, file.relative.split('/')[0]);
108
const manifest = readFileSync(path.join(folderPath, 'package.json'), 'utf-8');
109
const manifestJson = JSON.parse(manifest);
110
const key = manifestJson.publisher + '.' + manifestJson.name;
111
return { [key]: parsedJson };
112
},
113
}));
114
115
const nlsMessagesJs = vfs.src('out-build/nls.messages.js', { base: 'out-build' });
116
117
es.merge(combinedMetadataJson, nlsMessagesJs)
118
.pipe(gzip({ append: false }))
119
.pipe(vfs.dest('./nlsMetadata'))
120
.pipe(es.through(function (data: Vinyl) {
121
console.log(`Uploading ${data.path}`);
122
// trigger artifact upload
123
console.log(`##vso[artifact.upload containerfolder=nlsmetadata;artifactname=${data.basename}]${data.path}`);
124
this.emit('data', data);
125
}))
126
.pipe(azure.upload({
127
account: process.env.AZURE_STORAGE_ACCOUNT,
128
credential,
129
container: '$web',
130
prefix: `nlsmetadata/${commit}/`,
131
contentSettings: {
132
contentEncoding: 'gzip',
133
cacheControl: 'max-age=31536000, public'
134
}
135
}))
136
.on('end', () => c())
137
.on('error', (err: any) => e(err));
138
});
139
}
140
141
main().catch(err => {
142
console.error(err);
143
process.exit(1);
144
});
145
146