当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript node-file-exists.default函数代码示例

本文整理汇总了TypeScript中node-file-exists.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: readFile

export default function readFile(dir: string, file: string): Object|boolean {
  const pathToFile = join(dir, file);
  if (!fileExists(pathToFile)) { return false; }
  try {
    return JSON.parse(readFileSync(pathToFile, 'utf8'));
  } catch (e) {
    return null;
  }
}
开发者ID:coderoad,项目名称:builder-coderoad,代码行数:9,代码来源:readFile.ts

示例2: commandLine

export default function commandLine(root: string,
  commands?: string): Promise<string> {

  // use root path for mac/linux (usr/local/bin, usr/bin), or windows (root)
  if (process.platform === 'darwin' && process.resourcesPath) {
    const localPath = '/usr/local/bin/' + root;
    const globalPath = '/usr/bin/' + root;
    if (fileExists(localPath)) {
      root = localPath;
    } else if (fileExists(globalPath)) {
      root = globalPath;
    } else {
      throw root + ' not found.';
    }
  }

  const run = exec(`${root}${commands ? ' ' + commands : ''}`);

  return new Promise((resolve, reject) => {
    run.stdout.on('data', data => resolve(data));
    run.stderr.on('data', data => reject(data));
  });
}
开发者ID:ShMcK,项目名称:atom-plugin-command-line,代码行数:23,代码来源:index.ts

示例3: configRunner

export default function configRunner(name: string, runner: string, dir: string): () => any {
  // test runner dir
  let flatDep = join(
    dir, 'node_modules', runner, 'package.json'
  );
  let treeDep = join(
    dir, 'node_modules', name, 'node_modules', runner, 'package.json'
  );

  let runnerMain;
  let runnerRoot;
  if (fileExists(flatDep)) {
    runnerMain = require(flatDep).main;
    runnerRoot = flatDep;
  } else if (fileExists(treeDep)) {
    runnerMain = require(treeDep).main;
    runnerRoot = treeDep;
  } else {
    let message = 'Error loading test runner. Post an issue. https://github.com/coderoad/atom-coderoad/issues';
    console.log(message);
    throw message;
  }

  // fix main path for Windows
  let slash = isWindows ? '\\' : '/';
  runnerMain = join.apply(null, runnerMain.split(slash));
  // trim root path to folder
  runnerRoot = runnerRoot.substring(0, runnerRoot.lastIndexOf(slash));

  let pathToMain = join(runnerRoot, runnerMain);

  if (!!require(pathToMain).default) {
    return require(pathToMain).default;
  } else {
    return require(pathToMain);
  }
}
开发者ID:excalliburbd,项目名称:atom-coderoad,代码行数:37,代码来源:config-runner.ts

示例4: packageJson

export default function packageJson(
  pj = null, action: Action
): PackageJson {
  switch (action.type) {

    case SETUP_PACKAGE:
      const pathToPackageJson = join(action.payload.dir, 'package.json');
      return fileExists(pathToPackageJson)
        ? readParse(pathToPackageJson)
        : null;

    default:
      return pj;
  }
}
开发者ID:excalliburbd,项目名称:atom-coderoad,代码行数:15,代码来源:index.ts

示例5: loadRunner

export default function loadRunner(dir: string, name: string) {
  const packagePath = join(dir, 'node_modules', name);
  // no runner installed
  if (!fileExists(packagePath)) {
    return noRunner;
  }
  let runner;
  try {
    const pj = join(packagePath, 'package.json');
    const runnerMain = require(pj).main;
    let pathToMain = resolve(packagePath, runnerMain);
    runner = require(pathToMain);
  } catch (e) {
    console.log(e);
  }
  return runner ? runner.default : noRunner;
}
开发者ID:coderoad,项目名称:builder-coderoad,代码行数:17,代码来源:loadRunner.ts

示例6: packageJson

export default function packageJson(
  pj = null, action: Action
): PackageJson {
  switch (action.type) {

    case 'SETUP_PACKAGE':
      const {dir} = action.payload;
      const pathToPackageJson = join(dir, 'package.json');
      if (fileExists(pathToPackageJson)) {
        return JSON.parse(readFileSync(pathToPackageJson, 'utf8'));
      }
      return null;

    default:
      return pj;
  }
}
开发者ID:lixonics,项目名称:atom-coderoad,代码行数:17,代码来源:index.ts

示例7: join

 folders.forEach(x => {
   current.push(x);
   const folderPath = join(dir, current.join('/'));
   if (!fileExists(folderPath)) {
     mkdirSync(folderPath);
   }
 });
开发者ID:coderoad,项目名称:builder-coderoad,代码行数:7,代码来源:writeFile.ts

示例8: join

      .map(function(name: string) {
        const pathToTutorialPackageJson = join(
          dir, 'node_modules', name, 'package.json'
        );
        // no package.json
        if (!fileExists(pathToTutorialPackageJson)) {
          console.log(
            `Error with ${name}: no package.json file found. ${tutorialError}`
          );
          return {
            name,
            version: 'NOT INSTALLED'
          };
        }

        let tutorialPackageJson = JSON.parse(
          readFileSync(pathToTutorialPackageJson, 'utf8')
        );
        const version = tutorialPackageJson.version;

        return {
          name,
          version,
          latest: !!canUpdateTutorial(name, version)
        };
      }));
开发者ID:lixonics,项目名称:atom-coderoad,代码行数:26,代码来源:check.ts

示例9: Promise

 return new Promise((resolve, reject) => {
   // delete file first, to avoid bug
   if (fileExists(file)) {
     unlink(file);
   }
   // delay necessary since opening a file is slow
   const openTimeout = 200;
   atom.workspace.open(file, options);
   setTimeout(() => resolve(), openTimeout);
 });
开发者ID:lixonics,项目名称:atom-coderoad,代码行数:10,代码来源:file.ts

示例10: isTutorial

export function isTutorial(dir: string, name: string): boolean {
  // has package.json
  const pathToTutorialPackageJson = join(
    dir, 'node_modules', name, 'package.json'
  );
  if (!fileExists(pathToTutorialPackageJson)) {
    console.log(`Error with ${name}: no package.json file found. ${tutorialError}`);
    return false;
  }
  // main path to coderoad.json
  let packageJson = JSON.parse(readFileSync(pathToTutorialPackageJson, 'utf8'));
  if (!packageJson.main && packageJson.main.match(/coderoad.json$/)) {
    console.log(`Error with ${name}: main does not load a coderoad.json file. ${tutorialError}`);
    return false;
  }
  // coderoad.json file exists
  let pathToCoderoadJson = join(
    dir, 'node_modules', name, packageJson.main
  );
  if (!fileExists(pathToCoderoadJson)) {
    console.log(`Error with ${name}: no coderoad.json file. ${tutorialError}`);
    return false;
  };
  if (!packageJson.config || !packageJson.config.runner) {
    console.log(`Error with ${name}: no test runner specified. ${tutorialError}`);
    return false;
  }

  // let currentTutorialVersion: string = packageJson.dependencies[name] || packageJson.devDependencies[name];
  // canUpdateTutorial(name, currentTutorialVersion);

  // let pathToTestRunner = path.join(dir, 'node_modules', packageJson.config.testRunner);
  // // if (!fileExists(pathToTestRunner)) {
  // //   console.log(`Error with ${name}: ${packageJson.config.testRunner} test runner not installed`);
  // //   return false;
  // // }
  return true;
}
开发者ID:lixonics,项目名称:atom-coderoad,代码行数:38,代码来源:is-tutorial.ts


注:本文中的node-file-exists.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。