本文整理汇总了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}`);
}
}
示例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'));
});
示例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');
});
示例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);
}
}
示例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);
};
示例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;
}
}
}
}
示例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()
);
};
}
示例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;
}
}
示例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}`);
}
}
示例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;
}