From 03682d03124266e4d828ae77f6ce5ac425a4e30c Mon Sep 17 00:00:00 2001 From: John Miller Date: Thu, 21 Jul 2016 18:23:18 -0700 Subject: [PATCH 1/4] Added gulp install-deploy --- .gitignore | 3 ++ gulpfile.js | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 96 insertions(+) diff --git a/.gitignore b/.gitignore index 6691bf0db4bb6c..f523ef7ead10f3 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,6 @@ typings/webparts # Configs that contain sensitive information TDSDeployConfig.json + +#ftp config +ftpconfig.json diff --git a/gulpfile.js b/gulpfile.js index 47d1a95e35cdec..aad52b7a53e671 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,6 +2,8 @@ let build = require('web-library-build'); let gulp = require('gulp'); +let configFile = "./ftpconfig.json"; +let fs = require('fs'); /** @todo: disable lint config. */ build.tslint.setConfig({ lintConfig: require('./tslint.json') }); @@ -25,6 +27,96 @@ if (isProduction || isNuke) { }); } +gulp.task('install-deploy', function(cb) { + let prompt = require('gulp-prompt'); + + gulp.src('index.html') + .pipe(prompt.prompt([{ + type: 'input', + name: 'host', + message: 'Please enter hostname' + }, + { + type: 'input', + name: 'user', + message: 'Please enter username' + }, + { + type: 'input', + name: 'password', + message: 'Please enter password' + }, + { + type: 'input', + name: 'deployurl', + message: 'Enter deploy URL' + }, + { + type: 'input', + name: 'deploybasepath', + message: 'Please deployment base path' + }], function(res) { + let ftpdata = { + "host": res.host, + "user": res.user, + "password": res.password, + "deployurl": res.deployurl, + "deploybasepath": res.deploybasepath + }; + fs.writeFileSync(configFile, JSON.stringify(ftpdata)); + cb(); + })); +}); + +gulp.task('deploy', ['bundle'], function(cb) { + let ftp = require('vinyl-ftp'); + let git = require('git-rev'); + let debug = require('gulp-debug'); + let gutil = require('gulp-util'); + let os = require('os'); + let currentBranch; + let json; + let data; + + try { + json = fs.readFileSync(configFile, 'utf8'); + data = JSON.parse(json); + + git.branch(function(branch) { + currentBranch = os.hostname().split('.')[0] + '-' + branch.replace('/', '-'); + let ftpConnection = ftp.create({ + host: data.host, + user: data.user, + pass: data.password, + parallel: 10, + secure: true, + idleTimeout: 10000 + }); + let globs = [ + './index.html', + './dist/**/*' + ]; + if (process.env.masterBuildLink || isProduction) { + currentBranch = 'master'; + } + + let stream = gulp.src( globs, { base: '.', buffer: false }) + .pipe(debug({ title: 'Copying file to server' })) + .pipe(ftpConnection.dest(data.deployurl + currentBranch )) + .on('error', function(er) { + console.log(er); + }) + .on("end", function() { + gutil.log( data.deployurl + currentBranch + '/' ); + cb(); + }); + }); + } + catch(err) { + gutil.log("Please run gulp install-deploy before deploying"); + } +}); + /** @todo: Enable css modules when ready. */ // build.sass.setConfig({ useCSSModules: true }); diff --git a/package.json b/package.json index fedd90f164b445..3cf17ea66f4889 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "git-rev": "0.2.1", "gulp": "~3.9.1", "gulp-debug": "2.1.2", + "gulp-prompt": "^0.2.0", "gulp-util": "3.0.7", "gutil": "1.6.4", "highlight.js": "9.4.0", From f7d33726ffda563ea73e7025e853c90f030997e4 Mon Sep 17 00:00:00 2001 From: John Miller Date: Fri, 22 Jul 2016 11:01:49 -0700 Subject: [PATCH 2/4] Test works --- gulpfile.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index aad52b7a53e671..80acf046f781e7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -77,6 +77,7 @@ gulp.task('deploy', ['bundle'], function(cb) { let currentBranch; let json; let data; + let uploadPath; try { json = fs.readFileSync(configFile, 'utf8'); @@ -100,9 +101,10 @@ gulp.task('deploy', ['bundle'], function(cb) { currentBranch = 'master'; } + let uploadPath = data.deploybasepath + currentBranch; let stream = gulp.src( globs, { base: '.', buffer: false }) .pipe(debug({ title: 'Copying file to server' })) - .pipe(ftpConnection.dest(data.deployurl + currentBranch )) + .pipe(ftpConnection.dest(uploadPath)) .on('error', function(er) { console.log(er); }) From edf4d8e0dda4d8ee6d8e4d89996a3aa0e11fca02 Mon Sep 17 00:00:00 2001 From: John Miller Date: Fri, 22 Jul 2016 11:55:34 -0700 Subject: [PATCH 3/4] Added prompt for secure and idletimeout as well --- gulpfile.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 80acf046f781e7..9a164c265c6206 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -55,13 +55,26 @@ gulp.task('install-deploy', function(cb) { type: 'input', name: 'deploybasepath', message: 'Please deployment base path' + }, + { + type: 'input', + name: 'secureconnection', + message: 'Secure connection?', + choices: ["true", "false"] + }, + { + type: 'input', + name: 'idletimeout', + message: 'Enter Idle timeout' }], function(res) { let ftpdata = { "host": res.host, "user": res.user, "password": res.password, "deployurl": res.deployurl, - "deploybasepath": res.deploybasepath + "deploybasepath": res.deploybasepath, + "secureconnection": res.secureconnection, + "idletimeout": res.idletimeout }; fs.writeFileSync(configFile, JSON.stringify(ftpdata)); cb(); @@ -90,8 +103,8 @@ gulp.task('deploy', ['bundle'], function(cb) { user: data.user, pass: data.password, parallel: 10, - secure: true, - idleTimeout: 10000 + secure: (data.secureconnection == "true") ? true : false, + idleTimeout: data.idletimeout }); let globs = [ './index.html', @@ -100,7 +113,6 @@ gulp.task('deploy', ['bundle'], function(cb) { if (process.env.masterBuildLink || isProduction) { currentBranch = 'master'; } - let uploadPath = data.deploybasepath + currentBranch; let stream = gulp.src( globs, { base: '.', buffer: false }) .pipe(debug({ title: 'Copying file to server' })) From 54e4811776fa0cac6f43692ce6f9505a276810d8 Mon Sep 17 00:00:00 2001 From: John Miller Date: Fri, 22 Jul 2016 12:13:59 -0700 Subject: [PATCH 4/4] Adding hints for each prompt --- gulpfile.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 9a164c265c6206..594d04a2bebeee 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -34,38 +34,38 @@ gulp.task('install-deploy', function(cb) { .pipe(prompt.prompt([{ type: 'input', name: 'host', - message: 'Please enter hostname' + message: 'Please enter hostname (ftp.example.com)' }, { type: 'input', name: 'user', - message: 'Please enter username' + message: 'Please enter username (exampleusername)' }, { type: 'input', name: 'password', - message: 'Please enter password' + message: 'Please enter password (examplepassword)' }, { type: 'input', name: 'deployurl', - message: 'Enter deploy URL' + message: 'Enter deploy URL (http://example.com/website-subfolder/)' }, { type: 'input', name: 'deploybasepath', - message: 'Please deployment base path' + message: 'Please deployment base path (/wwwroot/base/path/website-subfolder/)' }, { type: 'input', name: 'secureconnection', - message: 'Secure connection?', + message: 'Secure connection? (Type true or false)', choices: ["true", "false"] }, { type: 'input', name: 'idletimeout', - message: 'Enter Idle timeout' + message: 'Enter Idle timeout in milleseconds(1000)' }], function(res) { let ftpdata = { "host": res.host,