mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 09:42:34 -05:00
add samples (#920)
This commit is contained in:
118
samples/extensionSamples/tasks/buildtasks.js
Normal file
118
samples/extensionSamples/tasks/buildtasks.js
Normal file
@@ -0,0 +1,118 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
"use strict";
|
||||
|
||||
let del = require('del');
|
||||
let gulp = require('gulp');
|
||||
let srcmap = require('gulp-sourcemaps');
|
||||
let tslint = require('gulp-tslint');
|
||||
let ts = require('gulp-typescript');
|
||||
let cproc = require('child_process');
|
||||
let os = require('os');
|
||||
|
||||
let config = require('./config');
|
||||
let tsProject = ts.createProject('tsconfig.json');
|
||||
|
||||
|
||||
// GULP TASKS //////////////////////////////////////////////////////////////
|
||||
gulp.task('clean', function(done) {
|
||||
return del('out', done);
|
||||
});
|
||||
|
||||
gulp.task('lint', () => {
|
||||
return gulp.src([
|
||||
config.paths.project.root + '/src/**/*.ts',
|
||||
config.paths.project.root + '/test/**/*.ts'
|
||||
])
|
||||
.pipe((tslint({
|
||||
formatter: "verbose"
|
||||
})))
|
||||
.pipe(tslint.report());
|
||||
});
|
||||
|
||||
gulp.task('compile:src', function(done) {
|
||||
gulp.src([
|
||||
config.paths.project.root + '/src/**/*.sql',
|
||||
config.paths.project.root + '/src/**/*.svg',
|
||||
config.paths.project.root + '/src/**/*.html'
|
||||
]).pipe(gulp.dest('out/src/'));
|
||||
|
||||
let srcFiles = [
|
||||
config.paths.project.root + '/src/**/*.ts',
|
||||
config.paths.project.root + '/src/**/*.js',
|
||||
config.paths.project.root + '/typings/**/*.ts'
|
||||
];
|
||||
|
||||
return gulp.src(srcFiles)
|
||||
.pipe(srcmap.init())
|
||||
.pipe(tsProject())
|
||||
.on('error', function() {
|
||||
if(process.env.BUILDMACHINE) {
|
||||
done('Failed to compile extension source, see above.');
|
||||
process.exit(1);
|
||||
}
|
||||
})
|
||||
// TODO: Reinstate localization code
|
||||
// .pipe(nls.rewriteLocalizeCalls())
|
||||
// .pipe(nls.createAdditionalLanguageFiles(nls.coreLanguages, config.paths.project.root + '/localization/i18n', undefined, false))
|
||||
.pipe(srcmap.write('.', { sourceRoot: function(file) { return file.cwd + '/src'; }}))
|
||||
.pipe(gulp.dest('out/src/'));
|
||||
});
|
||||
|
||||
gulp.task('compile:test', function(done) {
|
||||
let srcFiles = [
|
||||
config.paths.project.root + '/test/**/*.ts',
|
||||
config.paths.project.root + '/typings/**/*.ts'
|
||||
];
|
||||
|
||||
return gulp.src(srcFiles)
|
||||
.pipe(srcmap.init())
|
||||
.pipe(tsProject())
|
||||
.on('error', function() {
|
||||
if(process.env.BUILDMACHINE) {
|
||||
done('Failed to compile test source, see above.');
|
||||
process.exit(1);
|
||||
}
|
||||
})
|
||||
.pipe(srcmap.write('.', {sourceRoot: function(file) { return file.cwd + '/test'; }}))
|
||||
.pipe(gulp.dest('out/test/'));
|
||||
});
|
||||
|
||||
// COMPOSED GULP TASKS /////////////////////////////////////////////////////
|
||||
gulp.task("compile", gulp.series("compile:src", "compile:test"));
|
||||
|
||||
gulp.task("build", gulp.series("clean", "lint", "compile"));
|
||||
|
||||
gulp.task("watch", function() {
|
||||
gulp.watch([config.paths.project.root + '/src/**/*',
|
||||
config.paths.project.root + '/test/**/*.ts'],
|
||||
gulp.series('build'))
|
||||
});
|
||||
|
||||
gulp.task('test', (done) => {
|
||||
let workspace = process.env['WORKSPACE'];
|
||||
if (!workspace) {
|
||||
workspace = process.cwd();
|
||||
}
|
||||
process.env.JUNIT_REPORT_PATH = workspace + '/test-reports/ext_xunit.xml';
|
||||
|
||||
let sqlopsPath = 'sqlops';
|
||||
if (process.env['SQLOPS_DEV']) {
|
||||
let suffix = os.platform === 'win32' ? 'bat' : 'sh';
|
||||
sqlopsPath = `${process.env['SQLOPS_DEV']}/scripts/sql-cli.${suffix}`;
|
||||
}
|
||||
console.log(`Using SQLOPS Path of ${sqlopsPath}`);
|
||||
|
||||
cproc.exec(`${sqlopsPath} --extensionDevelopmentPath="${workspace}" --extensionTestsPath="${workspace}/out/test" --verbose`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`exec error: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`stdout: ${stdout}`);
|
||||
console.log(`stderr: ${stderr}`);
|
||||
done();
|
||||
});
|
||||
});
|
||||
27
samples/extensionSamples/tasks/config.js
Normal file
27
samples/extensionSamples/tasks/config.js
Normal file
@@ -0,0 +1,27 @@
|
||||
var path = require('path');
|
||||
|
||||
var projectRoot = path.resolve(path.dirname(__dirname));
|
||||
var srcRoot = path.resolve(projectRoot, 'src');
|
||||
var viewsRoot = path.resolve(srcRoot, 'views');
|
||||
var htmlcontentRoot = path.resolve(viewsRoot, 'htmlcontent');
|
||||
var outRoot = path.resolve(projectRoot, 'out');
|
||||
var htmloutroot = path.resolve(outRoot, 'src/views/htmlcontent');
|
||||
var localization = path.resolve(projectRoot, 'localization');
|
||||
|
||||
var config = {
|
||||
paths: {
|
||||
project: {
|
||||
root: projectRoot,
|
||||
localization: localization
|
||||
},
|
||||
extension: {
|
||||
root: srcRoot
|
||||
},
|
||||
html: {
|
||||
root: htmlcontentRoot,
|
||||
out: htmloutroot
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = config;
|
||||
148
samples/extensionSamples/tasks/packagetasks.js
Normal file
148
samples/extensionSamples/tasks/packagetasks.js
Normal file
@@ -0,0 +1,148 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
let gulp = require('gulp');
|
||||
let exec = require('child-process-promise').exec;
|
||||
let color = require('gulp-color');
|
||||
|
||||
// CONSTANTS ///////////////////////////////////////////////////////////////
|
||||
let packageVals = require('../package');
|
||||
|
||||
// HELPER FUNCTIONS ////////////////////////////////////////////////////////
|
||||
|
||||
let buildPackage = function(packageName) {
|
||||
// Make sure there are
|
||||
if (!packageVals.repository) {
|
||||
return Promise.reject("Repository field is not defined in package.json");
|
||||
}
|
||||
|
||||
// Initialize the package command with program and command
|
||||
let vsceArgs = [];
|
||||
vsceArgs.push('./node_modules/vsce/out/vsce');
|
||||
vsceArgs.push('package'); // package command
|
||||
|
||||
// Add the package name
|
||||
vsceArgs.push('-o');
|
||||
vsceArgs.push(packageName);
|
||||
|
||||
// Put it all together and execute the command
|
||||
let command = vsceArgs.join(' ');
|
||||
console.log(command);
|
||||
return exec(command);
|
||||
};
|
||||
|
||||
|
||||
// function getServiceInstaller() {
|
||||
// let Constants = require('../out/src/models/constants').Constants;
|
||||
// let ServiceInstaller = require('../out/src/languageservice/serviceInstallerUtil').ServiceInstaller;
|
||||
// return new ServiceInstaller(new Constants())
|
||||
// }
|
||||
//
|
||||
// function installToolsService(platform) {
|
||||
// let installer = getServiceInstaller();
|
||||
// return installer.installService(platform);
|
||||
// }
|
||||
|
||||
// function cleanServiceInstallFolder() {
|
||||
// let installer = getServiceInstaller();
|
||||
// return new Promise(function(resolve, reject) {
|
||||
// installer.getServiceInstallDirectoryRoot().then(function (serviceInstallFolder) {
|
||||
// console.log('Deleting Service Install folder: ' + serviceInstallFolder);
|
||||
// del(serviceInstallFolder + '/*').then(function () {
|
||||
// resolve();
|
||||
// }).catch(function (error) {
|
||||
// reject(error)
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
// function doOfflinePackage(runtimeId, platform, packageName) {
|
||||
// return installSqlToolsService(platform).then(function() {
|
||||
// return doPackageSync(packageName + '-' + runtimeId + '.vsix');
|
||||
// });
|
||||
// }
|
||||
|
||||
// ORIGINAL GULP TASKS /////////////////////////////////////////////////////
|
||||
// TODO: Reinstate when we have code for loading a tools service
|
||||
|
||||
// gulp.task('ext:install-service', function() {
|
||||
// return installSqlToolsService();
|
||||
// });
|
||||
|
||||
// Install vsce to be able to run this task: npm install -g vsce
|
||||
// gulp.task('package:online', function() {
|
||||
// return cleanServiceInstallFolder()
|
||||
// .then(function() { return doPackageSync(); });
|
||||
// });
|
||||
|
||||
// Install vsce to be able to run this task: npm install -g vsce
|
||||
// gulp.task('package:offline', function() {
|
||||
// const platform = require('../out/src/models/platform');
|
||||
// const Runtime = platform.Runtime;
|
||||
// let json = JSON.parse(fs.readFileSync('package.json').toString());
|
||||
// let name = json.name;
|
||||
// let version = json.version;
|
||||
// let packageName = name + '-' + version;
|
||||
//
|
||||
// let packages = [];
|
||||
// packages.push({rid: 'win-x64', runtime: Runtime.Windows_64});
|
||||
// packages.push({rid: 'win-x86', runtime: Runtime.Windows_86});
|
||||
// packages.push({rid: 'osx', runtime: Runtime.OSX});
|
||||
// packages.push({rid: 'linux-x64', runtime: Runtime.Linux_64});
|
||||
//
|
||||
// let promise = Promise.resolve();
|
||||
// cleanServiceInstallFolder().then(function () {
|
||||
// packages.forEach(function (data) {
|
||||
// promise = promise.then(function () {
|
||||
// return doOfflinePackage(data.rid, data.runtime, packageName).then(function () {
|
||||
// return cleanServiceInstallFolder();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// return promise;
|
||||
// });
|
||||
|
||||
function getOnlinePackageName() {
|
||||
return packageVals.name + "-" + packageVals.version + ".vsix";
|
||||
}
|
||||
|
||||
function getOnlinePackagePath() {
|
||||
return './' + getOnlinePackageName();
|
||||
}
|
||||
|
||||
// TEMPORARY GULP TASKS ////////////////////////////////////////////////////
|
||||
gulp.task('package:online', gulp.series("build", function() {
|
||||
return buildPackage(getOnlinePackageName());
|
||||
}));
|
||||
|
||||
gulp.task('package:offline', gulp.series("build", function(done) {
|
||||
// TODO: Get list of platforms
|
||||
// TODO: For each platform: clean the package service folder, download the service, build the package
|
||||
console.error("This mode is not yet supported");
|
||||
done("This mode is not yet supported");
|
||||
}));
|
||||
|
||||
gulp.task('install:sqlops', gulp.series("package:online", function() {
|
||||
let command = 'sqlops --install-extension ' + getOnlinePackagePath();
|
||||
console.log(command);
|
||||
return exec(command);
|
||||
}));
|
||||
|
||||
gulp.task("help:debug", function(done) {
|
||||
let command = '$SQLOPS_DEV/scripts/sql.sh --extensionDevelopmentPath='+process.cwd();
|
||||
console.log('Launch sqlops + your extension (from a sqlops dev enlistment after setting $SQLOPS_DEV to your enlistment root):\n')
|
||||
console.log(color(command, 'GREEN'));
|
||||
|
||||
command = 'sqlops --extensionDevelopmentPath='+process.cwd();
|
||||
console.log('\nLaunch sqlops + your extension (full SQLOPS - requires setting PATH variable)\n');
|
||||
console.log(color(command, 'GREEN'));
|
||||
done();
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user