• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript utils-fs.pathExists函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: run

  async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
    const { getGeneratedPrivateKeyPath } = await import('../../lib/ssh');

    const { bits, annotation } = options;

    const keyPath = inputs[0] ? expandPath(String(inputs[0])) : await getGeneratedPrivateKeyPath(this.env.config.get('user.id'));
    const keyPathDir = path.dirname(keyPath);
    const pubkeyPath = `${keyPath}.pub`;

    if (!(await pathExists(keyPathDir))) {
      await mkdirp(keyPathDir, 0o700 as any); // tslint:disable-line
      this.env.log.msg(`Created ${strong(prettyPath(keyPathDir))} directory for you.`);
    }

    if (await pathExists(keyPath)) {
      const confirm = await this.env.prompt({
        type: 'confirm',
        name: 'confirm',
        message: `Key ${strong(prettyPath(keyPath))} exists. Overwrite?`,
      });

      if (confirm) {
        await unlink(keyPath);
      } else {
        this.env.log.msg(`Not overwriting ${strong(prettyPath(keyPath))}.`);
        return;
      }
    }

    this.env.log.info(
      'Enter a passphrase for your private key.\n' +
      `You will be prompted to provide a ${strong('passphrase')}, which is used to protect your private key should you lose it. (If someone has your private key, they can impersonate you!) Passphrases are recommended, but not required.\n`
    );

    const shellOptions = { stdio: 'inherit', showCommand: false, showError: false };
    await this.env.shell.run('ssh-keygen', ['-q', '-t', String(options['type']), '-b', String(bits), '-C', String(annotation), '-f', keyPath], shellOptions);

    this.env.log.nl();

    this.env.log.rawmsg(
      `Private Key (${strong(prettyPath(keyPath))}): Keep this safe!\n` +
      `Public Key (${strong(prettyPath(pubkeyPath))}): Give this to all your friends!\n\n`
    );

    this.env.log.ok('A new pair of SSH keys has been generated!');
    this.env.log.nl();

    this.env.log.msg(
      `${strong('Next steps:')}\n` +
      ` * Add your public key to Ionic: ${input('ionic ssh add ' + prettyPath(pubkeyPath))}\n` +
      ` * Use your private key for secure communication with Ionic: ${input('ionic ssh use ' + prettyPath(keyPath))}`
    );
  }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:53,代码来源:generate.ts


示例2: preRunChecks

  protected async preRunChecks(runinfo: CommandInstanceInfo) {
    if (!this.project) {
      throw new FatalException('Cannot use Cordova outside a project directory.');
    }

    const { loadConfigXml } = await import('../../lib/integrations/cordova/config');

    await this.checkCordova(runinfo);

    // Check for www folder
    if (this.project.directory) {
      const wwwPath = path.join(this.integration.root, 'www');
      const wwwExists = await pathExists(wwwPath); // TODO: hard-coded

      if (!wwwExists) {
        const tasks = this.createTaskChain();

        tasks.next(`Creating ${strong(prettyPath(wwwPath))} directory for you`);
        await mkdirp(wwwPath);
        tasks.end();
      }
    }

    const conf = await loadConfigXml(this.integration);
    conf.resetContentSrc();
    await conf.save();
  }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:27,代码来源:base.ts


示例3: async

  const serveCordovaPlatformResource = async (req: Request, res: Response, next: NextFunction) => {
    if (options.engine !== 'cordova' || !options.platform) {
      return next();
    }

    const resourcePath = path.resolve('platforms', options.platform, 'platform_www');

    if (await pathExists(path.join(resourcePath, req.url))) {
      res.sendFile(req.url, { root: resourcePath });
    } else {
      next();
    }
  };
开发者ID:driftyco,项目名称:ionic-cli,代码行数:13,代码来源:serve.ts


示例4: checkExistingFile

  private async checkExistingFile(p: string): Promise<boolean | undefined> {
    if (await pathExists(p)) {
      const confirm = await this.env.prompt({
        type: 'confirm',
        name: 'confirm',
        message: `Key ${strong(prettyPath(p))} exists. Overwrite?`,
      });

      if (confirm) {
        return true;
      } else {
        throw new FatalException(`Not overwriting ${strong(prettyPath(p))}.`);
      }
    }
  }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:15,代码来源:generate.ts


