当前位置: 首页>>代码示例>>TypeScript>>正文


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

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


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

示例1: readPem

 async readPem(p: string): Promise<string> {
   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}`);
   }
 }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:8,代码来源:index.ts

示例2: it

 it('should stringify with config4 file', async () => {
   const config4 = await readFile(path.resolve(__dirname, 'fixtures/ssh-config/config4'), { encoding: 'utf8' });
   const conf = SSHConfig.parse(config4);
   ensureHostAndKeyPath(conf, { host: 'bar' }, '/id_rsa');
   const s = config4.split('\n');
   s[s.length - 2] = '    IdentityFile /id_rsa';
   expect(SSHConfig.stringify(conf)).toEqual(s.join('\n'));
 });
开发者ID:driftyco,项目名称:ionic-cli,代码行数:8,代码来源:ssh-config.ts

示例3: it

      it('should inject script into app template', async () => {
        // TODO: this test is fragile and gross
        const apphtml = await readFile(path.resolve(__dirname, 'fixtures/dev-server/app.html'), { encoding: 'utf8' });
        const code = `
    <script src="script.js"></script>
`;

        const result = injectScript(apphtml, code);
        const lines = apphtml.split('\n');
        lines.splice(-3);
        expect(result).toEqual(lines.join('\n') + '\n  ' + code + '</body>\n</html>\n');
      });
开发者ID:driftyco,项目名称:ionic-cli,代码行数:12,代码来源:dev-server.ts

示例4: readConfig

  async readConfig(p: string): Promise<{ [key: string]: any; }> {
    try {
      let configContents = await readFile(p, { encoding: 'utf8' });

      if (!configContents) {
        configContents = '{}\n';
        await writeFile(p, configContents, { encoding: 'utf8' });
      }

      return await JSON.parse(configContents);
    } catch (e) {
      throw new ProjectDetailsError('Could not read project file', 'ERR_INVALID_PROJECT_FILE', e);
    }
  }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:14,代码来源:index.ts

示例5: async

  const serveIndex = async (req: Request, res: Response) => {
    // respond with the index.html file
    const indexFileName = path.join(options.wwwDir, 'index.html');
    let indexHtml = await readFile(indexFileName, { encoding: 'utf8' });

    indexHtml = injectDevServerScript(indexHtml);

    if (options.livereload) {
      indexHtml = injectLiveReloadScript(indexHtml, options.livereloadPort);
    }

    res.set('Content-Type', 'text/html');
    res.send(indexHtml);
  };
开发者ID:driftyco,项目名称:ionic-cli,代码行数:14,代码来源:serve.ts

示例6: getAndroidSdkToolsVersion

export async function getAndroidSdkToolsVersion(): Promise<string | undefined> {
  const androidHome = await locateSDKHome();

  if (androidHome) {
    try {
      const f = await readFile(path.join(androidHome, 'tools', 'source.properties'), { encoding: 'utf8' });
      return `${await parseSDKVersion(f)} (${androidHome})`;
    } catch (e) {
      if (e.code !== 'ENOENT') {
        throw e;
      }
    }
  }
}
开发者ID:driftyco,项目名称:ionic-cli,代码行数:14,代码来源:android.ts

示例7: createDevServerHandler

export async function createDevServerHandler(options: DevServerOptions): Promise<RequestHandler> {
  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()
    );
  };
}
开发者ID:driftyco,项目名称:ionic-cli,代码行数:17,代码来源:dev-server.ts

示例8: validatePrivateKey

export async function validatePrivateKey(keyPath: string): Promise<void> {
  try {
    await stat(keyPath);
  } catch (e) {
    if (e.code === 'ENOENT') {
      throw ERROR_SSH_MISSING_PRIVKEY;
    }

    throw e;
  }

  const f = await readFile(keyPath, { encoding: 'utf8' });
  const lines = f.split('\n');

  if (!lines[0].match(/^\-{5}BEGIN [A-Z]+ PRIVATE KEY\-{5}$/)) {
    throw ERROR_SSH_INVALID_PRIVKEY;
  }
}
开发者ID:driftyco,项目名称:ionic-cli,代码行数:18,代码来源:ssh.ts

示例9: uploadSourcemap

  async uploadSourcemap(sourcemap: APIResponseSuccess, file: string) {
    const { createRequest } = await import('../../lib/utils/http');

    const sm = sourcemap as any;

    const fileData = await readFile(file, { encoding: 'utf8' });
    const sourcemapPost = sm.data.sourcemap_post;

    const { req } = await createRequest('POST', sourcemapPost.url, this.env.config.getHTTPConfig());

    req
      .field(sourcemapPost.fields)
      .field('file', fileData);

    const res = await req;

    if (res.status !== 204) {
      throw new FatalException(`Unexpected status code from AWS: ${res.status}`);
    }
  }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:20,代码来源:syncmaps.ts

示例10: getSuccessHtml

  protected async getSuccessHtml(): Promise<string> {
    const p = path.resolve(ASSETS_DIRECTORY, 'sso', 'success', 'index.html');
    const contents = await readFile(p, { encoding: 'utf8' });

    return contents;
  }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:6,代码来源:sso.ts


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