本文整理匯總了TypeScript中fs-extra.lstatSync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript lstatSync函數的具體用法?TypeScript lstatSync怎麽用?TypeScript lstatSync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了lstatSync函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: async
export default async (foldername: string): Promise<void> => {
if (!existsSync(resolveApp(foldername))) {
console.log('No such file or directory.');
return;
}
const isDirectory = lstatSync(resolveApp(foldername)).isDirectory();
console.log(' - now uploading');
//TODO: progress bar for uploads
try {
const projectId = await getProjectId();
await initializeAndEnsureAuth(projectId);
if (isDirectory) {
getShallowFiles(resolveApp(foldername)).forEach(async file => {
try {
await uploadFile(projectId, file);
} catch (error) {
console.log(file, error);
}
});
} else {
await uploadFile(projectId, resolveApp(foldername));
}
} catch (error) {
console.log(error);
}
};
示例2: lstatSync
files.forEach((file) => {
stats = lstatSync(pathJoin(path, file));
if (stats.isDirectory()) {
list = list.concat(listdir(pathJoin(path, file)));
} else {
list.push(pathJoin(path, file));
}
});
示例3:
fs.readdirSync(folderpath).forEach((file: string, index: number) => {
var curPath = path.join(folderpath, file);
if (fs.lstatSync(curPath).isDirectory()) { // recurse
this.deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
示例4: isSymlink
/**
* Check if a given path is symlink.
*
* @export
* @param {string} path File path.
* @returns {boolean}
*/
export default function isSymlink(path: string): boolean {
if (existsSync(path)) {
let stats = lstatSync(path);
return stats.isSymbolicLink();
} else {
return false;
}
}
示例5: deleteFolderRecursive
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);
}
});
示例6: analyzeImportUrl
export function analyzeImportUrl (
sourceFilePath: string,
scriptFiles: Set<string>,
source: t.StringLiteral,
value: string
) {
const valueExtname = path.extname(value)
if (path.isAbsolute(value)) {
printLog(processTypeEnum.ERROR, '引用文件', `文件 ${sourceFilePath} 中引用 ${value} 是絕對路徑!`)
return
}
if (value.indexOf('.') === 0) {
if (REG_SCRIPT.test(valueExtname) || REG_TYPESCRIPT.test(valueExtname)) {
const vpath = path.resolve(sourceFilePath, '..', value)
let fPath = value
if (fs.existsSync(vpath)) {
fPath = vpath
} else {
printLog(processTypeEnum.ERROR, '引用文件', `文件 ${sourceFilePath} 中引用 ${value} 不存在!`)
}
scriptFiles.add(fPath)
} else {
let vpath = resolveScriptPath(path.resolve(sourceFilePath, '..', value))
if (vpath) {
if (!fs.existsSync(vpath)) {
printLog(processTypeEnum.ERROR, '引用文件', `文件 ${sourceFilePath} 中引用 ${value} 不存在!`)
} else {
if (fs.lstatSync(vpath).isDirectory()) {
if (fs.existsSync(path.join(vpath, 'index.js'))) {
vpath = path.join(vpath, 'index.js')
} else {
printLog(processTypeEnum.ERROR, '引用目錄', `文件 ${sourceFilePath} 中引用了目錄 ${value}!`)
return
}
}
let relativePath = path.relative(sourceFilePath, vpath)
const relativePathExtname = path.extname(relativePath)
scriptFiles.add(vpath)
relativePath = promoteRelativePath(relativePath)
if (/\.wxs/.test(relativePathExtname)) {
relativePath += '.js'
} else {
relativePath = relativePath.replace(relativePathExtname, '.js')
}
source.value = relativePath
}
}
}
}
}
示例7: constructor
constructor(
importPath: string,
types: string,
client: Client,
out: Output,
config: Config,
) {
if (!fs.pathExistsSync(importPath)) {
throw new Error(`Import path ${importPath} does not exist`)
}
this.config = config
this.importPath = importPath
this.isDir = fs.lstatSync(importPath).isDirectory()
this.importDir = this.isDir ? importPath : path.join(config.cwd, '.import/')
this.client = client
this.types = types
this.out = out
this.statePath = path.join(this.importDir, 'state.json')
}
示例8: 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)
}
})
示例9: upload
async function upload(config, subscription) {
// create the necessary storage client
let smClient = get_client(config[optionsKey][authFileKey], subscription, "storage");
let rmClient = get_client(config[optionsKey][authFileKey], subscription, "resource");
// Perform some checks to ensure that all necessary resources exist
// - resource group
let rgExists = await rmClient.resourceGroups.checkExistence(config[storageAccountKey][groupNameKey]);
// - storage account
let saExists = await checkStorageAccountExists(smClient, config[storageAccountKey][storageAccountNameKey]);
// - container
let containerExists = await checkContainerExists(smClient, config[storageAccountKey][groupNameKey], config[storageAccountKey][storageAccountNameKey], config[storageAccountKey][containerNameKey]);
// determine if the credentials file can be located
if (rgExists && saExists && containerExists) {
// create blob service so that files can be uploaded
let sakeys = await smClient.storageAccounts.listKeys(config[storageAccountKey][groupNameKey], config[storageAccountKey][storageAccountNameKey], {});
let blobService = createBlobService(config[storageAccountKey][storageAccountNameKey], sakeys.keys[0].value);
// get all the files in the specified directory to be uploaded
let items = listdir(config[dirsKey][workingKey]);
// iterate around all the files
let stats;
let name;
for (let item of items) {
// continue onto the next item if this is is a directory
stats = lstatSync(item);
if (stats.isDirectory()) {
continue;
}
// the item is a file
name = item.replace(/\\/g, "/");
// create the correct name for the blob
let stringToCheck = config[dirsKey][workingKey].replace(/\\/g, "/");
if (stringToCheck.endsWith("/") === false) {
stringToCheck += "/";
}
name = name.replace(stringToCheck, "");
// upload the item
blobService.createBlockBlobFromLocalFile(config[storageAccountKey][containerNameKey], name, item, {}, (error, result) => {
if (error) {
console.log("FAILED to upload: %s", getError(error));
} else {
console.log("SUCCESS upload file: %s", item);
}
});
}
} else {
console.error("Resource Group \"%s\" exists: %s", config[storageAccountKey][groupNameKey], rgExists);
console.error("Storage Account \"%s\" exists: %s", config[storageAccountKey][storageAccountNameKey], saExists);
console.error("Container \"%s\" exists: %s", config[storageAccountKey][containerNameKey], containerExists);
console.error("Errors have occurred, please ensure that all the above resources exist");
process.exit(4);
}
}
示例10: analyzeImportUrl
//.........這裏部分代碼省略.........
const vpath = path.resolve(sourceFilePath, '..', value)
let fPath = value
if (fs.existsSync(vpath) && vpath !== sourceFilePath) {
fPath = vpath
}
if (scriptFiles.indexOf(fPath) < 0) {
scriptFiles.push(fPath)
}
} else if (REG_JSON.test(valueExtname)) {
const vpath = path.resolve(sourceFilePath, '..', value)
if (jsonFiles.indexOf(vpath) < 0) {
jsonFiles.push(vpath)
}
if (fs.existsSync(vpath)) {
const obj = JSON.parse(fs.readFileSync(vpath).toString())
const specifiers = node.specifiers
let defaultSpecifier = null
specifiers.forEach(item => {
if (item.type === 'ImportDefaultSpecifier') {
defaultSpecifier = item.local.name
}
})
if (defaultSpecifier) {
let objArr: t.NullLiteral | t.Expression = t.nullLiteral()
if (Array.isArray(obj)) {
objArr = t.arrayExpression(convertArrayToAstExpression(obj))
} else {
objArr = t.objectExpression(convertObjectToAstExpression(obj))
}
astPath.replaceWith(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(defaultSpecifier), objArr)]))
}
}
} else if (REG_FONT.test(valueExtname) || REG_IMAGE.test(valueExtname) || REG_MEDIA.test(valueExtname)) {
const vpath = path.resolve(sourceFilePath, '..', value)
if (!fs.existsSync(vpath)) {
printLog(processTypeEnum.ERROR, '引用文件', `文件 ${sourceFilePath} 中引用 ${value} 不存在!`)
return
}
if (mediaFiles.indexOf(vpath) < 0) {
mediaFiles.push(vpath)
}
const specifiers = node.specifiers
let defaultSpecifier = null
specifiers.forEach(item => {
if (item.type === 'ImportDefaultSpecifier') {
defaultSpecifier = item.local.name
}
})
let showPath
if (NODE_MODULES_REG.test(vpath)) {
showPath = vpath.replace(nodeModulesPath, `/${npmConfig.name}`)
} else {
showPath = vpath.replace(sourceDir, '')
}
if (defaultSpecifier) {
astPath.replaceWith(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(defaultSpecifier), t.stringLiteral(showPath.replace(/\\/g, '/')))]))
} else {
astPath.remove()
}
} else if (REG_STYLE.test(valueExtname)) {
const stylePath = path.resolve(path.dirname(sourceFilePath), value)
if (styleFiles.indexOf(stylePath) < 0) {
styleFiles.push(stylePath)
}
astPath.remove()
} else {
let vpath = resolveScriptPath(path.resolve(sourceFilePath, '..', value))
let outputVpath
if (NODE_MODULES_REG.test(vpath)) {
outputVpath = vpath.replace(nodeModulesPath, npmOutputDir)
} else {
outputVpath = vpath.replace(sourceDir, outputDir)
}
let relativePath = path.relative(filePath, outputVpath)
if (vpath && vpath !== sourceFilePath) {
if (!fs.existsSync(vpath)) {
printLog(processTypeEnum.ERROR, '引用文件', `文件 ${sourceFilePath} 中引用 ${value} 不存在!`)
} else {
if (fs.lstatSync(vpath).isDirectory()) {
if (fs.existsSync(path.join(vpath, 'index.js'))) {
vpath = path.join(vpath, 'index.js')
relativePath = path.join(relativePath, 'index.js')
} else {
printLog(processTypeEnum.ERROR, '引用目錄', `文件 ${sourceFilePath} 中引用了目錄 ${value}!`)
return
}
}
if (scriptFiles.indexOf(vpath) < 0) {
scriptFiles.push(vpath)
}
relativePath = promoteRelativePath(relativePath)
relativePath = relativePath.replace(path.extname(relativePath), '.js')
node.source.value = relativePath
}
}
}
}
}
}