當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。