feat: camper info (#62)

* feat: camper info

* remember log file

* remember bug report

* specify where to run script

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
Shaun Hamilton
2022-09-27 15:17:38 +01:00
committed by GitHub
parent 544b18f451
commit 51aa3b6d38
4 changed files with 96 additions and 6 deletions

View File

@@ -4,10 +4,7 @@ about: Report a bug with the platform/content
title: '[BUG]: '
---
### Project
### Lesson Number
### Issue/Experience
### Code and Screenshots
### Output of running `node tooling/camper-info.js` from the workspace root

0
.logs/.history_cwd.log Normal file
View File

View File

@@ -126,5 +126,5 @@ for i in $(ls -A $HOME/.bashrc.d/); do source $HOME/.bashrc.d/$i; done
WD=/workspace/web3-curriculum
PROMPT_COMMAND='>| $WD/.logs/.terminal-out.log && cat $WD/.logs/.temp.log >| $WD/.logs/.terminal-out.log && truncate -s 0 $WD/.logs/.temp.log; echo $PWD >> $WD/.logs/.cwd.log; history -a $WD/.logs/.bash_history.log'
PROMPT_COMMAND='>| $WD/.logs/.terminal-out.log && cat $WD/.logs/.temp.log >| $WD/.logs/.terminal-out.log && truncate -s 0 $WD/.logs/.temp.log; echo $PWD >> $WD/.logs/.cwd.log; history -a $WD/.logs/.bash_history.log; echo $PWD\$ $(history | tail -n 1) >> $WD/.logs/.history_cwd.log;'
exec > >(tee -ia $WD/.logs/.temp.log) 2>&1

93
tooling/camper-info.js Normal file
View File

@@ -0,0 +1,93 @@
/**
* @file Provides command-line output of useful debugging information
* @example
*
* ```bash
* node tooling/camper-info.js --history --directory
* ```
*/
import {
getProjectConfig,
getConfig,
getState
} from '../.freeCodeCamp/tooling/env.js';
import __helpers from '../.freeCodeCamp/tooling/test-utils.js';
import { Logger } from 'logover';
import { readdir, readFile } from 'fs/promises';
import { join } from 'path';
const logover = new Logger({ level: 'debug', timestamp: null });
const FLAGS = process.argv;
async function main() {
try {
const handleFlag = {
'--history': printCommandHistory,
'--directory': printDirectoryTree
};
const projectConfig = await getProjectConfig();
const config = await getConfig();
const state = await getState();
const { currentProject } = state;
const { currentLesson } = projectConfig;
const { version } = config;
const devContainerFile = await readFile(
'.devcontainer/devcontainer.json',
'utf-8'
);
const devConfig = JSON.parse(devContainerFile);
const coursesVersion = devConfig.extensions?.find(e =>
e.match('freecodecamp-courses')
);
const { stdout } = await __helpers.getCommandOutput('git log -1');
logover.info('Project: ', currentProject);
logover.info('Lesson Number: ', currentLesson);
logover.info('Curriculum Version: ', version);
logover.info('freeCodeCamp - Courses: ', coursesVersion);
logover.info('Commit: ', stdout);
for (const arg of FLAGS) {
await handleFlag[arg]?.();
}
async function printDirectoryTree() {
const files = await readdir('.', { withFileTypes: true });
let depth = 0;
for (const file of files) {
if (file.isDirectory() && file.name === currentProject) {
await recurseDirectory(file.name, depth);
}
}
}
async function printCommandHistory() {
const historyCwd = await readFile('.logs/.history_cwd.log', 'utf-8');
logover.info('Command History:\n', historyCwd);
}
} catch (e) {
logover.error(e);
}
}
main();
const IGNORE = ['node_modules', 'target'];
async function recurseDirectory(path, depth) {
logover.info(`|${' '.repeat(depth * 2)}|-- ${path}`);
depth++;
const files = await readdir(path, { withFileTypes: true });
for (const file of files) {
if (!IGNORE.includes(file.name)) {
if (file.isDirectory()) {
await recurseDirectory(join(path, file.name), depth);
} else {
logover.info(`|${' '.repeat(depth * 2)}|-- ${file.name}`);
}
}
}
}