當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。