├── .gitattributes ├── .gitignore ├── .npmignore ├── README.markdown ├── bin ├── kuduscript └── kuduscript.js ├── build.cmd ├── lib ├── generator._js ├── generator.js ├── polyfill.js └── templates │ ├── deploy.bash.aspnet.core.template │ ├── deploy.bash.aspnet.template │ ├── deploy.bash.basic.template │ ├── deploy.bash.functionbasic.template │ ├── deploy.bash.go.template │ ├── deploy.bash.node.template │ ├── deploy.bash.php.template │ ├── deploy.bash.postfix.template │ ├── deploy.bash.prefix.template │ ├── deploy.bash.python.template │ ├── deploy.bash.ruby.template │ ├── deploy.batch.aspnet.core.msbuild16.template │ ├── deploy.batch.aspnet.core.msbuild1607.template │ ├── deploy.batch.aspnet.core.template │ ├── deploy.batch.aspnet.template │ ├── deploy.batch.aspnet.wap.template │ ├── deploy.batch.aspnet.website.template │ ├── deploy.batch.basic.template │ ├── deploy.batch.dotnetconsole.msbuild16.template │ ├── deploy.batch.dotnetconsole.msbuild1607.template │ ├── deploy.batch.dotnetconsole.template │ ├── deploy.batch.function.msbuild16.template │ ├── deploy.batch.function.msbuild1607.template │ ├── deploy.batch.functionbasic.template │ ├── deploy.batch.functionmsbuild.template │ ├── deploy.batch.node.template │ ├── deploy.batch.postfix.template │ ├── deploy.batch.prefix.template │ ├── deploy.batch.python.template │ ├── deploy.posh.aspnet.core.template │ ├── deploy.posh.aspnet.template │ ├── deploy.posh.aspnet.wap.template │ ├── deploy.posh.aspnet.website.template │ ├── deploy.posh.basic.template │ ├── deploy.posh.dotnetconsole.template │ ├── deploy.posh.node.template │ ├── deploy.posh.postfix.template │ └── deploy.posh.prefix.template ├── npmpublish.cmd ├── package-lock.json ├── package.json ├── smoketest.cmd ├── test.cmd └── test └── smokeTest.js /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js text=auto 2 | kuduscript eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.cache 2 | _ReSharper.* 3 | *.csproj.user 4 | *[Rr]e[Ss]harper.user 5 | _ReSharper.*/ 6 | node_packages/* 7 | node_modules/* 8 | *.log 9 | *.map 10 | deploy.sh 11 | deploy.cmd 12 | .deployment 13 | .vscode 14 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # git # 2 | .git* 3 | 4 | # Node # 5 | node_modules/ 6 | 7 | lib/*._js 8 | build.cmd 9 | *.map 10 | npmpublish.cmd 11 | 12 | deploy.sh 13 | deploy.cmd 14 | .deployment 15 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | ### Kudu Script 2 | 3 | Tool for generating deployment scripts for Azure Websites 4 | 5 | Here is the workflow to make fixes and propagate them: 6 | 7 | - Make fix and commit it to this repo 8 | - Run `npmpublish.cmd` to publish it to npm and create a tag with a new version. Check that the new version is on https://www.npmjs.com/package/kuduscript 9 | - Push the fix to this repo. Use `git push --follow-tags` to push the new tag 10 | - Go to https://github.com/Azure/azure-xplat-cli/blob/dev/package.json and send a PR to update the kuduscript reference to the new version. This will make it available in the xplat tool 11 | - Change https://github.com/projectkudu/kudu/blob/master/Kudu.Services.Web/updateNodeModules.cmd to point to the new kuduscript commit. This will make Kudu use it 12 | 13 | This project is under the benevolent umbrella of the [.NET Foundation](http://www.dotnetfoundation.org/). 14 | -------------------------------------------------------------------------------- /bin/kuduscript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Copyright (c) Outercurve Foundation. All rights reserved. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | var ks = require('./kuduscript.js'); 19 | ks.main(); 20 | -------------------------------------------------------------------------------- /bin/kuduscript.js: -------------------------------------------------------------------------------- 1 | var commander = require('commander'); 2 | var generator = require('../lib/generator'); 3 | if (!String.prototype.endsWith) { 4 | String.prototype.endsWith = require('../lib/polyfill.js').endsWith; 5 | } 6 | var version = require('../package.json').version; 7 | 8 | function addDeploymentScriptOptions(command) { 9 | command 10 | .usage('[options]') 11 | .description('Generate custom deployment script') 12 | .option('-r, --repositoryRoot [dir path]', 'The root path for the repository (default: .)') 13 | .option('--aspWAP ', 'Create a deployment script for .NET web application, specify the project file path') 14 | .option('--aspNetCore ', 'Create a deployment script for ASP.NET Core web application, specify the project file path') // could be project.json, xproj, csproj 15 | .option('--aspNetCoreMSBuild16 ', 'Create a deployment script for ASP.NET Core web application using MSBuild16, specify the project file path') // could be project.json, xproj, csproj 16 | .option('--aspWebSite', 'Create a deployment script for basic website') 17 | .option('--go', 'Create a deployment script for Go website') 18 | .option('--node', 'Create a deployment script for node.js website') 19 | .option('--ruby', 'Create a deployment script for ruby website') 20 | .option('--php', 'Create a deployment script for php website') 21 | .option('--python', 'Create a deployment script for python website') 22 | .option('--functionApp [projectFilePath]', 'Create a deployment script for function App, specify the project file path if using msbuild') 23 | .option('--functionAppMSBuild16 [projectFilePath]', 'Create a deployment script for function App using MSBuild16, specify the project file path if using msbuild') 24 | .option('--basic', 'Create a deployment script for any other website') 25 | .option('--dotNetConsole ', 'Create a deployment script for .NET console application, specify the project file path') 26 | .option('--dotNetConsoleMSBuild16 ', 'Create a deployment script for .NET console application using MSBuild16, specify the project file path') 27 | .option('-s, --solutionFile ', 'The solution file path (sln)') 28 | .option('-p, --sitePath ', 'The path to the site being deployed (default: same as repositoryRoot)') 29 | .option('-t, --scriptType ', 'The script output type (default: batch)') 30 | .option('-o, --outputPath ', 'The path to output generated script (default: same as repository root)') 31 | .option('-y, --suppressPrompt', 'Suppresses prompting to confirm you want to overwrite an existing destination file.') 32 | .option('--no-dot-deployment', 'Do not generate the .deployment file.') 33 | .option('--no-solution', 'Do not require a solution file path (only for --aspWAP otherwise ignored).') 34 | .option('--aspNetCoreMSBuild1607 ', 'Create a deployment script for ASP.NET Core web application using MSBuild16.7.0, specify the project file path') // could be project.json, xproj, csproj; 35 | .option('--dotNetConsoleMSBuild1607 ', 'Create a deployment script for .NET console application using MSBuild16.7.0, specify the project file path') 36 | .option('--functionAppMSBuild1607 [projectFilePath]', 'Create a deployment script for function App using MSBuild16.7.0, specify the project file path if using msbuild') 37 | } 38 | 39 | function tryOptionalInput(argument) { 40 | // if argument == true, means option is specified, but optional input IS NOT provided 41 | // if argument != true, value of its optional input is stored in argument 42 | return argument === true ? undefined : argument; 43 | } 44 | 45 | function deploymentScriptExecute(name, options, log, confirm, _) { 46 | var repositoryRoot = options.repositoryRoot || '.'; 47 | var outputPath = options.outputPath || repositoryRoot; 48 | var scriptType = options.scriptType; 49 | var projectFile = options.aspWAP || options.dotNetConsole || options.aspNetCore || 50 | options.dotNetConsoleMSBuild16 || options.aspNetCoreMSBuild16 || options.aspNetCoreMSBuild1607 || 51 | options.dotNetConsoleMSBuild1607 || tryOptionalInput(options.functionApp) || tryOptionalInput(options.functionAppMSBuild16) || tryOptionalInput(options.functionAppMSBuild1607); 52 | var solutionFile = options.solutionFile; 53 | var sitePath = options.sitePath || repositoryRoot; 54 | var noDotDeployment = options.dotDeployment === false; 55 | var noSolution = options.solution === false; 56 | 57 | var exclusionFlags = [options.aspWAP, options.php, options.python, options.aspWebSite, options.node, options.ruby, 58 | options.basic, options.functionApp, options.dotNetConsole, options.aspNetCore, options.go, 59 | options.functionAppMSBuild16, options.functionAppMSBuild1607, options.dotNetConsoleMSBuild16, options.dotNetConsoleMSBuild1607, options.aspNetCoreMSBuild16, options.aspNetCoreMSBuild1607] ; 60 | var flagCount = 0; 61 | for (var i in exclusionFlags) { 62 | if (exclusionFlags[i]) { 63 | flagCount++; 64 | } 65 | } 66 | 67 | if (flagCount === 0) { 68 | options.helpInformation(); 69 | log.help(''); 70 | log.help('Please specify one of these flags: --aspWAP, --aspNetCore, --aspWebSite, --php, --python, --dotNetConsole, ' + 71 | '--basic, --ruby, --functionApp, --node, --aspNetCoreMSBuild16, --aspNetCoreMSBuild1607, --dotNetConsoleMSBuild16, --dotNetConsoleMSBuild1607, --functionAppMSBuild1607 or --functionAppMSBuild16'); 72 | return; 73 | } else if (flagCount > 1) { 74 | throw new Error('Please specify only one of these flags: --aspWAP, --aspNetCore, --aspWebSite, --php, --python, --dotNetConsole, ' + 75 | '--basic, --ruby, --functionApp, --node, --aspNetCoreMSBuild16, --aspNetCoreMSBuild1607, --dotNetConsoleMSBuild16, --dotNetConsoleMSBuild1607, --functionAppMSBuild1607 or --functionAppMSBuild16'); 76 | } 77 | 78 | var projectType; 79 | if (options.aspWAP) { 80 | projectType = generator.ProjectType.wap; 81 | } else if (options.aspNetCore) { 82 | projectType = generator.ProjectType.aspNetCore; 83 | } else if (options.aspNetCoreMSBuild16) { 84 | projectType = generator.ProjectType.aspNetCoreMSBuild16; 85 | } else if(options.aspNetCoreMSBuild1607){ 86 | projectType = generator.ProjectType.aspNetCoreMSBuild1607; 87 | } else if (options.aspWebSite) { 88 | projectType = generator.ProjectType.website; 89 | } else if (options.go) { 90 | projectType = generator.ProjectType.go; 91 | } else if (options.node) { 92 | projectType = generator.ProjectType.node; 93 | } else if (options.python) { 94 | projectType = generator.ProjectType.python; 95 | } else if (options.dotNetConsole) { 96 | projectType = generator.ProjectType.dotNetConsole; 97 | } else if (options.dotNetConsoleMSBuild16) { 98 | projectType = generator.ProjectType.dotNetConsoleMSBuild16; 99 | } else if (options.dotNetConsoleMSBuild1607) { 100 | projectType = generator.ProjectType.dotNetConsoleMSBuild1607; 101 | } else if (options.functionApp) { 102 | projectType = generator.ProjectType.functionApp; 103 | } else if (options.functionAppMSBuild16) { 104 | projectType = generator.ProjectType.functionAppMSBuild16; 105 | } else if (options.functionAppMSBuild1607) { 106 | projectType = generator.ProjectType.functionAppMSBuild1607; 107 | } else if (options.ruby) { 108 | projectType = generator.ProjectType.ruby; 109 | } else if (options.php) { 110 | projectType = generator.ProjectType.php; 111 | } else { 112 | projectType = generator.ProjectType.basic; 113 | } 114 | 115 | var confirmFunc = confirm; 116 | if (options.suppressPrompt) { 117 | confirmFunc = function (message, callback) { callback(undefined, true); }; 118 | } 119 | 120 | var scriptGenerator = new generator.ScriptGenerator(repositoryRoot, projectType, projectFile, solutionFile, sitePath, scriptType, outputPath, noDotDeployment, noSolution, log, confirmFunc); 121 | scriptGenerator.generateDeploymentScript(_); 122 | } 123 | 124 | var log = {}; 125 | log.info = function (msg) { 126 | console.log(msg); 127 | }; 128 | log.help = function (msg) { 129 | console.log(msg); 130 | }; 131 | log.error = function (msg) { 132 | console.error("error: " + msg); 133 | }; 134 | 135 | function main() { 136 | commander.version(version); 137 | 138 | addDeploymentScriptOptions(commander); 139 | 140 | commander.parse(process.argv); 141 | 142 | if (!commander.suppressPrompt) { 143 | log.error('Unsuppressed prompt mode is not supported, please add -y flag'); 144 | process.exit(1); 145 | } 146 | 147 | deploymentScriptExecute( 148 | '', 149 | commander, 150 | log, 151 | null, 152 | function (err) { 153 | if (err) { 154 | log.error(err.message); 155 | process.exit(1); 156 | } 157 | process.exit(0); 158 | }); 159 | } 160 | 161 | exports.addDeploymentScriptOptions = addDeploymentScriptOptions; 162 | exports.deploymentScriptExecute = deploymentScriptExecute; 163 | exports.main = main; 164 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | call npm install 4 | 5 | echo Building streamline _js files 6 | call npm run-script build 7 | -------------------------------------------------------------------------------- /lib/generator._js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | var package = require('../package.json'); 17 | 18 | var fs = require('fs'); 19 | var path = require('path'); 20 | 21 | var isWindows = process.platform === 'win32'; 22 | 23 | // Making sure this works on node 0.6.20 as well as 0.8 24 | fs.existsSync = fs.existsSync || path.existsSync; 25 | path.sep = path.sep || (isWindows ? '\\' : '/'); 26 | 27 | var templatesDir = path.join(__dirname, 'templates'); 28 | var log = { info: function () { } }; 29 | var confirm = function () { return false; }; 30 | 31 | var ScriptType = { 32 | batch: 'BATCH', 33 | bash: 'BASH', 34 | posh: 'POSH' 35 | }; 36 | 37 | var ProjectType = { 38 | wap: 'WAP', 39 | website: 'WEBSITE', 40 | node: 'NODE', 41 | python: 'PYTHON', 42 | basic: 'BASIC', 43 | functionApp: 'FUNCTIONAPP', 44 | dotNetConsole: 'DOT_NET_CONSOLE', 45 | aspNetCore: 'ASP_NET_CORE', 46 | functionAppMSBuild16: 'FUNCTION_APP_MSBUILD16', 47 | dotNetConsoleMSBuild16: 'DOT_NET_CONSOLE_MSBUILD16', 48 | aspNetCoreMSBuild16: 'ASP_NET_CORE_MSBUILD16', 49 | aspNetCoreMSBuild1607: 'ASP_NET_CORE_MSBUILD1607', 50 | dotNetConsoleMSBuild1607: 'DOT_NET_CONSOLE_MSBUILD1607', 51 | functionAppMSBuild1607: 'FUNCTION_APP_MSBUILD1607', 52 | go: 'GO', 53 | ruby: "RUBY", 54 | php: "PHP" 55 | }; 56 | 57 | exports.ScriptType = ScriptType; 58 | exports.ProjectType = ProjectType; 59 | 60 | function ScriptGenerator(repositoryRoot, projectType, projectPath, solutionPath, sitePath, scriptType, scriptOutputPath, noDotDeployment, noSolution, logger, confirmFunc) { 61 | argNotNull(repositoryRoot, 'repositoryRoot'); 62 | argNotNull(scriptOutputPath, 'scriptOutputPath'); 63 | argNotNull(projectType, 'projectType'); 64 | argNotNull(sitePath, 'sitePath'); 65 | 66 | projectType = projectType.toUpperCase(); 67 | 68 | if (!scriptType) { 69 | // If no script type is passed, use the default one 70 | if (projectType === ProjectType.wap || projectType === ProjectType.website) { 71 | // For .NET the default script type is batch 72 | scriptType = ScriptType.batch; 73 | } else { 74 | // Otherwise the default depends on the os 75 | scriptType = isWindows ? ScriptType.batch : ScriptType.bash; 76 | } 77 | } else { 78 | scriptType = scriptType.toUpperCase(); 79 | if (scriptType !== ScriptType.batch && scriptType !== ScriptType.bash && scriptType !== ScriptType.posh) { 80 | throw new Error('Script type should be either batch or bash or posh'); 81 | } 82 | } 83 | this.scriptType = scriptType; 84 | 85 | log = logger || log; 86 | confirm = confirmFunc || confirm; 87 | 88 | if (projectPath) { 89 | if (!isPathSubDir(repositoryRoot, projectPath)) { 90 | throw new Error('The project file path should be a sub-directory of the repository root'); 91 | } 92 | 93 | var relativeProjectPath = path.relative(repositoryRoot, projectPath); 94 | log.info('Project file path: .' + path.sep + relativeProjectPath); 95 | this.projectPath = relativeProjectPath; 96 | this.absoluteProjectPath = projectPath; 97 | } 98 | 99 | if (solutionPath) { 100 | if (!isPathSubDir(repositoryRoot, solutionPath)) { 101 | throw new Error('The solution file path should be the same as repository root or a sub-directory of it.'); 102 | } 103 | 104 | var relativeSolutionPath = path.relative(repositoryRoot, solutionPath); 105 | log.info('Solution file path: .' + path.sep + relativeSolutionPath); 106 | this.solutionPath = relativeSolutionPath; 107 | } 108 | 109 | if (!isPathSubDir(repositoryRoot, sitePath)) { 110 | throw new Error('The site directory path should be the same as repository root or a sub-directory of it.'); 111 | } 112 | 113 | var relativeSitePath = path.relative(repositoryRoot, sitePath); 114 | if (relativeSitePath) { 115 | relativeSitePath = path.sep + relativeSitePath; 116 | log.info('The site directory path: .' + relativeSitePath); 117 | } 118 | this.sitePath = relativeSitePath || ''; 119 | 120 | this.repositoryRoot = repositoryRoot; 121 | this.scriptOutputPath = scriptOutputPath; 122 | this.projectType = projectType; 123 | this.noDotDeployment = noDotDeployment; 124 | this.noSolution = noSolution; 125 | this.absoluteSitePath = path.join(this.repositoryRoot, this.sitePath); 126 | 127 | this.generators = []; 128 | this.generators[ProjectType.wap] = generateWapDeploymentScript; 129 | this.generators[ProjectType.website] = generateWebSiteDeploymentScript; 130 | this.generators[ProjectType.node] = generateNodeDeploymentScript; 131 | this.generators[ProjectType.python] = generatePythonDeploymentScript; 132 | this.generators[ProjectType.basic] = generateBasicWebSiteDeploymentScript; 133 | this.generators[ProjectType.functionApp] = generateFunctionAppDeploymentScript; 134 | this.generators[ProjectType.dotNetConsole] = generateDotNetConsoleDeploymentScript; 135 | this.generators[ProjectType.aspNetCore] = generateAspNetCoreDeploymentScript; 136 | this.generators[ProjectType.functionAppMSBuild16] = generateFunctionAppMSBuild16DeploymentScript; 137 | this.generators[ProjectType.functionAppMSBuild1607] = generateFunctionAppMSBuild1607DeploymentScript; 138 | this.generators[ProjectType.dotNetConsoleMSBuild16] = generateDotNetConsoleMSBuild16DeploymentScript; 139 | this.generators[ProjectType.aspNetCoreMSBuild16] = generateAspNetCoreMSBuild16DeploymentScript; 140 | this.generators[ProjectType.aspNetCoreMSBuild1607] = generateAspNetCoreMSBuild1607DeploymentScript; 141 | this.generators[ProjectType.dotNetConsoleMSBuild1607] = generateDotNetConsoleMSBuild1607DeploymentScript; 142 | this.generators[ProjectType.go] = generateGoDeploymentScript; 143 | this.generators[ProjectType.ruby] = generateRubyDeploymentScript; 144 | this.generators[ProjectType.php] = generatePHPDeploymentScript; 145 | } 146 | 147 | function generateGoDeploymentScript(scriptGenerator, _) { 148 | scriptGenerator.generateGoDeploymentScript(_); 149 | } 150 | 151 | function generateAspNetCoreDeploymentScript(scriptGenerator, _) { 152 | scriptGenerator.generateAspNetCoreDeploymentScript(_); 153 | } 154 | 155 | function generateDotNetConsoleDeploymentScript(scriptGenerator, _) { 156 | scriptGenerator.generateDotNetConsoleDeploymentScript(_); 157 | } 158 | 159 | function generateAspNetCoreMSBuild16DeploymentScript(scriptGenerator, _) { 160 | scriptGenerator.generateAspNetCoreMSBuild16DeploymentScript(_); 161 | } 162 | 163 | function generateAspNetCoreMSBuild1607DeploymentScript(scriptGenerator, _) { 164 | scriptGenerator.generateAspNetCoreMSBuild1607DeploymentScript(_); 165 | } 166 | 167 | function generateDotNetConsoleMSBuild16DeploymentScript(scriptGenerator, _) { 168 | scriptGenerator.generateDotNetConsoleMSBuild16DeploymentScript(_); 169 | } 170 | 171 | function generateDotNetConsoleMSBuild1607DeploymentScript(scriptGenerator, _) { 172 | scriptGenerator.generateDotNetConsoleMSBuild1607DeploymentScript(_); 173 | } 174 | 175 | function generateFunctionAppMSBuild16DeploymentScript(scriptGenerator, _) { 176 | scriptGenerator.generateFunctionAppMSBuild16DeploymentScript(_); 177 | } 178 | 179 | function generateFunctionAppMSBuild1607DeploymentScript(scriptGenerator, _) { 180 | scriptGenerator.generateFunctionAppMSBuild1607DeploymentScript(_); 181 | } 182 | 183 | function generateWapDeploymentScript(scriptGenerator, _) { 184 | scriptGenerator.generateWapDeploymentScript(_); 185 | } 186 | 187 | function generateWebSiteDeploymentScript(scriptGenerator, _) { 188 | scriptGenerator.generateWebSiteDeploymentScript(_); 189 | } 190 | 191 | function generateNodeDeploymentScript(scriptGenerator, _) { 192 | scriptGenerator.generateNodeDeploymentScript(_); 193 | } 194 | 195 | function generatePythonDeploymentScript(scriptGenerator, _) { 196 | scriptGenerator.generatePythonDeploymentScript(_); 197 | } 198 | 199 | function generateRubyDeploymentScript(scriptGenerator, _) { 200 | scriptGenerator.generateRubyDeploymentScript(_); 201 | } 202 | 203 | function generatePHPDeploymentScript(scriptGenerator, _) { 204 | scriptGenerator.generatePHPDeploymentScript(_); 205 | } 206 | 207 | function generateBasicWebSiteDeploymentScript(scriptGenerator, _) { 208 | if (scriptGenerator.solutionPath) { 209 | throw new Error('Solution path is not supported with this website type'); 210 | } 211 | scriptGenerator.generateWebSiteDeploymentScript(_); 212 | } 213 | 214 | function generateFunctionAppDeploymentScript(scriptGenerator, _) { 215 | scriptGenerator.generateFunctionAppDeploymentScript(_); 216 | } 217 | 218 | ScriptGenerator.prototype.generateDeploymentScript = function (_) { 219 | var generator = this.generators[this.projectType]; 220 | if (!generator) { 221 | throw new Error('Invalid project type received: ' + this.projectType); 222 | } 223 | 224 | generator(this, _); 225 | }; 226 | 227 | function isPathSubDir(parentPath, childPath) { 228 | var relativePath = path.relative(parentPath, childPath); 229 | 230 | // The parent path is actually the parent of the child path if the result of path.relative: 231 | // a. Doesn't contain '..' at the start 232 | // b. Doesn't equal to the child path entirely 233 | return relativePath.indexOf('..') !== 0 && 234 | relativePath !== path.resolve(childPath); 235 | } 236 | 237 | ScriptGenerator.prototype.generateGoDeploymentScript = function (_) { 238 | log.info('Generating deployment script for Go Web Site'); 239 | 240 | this.generateBasicDeploymentScript('go.template', _); 241 | }; 242 | 243 | ScriptGenerator.prototype.generateNodeDeploymentScript = function (_) { 244 | log.info('Generating deployment script for node.js Web Site'); 245 | 246 | this.generateBasicDeploymentScript('node.template', _); 247 | }; 248 | 249 | ScriptGenerator.prototype.generateFunctionAppDeploymentScript = function (_) { 250 | log.info('Generating deployment script for function App'); 251 | 252 | options = {} 253 | if (this.projectPath) { 254 | if (this.scriptType == ScriptType.bash) { 255 | throw new Error('csharp function targeting dotnet core is currently not supported'); 256 | // TODO add dotnet build template, restrict to function 2.0 257 | } 258 | options.projectPath = fixPathSeparatorToWindows(this.projectPath); 259 | if (this.solutionPath) { // nuget restore argument 260 | options.RestoreArguments = fixPathSeparatorToWindows(this.solutionPath); 261 | } else { 262 | options.RestoreArguments = options.projectPath; 263 | } 264 | this.generateFunctionAppScript('functionmsbuild.template', options, _); 265 | } else { 266 | if (this.scriptType == ScriptType.bash) { 267 | // this template should be able to handle all three kind of functions 268 | // node(tested), csx(tested), and csproj(cannot yet be created with function cli) 269 | options.sitePath = fixPathSeparatorToUnix(this.sitePath); 270 | } else { 271 | options.sitePath = fixPathSeparatorToWindows(this.sitePath); 272 | } 273 | this.generateFunctionAppScript('functionbasic.template', options, _); 274 | } 275 | }; 276 | 277 | ScriptGenerator.prototype.generateFunctionAppMSBuild1607DeploymentScript = function (_) { 278 | log.info('Generating deployment script for function MSBuild16 App'); 279 | 280 | options = {} 281 | if (this.scriptType == ScriptType.bash) { 282 | throw new Error('csharp function targeting dotnet core is currently not supported'); 283 | // TODO add dotnet build template, restrict to function 2.0 284 | } 285 | options.projectPath = fixPathSeparatorToWindows(this.projectPath); 286 | this.generateFunctionAppScript('function.msbuild1607.template', options, _); 287 | }; 288 | 289 | ScriptGenerator.prototype.generateFunctionAppMSBuild16DeploymentScript = function (_) { 290 | log.info('Generating deployment script for function MSBuild16 App'); 291 | 292 | options = {} 293 | if (this.scriptType == ScriptType.bash) { 294 | throw new Error('csharp function targeting dotnet core is currently not supported'); 295 | // TODO add dotnet build template, restrict to function 2.0 296 | } 297 | options.projectPath = fixPathSeparatorToWindows(this.projectPath); 298 | this.generateFunctionAppScript('function.msbuild16.template', options, _); 299 | }; 300 | 301 | ScriptGenerator.prototype.generatePythonDeploymentScript = function (_) { 302 | log.info('Generating deployment script for python Web Site'); 303 | 304 | this.generateBasicDeploymentScript('python.template', _); 305 | }; 306 | 307 | ScriptGenerator.prototype.generateRubyDeploymentScript = function (_) { 308 | log.info('Generating deployment script for Ruby Web Site'); 309 | 310 | this.generateBasicDeploymentScript('ruby.template', _); 311 | }; 312 | 313 | ScriptGenerator.prototype.generatePHPDeploymentScript = function (_) { 314 | log.info('Generating deployment script for PHP Web Site'); 315 | 316 | this.generateBasicDeploymentScript('php.template', _); 317 | }; 318 | 319 | ScriptGenerator.prototype.generateWapDeploymentScript = function (_) { 320 | argNotNull(this.projectPath, 'projectPath'); 321 | 322 | if (this.scriptType != ScriptType.batch && this.scriptType != ScriptType.posh) { 323 | throw new Error('Only batch and posh script files are supported for .NET Web Application'); 324 | } 325 | 326 | if (!this.solutionPath && !this.noSolution) { 327 | throw new Error('Missing solution file path (--solutionFile), to explicitly not require a solution use the flag --no-solution'); 328 | } 329 | 330 | log.info('Generating deployment script for .NET Web Application'); 331 | 332 | var msbuildArguments, msbuildArgumentsForInPlace; 333 | 334 | if (this.scriptType == ScriptType.batch) { 335 | msbuildArguments = '"%DEPLOYMENT_SOURCE%\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="%DEPLOYMENT_TEMP%";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false'; 336 | msbuildArgumentsForInPlace = '"%DEPLOYMENT_SOURCE%\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false'; 337 | 338 | if (this.solutionPath) { 339 | var solutionDir = path.dirname(this.solutionPath), 340 | solutionArgs = ' /p:SolutionDir="%DEPLOYMENT_SOURCE%\\' + solutionDir + '\\\\\"'; 341 | msbuildArguments += solutionArgs; 342 | msbuildArgumentsForInPlace += solutionArgs; 343 | } 344 | 345 | msbuildArguments += ' %SCM_BUILD_ARGS%'; 346 | msbuildArgumentsForInPlace += ' %SCM_BUILD_ARGS%'; 347 | } else { 348 | msbuildArguments = '"$DEPLOYMENT_SOURCE\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="$DEPLOYMENT_TEMP"`;AutoParameterizationWebConfigConnectionStrings=false`;Configuration=Release`;UseSharedCompilation=false'; 349 | msbuildArgumentsForInPlace = '"$DEPLOYMENT_SOURCE\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false`;Configuration=Release`;UseSharedCompilation=false'; 350 | 351 | if (this.solutionPath) { 352 | var solutionDir = path.dirname(this.solutionPath), 353 | solutionArgs = ' /p:SolutionDir="$DEPLOYMENT_SOURCE\\' + solutionDir + '\\\\\"'; 354 | msbuildArguments += solutionArgs; 355 | msbuildArgumentsForInPlace += solutionArgs; 356 | } 357 | 358 | msbuildArguments += ' $env:SCM_BUILD_ARGS'; 359 | msbuildArgumentsForInPlace += ' $env:SCM_BUILD_ARGS'; 360 | } 361 | 362 | var options = { 363 | msbuildArguments: msbuildArguments, 364 | msbuildArgumentsForInPlace: msbuildArgumentsForInPlace 365 | }; 366 | 367 | this.generateDotNetDeploymentScript('aspnet.wap.template', options, _); 368 | }; 369 | 370 | ScriptGenerator.prototype.generateAspNetCoreMSBuild16DeploymentScript = function (_) { 371 | log.info('Generating deployment script for ASP.NET MSBuild16 App'); 372 | 373 | options = {} 374 | options.projectPath = fixPathSeparatorToWindows(this.projectPath); 375 | this.generateAspNetCoreMSBuild16AppScript('aspnet.core.msbuild16.template', options, _); 376 | }; 377 | 378 | ScriptGenerator.prototype.generateAspNetCoreMSBuild1607DeploymentScript = function (_) { 379 | log.info('Generating deployment script for ASP.NET MSBuild16.7.0 App'); 380 | 381 | options = {} 382 | options.projectPath = fixPathSeparatorToWindows(this.projectPath); 383 | this.generateAspNetCoreMSBuild16AppScript('aspnet.core.msbuild1607.template', options, _); 384 | }; 385 | 386 | ScriptGenerator.prototype.generateAspNetCoreDeploymentScript = function (_) { 387 | argNotNull(this.absoluteProjectPath, 'absoluteProjectPath'); 388 | // no need to check scriptType since dotnet core is supported on both linux and windows 389 | 390 | // this.solutionPath and this.projectPath are both relative 391 | var options = {}; 392 | options.RestoreArguments = ((this.solutionPath) ? this.solutionPath : this.projectPath); 393 | options.DotnetpublishArguments = this.projectPath; 394 | 395 | this.generateAspNetCoreScript('aspnet.core.template', options, _); 396 | }; 397 | 398 | ScriptGenerator.prototype.generateDotNetConsoleMSBuild1607DeploymentScript = function (_) { 399 | argNotNull(this.projectPath, 'projectPath'); 400 | 401 | if (this.scriptType != ScriptType.batch && this.scriptType != ScriptType.posh) { 402 | throw new Error('Only batch and posh script files are supported for .NET Web Application'); 403 | } 404 | 405 | if (!this.solutionPath && !this.noSolution) { 406 | throw new Error('Missing solution file path (--solutionFile), to explicitly not require a solution use the flag --no-solution'); 407 | } 408 | 409 | log.info('Generating deployment script for .NET console application'); 410 | 411 | var msbuildArguments; 412 | 413 | if (this.scriptType == ScriptType.batch) { 414 | msbuildArguments = '"%DEPLOYMENT_SOURCE%\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:Configuration=Release;OutputPath="%DEPLOYMENT_TEMP%\\app_data\\jobs\\continuous\\deployedJob";UseSharedCompilation=false'; 415 | 416 | if (this.solutionPath) { 417 | var solutionDir = path.dirname(this.solutionPath), 418 | solutionArgs = ' /p:SolutionDir="%DEPLOYMENT_SOURCE%\\' + solutionDir + '\\\\\"'; 419 | msbuildArguments += solutionArgs; 420 | } 421 | 422 | msbuildArguments += ' %SCM_BUILD_ARGS%'; 423 | } else { 424 | msbuildArguments = '"$DEPLOYMENT_SOURCE\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:Configuration=Release`;OutputPath="$DEPLOYMENT_TEMP\\app_data\\jobs\\continuous\\deployedJob"`;UseSharedCompilation=false'; 425 | 426 | if (this.solutionPath) { 427 | var solutionDir = path.dirname(this.solutionPath), 428 | solutionArgs = ' /p:SolutionDir="$DEPLOYMENT_SOURCE\\' + solutionDir + '\\\\\"'; 429 | msbuildArguments += solutionArgs; 430 | } 431 | 432 | msbuildArguments += ' $env:SCM_BUILD_ARGS'; 433 | } 434 | 435 | var options = { 436 | msbuildArguments: msbuildArguments, 437 | msbuildArgumentsForInPlace: msbuildArguments 438 | }; 439 | 440 | this.generateDotNetDeploymentScript('dotnetconsole.msbuild1607.template', options, _); 441 | }; 442 | 443 | ScriptGenerator.prototype.generateDotNetConsoleMSBuild16DeploymentScript = function (_) { 444 | argNotNull(this.projectPath, 'projectPath'); 445 | 446 | if (this.scriptType != ScriptType.batch && this.scriptType != ScriptType.posh) { 447 | throw new Error('Only batch and posh script files are supported for .NET Web Application'); 448 | } 449 | 450 | if (!this.solutionPath && !this.noSolution) { 451 | throw new Error('Missing solution file path (--solutionFile), to explicitly not require a solution use the flag --no-solution'); 452 | } 453 | 454 | log.info('Generating deployment script for .NET console application'); 455 | 456 | var msbuildArguments; 457 | 458 | if (this.scriptType == ScriptType.batch) { 459 | msbuildArguments = '"%DEPLOYMENT_SOURCE%\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:Configuration=Release;OutputPath="%DEPLOYMENT_TEMP%\\app_data\\jobs\\continuous\\deployedJob";UseSharedCompilation=false'; 460 | 461 | if (this.solutionPath) { 462 | var solutionDir = path.dirname(this.solutionPath), 463 | solutionArgs = ' /p:SolutionDir="%DEPLOYMENT_SOURCE%\\' + solutionDir + '\\\\\"'; 464 | msbuildArguments += solutionArgs; 465 | } 466 | 467 | msbuildArguments += ' %SCM_BUILD_ARGS%'; 468 | } else { 469 | msbuildArguments = '"$DEPLOYMENT_SOURCE\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:Configuration=Release`;OutputPath="$DEPLOYMENT_TEMP\\app_data\\jobs\\continuous\\deployedJob"`;UseSharedCompilation=false'; 470 | 471 | if (this.solutionPath) { 472 | var solutionDir = path.dirname(this.solutionPath), 473 | solutionArgs = ' /p:SolutionDir="$DEPLOYMENT_SOURCE\\' + solutionDir + '\\\\\"'; 474 | msbuildArguments += solutionArgs; 475 | } 476 | 477 | msbuildArguments += ' $env:SCM_BUILD_ARGS'; 478 | } 479 | 480 | var options = { 481 | msbuildArguments: msbuildArguments, 482 | msbuildArgumentsForInPlace: msbuildArguments 483 | }; 484 | 485 | this.generateDotNetDeploymentScript('dotnetconsole.msbuild16.template', options, _); 486 | }; 487 | 488 | ScriptGenerator.prototype.generateDotNetConsoleDeploymentScript = function (_) { 489 | argNotNull(this.projectPath, 'projectPath'); 490 | 491 | if (this.scriptType != ScriptType.batch && this.scriptType != ScriptType.posh) { 492 | throw new Error('Only batch and posh script files are supported for .NET Web Application'); 493 | } 494 | 495 | if (!this.solutionPath && !this.noSolution) { 496 | throw new Error('Missing solution file path (--solutionFile), to explicitly not require a solution use the flag --no-solution'); 497 | } 498 | 499 | log.info('Generating deployment script for .NET console application'); 500 | 501 | var msbuildArguments; 502 | 503 | if (this.scriptType == ScriptType.batch) { 504 | msbuildArguments = '"%DEPLOYMENT_SOURCE%\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:Configuration=Release;OutputPath="%DEPLOYMENT_TEMP%\\app_data\\jobs\\continuous\\deployedJob";UseSharedCompilation=false'; 505 | 506 | if (this.solutionPath) { 507 | var solutionDir = path.dirname(this.solutionPath), 508 | solutionArgs = ' /p:SolutionDir="%DEPLOYMENT_SOURCE%\\' + solutionDir + '\\\\\"'; 509 | msbuildArguments += solutionArgs; 510 | } 511 | 512 | msbuildArguments += ' %SCM_BUILD_ARGS%'; 513 | } else { 514 | msbuildArguments = '"$DEPLOYMENT_SOURCE\\' + this.projectPath + '" /nologo /verbosity:m /t:Build /p:Configuration=Release`;OutputPath="$DEPLOYMENT_TEMP\\app_data\\jobs\\continuous\\deployedJob"`;UseSharedCompilation=false'; 515 | 516 | if (this.solutionPath) { 517 | var solutionDir = path.dirname(this.solutionPath), 518 | solutionArgs = ' /p:SolutionDir="$DEPLOYMENT_SOURCE\\' + solutionDir + '\\\\\"'; 519 | msbuildArguments += solutionArgs; 520 | } 521 | 522 | msbuildArguments += ' $env:SCM_BUILD_ARGS'; 523 | } 524 | 525 | var options = { 526 | msbuildArguments: msbuildArguments, 527 | msbuildArgumentsForInPlace: msbuildArguments 528 | }; 529 | 530 | this.generateDotNetDeploymentScript('dotnetconsole.template', options, _); 531 | }; 532 | 533 | ScriptGenerator.prototype.generateWebSiteDeploymentScript = function (_) { 534 | if (this.solutionPath) { 535 | // Solution based website (.NET) 536 | log.info('Generating deployment script for .NET Web Site'); 537 | 538 | if (this.scriptType != ScriptType.batch && this.scriptType != ScriptType.posh) { 539 | throw new Error('Only batch and posh script files are supported for .NET Web Site'); 540 | } 541 | 542 | var msbuildArguments; 543 | 544 | if (this.scriptType == ScriptType.batch) { 545 | msbuildArguments = '"%DEPLOYMENT_SOURCE%\\' + fixPathSeparatorToWindows(this.solutionPath) + '" /verbosity:m /nologo %SCM_BUILD_ARGS%'; 546 | } else { 547 | msbuildArguments = '"$DEPLOYMENT_SOURCE\\' + fixPathSeparatorToWindows(this.solutionPath) + '" /verbosity:m /nologo $env:SCM_BUILD_ARGS'; 548 | } 549 | 550 | this.generateDotNetDeploymentScript('aspnet.website.template', { msbuildArguments: msbuildArguments }, _); 551 | } else { 552 | // Basic website 553 | log.info('Generating deployment script for Web Site'); 554 | this.generateBasicDeploymentScript('basic.template', _); 555 | } 556 | }; 557 | 558 | ScriptGenerator.prototype.generateBasicDeploymentScript = function (templateFileName, _) { 559 | argNotNull(templateFileName, 'templateFileName'); 560 | 561 | var lowerCaseScriptType = this.scriptType.toLowerCase(); 562 | var fixedSitePath = this.scriptType === ScriptType.batch ? fixPathSeparatorToWindows(this.sitePath) : fixPathSeparatorToUnix(this.sitePath); 563 | var templateContent = getTemplatesContent([ 564 | 'deploy.' + lowerCaseScriptType + '.prefix.template', 565 | 'deploy.' + lowerCaseScriptType + '.' + templateFileName, 566 | 'deploy.' + lowerCaseScriptType + '.postfix.template' 567 | ]).replace(/{SitePath}/g, fixedSitePath); 568 | 569 | this.writeDeploymentFiles(templateContent, _); 570 | }; 571 | 572 | ScriptGenerator.prototype.generateFunctionAppScript = function (templateFileName, options, _) { 573 | argNotNull(templateFileName, 'templateFileName'); 574 | 575 | var lowerCaseScriptType = this.scriptType.toLowerCase(); 576 | var templateContent = getTemplatesContent([ 577 | 'deploy.' + lowerCaseScriptType + '.prefix.template', 578 | 'deploy.' + lowerCaseScriptType + '.' + templateFileName, 579 | 'deploy.' + lowerCaseScriptType + '.postfix.template' 580 | ]).replace(/{SitePath}/g, options.sitePath) 581 | .replace(/{RestoreArguments}/g, options.RestoreArguments) 582 | .replace(/{ProjectPath}/g, options.projectPath); 583 | 584 | this.writeDeploymentFiles(templateContent, _); 585 | } 586 | 587 | ScriptGenerator.prototype.generateDotNetDeploymentScript = function (templateFileName, options, _) { 588 | argNotNull(templateFileName, 'templateFileName'); 589 | 590 | 591 | var lowerCaseScriptType = this.scriptType.toLowerCase(); 592 | var solutionDir = this.solutionPath ? path.dirname(this.solutionPath) : ''; 593 | var templateContent = getTemplatesContent([ 594 | 'deploy.' + lowerCaseScriptType + '.prefix.template', 595 | 'deploy.' + lowerCaseScriptType + '.aspnet.template', 596 | 'deploy.' + lowerCaseScriptType + '.' + templateFileName, 597 | 'deploy.' + lowerCaseScriptType + '.postfix.template' 598 | ]).replace(/{MSBuildArguments}/g, options.msbuildArguments || "") 599 | .replace(/{MSBuildArgumentsForInPlace}/g, options.msbuildArgumentsForInPlace || "") 600 | .replace(/{SolutionPath}/g, this.solutionPath || "") 601 | .replace(/{SolutionDir}/g, solutionDir) 602 | .replace(/{SitePath}/g, fixPathSeparatorToWindows(this.sitePath)); 603 | 604 | this.writeDeploymentFiles(templateContent, _); 605 | }; 606 | 607 | ScriptGenerator.prototype.generateAspNetCoreMSBuild16AppScript = function (templateFileName, options, _) { 608 | argNotNull(templateFileName, 'templateFileName'); 609 | 610 | var lowerCaseScriptType = this.scriptType.toLowerCase(); 611 | var templateContent = getTemplatesContent([ 612 | 'deploy.' + lowerCaseScriptType + '.prefix.template', 613 | 'deploy.' + lowerCaseScriptType + '.' + templateFileName, 614 | 'deploy.' + lowerCaseScriptType + '.postfix.template' 615 | ]).replace(/{SitePath}/g, options.sitePath) 616 | .replace(/{ProjectPath}/g, options.projectPath); 617 | 618 | this.writeDeploymentFiles(templateContent, _); 619 | } 620 | 621 | ScriptGenerator.prototype.generateAspNetCoreScript = function (templateFileName, options, _) { 622 | argNotNull(templateFileName, 'templateFileName'); 623 | 624 | if (this.scriptType === ScriptType.batch) { 625 | for (var prop in options) { 626 | options[prop] = fixPathSeparatorToWindows(options[prop]) 627 | } 628 | } else { 629 | for (var prop in options) { 630 | options[prop] = fixPathSeparatorToUnix(options[prop]) 631 | } 632 | } 633 | 634 | var lowerCaseScriptType = this.scriptType.toLowerCase(); 635 | var templateContent = getTemplatesContent([ 636 | 'deploy.' + lowerCaseScriptType + '.prefix.template', 637 | 'deploy.' + lowerCaseScriptType + '.aspnet.template', 638 | 'deploy.' + lowerCaseScriptType + '.' + templateFileName, 639 | 'deploy.' + lowerCaseScriptType + '.postfix.template' 640 | ]).replace(/{DotnetpublishArguments}/g, options.DotnetpublishArguments) 641 | .replace(/{RestoreArguments}/g, options.RestoreArguments); 642 | 643 | this.writeDeploymentFiles(templateContent, _); 644 | }; 645 | 646 | function getTemplatesContent(fileNames) { 647 | var content = ''; 648 | 649 | for (var i in fileNames) { 650 | content += getTemplateContent(fileNames[i]); 651 | } 652 | 653 | content = content.replace(/{Version}/g, package.version); 654 | 655 | return content; 656 | } 657 | 658 | function fixPathSeparatorToWindows(pathStr) { 659 | return pathStr ? pathStr.replace(/\//g, '\\') : pathStr; 660 | } 661 | 662 | function fixPathSeparatorToUnix(pathStr) { 663 | return pathStr ? pathStr.replace(/\\/g, '/') : pathStr; 664 | } 665 | 666 | function fixLineEndingsToUnix(contentStr) { 667 | return contentStr.replace(/\r\n/g, '\n'); 668 | } 669 | 670 | function fixLineEndingsToWindows(contentStr) { 671 | return contentStr.replace(/(?:\r\n|\n)/g, '\r\n'); 672 | } 673 | 674 | ScriptGenerator.prototype.writeDeploymentFiles = function (templateContent, _) { 675 | argNotNull(templateContent, 'templateContent'); 676 | 677 | var deployScriptFileName; 678 | var deploymentCommand; 679 | if (this.scriptType == ScriptType.batch) { 680 | deployScriptFileName = 'deploy.cmd'; 681 | deploymentCommand = deployScriptFileName; 682 | templateContent = fixLineEndingsToWindows(templateContent); 683 | } else if (this.scriptType == ScriptType.posh) { 684 | deployScriptFileName = 'deploy.ps1'; 685 | deploymentCommand = 'powershell -NoProfile -NoLogo -ExecutionPolicy Unrestricted -Command "& "$pwd\\' + deployScriptFileName + '" 2>&1 | echo"'; 686 | templateContent = fixLineEndingsToWindows(templateContent); 687 | } else { 688 | deployScriptFileName = 'deploy.sh'; 689 | deploymentCommand = 'bash ' + deployScriptFileName; 690 | templateContent = fixLineEndingsToUnix(templateContent); 691 | } 692 | 693 | var deployScriptPath = path.join(this.scriptOutputPath, deployScriptFileName); 694 | var deploymentFilePath = path.join(this.repositoryRoot, '.deployment'); 695 | 696 | // Write the custom deployment script 697 | writeContentToFile(deployScriptPath, templateContent, _); 698 | 699 | if (!this.noDotDeployment) { 700 | // Write the .deployment file 701 | writeContentToFile(deploymentFilePath, '[config]\ncommand = ' + deploymentCommand, _); 702 | } 703 | 704 | log.info('Generated deployment script files'); 705 | }; 706 | 707 | function getTemplateContent(templateFileName) { 708 | return fs.readFileSync(getTemplatePath(templateFileName), 'utf8'); 709 | } 710 | 711 | function getTemplatePath(fileName) { 712 | return path.join(templatesDir, fileName); 713 | } 714 | 715 | function writeContentToFile(path, content, _) { 716 | // TODO: Add check whether file exist 717 | if (fs.existsSync(path)) { 718 | if (!confirm('The file: "' + path + '" already exists\nAre you sure you want to overwrite it (y/n): ', _)) { 719 | // Do not overwrite the file 720 | return; 721 | } 722 | } 723 | 724 | fs.writeFile(path, content, _); 725 | } 726 | 727 | function argNotNull(arg, argName) { 728 | if (arg === null || arg === undefined) { 729 | throw new Error('The argument "' + argName + '" is null'); 730 | } 731 | } 732 | 733 | exports.ScriptGenerator = ScriptGenerator; 734 | -------------------------------------------------------------------------------- /lib/generator.js: -------------------------------------------------------------------------------- 1 | /*** Generated by streamline 0.4.11 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename),__func=__rt.__func,__cb=__rt.__cb; var package = require("../package.json"); 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | var fs = require("fs"); 19 | var path = require("path"); 20 | 21 | var isWindows = (process.platform === "win32"); 22 | 23 | 24 | fs.existsSync = (fs.existsSync || path.existsSync); 25 | path.sep = (path.sep || ((isWindows ? "\\" : "/"))); 26 | 27 | var templatesDir = path.join(__dirname, "templates"); 28 | var log = { info: function() { }}; 29 | var confirm = function() { return false;}; 30 | 31 | var ScriptType = { 32 | batch: "BATCH", 33 | bash: "BASH", 34 | posh: "POSH"}; 35 | 36 | 37 | var ProjectType = { 38 | wap: "WAP", 39 | website: "WEBSITE", 40 | node: "NODE", 41 | python: "PYTHON", 42 | basic: "BASIC", 43 | functionApp: "FUNCTIONAPP", 44 | dotNetConsole: "DOT_NET_CONSOLE", 45 | aspNetCore: "ASP_NET_CORE", 46 | functionAppMSBuild16: "FUNCTION_APP_MSBUILD16", 47 | dotNetConsoleMSBuild16: "DOT_NET_CONSOLE_MSBUILD16", 48 | aspNetCoreMSBuild16: "ASP_NET_CORE_MSBUILD16", 49 | aspNetCoreMSBuild1607: "ASP_NET_CORE_MSBUILD1607", 50 | dotNetConsoleMSBuild1607: "DOT_NET_CONSOLE_MSBUILD1607", 51 | functionAppMSBuild1607: "FUNCTION_APP_MSBUILD1607", 52 | go: "GO", 53 | ruby: "RUBY", 54 | php: "PHP"}; 55 | 56 | 57 | exports.ScriptType = ScriptType; 58 | exports.ProjectType = ProjectType; 59 | 60 | function ScriptGenerator(repositoryRoot, projectType, projectPath, solutionPath, sitePath, scriptType, scriptOutputPath, noDotDeployment, noSolution, logger, confirmFunc) { 61 | argNotNull(repositoryRoot, "repositoryRoot"); 62 | argNotNull(scriptOutputPath, "scriptOutputPath"); 63 | argNotNull(projectType, "projectType"); 64 | argNotNull(sitePath, "sitePath"); 65 | 66 | projectType = projectType.toUpperCase(); 67 | 68 | if (!scriptType) { 69 | 70 | if (((projectType === ProjectType.wap) || (projectType === ProjectType.website))) { 71 | 72 | scriptType = ScriptType.batch; } 73 | else { 74 | 75 | scriptType = (isWindows ? ScriptType.batch : ScriptType.bash); } ; } 76 | 77 | else { 78 | scriptType = scriptType.toUpperCase(); 79 | if ((((scriptType !== ScriptType.batch) && (scriptType !== ScriptType.bash)) && (scriptType !== ScriptType.posh))) { 80 | throw new Error("Script type should be either batch or bash or posh"); } ; }; 81 | 82 | 83 | this.scriptType = scriptType; 84 | 85 | log = (logger || log); 86 | confirm = (confirmFunc || confirm); 87 | 88 | if (projectPath) { 89 | if (!isPathSubDir(repositoryRoot, projectPath)) { 90 | throw new Error("The project file path should be a sub-directory of the repository root"); } ; 91 | 92 | 93 | var relativeProjectPath = path.relative(repositoryRoot, projectPath); 94 | log.info((("Project file path: ." + path.sep) + relativeProjectPath)); 95 | this.projectPath = relativeProjectPath; 96 | this.absoluteProjectPath = projectPath; }; 97 | 98 | 99 | if (solutionPath) { 100 | if (!isPathSubDir(repositoryRoot, solutionPath)) { 101 | throw new Error("The solution file path should be the same as repository root or a sub-directory of it."); } ; 102 | 103 | 104 | var relativeSolutionPath = path.relative(repositoryRoot, solutionPath); 105 | log.info((("Solution file path: ." + path.sep) + relativeSolutionPath)); 106 | this.solutionPath = relativeSolutionPath; }; 107 | 108 | 109 | if (!isPathSubDir(repositoryRoot, sitePath)) { 110 | throw new Error("The site directory path should be the same as repository root or a sub-directory of it."); }; 111 | 112 | 113 | var relativeSitePath = path.relative(repositoryRoot, sitePath); 114 | if (relativeSitePath) { 115 | relativeSitePath = (path.sep + relativeSitePath); 116 | log.info(("The site directory path: ." + relativeSitePath)); }; 117 | 118 | this.sitePath = (relativeSitePath || ""); 119 | 120 | this.repositoryRoot = repositoryRoot; 121 | this.scriptOutputPath = scriptOutputPath; 122 | this.projectType = projectType; 123 | this.noDotDeployment = noDotDeployment; 124 | this.noSolution = noSolution; 125 | this.absoluteSitePath = path.join(this.repositoryRoot, this.sitePath); 126 | 127 | this.generators = []; 128 | this.generators[ProjectType.wap] = generateWapDeploymentScript; 129 | this.generators[ProjectType.website] = generateWebSiteDeploymentScript; 130 | this.generators[ProjectType.node] = generateNodeDeploymentScript; 131 | this.generators[ProjectType.python] = generatePythonDeploymentScript; 132 | this.generators[ProjectType.basic] = generateBasicWebSiteDeploymentScript; 133 | this.generators[ProjectType.functionApp] = generateFunctionAppDeploymentScript; 134 | this.generators[ProjectType.dotNetConsole] = generateDotNetConsoleDeploymentScript; 135 | this.generators[ProjectType.aspNetCore] = generateAspNetCoreDeploymentScript; 136 | this.generators[ProjectType.functionAppMSBuild16] = generateFunctionAppMSBuild16DeploymentScript; 137 | this.generators[ProjectType.functionAppMSBuild1607] = generateFunctionAppMSBuild1607DeploymentScript; 138 | this.generators[ProjectType.dotNetConsoleMSBuild16] = generateDotNetConsoleMSBuild16DeploymentScript; 139 | this.generators[ProjectType.aspNetCoreMSBuild16] = generateAspNetCoreMSBuild16DeploymentScript; 140 | this.generators[ProjectType.aspNetCoreMSBuild1607] = generateAspNetCoreMSBuild1607DeploymentScript; 141 | this.generators[ProjectType.dotNetConsoleMSBuild1607] = generateDotNetConsoleMSBuild1607DeploymentScript; 142 | this.generators[ProjectType.go] = generateGoDeploymentScript; 143 | this.generators[ProjectType.ruby] = generateRubyDeploymentScript; 144 | this.generators[ProjectType.php] = generatePHPDeploymentScript;}; 145 | 146 | 147 | function generateGoDeploymentScript(scriptGenerator, _) { var __frame = { name: "generateGoDeploymentScript", line: 147 }; return __func(_, this, arguments, generateGoDeploymentScript, 1, __frame, function __$generateGoDeploymentScript() { 148 | return scriptGenerator.generateGoDeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 149 | 150 | 151 | function generateAspNetCoreDeploymentScript(scriptGenerator, _) { var __frame = { name: "generateAspNetCoreDeploymentScript", line: 151 }; return __func(_, this, arguments, generateAspNetCoreDeploymentScript, 1, __frame, function __$generateAspNetCoreDeploymentScript() { 152 | return scriptGenerator.generateAspNetCoreDeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 153 | 154 | 155 | function generateDotNetConsoleDeploymentScript(scriptGenerator, _) { var __frame = { name: "generateDotNetConsoleDeploymentScript", line: 155 }; return __func(_, this, arguments, generateDotNetConsoleDeploymentScript, 1, __frame, function __$generateDotNetConsoleDeploymentScript() { 156 | return scriptGenerator.generateDotNetConsoleDeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 157 | 158 | 159 | function generateAspNetCoreMSBuild16DeploymentScript(scriptGenerator, _) { var __frame = { name: "generateAspNetCoreMSBuild16DeploymentScript", line: 159 }; return __func(_, this, arguments, generateAspNetCoreMSBuild16DeploymentScript, 1, __frame, function __$generateAspNetCoreMSBuild16DeploymentScript() { 160 | return scriptGenerator.generateAspNetCoreMSBuild16DeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 161 | 162 | 163 | function generateAspNetCoreMSBuild1607DeploymentScript(scriptGenerator, _) { var __frame = { name: "generateAspNetCoreMSBuild1607DeploymentScript", line: 163 }; return __func(_, this, arguments, generateAspNetCoreMSBuild1607DeploymentScript, 1, __frame, function __$generateAspNetCoreMSBuild1607DeploymentScript() { 164 | return scriptGenerator.generateAspNetCoreMSBuild1607DeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 165 | 166 | 167 | function generateDotNetConsoleMSBuild16DeploymentScript(scriptGenerator, _) { var __frame = { name: "generateDotNetConsoleMSBuild16DeploymentScript", line: 167 }; return __func(_, this, arguments, generateDotNetConsoleMSBuild16DeploymentScript, 1, __frame, function __$generateDotNetConsoleMSBuild16DeploymentScript() { 168 | return scriptGenerator.generateDotNetConsoleMSBuild16DeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 169 | 170 | 171 | function generateDotNetConsoleMSBuild1607DeploymentScript(scriptGenerator, _) { var __frame = { name: "generateDotNetConsoleMSBuild1607DeploymentScript", line: 171 }; return __func(_, this, arguments, generateDotNetConsoleMSBuild1607DeploymentScript, 1, __frame, function __$generateDotNetConsoleMSBuild1607DeploymentScript() { 172 | return scriptGenerator.generateDotNetConsoleMSBuild1607DeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 173 | 174 | 175 | function generateFunctionAppMSBuild16DeploymentScript(scriptGenerator, _) { var __frame = { name: "generateFunctionAppMSBuild16DeploymentScript", line: 175 }; return __func(_, this, arguments, generateFunctionAppMSBuild16DeploymentScript, 1, __frame, function __$generateFunctionAppMSBuild16DeploymentScript() { 176 | return scriptGenerator.generateFunctionAppMSBuild16DeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 177 | 178 | 179 | function generateFunctionAppMSBuild1607DeploymentScript(scriptGenerator, _) { var __frame = { name: "generateFunctionAppMSBuild1607DeploymentScript", line: 179 }; return __func(_, this, arguments, generateFunctionAppMSBuild1607DeploymentScript, 1, __frame, function __$generateFunctionAppMSBuild1607DeploymentScript() { 180 | return scriptGenerator.generateFunctionAppMSBuild1607DeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 181 | 182 | 183 | function generateWapDeploymentScript(scriptGenerator, _) { var __frame = { name: "generateWapDeploymentScript", line: 183 }; return __func(_, this, arguments, generateWapDeploymentScript, 1, __frame, function __$generateWapDeploymentScript() { 184 | return scriptGenerator.generateWapDeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 185 | 186 | 187 | function generateWebSiteDeploymentScript(scriptGenerator, _) { var __frame = { name: "generateWebSiteDeploymentScript", line: 187 }; return __func(_, this, arguments, generateWebSiteDeploymentScript, 1, __frame, function __$generateWebSiteDeploymentScript() { 188 | return scriptGenerator.generateWebSiteDeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 189 | 190 | 191 | function generateNodeDeploymentScript(scriptGenerator, _) { var __frame = { name: "generateNodeDeploymentScript", line: 191 }; return __func(_, this, arguments, generateNodeDeploymentScript, 1, __frame, function __$generateNodeDeploymentScript() { 192 | return scriptGenerator.generateNodeDeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 193 | 194 | 195 | function generatePythonDeploymentScript(scriptGenerator, _) { var __frame = { name: "generatePythonDeploymentScript", line: 195 }; return __func(_, this, arguments, generatePythonDeploymentScript, 1, __frame, function __$generatePythonDeploymentScript() { 196 | return scriptGenerator.generatePythonDeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 197 | 198 | 199 | function generateRubyDeploymentScript(scriptGenerator, _) { var __frame = { name: "generateRubyDeploymentScript", line: 199 }; return __func(_, this, arguments, generateRubyDeploymentScript, 1, __frame, function __$generateRubyDeploymentScript() { 200 | return scriptGenerator.generateRubyDeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 201 | 202 | 203 | function generatePHPDeploymentScript(scriptGenerator, _) { var __frame = { name: "generatePHPDeploymentScript", line: 203 }; return __func(_, this, arguments, generatePHPDeploymentScript, 1, __frame, function __$generatePHPDeploymentScript() { 204 | return scriptGenerator.generatePHPDeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 205 | 206 | 207 | function generateBasicWebSiteDeploymentScript(scriptGenerator, _) { var __frame = { name: "generateBasicWebSiteDeploymentScript", line: 207 }; return __func(_, this, arguments, generateBasicWebSiteDeploymentScript, 1, __frame, function __$generateBasicWebSiteDeploymentScript() { 208 | if (scriptGenerator.solutionPath) { 209 | return _(new Error("Solution path is not supported with this website type")); } ; 210 | 211 | return scriptGenerator.generateWebSiteDeploymentScript(__cb(_, __frame, 4, 2, _, true)); });}; 212 | 213 | 214 | function generateFunctionAppDeploymentScript(scriptGenerator, _) { var __frame = { name: "generateFunctionAppDeploymentScript", line: 214 }; return __func(_, this, arguments, generateFunctionAppDeploymentScript, 1, __frame, function __$generateFunctionAppDeploymentScript() { 215 | return scriptGenerator.generateFunctionAppDeploymentScript(__cb(_, __frame, 1, 2, _, true)); });}; 216 | 217 | 218 | ScriptGenerator.prototype.generateDeploymentScript = function ScriptGenerator_prototype_generateDeploymentScript__1(_) { var generator, __this = this; var __frame = { name: "ScriptGenerator_prototype_generateDeploymentScript__1", line: 218 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateDeploymentScript__1, 0, __frame, function __$ScriptGenerator_prototype_generateDeploymentScript__1() { 219 | generator = __this.generators[__this.projectType]; 220 | if (!generator) { 221 | return _(new Error(("Invalid project type received: " + __this.projectType))); } ; 222 | 223 | 224 | return generator(__this, __cb(_, __frame, 6, 2, _, true)); });}; 225 | 226 | 227 | function isPathSubDir(parentPath, childPath) { 228 | var relativePath = path.relative(parentPath, childPath); 229 | 230 | 231 | 232 | 233 | return ((relativePath.indexOf("..") !== 0) && (relativePath !== path.resolve(childPath)));}; 234 | 235 | 236 | 237 | ScriptGenerator.prototype.generateGoDeploymentScript = function ScriptGenerator_prototype_generateGoDeploymentScript__2(_) { var __this = this; var __frame = { name: "ScriptGenerator_prototype_generateGoDeploymentScript__2", line: 237 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateGoDeploymentScript__2, 0, __frame, function __$ScriptGenerator_prototype_generateGoDeploymentScript__2() { 238 | log.info("Generating deployment script for Go Web Site"); 239 | 240 | return __this.generateBasicDeploymentScript("go.template", __cb(_, __frame, 3, 2, _, true)); });}; 241 | 242 | 243 | ScriptGenerator.prototype.generateNodeDeploymentScript = function ScriptGenerator_prototype_generateNodeDeploymentScript__3(_) { var __this = this; var __frame = { name: "ScriptGenerator_prototype_generateNodeDeploymentScript__3", line: 243 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateNodeDeploymentScript__3, 0, __frame, function __$ScriptGenerator_prototype_generateNodeDeploymentScript__3() { 244 | log.info("Generating deployment script for node.js Web Site"); 245 | 246 | return __this.generateBasicDeploymentScript("node.template", __cb(_, __frame, 3, 2, _, true)); });}; 247 | 248 | 249 | ScriptGenerator.prototype.generateFunctionAppDeploymentScript = function ScriptGenerator_prototype_generateFunctionAppDeploymentScript__4(_) { var __this = this; var __frame = { name: "ScriptGenerator_prototype_generateFunctionAppDeploymentScript__4", line: 249 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateFunctionAppDeploymentScript__4, 0, __frame, function __$ScriptGenerator_prototype_generateFunctionAppDeploymentScript__4() { 250 | log.info("Generating deployment script for function App"); 251 | 252 | options = { }; return (function __$ScriptGenerator_prototype_generateFunctionAppDeploymentScript__4(__then) { 253 | if (__this.projectPath) { 254 | if ((__this.scriptType == ScriptType.bash)) { 255 | return _(new Error("csharp function targeting dotnet core is currently not supported")); } ; 256 | 257 | 258 | options.projectPath = fixPathSeparatorToWindows(__this.projectPath); 259 | if (__this.solutionPath) { 260 | options.RestoreArguments = fixPathSeparatorToWindows(__this.solutionPath); } 261 | else { 262 | options.RestoreArguments = options.projectPath; } ; 263 | 264 | return __this.generateFunctionAppScript("functionmsbuild.template", options, __cb(_, __frame, 15, 4, __then, true)); } else { 265 | 266 | if ((__this.scriptType == ScriptType.bash)) { 267 | 268 | 269 | options.sitePath = fixPathSeparatorToUnix(__this.sitePath); } 270 | else { 271 | options.sitePath = fixPathSeparatorToWindows(__this.sitePath); } ; 272 | 273 | return __this.generateFunctionAppScript("functionbasic.template", options, __cb(_, __frame, 24, 4, __then, true)); } ; })(_); });}; 274 | 275 | 276 | 277 | ScriptGenerator.prototype.generateFunctionAppMSBuild1607DeploymentScript = function ScriptGenerator_prototype_generateFunctionAppMSBuild1607DeploymentScript__5(_) { var __this = this; var __frame = { name: "ScriptGenerator_prototype_generateFunctionAppMSBuild1607DeploymentScript__5", line: 277 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateFunctionAppMSBuild1607DeploymentScript__5, 0, __frame, function __$ScriptGenerator_prototype_generateFunctionAppMSBuild1607DeploymentScript__5() { 278 | log.info("Generating deployment script for function MSBuild16 App"); 279 | 280 | options = { }; 281 | if ((__this.scriptType == ScriptType.bash)) { 282 | return _(new Error("csharp function targeting dotnet core is currently not supported")); } ; 283 | 284 | 285 | options.projectPath = fixPathSeparatorToWindows(__this.projectPath); 286 | return __this.generateFunctionAppScript("function.msbuild1607.template", options, __cb(_, __frame, 9, 2, _, true)); });}; 287 | 288 | 289 | ScriptGenerator.prototype.generateFunctionAppMSBuild16DeploymentScript = function ScriptGenerator_prototype_generateFunctionAppMSBuild16DeploymentScript__6(_) { var __this = this; var __frame = { name: "ScriptGenerator_prototype_generateFunctionAppMSBuild16DeploymentScript__6", line: 289 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateFunctionAppMSBuild16DeploymentScript__6, 0, __frame, function __$ScriptGenerator_prototype_generateFunctionAppMSBuild16DeploymentScript__6() { 290 | log.info("Generating deployment script for function MSBuild16 App"); 291 | 292 | options = { }; 293 | if ((__this.scriptType == ScriptType.bash)) { 294 | return _(new Error("csharp function targeting dotnet core is currently not supported")); } ; 295 | 296 | 297 | options.projectPath = fixPathSeparatorToWindows(__this.projectPath); 298 | return __this.generateFunctionAppScript("function.msbuild16.template", options, __cb(_, __frame, 9, 2, _, true)); });}; 299 | 300 | 301 | ScriptGenerator.prototype.generatePythonDeploymentScript = function ScriptGenerator_prototype_generatePythonDeploymentScript__7(_) { var __this = this; var __frame = { name: "ScriptGenerator_prototype_generatePythonDeploymentScript__7", line: 301 }; return __func(_, this, arguments, ScriptGenerator_prototype_generatePythonDeploymentScript__7, 0, __frame, function __$ScriptGenerator_prototype_generatePythonDeploymentScript__7() { 302 | log.info("Generating deployment script for python Web Site"); 303 | 304 | return __this.generateBasicDeploymentScript("python.template", __cb(_, __frame, 3, 2, _, true)); });}; 305 | 306 | 307 | ScriptGenerator.prototype.generateRubyDeploymentScript = function ScriptGenerator_prototype_generateRubyDeploymentScript__8(_) { var __this = this; var __frame = { name: "ScriptGenerator_prototype_generateRubyDeploymentScript__8", line: 307 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateRubyDeploymentScript__8, 0, __frame, function __$ScriptGenerator_prototype_generateRubyDeploymentScript__8() { 308 | log.info("Generating deployment script for Ruby Web Site"); 309 | 310 | return __this.generateBasicDeploymentScript("ruby.template", __cb(_, __frame, 3, 2, _, true)); });}; 311 | 312 | 313 | ScriptGenerator.prototype.generatePHPDeploymentScript = function ScriptGenerator_prototype_generatePHPDeploymentScript__9(_) { var __this = this; var __frame = { name: "ScriptGenerator_prototype_generatePHPDeploymentScript__9", line: 313 }; return __func(_, this, arguments, ScriptGenerator_prototype_generatePHPDeploymentScript__9, 0, __frame, function __$ScriptGenerator_prototype_generatePHPDeploymentScript__9() { 314 | log.info("Generating deployment script for PHP Web Site"); 315 | 316 | return __this.generateBasicDeploymentScript("php.template", __cb(_, __frame, 3, 2, _, true)); });}; 317 | 318 | 319 | ScriptGenerator.prototype.generateWapDeploymentScript = function ScriptGenerator_prototype_generateWapDeploymentScript__10(_) { var msbuildArguments, msbuildArgumentsForInPlace, solutionDir, solutionArgs, options, __this = this; var __frame = { name: "ScriptGenerator_prototype_generateWapDeploymentScript__10", line: 319 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateWapDeploymentScript__10, 0, __frame, function __$ScriptGenerator_prototype_generateWapDeploymentScript__10() { 320 | argNotNull(__this.projectPath, "projectPath"); 321 | 322 | if (((__this.scriptType != ScriptType.batch) && (__this.scriptType != ScriptType.posh))) { 323 | return _(new Error("Only batch and posh script files are supported for .NET Web Application")); } ; 324 | 325 | 326 | if ((!__this.solutionPath && !__this.noSolution)) { 327 | return _(new Error("Missing solution file path (--solutionFile), to explicitly not require a solution use the flag --no-solution")); } ; 328 | 329 | 330 | log.info("Generating deployment script for .NET Web Application"); 331 | 332 | 333 | 334 | if ((__this.scriptType == ScriptType.batch)) { 335 | msbuildArguments = (("\"%DEPLOYMENT_SOURCE%\\" + __this.projectPath) + "\" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir=\"%DEPLOYMENT_TEMP%\";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false"); 336 | msbuildArgumentsForInPlace = (("\"%DEPLOYMENT_SOURCE%\\" + __this.projectPath) + "\" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false"); 337 | 338 | if (__this.solutionPath) { 339 | solutionDir = path.dirname(__this.solutionPath); 340 | solutionArgs = ((" /p:SolutionDir=\"%DEPLOYMENT_SOURCE%\\" + solutionDir) + "\\\\\""); 341 | msbuildArguments += solutionArgs; 342 | msbuildArgumentsForInPlace += solutionArgs; } ; 343 | 344 | 345 | msbuildArguments += " %SCM_BUILD_ARGS%"; 346 | msbuildArgumentsForInPlace += " %SCM_BUILD_ARGS%"; } 347 | else { 348 | msbuildArguments = (("\"$DEPLOYMENT_SOURCE\\" + __this.projectPath) + "\" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir=\"$DEPLOYMENT_TEMP\"`;AutoParameterizationWebConfigConnectionStrings=false`;Configuration=Release`;UseSharedCompilation=false"); 349 | msbuildArgumentsForInPlace = (("\"$DEPLOYMENT_SOURCE\\" + __this.projectPath) + "\" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false`;Configuration=Release`;UseSharedCompilation=false"); 350 | 351 | if (__this.solutionPath) { 352 | solutionDir = path.dirname(__this.solutionPath); 353 | solutionArgs = ((" /p:SolutionDir=\"$DEPLOYMENT_SOURCE\\" + solutionDir) + "\\\\\""); 354 | msbuildArguments += solutionArgs; 355 | msbuildArgumentsForInPlace += solutionArgs; } ; 356 | 357 | 358 | msbuildArguments += " $env:SCM_BUILD_ARGS"; 359 | msbuildArgumentsForInPlace += " $env:SCM_BUILD_ARGS"; } ; 360 | 361 | 362 | options = { 363 | msbuildArguments: msbuildArguments, 364 | msbuildArgumentsForInPlace: msbuildArgumentsForInPlace }; 365 | 366 | 367 | return __this.generateDotNetDeploymentScript("aspnet.wap.template", options, __cb(_, __frame, 48, 2, _, true)); });}; 368 | 369 | 370 | ScriptGenerator.prototype.generateAspNetCoreMSBuild16DeploymentScript = function ScriptGenerator_prototype_generateAspNetCoreMSBuild16DeploymentScript__11(_) { var __this = this; var __frame = { name: "ScriptGenerator_prototype_generateAspNetCoreMSBuild16DeploymentScript__11", line: 370 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateAspNetCoreMSBuild16DeploymentScript__11, 0, __frame, function __$ScriptGenerator_prototype_generateAspNetCoreMSBuild16DeploymentScript__11() { 371 | log.info("Generating deployment script for ASP.NET MSBuild16 App"); 372 | 373 | options = { }; 374 | options.projectPath = fixPathSeparatorToWindows(__this.projectPath); 375 | return __this.generateAspNetCoreMSBuild16AppScript("aspnet.core.msbuild16.template", options, __cb(_, __frame, 5, 2, _, true)); });}; 376 | 377 | 378 | ScriptGenerator.prototype.generateAspNetCoreMSBuild1607DeploymentScript = function ScriptGenerator_prototype_generateAspNetCoreMSBuild1607DeploymentScript__12(_) { var __this = this; var __frame = { name: "ScriptGenerator_prototype_generateAspNetCoreMSBuild1607DeploymentScript__12", line: 378 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateAspNetCoreMSBuild1607DeploymentScript__12, 0, __frame, function __$ScriptGenerator_prototype_generateAspNetCoreMSBuild1607DeploymentScript__12() { 379 | log.info("Generating deployment script for ASP.NET MSBuild16.7.0 App"); 380 | 381 | options = { }; 382 | options.projectPath = fixPathSeparatorToWindows(__this.projectPath); 383 | return __this.generateAspNetCoreMSBuild16AppScript("aspnet.core.msbuild1607.template", options, __cb(_, __frame, 5, 2, _, true)); });}; 384 | 385 | 386 | ScriptGenerator.prototype.generateAspNetCoreDeploymentScript = function ScriptGenerator_prototype_generateAspNetCoreDeploymentScript__13(_) { var options, __this = this; var __frame = { name: "ScriptGenerator_prototype_generateAspNetCoreDeploymentScript__13", line: 386 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateAspNetCoreDeploymentScript__13, 0, __frame, function __$ScriptGenerator_prototype_generateAspNetCoreDeploymentScript__13() { 387 | argNotNull(__this.absoluteProjectPath, "absoluteProjectPath"); 388 | 389 | 390 | 391 | options = { }; 392 | options.RestoreArguments = (((__this.solutionPath) ? __this.solutionPath : __this.projectPath)); 393 | options.DotnetpublishArguments = __this.projectPath; 394 | 395 | return __this.generateAspNetCoreScript("aspnet.core.template", options, __cb(_, __frame, 9, 2, _, true)); });}; 396 | 397 | 398 | ScriptGenerator.prototype.generateDotNetConsoleMSBuild1607DeploymentScript = function ScriptGenerator_prototype_generateDotNetConsoleMSBuild1607DeploymentScript__14(_) { var msbuildArguments, solutionDir, solutionArgs, options, __this = this; var __frame = { name: "ScriptGenerator_prototype_generateDotNetConsoleMSBuild1607DeploymentScript__14", line: 398 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateDotNetConsoleMSBuild1607DeploymentScript__14, 0, __frame, function __$ScriptGenerator_prototype_generateDotNetConsoleMSBuild1607DeploymentScript__14() { 399 | argNotNull(__this.projectPath, "projectPath"); 400 | 401 | if (((__this.scriptType != ScriptType.batch) && (__this.scriptType != ScriptType.posh))) { 402 | return _(new Error("Only batch and posh script files are supported for .NET Web Application")); } ; 403 | 404 | 405 | if ((!__this.solutionPath && !__this.noSolution)) { 406 | return _(new Error("Missing solution file path (--solutionFile), to explicitly not require a solution use the flag --no-solution")); } ; 407 | 408 | 409 | log.info("Generating deployment script for .NET console application"); 410 | 411 | 412 | 413 | if ((__this.scriptType == ScriptType.batch)) { 414 | msbuildArguments = (("\"%DEPLOYMENT_SOURCE%\\" + __this.projectPath) + "\" /nologo /verbosity:m /t:Build /p:Configuration=Release;OutputPath=\"%DEPLOYMENT_TEMP%\\app_data\\jobs\\continuous\\deployedJob\";UseSharedCompilation=false"); 415 | 416 | if (__this.solutionPath) { 417 | solutionDir = path.dirname(__this.solutionPath); 418 | solutionArgs = ((" /p:SolutionDir=\"%DEPLOYMENT_SOURCE%\\" + solutionDir) + "\\\\\""); 419 | msbuildArguments += solutionArgs; } ; 420 | 421 | 422 | msbuildArguments += " %SCM_BUILD_ARGS%"; } 423 | else { 424 | msbuildArguments = (("\"$DEPLOYMENT_SOURCE\\" + __this.projectPath) + "\" /nologo /verbosity:m /t:Build /p:Configuration=Release`;OutputPath=\"$DEPLOYMENT_TEMP\\app_data\\jobs\\continuous\\deployedJob\"`;UseSharedCompilation=false"); 425 | 426 | if (__this.solutionPath) { 427 | solutionDir = path.dirname(__this.solutionPath); 428 | solutionArgs = ((" /p:SolutionDir=\"$DEPLOYMENT_SOURCE\\" + solutionDir) + "\\\\\""); 429 | msbuildArguments += solutionArgs; } ; 430 | 431 | 432 | msbuildArguments += " $env:SCM_BUILD_ARGS"; } ; 433 | 434 | 435 | options = { 436 | msbuildArguments: msbuildArguments, 437 | msbuildArgumentsForInPlace: msbuildArguments }; 438 | 439 | 440 | return __this.generateDotNetDeploymentScript("dotnetconsole.msbuild1607.template", options, __cb(_, __frame, 42, 2, _, true)); });}; 441 | 442 | 443 | ScriptGenerator.prototype.generateDotNetConsoleMSBuild16DeploymentScript = function ScriptGenerator_prototype_generateDotNetConsoleMSBuild16DeploymentScript__15(_) { var msbuildArguments, solutionDir, solutionArgs, options, __this = this; var __frame = { name: "ScriptGenerator_prototype_generateDotNetConsoleMSBuild16DeploymentScript__15", line: 443 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateDotNetConsoleMSBuild16DeploymentScript__15, 0, __frame, function __$ScriptGenerator_prototype_generateDotNetConsoleMSBuild16DeploymentScript__15() { 444 | argNotNull(__this.projectPath, "projectPath"); 445 | 446 | if (((__this.scriptType != ScriptType.batch) && (__this.scriptType != ScriptType.posh))) { 447 | return _(new Error("Only batch and posh script files are supported for .NET Web Application")); } ; 448 | 449 | 450 | if ((!__this.solutionPath && !__this.noSolution)) { 451 | return _(new Error("Missing solution file path (--solutionFile), to explicitly not require a solution use the flag --no-solution")); } ; 452 | 453 | 454 | log.info("Generating deployment script for .NET console application"); 455 | 456 | 457 | 458 | if ((__this.scriptType == ScriptType.batch)) { 459 | msbuildArguments = (("\"%DEPLOYMENT_SOURCE%\\" + __this.projectPath) + "\" /nologo /verbosity:m /t:Build /p:Configuration=Release;OutputPath=\"%DEPLOYMENT_TEMP%\\app_data\\jobs\\continuous\\deployedJob\";UseSharedCompilation=false"); 460 | 461 | if (__this.solutionPath) { 462 | solutionDir = path.dirname(__this.solutionPath); 463 | solutionArgs = ((" /p:SolutionDir=\"%DEPLOYMENT_SOURCE%\\" + solutionDir) + "\\\\\""); 464 | msbuildArguments += solutionArgs; } ; 465 | 466 | 467 | msbuildArguments += " %SCM_BUILD_ARGS%"; } 468 | else { 469 | msbuildArguments = (("\"$DEPLOYMENT_SOURCE\\" + __this.projectPath) + "\" /nologo /verbosity:m /t:Build /p:Configuration=Release`;OutputPath=\"$DEPLOYMENT_TEMP\\app_data\\jobs\\continuous\\deployedJob\"`;UseSharedCompilation=false"); 470 | 471 | if (__this.solutionPath) { 472 | solutionDir = path.dirname(__this.solutionPath); 473 | solutionArgs = ((" /p:SolutionDir=\"$DEPLOYMENT_SOURCE\\" + solutionDir) + "\\\\\""); 474 | msbuildArguments += solutionArgs; } ; 475 | 476 | 477 | msbuildArguments += " $env:SCM_BUILD_ARGS"; } ; 478 | 479 | 480 | options = { 481 | msbuildArguments: msbuildArguments, 482 | msbuildArgumentsForInPlace: msbuildArguments }; 483 | 484 | 485 | return __this.generateDotNetDeploymentScript("dotnetconsole.msbuild16.template", options, __cb(_, __frame, 42, 2, _, true)); });}; 486 | 487 | 488 | ScriptGenerator.prototype.generateDotNetConsoleDeploymentScript = function ScriptGenerator_prototype_generateDotNetConsoleDeploymentScript__16(_) { var msbuildArguments, solutionDir, solutionArgs, options, __this = this; var __frame = { name: "ScriptGenerator_prototype_generateDotNetConsoleDeploymentScript__16", line: 488 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateDotNetConsoleDeploymentScript__16, 0, __frame, function __$ScriptGenerator_prototype_generateDotNetConsoleDeploymentScript__16() { 489 | argNotNull(__this.projectPath, "projectPath"); 490 | 491 | if (((__this.scriptType != ScriptType.batch) && (__this.scriptType != ScriptType.posh))) { 492 | return _(new Error("Only batch and posh script files are supported for .NET Web Application")); } ; 493 | 494 | 495 | if ((!__this.solutionPath && !__this.noSolution)) { 496 | return _(new Error("Missing solution file path (--solutionFile), to explicitly not require a solution use the flag --no-solution")); } ; 497 | 498 | 499 | log.info("Generating deployment script for .NET console application"); 500 | 501 | 502 | 503 | if ((__this.scriptType == ScriptType.batch)) { 504 | msbuildArguments = (("\"%DEPLOYMENT_SOURCE%\\" + __this.projectPath) + "\" /nologo /verbosity:m /t:Build /p:Configuration=Release;OutputPath=\"%DEPLOYMENT_TEMP%\\app_data\\jobs\\continuous\\deployedJob\";UseSharedCompilation=false"); 505 | 506 | if (__this.solutionPath) { 507 | solutionDir = path.dirname(__this.solutionPath); 508 | solutionArgs = ((" /p:SolutionDir=\"%DEPLOYMENT_SOURCE%\\" + solutionDir) + "\\\\\""); 509 | msbuildArguments += solutionArgs; } ; 510 | 511 | 512 | msbuildArguments += " %SCM_BUILD_ARGS%"; } 513 | else { 514 | msbuildArguments = (("\"$DEPLOYMENT_SOURCE\\" + __this.projectPath) + "\" /nologo /verbosity:m /t:Build /p:Configuration=Release`;OutputPath=\"$DEPLOYMENT_TEMP\\app_data\\jobs\\continuous\\deployedJob\"`;UseSharedCompilation=false"); 515 | 516 | if (__this.solutionPath) { 517 | solutionDir = path.dirname(__this.solutionPath); 518 | solutionArgs = ((" /p:SolutionDir=\"$DEPLOYMENT_SOURCE\\" + solutionDir) + "\\\\\""); 519 | msbuildArguments += solutionArgs; } ; 520 | 521 | 522 | msbuildArguments += " $env:SCM_BUILD_ARGS"; } ; 523 | 524 | 525 | options = { 526 | msbuildArguments: msbuildArguments, 527 | msbuildArgumentsForInPlace: msbuildArguments }; 528 | 529 | 530 | return __this.generateDotNetDeploymentScript("dotnetconsole.template", options, __cb(_, __frame, 42, 2, _, true)); });}; 531 | 532 | 533 | ScriptGenerator.prototype.generateWebSiteDeploymentScript = function ScriptGenerator_prototype_generateWebSiteDeploymentScript__17(_) { var msbuildArguments, __this = this; var __frame = { name: "ScriptGenerator_prototype_generateWebSiteDeploymentScript__17", line: 533 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateWebSiteDeploymentScript__17, 0, __frame, function __$ScriptGenerator_prototype_generateWebSiteDeploymentScript__17() { return (function __$ScriptGenerator_prototype_generateWebSiteDeploymentScript__17(__then) { 534 | if (__this.solutionPath) { 535 | 536 | log.info("Generating deployment script for .NET Web Site"); 537 | 538 | if (((__this.scriptType != ScriptType.batch) && (__this.scriptType != ScriptType.posh))) { 539 | return _(new Error("Only batch and posh script files are supported for .NET Web Site")); } ; 540 | 541 | 542 | 543 | 544 | if ((__this.scriptType == ScriptType.batch)) { 545 | msbuildArguments = (("\"%DEPLOYMENT_SOURCE%\\" + fixPathSeparatorToWindows(__this.solutionPath)) + "\" /verbosity:m /nologo %SCM_BUILD_ARGS%"); } 546 | else { 547 | msbuildArguments = (("\"$DEPLOYMENT_SOURCE\\" + fixPathSeparatorToWindows(__this.solutionPath)) + "\" /verbosity:m /nologo $env:SCM_BUILD_ARGS"); } ; 548 | 549 | 550 | return __this.generateDotNetDeploymentScript("aspnet.website.template", { msbuildArguments: msbuildArguments }, __cb(_, __frame, 17, 4, __then, true)); } else { 551 | 552 | 553 | log.info("Generating deployment script for Web Site"); 554 | return __this.generateBasicDeploymentScript("basic.template", __cb(_, __frame, 21, 4, __then, true)); } ; })(_); });}; 555 | 556 | 557 | 558 | ScriptGenerator.prototype.generateBasicDeploymentScript = function ScriptGenerator_prototype_generateBasicDeploymentScript__18(templateFileName, _) { var lowerCaseScriptType, fixedSitePath, templateContent, __this = this; var __frame = { name: "ScriptGenerator_prototype_generateBasicDeploymentScript__18", line: 558 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateBasicDeploymentScript__18, 1, __frame, function __$ScriptGenerator_prototype_generateBasicDeploymentScript__18() { 559 | argNotNull(templateFileName, "templateFileName"); 560 | 561 | lowerCaseScriptType = __this.scriptType.toLowerCase(); 562 | fixedSitePath = ((__this.scriptType === ScriptType.batch) ? fixPathSeparatorToWindows(__this.sitePath) : fixPathSeparatorToUnix(__this.sitePath)); 563 | 564 | 565 | 566 | 567 | templateContent = getTemplatesContent([(("deploy." + lowerCaseScriptType) + ".prefix.template"),((("deploy." + lowerCaseScriptType) + ".") + templateFileName),(("deploy." + lowerCaseScriptType) + ".postfix.template"),]).replace(/{SitePath}/g, fixedSitePath); 568 | 569 | return __this.writeDeploymentFiles(templateContent, __cb(_, __frame, 11, 2, _, true)); });}; 570 | 571 | 572 | ScriptGenerator.prototype.generateFunctionAppScript = function ScriptGenerator_prototype_generateFunctionAppScript__19(templateFileName, options, _) { var lowerCaseScriptType, templateContent, __this = this; var __frame = { name: "ScriptGenerator_prototype_generateFunctionAppScript__19", line: 572 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateFunctionAppScript__19, 2, __frame, function __$ScriptGenerator_prototype_generateFunctionAppScript__19() { 573 | argNotNull(templateFileName, "templateFileName"); 574 | 575 | lowerCaseScriptType = __this.scriptType.toLowerCase(); 576 | 577 | 578 | 579 | 580 | 581 | 582 | templateContent = getTemplatesContent([(("deploy." + lowerCaseScriptType) + ".prefix.template"),((("deploy." + lowerCaseScriptType) + ".") + templateFileName),(("deploy." + lowerCaseScriptType) + ".postfix.template"),]).replace(/{SitePath}/g, options.sitePath).replace(/{RestoreArguments}/g, options.RestoreArguments).replace(/{ProjectPath}/g, options.projectPath); 583 | 584 | return __this.writeDeploymentFiles(templateContent, __cb(_, __frame, 12, 2, _, true)); });}; 585 | 586 | 587 | ScriptGenerator.prototype.generateDotNetDeploymentScript = function ScriptGenerator_prototype_generateDotNetDeploymentScript__20(templateFileName, options, _) { var lowerCaseScriptType, solutionDir, templateContent, __this = this; var __frame = { name: "ScriptGenerator_prototype_generateDotNetDeploymentScript__20", line: 587 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateDotNetDeploymentScript__20, 2, __frame, function __$ScriptGenerator_prototype_generateDotNetDeploymentScript__20() { 588 | argNotNull(templateFileName, "templateFileName"); 589 | 590 | 591 | lowerCaseScriptType = __this.scriptType.toLowerCase(); 592 | solutionDir = (__this.solutionPath ? path.dirname(__this.solutionPath) : ""); 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | templateContent = getTemplatesContent([(("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 || "")).replace(/{SolutionDir}/g, solutionDir).replace(/{SitePath}/g, fixPathSeparatorToWindows(__this.sitePath)); 603 | 604 | return __this.writeDeploymentFiles(templateContent, __cb(_, __frame, 17, 2, _, true)); });}; 605 | 606 | 607 | ScriptGenerator.prototype.generateAspNetCoreMSBuild16AppScript = function ScriptGenerator_prototype_generateAspNetCoreMSBuild16AppScript__21(templateFileName, options, _) { var lowerCaseScriptType, templateContent, __this = this; var __frame = { name: "ScriptGenerator_prototype_generateAspNetCoreMSBuild16AppScript__21", line: 607 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateAspNetCoreMSBuild16AppScript__21, 2, __frame, function __$ScriptGenerator_prototype_generateAspNetCoreMSBuild16AppScript__21() { 608 | argNotNull(templateFileName, "templateFileName"); 609 | 610 | lowerCaseScriptType = __this.scriptType.toLowerCase(); 611 | 612 | 613 | 614 | 615 | 616 | templateContent = getTemplatesContent([(("deploy." + lowerCaseScriptType) + ".prefix.template"),((("deploy." + lowerCaseScriptType) + ".") + templateFileName),(("deploy." + lowerCaseScriptType) + ".postfix.template"),]).replace(/{SitePath}/g, options.sitePath).replace(/{ProjectPath}/g, options.projectPath); 617 | 618 | return __this.writeDeploymentFiles(templateContent, __cb(_, __frame, 11, 2, _, true)); });}; 619 | 620 | 621 | ScriptGenerator.prototype.generateAspNetCoreScript = function ScriptGenerator_prototype_generateAspNetCoreScript__22(templateFileName, options, _) { var prop, lowerCaseScriptType, templateContent, __this = this; var __frame = { name: "ScriptGenerator_prototype_generateAspNetCoreScript__22", line: 621 }; return __func(_, this, arguments, ScriptGenerator_prototype_generateAspNetCoreScript__22, 2, __frame, function __$ScriptGenerator_prototype_generateAspNetCoreScript__22() { 622 | argNotNull(templateFileName, "templateFileName"); 623 | 624 | if ((__this.scriptType === ScriptType.batch)) { 625 | for (prop in options) { 626 | options[prop] = fixPathSeparatorToWindows(options[prop]); }; } 627 | 628 | else { 629 | for (prop in options) { 630 | options[prop] = fixPathSeparatorToUnix(options[prop]); }; } ; 631 | 632 | 633 | 634 | lowerCaseScriptType = __this.scriptType.toLowerCase(); 635 | 636 | 637 | 638 | 639 | 640 | 641 | templateContent = getTemplatesContent([(("deploy." + lowerCaseScriptType) + ".prefix.template"),(("deploy." + lowerCaseScriptType) + ".aspnet.template"),((("deploy." + lowerCaseScriptType) + ".") + templateFileName),(("deploy." + lowerCaseScriptType) + ".postfix.template"),]).replace(/{DotnetpublishArguments}/g, options.DotnetpublishArguments).replace(/{RestoreArguments}/g, options.RestoreArguments); 642 | 643 | return __this.writeDeploymentFiles(templateContent, __cb(_, __frame, 22, 2, _, true)); });}; 644 | 645 | 646 | function getTemplatesContent(fileNames) { 647 | var content = ""; 648 | 649 | for (var i in fileNames) { 650 | content += getTemplateContent(fileNames[i]); }; 651 | 652 | 653 | content = content.replace(/{Version}/g, package.version); 654 | 655 | return content;}; 656 | 657 | 658 | function fixPathSeparatorToWindows(pathStr) { 659 | return (pathStr ? pathStr.replace(/\//g, "\\") : pathStr);}; 660 | 661 | 662 | function fixPathSeparatorToUnix(pathStr) { 663 | return (pathStr ? pathStr.replace(/\\/g, "/") : pathStr);}; 664 | 665 | 666 | function fixLineEndingsToUnix(contentStr) { 667 | return contentStr.replace(/\r\n/g, "\n");}; 668 | 669 | 670 | function fixLineEndingsToWindows(contentStr) { 671 | return contentStr.replace(/(?:\r\n|\n)/g, "\r\n");}; 672 | 673 | 674 | ScriptGenerator.prototype.writeDeploymentFiles = function ScriptGenerator_prototype_writeDeploymentFiles__23(templateContent, _) { var deployScriptFileName, deploymentCommand, deployScriptPath, deploymentFilePath, __this = this; var __frame = { name: "ScriptGenerator_prototype_writeDeploymentFiles__23", line: 674 }; return __func(_, this, arguments, ScriptGenerator_prototype_writeDeploymentFiles__23, 1, __frame, function __$ScriptGenerator_prototype_writeDeploymentFiles__23() { 675 | argNotNull(templateContent, "templateContent"); 676 | 677 | 678 | 679 | if ((__this.scriptType == ScriptType.batch)) { 680 | deployScriptFileName = "deploy.cmd"; 681 | deploymentCommand = deployScriptFileName; 682 | templateContent = fixLineEndingsToWindows(templateContent); } else { 683 | if ((__this.scriptType == ScriptType.posh)) { 684 | deployScriptFileName = "deploy.ps1"; 685 | deploymentCommand = (("powershell -NoProfile -NoLogo -ExecutionPolicy Unrestricted -Command \"& \"$pwd\\" + deployScriptFileName) + "\" 2>&1 | echo\""); 686 | templateContent = fixLineEndingsToWindows(templateContent); } 687 | else { 688 | deployScriptFileName = "deploy.sh"; 689 | deploymentCommand = ("bash " + deployScriptFileName); 690 | templateContent = fixLineEndingsToUnix(templateContent); } ; } ; 691 | 692 | 693 | deployScriptPath = path.join(__this.scriptOutputPath, deployScriptFileName); 694 | deploymentFilePath = path.join(__this.repositoryRoot, ".deployment"); 695 | 696 | 697 | return writeContentToFile(deployScriptPath, templateContent, __cb(_, __frame, 23, 2, function __$ScriptGenerator_prototype_writeDeploymentFiles__23() { return (function __$ScriptGenerator_prototype_writeDeploymentFiles__23(__then) { 698 | 699 | if (!__this.noDotDeployment) { 700 | 701 | return writeContentToFile(deploymentFilePath, ("[config]\ncommand = " + deploymentCommand), __cb(_, __frame, 27, 4, __then, true)); } else { __then(); } ; })(function __$ScriptGenerator_prototype_writeDeploymentFiles__23() { 702 | 703 | 704 | log.info("Generated deployment script files"); _(); }); }, true)); });}; 705 | 706 | 707 | function getTemplateContent(templateFileName) { 708 | return fs.readFileSync(getTemplatePath(templateFileName), "utf8");}; 709 | 710 | 711 | function getTemplatePath(fileName) { 712 | return path.join(templatesDir, fileName);}; 713 | 714 | 715 | function writeContentToFile(path, content, _) { var __frame = { name: "writeContentToFile", line: 715 }; return __func(_, this, arguments, writeContentToFile, 2, __frame, function __$writeContentToFile() { return (function __$writeContentToFile(__then) { 716 | 717 | if (fs.existsSync(path)) { 718 | return confirm((("The file: \"" + path) + "\" already exists\nAre you sure you want to overwrite it (y/n): "), __cb(_, __frame, 3, 9, function ___(__0, __2) { var __1 = !__2; return (function __$writeContentToFile(__then) { if (__1) { return _(null); } else { __then(); } ; })(__then); }, true)); } else { __then(); } ; })(function __$writeContentToFile() { 719 | 720 | 721 | 722 | 723 | 724 | return fs.writeFile(path, content, __cb(_, __frame, 9, 2, _, true)); }); });}; 725 | 726 | 727 | function argNotNull(arg, argName) { 728 | if (((arg === null) || (arg === undefined))) { 729 | throw new Error((("The argument \"" + argName) + "\" is null")); };}; 730 | 731 | 732 | 733 | exports.ScriptGenerator = ScriptGenerator; -------------------------------------------------------------------------------- /lib/polyfill.js: -------------------------------------------------------------------------------- 1 | // support node prior to v4.0.0 2 | exports.endsWith = function(searchString, position) { 3 | var subjectString = this.toString(); 4 | if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) { 5 | position = subjectString.length; 6 | } 7 | position -= searchString.length; 8 | var lastIndex = subjectString.lastIndexOf(searchString, position); 9 | return lastIndex !== -1 && lastIndex === position; 10 | }; 11 | -------------------------------------------------------------------------------- /lib/templates/deploy.bash.aspnet.core.template: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################################################################## 3 | # Deployment 4 | # ---------- 5 | 6 | echo Handling ASP.NET Core Web Application deployment. 7 | 8 | # 1. Restore nuget packages 9 | dotnet restore "$DEPLOYMENT_SOURCE/{RestoreArguments}" 10 | exitWithMessageOnError "dotnet restore failed" 11 | 12 | # 2. Build and publish 13 | dotnet publish "$DEPLOYMENT_SOURCE/{DotnetpublishArguments}" --output "$DEPLOYMENT_TEMP" --configuration Release 14 | exitWithMessageOnError "dotnet publish failed" 15 | 16 | # 3. KuduSync 17 | "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_TEMP" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh" 18 | exitWithMessageOnError "Kudu Sync failed" 19 | 20 | 21 | ################################################################################################################################## 22 | -------------------------------------------------------------------------------- /lib/templates/deploy.bash.aspnet.template: -------------------------------------------------------------------------------- 1 | if [ "x$DEPLOYMENT_TEMP" = x ]; then 2 | DEPLOYMENT_TEMP=/tmp/`date +%s` 3 | CLEAN_LOCAL_DEPLOYMENT_TEMP=true 4 | fi 5 | 6 | if [ "x$CLEAN_LOCAL_DEPLOYMENT_TEMP" = xtrue ]; then 7 | rm -rf "$DEPLOYMENT_TEMP" 8 | mkdir "$DEPLOYMENT_TEMP" 9 | fi 10 | -------------------------------------------------------------------------------- /lib/templates/deploy.bash.basic.template: -------------------------------------------------------------------------------- 1 | ################################################################################################################################## 2 | # Deployment 3 | # ---------- 4 | 5 | echo Handling Basic Web Site deployment. 6 | 7 | # 1. KuduSync 8 | if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then 9 | 10 | if [[ "$IGNORE_MANIFEST" -eq "1" ]]; then 11 | IGNORE_MANIFEST_PARAM=-x 12 | fi 13 | 14 | "$KUDU_SYNC_CMD" -v 50 $IGNORE_MANIFEST_PARAM -f "$DEPLOYMENT_SOURCE{SitePath}" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh" 15 | exitWithMessageOnError "Kudu Sync failed" 16 | fi 17 | 18 | ################################################################################################################################## 19 | -------------------------------------------------------------------------------- /lib/templates/deploy.bash.functionbasic.template: -------------------------------------------------------------------------------- 1 | # Npm helper 2 | # ------------ 3 | 4 | npmPath=`which npm 2> /dev/null` 5 | if [ -z $npmPath ] 6 | then 7 | NPM_CMD="node \"$NPM_JS_PATH\"" # on windows server there's only npm.cmd 8 | else 9 | NPM_CMD=npm 10 | fi 11 | 12 | ################################################################################################################################## 13 | # Deployment 14 | # ---------- 15 | 16 | echo Handling function App deployment. 17 | 18 | RunNpm() { 19 | echo Restoring npm packages in $1 20 | 21 | pushd $1 > /dev/null 22 | eval $NPM_CMD install --production 2>&1 23 | exitWithMessageOnError "Npm Install Failed" 24 | popd > /dev/null 25 | } 26 | 27 | RestoreNpmPackages() { 28 | 29 | local lookup="package.json" 30 | if [ -e "$1/$lookup" ] 31 | then 32 | RunNpm $1 33 | fi 34 | 35 | for subDirectory in "$1"/* 36 | do 37 | if [ -d $subDirectory ] && [ -e "$subDirectory/$lookup" ] 38 | then 39 | RunNpm $subDirectory 40 | fi 41 | done 42 | } 43 | 44 | InstallFunctionExtensions() { 45 | echo Installing azure function extensions from nuget 46 | 47 | local lookup="extensions.csproj" 48 | if [ -e "$1/$lookup" ] 49 | then 50 | pushd $1 > /dev/null 51 | dotnet build -o bin 52 | exitWithMessageOnError "Function extensions installation failed" 53 | popd > /dev/null 54 | fi 55 | } 56 | 57 | DeployWithoutFuncPack() { 58 | echo Not using funcpack because SCM_USE_FUNCPACK is not set to 1 59 | 60 | # 1. Install function extensions 61 | InstallFunctionExtensions "$DEPLOYMENT_SOURCE{SitePath}" 62 | 63 | # 2. KuduSync 64 | if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then 65 | "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE{SitePath}" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh;obj" 66 | exitWithMessageOnError "Kudu Sync failed" 67 | fi 68 | 69 | # 3. Restore npm 70 | RestoreNpmPackages "$DEPLOYMENT_TARGET" 71 | } 72 | 73 | DeployWithoutFuncPack 74 | # TODO funcpack is not installed on linux machine 75 | 76 | ################################################################################################################################## 77 | -------------------------------------------------------------------------------- /lib/templates/deploy.bash.go.template: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################################################################## 3 | # Deployment 4 | # ---------- 5 | 6 | echo Handling Go app deployment. 7 | 8 | APPNAME=app 9 | export GOPATH=$DEPLOYMENT_TEMP/go 10 | export APPPATH=$GOPATH/src/$APPNAME 11 | 12 | # 1. KuduSync 13 | mkdir -p $APPPATH 14 | "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE{SitePath}" -t "$APPPATH" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh" 15 | exitWithMessageOnError "Kudu Sync failed" 16 | 17 | # 2. Install dependencies 18 | pushd $APPPATH 19 | if ls *.toml >/dev/null 2>&1; then 20 | dep ensure 21 | exitWithMessageOnError "dep ensure failed" 22 | else 23 | go get -v -d ./... 24 | exitWithMessageOnError "go get failed" 25 | fi 26 | 27 | # 3. Build ( since we are building on debian based image for an alpine image we need to compile with static linking against musl). 28 | CC=$(which musl-gcc) go build --ldflags '-linkmode external -extldflags "-static"' -o $APPNAME 29 | exitWithMessageOnError "go build failed" 30 | popd 31 | 32 | # 4. KuduSync 33 | "$KUDU_SYNC_CMD" -v 50 -f "$APPPATH" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh" 34 | exitWithMessageOnError "Kudu Sync failed" 35 | 36 | 37 | ################################################################################################################################## 38 | -------------------------------------------------------------------------------- /lib/templates/deploy.bash.node.template: -------------------------------------------------------------------------------- 1 | # Node Helpers 2 | # ------------ 3 | 4 | selectNodeVersion () { 5 | if [[ -n "$KUDU_SELECT_NODE_VERSION_CMD" ]]; then 6 | SELECT_NODE_VERSION="$KUDU_SELECT_NODE_VERSION_CMD \"$DEPLOYMENT_SOURCE{SitePath}\" \"$DEPLOYMENT_TARGET\" \"$DEPLOYMENT_TEMP\"" 7 | eval $SELECT_NODE_VERSION 8 | exitWithMessageOnError "select node version failed" 9 | 10 | if [[ -e "$DEPLOYMENT_TEMP/__nodeVersion.tmp" ]]; then 11 | NODE_EXE=`cat "$DEPLOYMENT_TEMP/__nodeVersion.tmp"` 12 | exitWithMessageOnError "getting node version failed" 13 | fi 14 | 15 | if [[ -e "$DEPLOYMENT_TEMP/__npmVersion.tmp" ]]; then 16 | NPM_JS_PATH=`cat "$DEPLOYMENT_TEMP/__npmVersion.tmp"` 17 | exitWithMessageOnError "getting npm version failed" 18 | fi 19 | 20 | if [[ ! -n "$NODE_EXE" ]]; then 21 | NODE_EXE=node 22 | fi 23 | 24 | NPM_CMD="\"$NODE_EXE\" \"$NPM_JS_PATH\"" 25 | else 26 | NPM_CMD=npm 27 | NODE_EXE=node 28 | fi 29 | } 30 | 31 | ################################################################################################################################## 32 | # Deployment 33 | # ---------- 34 | 35 | echo Handling node.js deployment. 36 | 37 | # 1. KuduSync 38 | if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then 39 | "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE{SitePath}" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh" 40 | exitWithMessageOnError "Kudu Sync failed" 41 | fi 42 | 43 | # 2. Select node version 44 | selectNodeVersion 45 | 46 | # 3. Install npm packages 47 | if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then 48 | cd "$DEPLOYMENT_TARGET" 49 | echo "Running $NPM_CMD install --production" 50 | eval $NPM_CMD install --production 51 | exitWithMessageOnError "npm failed" 52 | cd - > /dev/null 53 | fi 54 | 55 | ################################################################################################################################## 56 | -------------------------------------------------------------------------------- /lib/templates/deploy.bash.php.template: -------------------------------------------------------------------------------- 1 | # PHP Helpers 2 | # ----------- 3 | 4 | initializeDeploymentConfig() { 5 | if [ ! -e "$COMPOSER_ARGS" ]; then 6 | COMPOSER_ARGS="--no-interaction --prefer-dist --optimize-autoloader --no-progress --no-dev --verbose" 7 | echo "No COMPOSER_ARGS variable declared in App Settings, using the default settings" 8 | else 9 | echo "Using COMPOSER_ARGS variable declared in App Setting" 10 | fi 11 | echo "Composer settings: $COMPOSER_ARGS" 12 | } 13 | 14 | ################################################################################################################################## 15 | # Deployment 16 | # ---------- 17 | 18 | echo PHP deployment 19 | 20 | # 1. KuduSync 21 | if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then 22 | "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE{SitePath}" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh" 23 | exitWithMessageOnError "Kudu Sync failed" 24 | fi 25 | 26 | # 2. Verify composer installed 27 | hash composer 2>/dev/null 28 | exitWithMessageOnError "Missing composer executable" 29 | 30 | # 3. Initialize Composer Config 31 | initializeDeploymentConfig 32 | 33 | # 4. Use composer 34 | echo "$DEPLOYMENT_TARGET" 35 | if [ -e "$DEPLOYMENT_TARGET/composer.json" ]; then 36 | echo "Found composer.json" 37 | pushd "$DEPLOYMENT_TARGET" 38 | composer install $COMPOSER_ARGS 39 | exitWithMessageOnError "Composer install failed" 40 | popd 41 | fi 42 | ################################################################################################################################## 43 | -------------------------------------------------------------------------------- /lib/templates/deploy.bash.postfix.template: -------------------------------------------------------------------------------- 1 | echo "Finished successfully." 2 | -------------------------------------------------------------------------------- /lib/templates/deploy.bash.prefix.template: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ---------------------- 4 | # KUDU Deployment Script 5 | # Version: {Version} 6 | # ---------------------- 7 | 8 | # Helpers 9 | # ------- 10 | 11 | exitWithMessageOnError () { 12 | if [ ! $? -eq 0 ]; then 13 | echo "An error has occurred during web site deployment." 14 | echo $1 15 | exit 1 16 | fi 17 | } 18 | 19 | # Prerequisites 20 | # ------------- 21 | 22 | # Verify node.js installed 23 | hash node 2>/dev/null 24 | exitWithMessageOnError "Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment." 25 | 26 | # Setup 27 | # ----- 28 | 29 | SCRIPT_DIR="${BASH_SOURCE[0]%\\*}" 30 | SCRIPT_DIR="${SCRIPT_DIR%/*}" 31 | ARTIFACTS=$SCRIPT_DIR/../artifacts 32 | KUDU_SYNC_CMD=${KUDU_SYNC_CMD//\"} 33 | 34 | if [[ ! -n "$DEPLOYMENT_SOURCE" ]]; then 35 | DEPLOYMENT_SOURCE=$SCRIPT_DIR 36 | fi 37 | 38 | if [[ ! -n "$NEXT_MANIFEST_PATH" ]]; then 39 | NEXT_MANIFEST_PATH=$ARTIFACTS/manifest 40 | 41 | if [[ ! -n "$PREVIOUS_MANIFEST_PATH" ]]; then 42 | PREVIOUS_MANIFEST_PATH=$NEXT_MANIFEST_PATH 43 | fi 44 | fi 45 | 46 | if [[ ! -n "$DEPLOYMENT_TARGET" ]]; then 47 | DEPLOYMENT_TARGET=$ARTIFACTS/wwwroot 48 | else 49 | KUDU_SERVICE=true 50 | fi 51 | 52 | if [[ ! -n "$KUDU_SYNC_CMD" ]]; then 53 | # Install kudu sync 54 | echo Installing Kudu Sync 55 | npm install kudusync -g --silent 56 | exitWithMessageOnError "npm failed" 57 | 58 | if [[ ! -n "$KUDU_SERVICE" ]]; then 59 | # In case we are running locally this is the correct location of kuduSync 60 | KUDU_SYNC_CMD=kuduSync 61 | else 62 | # In case we are running on kudu service this is the correct location of kuduSync 63 | KUDU_SYNC_CMD=$APPDATA/npm/node_modules/kuduSync/bin/kuduSync 64 | fi 65 | fi 66 | 67 | -------------------------------------------------------------------------------- /lib/templates/deploy.bash.python.template: -------------------------------------------------------------------------------- 1 | echo Python deployment. 2 | 3 | # 1. KuduSync 4 | 5 | if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then 6 | "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE{SitePath}" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh" 7 | exitWithMessageOnError "Kudu Sync failed" 8 | fi 9 | 10 | 11 | #2. Install any dependencies 12 | 13 | export ANTENV="antenv" 14 | export PYTHON3="python3.7" 15 | 16 | if [ "$WEBSITE_PYTHON_VERSION" = "3.6" ]; then 17 | export ANTENV="antenv3.6" 18 | export PYTHON3="python3.6" 19 | fi 20 | 21 | echo "$DEPLOYMENT_SOURCE" 22 | echo "$DEPLOYMENT_TARGET" 23 | 24 | 25 | if [ -e "$DEPLOYMENT_TARGET/requirements.txt" ]; then 26 | echo "Found requirements.txt" 27 | echo "Python Virtual Environment: $ANTENV" 28 | echo "Python Version: $PYTHON3" 29 | 30 | cd "$DEPLOYMENT_TARGET" 31 | 32 | #2a. Setup virtual Environment 33 | echo "Create virtual environment" 34 | $PYTHON3 -m venv $ANTENV --copies 35 | 36 | #2b. Activate virtual environment 37 | echo "Activate virtual environment" 38 | source $ANTENV/bin/activate 39 | 40 | #2c. Install dependencies 41 | pip install -r requirements.txt 42 | 43 | echo "pip install finished" 44 | fi 45 | -------------------------------------------------------------------------------- /lib/templates/deploy.bash.ruby.template: -------------------------------------------------------------------------------- 1 | # Rails Helpers 2 | # ----------- 3 | 4 | setRubyVersion(){ 5 | if [ "$FRAMEWORK_VERSION" = "2.3" ]; then # default to 2.3.3 6 | FRAMEWORK_VERSION=2.3.3 7 | fi 8 | RUBY_VERSION=$(ls /usr/local/.rbenv/versions | grep -v - | grep $FRAMEWORK_VERSION | tail -n 1) 9 | echo "Using ruby version $RUBY_VERSION" 10 | } 11 | 12 | initializeDeploymentConfig() { 13 | if [ -z $BUNDLE_WITHOUT ]; then 14 | echo "Bundle install with no 'without' options"; 15 | RUBY_OPTIONS=""; 16 | else 17 | RUBY_OPTIONS="--without $BUNDLE_WITHOUT"; 18 | echo "Bundle install with options $RUBY_OPTIONS"; 19 | fi 20 | 21 | if [ -z $BUNDLE_INSTALL_LOCATION ]; then 22 | echo "Defaulting gem installation directory to /tmp/bundle"; 23 | BUNDLE_INSTALL_LOCATION="/tmp/bundle"; 24 | else 25 | echo "Gem installation directory is $BUNDLE_INSTALL_LOCATION"; 26 | fi 27 | 28 | if [ -z $RUBY_SITE_CONFIG_DIR ]; then 29 | echo "Defaulting site config directory to /home/site/config"; 30 | RUBY_SITE_CONFIG_DIR="/home/site/config" 31 | else 32 | echo "site config directory is $RUBY_SITE_CONFIG_DIR"; 33 | fi 34 | 35 | setRubyVersion 36 | } 37 | 38 | 39 | 40 | ################################################################################################################################## 41 | # Deployment 42 | # ---------- 43 | 44 | echo Ruby on Rails deployment. 45 | 46 | # 1. KuduSync 47 | if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then 48 | "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE{SitePath}" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh" 49 | exitWithMessageOnError "Kudu Sync failed" 50 | fi 51 | 52 | initializeDeploymentConfig 53 | 54 | echo "$DEPLOYMENT_TARGET" 55 | if [ -e "$DEPLOYMENT_TARGET/Gemfile" ]; then 56 | echo "Found gemfile" 57 | pushd "$DEPLOYMENT_TARGET" 58 | 59 | eval "$(rbenv init -)" 60 | exitWithMessageOnError "init failed" 61 | 62 | echo "Setting ruby version" 63 | rbenv local $RUBY_VERSION 64 | exitWithMessageOnError "Failed to switch ruby versions" 65 | 66 | echo "Running bundle clean" 67 | bundle clean --force 68 | 69 | echo "Running bundle install" 70 | mkdir -p $BUNDLE_INSTALL_LOCATION 71 | bundle config --global path $BUNDLE_INSTALL_LOCATION 72 | bundle install --no-deployment $RUBY_OPTIONS 73 | exitWithMessageOnError "bundler failed" 74 | 75 | echo "Zipping up bundle contents" 76 | tar -zcf /tmp/gems.tgz -C $BUNDLE_INSTALL_LOCATION . 77 | exitWithMessageOnError "Error compressing gems" 78 | 79 | mkdir -p $RUBY_SITE_CONFIG_DIR 80 | exitWithMessageOnError "Error making config directory" 81 | 82 | mv -f /tmp/gems.tgz $RUBY_SITE_CONFIG_DIR 83 | 84 | if [ "$ASSETS_PRECOMPILE" == true ]; then 85 | echo "running rake assets:precompile" 86 | bundle exec rake --trace assets:precompile 87 | fi 88 | exitWithMessageOnError "precompilation failed" 89 | popd 90 | fi 91 | 92 | ################################################################################################################################## 93 | 94 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.aspnet.core.msbuild16.template: -------------------------------------------------------------------------------- 1 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 | :: Deployment 3 | :: ---------- 4 | 5 | echo Handling ASP.NET Core Web Application deployment with MSBuild16. 6 | 7 | :: 1. Restore, Build and publish 8 | call :ExecuteCmd "%MSBUILD_16_DIR%\MSBuild.exe" /restore "%DEPLOYMENT_SOURCE%\{ProjectPath}" /p:DeployOnBuild=true /p:configuration=Release /p:publishurl="%DEPLOYMENT_TEMP%" %SCM_BUILD_ARGS% 9 | IF !ERRORLEVEL! NEQ 0 goto error 10 | 11 | :: 2. KuduSync 12 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 13 | IF !ERRORLEVEL! NEQ 0 goto error 14 | 15 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 16 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.aspnet.core.msbuild1607.template: -------------------------------------------------------------------------------- 1 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 | :: Deployment 3 | :: ---------- 4 | 5 | echo Handling ASP.NET Core Web Application deployment with MSBuild16.7.0. 6 | 7 | :: 1. Restore, Build and publish 8 | call :ExecuteCmd "%MSBUILD_1670_DIR%\MSBuild.exe" /restore "%DEPLOYMENT_SOURCE%\{ProjectPath}" /p:DeployOnBuild=true /p:configuration=Release /p:publishurl="%DEPLOYMENT_TEMP%" %SCM_BUILD_ARGS% 9 | IF !ERRORLEVEL! NEQ 0 goto error 10 | 11 | :: 2. KuduSync 12 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 13 | IF !ERRORLEVEL! NEQ 0 goto error 14 | 15 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 16 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.aspnet.core.template: -------------------------------------------------------------------------------- 1 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 | :: Deployment 3 | :: ---------- 4 | 5 | echo Handling ASP.NET Core Web Application deployment. 6 | 7 | :: 1. Restore nuget packages 8 | call :ExecuteCmd dotnet restore "%DEPLOYMENT_SOURCE%\{RestoreArguments}" 9 | IF !ERRORLEVEL! NEQ 0 goto error 10 | 11 | :: 2. Build and publish 12 | call :ExecuteCmd dotnet publish "%DEPLOYMENT_SOURCE%\{DotnetpublishArguments}" --output "%DEPLOYMENT_TEMP%" --configuration Release 13 | IF !ERRORLEVEL! NEQ 0 goto error 14 | 15 | :: 3. KuduSync 16 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 17 | IF !ERRORLEVEL! NEQ 0 goto error 18 | 19 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 20 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.aspnet.template: -------------------------------------------------------------------------------- 1 | IF NOT DEFINED DEPLOYMENT_TEMP ( 2 | SET DEPLOYMENT_TEMP=%temp%\___deployTemp%random% 3 | SET CLEAN_LOCAL_DEPLOYMENT_TEMP=true 4 | ) 5 | 6 | IF DEFINED CLEAN_LOCAL_DEPLOYMENT_TEMP ( 7 | IF EXIST "%DEPLOYMENT_TEMP%" rd /s /q "%DEPLOYMENT_TEMP%" 8 | mkdir "%DEPLOYMENT_TEMP%" 9 | ) 10 | 11 | IF DEFINED MSBUILD_PATH goto MsbuildPathDefined 12 | SET MSBUILD_PATH=%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe 13 | :MsbuildPathDefined 14 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.aspnet.wap.template: -------------------------------------------------------------------------------- 1 | 2 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 | :: Deployment 4 | :: ---------- 5 | 6 | echo Handling .NET Web Application deployment. 7 | 8 | :: 1. Restore NuGet packages 9 | IF /I "{SolutionPath}" NEQ "" ( 10 | call :ExecuteCmd nuget restore "%DEPLOYMENT_SOURCE%\{SolutionPath}" 11 | IF !ERRORLEVEL! NEQ 0 goto error 12 | ) 13 | 14 | :: 2. Build to the temporary path 15 | IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" ( 16 | call :ExecuteCmd "%MSBUILD_PATH%" {MSBuildArguments} 17 | ) ELSE ( 18 | call :ExecuteCmd "%MSBUILD_PATH%" {MSBuildArgumentsForInPlace} 19 | ) 20 | 21 | IF !ERRORLEVEL! NEQ 0 goto error 22 | 23 | :: 3. KuduSync 24 | IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" ( 25 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 26 | IF !ERRORLEVEL! NEQ 0 goto error 27 | ) 28 | 29 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 30 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.aspnet.website.template: -------------------------------------------------------------------------------- 1 | 2 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 | :: Deployment 4 | :: ---------- 5 | 6 | echo Handling .NET Web Site deployment. 7 | 8 | :: 1. Build to the repository path 9 | call :ExecuteCmd "%MSBUILD_PATH%" {MSBuildArguments} 10 | IF !ERRORLEVEL! NEQ 0 goto error 11 | 12 | :: 2. KuduSync 13 | IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" ( 14 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%{SitePath}" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 15 | IF !ERRORLEVEL! NEQ 0 goto error 16 | ) 17 | 18 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 19 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.basic.template: -------------------------------------------------------------------------------- 1 | 2 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 | :: Deployment 4 | :: ---------- 5 | 6 | echo Handling Basic Web Site deployment. 7 | 8 | :: 1. KuduSync 9 | IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" ( 10 | 11 | IF /I "%IGNORE_MANIFEST%" EQU "1" ( 12 | SET IGNORE_MANIFEST_PARAM=-x 13 | ) 14 | 15 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 !IGNORE_MANIFEST_PARAM! -f "%DEPLOYMENT_SOURCE%{SitePath}" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 16 | IF !ERRORLEVEL! NEQ 0 goto error 17 | ) 18 | 19 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 20 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.dotnetconsole.msbuild16.template: -------------------------------------------------------------------------------- 1 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 | :: Deployment 3 | :: ---------- 4 | 5 | echo Handling .NET Console Application deployment with MSBuild16. 6 | 7 | :: 1. Build to the temporary path 8 | call :ExecuteCmd "%MSBUILD_16_DIR%\MSBuild.exe" /restore {MSBuildArguments} 9 | IF !ERRORLEVEL! NEQ 0 goto error 10 | 11 | :: 2. Run web job deploy script 12 | IF DEFINED WEBJOBS_DEPLOY_CMD ( 13 | call :ExecuteCmd "%WEBJOBS_DEPLOY_CMD%" 14 | ) 15 | 16 | :: 3. KuduSync 17 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 18 | IF !ERRORLEVEL! NEQ 0 goto error 19 | 20 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 21 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.dotnetconsole.msbuild1607.template: -------------------------------------------------------------------------------- 1 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 | :: Deployment 3 | :: ---------- 4 | 5 | echo Handling .NET Console Application deployment with MSBuild16.7.0. 6 | 7 | :: 1. Build to the temporary path 8 | call :ExecuteCmd "%MSBUILD_1670_DIR%\MSBuild.exe" /restore {MSBuildArguments} 9 | IF !ERRORLEVEL! NEQ 0 goto error 10 | 11 | :: 2. Run web job deploy script 12 | IF DEFINED WEBJOBS_DEPLOY_CMD ( 13 | call :ExecuteCmd "%WEBJOBS_DEPLOY_CMD%" 14 | ) 15 | 16 | :: 3. KuduSync 17 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 18 | IF !ERRORLEVEL! NEQ 0 goto error 19 | 20 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 21 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.dotnetconsole.template: -------------------------------------------------------------------------------- 1 | 2 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 | :: Deployment 4 | :: ---------- 5 | 6 | echo Handling .NET Console Application deployment. 7 | 8 | :: 1. Restore NuGet packages 9 | IF /I "{SolutionPath}" NEQ "" ( 10 | call :ExecuteCmd nuget restore "%DEPLOYMENT_SOURCE%\{SolutionPath}" -MSBuildPath "%MSBUILD_15_DIR%" 11 | IF !ERRORLEVEL! NEQ 0 goto error 12 | ) 13 | 14 | :: 2. Build to the temporary path 15 | call :ExecuteCmd "%MSBUILD_15_DIR%\MSBuild.exe" {MSBuildArguments} 16 | IF !ERRORLEVEL! NEQ 0 goto error 17 | 18 | :: 3. Run web job deploy script 19 | IF DEFINED WEBJOBS_DEPLOY_CMD ( 20 | call :ExecuteCmd "%WEBJOBS_DEPLOY_CMD%" 21 | ) 22 | 23 | :: 4. KuduSync 24 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 25 | IF !ERRORLEVEL! NEQ 0 goto error 26 | 27 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 28 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.function.msbuild16.template: -------------------------------------------------------------------------------- 1 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 | :: Deployment 3 | :: ---------- 4 | 5 | echo Handling function App deployment with Msbuild16. 6 | 7 | :: 1. Restore, Build and publish 8 | call :ExecuteCmd "%MSBUILD_16_DIR%\MSBuild.exe" /restore "%DEPLOYMENT_SOURCE%\{ProjectPath}" /p:DeployOnBuild=true /p:configuration=Release /p:publishurl="%DEPLOYMENT_TEMP%" %SCM_BUILD_ARGS% 9 | IF !ERRORLEVEL! NEQ 0 goto error 10 | 11 | :: 2. KuduSync 12 | IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" ( 13 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 14 | IF !ERRORLEVEL! NEQ 0 goto error 15 | ) 16 | 17 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 18 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.function.msbuild1607.template: -------------------------------------------------------------------------------- 1 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 | :: Deployment 3 | :: ---------- 4 | 5 | echo Handling function App deployment with Msbuild16.7.0. 6 | 7 | :: 1. Restore, Build and publish 8 | call :ExecuteCmd "%MSBUILD_1670_DIR%\MSBuild.exe" /restore "%DEPLOYMENT_SOURCE%\{ProjectPath}" /p:DeployOnBuild=true /p:configuration=Release /p:publishurl="%DEPLOYMENT_TEMP%" %SCM_BUILD_ARGS% 9 | IF !ERRORLEVEL! NEQ 0 goto error 10 | 11 | :: 2. KuduSync 12 | IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" ( 13 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 14 | IF !ERRORLEVEL! NEQ 0 goto error 15 | ) 16 | 17 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 18 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.functionbasic.template: -------------------------------------------------------------------------------- 1 | 2 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 | :: Deployment 4 | :: ---------- 5 | 6 | echo Handling function App deployment. 7 | 8 | if "%SCM_USE_FUNCPACK%" == "1" ( 9 | call :DeployWithFuncPack 10 | ) else ( 11 | call :DeployWithoutFuncPack 12 | ) 13 | 14 | goto end 15 | 16 | :DeployWithFuncPack 17 | setlocal 18 | 19 | echo Using funcpack to optimize cold start 20 | 21 | :: 1. Copy to local storage 22 | echo Copying repository files to local storage 23 | xcopy "%DEPLOYMENT_SOURCE%{SitePath}" "%DEPLOYMENT_TEMP%" /seyiq 24 | IF !ERRORLEVEL! NEQ 0 goto error 25 | 26 | :: 2. Install function extensions 27 | call :InstallFunctionExtensions "%DEPLOYMENT_TEMP%" 28 | 29 | :: 3. Restore npm 30 | call :RestoreNpmPackages "%DEPLOYMENT_TEMP%" 31 | 32 | :: 4. FuncPack 33 | pushd "%DEPLOYMENT_TEMP%" 34 | call funcpack pack . 35 | IF !ERRORLEVEL! NEQ 0 goto error 36 | popd 37 | 38 | :: 5. KuduSync 39 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd;node_modules;obj" 40 | IF !ERRORLEVEL! NEQ 0 goto error 41 | 42 | exit /b %ERRORLEVEL% 43 | 44 | 45 | :DeployWithoutFuncPack 46 | setlocal 47 | 48 | echo Not using funcpack because SCM_USE_FUNCPACK is not set to 1 49 | 50 | :: 1. Install function extensions 51 | call :InstallFunctionExtensions "%DEPLOYMENT_SOURCE%{SitePath}" 52 | 53 | :: 2. KuduSync 54 | IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" ( 55 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%{SitePath}" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd;obj" 56 | IF !ERRORLEVEL! NEQ 0 goto error 57 | ) 58 | 59 | :: 3. Restore npm 60 | call :RestoreNpmPackages "%DEPLOYMENT_TARGET%" 61 | 62 | exit /b %ERRORLEVEL% 63 | 64 | 65 | :RestoreNpmPackages 66 | setlocal 67 | 68 | echo Restoring npm packages in %1 69 | 70 | IF EXIST "%1\package.json" ( 71 | pushd "%1" 72 | call npm install --production 73 | IF !ERRORLEVEL! NEQ 0 goto error 74 | popd 75 | ) 76 | 77 | FOR /F "tokens=*" %%i IN ('DIR /B %1 /A:D') DO ( 78 | IF EXIST "%1\%%i\package.json" ( 79 | pushd "%1\%%i" 80 | call npm install --production 81 | IF !ERRORLEVEL! NEQ 0 goto error 82 | popd 83 | ) 84 | ) 85 | 86 | exit /b %ERRORLEVEL% 87 | 88 | :InstallFunctionExtensions 89 | setlocal 90 | 91 | echo Installing function extensions from nuget 92 | 93 | IF EXIST "%1\extensions.csproj" ( 94 | pushd "%1" 95 | call dotnet build -o bin 96 | IF !ERRORLEVEL! NEQ 0 goto error 97 | popd 98 | ) 99 | 100 | exit /b %ERRORLEVEL% 101 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 102 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.functionmsbuild.template: -------------------------------------------------------------------------------- 1 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 | :: Deployment 3 | :: ---------- 4 | echo Handling function App deployment with Msbuild. 5 | 6 | :: 1. Restore nuget packages 7 | call :ExecuteCmd nuget.exe restore "%DEPLOYMENT_SOURCE%\{RestoreArguments}" -MSBuildPath "%MSBUILD_15_DIR%" 8 | IF !ERRORLEVEL! NEQ 0 goto error 9 | 10 | :: 2. Build and publish 11 | call :ExecuteCmd "%MSBUILD_15_DIR%\MSBuild.exe" "%DEPLOYMENT_SOURCE%\{ProjectPath}" /p:DeployOnBuild=true /p:configuration=Release /p:publishurl="%DEPLOYMENT_TEMP%" %SCM_BUILD_ARGS% 12 | IF !ERRORLEVEL! NEQ 0 goto error 13 | 14 | :: 3. KuduSync 15 | IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" ( 16 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 17 | IF !ERRORLEVEL! NEQ 0 goto error 18 | ) 19 | 20 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 21 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.node.template: -------------------------------------------------------------------------------- 1 | goto Deployment 2 | 3 | :: Utility Functions 4 | :: ----------------- 5 | 6 | :SelectNodeVersion 7 | 8 | IF DEFINED KUDU_SELECT_NODE_VERSION_CMD ( 9 | :: The following are done only on Windows Azure Websites environment 10 | call %KUDU_SELECT_NODE_VERSION_CMD% "%DEPLOYMENT_SOURCE%{SitePath}" "%DEPLOYMENT_TARGET%" "%DEPLOYMENT_TEMP%" 11 | IF !ERRORLEVEL! NEQ 0 goto error 12 | 13 | IF EXIST "%DEPLOYMENT_TEMP%\__nodeVersion.tmp" ( 14 | SET /p NODE_EXE=<"%DEPLOYMENT_TEMP%\__nodeVersion.tmp" 15 | IF !ERRORLEVEL! NEQ 0 goto error 16 | ) 17 | 18 | IF EXIST "%DEPLOYMENT_TEMP%\__npmVersion.tmp" ( 19 | SET /p NPM_JS_PATH=<"%DEPLOYMENT_TEMP%\__npmVersion.tmp" 20 | IF !ERRORLEVEL! NEQ 0 goto error 21 | ) 22 | 23 | IF NOT DEFINED NODE_EXE ( 24 | SET NODE_EXE=node 25 | ) 26 | 27 | SET NPM_CMD="!NODE_EXE!" "!NPM_JS_PATH!" 28 | ) ELSE ( 29 | SET NPM_CMD=npm 30 | SET NODE_EXE=node 31 | ) 32 | 33 | goto :EOF 34 | 35 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 36 | :: Deployment 37 | :: ---------- 38 | 39 | :Deployment 40 | echo Handling node.js deployment. 41 | 42 | :: 1. KuduSync 43 | IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" ( 44 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%{SitePath}" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 45 | IF !ERRORLEVEL! NEQ 0 goto error 46 | ) 47 | 48 | :: 2. Select node version 49 | call :SelectNodeVersion 50 | 51 | :: 3. Install npm packages 52 | IF EXIST "%DEPLOYMENT_TARGET%\package.json" ( 53 | pushd "%DEPLOYMENT_TARGET%" 54 | call :ExecuteCmd !NPM_CMD! install --production 55 | IF !ERRORLEVEL! NEQ 0 goto error 56 | popd 57 | ) 58 | 59 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 60 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.postfix.template: -------------------------------------------------------------------------------- 1 | goto end 2 | 3 | :: Execute command routine that will echo out when error 4 | :ExecuteCmd 5 | setlocal 6 | set _CMD_=%* 7 | call %_CMD_% 8 | if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_% 9 | exit /b %ERRORLEVEL% 10 | 11 | :error 12 | endlocal 13 | echo An error has occurred during web site deployment. 14 | call :exitSetErrorLevel 15 | call :exitFromFunction 2>nul 16 | 17 | :exitSetErrorLevel 18 | exit /b 1 19 | 20 | :exitFromFunction 21 | () 22 | 23 | :end 24 | endlocal 25 | echo Finished successfully. 26 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.prefix.template: -------------------------------------------------------------------------------- 1 | @if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off 2 | 3 | :: ---------------------- 4 | :: KUDU Deployment Script 5 | :: Version: {Version} 6 | :: ---------------------- 7 | 8 | :: Prerequisites 9 | :: ------------- 10 | 11 | :: Verify node.js installed 12 | where node 2>nul >nul 13 | IF %ERRORLEVEL% NEQ 0 ( 14 | echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment. 15 | goto error 16 | ) 17 | 18 | :: Setup 19 | :: ----- 20 | 21 | setlocal enabledelayedexpansion 22 | 23 | SET ARTIFACTS=%~dp0%..\artifacts 24 | 25 | IF NOT DEFINED DEPLOYMENT_SOURCE ( 26 | SET DEPLOYMENT_SOURCE=%~dp0%. 27 | ) 28 | 29 | IF NOT DEFINED DEPLOYMENT_TARGET ( 30 | SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot 31 | ) 32 | 33 | IF NOT DEFINED NEXT_MANIFEST_PATH ( 34 | SET NEXT_MANIFEST_PATH=%ARTIFACTS%\manifest 35 | 36 | IF NOT DEFINED PREVIOUS_MANIFEST_PATH ( 37 | SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%\manifest 38 | ) 39 | ) 40 | 41 | IF NOT DEFINED KUDU_SYNC_CMD ( 42 | :: Install kudu sync 43 | echo Installing Kudu Sync 44 | call npm install kudusync -g --silent 45 | IF !ERRORLEVEL! NEQ 0 goto error 46 | 47 | :: Locally just running "kuduSync" would also work 48 | SET KUDU_SYNC_CMD=%appdata%\npm\kuduSync.cmd 49 | ) 50 | -------------------------------------------------------------------------------- /lib/templates/deploy.batch.python.template: -------------------------------------------------------------------------------- 1 | goto Deployment 2 | 3 | :: Utility Functions 4 | :: ----------------- 5 | 6 | :SelectPythonVersion 7 | 8 | IF DEFINED KUDU_SELECT_PYTHON_VERSION_CMD ( 9 | call %KUDU_SELECT_PYTHON_VERSION_CMD% "%DEPLOYMENT_SOURCE%{SitePath}" "%DEPLOYMENT_TARGET%" "%DEPLOYMENT_TEMP%" 10 | IF !ERRORLEVEL! NEQ 0 goto error 11 | 12 | SET /P PYTHON_RUNTIME=<"%DEPLOYMENT_TEMP%\__PYTHON_RUNTIME.tmp" 13 | IF !ERRORLEVEL! NEQ 0 goto error 14 | 15 | SET /P PYTHON_VER=<"%DEPLOYMENT_TEMP%\__PYTHON_VER.tmp" 16 | IF !ERRORLEVEL! NEQ 0 goto error 17 | 18 | SET /P PYTHON_EXE=<"%DEPLOYMENT_TEMP%\__PYTHON_EXE.tmp" 19 | IF !ERRORLEVEL! NEQ 0 goto error 20 | 21 | SET /P PYTHON_ENV_MODULE=<"%DEPLOYMENT_TEMP%\__PYTHON_ENV_MODULE.tmp" 22 | IF !ERRORLEVEL! NEQ 0 goto error 23 | ) ELSE ( 24 | SET PYTHON_RUNTIME=python-2.7 25 | SET PYTHON_VER=2.7 26 | SET PYTHON_EXE=%SYSTEMDRIVE%\python27\python.exe 27 | SET PYTHON_ENV_MODULE=virtualenv 28 | ) 29 | 30 | goto :EOF 31 | 32 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 33 | :: Deployment 34 | :: ---------- 35 | 36 | :Deployment 37 | echo Handling python deployment. 38 | 39 | :: 1. KuduSync 40 | IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" ( 41 | call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%{SitePath}" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd" 42 | IF !ERRORLEVEL! NEQ 0 goto error 43 | ) 44 | 45 | IF NOT EXIST "%DEPLOYMENT_TARGET%\requirements.txt" goto postPython 46 | IF EXIST "%DEPLOYMENT_TARGET%\.skipPythonDeployment" goto postPython 47 | 48 | echo Detected requirements.txt. You can skip Python specific steps with a .skipPythonDeployment file. 49 | 50 | :: 2. Select Python version 51 | call :SelectPythonVersion 52 | 53 | pushd "%DEPLOYMENT_TARGET%" 54 | 55 | :: 3. Create virtual environment 56 | IF NOT EXIST "%DEPLOYMENT_TARGET%\env\azure.env.%PYTHON_RUNTIME%.txt" ( 57 | IF EXIST "%DEPLOYMENT_TARGET%\env" ( 58 | echo Deleting incompatible virtual environment. 59 | rmdir /q /s "%DEPLOYMENT_TARGET%\env" 60 | IF !ERRORLEVEL! NEQ 0 goto error 61 | ) 62 | 63 | echo Creating %PYTHON_RUNTIME% virtual environment. 64 | %PYTHON_EXE% -m %PYTHON_ENV_MODULE% env 65 | IF !ERRORLEVEL! NEQ 0 goto error 66 | 67 | copy /y NUL "%DEPLOYMENT_TARGET%\env\azure.env.%PYTHON_RUNTIME%.txt" >NUL 68 | ) ELSE ( 69 | echo Found compatible virtual environment. 70 | ) 71 | 72 | :: 4. Install packages 73 | echo Pip install requirements. 74 | env\scripts\pip install -r requirements.txt 75 | IF !ERRORLEVEL! NEQ 0 goto error 76 | 77 | REM Add additional package installation here 78 | REM -- Example -- 79 | REM env\scripts\easy_install pytz 80 | REM IF !ERRORLEVEL! NEQ 0 goto error 81 | 82 | :: 5. Copy web.config 83 | IF EXIST "%DEPLOYMENT_SOURCE%{SitePath}\web.%PYTHON_VER%.config" ( 84 | echo Overwriting web.config with web.%PYTHON_VER%.config 85 | copy /y "%DEPLOYMENT_SOURCE%{SitePath}\web.%PYTHON_VER%.config" "%DEPLOYMENT_TARGET%\web.config" 86 | ) 87 | 88 | :: 6. Django collectstatic 89 | IF EXIST "%DEPLOYMENT_TARGET%\manage.py" ( 90 | IF EXIST "%DEPLOYMENT_TARGET%\env\lib\site-packages\django" ( 91 | IF NOT EXIST "%DEPLOYMENT_TARGET%\.skipDjango" ( 92 | echo Collecting Django static files. You can skip Django specific steps with a .skipDjango file. 93 | IF NOT EXIST "%DEPLOYMENT_TARGET%\static" ( 94 | MKDIR "%DEPLOYMENT_TARGET%\static" 95 | ) 96 | env\scripts\python manage.py collectstatic --noinput --clear 97 | ) 98 | ) 99 | ) 100 | 101 | popd 102 | 103 | :postPython 104 | 105 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 106 | -------------------------------------------------------------------------------- /lib/templates/deploy.posh.aspnet.core.template: -------------------------------------------------------------------------------- 1 | ################################################################################################################################## 2 | # Deployment 3 | # ---------- 4 | 5 | echo "Handling ASP.NET Core Web Application deployment." 6 | 7 | # 1. Restore nuget packages 8 | dotnet restore "$DEPLOYMENT_SOURCE\{RestoreArguments}" 9 | exitWithMessageOnError "Restore failed" 10 | 11 | # 2. Build and publish 12 | dotnet publish "$DEPLOYMENT_SOURCE\{DotnetpublishArguments}" --output "$DEPLOYMENT_TEMP" --configuration Release 13 | exitWithMessageOnError "dotnet publish failed" 14 | 15 | # 3. KuduSync 16 | & $KUDU_SYNC_CMD -v 50 -f "$DEPLOYMENT_TEMP" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.ps1" 17 | exitWithMessageOnError "Kudu Sync failed" 18 | 19 | ################################################################################################################################## 20 | -------------------------------------------------------------------------------- /lib/templates/deploy.posh.aspnet.template: -------------------------------------------------------------------------------- 1 | 2 | $DEPLOYMENT_TEMP = $env:DEPLOYMENT_TEMP 3 | $MSBUILD_PATH = $env:MSBUILD_PATH 4 | 5 | if ($DEPLOYMENT_TEMP -eq $null) { 6 | $DEPLOYMENT_TEMP = "$env:temp\___deployTemp$env:random" 7 | $CLEAN_LOCAL_DEPLOYMENT_TEMP = $true 8 | } 9 | 10 | if ($CLEAN_LOCAL_DEPLOYMENT_TEMP -eq $true) { 11 | if (Test-Path $DEPLOYMENT_TEMP) { 12 | rd -Path $DEPLOYMENT_TEMP -Recurse -Force 13 | } 14 | mkdir "$DEPLOYMENT_TEMP" 15 | } 16 | 17 | if ($MSBUILD_PATH -eq $null) { 18 | $MSBUILD_PATH = "${env:ProgramFiles(x86)}\MSBuild\14.0\Bin\MSBuild.exe" 19 | } 20 | -------------------------------------------------------------------------------- /lib/templates/deploy.posh.aspnet.wap.template: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################################################################## 3 | # Deployment 4 | # ---------- 5 | 6 | echo "Handling .NET Web Application deployment." 7 | 8 | # 1. Restore NuGet packages 9 | if (Test-Path "{SolutionPath}") { 10 | nuget restore "$DEPLOYMENT_SOURCE\{SolutionPath}" 11 | exitWithMessageOnError "NuGet restore failed" 12 | } 13 | 14 | # 2. Build to the temporary path 15 | if ($env:IN_PLACE_DEPLOYMENT -ne "1") { 16 | & "$MSBUILD_PATH" {MSBuildArguments} 17 | } else { 18 | & "$MSBUILD_PATH" {MSBuildArgumentsForInPlace} 19 | } 20 | 21 | exitWithMessageOnError "MSBuild failed" 22 | 23 | # 3. KuduSync 24 | if ($env:IN_PLACE_DEPLOYMENT -ne "1") { 25 | & $KUDU_SYNC_CMD -v 50 -f "$DEPLOYMENT_TEMP" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.ps1" 26 | exitWithMessageOnError "Kudu Sync failed" 27 | } 28 | 29 | ################################################################################################################################## 30 | -------------------------------------------------------------------------------- /lib/templates/deploy.posh.aspnet.website.template: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################################################################## 3 | # Deployment 4 | # ---------- 5 | 6 | echo "Handling .NET Web Site deployment." 7 | 8 | # 1. Build to the repository path 9 | & "$MSBUILD_PATH" {MSBuildArguments} 10 | exitWithMessageOnError "MSBuild failed" 11 | 12 | # 2. KuduSync 13 | if ($env:IN_PLACE_DEPLOYMENT -ne "1") { 14 | & $KUDU_SYNC_CMD -v 50 -f "$DEPLOYMENT_SOURCE{SitePath}" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.ps1" 15 | exitWithMessageOnError "Kudu Sync failed" 16 | } 17 | 18 | ################################################################################################################################## 19 | -------------------------------------------------------------------------------- /lib/templates/deploy.posh.basic.template: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################################################################## 3 | # Deployment 4 | # ---------- 5 | 6 | echo "Handling Basic Web Site deployment." 7 | 8 | # 1. KuduSync 9 | if ($env:IN_PLACE_DEPLOYMENT -ne "1") { 10 | 11 | if ($env:IGNORE_MANIFEST -eq "1") { 12 | $env:IGNORE_MANIFEST='-x' 13 | } 14 | 15 | & $KUDU_SYNC_CMD -v 50 $env:IGNORE_MANIFEST -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.ps1" 16 | exitWithMessageOnError "Kudu Sync failed" 17 | } 18 | 19 | ################################################################################################################################## 20 | -------------------------------------------------------------------------------- /lib/templates/deploy.posh.dotnetconsole.template: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################################################################## 3 | # Deployment 4 | # ---------- 5 | 6 | echo "Handling .NET Console Application deployment." 7 | 8 | # 1. Restore NuGet packages 9 | if (Test-Path "{SolutionPath}") { 10 | nuget restore "$DEPLOYMENT_SOURCE\{SolutionPath}" 11 | exitWithMessageOnError "NuGet restore failed" 12 | } 13 | 14 | # 2. Build to the temporary path 15 | & "$MSBUILD_PATH" {MSBuildArguments} 16 | exitWithMessageOnError "MSBuild failed" 17 | 18 | # 3. Run web job deploy script 19 | if ($env:WEBJOBS_DEPLOY_CMD -ne $null) { 20 | & $env:WEBJOBS_DEPLOY_CMD 21 | } 22 | 23 | # 4. KuduSync 24 | & $KUDU_SYNC_CMD -v 50 -f "$DEPLOYMENT_TEMP" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.ps1" 25 | exitWithMessageOnError "Kudu Sync failed" 26 | 27 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 28 | -------------------------------------------------------------------------------- /lib/templates/deploy.posh.node.template: -------------------------------------------------------------------------------- 1 | 2 | # Node Helpers 3 | # ------------ 4 | 5 | $NODE_EXE = "node" 6 | $NPM_CMD = "npm" 7 | 8 | function selectNodeVersion() { 9 | if ($env:KUDU_SELECT_NODE_VERSION_CMD -ne $null) { 10 | # The following are done only on Windows Azure Websites environment 11 | $SELECT_NODE_VERSION = "$env:KUDU_SELECT_NODE_VERSION_CMD `"$DEPLOYMENT_SOURCE{SitePath}`" `"$DEPLOYMENT_TARGET`" `"$DEPLOYMENT_TEMP`"" 12 | try { 13 | iex $SELECT_NODE_VERSION 14 | } catch { 15 | exitWithMessageOnError "select node version failed" 16 | } 17 | 18 | if (Test-Path "$DEPLOYMENT_TEMP\__nodeVersion.tmp") { 19 | $NODE_EXE = cat "$DEPLOYMENT_TEMP\__nodeVersion.tmp" 20 | exitWithMessageOnError "getting node version failed" 21 | } 22 | 23 | if (Test-Path "$DEPLOYMENT_TEMP\__npmVersion.tmp") { 24 | $NPM_JS_PATH = cat "$DEPLOYMENT_TEMP\__npmVersion.tmp" 25 | exitWithMessageOnError "getting npm version failed" 26 | } 27 | 28 | if ($NODE_EXE -eq $null) { 29 | $NODE_EXE = "node" 30 | } 31 | $NPM_CMD = "`"$NODE_EXE`" `"$NPM_JS_PATH`"" 32 | } 33 | } 34 | 35 | ################################################################################################################################## 36 | # Deployment 37 | # ---------- 38 | 39 | echo "Handling node.js deployment." 40 | 41 | # 1. KuduSync 42 | if ($env:IN_PLACE_DEPLOYMENT -ne "1") { 43 | & $KUDU_SYNC_CMD -v 50 -f "$DEPLOYMENT_SOURCE{SitePath}" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.ps1" 44 | exitWithMessageOnError "Kudu Sync failed" 45 | } 46 | 47 | # 2. Select node version 48 | selectNodeVersion 49 | 50 | # 3. Install npm packages 51 | if (Test-Path "$DEPLOYMENT_TARGET\package.json") { 52 | pushd "$DEPLOYMENT_TARGET" 53 | try { 54 | iex "$NPM_CMD install --production" 55 | } catch { 56 | exitWithMessageOnError "npm failed" 57 | } 58 | popd 59 | } 60 | 61 | ################################################################################################################################## 62 | -------------------------------------------------------------------------------- /lib/templates/deploy.posh.postfix.template: -------------------------------------------------------------------------------- 1 | echo "Finished successfully." 2 | -------------------------------------------------------------------------------- /lib/templates/deploy.posh.prefix.template: -------------------------------------------------------------------------------- 1 | 2 | # ---------------------- 3 | # KUDU Deployment Script 4 | # Version: {Version} 5 | # ---------------------- 6 | 7 | # Helpers 8 | # ------- 9 | 10 | function exitWithMessageOnError($1) { 11 | if ($? -eq $false) { 12 | echo "An error has occurred during web site deployment." 13 | echo $1 14 | exit 1 15 | } 16 | } 17 | 18 | # Prerequisites 19 | # ------------- 20 | 21 | # Verify node.js installed 22 | where.exe node 2> $null > $null 23 | exitWithMessageOnError "Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment." 24 | 25 | # Setup 26 | # ----- 27 | 28 | $SCRIPT_DIR = $PSScriptRoot 29 | $ARTIFACTS = "$SCRIPT_DIR\..\artifacts" 30 | 31 | $KUDU_SYNC_CMD = $env:KUDU_SYNC_CMD 32 | 33 | $DEPLOYMENT_SOURCE = $env:DEPLOYMENT_SOURCE 34 | $DEPLOYMENT_TARGET = $env:DEPLOYMENT_TARGET 35 | 36 | $NEXT_MANIFEST_PATH = $env:NEXT_MANIFEST_PATH 37 | $PREVIOUS_MANIFEST_PATH = $env:PREVIOUS_MANIFEST_PATH 38 | 39 | if ($DEPLOYMENT_SOURCE -eq $null) { 40 | $DEPLOYMENT_SOURCE = $SCRIPT_DIR 41 | } 42 | 43 | if ($DEPLOYMENT_TARGET -eq $null) { 44 | $DEPLOYMENT_TARGET = "$ARTIFACTS\wwwroot" 45 | } 46 | 47 | if ($NEXT_MANIFEST_PATH -eq $null) { 48 | $NEXT_MANIFEST_PATH = "$ARTIFACTS\manifest" 49 | 50 | if ($PREVIOUS_MANIFEST_PATH -eq $null) { 51 | $PREVIOUS_MANIFEST_PATH = $NEXT_MANIFEST_PATH 52 | } 53 | } 54 | 55 | if ($KUDU_SYNC_CMD -eq $null) { 56 | # Install kudu sync 57 | echo "Installing Kudu Sync" 58 | npm install kudusync -g --silent 59 | exitWithMessageOnError "npm failed" 60 | 61 | # Locally just running "kuduSync" would also work 62 | $KUDU_SYNC_CMD = "$env:APPDATA\npm\kuduSync.cmd" 63 | } 64 | -------------------------------------------------------------------------------- /npmpublish.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | setlocal 4 | 5 | set GIT_STATUS_RETURN_VALUE= 6 | 7 | echo Make sure no outstanding files to commit 8 | FOR /F "tokens=*" %%i IN ('git status -z') DO ( 9 | set GIT_STATUS_RETURN_VALUE=%%i 10 | ) 11 | 12 | if NOT "%GIT_STATUS_RETURN_VALUE%" == "" ( 13 | git status 14 | goto error 15 | ) 16 | 17 | echo Building kuduscript 18 | call build.cmd 19 | 20 | echo Testing kuduscript 21 | call npm test 22 | IF %ERRORLEVEL% NEQ 0 goto error 23 | 24 | echo Incrementing kuduscript version 25 | call npm version patch 26 | IF %ERRORLEVEL% NEQ 0 goto error 27 | 28 | echo Trying to install kuduscript 29 | call npm install . -g 30 | IF %ERRORLEVEL% NEQ 0 goto error 31 | 32 | echo Publishing kuduscript 33 | call npm publish 34 | IF %ERRORLEVEL% NEQ 0 goto error 35 | 36 | echo Trying to install kuduscript from npm registry 37 | call npm install kuduscript -g 38 | IF %ERRORLEVEL% NEQ 0 goto error 39 | 40 | goto end 41 | 42 | :error 43 | echo Publishing kuduscript failed 44 | exit /b 1 45 | 46 | :end 47 | echo Published successfully 48 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kuduscript", 3 | "version": "1.0.17", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "commander": { 8 | "version": "1.1.1", 9 | "resolved": "https://registry.npmjs.org/commander/-/commander-1.1.1.tgz", 10 | "integrity": "sha1-UNFlGGiuYOzP8KLZ80WVN2vGsEE=", 11 | "requires": { 12 | "keypress": "0.1.0" 13 | } 14 | }, 15 | "debug": { 16 | "version": "3.1.0", 17 | "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", 18 | "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", 19 | "dev": true, 20 | "requires": { 21 | "ms": "2.0.0" 22 | } 23 | }, 24 | "diff": { 25 | "version": "1.0.7", 26 | "resolved": "https://registry.npmjs.org/diff/-/diff-1.0.7.tgz", 27 | "integrity": "sha1-JLuwAcSn1VIhaefKvbLCgU7ZHPQ=", 28 | "dev": true 29 | }, 30 | "glob": { 31 | "version": "3.2.3", 32 | "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.3.tgz", 33 | "integrity": "sha1-4xPusknHr/qlxHUoaw4RW1mDlGc=", 34 | "dev": true, 35 | "requires": { 36 | "graceful-fs": "2.0.3", 37 | "inherits": "2.0.3", 38 | "minimatch": "0.2.14" 39 | } 40 | }, 41 | "graceful-fs": { 42 | "version": "2.0.3", 43 | "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.3.tgz", 44 | "integrity": "sha1-fNLNsiiko/Nule+mzBQt59GhNtA=", 45 | "dev": true 46 | }, 47 | "growl": { 48 | "version": "1.7.0", 49 | "resolved": "https://registry.npmjs.org/growl/-/growl-1.7.0.tgz", 50 | "integrity": "sha1-3i1mE20ALhErpw8/EMMc98NQsto=", 51 | "dev": true 52 | }, 53 | "inherits": { 54 | "version": "2.0.3", 55 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 56 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", 57 | "dev": true 58 | }, 59 | "jade": { 60 | "version": "0.26.3", 61 | "resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz", 62 | "integrity": "sha1-jxDXl32NefL2/4YqgbBRPMslaGw=", 63 | "dev": true, 64 | "requires": { 65 | "commander": "0.6.1", 66 | "mkdirp": "0.3.0" 67 | }, 68 | "dependencies": { 69 | "commander": { 70 | "version": "0.6.1", 71 | "resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz", 72 | "integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=", 73 | "dev": true 74 | }, 75 | "mkdirp": { 76 | "version": "0.3.0", 77 | "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz", 78 | "integrity": "sha1-G79asbqCevI1dRQ0kEJkVfSB/h4=", 79 | "dev": true 80 | } 81 | } 82 | }, 83 | "keypress": { 84 | "version": "0.1.0", 85 | "resolved": "https://registry.npmjs.org/keypress/-/keypress-0.1.0.tgz", 86 | "integrity": "sha1-SjGI1CkbZrT2XtuZ+AaqmuKTWSo=" 87 | }, 88 | "lru-cache": { 89 | "version": "2.7.3", 90 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", 91 | "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", 92 | "dev": true 93 | }, 94 | "minimatch": { 95 | "version": "0.2.14", 96 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz", 97 | "integrity": "sha1-x054BXT2PG+aCQ6Q775u9TpqdWo=", 98 | "dev": true, 99 | "requires": { 100 | "lru-cache": "2.7.3", 101 | "sigmund": "1.0.1" 102 | } 103 | }, 104 | "mkdirp": { 105 | "version": "0.3.5", 106 | "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz", 107 | "integrity": "sha1-3j5fiWHIjHh+4TaN+EmsRBPsqNc=", 108 | "dev": true 109 | }, 110 | "mocha": { 111 | "version": "1.13.0", 112 | "resolved": "https://registry.npmjs.org/mocha/-/mocha-1.13.0.tgz", 113 | "integrity": "sha1-jY+k4xC5TMbv6z7SauypbeqTMHw=", 114 | "dev": true, 115 | "requires": { 116 | "commander": "0.6.1", 117 | "debug": "3.1.0", 118 | "diff": "1.0.7", 119 | "glob": "3.2.3", 120 | "growl": "1.7.0", 121 | "jade": "0.26.3", 122 | "mkdirp": "0.3.5" 123 | }, 124 | "dependencies": { 125 | "commander": { 126 | "version": "0.6.1", 127 | "resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz", 128 | "integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=", 129 | "dev": true 130 | } 131 | } 132 | }, 133 | "ms": { 134 | "version": "2.0.0", 135 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 136 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", 137 | "dev": true 138 | }, 139 | "should": { 140 | "version": "1.3.0", 141 | "resolved": "https://registry.npmjs.org/should/-/should-1.3.0.tgz", 142 | "integrity": "sha1-ILcaCbXtFhRrkDAivTBu8zLv6HM=", 143 | "dev": true 144 | }, 145 | "sigmund": { 146 | "version": "1.0.1", 147 | "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", 148 | "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", 149 | "dev": true 150 | }, 151 | "streamline": { 152 | "version": "0.4.11", 153 | "resolved": "https://registry.npmjs.org/streamline/-/streamline-0.4.11.tgz", 154 | "integrity": "sha1-DjxPJKPwUrIxsS1QSQhaCgmb54I=" 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kuduscript", 3 | "author": "Outercurve Foundation", 4 | "version": "1.0.17", 5 | "description": "Tool for generating deployment scripts for Azure Websites", 6 | "tags": [ 7 | "azure", 8 | "deployment" 9 | ], 10 | "keywords": [ 11 | "node", 12 | "azure", 13 | "deployment" 14 | ], 15 | "main": "./bin/kuduscript.js", 16 | "engines": { 17 | "node": ">= 0.6.20" 18 | }, 19 | "scripts": { 20 | "build": "_node -c lib", 21 | "test": "test.cmd" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "https://github.com/projectkudu/kuduscript.git" 26 | }, 27 | "homepage": "http://github.com/projectkudu/kuduscript", 28 | "bugs": { 29 | "url": "http://github.com/projectkudu/kuduscript/issues" 30 | }, 31 | "bin": { 32 | "kuduscript": "./bin/kuduscript" 33 | }, 34 | "licenses": [ 35 | { 36 | "type": "Apache", 37 | "url": "http://www.apache.org/licenses/LICENSE-2.0" 38 | } 39 | ], 40 | "readmeFilename": "README.markdown", 41 | "dependencies": { 42 | "commander": "~1.1.1", 43 | "streamline": "~0.4.10" 44 | }, 45 | "devDependencies": { 46 | "mocha": "~1.13.0", 47 | "should": "~1.3.0" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /smoketest.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | call npm install 4 | call npm install mocha 5 | call npm install should 6 | 7 | call node_modules\.bin\mocha.cmd -u tdd -R spec test\smokeTest.js -s 10000 -t 60000 8 | -------------------------------------------------------------------------------- /test.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | setlocal enabledelayedexpansion 4 | 5 | set kuduscript_dir=%~dp0 6 | pushd %temp% 7 | 8 | rd /s /q kuduscript_test 2>nul 9 | mkdir kuduscript_test 10 | cd kuduscript_test 11 | 12 | git clone https://github.com/amitapl/azure-sdk-tools-xplat.git 13 | IF !ERRORLEVEL! NEQ 0 goto error 14 | 15 | cd azure-sdk-tools-xplat 16 | 17 | git checkout dev 18 | IF !ERRORLEVEL! NEQ 0 goto error 19 | 20 | call npm install 21 | IF !ERRORLEVEL! NEQ 0 goto error 22 | 23 | call npm install %kuduscript_dir% 24 | IF !ERRORLEVEL! NEQ 0 goto error 25 | 26 | call node_modules\.bin\mocha.cmd -u tdd -R spec test\commands\cli.site-deploymentscript-tests.js 27 | IF !ERRORLEVEL! NEQ 0 goto error 28 | 29 | goto success 30 | 31 | :error 32 | popd 33 | echo Failed 34 | call :exitSetErrorLevel 35 | call :exitFromFunction 2>nul 36 | 37 | :exitSetErrorLevel 38 | exit /b 1 39 | 40 | :exitFromFunction 41 | () 42 | 43 | 44 | :success 45 | popd 46 | echo Success 47 | -------------------------------------------------------------------------------- /test/smokeTest.js: -------------------------------------------------------------------------------- 1 | // Functional tests using mocha and should. 2 | 3 | var should = require("should"); 4 | var fs = require("fs"); 5 | var pathUtil = require("path"); 6 | 7 | var exec = require("child_process").exec; 8 | 9 | // Globals 10 | var baseTestTempDir = "temp"; 11 | var testDirBase = "test"; 12 | var testDirIndex = 0; 13 | var testDir = ""; 14 | 15 | var ScriptType = { 16 | batch: 'BATCH', 17 | bash: 'BASH', 18 | posh: 'POSH' 19 | }; 20 | 21 | // Tests Suite 22 | suite('Kudu Script Smoke Tests', function () { 23 | test('Basic generated batch script runs without a failure', function (done) { 24 | generateFile(pathUtil.join(testDir, "server.js"), "content"); 25 | var scriptType = ScriptType.batch; 26 | runScenario("--basic", scriptType, done); 27 | }); 28 | 29 | test('Node generated batch script runs without a failure', function (done) { 30 | generateFile(pathUtil.join(testDir, "server.js"), "content"); 31 | var scriptType = ScriptType.batch; 32 | runScenario("--node", scriptType, done); 33 | }); 34 | 35 | test('Python generated batch script runs without a failure', function (done) { 36 | generateFile(pathUtil.join(testDir, "app.py"), "content"); 37 | var scriptType = ScriptType.batch; 38 | runScenario("--python", scriptType, done); 39 | }); 40 | 41 | test('Basic generated bash script runs without a failure', function (done) { 42 | generateFile(pathUtil.join(testDir, "server.js"), "content"); 43 | var scriptType = ScriptType.bash; 44 | runScenario("--basic", scriptType, done); 45 | }); 46 | 47 | test('Node generated bash script runs without a failure', function (done) { 48 | generateFile(pathUtil.join(testDir, "server.js"), "content"); 49 | var scriptType = ScriptType.bash; 50 | runScenario("--node", scriptType, done); 51 | }); 52 | 53 | test('PHP generated bash script runs without a failure', function (done) { 54 | generateFile(pathUtil.join(testDir, "composer.json"), "content"); 55 | var scriptType = ScriptType.bash; 56 | runScenario("--php", scriptType, done); 57 | }); 58 | 59 | test('Basic generated posh script runs without a failure', function (done) { 60 | generateFile(pathUtil.join(testDir, "server.js"), "content"); 61 | var scriptType = ScriptType.posh; 62 | runScenario("--basic", scriptType, done); 63 | }); 64 | 65 | test('Node generated posh script runs without a failure', function (done) { 66 | generateFile(pathUtil.join(testDir, "server.js"), "content"); 67 | var scriptType = ScriptType.posh; 68 | runScenario("--node", scriptType, done); 69 | }); 70 | 71 | setup(function () { 72 | // Setting a different test directory per test. 73 | incrementTestDir(); 74 | removePath(testDir); 75 | console.log(); 76 | }); 77 | 78 | teardown(function () { 79 | // Cleaning up after each test 80 | removePath(baseTestTempDir); 81 | }); 82 | }); 83 | 84 | function incrementTestDir() { 85 | testDirIndex++; 86 | testDir = pathUtil.join(baseTestTempDir, testDirBase, "project" + testDirIndex); 87 | } 88 | 89 | // Scenario: 90 | // 1. Generate the script using the flags provided. 91 | // 2. Run the generated script. 92 | // 3. Make sure script generation and script generated didn't fail execution. 93 | function runScenario(flags, scriptType, callback) { 94 | var command = "node " + pathUtil.join(__dirname, "..", "bin", "kuduscript") + " -y -o \"" + testDir + "\" " + flags + " --scriptType " + scriptType; 95 | 96 | console.log("command: " + command); 97 | exec(command, 98 | function (error, stdout, stderr) { 99 | if (stdout !== '') { 100 | console.log('---------stdout: ---------\n' + stdout); 101 | } 102 | if (stderr !== '') { 103 | console.log('---------stderr: ---------\n' + stderr); 104 | } 105 | if (error !== null) { 106 | console.log('---------exec error: ---------\n[' + error + ']'); 107 | } 108 | if (error) { 109 | callback(error); 110 | } else { 111 | testScript(scriptType, callback); 112 | } 113 | }); 114 | } 115 | 116 | function testScript(scriptType, callback) { 117 | var generatedScriptPath = pathUtil.join(testDir, "deploy"); 118 | generatedScriptPath += (scriptType == ScriptType.bash ? ".sh" : (scriptType == ScriptType.posh ? ".ps1" : ".cmd")); 119 | 120 | var command = "\"" + generatedScriptPath + "\""; 121 | 122 | if (scriptType == ScriptType.bash) { 123 | command = "bash " + command; 124 | } else if (scriptType == ScriptType.posh) { 125 | command = "powershell -NoProfile -NoLogo -ExecutionPolicy Unrestricted -File " + command; 126 | } 127 | 128 | console.log("command: " + command); 129 | exec(command, 130 | function (error, stdout, stderr) { 131 | if (stdout !== '') { 132 | console.log('---------stdout: ---------\n' + stdout); 133 | } 134 | if (stderr !== '') { 135 | console.log('---------stderr: ---------\n' + stderr); 136 | } 137 | if (error !== null) { 138 | console.log('---------exec error: ---------\n[' + error + ']'); 139 | } 140 | callback(error); 141 | }); 142 | } 143 | 144 | function generateFile(path, content) { 145 | if (content == null) { 146 | content = randomString(); 147 | } 148 | ensurePathExists(pathUtil.dirname(path)); 149 | fs.writeFileSync(path, content, 'utf8'); 150 | return content; 151 | } 152 | 153 | function removePath(path) { 154 | var stat = tryGetFileStat(path); 155 | if (stat) { 156 | if (!stat.isDirectory()) { 157 | tryRemoveFile(path); 158 | } 159 | else { 160 | var files = fs.readdirSync(path); 161 | for (var index in files) { 162 | var file = files[index]; 163 | var filePath = pathUtil.join(path, file); 164 | removePath(filePath); 165 | } 166 | 167 | tryRemoveDir(path); 168 | } 169 | } 170 | } 171 | 172 | function tryGetFileStat(path) { 173 | try { 174 | return fs.statSync(path); 175 | } catch (e) { 176 | if (e.errno == 34 || e.code == 'ENOENT') { 177 | // Return null if path doesn't exist 178 | return null; 179 | } 180 | 181 | throw e; 182 | } 183 | } 184 | 185 | function tryRemoveFile(path) { 186 | try { 187 | fs.unlinkSync(path); 188 | } 189 | catch (e) { 190 | console.log(e); 191 | } 192 | } 193 | 194 | function tryRemoveDir(path) { 195 | try { 196 | fs.rmdirSync(path); 197 | } 198 | catch (e) { 199 | } 200 | } 201 | 202 | function ensurePathExists(path) { 203 | if (!fs.existsSync(path)) { 204 | ensurePathExists(pathUtil.dirname(path)); 205 | fs.mkdirSync(path); 206 | } 207 | } 208 | 209 | // Create a random string, more chance for /n and space. 210 | function randomString() { 211 | var length = Math.floor(Math.random() * 1024) + 100; 212 | 213 | var text = ""; 214 | var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ \n abcdefghijklmnopqrstuvwxyz \n 0123456789 \n \t"; 215 | 216 | for (var i = 0; i < length; i++) 217 | text += possible.charAt(Math.floor(Math.random() * possible.length)); 218 | 219 | return text; 220 | } 221 | --------------------------------------------------------------------------------