xe-utils-es
Version:
JavaScript 函数库、工具类
27 lines (23 loc) • 878 B
text/typescript
import { readFile, readdir, rename, writeFile } from 'node:fs/promises'
import { join } from 'node:path'
async function jstots() {
const res = await readdir('src')
for (let index = 0; index < res.length; index++) {
const name = res[index]
const targetname = join('target', `${name.slice(0, -3)}.ts`)
await rename(join('src', name), targetname)
console.log(targetname)
}
}
async function removeImportJs() {
const res = await readdir('src')
for (let index = 0; index < res.length; index++) {
const name = res[index]
const targetname = join('target', `${name.slice(0, -3)}.ts`)
const jsSourceStr = await readFile(join('src', name), { encoding: 'utf-8' })
const transSourceStr = jsSourceStr.replaceAll('.js', '')
await writeFile(targetname, transSourceStr)
console.log(targetname)
}
}
removeImportJs()