Skip to content

Commit

Permalink
Changed build script - closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Majcica committed Mar 20, 2018
1 parent 4abd391 commit 704cb6d
Show file tree
Hide file tree
Showing 42 changed files with 2,769 additions and 232 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# default behavior to automatically normalize line endings
* text=auto
47 changes: 6 additions & 41 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
# Created by https://www.gitignore.io/api/node

### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
dist
node_modules/
*.vsix
_build/
_packages/
_test-results/
.vscode

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
coverage
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Mario Majcica

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ The only requirement is PowerShell V5 installed both on the build server and on
* **Clean Target**: Checking this option will clean the destination folder prior to copying the files to it.
* **Copy Files in Parallel**: Checking this option will copy files to all the target machines in parallel, which can speed up the copying process.


## Contributing

Feel free to notify any issue in the issues section of this GitHub repository.
In order to build this task, you will need Node.js and gulp installed. Once cloned the repository, just run 'gulp package' and in the newly created folder called dist you will find a new version of the extension.
Feel free to notify any issue in the issues section of this GitHub repository. In order to build this task, you will need Node.js and gulp installed. Once cloned the repository, just run 'npm install' then 'gulp package' and in the newly created folder called _packages you will find a new version of the extension.

## Task version history

* 2.0.2 - Resolve CNAME before creating a WinRM session ([#2](https://github.com/mmajcica/win-rm-file-copy/issues/2))
* 2.0.1 - Implements the Skip CA Check for HTTPS with a self signed certificate ([#1](https://github.com/mmajcica/win-rm-file-copy/issues/1))
160 changes: 28 additions & 132 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,138 +1,34 @@
'use strict';

var fs = require('fs');
var path = require('path');
var del = require('del');
var eslint = require('gulp-eslint');
var gulp = require('gulp');
var istanbul = require('gulp-istanbul');
var mocha = require('gulp-mocha');
var plumber = require('gulp-plumber');
var shell = require('shelljs');
var spawn = require('child_process').spawn;
var gutil = require('gulp-util');

var copyNodeModulesToTasks = function (done) {
fs.readdirSync('src').forEach(function (file) {
var filePath = path.join('dist', 'src', file);
if (fs.statSync(filePath).isDirectory()) {
try {
if (fs.statSync(path.join(filePath, 'task.json')).isFile()) {
shell.cp('-rf', 'dist/node_modules', filePath);
}
} catch (e) {
/* swallow error: not a task directory */
}
}
});
done();
};

var executeCommand = function (cmd, dir, done) {
gutil.log('Running command: ' + cmd);
var pwd = shell.pwd();
if (undefined !== dir) {
gutil.log(' Working directory: ' + dir);
shell.cd(dir);
}
shell.exec(cmd, {silent: true}, function (code, stdout, stderr) {
gutil.log(' stdout: ' + stdout);
if (code !== 0) {
gutil.log('Command failed: ' + cmd + '\nManually execute to debug');
gutil.log(' stderr: ' + stderr);
}
shell.cd(pwd);
done();
});
};

var createVsixPackage = function (done) {
if (!shell.which('tfx')) {
gutil.log('Packaging requires tfx cli. Please install with `npm install tfx-cli -g`.');
done();
return;
}
var packagingCmd = 'tfx extension create --manifest-globs vss-extension.json --root dist/src --output-path dist';
executeCommand(packagingCmd, shell.pwd(), done);
};

var getNodeDependencies = function (done) {
gutil.log('Copy package.json to dist directory');
shell.mkdir('-p', 'dist/node_modules');
shell.cp('-f', 'package.json', 'dist');

gutil.log('Fetch node modules to package with tasks');
var npmPath = shell.which('npm');
var npmInstallCommand = '"' + npmPath + '" install --production';
executeCommand(npmInstallCommand, 'dist', done);
};

// Tasks
gulp.task('clean', function (done) {
del('dist').then(function () {
done();
});
});

gulp.task('lint', ['clean'], function () {
return gulp.src('**/*.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('build', ['lint'], function () {
return gulp.src('src/**/*', {base: '.'})
.pipe(gulp.dest('dist'));
});

gulp.task('pre-test', ['build'], function () {
return gulp.src('src/**/*.js')
.pipe(istanbul({includeUntested: true}))
.pipe(istanbul.hookRequire());
});

gulp.task('test', ['mocha-test']);

gulp.task('mocha-test', ['pre-test'], function (done) {
var mochaErr;

gulp.src('test/**/*.js')
.pipe(plumber())
.pipe(mocha({reporter: 'spec'}))
.on('error', function (err) {
mochaErr = err;
})
.pipe(istanbul.writeReports())
.on('end', function () {
done(mochaErr);
});
var debug = require('gulp-debug');
var del = require('del');
var merge = require('merge-stream');
var path = require('path');
var shell = require('shelljs');
var minimist = require('minimist');

var _buildRoot = path.join(__dirname, '_build');
var _packagesRoot = path.join(__dirname, '_packages');

gulp.task('default', ['build']);

gulp.task('build', ['clean'], function () {
var extension = gulp.src(['README.md', 'LICENSE.txt', 'images/**/*', '!images/**/*.pdn', 'vss-extension.json'], { base: '.' })
.pipe(debug({title: 'extension:'}))
.pipe(gulp.dest(_buildRoot));
var task = gulp.src('task/**/*', { base: '.' })
.pipe(debug({title: 'task:'}))
.pipe(gulp.dest(_buildRoot));

return merge(extension, task);
});

gulp.task('pester-test', ['pre-test'], function (done) {
// Runs powershell unit tests based on pester
var pester = spawn('powershell.exe', ['-Command', 'Invoke-Pester -EnableExit -Path test'], {stdio: 'inherit'});
pester.on('exit', function (code) {
if (code === 0) {
done();
} else {
done('Pester tests failed!');
}
});

pester.on('error', function () {
// We may be in a non-windows machine or powershell.exe is not in path. Skip pester tests.
done();
});
gulp.task('clean', function() {
return del([_buildRoot]);
});

gulp.task('default', ['test']);

gulp.task('package', ['test'], function (done) {
getNodeDependencies(function () {
// TODO We need a per task dependency copy
copyNodeModulesToTasks(function () {
createVsixPackage(done);
});
});
});
gulp.task('package', ['build'], function() {
var args = minimist(process.argv.slice(2), {})

shell.exec('tfx extension create --root "' + _buildRoot + '" --output-path "' + _packagesRoot +'"')
});
File renamed without changes
File renamed without changes
File renamed without changes
Loading

0 comments on commit 704cb6d

Please sign in to comment.