示例#1
0
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();
      });
    });
  });
}
示例#2
0
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();
      }
    });
  });
}
示例#3
0
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;
}
示例#5
0
 .catch(ex => {
     if(ex.code === 'EMODNOTFOUND') {
         return fs.stat(targetPath);
     } else {
         return Promise.reject(ex);
     }
 })
示例#6
0
const isDir = async (dirPath) => {
  let stats
  try {
    stats = await fsp.stat(dirPath)
  } catch (err) {}
  return (stats != null && stats.isDirectory())
}
示例#7
0
 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);
 }));
示例#8
0
function isPath(path) {
  return getFileStats(path).then(function () {
    return true;
  }).catch(function () {
    return false;
  });
}
示例#9
0
      .then(exists => {
        if (!exists) {
          return false;
        }

        return fsp.stat(dest);
      })
示例#10
0
 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();
   });
 });
示例#11
0
 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
  }
}
示例#14
0
文件: tools.js 项目: diegoefe/tools
 return promiseChain.catch(function(){
     return fs.stat(path).then(function(stat){
         if(stat.isDirectory()){
             return path;
         }else{
             return Promises.reject('not dir');
         }
     });
 });
示例#15
0
文件: util.js 项目: qinhaojie/jestart
 return co(function * () {
   p = path.resolve(__dirname, p)
   try {
     yield fsp.stat(p)
     return true
   } catch (error) {
     return false
   }
 })
示例#16
0
文件: touteta.js 项目: leny/touteta
 .then( ( bExists ) => {
     if ( bExists ) {
         return fs.stat( sFolder )
             .then( ( oStat ) => {
                 return oStat.isDirectory();
             } );
     }
     return Promise.resolve( bExists );
 } )
示例#17
0
文件: survey.js 项目: Emapic/emapic
 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);
         }
     });
 });
示例#18
0
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]);
});
示例#19
0
		}).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 () {
示例#20
0
文件: touteta.js 项目: leny/touteta
 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 );
         }
     } );
 } );
示例#21
0
文件: mkdirs.js 项目: Kackey/felt
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)
})
示例#22
0
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}`);
    }
  }
};
示例#23
0
文件: getfx.js 项目: 1234-/loop
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);
  });
});
示例#24
0
  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);
    }
  }
}
示例#26
0
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;
}
示例#27
0
文件: spec.js 项目: cognitom/felt
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)
})
示例#28
0
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;
}
示例#29
0
文件: spec.js 项目: cognitom/felt
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)
})
示例#30
0
 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);
             }
         });
 },