Skip to content

Commit

Permalink
chore: Drop export lists, exporting individual features instead
Browse files Browse the repository at this point in the history
  • Loading branch information
bencergazda committed Sep 9, 2021
1 parent e95833d commit 464e703
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 42 deletions.
15 changes: 4 additions & 11 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Config, TsProject, TsProjectWithFiles } from './types';
* @param projects
* @param config
*/
async function collect_projects_files(projects: TsProject[], config: Config): Promise<TsProjectWithFiles[]> {
export async function collect_projects_files(projects: TsProject[], config: Config): Promise<TsProjectWithFiles[]> {
// console.log('collect_projects_files');
if (!Array.isArray(projects)) {
throw new Error('No project data received');
Expand All @@ -42,7 +42,7 @@ async function collect_projects_files(projects: TsProject[], config: Config): Pr
* Returns a flat array with the source and target paths of all files that will be processed
* @param globed_projects
*/
async function collect_projects_files_flat(globed_projects: TsProjectWithFiles[]): Promise<{ source_path: string; target_path: string; }[]> {
export async function collect_projects_files_flat(globed_projects: TsProjectWithFiles[]): Promise<{ source_path: string; target_path: string; }[]> {
const all_projects_files = await Promise.all(globed_projects.map(async (project) => {
const { root_dir, out_dir, source_files } = project;

Expand All @@ -62,7 +62,7 @@ async function collect_projects_files_flat(globed_projects: TsProjectWithFiles[]
* @param projects
* @param config
*/
async function copy_files(projects: TsProject[], config: Config): Promise<void> {
export async function copy_files(projects: TsProject[], config: Config): Promise<void> {
// console.log('copy_projects');
const globed_projects = await collect_projects_files(projects, config);

Expand All @@ -85,7 +85,7 @@ async function copy_files(projects: TsProject[], config: Config): Promise<void>
* @param projects
* @param config
*/
async function watch_files(projects: TsProject[], config: Config): Promise<void> {
export async function watch_files(projects: TsProject[], config: Config): Promise<void> {
// console.log('watch_projects');
const globed_projects = await collect_projects_files(projects, config);

Expand Down Expand Up @@ -180,10 +180,3 @@ async function watch_files(projects: TsProject[], config: Config): Promise<void>
await close_watcher();
});
}

export {
collect_projects_files,
collect_projects_files_flat,
copy_files,
watch_files,
}
45 changes: 14 additions & 31 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import rimraf from 'rimraf';
import { cosmiconfig } from 'cosmiconfig';
import { CliOptions, Config, LoaderMeta, Rule, RuleCondition, TsProject } from './types';

const promisified = {
export const promisified = {
fs: {
...pify(fs),
exists: pify(fs.exists, { errorFirst: false }),
Expand All @@ -20,7 +20,7 @@ const promisified = {

// https://stackoverflow.com/a/41407246/3111787
// https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
enum console_colors {
export enum console_colors {
Reset = '\x1b[0m',
Bright = '\x1b[1m',
Dim = '\x1b[2m',
Expand Down Expand Up @@ -95,7 +95,7 @@ const options: CliOptions = program.opts();
/**
* Returns the complete, resolved configuration object
*/
async function get_config(): Promise<Config> {
export async function get_config(): Promise<Config> {
const cwd = definitely_posix(process.cwd());

const ts_config = get_ts_config(cwd, options.project);
Expand Down Expand Up @@ -130,7 +130,7 @@ async function get_config(): Promise<Config> {
* @param currentDir
* @param project
*/
function get_ts_config(currentDir: string, project: string): ParsedCommandLine {
export function get_ts_config(currentDir: string, project: string): ParsedCommandLine {
const configFile = ts.findConfigFile(currentDir, ts.sys.fileExists, project);

if (!configFile) throw Error('tsconfig.json not found')
Expand Down Expand Up @@ -176,7 +176,7 @@ function build_project_path(cwd: string, project_path: string, ts_config: Parsed
* Returns the internal project descriptor of a TS project that doesn't have project references
* @param options
*/
function get_ts_project_paths(options: Config): TsProject {
export function get_ts_project_paths(options: Config): TsProject {
const { cwd, cli_options, ts_config } = options;

return build_project_path(cwd, cli_options.project, ts_config);
Expand All @@ -186,7 +186,7 @@ function get_ts_project_paths(options: Config): TsProject {
* Returns the internal project descriptor of a TS project that has project references
* @param options
*/
function get_ts_projects_paths(options: Config): TsProject[] {
export function get_ts_projects_paths(options: Config): TsProject[] {
const { ts_config } = options;

if (!ts_config.projectReferences) {
Expand Down Expand Up @@ -215,7 +215,7 @@ function get_ts_projects_paths(options: Config): TsProject[] {
* @param config
* @param projects
*/
function get_ignore_list(config: Config, projects: TsProject | TsProject[]): string[] {
export function get_ignore_list(config: Config, projects: TsProject | TsProject[]): string[] {
const ignore_list: string[] = [];

if (config.use_ts_exclude) {
Expand Down Expand Up @@ -246,15 +246,15 @@ function get_ignore_list(config: Config, projects: TsProject | TsProject[]): str
* @param msg
* @param color
*/
function color_log(msg: string, color: typeof console_colors[keyof typeof console_colors]): string {
export function color_log(msg: string, color: typeof console_colors[keyof typeof console_colors]): string {
return `${color}${msg}${console_colors.Reset}`;
}

/**
* Makes sure that the given folder (or the parent folder of a file) exists - creates if not
* @param p {string}
*/
async function validate_path(p: string): Promise<void> {
export async function validate_path(p: string): Promise<void> {
const dirname = path.dirname(p);

if (!await promisified.fs.exists(dirname)) {
Expand All @@ -266,7 +266,7 @@ async function validate_path(p: string): Promise<void> {
* Error-safe `fs.lstat` - returns stats if the file exists, otherwise null
* @param file_path
*/
async function get_file_stats(file_path: string): Promise<fs.Stats | void> {
export async function get_file_stats(file_path: string): Promise<fs.Stats | void> {
try {
return await promisified.fse.lstat(file_path);
} catch (e) {
Expand All @@ -278,7 +278,7 @@ async function get_file_stats(file_path: string): Promise<fs.Stats | void> {
* Deletes the `file_path` file. Doesn't throw error if the file doesn't exist.
* @param file_path
*/
async function remove_file_or_directory(file_path: string): Promise<void> {
export async function remove_file_or_directory(file_path: string): Promise<void> {
const stats = await get_file_stats(file_path);

if (!stats) {
Expand All @@ -298,7 +298,7 @@ const files_without_loaders: string[] = [];
* @param destination_path
* @param config
*/
async function copy_file_or_directory(source_path: string, destination_path: string, config: Config) {
export async function copy_file_or_directory(source_path: string, destination_path: string, config: Config) {
const stats = await get_file_stats(source_path);

if (!stats) {
Expand Down Expand Up @@ -430,7 +430,7 @@ async function apply_loaders(raw_content: string, source_path: string, destinati
* Returns a Promise that resolves automatically after `ms`
* @param ms
*/
function sleep(ms: number) {
export function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

Expand All @@ -439,23 +439,6 @@ function sleep(ms: number) {
* @param p path string
* @see https://stackoverflow.com/a/63251716/3111787
*/
function definitely_posix(p: string) {
export function definitely_posix(p: string) {
return p.split(path.sep).join(path.posix.sep);
}

export {
get_config,
get_ts_config,
get_ts_project_paths,
get_ts_projects_paths,
get_ignore_list,
validate_path,
get_file_stats,
remove_file_or_directory,
copy_file_or_directory,
sleep,
definitely_posix,
promisified,
console_colors,
color_log,
};

0 comments on commit 464e703

Please sign in to comment.