-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: implement renameFiles as typescript, and update script accordi…
…ngly
- Loading branch information
1 parent
31c55fa
commit a8e836b
Showing
5 changed files
with
100 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
/** | ||
* 주어진 디렉토리에서 특정 확장자의 파일을 다른 확장자로 변경하는 함수 | ||
* @param directory - 파일이 있는 디렉토리 경로 | ||
* @param oldExt - 변경할 기존 파일 확장자 | ||
* @param newExt - 변경될 새로운 파일 확장자 | ||
*/ | ||
function renameFiles(directory, oldExt, newExt) { | ||
fs.readdir(directory, (err, files) => { | ||
if (err) throw err; | ||
|
||
files.forEach((file) => { | ||
if (path.extname(file) === oldExt) { | ||
const oldPath = path.join(directory, file); | ||
const newPath = path.join( | ||
directory, | ||
path.basename(file, oldExt) + newExt, | ||
); | ||
fs.rename(oldPath, newPath, (err) => { | ||
if (err) throw err; | ||
console.log(`Renamed: ${file} -> ${path.basename(newPath)}`); | ||
fs.readdir(directory, function (err, files) { | ||
if (err) | ||
throw err; | ||
files.forEach(function (file) { | ||
if (path.extname(file) === oldExt) { | ||
var oldPath = path.join(directory, file); | ||
var newPath_1 = path.join(directory, path.basename(file, oldExt) + newExt); | ||
fs.rename(oldPath, newPath_1, function (err) { | ||
if (err) | ||
throw err; | ||
console.log("Renamed: ".concat(file, " -> ").concat(path.basename(newPath_1))); // 변경된 파일 로그 출력 | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
// dist 디렉토리의 .js 파일을 .cjs 파일로 변경 | ||
renameFiles('./build/cjs', '.js', '.cjs'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
/** | ||
* 주어진 디렉토리에서 특정 확장자의 파일을 다른 확장자로 변경하는 함수 | ||
* @param directory - 파일이 있는 디렉토리 경로 | ||
* @param oldExt - 변경할 기존 파일 확장자 | ||
* @param newExt - 변경될 새로운 파일 확장자 | ||
*/ | ||
function renameFiles(directory: string, oldExt: string, newExt: string): void { | ||
fs.readdir(directory, (err, files) => { | ||
if (err) throw err; | ||
|
||
files.forEach((file) => { | ||
if (path.extname(file) === oldExt) { | ||
const oldPath = path.join(directory, file); | ||
const newPath = path.join( | ||
directory, | ||
path.basename(file, oldExt) + newExt, | ||
); | ||
fs.rename(oldPath, newPath, (err) => { | ||
if (err) throw err; | ||
console.log(`Renamed: ${file} -> ${path.basename(newPath)}`); // 변경된 파일 로그 출력 | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
// dist 디렉토리의 .js 파일을 .cjs 파일로 변경 | ||
renameFiles('./build/cjs', '.js', '.cjs'); |