Skip to content

Commit

Permalink
fix: expose push command results
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Oct 5, 2021
1 parent acbfd36 commit c6a5299
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Article, Repository } from '../models.js';

const debug = Debug('push');

interface PushOptions {
export interface PushOptions {
devtoKey: string;
repo: string;
branch: string;
Expand All @@ -30,7 +30,7 @@ interface PushOptions {
checkImages: boolean;
}

interface PushResult {
export interface PushResult {
article: Article;
status: string;
publishedStatus: string;
Expand Down Expand Up @@ -114,7 +114,7 @@ async function processArticles(
return pMap(localArticles, processArticle, { concurrency: 5 });
}

export async function push(files: string[], options?: Partial<PushOptions>) {
export async function push(files: string[], options?: Partial<PushOptions>): Promise<PushResult[] | null> {
options = options ?? {};
files = files.length > 0 ? files : ['posts/**/*.md'];
debug('files: %O', files);
Expand All @@ -125,7 +125,7 @@ export async function push(files: string[], options?: Partial<PushOptions>) {
console.error(
chalk`{red No dev.to API key provided.}\nUse {bold --token} option or {bold .env} file to provide one.`
);
return;
return null;
}

if (options.dryRun) {
Expand All @@ -141,7 +141,7 @@ export async function push(files: string[], options?: Partial<PushOptions>) {
console.error(
chalk`{red No GitHub repository provided.}\nUse {bold --repo} option or {bold .env} file to provide one.`
);
return;
return null;
}

debug('repository: %O', repository);
Expand All @@ -152,7 +152,7 @@ export async function push(files: string[], options?: Partial<PushOptions>) {
console.error(
chalk`{red No GitHub branch provided.}\nUse {bold --branch} option or {bold .env} file to provide one.`
);
return;
return null;
}

debug('branch: %s', branch);
Expand All @@ -162,7 +162,7 @@ export async function push(files: string[], options?: Partial<PushOptions>) {

if (articles.length === 0) {
console.warn(chalk`No articles to push.`);
return;
return [];
}

spinner.text = 'Retrieving articles from dev.to…';
Expand All @@ -189,10 +189,13 @@ export async function push(files: string[], options?: Partial<PushOptions>) {
if (failed) {
process.exitCode = -1;
}

return results;
} catch (error) {
spinner.stop();
process.exitCode = -1;
console.error(chalk`{red Error: ${(error as Error).message}}`);
console.error('Push failed');
return null;
}
}

0 comments on commit c6a5299

Please sign in to comment.