示例5: run

  async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
    const { loadConfigXml } = await import('../../lib/integrations/cordova/config');

    if (!this.project) {
      throw new FatalException(`Cannot run ${input('ionic monitoring syncmaps')} outside a project directory.`);
    }

    const token = this.env.session.getUserToken();
    const appflowId = await this.project.requireAppflowId();

    const [ snapshotId ] = inputs;
    const doBuild = options.build ? true : false;

    const cordova = this.project.requireIntegration('cordova');
    const conf = await loadConfigXml(cordova);
    const cordovaInfo = conf.getProjectInfo();

    const appVersion = cordovaInfo.version;
    const commitHash = (await this.env.shell.output('git', ['rev-parse', 'HEAD'], { cwd: this.project.directory })).trim();
    debug(`Commit hash: ${strong(commitHash)}`);

    const sourcemapsDir = path.resolve(this.project.directory, SOURCEMAP_DIRECTORY);
    let sourcemapsExist = await pathExists(sourcemapsDir);

    if (doBuild || !sourcemapsExist) {
      // TODO: use runner directly
      await build({ config: this.env.config, log: this.env.log, shell: this.env.shell, prompt: this.env.prompt, project: this.project }, [], { _: [], prod: true });
    }

    sourcemapsExist = await pathExists(sourcemapsDir);

    if (sourcemapsExist) {
      this.env.log.msg(`Using existing sourcemaps in ${strong(prettyPath(sourcemapsDir))}`);
    } else { // TODO: this is hard-coded for ionic-angular, make it work for all project types
      throw new FatalException(
        `Cannot find directory: ${strong(prettyPath(sourcemapsDir))}.\n` +
        `Make sure you have the latest ${strong('@ionic/app-scripts')}. Then, re-run this command.`
      );
    }

    let count = 0;
    const tasks = this.createTaskChain();
    const syncTask = tasks.next('Syncing sourcemaps');

    const sourcemapFiles = (await readdirSafe(sourcemapsDir)).filter(f => f.endsWith('.js.map'));
    debug(`Found ${sourcemapFiles.length} sourcemap files: ${sourcemapFiles.map(f => strong(f)).join(', ')}`);

    await Promise.all(sourcemapFiles.map(async f => {
      await this.syncSourcemap(path.resolve(sourcemapsDir, f), snapshotId, appVersion, commitHash, appflowId, token);
      count += 1;
      syncTask.msg = `Syncing sourcemaps: ${strong(`${count} / ${sourcemapFiles.length}`)}`;
    }));

    syncTask.msg = `Syncing sourcemaps: ${strong(`${sourcemapFiles.length} / ${sourcemapFiles.length}`)}`;
    tasks.end();

    const details = columnar([
      ['App ID', strong(appflowId)],
      ['Version', strong(appVersion)],
      ['Package ID', strong(cordovaInfo.id)],
      ['Snapshot ID', snapshotId ? strong(snapshotId) : weak('not set')],
    ], { vsep: ':' });

    this.env.log.ok(
      `Sourcemaps synced!\n` +
      details + '\n\n' +
      `See the Error Monitoring docs for usage information and next steps: ${strong('https://ionicframework.com/docs/appflow/monitoring')}`
    );
  }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:69,代码来源:syncmaps.ts


示例6: pathExists

 const platforms = (await Promise.all(platformsToCheck.map(async (p): Promise<[string, boolean]> => [p, await pathExists(path.resolve(integrationRoot, p))])))
开发者ID:driftyco,项目名称:ionic-cli,代码行数:1,代码来源:base.ts


