How to use the @ionic/utils-fs.readFile 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 / cordova-res / src / config.ts View on Github external
export async function read(path: string): Promise {
  const contents = await readFile(path, 'utf8');
  const doc = et.parse(contents);

  return doc;
}
github ionic-team / ionic-cli / packages / @ionic / lab / src / index.ts View on Github external
async readPem(p: string): Promise {
    try {
      return await readFile(p, { encoding: 'utf8' });
    } catch (e) {
      process.stderr.write(String(e.stack ? e.stack : e) + '\n');
      throw new Error(`Error encountered with ${p}`);
    }
  }
}
github ionic-team / ionic-cli / packages / ionic / src / lib / doctor / ailments / index.ts View on Github external
async detected() {
    const indexHtml = await readFile(path.resolve(await this.project.getSourceDir(), 'index.html'), { encoding: 'utf8' });
    const m = indexHtml.match(/\/);
    return !Boolean(m);
  }
github ionic-team / ionic-cli / packages / @ionic / v1-toolkit / src / lib / dev-server.ts View on Github external
export async function createDevServerHandler(options: DevServerOptions): Promise {
  const devServerConfig = {
    consolelogs: options.consolelogs,
    wsPort: options.devPort,
  };

  const devServerJs = await readFile(path.join(__dirname, '..', '..', 'assets', 'dev-server.js'), { encoding: 'utf8' });

  return (req, res) => {
    res.set('Content-Type', 'application/javascript');

    res.send(
      `window.Ionic = window.Ionic || {}; window.Ionic.DevServerConfig = ${JSON.stringify(devServerConfig)};\n\n` +
      `${devServerJs}`.trim()
    );
  };
}
github ionic-team / native-run / src / utils / ini.ts View on Github external
export async function readINI(p: string, guard: INIGuard = (o: any): o is T => true): Promise {
  const ini = await import('ini');

  try {
    const contents = await readFile(p, { encoding: 'utf8' });
    const config = ini.decode(contents);

    if (!guard(config)) {
      throw new Error(
        `Invalid ini configuration file: ${p}\n` +
        `The following guard was used: ${guard.toString()}\n` +
        `INI config parsed as: ${util.inspect(config)}`
      );
    }

    return { __filename: p, ...config as any };
  } catch (e) {
    debug(e);
  }
}
github ionic-team / ionic-cli / packages / ionic / src / lib / utils / http.ts View on Github external
      req.key(await Promise.all(keyfiles.map(p => readFile(p, { encoding: 'utf8' }))));
    }
github ionic-team / ionic-cli / packages / ionic / src / lib / integrations / cordova / config.ts View on Github external
protected async reload(): Promise {
    const configXml = await readFile(this.configXmlPath, { encoding: 'utf8' });

    if (!configXml) {
      throw new Error(`Cannot load empty config.xml file.`);
    }

    try {
      this._doc = et.parse(configXml);
      this._sessionid = shortid();
    } catch (e) {
      throw new Error(`Cannot parse config.xml file: ${e.stack ? e.stack : e}`);
    }

    const packageJson = await readPackageJsonFile(this.packageJsonPath);

    if (isCordovaPackageJson(packageJson)) {
      this._pkg = packageJson;