How to use @ionic/utils-fs - 10 common examples

To help you get started, we’ve selected a few @ionic/utils-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ionic-team / ionic-cli / packages / ionic / src / commands / ssh / generate.ts View on Github external
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise {
    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' +
github ionic-team / ionic-cli / packages / ionic / src / commands / deploy / core.ts View on Github external
protected async getIosCapPlist(): Promise {
    if (!this.project) {
      return '';
    }
    const capIntegration = this.project.getIntegration('capacitor');
    if (!capIntegration) {
      return '';
    }
    // check first if iOS exists
    if (!await pathExists(path.join(capIntegration.root, 'ios'))) {
      return '';
    }
    const assumedPlistPath = path.join(capIntegration.root, 'ios', 'App', 'App', 'Info.plist');
    if (!await pathWritable(assumedPlistPath)) {
      throw new Error('The iOS Info.plist could not be found.');
    }
    return assumedPlistPath;
  }
github ionic-team / ionic-cli / packages / ionic / src / commands / ssh / generate.ts View on Github external
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise {
    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;
github ionic-team / ionic-cli / packages / ionic / src / commands / ssl / generate.ts View on Github external
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.`);
    }
  }
github ionic-team / ionic-cli / packages / ionic / src / commands / ssh / use.ts View on Github external
this.env.log.rawmsg(diff);

      const confirm = await this.env.prompt({
        type: 'confirm',
        name: 'confirm',
        message: `May we make the above change(s) to '${prettyPath(sshConfigPath)}'?`,
      });

      if (!confirm) {
        // TODO: link to docs about manual git setup
        throw new FatalException();
      }
    }

    await writeFile(sshConfigPath, text2, { encoding: 'utf8', mode: 0o600 });

    this.env.log.ok(`Your active Ionic SSH key has been set to ${strong(keyPath)}!`);
  }
}
github ionic-team / cordova-res / src / config.ts View on Github external
export async function write(path: string, doc: et.ElementTree): Promise {
  // Cordova hard codes an indentation of 4 spaces, so we'll follow.
  const contents = doc.write({ indent: 4 });

  await writeFile(path, contents, 'utf8');
}
github ionic-team / ionic-cli / packages / cli-scripts / src / docs / index.ts View on Github external
for (const projectType of projectTypes) {
      // TODO: possible to do this without a physical directory?
      const ctx = { ...baseCtx, execPath: path.resolve(PROJECTS_DIRECTORY, projectType) };
      const executor = await loadExecutor(ctx, []);

      const location = await executor.namespace.locate([]);
      const formatter = new NamespaceSchemaHelpFormatter({ location, namespace: executor.namespace });
      const formatted = await formatter.serialize();
      const projectJson = { type: projectType, ...formatted };

      // TODO: `serialize()` from base formatter isn't typed properly
      projectJson.commands = await Promise.all(projectJson.commands.map(async cmd => this.extractCommand(cmd as CommandHelpSchema)));
      projectJson.commands.sort((a, b) => strcmp(a.name, b.name));

      await writeFile(path.resolve(STAGING_DIRECTORY, `${projectType}.json`), JSON.stringify(projectJson, undefined, 2) + '\n', { encoding: 'utf8' });
    }

    process.stdout.write(`${chalk.green('Done.')}\n`);
  }
github ionic-team / ionic-cli / packages / ionic / src / lib / integrations / cordova / index.ts View on Github external
const onFileCreate = handlers.onFileCreate ? handlers.onFileCreate : lodash.noop;
    const conflictHandler = handlers.conflictHandler ? handlers.conflictHandler : async () => false;

    const { createRequest, download } = await import('../../utils/http');
    const { tar } = await import('../../utils/archive');

    this.e.log.info(`Downloading integration ${input(this.name)}`);
    const tmpdir = path.resolve(os.tmpdir(), `ionic-integration-${this.name}`);

    // TODO: etag

    if (await pathExists(tmpdir)) {
      await remove(tmpdir);
    }

    await mkdirp(tmpdir);

    const ws = tar.extract({ cwd: tmpdir });
    const { req } = await createRequest('GET', this.archiveUrl, this.e.config.getHTTPConfig());
    await download(req, ws, {});

    const contents = await readdirSafe(tmpdir);
    const blacklist: string[] = [];

    debug(`Integration files downloaded to ${strong(tmpdir)} (files: ${contents.map(f => strong(f)).join(', ')})`);

    for (const f of contents) {
      const projectf = path.resolve(this.e.project.directory, f);

      try {
        const stats = await stat(projectf);
        const overwrite = await conflictHandler(projectf, stats);
github ionic-team / ionic-cli / packages / ionic / src / commands / ssh / generate.ts View on Github external
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise {
    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;
      }
github ionic-team / ionic-cli / packages / ionic / src / commands / ssl / generate.ts View on Github external
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.`);
    }
  }