示例7: run

  async run(inputs: CommandLineInputs, options: CommandLineOptions, runinfo: CommandInstanceInfo): Promise<void> {
    const { getGeneratedPrivateKeyPath } = await import('../../lib/ssh');
    const { getConfigPath } = await import('../../lib/ssh-config');
    const { promptToLogin } = await import('../../lib/session');

    if (!this.env.session.isLoggedIn()) {
      await promptToLogin(this.env);
    }

    const CHOICE_AUTOMATIC = 'automatic';
    const CHOICE_MANUAL = 'manual';
    const CHOICE_SKIP = 'skip';
    const CHOICE_IGNORE = 'ignore';

    if (this.env.config.get('git.setup')) {
      const rerun = await this.env.prompt({
        type: 'confirm',
        name: 'confirm',
        message: `SSH setup wizard has run before. Would you like to run it again?`,
      });

      if (!rerun) {
        return;
      }
    } else {
      this.env.log.msg(`Looks like you haven't configured your SSH settings yet.`);
    }

    // TODO: link to docs about manual git setup

    const setupChoice = await this.env.prompt({
      type: 'list',
      name: 'setupChoice',
      message: `How would you like to connect to Ionic?`,
      choices: [
        {
          name: 'Automatically setup new a SSH key pair for Ionic',
          value: CHOICE_AUTOMATIC,
        },
        {
          name: 'Use an existing SSH key pair',
          value: CHOICE_MANUAL,
        },
        {
          name: 'Skip for now',
          value: CHOICE_SKIP,
        },
        {
          name: 'Ignore this prompt forever',
          value: CHOICE_IGNORE,
        },
      ],
    });

    if (setupChoice === CHOICE_AUTOMATIC) {
      const sshconfigPath = getConfigPath();
      const keyPath = await getGeneratedPrivateKeyPath(this.env.config.get('user.id'));
      const pubkeyPath = `${keyPath}.pub`;

      const [ pubkeyExists, keyExists ] = await Promise.all([pathExists(keyPath), pathExists(pubkeyPath)]);

      if (!pubkeyExists && !keyExists) {
        this.env.log.info(
          'The automatic SSH setup will do the following:\n' +
          `1) Generate a new SSH key pair with OpenSSH (will not overwrite any existing keys).\n` +
          `2) Upload the generated SSH public key to our server, registering it on your account.\n` +
          `3) Modify your SSH config (${strong(prettyPath(sshconfigPath))}) to use the generated SSH private key for our server(s).`
        );

        const confirm = await this.env.prompt({
          type: 'confirm',
          name: 'confirm',
          message: 'May we proceed?',
        });

        if (!confirm) {
          throw new FatalException();
        }
      }

      if (pubkeyExists && keyExists) {
        this.env.log.msg(
          `Using your previously generated key: ${strong(prettyPath(keyPath))}.\n` +
          `You can generate a new one by deleting it.`
        );
      } else {
        await runCommand(runinfo, ['ssh', 'generate', keyPath]);
      }

      await runCommand(runinfo, ['ssh', 'add', pubkeyPath, '--use']);
    } else if (setupChoice === CHOICE_MANUAL) {
      await runCommand(runinfo, ['ssh', 'add']);
    }

    if (setupChoice === CHOICE_SKIP) {
      this.env.log.warn(`Skipping for now. You can configure your SSH settings using ${input('ionic ssh setup')}.`);
    } else {
      if (setupChoice === CHOICE_IGNORE) {
        this.env.log.ok(`We won't pester you about SSH settings anymore!`);
      } else {
//.........这里部分代码省略.........
开发者ID:driftyco,项目名称:ionic-cli,代码行数:101,代码来源:setup.ts


示例8: ensureDirectory

 private async ensureDirectory(p: string) {
   if (!(await pathExists(p))) {
     await mkdirp(p, 0o700 as any); // tslint:disable-line
     this.env.log.msg(`Created ${strong(prettyPath(p))} directory for you.`);
   }
 }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:6,代码来源:generate.ts


示例9: isRepoInitialized

export async function isRepoInitialized(dir: string): Promise<boolean> {
  return pathExists(path.join(dir, '.git'));
}
开发者ID:driftyco,项目名称:ionic-cli,代码行数:3,代码来源:git.ts


示例10: run

  async run(inputs: CommandLineInputs, options: CommandLineOptions, runinfo: CommandInstanceInfo): Promise<void> {
    const { ERROR_SSH_INVALID_PUBKEY, SSHKeyClient, parsePublicKeyFile } = await import('../../lib/ssh');

    const pubkeyPath = expandPath(inputs[0]);
    const pubkeyName = prettyPath(pubkeyPath);

    let pubkey: string;

    try {
      [ pubkey ] = await parsePublicKeyFile(pubkeyPath);
    } catch (e) {
      if (e.code === 'ENOENT') {
        throw new FatalException(
          `${strong(prettyPath(pubkeyPath))} does not appear to exist. Please specify a valid SSH public key.\n` +
          `If you are having issues, try using ${input('ionic ssh setup')}.`
        );
      } else if (e === ERROR_SSH_INVALID_PUBKEY) {
        throw new FatalException(
          `${strong(pubkeyName)} does not appear to be a valid SSH public key. (Not in ${strong('authorized_keys')} file format.)\n` +
          `If you are having issues, try using ${input('ionic ssh setup')}.`
        );
      }

      throw e;
    }

    const user = this.env.session.getUser();
    const token = this.env.session.getUserToken();
    const sshkeyClient = new SSHKeyClient({ client: this.env.client, token, user });

    try {
      const key = await sshkeyClient.create({ pubkey });
      this.env.log.ok(`Your public key (${strong(key.fingerprint)}) has been added to Ionic!`);
    } catch (e) {
      if (isSuperAgentError(e) && e.response.status === 409) {
        this.env.log.msg('Pubkey already added to Ionic.');
      } else {
        throw e;
      }
    }

    if (pubkeyPath.endsWith('.pub')) {
      let confirm = options['use'];

      if (!confirm) {
        confirm = await this.env.prompt({
          type: 'confirm',
          name: 'confirm',
          message: 'Would you like to use this key as your default for Ionic?',
        });
      }

      if (confirm) {
        const keyPath = pubkeyPath.substring(0, pubkeyPath.length - 4); // corresponding private key, theoretically
        const keyExists = await pathExists(keyPath);

        if (keyExists) {
          await runCommand(runinfo, ['ssh', 'use', prettyPath(keyPath)]);
        } else {
          this.env.log.error(
            `SSH key does not exist: ${strong(prettyPath(keyPath))}.\n` +
            `Please use ${input('ionic ssh use')} manually to use the corresponding private key.`
          );
        }
      }
    }
  }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:67,代码来源:add.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript utils-fs.readFile函数代码示例发布时间:2022-05-28
下一篇:
TypeScript utils-fs.mkdirp函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap