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

Add support for output file customisation #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ ProtobufPlugin.prototype.multipleOutput = function (files, cb) {
}
var promise = [];
var self = this;
var root = path.relative(process.cwd(), this.options.output);
mkdir.sync(root);
files.forEach(function (file) {
promise.push(new Promise(function (resolve, reject) {
let command = [].concat(self.command);
Expand All @@ -141,7 +139,13 @@ ProtobufPlugin.prototype.multipleOutput = function (files, cb) {
res.forEach(function (result) {
var output = result.output;
var file = result.file;
var outputPath = path.join(self.options.output, path.parse(file).name + '.js');
var outputPath;
if (typeof self.options.output === 'function') {
outputPath = self.options.output(file);
} else {
outputPath = path.join(self.options.output, path.parse(file).name + '.js');
}
mkdir.sync(path.parse(outputPath).dir);
fs.writeFile(outputPath, output, function (error) {
if (error) {
console.log('[protobuf plugin] output error: ', error);
Expand Down