Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
started to refactor to multi root support
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Oct 13, 2017
1 parent a7c3548 commit b95cdde
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log (vs-deploy)

## 10.0.0 (October 13th, 2017; multi root support)

* according to [that issue](https://github.com/mkloubert/vs-deploy/issues/112), started to refactor to new, upcoming [Multi Root Workspace API](https://github.com/Microsoft/vscode/wiki/Extension-Authoring:-Adopting-Multi-Root-Workspace-APIs)

## 9.34.1 (October 8th, 2017; placeholders in arguments of 'open' operations)

* added `usePlaceholdersInArguments` for [open](https://github.com/mkloubert/vs-deploy/wiki/targetoperations#open-) deploy operations
Expand Down
6 changes: 3 additions & 3 deletions src/compilers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const CoffeeScript = require('coffeescript');
import * as deploy_contracts from './contracts';
import * as deploy_globals from './globals';
import * as deploy_helpers from './helpers';
import * as deploy_workspace from './workspace';
import * as FS from 'fs';
const Glob = require('glob');
import * as HtmlMinifier from 'html-minifier';
Expand All @@ -39,7 +40,6 @@ import * as vscode from 'vscode';
import * as Workflows from 'node-workflows';



/**
* A CoffeeScript compiler error entry.
*/
Expand Down Expand Up @@ -423,11 +423,11 @@ export function collectCompilerFiles(defaultOpts: CompilerOptions, opts?: Compil
try {
Glob(f, {
absolute: true,
cwd: vscode.workspace.rootPath,
cwd: deploy_workspace.getRootPath(),
dot: true,
ignore: filesToExclude,
nodir: true,
root: vscode.workspace.rootPath,
root: deploy_workspace.getRootPath(),
}, (err, files) => {
if (err) {
completed(err);
Expand Down
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import * as deploy_contracts from './contracts';
import * as deploy_helpers from './helpers';
import * as deploy_values from './values';
import * as deploy_workspace from './workspace';
import * as FS from 'fs';
import * as i18 from './i18';
import * as Path from 'path';
Expand Down Expand Up @@ -142,7 +143,7 @@ export function mergeConfig(cfg: deploy_contracts.DeployConfiguration): Promise<
let src = deploy_helpers.toStringSafe(imp.from);
src = deploy_values.replaceWithValues(values, src);
if (!Path.isAbsolute(src)) {
src = Path.join(vscode.workspace.rootPath, '.vscode', src);
src = Path.join(deploy_workspace.getRootPath(), '.vscode', src);
}
src = Path.resolve(src);

Expand Down
13 changes: 7 additions & 6 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import * as deploy_targets from './targets';
import * as deploy_templates from './templates';
import * as deploy_urls from './urls';
import * as deploy_values from './values';
import * as deploy_workspace from './workspace';
import { DeployHost } from './host';
import * as Events from 'events';
import * as FS from 'fs';
Expand Down Expand Up @@ -1990,7 +1991,7 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
let scriptFile = scriptOpts.script;
if (!deploy_helpers.isEmptyString(scriptOpts.script)) {
if (!Path.isAbsolute(scriptFile)) {
scriptFile = Path.join(vscode.workspace.rootPath, scriptFile);
scriptFile = Path.join(deploy_workspace.getRootPath(), scriptFile);
}
scriptFile = Path.resolve(scriptFile);

Expand Down Expand Up @@ -2170,7 +2171,7 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {

dir = deploy_helpers.toStringSafe(dir, deploy_contracts.DEFAULT_HOST_DIR);
if (!Path.isAbsolute(dir)) {
dir = Path.join(vscode.workspace.rootPath, dir);
dir = Path.join(deploy_workspace.getRootPath(), dir);
}

// destroy old status bar item
Expand Down Expand Up @@ -2725,7 +2726,7 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
return;
}

let dir = vscode.workspace.rootPath;
let dir = deploy_workspace.getRootPath();
let f = filters.shift();

// hostname / machine filter(s)
Expand Down Expand Up @@ -3891,7 +3892,7 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
}).filter(x => !deploy_helpers.isEmptyString(x))
.map(x => {
if (!Path.isAbsolute(x)) {
x = Path.join(vscode.workspace.rootPath, x);
x = Path.join(deploy_workspace.getRootPath(), x);
}

return Path.resolve(x);
Expand Down Expand Up @@ -4271,7 +4272,7 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
let moduleScript = deploy_helpers.toStringSafe(e.script);
moduleScript = me.replaceWithValues(moduleScript);
if (!Path.isAbsolute(moduleScript)) {
moduleScript = Path.join(vscode.workspace.rootPath, moduleScript);
moduleScript = Path.join(deploy_workspace.getRootPath(), moduleScript);
}
moduleScript = Path.resolve(moduleScript);

Expand Down Expand Up @@ -4418,7 +4419,7 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
.filter(x => x)
.map(x => {
if (!Path.isAbsolute(x)) {
x = Path.join(vscode.workspace.rootPath, x);
x = Path.join(deploy_workspace.getRootPath(), x);
}

return x;
Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import * as deploy_content from './content';
import * as deploy_contracts from './contracts';
import * as deploy_helpers from './helpers';
import * as deploy_workspace from './workspace';
import * as FS from 'fs';
import * as Moment from 'moment';
import * as Path from 'path';
Expand All @@ -45,6 +46,8 @@ let deployer: vs_deploy.Deployer;
export function activate(context: vscode.ExtensionContext) {
let now = Moment();

deploy_workspace.resetSelectedWorkspaceFolder();

// version
let pkgFile: vs_contracts.PackageFile;
try {
Expand Down
27 changes: 14 additions & 13 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const CompareVersion = require('compare-versions');
import * as deploy_contracts from './contracts';
import * as deploy_globals from './globals';
import * as deploy_values from './values';
import * as deploy_workspace from './workspace';
import * as FileType from 'file-type';
import * as FS from 'fs';
const FTP = require('jsftp');
Expand Down Expand Up @@ -698,11 +699,11 @@ export function getFilesByFilter(filter: deploy_contracts.FileFilter,
allFilePatterns.forEach(x => {
let matchingFiles: string[] = Glob.sync(x, {
absolute: true,
cwd: vscode.workspace.rootPath,
cwd: deploy_workspace.getRootPath(),
dot: true,
ignore: allExcludePatterns,
nodir: true,
root: vscode.workspace.rootPath,
root: deploy_workspace.getRootPath(),
});

matchingFiles.forEach(y => filesToDeploy.push(y));
Expand Down Expand Up @@ -769,11 +770,11 @@ export function getFilesByFilterAsync(filter: deploy_contracts.FileFilter,
try {
Glob(x, {
absolute: true,
cwd: vscode.workspace.rootPath,
cwd: deploy_workspace.getRootPath(),
dot: true,
ignore: allExcludePatterns,
nodir: true,
root: vscode.workspace.rootPath,
root: deploy_workspace.getRootPath(),
}, (err: any, matchingFiles: string[]) => {
if (err) {
rej(err);
Expand Down Expand Up @@ -1054,7 +1055,7 @@ export function isFileIgnored(file: string, patterns: string | string[],
}

if (!Path.isAbsolute(file)) {
file = Path.join(vscode.workspace.rootPath, file);
file = Path.join(deploy_workspace.getRootPath(), file);
}
file = Path.resolve(file);
file = replaceAllStrings(file, Path.sep, '/');
Expand All @@ -1081,10 +1082,10 @@ export function isFileIgnored(file: string, patterns: string | string[],
else {
let matchingFiles: string[] = Glob.sync(p, {
absolute: true,
cwd: vscode.workspace.rootPath,
cwd: deploy_workspace.getRootPath(),
dot: true,
nodir: true,
root: vscode.workspace.rootPath,
root: deploy_workspace.getRootPath(),
});

isMatching = matchingFiles.indexOf(file) > -1;
Expand Down Expand Up @@ -1140,7 +1141,7 @@ export function loadBaseSettingsFromFiles<T extends deploy_contracts.CanLoadFrom
loadFrom = deploy_values.replaceWithValues(values, x.loadFrom);
if (!isEmptyString(x.loadFrom)) {
if (!Path.isAbsolute(loadFrom)) {
loadFrom = Path.join(vscode.workspace.rootPath, '.vscode', loadFrom);
loadFrom = Path.join(deploy_workspace.getRootPath(), '.vscode', loadFrom);
}

let basePackages: T[] = JSON.parse( FS.readFileSync(loadFrom).toString('utf8') );
Expand Down Expand Up @@ -1617,7 +1618,7 @@ export function loadFrom(src: string): Promise<DownloadResult> {

let filePath = src;
if (!Path.isAbsolute(filePath)) {
filePath = Path.join(vscode.workspace.rootPath, filePath);
filePath = Path.join(deploy_workspace.getRootPath(), filePath);
}
filePath = Path.resolve(filePath);

Expand Down Expand Up @@ -1744,7 +1745,7 @@ export function loadFrom(src: string): Promise<DownloadResult> {
*/
export function loadModule<TModule>(file: string, useCache: boolean = false): TModule {
if (!Path.isAbsolute(file)) {
file = Path.join(vscode.workspace.rootPath, file);
file = Path.join(deploy_workspace.getRootPath(), file);
}
file = Path.resolve(file);

Expand Down Expand Up @@ -1938,7 +1939,7 @@ export function open(target: string, opts?: OpenOptions): Promise<ChildProcess.C
let appArgs: string[] = [];
let args: string[] = [];
let cpOpts: ChildProcess.SpawnOptions = {
cwd: opts.cwd || vscode.workspace.rootPath,
cwd: opts.cwd || deploy_workspace.getRootPath(),
env: opts.env,
};

Expand Down Expand Up @@ -2411,11 +2412,11 @@ export function toRelativePath(path: string, baseDir?: string): string | false {
let result: string | false = false;

if (isEmptyString(baseDir)) {
baseDir = vscode.workspace.rootPath;
baseDir = deploy_workspace.getRootPath();
}
else {
if (!Path.isAbsolute(baseDir)) {
baseDir = Path.join(vscode.workspace.rootPath, baseDir);
baseDir = Path.join(deploy_workspace.getRootPath(), baseDir);
}

baseDir = Path.resolve(baseDir);
Expand Down
5 changes: 3 additions & 2 deletions src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Deployer } from './deploy';
import * as Crypto from 'crypto';
import * as deploy_contracts from './contracts';
import * as deploy_helpers from './helpers';
import * as deploy_workspace from './workspace';
import * as FS from 'fs';
import * as FSExtra from 'fs-extra';
import * as i18 from './i18';
Expand Down Expand Up @@ -303,7 +304,7 @@ export class DeployHost {
dir = deploy_helpers.toStringSafe(dir, deploy_contracts.DEFAULT_HOST_DIR);
dir = me.deployer.replaceWithValues(dir);
if (!Path.isAbsolute(dir)) {
dir = Path.join(vscode.workspace.rootPath, dir);
dir = Path.join(deploy_workspace.getRootPath(), dir);
}

jsonTransformer = deploy_helpers.toDataTransformerSafe(jsonTransformer);
Expand Down Expand Up @@ -643,7 +644,7 @@ export class DeployHost {
}

if (!Path.isAbsolute(targetFile)) {
targetFile = Path.join(vscode.workspace.rootPath, targetFile);
targetFile = Path.join(deploy_workspace.getRootPath(), targetFile);
}

action();
Expand Down
7 changes: 4 additions & 3 deletions src/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as deploy_compilers from './compilers';
import * as deploy_contracts from './contracts';
import * as deploy_helpers from './helpers';
import * as deploy_sql from './sql';
import * as deploy_workspace from './workspace';
import * as HTTP from 'http';
import * as HTTPs from 'https';
import * as i18 from './i18';
Expand Down Expand Up @@ -472,7 +473,7 @@ export function http(ctx: OperationContext<deploy_contracts.DeployHttpOperation>
bodyScript = './getBody.js';
}
if (!Path.isAbsolute(bodyScript)) {
bodyScript = Path.join(vscode.workspace.rootPath, bodyScript);
bodyScript = Path.join(deploy_workspace.getRootPath(), bodyScript);
}
bodyScript = Path.resolve(bodyScript);

Expand Down Expand Up @@ -584,7 +585,7 @@ export function open(ctx: OperationContext<deploy_contracts.DeployOpenOperation>
let app = deploy_helpers.toStringSafe(openOperation.target);
app = me.replaceWithValues(app);
if (!Path.isAbsolute(app)) {
app = Path.join(vscode.workspace.rootPath, app);
app = Path.join(deploy_workspace.getRootPath(), app);
}
app = Path.resolve(app);

Expand Down Expand Up @@ -871,7 +872,7 @@ export function webdeploy(ctx: OperationContext<deploy_contracts.DeployWebDeploy

let app = msDeploy;
if (!Path.isAbsolute(app)) {
app = Path.join(vscode.workspace.rootPath, app);
app = Path.join(deploy_workspace.getRootPath(), app);
}
app = Path.resolve(app);

Expand Down
5 changes: 4 additions & 1 deletion src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import * as deploy_contracts from './contracts';
import * as deploy_helpers from './helpers';
import * as deploy_workspace from './workspace';
import * as Events from 'events';
import * as i18 from './i18';
import * as vscode from 'vscode';
Expand All @@ -42,6 +43,8 @@ export function createPluginContext(baseCtx?: deploy_contracts.DeployContext): d

let hasCancelled = false;

const WORKSPACE_ROOT = deploy_workspace.getRootPath();

let ctx: deploy_contracts.DeployContext;
ctx = {
config: null,
Expand Down Expand Up @@ -118,7 +121,7 @@ export function createPluginContext(baseCtx?: deploy_contracts.DeployContext): d
return this;
},
workspace: function() {
return vscode.workspace.rootPath;
return WORKSPACE_ROOT;
},
write: function(msg) {
msg = deploy_helpers.toStringSafe(msg);
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as deploy_contracts from '../contracts';
import * as deploy_helpers from '../helpers';
import * as deploy_objects from '../objects';
import * as deploy_values from '../values';
import * as deploy_workspace from '../workspace';
import * as i18 from '../i18';
import * as Path from 'path';
import * as vscode from 'vscode';
Expand All @@ -46,7 +47,7 @@ function createAppArgsList(file: string, app: string, args: string[]): string[]

if (app) {
if (!Path.isAbsolute(app)) {
app = Path.join(vscode.workspace.rootPath, app);
app = Path.join(deploy_workspace.getRootPath(), app);
}
}

Expand Down Expand Up @@ -124,7 +125,7 @@ class AppPlugin extends deploy_objects.MultiFileDeployPluginBase {
}

if (!Path.isAbsolute(app)) {
app = Path.join(vscode.workspace.rootPath, app);
app = Path.join(deploy_workspace.getRootPath(), app);
}
app = Path.resolve(app);

Expand Down
5 changes: 3 additions & 2 deletions src/plugins/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import * as deploy_contracts from '../contracts';
import * as deploy_helpers from '../helpers';
import * as deploy_objects from '../objects';
import * as deploy_workspace from '../workspace';
import * as FS from 'fs';
import * as FSExtra from 'fs-extra';
import * as i18 from '../i18';
Expand Down Expand Up @@ -158,7 +159,7 @@ class LocalPlugin extends deploy_objects.DeployPluginBase {
let targetDir = deploy_helpers.toStringSafe(target.dir);
targetDir = me.context.replaceWithValues(targetDir);
if (!Path.isAbsolute(targetDir)) {
targetDir = Path.join(vscode.workspace.rootPath, targetDir);
targetDir = Path.join(deploy_workspace.getRootPath(), targetDir);
}

let hasCancelled = false;
Expand Down Expand Up @@ -386,7 +387,7 @@ function getFullDirPathFromTarget(target: DeployTargetLocal,
}

if (!Path.isAbsolute(dir)) {
dir = Path.join(vscode.workspace.rootPath, dir);
dir = Path.join(deploy_workspace.getRootPath(), dir);
}

return dir;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import * as deploy_contracts from '../contracts';
import * as deploy_helpers from '../helpers';
import * as deploy_objects from '../objects';
import * as deploy_workspace from '../workspace';
import * as i18 from '../i18';
import * as Path from 'path';
import * as vscode from 'vscode';
Expand Down Expand Up @@ -344,7 +345,7 @@ function getScriptFile(target: DeployTargetPipeline, plugin: PipelinePlugin): st
}

if (!Path.isAbsolute(scriptFile)) {
scriptFile = Path.join(vscode.workspace.rootPath, scriptFile);
scriptFile = Path.join(deploy_workspace.getRootPath(), scriptFile);
}

return scriptFile;
Expand Down
Loading

0 comments on commit b95cdde

Please sign in to comment.