forked from microsoft/vscode-node-debug2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
197 lines (169 loc) · 6.15 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
const gulp = require('gulp');
const path = require('path');
const ts = require('gulp-typescript');
const log = require('gulp-util').log;
const typescript = require('typescript');
const sourcemaps = require('gulp-sourcemaps');
const tslint = require('gulp-tslint');
const runSequence = require('run-sequence');
const nls = require('vscode-nls-dev');
const cp = require('child_process');
const del = require('del');
const fs = require('fs');
const vsce = require('vsce');
const es = require('event-stream');
const minimist = require('minimist');
const translationProjectName = 'azuredatastudio-extensions';
const translationExtensionName = 'sqlops-debug';
const defaultLanguages = [
{ id: 'zh-tw', folderName: 'cht', transifexId: 'zh-hant' },
{ id: 'zh-cn', folderName: 'chs', transifexId: 'zh-hans' },
{ id: 'ja', folderName: 'jpn' },
{ id: 'ko', folderName: 'kor' },
{ id: 'de', folderName: 'deu' },
{ id: 'fr', folderName: 'fra' },
{ id: 'es', folderName: 'esn' },
{ id: 'ru', folderName: 'rus' },
{ id: 'it', folderName: 'ita' },
// These language-pack languages are included for VS but excluded from the vscode package
{ id: 'cs', folderName: 'csy' },
{ id: 'tr', folderName: 'trk' },
{ id: 'pt-br', folderName: 'ptb', transifexId: 'pt_BR' },
{ id: 'pl', folderName: 'plk' }
];
const watchedSources = [
'src/**/*',
'test/**/*'
];
const scripts = [
'src/terminateProcess.sh'
];
const lintSources = [
'src'
].map(function(tsFolder) { return tsFolder + '/**/*.ts'; });
const tsProject = ts.createProject('tsconfig.json', { typescript });
function doBuild(buildNls, failOnError) {
let gotError = false;
const tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.once('error', () => {
gotError = true;
});
return tsResult.js
.pipe(buildNls ? nls.rewriteLocalizeCalls() : es.through())
.pipe(buildNls ? nls.createAdditionalLanguageFiles(defaultLanguages, 'i18n', 'out') : es.through())
.pipe(buildNls ? nls.bundleMetaDataFiles('ms-vscode.node-debug2', 'out') : es.through())
.pipe(buildNls ? nls.bundleLanguageFiles() : es.through())
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: '..' })) // .. to compensate for TS returning paths from 'out'
.pipe(gulp.dest('out'))
.once('error', () => {
gotError = true;
})
.once('finish', () => {
if (failOnError && gotError) {
process.exit(1);
}
});
}
gulp.task('build', () => {
return runSequence('clean', '_build');
});
gulp.task('_build', ['copy-scripts'], () => {
return doBuild(true, true);
});
gulp.task('_dev-build', ['copy-scripts'], () => {
return doBuild(false, false);
});
gulp.task('copy-scripts', () => {
return gulp.src(scripts, { base: '.' })
.pipe(gulp.dest('out'));
});
gulp.task('watch', ['clean'], cb => {
log('Watching build sources...');
return runSequence('_dev-build', () => gulp.watch(watchedSources, ['_dev-build']));
});
gulp.task('default', ['build']);
gulp.task('tslint', function() {
return gulp.src(lintSources, { base: '.' })
.pipe(tslint({
formatter: "verbose"
}))
.pipe(tslint.report());
});
gulp.task('clean', function() {
return del(['out/**', 'package.nls.*.json', 'sqlops-debug-*.vsix']);
});
function verifyNotALinkedModule(modulePath) {
return new Promise((resolve, reject) => {
fs.lstat(modulePath, (err, stat) => {
if (stat.isSymbolicLink()) {
reject(new Error('Symbolic link found: ' + modulePath));
} else {
resolve();
}
});
});
}
function verifyNoLinkedModules() {
return new Promise((resolve, reject) => {
fs.readdir('./node_modules', (err, files) => {
Promise.all(files.map(file => {
const modulePath = path.join('.', 'node_modules', file);
return verifyNotALinkedModule(modulePath);
})).then(resolve, reject);
});
});
}
gulp.task('verify-no-linked-modules', cb => verifyNoLinkedModules().then(() => cb, cb));
gulp.task('vsce-publish', function () {
return vsce.publish();
});
gulp.task('vsce-package', function () {
const cliOptions = minimist(process.argv.slice(2));
const packageOptions = {
packagePath: cliOptions.packagePath
};
return vsce.createVSIX(packageOptions);
});
gulp.task('publish', function(callback) {
runSequence('build', 'add-i18n', 'vsce-publish', callback);
});
gulp.task('package', function(callback) {
runSequence('build', 'add-i18n', 'vsce-package', callback);
});
gulp.task('add-i18n', function () {
return gulp.src(['package.nls.json'])
.pipe(nls.createAdditionalLanguageFiles(defaultLanguages, 'i18n'))
.pipe(gulp.dest('.'));
});
gulp.task('translations-export', ['_build'], function() {
return gulp.src(['package.nls.json', 'out/nls.metadata.header.json', 'out/nls.metadata.json'])
.pipe(nls.createXlfFiles(translationProjectName, translationExtensionName))
.pipe(gulp.dest(path.join('..', 'vscode-translations-export')));
});
gulp.task('translations-import', function() {
var options = minimist(process.argv.slice(2), {
string: 'location',
default: {
location: '../vscode-translations-import'
}
});
return es.merge(defaultLanguages.map(function(language) {
let id = language.transifexId || language.id;
console.log(path.join(options.location, id, 'vscode-extensions', `${translationExtensionName}.xlf`));
return gulp.src(path.join(options.location, id, 'vscode-extensions', `${translationExtensionName}.xlf`))
.pipe(nls.prepareJsonFiles())
.pipe(gulp.dest(path.join('./i18n', language.folderName)));
}));
});
gulp.task('i18n-import', function() {
return es.merge(defaultLanguages.map(function(language) {
return gulp.src(`../${translationExtensionName}-localization/${language.folderName}/**/*.xlf`)
.pipe(nls.prepareJsonFiles())
.pipe(gulp.dest(path.join('./i18n', language.folderName)));
}));
});