mirror of
https://github.com/valitydev/thrift-ts.git
synced 2024-11-06 08:45:17 +00:00
add getBasePath
This commit is contained in:
parent
d33e71fcd3
commit
e30cbe7079
@ -38,6 +38,34 @@ if (!argv._.length) {
|
||||
throw new Error('must specify a file');
|
||||
}
|
||||
|
||||
function getBasePath(files) {
|
||||
let i = 0;
|
||||
if (files.length <= 1) return '';
|
||||
while (i < files[0].length) {
|
||||
let char = '';
|
||||
const equal = files.every((file, index) => {
|
||||
if (index === 0) {
|
||||
char = file[i]
|
||||
return true;
|
||||
} else if (file[i] === char) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (!equal) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return files[0].slice(0, i);
|
||||
}
|
||||
|
||||
let basePath = null;
|
||||
if (argv._.length > 1) {
|
||||
basePath = getBasePath(argv._);
|
||||
}
|
||||
|
||||
argv._.forEach((p) => {
|
||||
let out;
|
||||
if (argv.out) {
|
||||
@ -47,6 +75,10 @@ argv._.forEach((p) => {
|
||||
}
|
||||
glob(p, (err, files) => {
|
||||
if (err) throw err;
|
||||
if (!basePath) {
|
||||
basePath = getBasePath(files);
|
||||
}
|
||||
console.log(basePath)
|
||||
files.forEach(file => {
|
||||
const files = thriftTs.default({
|
||||
filename: file,
|
||||
@ -56,9 +88,10 @@ argv._.forEach((p) => {
|
||||
spaceAsTab: argv.spaceAsTab,
|
||||
int64AsString: argv.int64AsString,
|
||||
});
|
||||
files.forEach(file => {
|
||||
console.log(path.join(out, file.filename))
|
||||
fs.writeFileSync(path.join(out, file.filename), file.content);
|
||||
files.forEach(newFile => {
|
||||
const outfile = path.join(out, path.relative(basePath, path.dirname(file)), newFile.filename);
|
||||
console.log(outfile);
|
||||
fs.writeFileSync(outfile, newFile.content);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "thrift-ts",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"description": "",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
|
Loading…
Reference in New Issue
Block a user