本文整理汇总了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);
}
};
开发者ID:accosine,项目名称:poltergeist,代码行数:29,代码来源:upload.ts
示例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));
}
});
开发者ID:ehanlon,项目名称:azure-managed-automate,代码行数:8,代码来源:deploy.ts
示例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);
}
});
开发者ID:nodulusteam,项目名称:-nodulus-modules,代码行数:8,代码来源:utility.ts
示例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;
}
}
开发者ID:gluons,项目名称:ConfC,代码行数:15,代码来源:isSymlink.ts
示例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);
}
});
开发者ID:gitter-badger,项目名称:nodulus,代码行数:8,代码来源:modules.ts
示例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
}
}
}
}
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:50,代码来源:helper.ts
示例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')
}
开发者ID:ahmb84,项目名称:prisma,代码行数:19,代码来源:Importer.ts
示例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)
}
})
开发者ID:YangShaoQun,项目名称:taro,代码行数:23,代码来源:index.ts
示例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);
}
}
开发者ID:ehanlon,项目名称:azure-managed-automate,代码行数:63,代码来源:deploy.ts
示例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
}
}
}
}
}
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:101,代码来源:astProcess.ts
注:本文中的fs-extra.lstatSync函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论