mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
38
build/lib/watch/index.js
Normal file
38
build/lib/watch/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
const es = require('event-stream');
|
||||
|
||||
/** Ugly hack for gulp-tsb */
|
||||
function handleDeletions() {
|
||||
return es.mapSync(f => {
|
||||
if (/\.ts$/.test(f.relative) && !f.contents) {
|
||||
f.contents = new Buffer('');
|
||||
f.stat = { mtime: new Date() };
|
||||
}
|
||||
|
||||
return f;
|
||||
});
|
||||
}
|
||||
|
||||
let watch = void 0;
|
||||
|
||||
if (!process.env['VSCODE_USE_LEGACY_WATCH']) {
|
||||
try {
|
||||
watch = require('./watch-nsfw');
|
||||
} catch (err) {
|
||||
console.warn('Could not load our cross platform file watcher: ' + err.toString());
|
||||
console.warn('Falling back to our platform specific watcher...');
|
||||
}
|
||||
}
|
||||
|
||||
if (!watch) {
|
||||
watch = process.platform === 'win32' ? require('./watch-win32') : require('gulp-watch');
|
||||
}
|
||||
|
||||
module.exports = function () {
|
||||
return watch.apply(null, arguments)
|
||||
.pipe(handleDeletions());
|
||||
};
|
||||
11
build/lib/watch/package.json
Normal file
11
build/lib/watch/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "watch",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"author": "Microsoft ",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"gulp-watch": "^4.3.9",
|
||||
"nsfw": "^1.0.15"
|
||||
}
|
||||
}
|
||||
94
build/lib/watch/watch-nsfw.js
Normal file
94
build/lib/watch/watch-nsfw.js
Normal file
@@ -0,0 +1,94 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
var nsfw = require('nsfw');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var File = require('vinyl');
|
||||
var es = require('event-stream');
|
||||
var filter = require('gulp-filter');
|
||||
|
||||
function toChangeType(type) {
|
||||
switch (type) {
|
||||
case 0: return 'add';
|
||||
case 1: return 'unlink';
|
||||
case 2: return 'change';
|
||||
}
|
||||
}
|
||||
|
||||
function watch(root) {
|
||||
var result = es.through();
|
||||
|
||||
function handleEvent(path, type) {
|
||||
if (/[/\\].git[/\\]/.test(path) || /[/\\]out[/\\]/.test(path)) {
|
||||
return; // filter as early as possible
|
||||
}
|
||||
|
||||
var file = new File({
|
||||
path: path,
|
||||
base: root
|
||||
});
|
||||
|
||||
file.event = type;
|
||||
result.emit('data', file);
|
||||
}
|
||||
|
||||
nsfw(root, function(events) {
|
||||
for (var i = 0; i < events.length; i++) {
|
||||
var e = events[i];
|
||||
var changeType = e.action;
|
||||
|
||||
if (changeType === 3 /* RENAMED */) {
|
||||
handleEvent(path.join(e.directory, e.oldFile), 'unlink');
|
||||
handleEvent(path.join(e.directory, e.newFile), 'add');
|
||||
} else {
|
||||
handleEvent(path.join(e.directory, e.file), toChangeType(changeType));
|
||||
}
|
||||
}
|
||||
}).then(function(watcher) {
|
||||
watcher.start();
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
var cache = Object.create(null);
|
||||
|
||||
module.exports = function(pattern, options) {
|
||||
options = options || {};
|
||||
|
||||
var cwd = path.normalize(options.cwd || process.cwd());
|
||||
var watcher = cache[cwd];
|
||||
|
||||
if (!watcher) {
|
||||
watcher = cache[cwd] = watch(cwd);
|
||||
}
|
||||
|
||||
var rebase = !options.base ? es.through() : es.mapSync(function(f) {
|
||||
f.base = options.base;
|
||||
return f;
|
||||
});
|
||||
|
||||
return watcher
|
||||
.pipe(filter(['**', '!.git{,/**}'])) // ignore all things git
|
||||
.pipe(filter(pattern))
|
||||
.pipe(es.map(function(file, cb) {
|
||||
fs.stat(file.path, function(err, stat) {
|
||||
if (err && err.code === 'ENOENT') { return cb(null, file); }
|
||||
if (err) { return cb(); }
|
||||
if (!stat.isFile()) { return cb(); }
|
||||
|
||||
fs.readFile(file.path, function(err, contents) {
|
||||
if (err && err.code === 'ENOENT') { return cb(null, file); }
|
||||
if (err) { return cb(); }
|
||||
|
||||
file.contents = contents;
|
||||
file.stat = stat;
|
||||
cb(null, file);
|
||||
});
|
||||
});
|
||||
}))
|
||||
.pipe(rebase);
|
||||
};
|
||||
108
build/lib/watch/watch-win32.js
Normal file
108
build/lib/watch/watch-win32.js
Normal file
@@ -0,0 +1,108 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
var path = require('path');
|
||||
var cp = require('child_process');
|
||||
var fs = require('fs');
|
||||
var File = require('vinyl');
|
||||
var es = require('event-stream');
|
||||
var filter = require('gulp-filter');
|
||||
|
||||
var watcherPath = path.join(__dirname, 'watcher.exe');
|
||||
|
||||
function toChangeType(type) {
|
||||
switch (type) {
|
||||
case '0': return 'change';
|
||||
case '1': return 'add';
|
||||
default: return 'unlink';
|
||||
}
|
||||
}
|
||||
|
||||
function watch(root) {
|
||||
var result = es.through();
|
||||
var child = cp.spawn(watcherPath, [root]);
|
||||
|
||||
child.stdout.on('data', function(data) {
|
||||
var lines = data.toString('utf8').split('\n');
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var line = lines[i].trim();
|
||||
if (line.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var changeType = line[0];
|
||||
var changePath = line.substr(2);
|
||||
|
||||
// filter as early as possible
|
||||
if (/^\.git/.test(changePath) || /(^|\\)out($|\\)/.test(changePath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var changePathFull = path.join(root, changePath);
|
||||
|
||||
var file = new File({
|
||||
path: changePathFull,
|
||||
base: root
|
||||
});
|
||||
|
||||
file.event = toChangeType(changeType);
|
||||
result.emit('data', file);
|
||||
}
|
||||
});
|
||||
|
||||
child.stderr.on('data', function(data) {
|
||||
result.emit('error', data);
|
||||
});
|
||||
|
||||
child.on('exit', function(code) {
|
||||
result.emit('error', 'Watcher died with code ' + code);
|
||||
child = null;
|
||||
});
|
||||
|
||||
process.once('SIGTERM', function () { process.exit(0); });
|
||||
process.once('SIGTERM', function () { process.exit(0); });
|
||||
process.once('exit', function () { child && child.kill(); });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
var cache = Object.create(null);
|
||||
|
||||
module.exports = function(pattern, options) {
|
||||
options = options || {};
|
||||
|
||||
var cwd = path.normalize(options.cwd || process.cwd());
|
||||
var watcher = cache[cwd];
|
||||
|
||||
if (!watcher) {
|
||||
watcher = cache[cwd] = watch(cwd);
|
||||
}
|
||||
|
||||
var rebase = !options.base ? es.through() : es.mapSync(function (f) {
|
||||
f.base = options.base;
|
||||
return f;
|
||||
});
|
||||
|
||||
return watcher
|
||||
.pipe(filter(['**', '!.git{,/**}'])) // ignore all things git
|
||||
.pipe(filter(pattern))
|
||||
.pipe(es.map(function (file, cb) {
|
||||
fs.stat(file.path, function (err, stat) {
|
||||
if (err && err.code === 'ENOENT') { return cb(null, file); }
|
||||
if (err) { return cb(); }
|
||||
if (!stat.isFile()) { return cb(); }
|
||||
|
||||
fs.readFile(file.path, function (err, contents) {
|
||||
if (err && err.code === 'ENOENT') { return cb(null, file); }
|
||||
if (err) { return cb(); }
|
||||
|
||||
file.contents = contents;
|
||||
file.stat = stat;
|
||||
cb(null, file);
|
||||
});
|
||||
});
|
||||
}))
|
||||
.pipe(rebase);
|
||||
};
|
||||
BIN
build/lib/watch/watcher.exe
Normal file
BIN
build/lib/watch/watcher.exe
Normal file
Binary file not shown.
Reference in New Issue
Block a user