line endings.

This commit is contained in:
isidor
2015-11-23 20:28:42 +01:00
parent 958bdd6ad2
commit 28e29d7977
8 changed files with 876 additions and 824 deletions

View File

@@ -1,253 +1,253 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var path = require('path');
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var filter = require('gulp-filter');
var minifyCSS = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var es = require('event-stream');
var concat = require('gulp-concat');
var File = require('vinyl');
var underscore = require('underscore');
var bundle = require('./lib/bundle');
var util = require('./lib/util');
var tsOptions = {
target: 'ES5',
module: 'amd',
verbose: true,
preserveConstEnums: true,
experimentalDecorators: true,
sourceMap: true,
rootDir: path.join(path.dirname(__dirname), 'src')
};
exports.loaderConfig = function (emptyPaths) {
var result = {
paths: {
'vs': 'out-build/vs',
'vs/extensions': 'extensions',
'vscode': 'empty:',
'lib': 'out-build/lib'
},
'vs/text': {
paths: {
'vs/extensions': 'extensions'
}
}
};
(emptyPaths || []).forEach(function(m) { result.paths[m] = 'empty:'; });
return result;
};
var IS_OUR_COPYRIGHT_REGEXP = /Copyright \(C\) Microsoft Corporation/i;
function loader(bundledFileHeader) {
var isFirst = true;
return gulp.src([
'out-build/vs/loader.js',
'out-build/vs/css.js',
'out-build/vs/nls.js',
'out-build/vs/text.js'
], { base: 'out-build' })
.pipe(es.through(function(data) {
if (isFirst) {
isFirst = false;
this.emit('data', new File({
path: 'fake',
base: '',
contents: new Buffer(bundledFileHeader)
}));
this.emit('data', data);
} else {
this.emit('data', data);
}
}))
.pipe(util.loadSourcemaps())
.pipe(concat('vs/loader.js'))
.pipe(es.mapSync(function (f) {
f.sourceMap.sourceRoot = util.toFileUri(tsOptions.rootDir);
return f;
}));
}
function toConcatStream(bundledFileHeader, sources, dest) {
var useSourcemaps = /\.js$/.test(dest) && !/\.nls\.js$/.test(dest);
// If a bundle ends up including in any of the sources our copyright, then
// insert a fake source at the beginning of each bundle with our copyright
var containsOurCopyright = false;
for (var i = 0, len = sources.length; i < len; i++) {
var fileContents = sources[i].contents;
if (IS_OUR_COPYRIGHT_REGEXP.test(fileContents)) {
containsOurCopyright = true;
break;
}
}
if (containsOurCopyright) {
sources.unshift({
path: null,
contents: bundledFileHeader
});
}
var treatedSources = sources.map(function(source) {
var root = source.path ? path.dirname(__dirname).replace(/\\/g, '/') : '';
var base = source.path ? root + '/out-build' : '';
return new File({
path: source.path ? root + '/' + source.path.replace(/\\/g, '/') : 'fake',
base: base,
contents: new Buffer(source.contents)
});
});
return es.readArray(treatedSources)
.pipe(useSourcemaps ? util.loadSourcemaps() : es.through())
.pipe(concat(dest));
}
function toBundleStream(bundledFileHeader, bundles) {
return es.merge(bundles.map(function(bundle) {
return toConcatStream(bundledFileHeader, bundle.sources, bundle.dest);
}));
}
/**
* opts:
* - entryPoints (for AMD files, will get bundled and get Copyright treatment)
* - otherSources (for non-AMD files that should get Copyright treatment)
* - resources (svg, etc.)
* - loaderConfig
* - header (basically the Copyright treatment)
* - out (out folder name)
*/
exports.optimizeTask = function(opts) {
var entryPoints = opts.entryPoints;
var otherSources = opts.otherSources;
var resources = opts.resources;
var loaderConfig = opts.loaderConfig;
var bundledFileHeader = opts.header;
var out = opts.out;
return function() {
var bundlesStream = es.through();
bundle.bundle(entryPoints, loaderConfig, function(err, result) {
if (err) { return bundlesStream.emit('error', JSON.stringify(err)); }
toBundleStream(bundledFileHeader, result).pipe(bundlesStream);
});
var otherSourcesStream = es.through();
var otherSourcesStreamArr = [];
gulp.src(otherSources, { base: 'out-build' })
.pipe(es.through(function (data) {
otherSourcesStreamArr.push(toConcatStream(bundledFileHeader, [data], data.relative));
}, function () {
if (!otherSourcesStreamArr.length) {
setTimeout(function () { otherSourcesStream.emit('end'); }, 0);
} else {
es.merge(otherSourcesStreamArr).pipe(otherSourcesStream);
}
}));
var result = es.merge(
loader(bundledFileHeader),
bundlesStream,
otherSourcesStream,
gulp.src(resources, { base: 'out-build' })
);
return result
.pipe(sourcemaps.write('./', {
sourceRoot: null,
addComment: true,
includeContent: true
}))
.pipe(gulp.dest(out));
};
};
/**
* wrap around uglify and allow the preserveComments function
* to have a file "context" to include our copyright only once per file
*/
function uglifyWithCopyrights() {
var currentFileHasOurCopyright = false;
var onNewFile = function() {
currentFileHasOurCopyright = false;
};
var preserveComments = function(node, comment) {
var text = comment.value;
var type = comment.type;
if (/@minifier_do_not_preserve/.test(text)) {
return false;
}
var isOurCopyright = IS_OUR_COPYRIGHT_REGEXP.test(text);
if (isOurCopyright) {
if (currentFileHasOurCopyright) {
return false;
}
currentFileHasOurCopyright = true;
return true;
}
if ('comment2' === type) {
// check for /*!. Note that text doesn't contain leading /*
return (text.length > 0 && text[0] === '!') || /@preserve|license|@cc_on|copyright/i.test(text);
} else if ('comment1' === type) {
return /license|copyright/i.test(text);
}
return false;
};
var uglifyStream = uglify({ preserveComments: preserveComments });
return es.through(function write(data) {
var _this = this;
onNewFile();
uglifyStream.once('data', function(data) {
_this.emit('data', data);
})
uglifyStream.write(data);
}, function end() {
this.emit('end')
});
}
exports.minifyTask = function (src, addSourceMapsComment) {
return function() {
var jsFilter = filter('**/*.js', { restore: true });
var cssFilter = filter('**/*.css', { restore: true });
return gulp.src([src + '/**', '!' + src + '/**/*.map'])
.pipe(jsFilter)
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglifyWithCopyrights())
.pipe(jsFilter.restore)
.pipe(cssFilter)
.pipe(minifyCSS())
.pipe(cssFilter.restore)
.pipe(sourcemaps.write('./', {
sourceRoot: null,
includeContent: true,
addComment: addSourceMapsComment
}))
.pipe(gulp.dest(src + '-min'));
};
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var path = require('path');
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var filter = require('gulp-filter');
var minifyCSS = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var es = require('event-stream');
var concat = require('gulp-concat');
var File = require('vinyl');
var underscore = require('underscore');
var bundle = require('./lib/bundle');
var util = require('./lib/util');
var tsOptions = {
target: 'ES5',
module: 'amd',
verbose: true,
preserveConstEnums: true,
experimentalDecorators: true,
sourceMap: true,
rootDir: path.join(path.dirname(__dirname), 'src')
};
exports.loaderConfig = function (emptyPaths) {
var result = {
paths: {
'vs': 'out-build/vs',
'vs/extensions': 'extensions',
'vscode': 'empty:',
'lib': 'out-build/lib'
},
'vs/text': {
paths: {
'vs/extensions': 'extensions'
}
}
};
(emptyPaths || []).forEach(function(m) { result.paths[m] = 'empty:'; });
return result;
};
var IS_OUR_COPYRIGHT_REGEXP = /Copyright \(C\) Microsoft Corporation/i;
function loader(bundledFileHeader) {
var isFirst = true;
return gulp.src([
'out-build/vs/loader.js',
'out-build/vs/css.js',
'out-build/vs/nls.js',
'out-build/vs/text.js'
], { base: 'out-build' })
.pipe(es.through(function(data) {
if (isFirst) {
isFirst = false;
this.emit('data', new File({
path: 'fake',
base: '',
contents: new Buffer(bundledFileHeader)
}));
this.emit('data', data);
} else {
this.emit('data', data);
}
}))
.pipe(util.loadSourcemaps())
.pipe(concat('vs/loader.js'))
.pipe(es.mapSync(function (f) {
f.sourceMap.sourceRoot = util.toFileUri(tsOptions.rootDir);
return f;
}));
}
function toConcatStream(bundledFileHeader, sources, dest) {
var useSourcemaps = /\.js$/.test(dest) && !/\.nls\.js$/.test(dest);
// If a bundle ends up including in any of the sources our copyright, then
// insert a fake source at the beginning of each bundle with our copyright
var containsOurCopyright = false;
for (var i = 0, len = sources.length; i < len; i++) {
var fileContents = sources[i].contents;
if (IS_OUR_COPYRIGHT_REGEXP.test(fileContents)) {
containsOurCopyright = true;
break;
}
}
if (containsOurCopyright) {
sources.unshift({
path: null,
contents: bundledFileHeader
});
}
var treatedSources = sources.map(function(source) {
var root = source.path ? path.dirname(__dirname).replace(/\\/g, '/') : '';
var base = source.path ? root + '/out-build' : '';
return new File({
path: source.path ? root + '/' + source.path.replace(/\\/g, '/') : 'fake',
base: base,
contents: new Buffer(source.contents)
});
});
return es.readArray(treatedSources)
.pipe(useSourcemaps ? util.loadSourcemaps() : es.through())
.pipe(concat(dest));
}
function toBundleStream(bundledFileHeader, bundles) {
return es.merge(bundles.map(function(bundle) {
return toConcatStream(bundledFileHeader, bundle.sources, bundle.dest);
}));
}
/**
* opts:
* - entryPoints (for AMD files, will get bundled and get Copyright treatment)
* - otherSources (for non-AMD files that should get Copyright treatment)
* - resources (svg, etc.)
* - loaderConfig
* - header (basically the Copyright treatment)
* - out (out folder name)
*/
exports.optimizeTask = function(opts) {
var entryPoints = opts.entryPoints;
var otherSources = opts.otherSources;
var resources = opts.resources;
var loaderConfig = opts.loaderConfig;
var bundledFileHeader = opts.header;
var out = opts.out;
return function() {
var bundlesStream = es.through();
bundle.bundle(entryPoints, loaderConfig, function(err, result) {
if (err) { return bundlesStream.emit('error', JSON.stringify(err)); }
toBundleStream(bundledFileHeader, result).pipe(bundlesStream);
});
var otherSourcesStream = es.through();
var otherSourcesStreamArr = [];
gulp.src(otherSources, { base: 'out-build' })
.pipe(es.through(function (data) {
otherSourcesStreamArr.push(toConcatStream(bundledFileHeader, [data], data.relative));
}, function () {
if (!otherSourcesStreamArr.length) {
setTimeout(function () { otherSourcesStream.emit('end'); }, 0);
} else {
es.merge(otherSourcesStreamArr).pipe(otherSourcesStream);
}
}));
var result = es.merge(
loader(bundledFileHeader),
bundlesStream,
otherSourcesStream,
gulp.src(resources, { base: 'out-build' })
);
return result
.pipe(sourcemaps.write('./', {
sourceRoot: null,
addComment: true,
includeContent: true
}))
.pipe(gulp.dest(out));
};
};
/**
* wrap around uglify and allow the preserveComments function
* to have a file "context" to include our copyright only once per file
*/
function uglifyWithCopyrights() {
var currentFileHasOurCopyright = false;
var onNewFile = function() {
currentFileHasOurCopyright = false;
};
var preserveComments = function(node, comment) {
var text = comment.value;
var type = comment.type;
if (/@minifier_do_not_preserve/.test(text)) {
return false;
}
var isOurCopyright = IS_OUR_COPYRIGHT_REGEXP.test(text);
if (isOurCopyright) {
if (currentFileHasOurCopyright) {
return false;
}
currentFileHasOurCopyright = true;
return true;
}
if ('comment2' === type) {
// check for /*!. Note that text doesn't contain leading /*
return (text.length > 0 && text[0] === '!') || /@preserve|license|@cc_on|copyright/i.test(text);
} else if ('comment1' === type) {
return /license|copyright/i.test(text);
}
return false;
};
var uglifyStream = uglify({ preserveComments: preserveComments });
return es.through(function write(data) {
var _this = this;
onNewFile();
uglifyStream.once('data', function(data) {
_this.emit('data', data);
})
uglifyStream.write(data);
}, function end() {
this.emit('end')
});
}
exports.minifyTask = function (src, addSourceMapsComment) {
return function() {
var jsFilter = filter('**/*.js', { restore: true });
var cssFilter = filter('**/*.css', { restore: true });
return gulp.src([src + '/**', '!' + src + '/**/*.map'])
.pipe(jsFilter)
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglifyWithCopyrights())
.pipe(jsFilter.restore)
.pipe(cssFilter)
.pipe(minifyCSS())
.pipe(cssFilter.restore)
.pipe(sourcemaps.write('./', {
sourceRoot: null,
includeContent: true,
addComment: addSourceMapsComment
}))
.pipe(gulp.dest(src + '-min'));
};
};

View File

@@ -1,107 +1,107 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var gulp = require('gulp');
var path = require('path');
var rename = require('gulp-rename');
var filter = require('gulp-filter');
var _ = require('underscore');
var es = require('event-stream');
var buildfile = require('../src/buildfile');
var util = require('./lib/util');
var common = require('./gulpfile.common');
var root = path.dirname(__dirname);
var commit = process.env['BUILD_SOURCEVERSION'] || require('./lib/git').getVersion(root);
// Build
var editorEntryPoints = _.flatten([
buildfile.entrypoint('vs/editor/editor.main'),
buildfile.base,
buildfile.standaloneLanguages,
buildfile.editor,
buildfile.languages
]);
var editorResources = [
'out-build/vs/{base,editor}/**/*.{svg,png}',
'out-build/vs/base/worker/workerMainCompatibility.html',
'out-build/vs/base/worker/workerMain.{js,js.map}',
'out-build/vs/languages/typescript/common/lib/lib.{d.ts,es6.d.ts}',
'!out-build/vs/workbench/**',
'!**/test/**'
];
var editorOtherSources = [
'out-build/vs/css.js',
'out-build/vs/nls.js',
'out-build/vs/text.js',
'out-build/vs/editor/css/*.css'
];
var BUNDLED_FILE_HEADER = [
'/*!-----------------------------------------------------------',
' * Copyright (C) Microsoft Corporation. All rights reserved.',
' * Version: ' + commit,
' * Released under the MIT license',
' * https://github.com/Microsoft/vscode/blob/master/LICENSE.txt',
' *-----------------------------------------------------------*/',
''
].join('\n');
function editorLoaderConfig(removeAllOSS) {
var result = common.loaderConfig();
// never ship marked in editor
result.paths['vs/languages/markdown/common/marked'] = 'out-build/vs/languages/markdown/common/marked.mock';
if (removeAllOSS) {
result.paths['vs/languages/lib/common/beautify-html'] = 'out-build/vs/languages/lib/common/beautify-html.mock';
}
return result;
}
gulp.task('clean-optimized-editor', util.rimraf('out-editor'));
gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-build'], common.optimizeTask({
entryPoints: editorEntryPoints,
otherSources: editorOtherSources,
resources: editorResources,
loaderConfig: editorLoaderConfig(false),
header: BUNDLED_FILE_HEADER,
out: 'out-editor'
}));
gulp.task('clean-minified-editor', util.rimraf('out-editor-min'));
gulp.task('minify-editor', ['clean-minified-editor', 'optimize-editor'], common.minifyTask('out-editor', true));
// Package
var root = path.dirname(__dirname);
function copyTask(src, dest, FILTER) {
return function () {
return (
gulp.src(src + '/**', { base: src })
.pipe(FILTER ? filter(FILTER) : es.through())
.pipe(gulp.dest(dest))
);
};
}
var DISTRO_DEV_FOLDER_PATH = path.join(path.dirname(root), 'Monaco-Editor');
gulp.task('clean-editor-distro-dev', util.rimraf(DISTRO_DEV_FOLDER_PATH));
gulp.task('editor-distro-dev', ['clean-editor-distro-dev', 'optimize-editor'], copyTask('out-editor', DISTRO_DEV_FOLDER_PATH));
var DISTRO_MIN_FOLDER_PATH = path.join(path.dirname(root), 'Monaco-Editor-Min');
gulp.task('clean-editor-distro-min', util.rimraf(DISTRO_MIN_FOLDER_PATH));
gulp.task('editor-distro-min', ['clean-editor-distro-min', 'minify-editor'], copyTask('out-editor-min', DISTRO_MIN_FOLDER_PATH, ['**', '!**/*.js.map', '!nls.metadata.json']));
var DISTRO_MIN_SOURCEMAPS_FOLDER_PATH = path.join(path.dirname(root), 'Monaco-Editor-Min-SourceMaps');
gulp.task('clean-editor-distro-min-sourcemaps', util.rimraf(DISTRO_MIN_SOURCEMAPS_FOLDER_PATH));
gulp.task('editor-distro-min-sourcemaps', ['clean-editor-distro-min-sourcemaps', 'minify-editor'], copyTask('out-editor-min', DISTRO_MIN_SOURCEMAPS_FOLDER_PATH, ['**/*.js.map']));
gulp.task('editor-distro', ['editor-distro-min', 'editor-distro-min-sourcemaps', 'editor-distro-dev']);
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var gulp = require('gulp');
var path = require('path');
var rename = require('gulp-rename');
var filter = require('gulp-filter');
var _ = require('underscore');
var es = require('event-stream');
var buildfile = require('../src/buildfile');
var util = require('./lib/util');
var common = require('./gulpfile.common');
var root = path.dirname(__dirname);
var commit = process.env['BUILD_SOURCEVERSION'] || require('./lib/git').getVersion(root);
// Build
var editorEntryPoints = _.flatten([
buildfile.entrypoint('vs/editor/editor.main'),
buildfile.base,
buildfile.standaloneLanguages,
buildfile.editor,
buildfile.languages
]);
var editorResources = [
'out-build/vs/{base,editor}/**/*.{svg,png}',
'out-build/vs/base/worker/workerMainCompatibility.html',
'out-build/vs/base/worker/workerMain.{js,js.map}',
'out-build/vs/languages/typescript/common/lib/lib.{d.ts,es6.d.ts}',
'!out-build/vs/workbench/**',
'!**/test/**'
];
var editorOtherSources = [
'out-build/vs/css.js',
'out-build/vs/nls.js',
'out-build/vs/text.js',
'out-build/vs/editor/css/*.css'
];
var BUNDLED_FILE_HEADER = [
'/*!-----------------------------------------------------------',
' * Copyright (C) Microsoft Corporation. All rights reserved.',
' * Version: ' + commit,
' * Released under the MIT license',
' * https://github.com/Microsoft/vscode/blob/master/LICENSE.txt',
' *-----------------------------------------------------------*/',
''
].join('\n');
function editorLoaderConfig(removeAllOSS) {
var result = common.loaderConfig();
// never ship marked in editor
result.paths['vs/languages/markdown/common/marked'] = 'out-build/vs/languages/markdown/common/marked.mock';
if (removeAllOSS) {
result.paths['vs/languages/lib/common/beautify-html'] = 'out-build/vs/languages/lib/common/beautify-html.mock';
}
return result;
}
gulp.task('clean-optimized-editor', util.rimraf('out-editor'));
gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-build'], common.optimizeTask({
entryPoints: editorEntryPoints,
otherSources: editorOtherSources,
resources: editorResources,
loaderConfig: editorLoaderConfig(false),
header: BUNDLED_FILE_HEADER,
out: 'out-editor'
}));
gulp.task('clean-minified-editor', util.rimraf('out-editor-min'));
gulp.task('minify-editor', ['clean-minified-editor', 'optimize-editor'], common.minifyTask('out-editor', true));
// Package
var root = path.dirname(__dirname);
function copyTask(src, dest, FILTER) {
return function () {
return (
gulp.src(src + '/**', { base: src })
.pipe(FILTER ? filter(FILTER) : es.through())
.pipe(gulp.dest(dest))
);
};
}
var DISTRO_DEV_FOLDER_PATH = path.join(path.dirname(root), 'Monaco-Editor');
gulp.task('clean-editor-distro-dev', util.rimraf(DISTRO_DEV_FOLDER_PATH));
gulp.task('editor-distro-dev', ['clean-editor-distro-dev', 'optimize-editor'], copyTask('out-editor', DISTRO_DEV_FOLDER_PATH));
var DISTRO_MIN_FOLDER_PATH = path.join(path.dirname(root), 'Monaco-Editor-Min');
gulp.task('clean-editor-distro-min', util.rimraf(DISTRO_MIN_FOLDER_PATH));
gulp.task('editor-distro-min', ['clean-editor-distro-min', 'minify-editor'], copyTask('out-editor-min', DISTRO_MIN_FOLDER_PATH, ['**', '!**/*.js.map', '!nls.metadata.json']));
var DISTRO_MIN_SOURCEMAPS_FOLDER_PATH = path.join(path.dirname(root), 'Monaco-Editor-Min-SourceMaps');
gulp.task('clean-editor-distro-min-sourcemaps', util.rimraf(DISTRO_MIN_SOURCEMAPS_FOLDER_PATH));
gulp.task('editor-distro-min-sourcemaps', ['clean-editor-distro-min-sourcemaps', 'minify-editor'], copyTask('out-editor-min', DISTRO_MIN_SOURCEMAPS_FOLDER_PATH, ['**/*.js.map']));
gulp.task('editor-distro', ['editor-distro-min', 'editor-distro-min-sourcemaps', 'editor-distro-dev']);

View File

@@ -1,258 +1,258 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/*global process,__dirname, Buffer*/
var gulp = require('gulp');
var fs = require('fs');
var path = require('path');
var es = require('event-stream');
var azure = require('gulp-azure-storage');
var electron = require('gulp-atom-electron');
var symdest = require('gulp-symdest');
var rename = require('gulp-rename');
var filter = require('gulp-filter');
var json = require('gulp-json-editor');
var insert = require('gulp-insert');
var remote = require('gulp-remote-src');
var File = require('vinyl');
var rimraf = require('rimraf');
var _ = require('underscore');
var packagejson = require('../package.json');
var util = require('./lib/util');
var buildfile = require('../src/buildfile');
var common = require('./gulpfile.common');
var root = path.dirname(__dirname);
var commit = process.env['BUILD_SOURCEVERSION'] || require('./lib/git').getVersion(root);
var baseModules = [
'app', 'applicationinsights', 'assert', 'auto-updater', 'browser-window',
'child_process', 'chokidar', 'crash-reporter', 'crypto', 'dialog', 'emmet',
'events', 'fs', 'getmac', 'glob', 'graceful-fs', 'http', 'http-proxy-agent',
'https', 'https-proxy-agent', 'iconv-lite', 'ipc', 'menu', 'menu-item', 'net',
'original-fs', 'os', 'path', 'readline', 'remote', 'sax', 'screen', 'semver',
'shell', 'stream', 'string_decoder', 'url', 'vscode-textmate', 'web-frame', 'winreg',
'yauzl'
];
// Build
var vscodeEntryPoints = _.flatten([
buildfile.entrypoint('vs/workbench/workbench.main'),
buildfile.base,
buildfile.editor,
buildfile.languages,
buildfile.vscode
]);
var vscodeResources = [
'out-build/bootstrap.js',
'out-build/vs/**/*.{svg,png,cur}',
'out-build/vs/base/node/{stdForkStart.js,terminateProcess.sh}',
'out-build/vs/base/worker/workerMainCompatibility.html',
'out-build/vs/base/worker/workerMain.{js,js.map}',
'out-build/vs/editor/css/*.css',
'out-build/vs/languages/typescript/common/lib/lib.{d.ts,es6.d.ts}',
'out-build/vs/languages/markdown/common/*.css',
'out-build/vs/workbench/browser/media/*-theme.css',
'out-build/vs/workbench/browser/media/octicons/**',
'out-build/vs/workbench/electron-browser/index.html',
'out-build/vs/workbench/electron-main/bootstrap.js',
'out-build/vs/workbench/parts/debug/**/*.json',
'out-build/vs/workbench/parts/execution/**/*.scpt',
'out-build/vs/workbench/parts/git/**/*.html',
'out-build/vs/workbench/parts/git/**/*.sh',
'out-build/vs/workbench/parts/markdown/**/*.md',
'out-build/vs/workbench/parts/tasks/**/*.json',
'out-build/vs/workbench/services/files/**/*.exe',
'out-build/vs/workbench/services/files/**/*.md',
'!**/test/**'
];
var BUNDLED_FILE_HEADER = [
'/*!--------------------------------------------------------',
' * Copyright (C) Microsoft Corporation. All rights reserved.',
' *--------------------------------------------------------*/'
].join('\n');
gulp.task('clean-optimized-vscode', util.rimraf('out-vscode'));
gulp.task('optimize-vscode', ['clean-optimized-vscode', 'compile-build', 'compile-plugins'], common.optimizeTask({
entryPoints: vscodeEntryPoints,
otherSources: [],
resources: vscodeResources,
loaderConfig: common.loaderConfig(baseModules),
header: BUNDLED_FILE_HEADER,
out: 'out-vscode'
}));
gulp.task('clean-minified-vscode', util.rimraf('out-vscode-min'));
gulp.task('minify-vscode', ['clean-minified-vscode', 'optimize-vscode'], common.minifyTask('out-vscode', false));
// Package
var product = JSON.parse(fs.readFileSync(path.join(root, 'product.json'), 'utf8'));
var darwinCreditsTemplate = product.darwinCredits && _.template(fs.readFileSync(path.join(root, product.darwinCredits), 'utf8'));
var config = {
version: packagejson.electronVersion,
productAppName: product.nameLong,
companyName: product.companyName,
copyright: product.copyright,
darwinIcon: product.icons.application.icns,
darwinBundleIdentifier: product.darwinBundleIdentifier,
darwinApplicationCategoryType: product.darwinApplicationCategoryType, // Finder: View-->Arrange by Application Category
darwinBundleDocumentTypes: product.darwinBundleDocumentTypes,
darwinCredits: darwinCreditsTemplate ? new Buffer(darwinCreditsTemplate({ commit: commit, date: new Date().toISOString() })) : void 0,
winIcon: product.icons.application.ico,
win32ExeBasename: product.win32ExeBasename,
token: process.env['GITHUB_TOKEN'] || void 0
};
gulp.task('electron', function () {
// Force windows to use ia32
var arch = (process.platform === 'win32' ? 'ia32' : process.arch);
return electron.dest(path.join(path.dirname(root), 'Electron-Build'), _.extend({}, config, { arch: arch }));
});
function mixinProduct() {
var product;
var url = process.env['PRODUCT_JSON_URL'];
if (url) {
var opts = { base: '' };
var username = process.env['PRODUCT_JSON_USERNAME'];
var password = process.env['PRODUCT_JSON_PASSWORD'];
if (username || password) {
opts.auth = { username: username || '', password: password || '' };
}
product = remote(url, opts);
} else {
product = gulp.src(['product.json'], { base: '.' });
}
return product.pipe(json({
commit: commit,
date: new Date().toISOString()
}));
}
function packageTask(platform, arch, opts) {
opts = opts || {};
var destination = path.join(path.dirname(root), 'VSCode') + (platform ? '-' + platform : '') + (arch ? '-' + arch : '');
platform = platform || process.platform;
arch = platform === 'win32' ? 'ia32' : arch;
return function () {
var out = opts.minified ? 'out-vscode-min' : 'out-vscode';
var pluginHostFilter = filter(out + '/vs/workbench/node/pluginHostProcess.js', { restore: true });
var src = gulp.src(out + '/**', { base: '.' })
.pipe(pluginHostFilter)
.pipe(insert.append('\n//# sourceMappingURL=pluginHostProcess.js.map'))
.pipe(pluginHostFilter.restore)
.pipe(rename(function (path) { path.dirname = path.dirname.replace(new RegExp('^' + out), 'out'); }))
.pipe(util.setExecutableBit(['**/*.sh']));
var extensions = gulp.src([
'extensions/**',
'!extensions/*/src/**',
'!extensions/*/out/**/test/**',
'!extensions/typescript/bin/**',
'!extensions/csharp-o/node_modules/del/**',
'!extensions/csharp-o/node_modules/gulp/**',
'!extensions/csharp-o/node_modules/gulp-decompress/**',
'!extensions/csharp-o/node_modules/gulp-download/**',
'!extensions/csharp-o/node_modules/typescript/**'
], { base: '.' });
var pluginHostSourceMap = gulp.src(out + '/vs/workbench/node/pluginHostProcess.js.map', { base: '.' })
.pipe(rename(function (path) { path.dirname = path.dirname.replace(new RegExp('^' + out), 'out'); }));
var sources = es.merge(
es.merge(src, extensions).pipe(filter(['**', '!**/*.js.map'])),
pluginHostSourceMap
).pipe(util.handleAzureJson({ platform: platform }));
var packageJson = gulp.src(['package.json'], { base: '.' }).pipe(json({ name: product.nameShort }));
var license = gulp.src(['Credits_*', 'LICENSE.txt', 'ThirdPartyNotices.txt'], { base: '.' });
var api = gulp.src('src/vs/vscode.d.ts').pipe(rename('out/vs/vscode.d.ts'));
var depsSrc = _.flatten(Object.keys(packagejson.dependencies)
.map(function (d) { return ['node_modules/' + d + '/**', '!node_modules/' + d + '/**/{test,tests}/**']; }));
var deps = gulp.src(depsSrc, { base: '.', dot: true })
.pipe(util.cleanNodeModule('fsevents', ['binding.gyp', 'fsevents.cc', 'build/**', 'src/**', 'test/**'], true))
.pipe(util.cleanNodeModule('oniguruma', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], true));
var resources = gulp.src('resources/*', { base: '.' });
if (platform === 'win32') {
resources = es.merge(resources, gulp.src(product.icons.file.ico, { base: '.' }));
} else if (platform === 'linux') {
resources = es.merge(resources, gulp.src(product.icons.application.png, { base: '.' }));
}
var all = es.merge(
api,
packageJson,
mixinProduct(),
license,
sources,
deps,
resources
).pipe(util.skipDirectories());
var result = all
.pipe(util.fixWin32DirectoryPermissions())
.pipe(electron(_.extend({}, config, { platform: platform, arch: arch })))
.pipe(filter(['**', '!LICENSE', '!version']));
if (platform === 'win32') {
result = es.merge(result, gulp.src('resources/win32/bin/**', { base: 'resources/win32' }));
}
return result.pipe(opts.zip ? electron.zfsdest(destination + '.zip') : symdest(destination));
};
}
gulp.task('clean-vscode-win32', util.rimraf(path.join(path.dirname(root), 'VSCode-win32')));
gulp.task('clean-vscode-darwin', util.rimraf(path.join(path.dirname(root), 'VSCode-darwin')));
gulp.task('clean-vscode-linux-ia32', util.rimraf(path.join(path.dirname(root), 'VSCode-linux-ia32')));
gulp.task('clean-vscode-linux-x64', util.rimraf(path.join(path.dirname(root), 'VSCode-linux-x64')));
gulp.task('vscode-win32', ['optimize-vscode', 'clean-vscode-win32'], packageTask('win32'));
gulp.task('vscode-darwin', ['optimize-vscode', 'clean-vscode-darwin'], packageTask('darwin'));
gulp.task('vscode-linux-ia32', ['optimize-vscode', 'clean-vscode-linux-ia32'], packageTask('linux', 'ia32'));
gulp.task('vscode-linux-x64', ['optimize-vscode', 'clean-vscode-linux-x64'], packageTask('linux', 'x64'));
gulp.task('vscode-win32-min', ['minify-vscode', 'clean-vscode-win32'], packageTask('win32', null, { minified: true }));
gulp.task('vscode-darwin-min', ['minify-vscode', 'clean-vscode-darwin'], packageTask('darwin', null, { minified: true }));
gulp.task('vscode-linux-ia32-min', ['minify-vscode', 'clean-vscode-linux-ia32'], packageTask('linux', 'ia32', { minified: true }));
gulp.task('vscode-linux-x64-min', ['minify-vscode', 'clean-vscode-linux-x64'], packageTask('linux', 'x64', { minified: true }));
gulp.task('vscode-win32-zip', ['optimize-vscode'], packageTask('win32', null, { zip: true }));
gulp.task('vscode-darwin-zip', ['optimize-vscode'], packageTask('darwin', null, { zip: true }));
gulp.task('vscode-linux-ia32-zip', ['optimize-vscode'], packageTask('linux', 'ia32', { zip: true }));
gulp.task('vscode-linux-x64-zip', ['optimize-vscode'], packageTask('linux', 'x64', { zip: true }));
gulp.task('vscode-win32-zip-min', ['minify-vscode'], packageTask('win32', null, { zip: true, minified: true }));
gulp.task('vscode-darwin-zip-min', ['minify-vscode'], packageTask('darwin', null, { zip: true, minified: true }));
gulp.task('vscode-linux-zip-ia32-min', ['minify-vscode'], packageTask('linux', 'ia32', { zip: true, minified: true }));
gulp.task('vscode-linux-zip-x64-min', ['minify-vscode'], packageTask('linux', 'x64', { zip: true, minified: true }));
// Sourcemaps
gulp.task('vscode-sourcemaps', ['minify-vscode'], function () {
return gulp.src('out-vscode-min/**/*.map')
.pipe(azure.upload({
account: process.env.AZURE_STORAGE_ACCOUNT,
key: process.env.AZURE_STORAGE_ACCESS_KEY,
container: 'sourcemaps',
prefix: commit + '/'
}));
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/*global process,__dirname, Buffer*/
var gulp = require('gulp');
var fs = require('fs');
var path = require('path');
var es = require('event-stream');
var azure = require('gulp-azure-storage');
var electron = require('gulp-atom-electron');
var symdest = require('gulp-symdest');
var rename = require('gulp-rename');
var filter = require('gulp-filter');
var json = require('gulp-json-editor');
var insert = require('gulp-insert');
var remote = require('gulp-remote-src');
var File = require('vinyl');
var rimraf = require('rimraf');
var _ = require('underscore');
var packagejson = require('../package.json');
var util = require('./lib/util');
var buildfile = require('../src/buildfile');
var common = require('./gulpfile.common');
var root = path.dirname(__dirname);
var commit = process.env['BUILD_SOURCEVERSION'] || require('./lib/git').getVersion(root);
var baseModules = [
'app', 'applicationinsights', 'assert', 'auto-updater', 'browser-window',
'child_process', 'chokidar', 'crash-reporter', 'crypto', 'dialog', 'emmet',
'events', 'fs', 'getmac', 'glob', 'graceful-fs', 'http', 'http-proxy-agent',
'https', 'https-proxy-agent', 'iconv-lite', 'ipc', 'menu', 'menu-item', 'net',
'original-fs', 'os', 'path', 'readline', 'remote', 'sax', 'screen', 'semver',
'shell', 'stream', 'string_decoder', 'url', 'vscode-textmate', 'web-frame', 'winreg',
'yauzl'
];
// Build
var vscodeEntryPoints = _.flatten([
buildfile.entrypoint('vs/workbench/workbench.main'),
buildfile.base,
buildfile.editor,
buildfile.languages,
buildfile.vscode
]);
var vscodeResources = [
'out-build/bootstrap.js',
'out-build/vs/**/*.{svg,png,cur}',
'out-build/vs/base/node/{stdForkStart.js,terminateProcess.sh}',
'out-build/vs/base/worker/workerMainCompatibility.html',
'out-build/vs/base/worker/workerMain.{js,js.map}',
'out-build/vs/editor/css/*.css',
'out-build/vs/languages/typescript/common/lib/lib.{d.ts,es6.d.ts}',
'out-build/vs/languages/markdown/common/*.css',
'out-build/vs/workbench/browser/media/*-theme.css',
'out-build/vs/workbench/browser/media/octicons/**',
'out-build/vs/workbench/electron-browser/index.html',
'out-build/vs/workbench/electron-main/bootstrap.js',
'out-build/vs/workbench/parts/debug/**/*.json',
'out-build/vs/workbench/parts/execution/**/*.scpt',
'out-build/vs/workbench/parts/git/**/*.html',
'out-build/vs/workbench/parts/git/**/*.sh',
'out-build/vs/workbench/parts/markdown/**/*.md',
'out-build/vs/workbench/parts/tasks/**/*.json',
'out-build/vs/workbench/services/files/**/*.exe',
'out-build/vs/workbench/services/files/**/*.md',
'!**/test/**'
];
var BUNDLED_FILE_HEADER = [
'/*!--------------------------------------------------------',
' * Copyright (C) Microsoft Corporation. All rights reserved.',
' *--------------------------------------------------------*/'
].join('\n');
gulp.task('clean-optimized-vscode', util.rimraf('out-vscode'));
gulp.task('optimize-vscode', ['clean-optimized-vscode', 'compile-build', 'compile-plugins'], common.optimizeTask({
entryPoints: vscodeEntryPoints,
otherSources: [],
resources: vscodeResources,
loaderConfig: common.loaderConfig(baseModules),
header: BUNDLED_FILE_HEADER,
out: 'out-vscode'
}));
gulp.task('clean-minified-vscode', util.rimraf('out-vscode-min'));
gulp.task('minify-vscode', ['clean-minified-vscode', 'optimize-vscode'], common.minifyTask('out-vscode', false));
// Package
var product = JSON.parse(fs.readFileSync(path.join(root, 'product.json'), 'utf8'));
var darwinCreditsTemplate = product.darwinCredits && _.template(fs.readFileSync(path.join(root, product.darwinCredits), 'utf8'));
var config = {
version: packagejson.electronVersion,
productAppName: product.nameLong,
companyName: product.companyName,
copyright: product.copyright,
darwinIcon: product.icons.application.icns,
darwinBundleIdentifier: product.darwinBundleIdentifier,
darwinApplicationCategoryType: product.darwinApplicationCategoryType, // Finder: View-->Arrange by Application Category
darwinBundleDocumentTypes: product.darwinBundleDocumentTypes,
darwinCredits: darwinCreditsTemplate ? new Buffer(darwinCreditsTemplate({ commit: commit, date: new Date().toISOString() })) : void 0,
winIcon: product.icons.application.ico,
win32ExeBasename: product.win32ExeBasename,
token: process.env['GITHUB_TOKEN'] || void 0
};
gulp.task('electron', function () {
// Force windows to use ia32
var arch = (process.platform === 'win32' ? 'ia32' : process.arch);
return electron.dest(path.join(path.dirname(root), 'Electron-Build'), _.extend({}, config, { arch: arch }));
});
function mixinProduct() {
var product;
var url = process.env['PRODUCT_JSON_URL'];
if (url) {
var opts = { base: '' };
var username = process.env['PRODUCT_JSON_USERNAME'];
var password = process.env['PRODUCT_JSON_PASSWORD'];
if (username || password) {
opts.auth = { username: username || '', password: password || '' };
}
product = remote(url, opts);
} else {
product = gulp.src(['product.json'], { base: '.' });
}
return product.pipe(json({
commit: commit,
date: new Date().toISOString()
}));
}
function packageTask(platform, arch, opts) {
opts = opts || {};
var destination = path.join(path.dirname(root), 'VSCode') + (platform ? '-' + platform : '') + (arch ? '-' + arch : '');
platform = platform || process.platform;
arch = platform === 'win32' ? 'ia32' : arch;
return function () {
var out = opts.minified ? 'out-vscode-min' : 'out-vscode';
var pluginHostFilter = filter(out + '/vs/workbench/node/pluginHostProcess.js', { restore: true });
var src = gulp.src(out + '/**', { base: '.' })
.pipe(pluginHostFilter)
.pipe(insert.append('\n//# sourceMappingURL=pluginHostProcess.js.map'))
.pipe(pluginHostFilter.restore)
.pipe(rename(function (path) { path.dirname = path.dirname.replace(new RegExp('^' + out), 'out'); }))
.pipe(util.setExecutableBit(['**/*.sh']));
var extensions = gulp.src([
'extensions/**',
'!extensions/*/src/**',
'!extensions/*/out/**/test/**',
'!extensions/typescript/bin/**',
'!extensions/csharp-o/node_modules/del/**',
'!extensions/csharp-o/node_modules/gulp/**',
'!extensions/csharp-o/node_modules/gulp-decompress/**',
'!extensions/csharp-o/node_modules/gulp-download/**',
'!extensions/csharp-o/node_modules/typescript/**'
], { base: '.' });
var pluginHostSourceMap = gulp.src(out + '/vs/workbench/node/pluginHostProcess.js.map', { base: '.' })
.pipe(rename(function (path) { path.dirname = path.dirname.replace(new RegExp('^' + out), 'out'); }));
var sources = es.merge(
es.merge(src, extensions).pipe(filter(['**', '!**/*.js.map'])),
pluginHostSourceMap
).pipe(util.handleAzureJson({ platform: platform }));
var packageJson = gulp.src(['package.json'], { base: '.' }).pipe(json({ name: product.nameShort }));
var license = gulp.src(['Credits_*', 'LICENSE.txt', 'ThirdPartyNotices.txt'], { base: '.' });
var api = gulp.src('src/vs/vscode.d.ts').pipe(rename('out/vs/vscode.d.ts'));
var depsSrc = _.flatten(Object.keys(packagejson.dependencies)
.map(function (d) { return ['node_modules/' + d + '/**', '!node_modules/' + d + '/**/{test,tests}/**']; }));
var deps = gulp.src(depsSrc, { base: '.', dot: true })
.pipe(util.cleanNodeModule('fsevents', ['binding.gyp', 'fsevents.cc', 'build/**', 'src/**', 'test/**'], true))
.pipe(util.cleanNodeModule('oniguruma', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], true));
var resources = gulp.src('resources/*', { base: '.' });
if (platform === 'win32') {
resources = es.merge(resources, gulp.src(product.icons.file.ico, { base: '.' }));
} else if (platform === 'linux') {
resources = es.merge(resources, gulp.src(product.icons.application.png, { base: '.' }));
}
var all = es.merge(
api,
packageJson,
mixinProduct(),
license,
sources,
deps,
resources
).pipe(util.skipDirectories());
var result = all
.pipe(util.fixWin32DirectoryPermissions())
.pipe(electron(_.extend({}, config, { platform: platform, arch: arch })))
.pipe(filter(['**', '!LICENSE', '!version']));
if (platform === 'win32') {
result = es.merge(result, gulp.src('resources/win32/bin/**', { base: 'resources/win32' }));
}
return result.pipe(opts.zip ? electron.zfsdest(destination + '.zip') : symdest(destination));
};
}
gulp.task('clean-vscode-win32', util.rimraf(path.join(path.dirname(root), 'VSCode-win32')));
gulp.task('clean-vscode-darwin', util.rimraf(path.join(path.dirname(root), 'VSCode-darwin')));
gulp.task('clean-vscode-linux-ia32', util.rimraf(path.join(path.dirname(root), 'VSCode-linux-ia32')));
gulp.task('clean-vscode-linux-x64', util.rimraf(path.join(path.dirname(root), 'VSCode-linux-x64')));
gulp.task('vscode-win32', ['optimize-vscode', 'clean-vscode-win32'], packageTask('win32'));
gulp.task('vscode-darwin', ['optimize-vscode', 'clean-vscode-darwin'], packageTask('darwin'));
gulp.task('vscode-linux-ia32', ['optimize-vscode', 'clean-vscode-linux-ia32'], packageTask('linux', 'ia32'));
gulp.task('vscode-linux-x64', ['optimize-vscode', 'clean-vscode-linux-x64'], packageTask('linux', 'x64'));
gulp.task('vscode-win32-min', ['minify-vscode', 'clean-vscode-win32'], packageTask('win32', null, { minified: true }));
gulp.task('vscode-darwin-min', ['minify-vscode', 'clean-vscode-darwin'], packageTask('darwin', null, { minified: true }));
gulp.task('vscode-linux-ia32-min', ['minify-vscode', 'clean-vscode-linux-ia32'], packageTask('linux', 'ia32', { minified: true }));
gulp.task('vscode-linux-x64-min', ['minify-vscode', 'clean-vscode-linux-x64'], packageTask('linux', 'x64', { minified: true }));
gulp.task('vscode-win32-zip', ['optimize-vscode'], packageTask('win32', null, { zip: true }));
gulp.task('vscode-darwin-zip', ['optimize-vscode'], packageTask('darwin', null, { zip: true }));
gulp.task('vscode-linux-ia32-zip', ['optimize-vscode'], packageTask('linux', 'ia32', { zip: true }));
gulp.task('vscode-linux-x64-zip', ['optimize-vscode'], packageTask('linux', 'x64', { zip: true }));
gulp.task('vscode-win32-zip-min', ['minify-vscode'], packageTask('win32', null, { zip: true, minified: true }));
gulp.task('vscode-darwin-zip-min', ['minify-vscode'], packageTask('darwin', null, { zip: true, minified: true }));
gulp.task('vscode-linux-zip-ia32-min', ['minify-vscode'], packageTask('linux', 'ia32', { zip: true, minified: true }));
gulp.task('vscode-linux-zip-x64-min', ['minify-vscode'], packageTask('linux', 'x64', { zip: true, minified: true }));
// Sourcemaps
gulp.task('vscode-sourcemaps', ['minify-vscode'], function () {
return gulp.src('out-vscode-min/**/*.map')
.pipe(azure.upload({
account: process.env.AZURE_STORAGE_ACCOUNT,
key: process.env.AZURE_STORAGE_ACCESS_KEY,
container: 'sourcemaps',
prefix: commit + '/'
}));
});

13
extensions/csharp-o/typings/mocha.d.ts vendored Normal file
View File

@@ -0,0 +1,13 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare function run(): void;
declare function suite(name: string, fn: (err?)=>void);
declare function test(name: string, fn: (done?: (err?)=>void)=>void);
declare function suiteSetup(fn: (done?: (err?)=>void)=>void);
declare function suiteTeardown(fn: (done?: (err?)=>void)=>void);
declare function setup(fn: (done?: (err?)=>void)=>void);
declare function teardown(fn: (done?: (err?)=>void)=>void);

13
extensions/php/typings/mocha.d.ts vendored Normal file
View File

@@ -0,0 +1,13 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare function run(): void;
declare function suite(name: string, fn: (err?)=>void);
declare function test(name: string, fn: (done?: (err?)=>void)=>void);
declare function suiteSetup(fn: (done?: (err?)=>void)=>void);
declare function suiteTeardown(fn: (done?: (err?)=>void)=>void);
declare function setup(fn: (done?: (err?)=>void)=>void);
declare function teardown(fn: (done?: (err?)=>void)=>void);

View File

@@ -0,0 +1,13 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare function run(): void;
declare function suite(name: string, fn: (err?)=>void);
declare function test(name: string, fn: (done?: (err?)=>void)=>void);
declare function suiteSetup(fn: (done?: (err?)=>void)=>void);
declare function suiteTeardown(fn: (done?: (err?)=>void)=>void);
declare function setup(fn: (done?: (err?)=>void)=>void);
declare function teardown(fn: (done?: (err?)=>void)=>void);

View File

@@ -0,0 +1,13 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare function run(): void;
declare function suite(name: string, fn: (err?)=>void);
declare function test(name: string, fn: (done?: (err?)=>void)=>void);
declare function suiteSetup(fn: (done?: (err?)=>void)=>void);
declare function suiteTeardown(fn: (done?: (err?)=>void)=>void);
declare function setup(fn: (done?: (err?)=>void)=>void);
declare function teardown(fn: (done?: (err?)=>void)=>void);

View File

@@ -1,209 +1,209 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import fs = require('fs');
import path = require('path');
import json = require('vs/base/common/json');
import objects = require('vs/base/common/objects');
import {EventProvider} from 'vs/base/common/eventProvider';
import {TPromise} from 'vs/base/common/winjs.base';
import {EventSource} from 'vs/base/common/eventSource';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
export interface ISettings {
settings: any;
settingsParseErrors?: string[];
keybindings: any
}
export class UserSettings {
private static CHANGE_BUFFER_DELAY = 300;
public globalSettings: ISettings;
private timeoutHandle: number;
private watcher: fs.FSWatcher;
private appSettingsPath: string;
private appKeybindingsPath: string;
private _onChange: EventSource<(settings: ISettings) => void>;
constructor(appSettingsPath: string, appKeybindingsPath: string) {
this.appSettingsPath = appSettingsPath;
this.appKeybindingsPath = appKeybindingsPath;
this._onChange = new EventSource<(settings: ISettings) => void>();
this.registerWatchers();
}
public static getValue(contextService: IWorkspaceContextService, key: string, fallback?: any): TPromise<any> {
return new TPromise((c, e) => {
const appSettingsPath = contextService.getConfiguration().env.appSettingsPath;
fs.readFile(appSettingsPath, (error /* ignore */, fileContents) => {
let root = Object.create(null);
let content = fileContents ? fileContents.toString() : '{}';
let contents = Object.create(null);
try {
contents = json.parse(content);
} catch (error) {
// ignore parse problem
}
for (let key in contents) {
UserSettings.setNode(root, key, contents[key]);
}
return c(UserSettings.doGetValue(root, key, fallback));
});
});
}
public get onChange(): EventProvider<(settings: ISettings) => void> {
return this._onChange.value;
}
public getValue(key: string, fallback?: any): any {
return UserSettings.doGetValue(this.globalSettings.settings, key, fallback);
}
private static doGetValue(globalSettings: any, key: string, fallback?: any): any {
if (!key) {
return fallback;
}
let value = globalSettings;
let parts = key.split('\.');
while (parts.length && value) {
let part = parts.shift();
value = value[part];
}
return typeof value !== 'undefined' ? value : fallback;
}
private registerWatchers(): void {
this.watcher = fs.watch(path.dirname(this.appSettingsPath));
this.watcher.on('change', (eventType: string, fileName: string) => this.onSettingsFileChange(eventType, fileName));
}
private onSettingsFileChange(eventType: string, fileName: string): void {
// we can get multiple change events for one change, so we buffer through a timeout
if (this.timeoutHandle) {
global.clearTimeout(this.timeoutHandle);
delete this.timeoutHandle;
}
this.timeoutHandle = global.setTimeout(() => {
// Reload
let didChange = this.loadSync();
// Emit event
if (didChange) {
this._onChange.fire(this.globalSettings);
}
}, UserSettings.CHANGE_BUFFER_DELAY);
}
public loadSync(): boolean {
let loadedSettings = this.doLoadSync();
if (!objects.equals(loadedSettings, this.globalSettings)) {
// Keep in class
this.globalSettings = loadedSettings;
return true; // changed value
}
return false; // no changed value
}
private doLoadSync(): ISettings {
let settings = this.doLoadSettingsSync();
return {
settings: settings.contents,
settingsParseErrors: settings.parseErrors,
keybindings: this.doLoadKeybindingsSync()
};
}
private doLoadSettingsSync(): { contents: any; parseErrors?: string[]; } {
let root = Object.create(null);
let content = '{}';
try {
content = fs.readFileSync(this.appSettingsPath).toString();
} catch (error) {
// ignore
}
let contents = Object.create(null);
try {
contents = json.parse(content);
} catch (error) {
// parse problem
return {
contents: Object.create(null),
parseErrors: [this.appSettingsPath]
};
}
for (let key in contents) {
UserSettings.setNode(root, key, contents[key]);
}
return {
contents: root
};
}
private static setNode(root: any, key: string, value: any): any {
let segments = key.split('.');
let last = segments.pop();
let curr = root;
segments.forEach((s) => {
let obj = curr[s];
switch (typeof obj) {
case 'undefined':
obj = curr[s] = {};
break;
case 'object':
break;
default:
console.log('Conflicting user settings: ' + key + ' at ' + s + ' with ' + JSON.stringify(obj));
}
curr = obj;
});
curr[last] = value;
}
private doLoadKeybindingsSync(): any {
try {
return json.parse(fs.readFileSync(this.appKeybindingsPath).toString());
} catch (error) {
// Ignore loading and parsing errors
}
return [];
}
public dispose(): void {
if (this.watcher) {
this.watcher.close();
this.watcher = null;
}
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import fs = require('fs');
import path = require('path');
import json = require('vs/base/common/json');
import objects = require('vs/base/common/objects');
import {EventProvider} from 'vs/base/common/eventProvider';
import {TPromise} from 'vs/base/common/winjs.base';
import {EventSource} from 'vs/base/common/eventSource';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
export interface ISettings {
settings: any;
settingsParseErrors?: string[];
keybindings: any
}
export class UserSettings {
private static CHANGE_BUFFER_DELAY = 300;
public globalSettings: ISettings;
private timeoutHandle: number;
private watcher: fs.FSWatcher;
private appSettingsPath: string;
private appKeybindingsPath: string;
private _onChange: EventSource<(settings: ISettings) => void>;
constructor(appSettingsPath: string, appKeybindingsPath: string) {
this.appSettingsPath = appSettingsPath;
this.appKeybindingsPath = appKeybindingsPath;
this._onChange = new EventSource<(settings: ISettings) => void>();
this.registerWatchers();
}
public static getValue(contextService: IWorkspaceContextService, key: string, fallback?: any): TPromise<any> {
return new TPromise((c, e) => {
const appSettingsPath = contextService.getConfiguration().env.appSettingsPath;
fs.readFile(appSettingsPath, (error /* ignore */, fileContents) => {
let root = Object.create(null);
let content = fileContents ? fileContents.toString() : '{}';
let contents = Object.create(null);
try {
contents = json.parse(content);
} catch (error) {
// ignore parse problem
}
for (let key in contents) {
UserSettings.setNode(root, key, contents[key]);
}
return c(UserSettings.doGetValue(root, key, fallback));
});
});
}
public get onChange(): EventProvider<(settings: ISettings) => void> {
return this._onChange.value;
}
public getValue(key: string, fallback?: any): any {
return UserSettings.doGetValue(this.globalSettings.settings, key, fallback);
}
private static doGetValue(globalSettings: any, key: string, fallback?: any): any {
if (!key) {
return fallback;
}
let value = globalSettings;
let parts = key.split('\.');
while (parts.length && value) {
let part = parts.shift();
value = value[part];
}
return typeof value !== 'undefined' ? value : fallback;
}
private registerWatchers(): void {
this.watcher = fs.watch(path.dirname(this.appSettingsPath));
this.watcher.on('change', (eventType: string, fileName: string) => this.onSettingsFileChange(eventType, fileName));
}
private onSettingsFileChange(eventType: string, fileName: string): void {
// we can get multiple change events for one change, so we buffer through a timeout
if (this.timeoutHandle) {
global.clearTimeout(this.timeoutHandle);
delete this.timeoutHandle;
}
this.timeoutHandle = global.setTimeout(() => {
// Reload
let didChange = this.loadSync();
// Emit event
if (didChange) {
this._onChange.fire(this.globalSettings);
}
}, UserSettings.CHANGE_BUFFER_DELAY);
}
public loadSync(): boolean {
let loadedSettings = this.doLoadSync();
if (!objects.equals(loadedSettings, this.globalSettings)) {
// Keep in class
this.globalSettings = loadedSettings;
return true; // changed value
}
return false; // no changed value
}
private doLoadSync(): ISettings {
let settings = this.doLoadSettingsSync();
return {
settings: settings.contents,
settingsParseErrors: settings.parseErrors,
keybindings: this.doLoadKeybindingsSync()
};
}
private doLoadSettingsSync(): { contents: any; parseErrors?: string[]; } {
let root = Object.create(null);
let content = '{}';
try {
content = fs.readFileSync(this.appSettingsPath).toString();
} catch (error) {
// ignore
}
let contents = Object.create(null);
try {
contents = json.parse(content);
} catch (error) {
// parse problem
return {
contents: Object.create(null),
parseErrors: [this.appSettingsPath]
};
}
for (let key in contents) {
UserSettings.setNode(root, key, contents[key]);
}
return {
contents: root
};
}
private static setNode(root: any, key: string, value: any): any {
let segments = key.split('.');
let last = segments.pop();
let curr = root;
segments.forEach((s) => {
let obj = curr[s];
switch (typeof obj) {
case 'undefined':
obj = curr[s] = {};
break;
case 'object':
break;
default:
console.log('Conflicting user settings: ' + key + ' at ' + s + ' with ' + JSON.stringify(obj));
}
curr = obj;
});
curr[last] = value;
}
private doLoadKeybindingsSync(): any {
try {
return json.parse(fs.readFileSync(this.appKeybindingsPath).toString());
} catch (error) {
// Ignore loading and parsing errors
}
return [];
}
public dispose(): void {
if (this.watcher) {
this.watcher.close();
this.watcher = null;
}
}
}