Skip to content

Commit

Permalink
feat(stdout): start to play around with the log ouput
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Sep 1, 2021
1 parent c99cf50 commit 9edb992
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import chalk from 'chalk';
import del from 'del';
import { join } from 'path';
import mkdirp from 'mkdirp';
import fs from 'fs/promises';

import { listFolder } from './lib/list-folder';
import { parseFile, parseVueFile, writeContentToFile } from './lib/parser';
import { getExtension } from './lib/utils';
import { generateVueSidebar } from './lib/vue-sidebar';

const fileTree: any[] = [];
const statistics: Record<string, any> = {};
Expand Down Expand Up @@ -56,6 +59,19 @@ export const generate = async (argv: Record<string, string>) => {
await mkdirp(docsFolder);

const parsePromises: Promise<any>[] = [];

console.log();
for (const file of filesAndFolder) {
if (!file.isDir) {
process.stdout.clearLine(-1);
process.stdout.cursorTo(0);
process.stdout.write(`${chalk.dim(` ${file.path} `)}`);
await new Promise(resolve => setTimeout(resolve, 20));
}
}
process.stdout.clearLine(-1);
process.stdout.cursorTo(0);

for (const file of filesAndFolder) {
if (!file.isDir) {
switch (file.ext) {
Expand Down Expand Up @@ -85,6 +101,38 @@ export const generate = async (argv: Record<string, string>) => {
);
}

// await fs.writeFile(
// `${docsFolder}/config.js`,
// `exports.fileTree=${JSON.stringify(fileTree)};exports.sidebarTree = (title = 'Mainpage') => (${JSON.stringify(
// generateVueSidebar({
// fileTree,
// codeFolder,
// title
// })
// ).replace('::vuepress-jsdoc-title::', '"+title+"')});`
// );

// create README.md
let readMeContent = `### Welcome to ${title}`;
const readmePath = readme || `${srcFolder}/README.md`;

try {
readMeContent = await fs.readFile(readmePath, 'utf-8');
if (deletedPaths.some(p => p.indexOf(`${codeFolder}/README.md`) !== -1)) {
console.log(`\n${chalk.black.bgYellow('found')} ${readmePath} and copies content to ${docsFolder}/README.md`);
}
} catch (e) {
console.log(`${chalk.white.bgBlack('skipped')} copy README.md`);
}

// Do nothing if README.md already exists
try {
readMeContent = await fs.readFile(`${docsFolder}/README.md`, 'utf-8');
console.log(`\n${chalk.yellow(`${docsFolder}/README.md already exists`)}`);
} catch (e) {
await fs.writeFile(`${docsFolder}/README.md`, readMeContent);
}

const resultTime = (Math.abs(startTime - +new Date()) / 1000).toFixed(2);

console.log(`\n⏰ Time: ${resultTime}s\n`);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export const parseVueFile = async (
const relativePathDest = join(destFolder, file.folder.replace(srcFolder, ''));
const folderInDest = join(root, relativePathDest);
const folderInSrc = join(root, file.folder);

const config = {
...extractConfig(join(root, file.folder)),
components: file.name + file.ext,
outDir: folderInDest
components: file.name + file.ext
};

let success = true;
Expand Down

0 comments on commit 9edb992

Please sign in to comment.