How to use the @angular-devkit/schematics.HostTree function in @angular-devkit/schematics

To help you get started, we’ve selected a few @angular-devkit/schematics 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 angular / components / src / cdk / schematics / testing / test-case-setup.ts View on Github external
export async function createFileSystemTestApp(runner: SchematicTestRunner) {
  const tempFileSystemHost = new TempScopedNodeJsSyncHost();
  const hostTree = new HostTree(tempFileSystemHost);
  const appTree: UnitTestTree = await createTestApp(runner, {name: 'cdk-testing'}, hostTree);
  const tempPath = getSystemPath(tempFileSystemHost.root);

  // Since the TypeScript compiler API expects all files to be present on the real file system, we
  // map every file in the app tree to a temporary location on the file system.
  appTree.files.forEach(f => writeFile(f, appTree.readContent(f)));

  return {
    appTree,
    tempFileSystemHost,
    tempPath,
    writeFile,
    removeTempDir: () => removeSync(tempPath),
  };

  function writeFile(filePath: string, content: string) {
github angular / angular-cli / packages / schematics / update / update / index_spec.ts View on Github external
describe('@schematics/update', () => {
  const schematicRunner = new SchematicTestRunner(
    '@schematics/update',
    require.resolve('../collection.json'),
  );
  let host: virtualFs.test.TestHost;
  let appTree: UnitTestTree = new UnitTestTree(new HostTree());

  beforeEach(() => {
    host = new virtualFs.test.TestHost({
      '/package.json': `{
        "name": "blah",
        "dependencies": {
          "@angular-devkit-tests/update-base": "1.0.0"
        }
      }`,
    });
    appTree = new UnitTestTree(new HostTree(host));
  });

  it('updates package.json', done => {
    // Since we cannot run tasks in unit tests, we need to validate that the default
    // update schematic updates the package.json appropriately, AND validate that the
github martinroob / ngx-i18nsupport / projects / tooling / src / schematics / src / ng-update / index_spec.ts View on Github external
it('should show error when there is a missing config file', () => {
            const xliffmergeProject: ProjectOptions = {
                name: 'projectWithXliffmerge'
            };
            const packageOptions: PackageJsonOptions = {
                project: xliffmergeProject.name,
                createExtractScriptCommandline: true,
                xliffmergeConfigFilePath: 'test/xliffmerge.config',
                languages: ['en', 'de']
            };
            host = createHost([xliffmergeProject], [packageOptions], []);
            appTree = new UnitTestTree(new HostTree(host));
            let loggerOutput = '';
            testRunner.logger.subscribe(entry => {
                loggerOutput = loggerOutput + entry.message;
            });
            appTree = testRunner.runSchematic('update-1', defaultOptions, appTree);
            expect(loggerOutput).toContain('Could not find config file "//test/xliffmerge.config"');
        });
github emyann / matron / packages / schematics / src / collection / snapshot / snapshot.schematic.spec.ts View on Github external
function getTree(files: File[] = []) {
  const tree = new HostTree();
  files.forEach(({ path, content = '' }) => {
    tree.create(path, content);
  });
  return tree;
}
function withFiles(source: string, ignore: string[], SOURCE_FILES: string[]) {
github angular / angular-cli / packages / schematics / update / update / index_spec.ts View on Github external
beforeEach(() => {
    host = new virtualFs.test.TestHost({
      '/package.json': `{
        "name": "blah",
        "dependencies": {
          "@angular-devkit-tests/update-base": "1.0.0"
        }
      }`,
    });
    appTree = new UnitTestTree(new HostTree(host));
  });
github nrwl / nx / packages / tao / src / commands / generate.ts View on Github external
async function readDefaultCollection(host: virtualFs.Host) {
  const workspaceJson = JSON.parse(
    new HostTree(host).read('workspace.json')!.toString()
  );
  return workspaceJson.cli ? workspaceJson.cli.defaultCollection : null;
}
github angular / angular-cli / packages / schematics / angular / utility / ast-utils_spec.ts View on Github external
function applyChanges(path: string, content: string, changes: Change[]): string {
  const tree = new HostTree();
  tree.create(path, content);
  const exportRecorder = tree.beginUpdate(path);
  for (const change of changes) {
    if (change instanceof InsertChange) {
      exportRecorder.insertLeft(change.pos, change.toAdd);
    }
  }
  tree.commitUpdate(exportRecorder);

  return getFileContent(tree, path);
}