Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/azure-pipelines/upload-cdn.js
3520 views
1
"use strict";
2
var __importDefault = (this && this.__importDefault) || function (mod) {
3
return (mod && mod.__esModule) ? mod : { "default": mod };
4
};
5
Object.defineProperty(exports, "__esModule", { value: true });
6
/*---------------------------------------------------------------------------------------------
7
* Copyright (c) Microsoft Corporation. All rights reserved.
8
* Licensed under the MIT License. See License.txt in the project root for license information.
9
*--------------------------------------------------------------------------------------------*/
10
const event_stream_1 = __importDefault(require("event-stream"));
11
const vinyl_1 = __importDefault(require("vinyl"));
12
const vinyl_fs_1 = __importDefault(require("vinyl-fs"));
13
const gulp_filter_1 = __importDefault(require("gulp-filter"));
14
const gulp_gzip_1 = __importDefault(require("gulp-gzip"));
15
const mime_1 = __importDefault(require("mime"));
16
const identity_1 = require("@azure/identity");
17
const azure = require('gulp-azure-storage');
18
const commit = process.env['BUILD_SOURCEVERSION'];
19
const credential = new identity_1.ClientAssertionCredential(process.env['AZURE_TENANT_ID'], process.env['AZURE_CLIENT_ID'], () => Promise.resolve(process.env['AZURE_ID_TOKEN']));
20
mime_1.default.define({
21
'application/typescript': ['ts'],
22
'application/json': ['code-snippets'],
23
});
24
// From default AFD configuration
25
const MimeTypesToCompress = new Set([
26
'application/eot',
27
'application/font',
28
'application/font-sfnt',
29
'application/javascript',
30
'application/json',
31
'application/opentype',
32
'application/otf',
33
'application/pkcs7-mime',
34
'application/truetype',
35
'application/ttf',
36
'application/typescript',
37
'application/vnd.ms-fontobject',
38
'application/xhtml+xml',
39
'application/xml',
40
'application/xml+rss',
41
'application/x-font-opentype',
42
'application/x-font-truetype',
43
'application/x-font-ttf',
44
'application/x-httpd-cgi',
45
'application/x-javascript',
46
'application/x-mpegurl',
47
'application/x-opentype',
48
'application/x-otf',
49
'application/x-perl',
50
'application/x-ttf',
51
'font/eot',
52
'font/ttf',
53
'font/otf',
54
'font/opentype',
55
'image/svg+xml',
56
'text/css',
57
'text/csv',
58
'text/html',
59
'text/javascript',
60
'text/js',
61
'text/markdown',
62
'text/plain',
63
'text/richtext',
64
'text/tab-separated-values',
65
'text/xml',
66
'text/x-script',
67
'text/x-component',
68
'text/x-java-source'
69
]);
70
function wait(stream) {
71
return new Promise((c, e) => {
72
stream.on('end', () => c());
73
stream.on('error', (err) => e(err));
74
});
75
}
76
async function main() {
77
const files = [];
78
const options = (compressed) => ({
79
account: process.env.AZURE_STORAGE_ACCOUNT,
80
credential,
81
container: '$web',
82
prefix: `${process.env.VSCODE_QUALITY}/${commit}/`,
83
contentSettings: {
84
contentEncoding: compressed ? 'gzip' : undefined,
85
cacheControl: 'max-age=31536000, public'
86
}
87
});
88
const all = vinyl_fs_1.default.src('**', { cwd: '../vscode-web', base: '../vscode-web', dot: true })
89
.pipe((0, gulp_filter_1.default)(f => !f.isDirectory()));
90
const compressed = all
91
.pipe((0, gulp_filter_1.default)(f => MimeTypesToCompress.has(mime_1.default.lookup(f.path))))
92
.pipe((0, gulp_gzip_1.default)({ append: false }))
93
.pipe(azure.upload(options(true)));
94
const uncompressed = all
95
.pipe((0, gulp_filter_1.default)(f => !MimeTypesToCompress.has(mime_1.default.lookup(f.path))))
96
.pipe(azure.upload(options(false)));
97
const out = event_stream_1.default.merge(compressed, uncompressed)
98
.pipe(event_stream_1.default.through(function (f) {
99
console.log('Uploaded:', f.relative);
100
files.push(f.relative);
101
this.emit('data', f);
102
}));
103
console.log(`Uploading files to CDN...`); // debug
104
await wait(out);
105
const listing = new vinyl_1.default({
106
path: 'files.txt',
107
contents: Buffer.from(files.join('\n')),
108
stat: { mode: 0o666 }
109
});
110
const filesOut = event_stream_1.default.readArray([listing])
111
.pipe((0, gulp_gzip_1.default)({ append: false }))
112
.pipe(azure.upload(options(true)));
113
console.log(`Uploading: files.txt (${files.length} files)`); // debug
114
await wait(filesOut);
115
}
116
main().catch(err => {
117
console.error(err);
118
process.exit(1);
119
});
120
//# sourceMappingURL=upload-cdn.js.map
121