本文整理汇总了TypeScript中@angular-devkit/core.virtualFs.fileBufferToString方法的典型用法代码示例。如果您正苦于以下问题:TypeScript virtualFs.fileBufferToString方法的具体用法?TypeScript virtualFs.fileBufferToString怎么用?TypeScript virtualFs.fileBufferToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular-devkit/core.virtualFs
的用法示例。
在下文中一共展示了virtualFs.fileBufferToString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: appendToFile
appendToFile(path: string, str: string) {
const content = virtualFs.fileBufferToString(this.scopedSync().read(normalize(path)));
this.scopedSync().write(normalize(path),
virtualFs.stringToFileBuffer(content.concat(str)));
}
示例2: tap
tap(() => {
expect(host.scopedSync().exists(extractionFile)).toBe(true);
expect(virtualFs.fileBufferToString(host.scopedSync().read(extractionFile)))
.toMatch(/i18n test/);
}),
示例3: tap
tap(() => {
const fileName = join(outputPath, 'index.html');
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
// tslint:disable-next-line:max-line-length
expect(content).toBe(`<html><head><base href="/"><%= csrf_meta_tags %></head> <body><app-root></app-root><script type="text/javascript" src="runtime.js"></script><script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="styles.js"></script><script type="text/javascript" src="vendor.js"></script><script type="text/javascript" src="main.js"></script></body></html>`);
}),
示例4: tap
tap(() => Object.keys(jsMatches).forEach(fileName => {
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
expect(content).toMatch(jsMatches[fileName]);
})),
示例5: tap
tap(() => {
const fileName = join(outputPath, 'main.js');
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
expect(content).toMatch(/Other content/);
}),
示例6: tap
tap(() => {
const fileName = join(outputPath, 'runtime.js');
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
expect(content).toContain('deployUrl/');
}),
示例7: tap
tap(() => {
const fileName = normalize('src/foo.ts');
const content = virtualFs.fileBufferToString(host.scopedSync().read(fileName));
expect(content).toContain(`const foo = '';`);
}),
示例8: map
map(data => virtualFs.fileBufferToString(data)),
示例9: tap
tap(() => {
const fileName = join(outputPath, 'main.js');
const content = virtualFs.fileBufferToString(host.scopedSync().read(fileName));
// Bundle contents should be uglified, which includes variable mangling.
expect(content).not.toContain('AppComponent');
}),
示例10: augmentAppWithServiceWorker
export async function augmentAppWithServiceWorker(
host: virtualFs.Host,
projectRoot: Path,
appRoot: Path,
outputPath: Path,
baseHref: string,
ngswConfigPath?: string,
): Promise<void> {
const distPath = normalize(outputPath);
const systemProjectRoot = getSystemPath(projectRoot);
// Find the service worker package
const workerPath = normalize(
require.resolve('@angular/service-worker/ngsw-worker.js', { paths: [systemProjectRoot] }),
);
const swConfigPath = require.resolve(
'@angular/service-worker/config',
{ paths: [systemProjectRoot] },
);
// Determine the configuration file path
let configPath;
if (ngswConfigPath) {
configPath = normalize(ngswConfigPath);
} else {
configPath = join(appRoot, 'ngsw-config.json');
}
// Ensure the configuration file exists
const configExists = await host.exists(configPath).toPromise();
if (!configExists) {
throw new Error(tags.oneLine`
Error: Expected to find an ngsw-config.json configuration
file in the ${appRoot} folder. Either provide one or disable Service Worker
in your angular.json configuration file.
`);
}
// Read the configuration file
const config = JSON.parse(virtualFs.fileBufferToString(await host.read(configPath).toPromise()));
// Generate the manifest
const GeneratorConstructor = require(swConfigPath).Generator as typeof Generator;
const generator = new GeneratorConstructor(new CliFilesystem(host, outputPath), baseHref);
const output = await generator.process(config);
// Write the manifest
const manifest = JSON.stringify(output, null, 2);
await host.write(join(distPath, 'ngsw.json'), virtualFs.stringToFileBuffer(manifest)).toPromise();
// Write the worker code
// NOTE: This is inefficient (kernel -> userspace -> kernel).
// `fs.copyFile` would be a better option but breaks the host abstraction
const workerCode = await host.read(workerPath).toPromise();
await host.write(join(distPath, 'ngsw-worker.js'), workerCode).toPromise();
// If present, write the safety worker code
const safetyPath = join(dirname(workerPath), 'safety-worker.js');
if (await host.exists(safetyPath).toPromise()) {
const safetyCode = await host.read(safetyPath).toPromise();
await host.write(join(distPath, 'worker-basic.min.js'), safetyCode).toPromise();
await host.write(join(distPath, 'safety-worker.js'), safetyCode).toPromise();
}
}