Skip to content

Commit

Permalink
#8 기존 js로 작성한 파일들 ts로 변환
Browse files Browse the repository at this point in the history
함수에 파라미터 타입과 리턴 타입 지정
  • Loading branch information
zwonlala committed Sep 18, 2021
1 parent dec417b commit 61b735a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
24 changes: 12 additions & 12 deletions Committer.js → Committer.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
const { exec } = require("child_process");

class Committer {
static logger = (code, command) =>
export default class Committer {
static logger = (code: number, command: string) =>
//if success code value is 0
code === 0
? console.log(`'${command}' command is successed. with exit code:${code}`)
: console.error(`'${command}' command is failed. with exit code:${code}`);

static commit(file) {
static commit(file: string): void {
//0. check cur dir is git directory

//1. check file is valid_
//first) file is located at this dir
//second) check file's located dir also

//2. git add
const getGitAddCmdStr = (file) => `git add ${file}`;
const getGitAddCmdStr = (file: string) => `git add ${file}`;

const addStdout = exec(
`${getGitAddCmdStr(file)}`,
(error, stdout, stderr) => {
(error: Error, stdout: string, stderr: string) => {
// console.error(error); //this value is 'null'
// console.error(stdout); //this value is ''
// console.error(stderr); //this value is ''
}
);
addStdout.on("exit", (code) => Committer.logger(code, "git add"));
addStdout.on("exit", (code: number) => Committer.logger(code, "git add"));

//3. git commit -m
const getCommitMessage = (file) => `Add ${file}`;
const getCommitMessage = (file: string) => `Add ${file}`;
const getGitCommitCmdStr = `git commit -m "${getCommitMessage(file)}"`;

const commitStdout = exec(getGitCommitCmdStr);
commitStdout.on("exit", (code) => Committer.logger(code, "git commit"));
commitStdout.on("exit", (code: number) =>
Committer.logger(code, "git commit")
);

//4. how to know git commit is succes?
}

static push() {
static push(): void {
const gitPushCmdStr = "git push";

const pushStdout = exec(gitPushCmdStr);
pushStdout.on("exit", (code) => Committer.logger(code, "git push"));
pushStdout.on("exit", (code: number) => Committer.logger(code, "git push"));
}
}

module.exports = Committer;
6 changes: 2 additions & 4 deletions DirectoryChecker.js → DirectoryChecker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { execSync } = require("child_process");

class DirectoryChecker {
static isExisted(directoryPath) {
export default class DirectoryChecker {
static isExisted(directoryPath: string): boolean {
const EXISTED = 1;

const dirs = directoryPath.split("/");
Expand All @@ -18,5 +18,3 @@ class DirectoryChecker {
return Number(stdout) == EXISTED;
}
}

module.exports = DirectoryChecker;
18 changes: 11 additions & 7 deletions FileMaker.js → FileMaker.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
// import fs from "fs";
const fs = require("fs");

class FileMaker {
static createFile = (name, path, format, content, callback) => {
const FILE_FORMAT_MAP = new Map()
export default class FileMaker {
static createFile = (
name: string,
path: string,
format: string,
content: string,
callback: () => void
) => {
const FILE_FORMAT_MAP: Map<string, string> = new Map()
.set("python", "py")
.set("javascript", "js")
.set("c", "c")
.set("cpp", "cpp");

const getFileFormat = (format) => {
const getFileFormat = (format: string) => {
return Boolean(FILE_FORMAT_MAP.get(format))
? FILE_FORMAT_MAP.get(format)
: "txt";
Expand All @@ -20,7 +26,7 @@ class FileMaker {
// return FILE_FORMAT_MAP.get(format) ?? "txt";
};

const errorCallback = (error) => {
const errorCallback = (error: Error) => {
if (error) throw error;
console.log("File is created successfully");
console.log("run callback func");
Expand All @@ -34,5 +40,3 @@ class FileMaker {
);
};
}

module.exports = FileMaker;
6 changes: 3 additions & 3 deletions index.js → index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const FileMaker = require("./FileMaker");
const DirectoryChecker = require("./DirectoryChecker");
const Committer = require("./Committer");
import FileMaker from "./FileMaker";
import DrirectoryChecker from "./DirectoryChecker";
import Committer from "./Committer";

// * FileMaker code

Expand Down

0 comments on commit 61b735a

Please sign in to comment.