From 61b735a0eb64b4768ad4b1c9c451788669069674 Mon Sep 17 00:00:00 2001 From: zwonlala Date: Sat, 18 Sep 2021 17:28:19 +0900 Subject: [PATCH] =?UTF-8?q?#8=20=EA=B8=B0=EC=A1=B4=20js=EB=A1=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=ED=95=9C=20=ED=8C=8C=EC=9D=BC=EB=93=A4=20ts?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 함수에 파라미터 타입과 리턴 타입 지정 --- Committer.js => Committer.ts | 24 +++++++++++----------- DirectoryChecker.js => DirectoryChecker.ts | 6 ++---- FileMaker.js => FileMaker.ts | 18 +++++++++------- index.js => index.ts | 6 +++--- 4 files changed, 28 insertions(+), 26 deletions(-) rename Committer.js => Committer.ts (62%) rename DirectoryChecker.js => DirectoryChecker.ts (85%) rename FileMaker.js => FileMaker.ts (68%) rename index.js => index.ts (91%) diff --git a/Committer.js b/Committer.ts similarity index 62% rename from Committer.js rename to Committer.ts index 9780925..ff0d754 100644 --- a/Committer.js +++ b/Committer.ts @@ -1,13 +1,13 @@ 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_ @@ -15,34 +15,34 @@ class Committer { //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; diff --git a/DirectoryChecker.js b/DirectoryChecker.ts similarity index 85% rename from DirectoryChecker.js rename to DirectoryChecker.ts index 47ac81e..1593b75 100644 --- a/DirectoryChecker.js +++ b/DirectoryChecker.ts @@ -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("/"); @@ -18,5 +18,3 @@ class DirectoryChecker { return Number(stdout) == EXISTED; } } - -module.exports = DirectoryChecker; diff --git a/FileMaker.js b/FileMaker.ts similarity index 68% rename from FileMaker.js rename to FileMaker.ts index d7463eb..cc92d65 100644 --- a/FileMaker.js +++ b/FileMaker.ts @@ -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 = 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"; @@ -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"); @@ -34,5 +40,3 @@ class FileMaker { ); }; } - -module.exports = FileMaker; diff --git a/index.js b/index.ts similarity index 91% rename from index.js rename to index.ts index 9f9a325..2ade3f4 100644 --- a/index.js +++ b/index.ts @@ -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