Skip to content

Commit

Permalink
chore: logging ( fix #53 )
Browse files Browse the repository at this point in the history
  • Loading branch information
ega4432 committed Feb 25, 2023
1 parent 9a0f5af commit f24be90
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ jobs:
steps:
- name: Checkout source
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Normal test
id: import
Expand Down
12 changes: 9 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { getInput, setFailed, info, error, setOutput } from '@actions/core';
import {
getInput,
setFailed,
info,
error,
setOutput,
debug
} from '@actions/core';
import { mkdirP } from '@actions/io';
import { Client } from '@notionhq/client';
import { readdir, writeFile } from 'fs/promises';
Expand Down Expand Up @@ -47,19 +54,22 @@ const run = async (
await createFiles(mdResponse, outDir);

const files = await readdir(outDir);
debug(`Output: files_count=${files.length.toString()}`);
setOutput('files_count', files.length.toString());

info('---> Successfully created markdown files!');
};

const createFiles = async (pages: MarkdownPage[], outDir: string) => {
for (const markdown of pages) {
pages.forEach(async (markdown) => {
if (markdown.filename.length) {
// NOTE: 現状すでにファイルが存在していても上書きする
await writeFile(`${outDir}/${markdown.filename}.md`, markdown.body);
const filename = `${outDir}/${markdown.filename}.md`;
await writeFile(filename, markdown.body);
debug(`Created: ${filename}`);
await downloadImages(markdown.filename, outDir);
}
}
});
};

const downloadImages = async (filename: string, outDir: string) => {
Expand All @@ -76,6 +86,8 @@ const downloadImages = async (filename: string, outDir: string) => {
const image = `${filename}/${alt || `untitled${untitledCount}`}.png`;
await writeFile(`${outDir}/${image}`, res.data, 'binary');

debug(`Created image: ${outDir}/${image}`);

replaced = replaced.replace(src, image);
}

Expand Down

0 comments on commit f24be90

Please sign in to comment.