How to use the @ionic/utils-fs.unlink function in @ionic/utils-fs

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 / start.ts View on Github external
await mkdir(projectDir);

    tasks.end();

    if (this.schema.cloned) {
      await this.env.shell.run('git', ['clone', this.schema.url, projectDir, '--progress'], { stdio: 'inherit' });
    } else {
      const starterTemplate = await this.findStarterTemplate(this.schema.template, this.schema.type, tag);
      await this.downloadStarterTemplate(projectDir, starterTemplate);
    }

    let project: IProject | undefined;

    if (this.project && this.project.details.context === 'multiapp' && !this.schema.cloned) {
      // We're in a multi-app setup, so the new config file isn't wanted.
      await unlink(path.resolve(projectDir, 'ionic.config.json'));

      project = await createProjectFromDetails({ context: 'multiapp', configPath: path.resolve(this.project.rootDirectory, PROJECT_FILE), id: projectId, type: this.schema.type, errors: [] }, this.env);
      project.config.set('type', this.schema.type);
      project.config.set('root', path.relative(this.project.rootDirectory, projectDir));
    } else {
      project = await createProjectFromDirectory(projectDir, { _: [] }, this.env, { logErrors: false });
    }

    // start is weird, once the project directory is created, it becomes a
    // "project" command and so we replace the `Project` instance that was
    // autogenerated when the CLI booted up. This has worked thus far?
    this.namespace.root.project = project;

    if (!this.project) {
      throw new FatalException('Error while loading project.');
    }
github ionic-team / ionic-cli / packages / ionic / src / commands / ssh / generate.ts View on Github external
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();
github ionic-team / ionic-cli / packages / ionic / src / commands / start.ts View on Github external
if (appflowId) {
          cmdArgs.push(appflowId);
        }

        cmdArgs.push('--name', this.schema.name);

        await runCommand(runinfo, cmdArgs);
        linkConfirmed = true;
      }

      const manifestPath = path.resolve(projectDir, 'ionic.starter.json');
      const manifest = await this.loadManifest(manifestPath);

      if (manifest) {
        await unlink(manifestPath);
      }

      if (gitIntegration) {
        try {
          await this.env.shell.run('git', ['add', '-A'], shellOptions);
          await this.env.shell.run('git', ['commit', '-m', 'Initial commit', '--no-gpg-sign'], shellOptions);
        } catch (e) {
          this.env.log.warn('Error encountered during commit. Disabling further git operations.');
          gitIntegration = false;
        }
      }

      if (manifest) {
        await this.performManifestOps(manifest);
      }
    }
github ionic-team / ionic-cli / packages / ionic / src / commands / repair.ts View on Github external
async npmRepair(project: IProject) {
    const { pkgManagerArgs } = await import('../lib/utils/npm');
    const [ installer, ...installerArgs ] = await pkgManagerArgs(this.env.config.get('npmClient'), { command: 'install' });

    const tasks = this.createTaskChain();
    const packageLockFile = path.resolve(project.directory, 'package-lock.json');
    const nodeModulesDir = path.resolve(project.directory, 'node_modules');

    tasks.next(`Removing ${strong(prettyPath(packageLockFile))}`);
    const packageLockFileExists = await pathExists(packageLockFile);

    if (packageLockFileExists) {
      await unlink(packageLockFile);
    }

    tasks.next(`Removing ${strong(prettyPath(nodeModulesDir))}`);
    await remove(nodeModulesDir);

    tasks.end();

    await this.env.shell.run(installer, installerArgs, { cwd: project.directory, stdio: 'inherit' });
  }
github ionic-team / ionic-cli / packages / ionic / src / commands / ssl / generate.ts View on Github external
const localityName = options['locality-name'] ? String(options['locality-name']) : DEFAULT_LOCALITY_NAME;
    const organizationName = options['organization-name'] ? String(options['organization-name']) : DEFAULT_ORGANIZATION_NAME;
    const commonName = options['common-name'] ? String(options['common-name']) : DEFAULT_COMMON_NAME;

    await this.ensureDirectory(keyPathDir);
    await this.ensureDirectory(certPathDir);

    const overwriteKeyPath = await this.checkExistingFile(keyPath);
    const overwriteCertPath = await this.checkExistingFile(certPath);

    if (overwriteKeyPath) {
      await unlink(keyPath);
    }

    if (overwriteCertPath) {
      await unlink(certPath);
    }

    const cnf = { bits, countryName, stateOrProvinceName, localityName, organizationName, commonName };
    const cnfPath = await this.writeConfig(cnf);

    await this.env.shell.run('openssl', ['req', '-x509', '-newkey', `rsa:${bits}`, '-nodes', '-subj', this.formatSubj(cnf), '-reqexts', 'SAN', '-extensions', 'SAN', '-config', cnfPath, '-days', '365', '-keyout', keyPath, '-out', certPath], {});

    this.env.log.nl();

    this.env.log.rawmsg(
      `Key:  ${strong(prettyPath(keyPath))}\n` +
      `Cert: ${strong(prettyPath(certPath))}\n\n`
    );

    this.env.log.ok('Generated key & certificate!');
  }
github ionic-team / ionic-cli / packages / ionic / src / commands / ssl / generate.ts View on Github external
const bits = options['bits'] ? String(options['bits']) : DEFAULT_BITS;
    const countryName = options['country-name'] ? String(options['country-name']) : DEFAULT_COUNTRY_NAME;
    const stateOrProvinceName = options['state-or-province-name'] ? String(options['state-or-province-name']) : DEFAULT_STATE_OR_PROVINCE_NAME;
    const localityName = options['locality-name'] ? String(options['locality-name']) : DEFAULT_LOCALITY_NAME;
    const organizationName = options['organization-name'] ? String(options['organization-name']) : DEFAULT_ORGANIZATION_NAME;
    const commonName = options['common-name'] ? String(options['common-name']) : DEFAULT_COMMON_NAME;

    await this.ensureDirectory(keyPathDir);
    await this.ensureDirectory(certPathDir);

    const overwriteKeyPath = await this.checkExistingFile(keyPath);
    const overwriteCertPath = await this.checkExistingFile(certPath);

    if (overwriteKeyPath) {
      await unlink(keyPath);
    }

    if (overwriteCertPath) {
      await unlink(certPath);
    }

    const cnf = { bits, countryName, stateOrProvinceName, localityName, organizationName, commonName };
    const cnfPath = await this.writeConfig(cnf);

    await this.env.shell.run('openssl', ['req', '-x509', '-newkey', `rsa:${bits}`, '-nodes', '-subj', this.formatSubj(cnf), '-reqexts', 'SAN', '-extensions', 'SAN', '-config', cnfPath, '-days', '365', '-keyout', keyPath, '-out', certPath], {});

    this.env.log.nl();

    this.env.log.rawmsg(
      `Key:  ${strong(prettyPath(keyPath))}\n` +
      `Cert: ${strong(prettyPath(certPath))}\n\n`