mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-20 21:01:37 -05:00
* feat: add challenge editor tool chore: prepare API/Client setup feat: migrate to react! feat: styling fix: useEffect loop feat: add challenge helpers feat: use actual code editor feat: styling Bring it a bit more in line with /learn * refactor: use workspaces Which unfortunately required a rollback to React 16, because having multiple React versions causes all sorts of issues. * chore: apply Oliver's review suggestions Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * chore: remove test files for now * fix: prettier issue * chore: apply oliver's review suggestions Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * chore: move scripts to root * fix: lint errors oops * chore: remove reportWebVitals thing * chore: DRY out paths * fix: create-empty-steps takes one arg * chore: start doesn't make sense now * chore: DRY out button requests * chore: one more review suggestion Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * chore: cleanup CRA files * fix: correct note for creating new project * feat: enable js and jsx highlighting * feat: include all superblocks * feat: improve button ux * feat: add "breadcrumbs" * feat: add link back to block from step tools * chore: remove unused deps * chore: apply oliver's review suggestions Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * chore: parity between file names and commands Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { exec } from 'child_process';
|
|
import { join } from 'path';
|
|
import { promisify } from 'util';
|
|
|
|
import { Request, Response } from 'express';
|
|
import { ToolsSwitch } from '../interfaces/Tools';
|
|
|
|
const asyncExec = promisify(exec);
|
|
|
|
const toolsSwitch: ToolsSwitch = {
|
|
'create-next-step': directory => {
|
|
return asyncExec(`cd ${directory} && npm run create-next-step`);
|
|
},
|
|
'create-empty-steps': (directory, num) => {
|
|
return asyncExec(`cd ${directory} && npm run create-empty-steps ${num}`);
|
|
},
|
|
'insert-step': (directory, num) => {
|
|
return asyncExec(`cd ${directory} && npm run insert-step ${num}`);
|
|
},
|
|
'delete-step': (directory, num) => {
|
|
return asyncExec(`cd ${directory} && npm run delete-step ${num}`);
|
|
},
|
|
'update-step-titles': directory => {
|
|
return asyncExec(`cd ${directory} && npm run update-step-titles`);
|
|
}
|
|
};
|
|
|
|
export const toolsRoute = async (req: Request, res: Response) => {
|
|
const { superblock, block, command } = req.params;
|
|
const { num } = req.body as Record<string, number>;
|
|
const directory = join(
|
|
__dirname,
|
|
'..',
|
|
'..',
|
|
'..',
|
|
'..',
|
|
'curriculum',
|
|
'challenges',
|
|
'english',
|
|
superblock,
|
|
block
|
|
);
|
|
|
|
if (!(command in toolsSwitch)) {
|
|
res.json({ stdout: '', stderr: 'Command not found' });
|
|
return;
|
|
}
|
|
|
|
const parsed = command as keyof ToolsSwitch;
|
|
|
|
const { stdout, stderr } = await toolsSwitch[parsed](directory, num);
|
|
res.json({ stdout, stderr });
|
|
};
|