This commit is contained in:
chrisdias 2017-06-05 17:55:05 -07:00
Родитель 52a04658ba
Коммит 7279b05b0f
19 изменённых файлов: 322 добавлений и 323 удалений

Просмотреть файл

@ -9,11 +9,11 @@ function hasWorkspaceFolder(): boolean {
return vscode.workspace.rootPath ? true : false;
}
function getDockerFileUris(): Thenable<vscode.Uri[]> {
async function getDockerFileUris(): Promise<vscode.Uri[]> {
if (!hasWorkspaceFolder()) {
return Promise.resolve(null);
return;
}
return Promise.resolve(vscode.workspace.findFiles(DOCKERFILE_GLOB_PATTERN, null, 1000, null));
return await vscode.workspace.findFiles(DOCKERFILE_GLOB_PATTERN, null, 1000, null);
}
interface Item extends vscode.QuickPickItem {
@ -40,61 +40,62 @@ function computeItems(uris: vscode.Uri[]): vscode.QuickPickItem[] {
return items;
}
function resolveImageItem(dockerFileUri?: vscode.Uri): Promise<Item> {
return new Promise((resolve) => {
if (dockerFileUri) {
return resolve(createItem(dockerFileUri));
};
async function resolveImageItem(dockerFileUri?: vscode.Uri): Promise<Item> {
if (dockerFileUri) {
return createItem(dockerFileUri);
};
const uris: vscode.Uri[] = await getDockerFileUris();
if (!uris || uris.length == 0) {
vscode.window.showInformationMessage('Couldn\'t find a Dockerfile in your workspace.');
return;
} else {
const res: vscode.QuickPickItem = await vscode.window.showQuickPick(computeItems(uris), {placeHolder: 'Choose Dockerfile to build'});
return <Item>res;
}
getDockerFileUris().then((uris: vscode.Uri[]) => {
if (!uris || uris.length == 0) {
vscode.window.showInformationMessage('Couldn\'t find a Dockerfile in your workspace.');
resolve();
} else {
let items: vscode.QuickPickItem[] = computeItems(uris);
vscode.window.showQuickPick(items, { placeHolder: 'Choose Dockerfile to build' }).then(resolve);
}
});
});
}
export function buildImage(dockerFileUri?: vscode.Uri) {
resolveImageItem(dockerFileUri).then((uri: Item) => {
if (!uri) return;
export async function buildImage(dockerFileUri?: vscode.Uri) {
let imageName: string;
const uri: Item = await resolveImageItem(dockerFileUri);
if (!uri) return;
let imageName: string;
if (process.platform === 'win32') {
imageName = uri.path.split('\\').pop().toLowerCase();
} else {
imageName = uri.path.split('/').pop().toLowerCase();
}
if (imageName === '.') {
if (process.platform === 'win32') {
imageName = uri.path.split('\\').pop().toLowerCase();
imageName = vscode.workspace.rootPath.split('\\').pop().toLowerCase();
} else {
imageName = uri.path.split('/').pop().toLowerCase();
imageName = vscode.workspace.rootPath.split('/').pop().toLowerCase();
}
}
if (imageName === '.') {
if (process.platform === 'win32') {
imageName = vscode.workspace.rootPath.split('\\').pop().toLowerCase();
} else {
imageName = vscode.workspace.rootPath.split('/').pop().toLowerCase();
}
}
const opt: vscode.InputBoxOptions = {
placeHolder: imageName + ':latest',
prompt: 'Tag image as...',
value: imageName + ':latest'
};
const opt: vscode.InputBoxOptions = {
placeHolder: imageName + ':latest',
prompt: 'Tag image as...',
value: imageName + ':latest'
};
const value: string = await vscode.window.showInputBox(opt);
vscode.window.showInputBox(opt).then((value: string) => {
if (!value) return;
if (!value) return;
let terminal: vscode.Terminal = vscode.window.createTerminal('Docker');
terminal.sendText(`docker build -f ${uri.file} -t ${value} ${uri.path}`);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
}
const terminal: vscode.Terminal = vscode.window.createTerminal('Docker');
terminal.sendText(`docker build -f ${uri.file} -t ${value} ${uri.path}`);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
});
}
}

Просмотреть файл

@ -8,11 +8,11 @@ function hasWorkspaceFolder(): boolean {
return vscode.workspace.rootPath ? true : false;
}
function getDockerComposeFileUris(): Thenable<vscode.Uri[]> {
async function getDockerComposeFileUris(): Promise<vscode.Uri[]> {
if (!hasWorkspaceFolder()) {
return Promise.resolve(null);
return;
}
return Promise.resolve(vscode.workspace.findFiles(COMPOSE_FILE_GLOB_PATTERN, null, 9999, null));
return await vscode.workspace.findFiles(COMPOSE_FILE_GLOB_PATTERN, null, 9999, null);
}
interface Item extends vscode.QuickPickItem {
@ -21,7 +21,7 @@ interface Item extends vscode.QuickPickItem {
}
function createItem(uri: vscode.Uri): Item {
let filePath = hasWorkspaceFolder() ? path.join('.', uri.fsPath.substr(vscode.workspace.rootPath.length)) : uri.fsPath;
const filePath = hasWorkspaceFolder() ? path.join('.', uri.fsPath.substr(vscode.workspace.rootPath.length)) : uri.fsPath;
return <Item>{
description: null,
@ -32,34 +32,33 @@ function createItem(uri: vscode.Uri): Item {
}
function computeItems(uris: vscode.Uri[]): vscode.QuickPickItem[] {
let items: vscode.QuickPickItem[] = [];
const items: vscode.QuickPickItem[] = [];
for (let i = 0; i < uris.length; i++) {
items.push(createItem(uris[i]));
}
return items;
}
export function compose(command: string, message: string) {
getDockerComposeFileUris().then(function (uris: vscode.Uri[]) {
if (!uris || uris.length == 0) {
vscode.window.showInformationMessage('Couldn\'t find any docker-compose file in your workspace.');
} else {
let items: vscode.QuickPickItem[] = computeItems(uris);
vscode.window.showQuickPick(items, { placeHolder: `Choose Docker Compose file ${message}` }).then(function (selectedItem: Item) {
if (selectedItem) {
let terminal: vscode.Terminal = vscode.window.createTerminal('Docker Compose');
terminal.sendText(`docker-compose -f ${selectedItem.file} ${command}`);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId + command
});
}
export async function compose(command: string, message: string) {
const uris: vscode.Uri[] = await getDockerComposeFileUris();
if (!uris || uris.length == 0) {
vscode.window.showInformationMessage('Couldn\'t find any docker-compose file in your workspace.');
} else {
const items: vscode.QuickPickItem[] = computeItems(uris);
const selectedItem: Item = <Item>await vscode.window.showQuickPick(items, { placeHolder: `Choose Docker Compose file ${message}` });
if (selectedItem) {
const terminal: vscode.Terminal = vscode.window.createTerminal('Docker Compose');
terminal.sendText(`docker-compose -f ${selectedItem.file} ${command}`);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId + command
});
}
}
});
}
});
}
}
export function composeUp() {

Просмотреть файл

@ -9,20 +9,21 @@ const engineTypeShellCommands = {
[DockerEngineType.Windows]: "powershell"
}
export function openShellContainer() {
quickPickContainer().then((selectedItem: ContainerItem) => {
if (selectedItem) {
docker.getEngineType().then((engineType: DockerEngineType) => {
const terminal = vscode.window.createTerminal(`Shell: ${selectedItem.label}`);
terminal.sendText(`docker exec -it ${selectedItem.ids[0]} ${engineTypeShellCommands[engineType]}`);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId,
dockerEngineType: engineTypeShellCommands[engineType]
});
}
});
}
});
export async function openShellContainer() {
const selectedItem: ContainerItem = await quickPickContainer();
if (selectedItem) {
docker.getEngineType().then((engineType: DockerEngineType) => {
const terminal = vscode.window.createTerminal(`Shell: ${selectedItem.label}`);
terminal.sendText(`docker exec -it ${selectedItem.ids[0]} ${engineTypeShellCommands[engineType]}`);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId,
dockerEngineType: engineTypeShellCommands[engineType]
});
}
});
}
}

