當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript utils-fs.pathExists函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。