本文整理匯總了TypeScript中fs-extra.rmdirSync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript rmdirSync函數的具體用法?TypeScript rmdirSync怎麽用?TypeScript rmdirSync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了rmdirSync函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: cleanupOldScreenshots
function* cleanupOldScreenshots() {
console.log("Cleaning up screenshots directory");
try {
fsa.emptyDirSync(SCREENSHOTS_DIRECTORY);
fsa.rmdirSync(SCREENSHOTS_DIRECTORY);
} catch(e) {
console.warn(`Cannot cleaup directory ${SCREENSHOTS_DIRECTORY}: `, e);
}
fsa.mkdirpSync(SCREENSHOTS_DIRECTORY);
}
示例2: function
var deleteFolderRecursive = function (path: string) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file: string, index: number) {
var curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}
示例3: deleteFolderRecursive
var deleteFolderRecursive = (folderpath: string) => {
if (fs.existsSync(folderpath)) {
fs.readdirSync(folderpath).forEach((file: string, index: number) => {
var curPath = path.join(folderpath, file);
if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}
示例4: emptyDirectory
fs.readdirSync(dirPath).forEach(file => {
const curPath = path.join(dirPath, file)
if (fs.lstatSync(curPath).isDirectory()) {
let removed = false
let i = 0 // retry counter
do {
try {
if (!opts.excludes.length || !opts.excludes.some(item => curPath.indexOf(item) >= 0)) {
emptyDirectory(curPath)
fs.rmdirSync(curPath)
}
removed = true
} catch (e) {
} finally {
if (++i < retries) {
continue
}
}
} while (!removed)
} else {
fs.unlinkSync(curPath)
}
})
示例5: if
//.........這裏部分代碼省略.........
await compileDepStyles(outputWXSSPath, item.styles)
resolve()
}, 300)
})
} else {
await compileDepStyles(outputWXSSPath, item.styles)
}
let modifyOutput = outputWXSSPath.replace(appPath + path.sep, '')
modifyOutput = modifyOutput.split(path.sep).join('/')
Util.printLog(processTypeEnum.GENERATE, '樣式文件', modifyOutput)
}))
} else {
let outputWXSSPath = filePath.replace(path.extname(filePath), outputFilesTypes.STYLE)
let modifySource = outputWXSSPath.replace(appPath + path.sep, '')
modifySource = modifySource.split(path.sep).join('/')
Util.printLog(processTypeEnum.MODIFY, '樣式文件', modifySource)
outputWXSSPath = outputWXSSPath.replace(sourceDir, outputDir)
if (isWindows) {
await new Promise((resolve, reject) => {
setTimeout(async () => {
await compileDepStyles(outputWXSSPath, [filePath])
resolve()
}, 300)
})
} else {
await compileDepStyles(outputWXSSPath, [filePath])
}
let modifyOutput = outputWXSSPath.replace(appPath + path.sep, '')
modifyOutput = modifyOutput.split(path.sep).join('/')
Util.printLog(processTypeEnum.GENERATE, '樣式文件', modifyOutput)
}
} else {
if (isCopyingFiles[outputFilePath]) return
isCopyingFiles[outputFilePath] = true
let modifyOutput = outputFilePath.replace(appPath + path.sep, '')
modifyOutput = modifyOutput.split(path.sep).join('/')
Util.printLog(processTypeEnum.COPY, '文件', modifyOutput)
if (!fs.existsSync(filePath)) {
let modifySrc = filePath.replace(appPath + path.sep, '')
modifySrc = modifySrc.split(path.sep).join('/')
Util.printLog(processTypeEnum.ERROR, '文件', `${modifySrc} 不存在`)
} else {
fs.ensureDir(path.dirname(outputFilePath))
if (filePath === outputFilePath) {
return
}
fs.copySync(filePath, outputFilePath)
}
}
// 如果 output/plugin 裏有新編譯出的文件,
// 先把 js 裏對 npm 的引用修改,然後把所有文件遷移到插件目錄
// 最後刪除 output/plugin
const names = glob.sync(`${outputDir}/${PLUGIN_ROOT}/**/*`)
if (names.length) {
const jsNames = glob.sync(`${outputDir}/${PLUGIN_ROOT}/{,!(npm)/**/}*.js`)
const ioPromises = jsNames.map(async name => {
const content = fs.readFileSync(name).toString()
let isShouldBeWritten
let replacement = content.replace(/['|"]((\.\.\/)+)npm\/.+?['|"]/g, (str, $1) => {
isShouldBeWritten = true
return $1 === '../' ? str.replace('../', './') : str.replace('../', '')
})
const REG_PLUGIN_DEPS = RegExp(`['|"](/${PLUGIN_ROOT}.+)['|"]`, 'g')
replacement = replacement.replace(REG_PLUGIN_DEPS, (str, $1) => {
if (REG_FONT.test($1) || REG_IMAGE.test($1) || REG_MEDIA.test($1)) {
return str.replace(RegExp(`^['|"]/${PLUGIN_ROOT}`, 'g'), str => str.replace(`${PLUGIN_ROOT}`, ''))
}
return str
})
if (isShouldBeWritten) await fs.writeFile(name, replacement)
})
await Promise.all(ioPromises)
await Promise.all(names.map(async from => {
if (fs.existsSync(from) && fs.statSync(from).isFile()) {
const to = from.replace(outputDir, appPath)
fs.ensureDirSync(path.dirname(to))
await fs.copyFile(from, to)
}
}))
const tempPluginPath = path.join(outputDir, PLUGIN_ROOT)
Util.emptyDirectory(tempPluginPath)
fs.rmdirSync(tempPluginPath)
}
// 遷移 npm 到 plugin 目錄
Util.emptyDirectory(path.join(pluginPath, NPM_DIR))
// fs.rmdirSync(tempPluginPath)
fs.copySync(path.join(outputDir, NPM_DIR), path.join(pluginPath, NPM_DIR))
initCompileScripts()
initCompileStyles()
isCopyingFiles = {}
})