proto-gen-dts
Version:
proto generate typescript dictionary type file
87 lines (68 loc) • 3.12 kB
JavaScript
;
var _path = _interopRequireDefault(require("path"));
var _stanUtils = require("stan-utils");
var _genDts = _interopRequireDefault(require("./gen-dts"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
var pkg = require('../package.json');
(0, _stanUtils.updateNotifier)({
pkg: pkg,
updateCheckInterval: 0,
shouldNotifyInNpmScript: true
}).notify({
defer: true
});
var _yParser = (0, _stanUtils.yParser)(process.argv.slice(2)),
files = _yParser._,
o = _yParser.o,
output = _yParser.output,
d = _yParser.d,
dir = _yParser.dir,
e = _yParser.e,
entryfile = _yParser.entryfile,
keepcase = _yParser.keepcase;
var outputDir = output || o || '';
var protoDir = dir || d || '';
var entryDTS = entryfile || e;
if (entryDTS) {
if (typeof entryDTS === 'boolean') {
entryDTS = 'index.d.ts';
} else if (!entryDTS.endsWith('.d.ts')) {
entryDTS = entryDTS + '.d.ts';
}
}
var genEntryFile = entryDTS ? entryDTS : outputDir ? _path.default.join(outputDir, 'index.d.ts') : false;
if (protoDir) {
try {
files.push.apply(files, _toConsumableArray(_stanUtils.globby.sync(_path.default.join(protoDir, '**/*.proto'))));
} catch (e) {
console.log(_stanUtils.chalk.red('Matching proto file error'), e);
process.exit(1);
}
}
try {
(0, _genDts.default)({
files: files.map(function (file) {
var _path$parse = _path.default.parse(file),
name = _path$parse.name,
dir = _path$parse.dir;
return {
file: file,
output: outputDir.endsWith('.d.ts') ? outputDir : _path.default.join(outputDir || dir, name + '.d.ts')
};
}),
referenceEntryFile: genEntryFile,
protoParseOptions: {
keepCase: !!keepcase
}
});
console.log(_stanUtils.chalk.cyanBright('Compile successfully.'));
process.exit(0);
} catch (e) {
process.exit(1);
}