Просмотреть файл

@ -3,17 +3,17 @@ import { ImageItem, quickPickImage } from './utils/quick-pick-image';
import { reporter } from '../telemetry/telemetry';
const teleCmdId: string = 'vscode-docker.image.push';
export function pushImage() {
quickPickImage(false).then(function (selectedItem: ImageItem) {
if (selectedItem) {
let terminal = vscode.window.createTerminal(selectedItem.label);
terminal.sendText(`docker push ${selectedItem.label}`);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
}
};
});
export async function pushImage() {
const selectedItem: ImageItem = await quickPickImage();
if (selectedItem) {
const terminal = vscode.window.createTerminal(selectedItem.label);
terminal.sendText(`docker push ${selectedItem.label}`);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
}
};
}

Просмотреть файл

@ -4,53 +4,54 @@ import vscode = require('vscode');
import { reporter } from '../telemetry/telemetry';
const teleCmdId: string = 'vscode-docker.image.remove';
export function removeImage() {
quickPickImage(true).then(function (selectedItem: ImageItem) {
export async function removeImage() {
const selectedItem: ImageItem = await quickPickImage();
if (selectedItem) {
// if we're removing all images, remove duplicate IDs, a result of tagging
if (selectedItem.label.toLowerCase().includes('all images')) {
selectedItem.ids = Array.from(new Set(selectedItem.ids));
// if we're removing all images, remove duplicate IDs, a result of tagging
if (selectedItem.label.toLowerCase().includes('all images')) {
selectedItem.ids = Array.from(new Set(selectedItem.ids));
}
for (let i = 0; i < selectedItem.ids.length; i++) {
const image = docker.getImage(selectedItem.ids[i]);
// image.remove removes by ID, so to remove a single *tagged* image we
// just overwrite the name. this is a hack around the dockerode api
if (selectedItem.ids.length === 1) {
if (!selectedItem.label.toLowerCase().includes('<none>')) {
image.name = selectedItem.label;
}
}
for (let i = 0; i < selectedItem.ids.length; i++) {
let image = docker.getImage(selectedItem.ids[i]);
image.remove({ force: true }, function (err, data: any) {
// image.remove removes by ID, so to remove a single *tagged* image we
// just overwrite the name. this is a hack around the dockerode api
if (selectedItem.ids.length === 1) {
if (!selectedItem.label.toLowerCase().includes('<none>')) {
image.name = selectedItem.label;
if (data) {
for (i = 0; i < data.length; i++) {
if (data[i].Untagged) {
console.log(data[i].Untagged);
} else if (data[i].Deleted) {
console.log(data[i].Deleted);
}
}
vscode.window.showInformationMessage(selectedItem.label + ' successfully removed');
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
}
}
});
}
image.remove({ force: true }, function (err, data: any) {
if (data) {
for (i = 0; i < data.length; i++) {
if (data[i].Untagged) {
console.log(data[i].Untagged);
} else if (data[i].Deleted) {
console.log(data[i].Deleted);
}
}
vscode.window.showInformationMessage(selectedItem.label + ' successfully removed');
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
}
}
});
}
// show the list again unless the user just did a 'remove all images'
// if (!selectedItem.label.toLowerCase().includes('all images')) {
// setInterval(removeImage, 1000);
// }
// show the list again unless the user just did a 'remove all images'
// if (!selectedItem.label.toLowerCase().includes('all images')) {
// setInterval(removeImage, 1000);
// }
}
});
}

Просмотреть файл

@ -3,17 +3,17 @@ import { ContainerItem, quickPickContainer } from './utils/quick-pick-container'
import { reporter } from '../telemetry/telemetry';
const teleCmdId: string = 'vscode-docker.container.show-logs';
export function showLogsContainer() {
quickPickContainer().then(function (selectedItem: ContainerItem) {
if (selectedItem) {
let terminal = vscode.window.createTerminal(selectedItem.label);
terminal.sendText(`docker logs -f ${selectedItem.ids[0]}`);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
}
export async function showLogsContainer() {
const selectedItem: ContainerItem = await quickPickContainer();
if (selectedItem) {
const terminal = vscode.window.createTerminal(selectedItem.label);
terminal.sendText(`docker logs -f ${selectedItem.ids[0]}`);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
}
});
}
}

Просмотреть файл

@ -6,28 +6,29 @@ import os = require('os');
import { reporter } from '../telemetry/telemetry';
const teleCmdId: string = 'vscode-docker.container.start';
function doStartContainer(interactive: boolean) {
quickPickImage(false).then(function (selectedItem: ImageItem) {
if (selectedItem) {
docker.getExposedPorts(selectedItem.label).then((ports: string[]) => {
let options = `--rm ${interactive ? '-it' : '-d'}`;
if (ports.length) {
const portMappings = ports.map((port) => `-p ${port}:${port}`);
options += ` ${portMappings.join(' ')}`;
}
const terminal = vscode.window.createTerminal(selectedItem.label);
terminal.sendText(`docker run ${options} ${selectedItem.label}`);
terminal.show();
async function doStartContainer(interactive: boolean) {
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: interactive ? teleCmdId + '.interactive' : teleCmdId
});
}
});
}
});
const selectedItem: ImageItem = await quickPickImage(false);
if (selectedItem) {
docker.getExposedPorts(selectedItem.label).then((ports: string[]) => {
let options = `--rm ${interactive ? '-it' : '-d'}`;
if (ports.length) {
const portMappings = ports.map((port) => `-p ${port}:${port}`);
options += ` ${portMappings.join(' ')}`;
}
const terminal = vscode.window.createTerminal(selectedItem.label);
terminal.sendText(`docker run ${options} ${selectedItem.label}`);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: interactive ? teleCmdId + '.interactive' : teleCmdId
});
}
});
}
}
export function startContainer() {
@ -38,42 +39,40 @@ export function startContainerInteractive() {
doStartContainer(true);
}
export function startAzureCLI() {
export async function startAzureCLI() {
// block of we are running windows containers...
docker.getEngineType().then((engineType: DockerEngineType) => {
const engineType: DockerEngineType = await docker.getEngineType();
if (engineType === DockerEngineType.Windows) {
vscode.window.showErrorMessage<vscode.MessageItem>('Currently, you can only run the Azure CLI when running Linux based containers.',
{
title: 'More Information',
},
{
title: 'Close',
isCloseAffordance: true
}
).then((selected) => {
if (!selected || selected.isCloseAffordance) {
return;
}
return cp.exec('start https://docs.docker.com/docker-for-windows/#/switch-between-windows-and-linux-containers');
});
} else {
let option: string = process.platform === 'linux' ? '--net=host' : '';
// volume map .azure folder so don't have to log in every time
let homeDir: string = process.platform === 'win32' ? os.homedir().replace(/\\/g, '/') : os.homedir();
let vol: string = `-v ${homeDir}/.azure:/root/.azure -v ${homeDir}/.ssh:/root/.ssh -v ${homeDir}/.kube:/root/.kube`;
let cmd: string = `docker run ${option} ${vol} -it --rm azuresdk/azure-cli-python:latest`;
let terminal: vscode.Terminal = vscode.window.createTerminal('Azure CLI');
terminal.sendText(cmd);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId + '.azurecli'
});
if (engineType === DockerEngineType.Windows) {
const selected = await vscode.window.showErrorMessage<vscode.MessageItem>('Currently, you can only run the Azure CLI when running Linux based containers.',
{
title: 'More Information',
},
{
title: 'Close',
isCloseAffordance: true
}
);
if (!selected || selected.isCloseAffordance) {
return;
}
});
return cp.exec('start https://docs.docker.com/docker-for-windows/#/switch-between-windows-and-linux-containers');
} else {
const option: string = process.platform === 'linux' ? '--net=host' : '';
// volume map .azure folder so don't have to log in every time
const homeDir: string = process.platform === 'win32' ? os.homedir().replace(/\\/g, '/') : os.homedir();
const vol: string = `-v ${homeDir}/.azure:/root/.azure -v ${homeDir}/.ssh:/root/.ssh -v ${homeDir}/.kube:/root/.kube`;
const cmd: string = `docker run ${option} ${vol} -it --rm azuresdk/azure-cli-python:latest`;
const terminal: vscode.Terminal = vscode.window.createTerminal('Azure CLI');
terminal.sendText(cmd);
terminal.show();
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId + '.azurecli'
});
}
}
}

