本文整理匯總了TypeScript中fs-extra.stat函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript stat函數的具體用法?TypeScript stat怎麽用?TypeScript stat使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了stat函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: determineConfigFilename
export async function determineConfigFilename(
cmdLineArgs: CliArgTypes
): Promise<string> {
if (cmdLineArgs.config == null) {
try {
await fs.stat('text-run.yml')
return 'text-run.yml'
} catch (e) {
return ''
}
}
// TODO: move this to the top of the method
try {
await fs.stat(cmdLineArgs.config)
return cmdLineArgs.config
} catch (e) {
console.log(
chalk.red(
`configuration file ${chalk.cyan(cmdLineArgs.config)} not found`
)
)
throw new PrintedUserError()
}
}
示例2: withAfterEach
withAfterEach(async t => {
shell.cd('test/assets');
shell.ln('-s', 'foo.txt', 'bar.txt');
shell.cd('../..');
const { stderr } = shell.exec('node dist/src/cp-cli -d test/assets out');
t.equal(stderr, '');
let stats = await fse.stat('out/foo.txt');
t.true(stats.isFile());
stats = await fse.stat('out/bar.txt');
t.true(stats.isFile());
t.false(stats.isSymbolicLink());
}),
示例3: checkLocalImage
async function checkLocalImage(imagePath: string, c: Configuration) {
try {
await fs.stat(path.join(c.sourceDir, imagePath))
} catch (err) {
throw new Error(`image ${chalk.red(imagePath)} does not exist`)
}
}
示例4: buildInlineLambda
export function buildInlineLambda({
path: inputPath,
name,
options,
parameters,
}: any) {
name = name ? name : defaultConfig.FunctionName;
options = options ? merge({}, defaultConfig, options) : defaultConfig;
inputPath = resolve(inputPath);
return stat(inputPath).then(rstat => {
if (rstat.isFile()) {
return _createInlineFunction({
name,
options,
parameters,
path: inputPath,
});
} else {
const indexPath = resolve(inputPath, 'index.js');
return stat(indexPath).then(statIndex => {
return _createInlineFunction({
name,
options,
parameters,
path: indexPath,
});
});
}
});
}
示例5: clearNodeModules
async function clearNodeModules(): Promise<void> {
const logger = getLogger();
if (isRsyncModeEnabled) {
return;
}
logger.trace(`moving node_modules to node_modules.bak.0`);
let bodyCount = 0;
let bakDirname;
while (true) {
bakDirname = `${nodeModules}.bak.${bodyCount}`;
logger.trace(`moving node_modules to ${bakDirname}`);
try {
await fsExtra.stat(bakDirname);
logger.trace(`${bakDirname} already exists; incrementing`);
bodyCount++;
} catch (err) {
if (err.code && err.code === 'ENOENT') {
await fsExtra.rename(nodeModules, bakDirname);
logger.trace(`move was successful; removing ${bakDirname} without blocking`);
return fsExtra.remove(bakDirname);
}
}
}
}
示例6: stat
export async function stat(p: string): Promise<fs.Stats | undefined> {
try {
return await fs.stat(p);
} catch (e) {
// ignore
}
}
示例7: remove
export function remove(path: string, callback: (err?: Error) => void) {
fs.stat(path, function (err, stats) {
if (err) {
return callback(err);
}
fs.remove(path, callback);
});
}
示例8: Then
Then('there is no {string} folder', async function(name) {
try {
await fs.stat(path.join(this.rootDir, name))
} catch (e) {
return
}
throw new Error(`Expected folder ${name} to not be there, but it is`)
})
示例9: hasDirectory
export async function hasDirectory(dirname: string): Promise<boolean> {
try {
const stats = await fs.stat(dirname)
return stats.isDirectory()
} catch (e) {
return false
}
}
示例10: fileExists
export async function fileExists(fileName: string): Promise<boolean> {
try {
const stat = await fs.stat(fileName);
return stat.isFile();
} catch {
return false;
}
}