Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add posh support. #33

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/kuduscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function addDeploymentScriptOptions(command) {
.option('--dotNetConsole <projectFilePath>', 'Create a deployment script for .NET console application, specify the project file path')
.option('-s, --solutionFile [file path]', 'The solution file path (sln)')
.option('-p, --sitePath [directory path]', 'The path to the site being deployed (default: same as repositoryRoot)')
.option('-t, --scriptType [batch|bash]', 'The script output type (default: batch)')
.option('-t, --scriptType [batch|bash|posh]', 'The script output type (default: batch)')
.option('-o, --outputPath <output path>', 'The path to output generated script (default: same as repository root)')
.option('-y, --suppressPrompt', 'Suppresses prompting to confirm you want to overwrite an existing destination file.')
.option('--no-dot-deployment', 'Do not generate the .deployment file.')
Expand Down
134 changes: 89 additions & 45 deletions lib/generator._js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ var confirm = function () { return false; };

var ScriptType = {
batch: 'BATCH',
bash: 'BASH'
bash: 'BASH',
posh: 'POSH'
};

var ProjectType = {
Expand Down Expand Up @@ -59,17 +60,17 @@ function ScriptGenerator(repositoryRoot, projectType, projectPath, solutionPath,
if (!scriptType) {
// If no script type is passed, use the default one
if (projectType === ProjectType.wap || projectType === ProjectType.website || projectType === ProjectType.aspNet5 || projectType === ProjectType.python || projectType === ProjectType.go) {
// For .NET the default script type is batch
scriptType = ScriptType.batch;
} else {
// Otherwise the default depends on the os
// For .NET the default script type is batch
scriptType = ScriptType.batch;
} else {
// Otherwise the default depends on the os
scriptType = isWindows ? ScriptType.batch : ScriptType.bash;
}
}
} else {
scriptType = scriptType.toUpperCase();
if (scriptType !== ScriptType.batch && scriptType !== ScriptType.bash) {
throw new Error('Script type should be either batch or bash');
}
scriptType = scriptType.toUpperCase();
if (scriptType !== ScriptType.batch && scriptType !== ScriptType.bash && scriptType !== ScriptType.posh) {
throw new Error('Script type should be either batch or bash or posh');
}
}
this.scriptType = scriptType;

Expand Down Expand Up @@ -214,8 +215,8 @@ ScriptGenerator.prototype.generatePythonDeploymentScript = function (_) {
ScriptGenerator.prototype.generateWapDeploymentScript = function (_) {
argNotNull(this.projectPath, 'projectPath');

if (this.scriptType != ScriptType.batch) {
throw new Error('Only batch script files are supported for .NET Web Application');
if (this.scriptType != ScriptType.batch && this.scriptType != ScriptType.posh) {
throw new Error('Only batch and posh script files are supported for .NET Web Application');
}

if (!this.solutionPath && !this.noSolution) {
Expand All @@ -224,25 +225,42 @@ ScriptGenerator.prototype.generateWapDeploymentScript = function (_) {

log.info('Generating deployment script for .NET Web Application');

var msbuildArguments = '"%DEPLOYMENT_SOURCE%\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="%DEPLOYMENT_TEMP%";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release',
msbuildArgumentsForInPlace = '"%DEPLOYMENT_SOURCE%\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release';
var msbuildArguments, msbuildArgumentsForInPlace;

if (this.solutionPath) {
var solutionDir = path.dirname(this.solutionPath),
solutionArgs = ' /p:SolutionDir="%DEPLOYMENT_SOURCE%\\' + solutionDir + '\\\\\"';
msbuildArguments += solutionArgs;
msbuildArgumentsForInPlace += solutionArgs;
if (this.scriptType == ScriptType.batch) {
msbuildArguments = '"%DEPLOYMENT_SOURCE%\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="%DEPLOYMENT_TEMP%";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release';
msbuildArgumentsForInPlace = '"%DEPLOYMENT_SOURCE%\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release';

if (this.solutionPath) {
var solutionDir = path.dirname(this.solutionPath),
solutionArgs = ' /p:SolutionDir="%DEPLOYMENT_SOURCE%\\' + solutionDir + '\\\\\"';
msbuildArguments += solutionArgs;
msbuildArgumentsForInPlace += solutionArgs;
}

msbuildArguments += ' %SCM_BUILD_ARGS%';
msbuildArgumentsForInPlace += ' %SCM_BUILD_ARGS%';
} else {
msbuildArguments = '"$DEPLOYMENT_SOURCE\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="$DEPLOYMENT_TEMP"`;AutoParameterizationWebConfigConnectionStrings=false`;Configuration=Release';
msbuildArgumentsForInPlace = '"$DEPLOYMENT_SOURCE\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false`;Configuration=Release';

if (this.solutionPath) {
var solutionDir = path.dirname(this.solutionPath),
solutionArgs = ' /p:SolutionDir="$DEPLOYMENT_SOURCE\\' + solutionDir + '\\\\\"';
msbuildArguments += solutionArgs;
msbuildArgumentsForInPlace += solutionArgs;
}

msbuildArguments += ' $env:SCM_BUILD_ARGS';
msbuildArgumentsForInPlace += ' $env:SCM_BUILD_ARGS';
}

msbuildArguments += ' %SCM_BUILD_ARGS%';
msbuildArgumentsForInPlace += ' %SCM_BUILD_ARGS%';

var options = {
msbuildArguments: msbuildArguments,
msbuildArgumentsForInPlace: msbuildArgumentsForInPlace
};
msbuildArguments: msbuildArguments,
msbuildArgumentsForInPlace: msbuildArgumentsForInPlace
};

this.generateDotNetDeploymentScript('deploy.batch.aspnet.wap.template', options, _);
this.generateDotNetDeploymentScript('aspnet.wap.template', options, _);
};

ScriptGenerator.prototype.generateAspNet5DeploymentScript = function (_) {
Expand Down Expand Up @@ -281,8 +299,8 @@ ScriptGenerator.prototype.generateDnxConsoleAppDeploymentScript = function (_) {
ScriptGenerator.prototype.generateDotNetConsoleDeploymentScript = function (_) {
argNotNull(this.projectPath, 'projectPath');

if (this.scriptType != ScriptType.batch) {
throw new Error('Only batch script files are supported for .NET Web Application');
if (this.scriptType != ScriptType.batch && this.scriptType != ScriptType.posh) {
throw new Error('Only batch and posh script files are supported for .NET Web Application');
}

if (!this.solutionPath && !this.noSolution) {
Expand All @@ -291,35 +309,56 @@ ScriptGenerator.prototype.generateDotNetConsoleDeploymentScript = function (_) {

log.info('Generating deployment script for .NET console application');

var msbuildArguments = '"%DEPLOYMENT_SOURCE%\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:Configuration=Release;OutputPath="%DEPLOYMENT_TEMP%\\app_data\\jobs\\continuous\\deployedJob"';
var msbuildArguments;

if (this.solutionPath) {
var solutionDir = path.dirname(this.solutionPath),
solutionArgs = ' /p:SolutionDir="%DEPLOYMENT_SOURCE%\\' + solutionDir + '\\\\\"';
msbuildArguments += solutionArgs;
}
if (this.scriptType == ScriptType.batch) {
msbuildArguments = '"%DEPLOYMENT_SOURCE%\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:Configuration=Release;OutputPath="%DEPLOYMENT_TEMP%\\app_data\\jobs\\continuous\\deployedJob"';

if (this.solutionPath) {
var solutionDir = path.dirname(this.solutionPath),
solutionArgs = ' /p:SolutionDir="%DEPLOYMENT_SOURCE%\\' + solutionDir + '\\\\\"';
msbuildArguments += solutionArgs;
}

msbuildArguments += ' %SCM_BUILD_ARGS%';
msbuildArguments += ' %SCM_BUILD_ARGS%';
} else {
msbuildArguments = '"$DEPLOYMENT_SOURCE\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:Configuration=Release`;OutputPath="$DEPLOYMENT_TEMP\\app_data\\jobs\\continuous\\deployedJob"';

if (this.solutionPath) {
var solutionDir = path.dirname(this.solutionPath),
solutionArgs = ' /p:SolutionDir="$DEPLOYMENT_SOURCE\\' + solutionDir + '\\\\\"';
msbuildArguments += solutionArgs;
}

msbuildArguments += ' $env:SCM_BUILD_ARGS';
}

var options = {
msbuildArguments: msbuildArguments,
msbuildArgumentsForInPlace: msbuildArguments
};

this.generateDotNetDeploymentScript('deploy.batch.dotnetconsole.template', options, _);
this.generateDotNetDeploymentScript('dotnetconsole.template', options, _);
};

ScriptGenerator.prototype.generateWebSiteDeploymentScript = function (_) {
if (this.solutionPath) {
// Solution based website (.NET)
log.info('Generating deployment script for .NET Web Site');

if (this.scriptType != ScriptType.batch) {
throw new Error('Only batch script files are supported for .NET Web Site');
if (this.scriptType != ScriptType.batch && this.scriptType != ScriptType.posh) {
throw new Error('Only batch and posh script files are supported for .NET Web Site');
}

var msbuildArguments = '"%DEPLOYMENT_SOURCE%\\' + fixPathSeperatorToWindows(this.solutionPath) + '" /verbosity:m /nologo %SCM_BUILD_ARGS%';
this.generateDotNetDeploymentScript('deploy.batch.aspnet.website.template', { msbuildArguments: msbuildArguments }, _);
var msbuildArguments;

if (this.scriptType == ScriptType.batch) {
msbuildArguments = '"%DEPLOYMENT_SOURCE%\\' + fixPathSeperatorToWindows(this.solutionPath) + '" /verbosity:m /nologo %SCM_BUILD_ARGS%';
} else {
msbuildArguments = '"$DEPLOYMENT_SOURCE\\' + fixPathSeperatorToWindows(this.solutionPath) + '" /verbosity:m /nologo $env:SCM_BUILD_ARGS';
}

this.generateDotNetDeploymentScript('aspnet.website.template', { msbuildArguments: msbuildArguments }, _);
} else {
// Basic website
log.info('Generating deployment script for Web Site');
Expand All @@ -343,14 +382,15 @@ ScriptGenerator.prototype.generateBasicDeploymentScript = function (templateFile

ScriptGenerator.prototype.generateDotNetDeploymentScript = function (templateFileName, options, _) {
argNotNull(templateFileName, 'templateFileName');



var lowerCaseScriptType = this.scriptType.toLowerCase();
var solutionDir = this.solutionPath ? path.dirname(this.solutionPath) : '';
var templateContent = getTemplatesContent([
'deploy.batch.prefix.template',
'deploy.batch.aspnet.template',
templateFileName,
'deploy.batch.postfix.template'
'deploy.' + lowerCaseScriptType + '.prefix.template',
'deploy.' + lowerCaseScriptType + '.aspnet.template',
'deploy.' + lowerCaseScriptType + '.' + templateFileName,
'deploy.' + lowerCaseScriptType + '.postfix.template'
]).replace(/{MSBuildArguments}/g, options.msbuildArguments || "")
.replace(/{MSBuildArgumentsForInPlace}/g, options.msbuildArgumentsForInPlace || "")
.replace(/{SolutionPath}/g, this.solutionPath || "")
Expand Down Expand Up @@ -425,6 +465,10 @@ ScriptGenerator.prototype.writeDeploymentFiles = function (templateContent, _) {
deployScriptFileName = 'deploy.cmd';
deploymentCommand = deployScriptFileName;
templateContent = fixLineEndingsToWindows(templateContent);
} else if (this.scriptType == ScriptType.posh) {
deployScriptFileName = 'deploy.ps1';
deploymentCommand = 'powershell -NoProfile -NoLogo -ExecutionPolicy Unrestricted -File ' + deployScriptFileName;
templateContent = fixLineEndingsToWindows(templateContent);
} else {
deployScriptFileName = 'deploy.sh';
deploymentCommand = 'bash ' + deployScriptFileName;
Expand Down
Loading