Просмотреть файл

@ -3,21 +3,20 @@ import { ContainerItem, quickPickContainer } from './utils/quick-pick-container'
import { reporter } from '../telemetry/telemetry';
const teleCmdId: string = 'vscode-docker.container.stop';
export function stopContainer() {
quickPickContainer(true).then(function (selectedItem: ContainerItem) {
if (selectedItem) {
for (let i = 0; i < selectedItem.ids.length; i++) {
let container = docker.getContainer(selectedItem.ids[i]);
container.stop(function (err, data) {
// console.log("Stopped - error: " + err);
// console.log("Stopped - data: " + data);
export async function stopContainer() {
const selectedItem: ContainerItem = await quickPickContainer(true);
if (selectedItem) {
for (let i = 0; i < selectedItem.ids.length; i++) {
const container = docker.getContainer(selectedItem.ids[i]);
container.stop(function (err, data) {
// console.log("Stopped - error: " + err);
// console.log("Stopped - data: " + data);
});
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
}
}
}
});
}
}

Просмотреть файл

@ -2,9 +2,9 @@ import vscode = require('vscode');
import { reporter } from '../telemetry/telemetry';
const teleCmdId: string = 'vscode-docker.system.prune';
export function systemPrune() {
export async function systemPrune() {
let terminal = vscode.window.createTerminal("docker system prune");
const terminal = vscode.window.createTerminal("docker system prune");
terminal.sendText(`docker system prune -f`);
terminal.show();
if (reporter) {

Просмотреть файл

@ -4,21 +4,22 @@ import { docker } from './utils/docker-endpoint';
import { reporter } from '../telemetry/telemetry';
const teleCmdId: string = 'vscode-docker.image.tag';
export function tagImage() {
export async function tagImage() {
const selectedItem: ImageItem = await quickPickImage(false);
quickPickImage(false).then(function (selectedItem: ImageItem) {
if (selectedItem) {
var imageName: string = selectedItem.label;
let imageName: string = selectedItem.label;
let configOptions: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration('docker');
const configOptions: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration('docker');
let defaultRegistryPath = configOptions.get('defaultRegistryPath', '');
const defaultRegistryPath = configOptions.get('defaultRegistryPath', '');
if (defaultRegistryPath.length > 0) {
imageName = defaultRegistryPath + '/' + imageName;
}
let defaultRegistry = configOptions.get('defaultRegistry', '');
const defaultRegistry = configOptions.get('defaultRegistry', '');
if (defaultRegistry.length > 0) {
imageName = defaultRegistry + '/' + imageName;
}
@ -30,27 +31,25 @@ export function tagImage() {
value: imageName
};
vscode.window.showInputBox(opt).then((value: string) => {
if (value) {
var repo: string = value;
var tag: string = 'latest';
if (value.lastIndexOf(':') > 0) {
repo = value.slice(0, value.lastIndexOf(':'));
tag = value.slice(value.lastIndexOf(':') + 1);
}
let image = docker.getImage(selectedItem.ids[0]);
image.tag({ repo: repo, tag: tag }, function (err, data) {
if (err) {
console.log('Docker Tag error: ' + err);
}
});
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
}
const value: string = await vscode.window.showInputBox(opt);
if (value) {
let repo: string = value;
let tag: string = 'latest';
if (value.lastIndexOf(':') > 0) {
repo = value.slice(0, value.lastIndexOf(':'));
tag = value.slice(value.lastIndexOf(':') + 1);
}
});
const image = docker.getImage(selectedItem.ids[0]);
image.tag({ repo: repo, tag: tag }, function (err, data) {
if (err) {
console.log('Docker Tag error: ' + err);
}
});
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
}
}
};
});
}

Просмотреть файл

@ -17,11 +17,11 @@ function createItem(container: Docker.ContainerDesc) : ContainerItem {
function computeItems(containers: Docker.ContainerDesc[], includeAll: boolean) : ContainerItem[] {
let allIds: string[] = [];
const allIds: string[] = [];
let items : ContainerItem[] = [];
const items : ContainerItem[] = [];
for (let i = 0; i < containers.length; i++) {
let item = createItem(containers[i]);
const item = createItem(containers[i]);
allIds.push(item.ids[0]);
items.push(item);
}
@ -37,14 +37,14 @@ function computeItems(containers: Docker.ContainerDesc[], includeAll: boolean) :
return items;
}
export function quickPickContainer(includeAll: boolean = false) : Thenable<ContainerItem>{
return docker.getContainerDescriptors().then(containers => {
if (!containers || containers.length == 0) {
vscode.window.showInformationMessage('There are no running docker containers.');
return Promise.resolve(null);
} else {
let items: ContainerItem[] = computeItems(containers, includeAll);
return vscode.window.showQuickPick(items, { placeHolder: 'Choose Container' });
}
});
export async function quickPickContainer(includeAll: boolean = false) : Promise<ContainerItem>{
const containers = await docker.getContainerDescriptors();
if (!containers || containers.length == 0) {
vscode.window.showInformationMessage('There are no running docker containers.');
return;
} else {
const items: ContainerItem[] = computeItems(containers, includeAll);
return vscode.window.showQuickPick(items, { placeHolder: 'Choose Container' });
}
}

Просмотреть файл

@ -13,7 +13,6 @@ export interface ImageItem extends vscode.QuickPickItem {
function createItem(image: Docker.ImageDesc, repoTag: string): ImageItem {
return <ImageItem>{
label: repoTag || '<none>',
description: null,
@ -28,19 +27,19 @@ function createItem(image: Docker.ImageDesc, repoTag: string): ImageItem {
function computeItems(images: Docker.ImageDesc[], includeAll?: boolean): ImageItem[] {
let allIds: string[] = [];
const allIds: string[] = [];
let items: ImageItem[] = [];
const items: ImageItem[] = [];
for (let i = 0; i < images.length; i++) {
if (!images[i].RepoTags) {
let item = createItem(images[i], '<none>:<none>');
const item = createItem(images[i], '<none>:<none>');
allIds.push(item.ids[0]);
items.push(item);
} else {
for (let j = 0; j < images[i].RepoTags.length; j++) {
let item = createItem(images[i], images[i].RepoTags[j]);
const item = createItem(images[i], images[i].RepoTags[j]);
allIds.push(item.ids[0]);
items.push(item);
}
@ -60,14 +59,16 @@ function computeItems(images: Docker.ImageDesc[], includeAll?: boolean): ImageIt
return items;
}
export function quickPickImage(includeAll?: boolean): Thenable<ImageItem> {
return docker.getImageDescriptors().then(images => {
if (!images || images.length == 0) {
vscode.window.showInformationMessage('There are no docker images yet. Try Build first.');
return Promise.resolve(null);
} else {
let items: ImageItem[] = computeItems(images, includeAll);
return vscode.window.showQuickPick(items, { placeHolder: 'Choose image' });
}
});
export async function quickPickImage(includeAll?: boolean): Promise<ImageItem> {
const images = await docker.getImageDescriptors();
if (!images || images.length == 0) {
vscode.window.showInformationMessage('There are no docker images yet. Try Build first.');
return;
} else {
const items: ImageItem[] = computeItems(images, includeAll);
return vscode.window.showQuickPick(items, { placeHolder: 'Choose image' });
}
}

Просмотреть файл

@ -1,6 +1,6 @@
import vscode = require('vscode');
export function promptForPort(): Thenable<string>{
export async function promptForPort(): Promise<string>{
var opt: vscode.InputBoxOptions = {
placeHolder: '3000',
prompt: 'What port does your app listen on?',
@ -10,14 +10,14 @@ export function promptForPort(): Thenable<string>{
return vscode.window.showInputBox(opt);
}
export function quickPickPlatform(): Thenable<string>{
export async function quickPickPlatform(): Promise<string>{
var opt: vscode.QuickPickOptions = {
matchOnDescription: true,
matchOnDetail: true,
placeHolder: 'Select Application Platform'
}
var items: string[] = [];
const items: string[] = [];
items.push('Go');
items.push('.NET Core');
items.push('Node.js');

Просмотреть файл

@ -221,51 +221,50 @@ function hasWorkspaceFolder(): boolean {
return vscode.workspace.rootPath ? true : false;
}
function getPackageJson(): Thenable<vscode.Uri[]> {
async function getPackageJson(): Promise<vscode.Uri[]> {
if (!hasWorkspaceFolder()) {
return Promise.resolve(null);
return;
}
return Promise.resolve(vscode.workspace.findFiles('package.json', null, 1, null));
return vscode.workspace.findFiles('package.json', null, 1, null);
}
function readPackageJson(): Thenable<PackageJson> {
async function readPackageJson(): Promise<PackageJson> {
// open package.json and look for main, scripts start
return getPackageJson().then(function (uris: vscode.Uri[]) {
var pkg: PackageJson = {
npmStart: true,
fullCommand: 'npm start',
cmd: 'npm start',
author: 'author',
version: '0.0.1'
}; //default
const uris: vscode.Uri[] = await getPackageJson();
var pkg: PackageJson = {
npmStart: true,
fullCommand: 'npm start',
cmd: 'npm start',
author: 'author',
version: '0.0.1'
}; //default
if (uris && uris.length > 0) {
var json = JSON.parse(fs.readFileSync(uris[0].fsPath, 'utf8'));
if (uris && uris.length > 0) {
const json = JSON.parse(fs.readFileSync(uris[0].fsPath, 'utf8'));
if (json.scripts && json.scripts.start) {
pkg.npmStart = true;
pkg.fullCommand = json.scripts.start;
pkg.cmd = 'npm start';
} else if (json.main) {
pkg.npmStart = false;
pkg.fullCommand = 'node' + ' ' + json.main;
pkg.cmd = pkg.fullCommand;
} else {
pkg.fullCommand = '';
}
if (json.author) {
pkg.author = json.author;
}
if (json.version) {
pkg.version = json.version;
}
if (json.scripts && json.scripts.start) {
pkg.npmStart = true;
pkg.fullCommand = json.scripts.start;
pkg.cmd = 'npm start';
} else if (json.main) {
pkg.npmStart = false;
pkg.fullCommand = 'node' + ' ' + json.main;
pkg.cmd = pkg.fullCommand;
} else {
pkg.fullCommand = '';
}
return Promise.resolve(pkg);
});
if (json.author) {
pkg.author = json.author;
}
if (json.version) {
pkg.version = json.version;
}
}
return pkg;
}
const DOCKER_FILE_TYPES = {

Просмотреть файл

@ -45,7 +45,7 @@ export class DockerHoverProvider implements HoverProvider {
}).then((results) => {
var r = results.filter(r => !!r.result);
if (r.length === 0) {
return null;
return;
}
let range = new Range(position.line, r[0].startIndex, position.line, r[0].endIndex);
@ -77,6 +77,6 @@ export class DockerHoverProvider implements HoverProvider {
return r2;
}
return null;
return;
}
}

Просмотреть файл

@ -25,7 +25,7 @@ export function tagsForImage(image: IHubSearchResponseResult): string {
export function searchImageInRegistryHub(imageName: string, cache: boolean): Promise<IHubSearchResponseResult> {
return invokeHubSearch(imageName, 1, cache).then((data) => {
if (data.results.length === 0) {
return null;
return;
}
return data.results[0];
});

Просмотреть файл

@ -15,14 +15,14 @@ export class DockerfileParser extends Parser {
parseLine(textLine: TextLine): IToken[] {
if (textLine.isEmptyOrWhitespace) {
return null;
return;
}
var startIndex = textLine.firstNonWhitespaceCharacterIndex;
// Check for comment
if (textLine.text.charAt(startIndex) === '#') {
return null;
return;
}
var tokens: IToken[] = [];

Просмотреть файл

@ -69,7 +69,7 @@ export class SuggestSupportHelper {
while (tokenIndex >= 0) {
var type = tokens[tokenIndex].type;
if (type === parser.TokenType.String || type === parser.TokenType.Text) {
return null;
return;
}
if (type === parser.TokenType.Key) {
keyToken = _parser.tokenValue(line, tokens[tokenIndex]);
@ -79,7 +79,7 @@ export class SuggestSupportHelper {
}
if (!keyToken) {
return null;
return;
}
var keyName = _parser.keyNameFromKeyToken(keyToken);
if (keyName === 'image' || keyName === 'FROM') {

Просмотреть файл

@ -30,5 +30,5 @@ function getPackageInfo(context: vscode.ExtensionContext): IPackageInfo {
aiKey: extensionPackage.aiKey
};
}
return null;
return;
}