chihab / dotenv-run

Seamlessly load environment variables. Supports cli, esbuild, rollup, vite, webpack, angular. ESM and Monorepos.
238 stars 17 forks source link

Support angular workspace for ng-add #60

Open aboudard opened 10 months ago

aboudard commented 10 months ago

Hello,

When running in an angular workspace, the ng-add command can recognize the proper project for the modifications of the angular.json file. But for the env.d.ts file, this is only a use of src folder, which makes that you have to move the file.

The following move function could use the project path :

export default function (options: any): Rule {
  return chain([
    mergeWith(apply(url("./template"), [move(normalize("./src"))])),
    builder(options),
  ]);
}

This can be helpful when we want to call the schematics from another schematics with externalSchematic method, giving the project as argument :

function addNgxEnvBuilder(): Rule {
    return (tree: Tree, context: SchematicContext) => {
        context.logger.log('info', `🛠 Adding ngx-env builder...`);
        return externalSchematic('@ngx-env/builder', 'ng-add', {
            project: 'sandbox'    //or options.project for example
        })(tree, context);
    }
}

Cheers !