tstosc
Version:
A transpiler that convert TypeScript to SuperCollider's SCLang.
123 lines (121 loc) • 4.65 kB
text/typescript
/**
* When encounter these args, stop parsing remaining, and use it as the intention of user.
*/
declare const priority_of_stop_early_global_option: readonly ["help", "h", "version", "v"];
declare const non_arg_accepting_global_option: readonly ["help", "h", "version", "v", "yes-to-all", "y"];
/**
* The argument shape parsed by `minimist`.
*/
type CLIGlobalArgs = CLIGlobalEarlyStopArgs & {
/** No arg parsed here. */
"_": string[];
/** The output dir of the files. If not specified, `cwd`. */
"d"?: string;
/** The output dir of the files. If not specified, `cwd`. */
"out-dir"?: string;
/** Do not keep directory structure, put all files in `out-dir`; by default, false. */
"flatten"?: true;
/** The path for storing class file, should be the path in `Platform.userExtensionDir` in SuperCollider. */
"u"?: string;
/** The path for storing class file, should be the path in `Platform.userExtensionDir` in SuperCollider. */
"user-extension-dir"?: string;
/** Project name, used to differentiate from other folders in `user-extension-dir`. By default `tstosc`. */
"p"?: string;
/** Project name, used to differentiate from other folders in `user-extension-dir`. By default `tstosc`. */
"project-name"?: string;
/** Whether ignore all warning (with type "y" to proceed) produced by `tstosc`. */
"y"?: true;
/** Whether ignore all warning (with type "y" to proceed) produced by `tstosc`. */
"yes-to-all"?: true;
};
type CLIGlobalEarlyStopArgs = {
/** Whether user asked for quick helping doc. */
"h"?: string;
/** Whether user asked for quick helping doc. */
"help"?: string;
/** Show the version of current used `tstosc`. */
"v"?: true;
/** Show the version of current used `tstosc`. */
"version"?: true;
};
type CLIPositionalArgs = {
/** File going to be transpiled by `tstosc`. */
"_": string;
"o"?: string;
"out"?: string;
"d"?: string;
"out-dir"?: string;
};
/**
* Pre-process the argument, cut it into these groups:
* * Global argument (`return[0]`)
* * Files to process (`return[1]` and more, if exist).
*
* @returns Groups of argument
*/
declare function seperateArgs(origin_arg: string[]): [string[], string[][]];
type UserIntention = UserTranspileIntention | UserQueryIntention | UserNoIntetion | UserIntentionUnknownOrError;
type UserTranspileIntention = {
type: "transpile";
global: {
/**
* The global (fallback) setting for directory of the output file (in absolute path).
* If not specified, will be current work directory.
*/
output_dir: string;
/**
* Should be the path of `Platform.userExtensionDir` in SuperCollider.
*/
user_extension_dir: string;
/**
* The sub-folder name under `Platform.userExtensionDir` in SuperCollider,
* used to differentiate with others.
* By default, `tstosc`.
*/
project_name: string;
/**
* Ignoring all warning and answer "y" to proceed.
*/
yes_to_all: boolean;
/**
* Flatten the files to global output dir.
*/
flatten: boolean;
};
files: ({
/**
* The received path to the input file, might be absolute or relative depending on user input.
*/
input_path: string;
/**
* The name of the output file.
* If not specified at positional args, then the input file's name with `scd` extension.
*/
output_name: string;
/**
* The directory of the output file (in absolute path).
* If not specified at positional args, then the directory set by global option.
* If global is also not set, use current work directory.
*/
output_dir: string;
})[];
};
type UserQueryIntention = {
/** User does not want to transpile (using only global arg). */
type: "query_info";
} & ({
command: "help";
arg: string;
} | {
command: "version";
arg: true;
});
type UserNoIntetion = {
type: "no_intention";
};
type UserIntentionUnknownOrError = {
type: "unknown_or_error";
hint?: string;
};
declare function parseArgs(global_arg: CLIGlobalArgs, positional_args: CLIPositionalArgs[]): UserIntention;
export { type CLIGlobalArgs, type CLIGlobalEarlyStopArgs, type CLIPositionalArgs, type UserIntention, type UserIntentionUnknownOrError, type UserNoIntetion, type UserQueryIntention, type UserTranspileIntention, non_arg_accepting_global_option, parseArgs, priority_of_stop_early_global_option, seperateArgs };