Skip to content

Instantly share code, notes, and snippets.

@FishingHacks
Created March 28, 2023 09:55
Show Gist options
  • Save FishingHacks/0bfb903eb516c03c51f399a1fb6ec954 to your computer and use it in GitHub Desktop.
Save FishingHacks/0bfb903eb516c03c51f399a1fb6ec954 to your computer and use it in GitHub Desktop.
Helps you develop stuff :3
/**
* @name dev helper
* @description Helps you develop stuff :3
* @author FishingHacks <gh/FishingHacks>
* @uses spawnWithOutput,fileExplorer
* @shortcut Super+X
*/
import { ChildProcessWithoutNullStreams, spawnSync } from 'child_process';
import { rm } from 'fs/promises';
import { homedir } from 'os';
import { join } from 'path';
import { dirExplorer } from './file-explorer.module';
import './globals';
import { spawnWithOutput } from './spawnWithOutput.module';
const { value, write } = await db('config', { devDir: homedir() });
async function getProject() {
const _files = await fs.listDir(value.devDir);
const files: string[] = [];
for (const f of _files)
if (await fs.isDir(join(value.devDir, f))) files.push(f);
return await arg(
'Select project for deletion',
files.map((el) => ({
key: join(value.devDir, el),
name: el,
description: join(value.devDir, el),
}))
);
}
setTabs([
{ key: 'clone-repo', name: 'Clone a github Repository' },
{ key: 'launch-project', name: 'Launch a Project' },
{ key: 'delete-project', name: 'Delete a Project' },
{ key: 'install-deps', name: 'Install node dependencies' },
{ key: 'set-dev', name: 'Change the dev folder' },
]);
onTab('clone-repo', async () => {
const repo = await arg('Repository (E.g. fishinghacks/qrunner)');
const name = repo.split('/')[1];
cd(value.devDir);
spawnSync('git', ['clone', `https://github.com/${repo}.git`, name], {
cwd: fs.getCwd(),
});
edit(join(fs.getCwd(), name));
process.exit(0);
});
onTab('launch-project', async () => {
edit(await getProject());
process.exit(0);
});
onTab('delete-project', async () => {
await rm(await getProject(), { recursive: true });
process.exit(0);
});
onTab('set-dev', async () => {
try {
const newdir = await dirExplorer(value.devDir);
value.devDir = newdir;
await write();
} catch (e) {
if (e.stack && !e.stack.toString().includes('exited') && !e.stack.toString().includes('UI Changed')) console.log(e);
else if (e.stack) return;
}
setTab('clone-repo');
});
onTab('install-deps', async () => {
cd(await getProject());
await spawnWithOutput(
getPackageManager(),
[getPackageManager() === 'yarn' ? 'add' : 'install']
)
setTab('clone-repo')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment