Skip to content

Commit

Permalink
fixing tests by increasing timeouts and formatting code with prettier.
Browse files Browse the repository at this point in the history
  • Loading branch information
mckn committed Mar 9, 2022
1 parent 7bef5e0 commit 80b6115
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 468 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
"use strict";

module.exports = {
pack: require('./lib/pack'),
push: require('./lib/push'),
restore: require('./lib/restore')
pack: require("./lib/pack"),
push: require("./lib/push"),
restore: require("./lib/restore"),
};
192 changes: 93 additions & 99 deletions lib/argsFor.js
Original file line number Diff line number Diff line change
@@ -1,108 +1,102 @@
'use strict';

exports.pack = function(nuspecFile, options) {
var args = ['pack', nuspecFile];

var withoutValues = [
'build',
'symbols',
'excludeEmptyDirectories',
'includeReferencedProjects',
'noDefaultExcludes',
'tool'
];

var withValues = [
'version',
'outputDirectory',
'basePath',
'exclude',
'properties',
'minClientVersion',
'msBuildVersion',
'verbosity',
'suffix',
];

withValues.forEach(function(prop) {
var value = options[prop];
if(value) {
args.push('-' + prop);
args.push(value);
}
});

withoutValues.forEach(function(prop) {
var value = options[prop];
if(value) {
args.push('-' + prop);
}
});

args.push('-nopackageanalysis');
args.push('-noninteractive');

return args;
"use strict";

exports.pack = function (nuspecFile, options) {
var args = ["pack", nuspecFile];

var withoutValues = [
"build",
"symbols",
"excludeEmptyDirectories",
"includeReferencedProjects",
"noDefaultExcludes",
"tool",
];

var withValues = [
"version",
"outputDirectory",
"basePath",
"exclude",
"properties",
"minClientVersion",
"msBuildVersion",
"verbosity",
"suffix",
];

withValues.forEach(function (prop) {
var value = options[prop];
if (value) {
args.push("-" + prop);
args.push(value);
}
});

withoutValues.forEach(function (prop) {
var value = options[prop];
if (value) {
args.push("-" + prop);
}
});

args.push("-nopackageanalysis");
args.push("-noninteractive");

return args;
};

exports.push = function(nupkg, options) {
var args = ['push', nupkg];
exports.push = function (nupkg, options) {
var args = ["push", nupkg];

var withValues = [
'source',
'apiKey',
'timeout',
'configFile',
'verbosity'
];
var withValues = ["source", "apiKey", "timeout", "configFile", "verbosity"];

withValues.forEach(function(prop) {
var value = options[prop];
if(value) {
args.push('-' + prop);
args.push(value);
}
});
withValues.forEach(function (prop) {
var value = options[prop];
if (value) {
args.push("-" + prop);
args.push(value);
}
});

args.push('-noninteractive');
args.push("-noninteractive");

return args;
return args;
};

exports.restore = function(nupkg, options) {
var args = ['restore', nupkg];

var withValues = [
'source',
'configFile',
'packagesDirectory',
'solutionDirectory',
'msBuildVersion',
'verbosity'
];

var withoutValues = [
'noCache',
'requireConsent',
'disableParallelProcessing'
];

withValues.forEach(function(prop) {
var value = options[prop];
if(value) {
args.push('-' + prop);
args.push(value);
}
});

withoutValues.forEach(function(prop) {
var value = options[prop];
if(value) {
args.push('-' + prop);
}
});

args.push('-noninteractive');

return args;
exports.restore = function (nupkg, options) {
var args = ["restore", nupkg];

var withValues = [
"source",
"configFile",
"packagesDirectory",
"solutionDirectory",
"msBuildVersion",
"verbosity",
];

var withoutValues = [
"noCache",
"requireConsent",
"disableParallelProcessing",
];

withValues.forEach(function (prop) {
var value = options[prop];
if (value) {
args.push("-" + prop);
args.push(value);
}
});

withoutValues.forEach(function (prop) {
var value = options[prop];
if (value) {
args.push("-" + prop);
}
});

args.push("-noninteractive");

return args;
};
130 changes: 67 additions & 63 deletions lib/pack.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,84 @@
'use strict';

var cproc = require('child_process');
var through = require('through2');
var fs = require('fs-extra');
var log = require('fancy-log');
var PluginError = require('plugin-error');
var argsFor = require('./argsFor');
var validFor = require('./validFor');
var path = require('path');
var File = require('vinyl');

module.exports = function(options) {
options = options || {};
options.nuget = options.nuget || './nuget.exe';
options.outputDirectory = options.outputDirectory || './.gulp-nuget';
options.maxBuffer = options.maxBuffer || 200*1024;

return through.obj(function(file, encoding, done) {
if(!validFor.pack(file)) {
return done(null, file);
}

var self = this;
var args = argsFor.pack(file.path, options);
var opts = { maxBuffer: options.maxBuffer };

fs.mkdirs(options.outputDirectory, function(err) {
if(err) throw new PluginError('gulp-nuget', err);

cproc.execFile(options.nuget, args, opts, function(err, stdout) {
if(err) throw new PluginError('gulp-nuget', err);

log(stdout.trim());

var files = findNupkgs(stdout);
pushFiles.call(self, files, done);
});

});
});
"use strict";

var cproc = require("child_process");
var through = require("through2");
var fs = require("fs-extra");
var log = require("fancy-log");
var PluginError = require("plugin-error");
var argsFor = require("./argsFor");
var validFor = require("./validFor");
var path = require("path");
var File = require("vinyl");

module.exports = function (options) {
options = options || {};
options.nuget = options.nuget || "./nuget.exe";
options.outputDirectory = options.outputDirectory || "./.gulp-nuget";
options.maxBuffer = options.maxBuffer || 200 * 1024;

return through.obj(function (file, encoding, done) {
if (!validFor.pack(file)) {
return done(null, file);
}

var self = this;
var args = argsFor.pack(file.path, options);
var opts = { maxBuffer: options.maxBuffer };

fs.mkdirs(options.outputDirectory, function (err) {
if (err) throw new PluginError("gulp-nuget", err);

cproc.execFile(options.nuget, args, opts, function (err, stdout) {
if (err) throw new PluginError("gulp-nuget", err);

log(stdout.trim());

var files = findNupkgs(stdout);
pushFiles.call(self, files, done);
});
});
});
};

function pushFiles(files, done) {
var self = this;

files.forEach(function(file, index) {
fs.readFile(file, function(err, data) {
if(err) throw new PluginError('gulp-nuget', err);

self.push(new File({
base: path.dirname(file),
path: file,
contents: data
}));

if((index + 1) === files.length) {
fs.remove('./.gulp-nuget', done);
}
});
});
var self = this;

files.forEach(function (file, index) {
fs.readFile(file, function (err, data) {
if (err) throw new PluginError("gulp-nuget", err);

self.push(
new File({
base: path.dirname(file),
path: file,
contents: data,
})
);

if (index + 1 === files.length) {
fs.remove("./.gulp-nuget", done);
}
});
});
}

function findNupkgs(stdout) {
var matches = [];
var nupkg = new RegExp('[\'"„“](.+\.nupkg)[\'"”]', 'ig');
var nupkg = new RegExp("['\"„“](.+.nupkg)['\"”]", "ig");

var match = nupkg.exec(stdout);

while(match != null) {
while (match != null) {
matches.push(match[1]);
match = nupkg.exec(stdout);
}

if(!matches || !matches.length) {
throw new PluginError('gulp-nuget', 'Could not detect any output .nupkg files from nuget.');
if (!matches || !matches.length) {
throw new PluginError(
"gulp-nuget",
"Could not detect any output .nupkg files from nuget."
);
}

return matches;
};
}
Loading

0 comments on commit 80b6115

Please sign in to comment.