mirror of
https://github.com/freeCodeCamp/web3-curriculum.git
synced 2026-01-10 05:57:58 -05:00
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:
7
.github/ISSUE_TEMPLATE/BUG.md
vendored
7
.github/ISSUE_TEMPLATE/BUG.md
vendored
@@ -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
0
.logs/.history_cwd.log
Normal 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
93
tooling/camper-info.js
Normal 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}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user