Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
fix: get git diff all at once
Browse files Browse the repository at this point in the history
Issue #263
  • Loading branch information
froucher committed Aug 5, 2020
1 parent 8d4fbc6 commit 1a3d08b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
38 changes: 23 additions & 15 deletions lib/cli/changeset.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var Manifest = require('../manifest');
var path = require('path');
var fs = require('fs-extra');
var vinylFs = require('vinyl-fs');
var mergeStream = require('merge-stream');
var miss = require('mississippi');
var Readable = require('stream').Readable;

var doc = "Usage:\n" +
" force-dev-tool changeset create <name> [<metadataFileOrComponentNames>...] [options]\n" +
Expand Down Expand Up @@ -71,20 +72,27 @@ SubCommand.prototype.process = function(proc, callback) {
}
});

var stdin = proc.stdin
.pipe(Diff.stream({
ignoreWhitespace: !!self.opts['--ignore-whitespace']
}))
.pipe(MetadataContainer.diffStream())
var diff = {}; // first get the stdin stream with all git diff changes
proc.stdin.pipe(miss.concat(function(result) {
diff = Diff.parse(result, { ignoreWhitespace: !!self.opts['--ignore-whitespace'] });
}));

mergeStream(stdin, metadataContainer.getStream())
.pipe(MetadataContainer.completeMetadataStream())
.pipe(MetadataContainer.outputStream({
apiVersion: apiVersion
}))
.pipe(vinylFs.dest(deploymentPath))
.on('end', function() {
return callback(null, "exported metadata container to " + path.relative(proc.cwd, deploymentPath));
});
miss.finished(proc.stdin, function(err) {
if (err) return console.trace('stream had an error or closed early', err);

var th = new Readable({ objectMode: true }); // new stream with git diff changes
th.push(diff);
th.push(null); // indicates end-of-file basically - the end of the stream

th.pipe(MetadataContainer.diffStream())
.pipe(MetadataContainer.completeMetadataStream())
.pipe(MetadataContainer.outputStream({
apiVersion: apiVersion
}))
.pipe(vinylFs.dest(deploymentPath))
.on('end', function() {
return callback(null, "exported metadata container to " + path.relative(proc.cwd, deploymentPath));
});
});

};
23 changes: 8 additions & 15 deletions lib/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var MetadataContainer = require('./metadata-container');
var Git = require('./git');
var Utils = require('./utils');
var path = require('path');
var miss = require('mississippi');

var Diff = module.exports = function(data) {
this.data = data;
Expand Down Expand Up @@ -56,16 +55,12 @@ Diff.prototype.getMetadataContainers = function(opts) {
};
};

Diff.stream = function(opts) {
Diff.parse = function(diff, opts) {
var git = new Git(process.cwd());
var unpackagedPath = path.join(process.cwd(), 'src');
opts = opts || {};

return miss.through.obj(function(diff, enc, cb) {
var files = parseDiff(diff.toString());

if (files.length <= 0) return cb();

var files = parseDiff(diff.toString());
if (files.length >= 0) {
var containerFrom = new MetadataContainer();
var containerTo = new MetadataContainer();
files.forEach(function(file) {
Expand Down Expand Up @@ -94,14 +89,12 @@ Diff.stream = function(opts) {
}
containerFrom.add(fileFrom, []);
containerTo.add(fileTo, []);

}
});
}

cb(null, {
source: containerFrom,
target: containerTo
});

});
return {
source: containerFrom,
target: containerTo
};
}

0 comments on commit 1a3d08b

Please sign in to comment.