function copy(src, dest, options) { options = options || {}; return Promise.all([ fsp.stat(src), fsp.exists(dest) .then(exists => { if (!exists) { return false; } return fsp.stat(dest); }) ]) .then(([srcStat, destStat]) => { if (srcStat.isFile() && destStat && destStat.isDirectory()) { let filename = path.basename(src); dest = path.join(dest, filename); } return new Promise((resolve, reject) => { fse.copy(src, dest, options, err => { if (err) { reject(err); } resolve(); }); }); }); }
export async function spawn(command, args, options = {}) { if (os.type() === 'Windows_NT') { try { // Prefer a cmd version if available const testCommand = `${command}.cmd`; const stats = await fs.stat(testCommand); if (stats.isFile()) { command = testCommand; } } catch (e) { // Ignore missing files. } } return new Promise((resolve, reject) => { const child = mz.child_process.spawn(command, args, options); child.on('error', reject); child.on('exit', (code) => { if (code !== 0) { reject(new Error(`Exited with exit code ${code}`)); } else { resolve(); } }); }); }
export async function buildFile(sourceFile, sourceStats) { let targetFile = getTargetPath(sourceFile); try { const targetStats = await fs.stat(targetFile); if (targetStats.mtime > sourceStats.mtime) { return; } } catch (e) { // The target may not exist. For whatever reason just go and try to build it } const extension = path.extname(sourceFile); if (extension === '.js' || extension === '.jsx') { const baseFile = targetFile.substring(0, targetFile.length - extension.length); targetFile = `${baseFile}.js`; const mapFile = `${baseFile}.map`; const results = await transpile(sourceFile, { sourceMaps: development, sourceFileName: fileUrl(sourceFile), }); if (development) { await fs.writeFile(mapFile, JSON.stringify(results.map)); // This must be an absolute URL since the devtools can't resolve relative // paths from node modules. results.code += `\n//# sourceMappingURL=${fileUrl(mapFile)}\n`; } await fs.writeFile(targetFile, results.code); } else { await fs.copy(sourceFile, targetFile); } }
export default async function install() { const thisProjectsGitFolder = path.resolve(path.join(__dirname, '../.git')); let gitPath = findParentFolder(__dirname, '.git'); if (thisProjectsGitFolder === gitPath) { return 0; } console.log('Installing JIRA pre-commit hook....'); try { gitPath = findParentFolder(__dirname, '.git'); } catch (error) { throw new Error('Your project needs a git repository to install the hook.'); } if ((await fsp.stat(gitPath)).isFile()) { console.log('Attempting install to git worktree, please install in the ' + 'primary worktree directory.'); return 0; } console.log(`Found .git directory at: ${gitPath}`); const hooksPath = path.join(gitPath, 'hooks'); verifyHooksFolder(hooksPath); await copyHookFiles(gitPath); console.log('Copied commit hook.'); return 0; }
.catch(ex => { if(ex.code === 'EMODNOTFOUND') { return fs.stat(targetPath); } else { return Promise.reject(ex); } })
const isDir = async (dirPath) => { let stats try { stats = await fsp.stat(dirPath) } catch (err) {} return (stats != null && stats.isDirectory()) }
it("breathing test", co.wrap(function *() { const first = yield TestUtil.makeTempDir(); const stat = yield fs.stat(first); assert(stat.isDirectory()); const second = yield TestUtil.makeTempDir(); assert.notEqual(first, second); }));
function isPath(path) { return getFileStats(path).then(function () { return true; }).catch(function () { return false; }); }
.then(exists => { if (!exists) { return false; } return fsp.stat(dest); })
exec("run", options, function(err, stdout, stderr) { expect(err).to.not.be.ok; fs.stat(path.join(paramDumpPath, "@param-dump.xpi")).then(function(stat) { expect(stat.size).to.be.equal(size); done(); }); });
function verifyInputs() { return fsp.stat(packagePath) .then(function(stats) { if (!stats.isDirectory()) { throw new Error(packagePath + " is not a directory"); } }); }
const files = await Promise.all((await fsp.readdir(dir)).map(async (file) => { const path = `${dir}/${file}`; const stat = await fsp.stat(path); if (stat.isDirectory()) return getFiles(path); if (excludedFiles.includes(file)) return null; if (!file.match(/.js$/)) return null; return path; }));
const fileExists = async (path) => { try { await fsp.stat(path) return true } catch (err) { return false } }
return promiseChain.catch(function(){ return fs.stat(path).then(function(stat){ if(stat.isDirectory()){ return path; }else{ return Promises.reject('not dir'); } }); });
return co(function * () { p = path.resolve(__dirname, p) try { yield fsp.stat(p) return true } catch (error) { return false } })
.then( ( bExists ) => { if ( bExists ) { return fs.stat( sFolder ) .then( ( oStat ) => { return oStat.isDirectory(); } ); } return Promise.resolve( bExists ); } )
return Promise.map(paths, function(path) { return fsp.stat(path).catch(function(error) { // We ignore the error when file doesn't exist }).then(function(stats) { if (stats && stats.isFile()) { return fsp.unlinkSync(path); } }); });
exports.executeableSubcommand = co.wrap(function *(args) { const colors = require("colors"); const fs = require("fs-promise"); const path = require("path"); const AddSubmodule = require("../util/add_submodule"); const GitUtil = require("../util/git_util"); const Hook = require("../util/hook"); const UserError = require("../util/user_error"); if (null !== args.branch && null === args.import_from) { throw new UserError(`Cannot use '-b' without '-i'.`); } const repo = yield GitUtil.getCurrentRepo(); // Bail if the path exists. let exists = false; try { yield fs.stat(path.join(repo.workdir(), args.path)); exists = true; } catch (e) { } if (exists) { throw new UserError(`\ The path ${colors.red(args.path)} already exists.`); } // Setup for an import if provided, default branch to 'master'. let importArg = null; if (null !== args.import_from) { importArg = { url: args.import_from, branch: (null === args.branch) ? "master" : args.branch, }; } // Generate the new submodule. yield AddSubmodule.addSubmodule(repo, args.url, args.path, importArg); // Warn the user to create commits or stage changes before committing. if (null === importArg) { console.log(`\ Added new sub-repo ${colors.blue(args.path)}. It is currently empty. Please stage changes under sub-repo before finishing with 'git meta commit'; you will not be able to use 'git meta commit' until you do so.`); } //Run post-add-submodule hook with submodule names which added successfully. yield Hook.execHook(repo, "post-add-submodule", [args.path]); });
}).then(function (result) { var actualCSS = result.css; fs.writeFileSync(actualPath, actualCSS); expect(actualCSS).to.eql(expectCSS); expect(result.warnings()).to.be.empty; return fs.stat(tempPath); }).then(function () {
return fCheckGit( sPath ).then( ( bIsGit ) => { if ( bIsGit ) { return fDisplayGitStatus( sPath ); } return fs.stat( sPath ).then( ( oStat ) => { if ( oStat.isDirectory() ) { return Promise.map( fGetSubPaths( sPath ), fCheckPath ); } } ); } );
module.exports = co.wrap(function* (dir) { try { const stats = yield fsp.stat(dir) if (stats.isDirectory()) return log.debug(`Deleting: ${ dir } (because it's not a directory)`) yield del(dir) } catch (err) { /* */ } log.debug(`Creating: ${ dir }`) yield fsp.mkdirs(dir) })
exports.expectReports = async function expectReports(reports) { for (const reportFile of reports) { try { debug(`checking for ${reportFile}`); await stat(reportFile); debug(`found ${reportFile}`); } catch (err) { throw new Error(`Could not find report ${reportFile}`); } } };
FxRunnerUtils.normalizeBinary(Commander.binary).then(function(binary) { Fs.stat(binary).then(function() { console.log(binary); }).catch(function(ex) { if (ex.code === "ENOENT") { console.error("Could not find " + binary); } else { console.error(ex); } process.exit(1); }); });
return Promise.resolve(x).then(something => { if( isResource(something) ) return Promise.resolve(something); if( typeof something === 'string' ) { if( path.basename(something) === '.oathframe.json' ) return resolve(path.dirname(something)); return fs.stat(something).then(stat => (stat.isDirectory() ? createDirectory : createFile)(something)); } throw new Error('Resource: not sure how to resolve ' + something); });
async function rm(filepath) { if (await fs.exists(filepath)) { if ((await fs.stat(filepath)).isDirectory()) { await Promise.all( (await fs.readdir(filepath)) .map(item => rm(path.resolve(filepath, item))) ); await fs.rmdir(filepath); } else { await fs.unlink(filepath); } } }
async function getTemplateDirForRepo(owner, repo) { try { const templates = path.join(TEMPLATE_BASE, owner, repo); const stats = await fs.stat(templates); if (stats.isDirectory()) { return templates; } } catch (e) { // If we can't access a path then it isn't the right directory. } try { const templates = path.join(TEMPLATE_BASE, owner); const stats = await fs.stat(templates); if (stats.isDirectory()) { return templates; } } catch (e) { // If we can't access a path then it isn't the right directory. } return TEMPLATE_BASE; }
test('makes dir at empty', async function(t) { const dir = path.join(__dirname, 'mkdirs-test') await mkdirs(dir) let dirCreated = false try { const stats = await fsp.stat(dir) if (stats.isDirectory()) dirCreated = true } catch (err) { /* */ } t.true(dirCreated) await del(dir) })
export async function normalizeCommand(command) { if (os.type() === 'Windows_NT') { try { // Prefer a cmd version if available const testCommand = `${command}.cmd`; const stats = await fs.stat(testCommand); if (stats.isFile()) { command = testCommand; } } catch (e) { // Ignore missing files. } } return command; }
test('makes dir but already file exists', async function(t) { const dir = path.join(__dirname, 'mkdirs-test2') await fsp.writeFile(dir, 'Hi!') await mkdirs(dir) let dirCreated = false try { const stats = await fsp.stat(dir) if (stats.isDirectory()) dirCreated = true } catch (err) { /* */ } t.true(dirCreated) await del(dir) })
checkModuleStructure: function(modulePath, name) { return fs.stat(modulePath) .catch(ex => { if(ex.code === 'ENOENT') { logger.warning(`${name}: Exists on index, but not on fs. Purging...`); return db.ModuleMeta.remove({ name: name }) .then(() => { var error = new Error('Invalid module structure.'); error.code = 'EINVALIDMODSTRUCTURE'; error.giskInternal = true; return Promise.reject(error); }); } else { logger.error(`${name}: ::checkModuleStructure: Unexpected error.`); logger.error(ex); return Promise.reject(ex); } }); },