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..594d04a2bebeee 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,110 @@ 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 (ftp.example.com)' + }, + { + type: 'input', + name: 'user', + message: 'Please enter username (exampleusername)' + }, + { + type: 'input', + name: 'password', + message: 'Please enter password (examplepassword)' + }, + { + type: 'input', + name: 'deployurl', + message: 'Enter deploy URL (http://example.com/website-subfolder/)' + }, + { + type: 'input', + name: 'deploybasepath', + message: 'Please deployment base path (/wwwroot/base/path/website-subfolder/)' + }, + { + type: 'input', + name: 'secureconnection', + message: 'Secure connection? (Type true or false)', + choices: ["true", "false"] + }, + { + type: 'input', + name: 'idletimeout', + message: 'Enter Idle timeout in milleseconds(1000)' + }], function(res) { + let ftpdata = { + "host": res.host, + "user": res.user, + "password": res.password, + "deployurl": res.deployurl, + "deploybasepath": res.deploybasepath, + "secureconnection": res.secureconnection, + "idletimeout": res.idletimeout + }; + 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; + let uploadPath; + + 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: (data.secureconnection == "true") ? true : false, + idleTimeout: data.idletimeout + }); + let globs = [ + './index.html', + './dist/**/*' + ]; + 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' })) + .pipe(ftpConnection.dest(uploadPath)) + .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 acdf5eda6cc83f..ecb2386e1b1e6f 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,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",