0

I've been following the example for creating a custom angular schematic here: Creating your own application template for angular-cli

And I've gotten it to work as expected on Mac. However, when I try to build from my schematic on a PC, I just get the basic src files of the schematic without any of the transformations from my custom files in the workspace and src directories.

For example, the angular.json and package.json in the source directory at @my-schematic/my-schematic/workspace/files/

Are not getting copied over into the new project's root folder.

To build the project I'm using the following steps:

1) npm install -g @angular-devkit/schematics 
1a) npm install -g @angular-devkit/schematics-cli 
2) npm install -g @my-schematic/my-schematic
3) ng new --collection=@my-schematic/my-schematic foldername 
4) cd [foldername] 
5) npm install 
6) ng serve 
Scott B
  • 38,833
  • 65
  • 160
  • 266
  • The @my-schematic/my-schematic package is hosted at my artifactory repo. That part works great. The package is pulled from the remote repo and installed into the global node_modules folder as expected. – Scott B Jul 18 '18 at 16:08
  • Can you share the schematics code? – eko Jul 18 '18 at 19:55
  • There is no code per se, based on the tutorial, its all about cloning the default collection and overwriting with your custom package.json and angular.json – Scott B Jul 18 '18 at 19:58
  • The way it works on my Mac is that the package.json and angular.json are pulled over into the final built site (foldername) from the copies I've placed into workspace/files. However, on PC, those files aren't moving over and I get the default ones instead, screwing my plan. – Scott B Jul 19 '18 at 20:40
  • Im assuming this is a pathing issue, are you writing any hardcoded paths somewhere? – eko Jul 22 '18 at 12:58

1 Answers1

0

the way your files would be 'moved' is by using the 'move' method from the schematic library - you would have to provide the path to this method that would define where your files would go. This move method is applied using 'apply' method to the template() --

apply(url(‘./files’), [
    filter( path => !path.match( /\.bak$/) ),
    template( ...strings, ...options ),
    move( options.path || ‘’ )
]);

so without you telling us what this method looks like in your schematic, it'll be hard to debug your problem :)

Chhirag Kataria
  • 278
  • 1
  • 9
  • Hi. Thanks for this. Also, can we check and skip this part if the file already exists at that place? It would be great if you can help me with that code as well. – Ankit Joshi Aug 06 '20 at 11:51