Skip to content

Commit

Permalink
(fix) reference nx function to read non-angularCli configs
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Jan 8, 2021
1 parent 9b37d68 commit 0009e69
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 38 deletions.
7 changes: 7 additions & 0 deletions app/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@angular/forms": "^11.0.0",
"@angular/platform-browser": "^11.0.0",
"@angular/platform-browser-dynamic": "^11.0.0",
"@nrwl/workspace": ">=11.1.0",
"@types/autoprefixer": "^9.4.0",
"@types/jest": "^25.1.1",
"jest": "^26.0.0",
Expand All @@ -90,10 +91,16 @@
"@angular/platform-browser": ">=6.0.0",
"@angular/platform-browser-dynamic": ">=6.0.0",
"@babel/core": "*",
"@nrwl/workspace": ">=11.1.0",
"rxjs": "^6.0.0",
"typescript": "^3.4.0 || >=4.0.0",
"zone.js": "^0.8.29 || ^0.9.0 || ^0.10.0 || ^0.11.0"
},
"peerDependenciesMeta": {
"@nrwl/workspace": {
"optional": true
}
},
"engines": {
"node": ">=8.0.0"
},
Expand Down
35 changes: 25 additions & 10 deletions app/angular/src/server/angular-cli_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,32 @@ function getTsConfigOptions(tsConfigPath: Path) {
}

export function getAngularCliConfig(dirToSearch: string) {
const possibleConfigNames = ['angular.json', 'workspace.json'];
const possibleConfigPaths = possibleConfigNames.map((name) => path.join(dirToSearch, name));

const validIndex = possibleConfigPaths.findIndex((configPath) => fs.existsSync(configPath));

if (validIndex === -1) {
logger.error(`Could not find angular.json using ${possibleConfigPaths[0]}`);
return undefined;
let angularCliConfig;
try {
/**
* Apologies for the following line
* If there's a better way to do it, let's do it
*/
/* eslint-disable global-require */
angularCliConfig = require('@nrwl/workspace').readWorkspaceConfig({
format: 'angularCli',
});
} catch (e) {
const possibleConfigNames = ['angular.json', 'workspace.json'];
const possibleConfigPaths = possibleConfigNames.map((name) => path.join(dirToSearch, name));

const validIndex = possibleConfigPaths.findIndex((configPath) => fs.existsSync(configPath));

if (validIndex === -1) {
logger.error(`Could not find angular.json using ${possibleConfigPaths[0]}`);
return undefined;
}

angularCliConfig = JSON.parse(
stripJsonComments(fs.readFileSync(possibleConfigPaths[validIndex], 'utf8'))
);
}

return JSON.parse(stripJsonComments(fs.readFileSync(possibleConfigPaths[validIndex], 'utf8')));
return angularCliConfig;
}

export function getLeadingAngularCliProject(ngCliConfig: any) {
Expand Down
Loading

0 comments on commit 0009e69

Please sign in to comment.