반응형
나는 내가 푼 문제의 코드를 Github에 올린다. 하지만 한 폴더에 수백 개씩 푼 코드를 저장하는 건 보기 좋지 않아 xx00 ~ xx99까지 한 폴더에 넣어서 관리해 주는 프로그램을 만들었다.
open_vscode.js
let argvs = process.argv;
let fs = require("fs");
let path = require("path");
const { exec } = require("child_process");
if (argvs.length <= 2) {
console.log("Usage: node code.js <number>");
process.exit(1);
}
console.log("Base Dir :", process.cwd());
let baseDir = process.cwd();
let fileName = argvs.slice(2).join("");
console.log("File Name :", fileName, ". cpp");
let fileFolder = fileName.slice(0, fileName.length - 2) + "__";
console.log("File Folder :", fileFolder);
// createFolder
let folderPath = path.join(baseDir, fileFolder);
console.log("Folder Path :", folderPath);
if (!fs.existsSync(folderPath)) fs.mkdirSync(folderPath);
// createFile
let filePath = path.join(folderPath, fileName + ".cpp");
console.log("File Path :", filePath);
let preset = fs.readFileSync(path.join(__dirname, "preset"), "utf8");
if (!fs.existsSync(filePath)) fs.writeFileSync(filePath, preset);
exec("code " + filePath, (err, stdout, stderr) => {});
upload_github.js
let argvs = process.argv;
let fs = require("fs");
let path = require("path");
const { exec } = require("child_process");
if (argvs.length <= 2) {
console.log("Usage: node code.js <number>");
process.exit(1);
}
console.log("Base Dir :", process.cwd());
let baseDir = process.cwd();
let fileName = argvs.slice(2).join("");
console.log("File Name :", fileName, ". cpp");
let fileFolder = fileName.slice(0, fileName.length - 2) + "__";
console.log("File Folder :", fileFolder);
// createFolder
let folderPath = path.join(baseDir, fileFolder);
console.log("Folder Path :", folderPath);
if (!fs.existsSync(folderPath)) fs.mkdirSync(folderPath);
// createFile
let filePath = path.join(folderPath, fileName + ".cpp");
console.log("File Path :", filePath);
let preset = fs.readFileSync(path.join(__dirname, "preset"), "utf8");
if (!fs.existsSync(filePath)) fs.writeFileSync(filePath, preset);
console.log("$ git add cpp_file");
exec("git add " + filePath, (err, stdout, stderr) => {
if (stdout) {
console.log("STD out : ");
console.log(stdout);
}
if (stderr) {
console.log("STD err : ");
console.log(stderr);
}
console.log("$ git add cph");
exec("git add " + folderPath + "/.cph/*.prob", (err, stdout, stderr) => {
if (stdout) {
console.log("STD out : ");
console.log(stdout);
}
if (stderr) {
console.log("STD err : ");
console.log(stderr);
}
console.log("$ git commit -m '[Message]'");
exec('git commit -m "Add' + fileName + '"', (err, stdout, stderr) => {
if (stdout) {
console.log("STD out : ");
console.log(stdout);
}
if (stderr) {
console.log("STD err : ");
console.log(stderr);
}
console.log("$ git push");
exec("git push", (err, stdout, stderr) => {
if (stdout) {
console.log("STD out : ");
console.log(stdout);
}
if (stderr) {
console.log("STD err : ");
console.log(stderr);
}
});
});
});
});
preset
#include <vector>
#include <algorithm>
#include <queue>
#include <iostream>
#include <map>
#include <set>
#include <math.h>
#include <numeric>
#include <cassert>
#include <stack>
#include <cstring>
using namespace std;
typedef long long ll;
typedef unsigned long ull;
typedef pair<int, int> pii;
typedef signed char i8;
typedef short i16;
typedef int i32;
typedef long long i64;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int main()
{
cin.tie(0);
cout.tie(0);
}
이 3가지 파일을 한 폴더에 넣고 아래처럼 사용하면 된다.
node scripts/open_vsc.js 1000
node scripts/upload_github.js 1000
Alias를 걸어서 사용하면 더욱 편하다!
반응형