2020-06-18 13:58:38 +02:00
|
|
|
/* eslint-disable no-sync */
|
|
|
|
import { dirname, join, sep, basename } from 'path';
|
|
|
|
import fs from 'fs-extra';
|
2020-06-16 12:52:41 +02:00
|
|
|
|
2020-06-18 13:58:38 +02:00
|
|
|
function read_dir (dir:string, exclude_files:boolean):string[] {
|
|
|
|
const contents = fs.readdirSync (dir);
|
|
|
|
contents.unshift ('..');
|
|
|
|
if (exclude_files) {
|
|
|
|
return contents.filter ((c) => {
|
|
|
|
const full_path = join (dir, c);
|
|
|
|
try {
|
|
|
|
return fs.statSync (full_path)
|
|
|
|
.isDirectory ();
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2020-06-16 12:52:41 +02:00
|
|
|
}
|
2020-06-18 13:58:38 +02:00
|
|
|
return contents;
|
|
|
|
}
|
2020-06-16 12:52:41 +02:00
|
|
|
|
2020-06-18 13:58:38 +02:00
|
|
|
interface PathPromptOptions {
|
|
|
|
starting_dir?: string;
|
|
|
|
folders_only?: boolean;
|
|
|
|
}
|
2020-06-16 12:52:41 +02:00
|
|
|
|
2020-06-18 13:58:38 +02:00
|
|
|
export class PathPrompt {
|
|
|
|
private _options: PathPromptOptions;
|
2020-06-16 12:52:41 +02:00
|
|
|
|
2020-06-18 13:58:38 +02:00
|
|
|
public constructor (options:PathPromptOptions) {
|
|
|
|
this._options = options;
|
2020-06-16 12:52:41 +02:00
|
|
|
}
|
|
|
|
}
|