Skip to content

Creating a new application in a temp folder and deleting all of its files, doesn't remove all temp files #12139

Closed
@alexeagle

Description

@alexeagle

From @sebawita on March 9, 2018 16:56

My use case is, as follows.
I need to generate a new ng application in a temp folder.
Then I need to get some of the files (like .angular-cli.json, package.json and .gitignore) to merge them with my current project.
Then I need to clean up => delete the temp folder.

However, app.component.html, app.component.spec.ts, app.component.ts and app.module.ts seem to be immune to tree.delete(filename).

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Area

- [ ] devkit
- [x] schematics

Versions

"@angular-devkit/core": "^0.4.5",
"@angular-devkit/schematics": "^0.4.5",
"@schematics/angular": "^0.4.5",

Repro steps

If I run this chain of rules

export default function(): Rule {
  return chain([
    createNgProject(),
    deleteNgProject
  ])
}

const createNgProject = () => {
  const options: ApplicationSchema = {
    name: 'tmp-name',
    directory: 'tmp',
    skipInstall: true
  }
  return externalSchematic('@schematics/angular', 'application', options);
}

const deleteNgProject = (tree: Tree) => {
  tree.visit(file => {
    if (file.startsWith('/tmp')) {
      tree.delete(file);
    }
  })
  
  return tree;
}

The log given by the failure

No errors, but the log will display:

create tmp/src/app/app.component.html (1141 bytes)
create tmp/src/app/app.component.spec.ts (986 bytes)
create tmp/src/app/app.component.ts (207 bytes)
create tmp/src/app/app.module.ts (316 bytes)

Desired functionality

When I run the application schematic, I should be able, to delete all of the files it creates.

Mention any other details that might be useful

Copied from original issue: angular/devkit#492

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions