Skip to content

Commit b4d9b51

Browse files
committed
Added angular ui library project, made custom type for getPath
1 parent 63295c8 commit b4d9b51

26 files changed

Lines changed: 220 additions & 182 deletions

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ They will give you a nice overview of all monorepos on your machine and their re
300300
## Angular app
301301
## Angular website
302302
## Angular library
303-
WIP
304303
## LoopBack
305304
## Typescript library
306305
## Wordpress

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "monux-cli",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"license": "MIT",
55
"main": "index.js",
66
"engines": {

src/__testing__/mock/constants.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
import { ANGULAR_JSON_FILE_NAME, ANGULAR_ROUTES_FILE_NAME, APP_CONFIG_FILE_NAME, APPS_DIRECTORY_NAME, DEV_DOCKER_COMPOSE_FILE_NAME, PROD_DOCKER_COMPOSE_FILE_NAME, ENV_FILE_NAME, ENVIRONMENT_MODEL_TS_FILE_NAME, ENVIRONMENT_TS_FILE_NAME, ESLINT_CONFIG_FILE_NAME, GLOBAL_ENVIRONMENT_MODEL_FILE_NAME, LIBS_DIRECTORY_NAME, PACKAGE_JSON_FILE_NAME, LOCAL_DOCKER_COMPOSE_FILE_NAME } from '../../constants';
22
import { OmitStrict } from '../../types';
3-
import { getPath } from '../../utilities';
3+
import { getPath, Path } from '../../utilities';
44

55
// eslint-disable-next-line jsdoc/require-jsdoc
66
export type MockConstants = {
77
// eslint-disable-next-line jsdoc/require-jsdoc
8-
readonly PROJECT_DIR: string,
8+
readonly PROJECT_DIR: Path,
99
// eslint-disable-next-line jsdoc/require-jsdoc
10-
readonly APPS_DIR: string,
10+
readonly APPS_DIR: Path,
1111
// eslint-disable-next-line jsdoc/require-jsdoc
12-
readonly LIBS_DIR: string,
12+
readonly LIBS_DIR: Path,
1313
// eslint-disable-next-line jsdoc/require-jsdoc
14-
readonly DOCKER_COMPOSE_YAML: string,
14+
readonly DOCKER_COMPOSE_YAML: Path,
1515
// eslint-disable-next-line jsdoc/require-jsdoc
16-
readonly DEV_DOCKER_COMPOSE_YAML: string,
16+
readonly DEV_DOCKER_COMPOSE_YAML: Path,
1717
// eslint-disable-next-line jsdoc/require-jsdoc
18-
readonly LOCAL_DOCKER_COMPOSE_YAML: string,
18+
readonly LOCAL_DOCKER_COMPOSE_YAML: Path,
1919
// eslint-disable-next-line jsdoc/require-jsdoc
20-
readonly ANGULAR_ESLINT_CONFIG_MJS: string,
20+
readonly ANGULAR_ESLINT_CONFIG_MJS: Path,
2121
// eslint-disable-next-line jsdoc/require-jsdoc
22-
readonly ANGULAR_PACKAGE_JSON: string,
22+
readonly ANGULAR_PACKAGE_JSON: Path,
2323
// eslint-disable-next-line jsdoc/require-jsdoc
2424
readonly ANGULAR_APP_NAME: string,
2525
// eslint-disable-next-line jsdoc/require-jsdoc
26-
readonly ANGULAR_APP_DIR: string,
26+
readonly ANGULAR_APP_DIR: Path,
2727
// eslint-disable-next-line jsdoc/require-jsdoc
28-
readonly ANGULAR_APP_COMPONENT_TS: string,
28+
readonly ANGULAR_APP_COMPONENT_TS: Path,
2929
// eslint-disable-next-line jsdoc/require-jsdoc
30-
readonly ANGULAR_APP_COMPONENT_HTML: string,
30+
readonly ANGULAR_APP_COMPONENT_HTML: Path,
3131
// eslint-disable-next-line jsdoc/require-jsdoc
32-
readonly ANGULAR_APP_ROUTES_TS: string,
32+
readonly ANGULAR_APP_ROUTES_TS: Path,
3333
// eslint-disable-next-line jsdoc/require-jsdoc
34-
readonly ANGULAR_ROUTES_TS: string,
34+
readonly ANGULAR_ROUTES_TS: Path,
3535
// eslint-disable-next-line jsdoc/require-jsdoc
36-
readonly ANGULAR_APP_CONFIG_TS: string,
36+
readonly ANGULAR_APP_CONFIG_TS: Path,
3737
// eslint-disable-next-line jsdoc/require-jsdoc
38-
readonly ANGULAR_JSON: string,
38+
readonly ANGULAR_JSON: Path,
3939
// eslint-disable-next-line jsdoc/require-jsdoc
40-
readonly ANGULAR_ENVIRONMENT_MODEL: string,
40+
readonly ANGULAR_ENVIRONMENT_MODEL: Path,
4141
// eslint-disable-next-line jsdoc/require-jsdoc
42-
readonly ANGULAR_ENVIRONMENT: string,
42+
readonly ANGULAR_ENVIRONMENT: Path,
4343
// eslint-disable-next-line jsdoc/require-jsdoc
44-
readonly TS_LIBRARY_DIR: string,
44+
readonly TS_LIBRARY_DIR: Path,
4545
// eslint-disable-next-line jsdoc/require-jsdoc
4646
readonly TS_LIBRARY_SCOPE: string,
4747
// eslint-disable-next-line jsdoc/require-jsdoc
48-
readonly TS_LIBRARY_PACKAGE_JSON: string,
48+
readonly TS_LIBRARY_PACKAGE_JSON: Path,
4949
// eslint-disable-next-line jsdoc/require-jsdoc
50-
readonly ROOT_PACKAGE_JSON: string,
50+
readonly ROOT_PACKAGE_JSON: Path,
5151
// eslint-disable-next-line jsdoc/require-jsdoc
5252
readonly TS_LIBRARY_NAME: string,
5353
// eslint-disable-next-line jsdoc/require-jsdoc
54-
readonly ENV: string,
54+
readonly ENV: Path,
5555
// eslint-disable-next-line jsdoc/require-jsdoc
56-
readonly GLOBAL_ENV_MODEL: string,
56+
readonly GLOBAL_ENV_MODEL: Path,
5757
// eslint-disable-next-line jsdoc/require-jsdoc
58-
readonly GITHUB_WORKFLOW_DIR: string
58+
readonly GITHUB_WORKFLOW_DIR: Path
5959
};
6060

6161
// eslint-disable-next-line jsdoc/require-jsdoc
@@ -79,14 +79,14 @@ export type DirMockConstants = OmitStrict<
7979
* @returns Constant values.
8080
*/
8181
export function getMockConstants(projectName: string): MockConstants {
82-
const TMP_DIR: string = getPath(__dirname, '..', 'tmp');
83-
const PROJECT_DIR: string = getPath(TMP_DIR, projectName);
84-
const APPS_DIR: string = getPath(PROJECT_DIR, APPS_DIRECTORY_NAME);
85-
const LIBS_DIR: string = getPath(PROJECT_DIR, LIBS_DIRECTORY_NAME);
82+
const TMP_DIR: Path = getPath(__dirname, '..', 'tmp');
83+
const PROJECT_DIR: Path = getPath(TMP_DIR, projectName);
84+
const APPS_DIR: Path = getPath(PROJECT_DIR, APPS_DIRECTORY_NAME);
85+
const LIBS_DIR: Path = getPath(PROJECT_DIR, LIBS_DIRECTORY_NAME);
8686
const ANGULAR_APP_NAME: string = 'angular';
87-
const ANGULAR_APP_DIR: string = getPath(APPS_DIR, ANGULAR_APP_NAME);
87+
const ANGULAR_APP_DIR: Path = getPath(APPS_DIR, ANGULAR_APP_NAME);
8888
const TS_LIBRARY_NAME: string = 'library';
89-
const TS_LIBRARY_DIR: string = getPath(LIBS_DIR, TS_LIBRARY_NAME);
89+
const TS_LIBRARY_DIR: Path = getPath(LIBS_DIR, TS_LIBRARY_NAME);
9090

9191
const mockConstants: MockConstants = {
9292
PROJECT_DIR: PROJECT_DIR,

src/__testing__/mock/file-mock.utilities.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AngularJson } from '../../angular';
44
import { CPUtilities, FsUtilities, JsonUtilities } from '../../encapsulation';
55
import { EnvUtilities } from '../../env';
66
import { WorkspaceUtilities } from '../../workspace';
7+
import { getPath } from '../../utilities';
78

89
export abstract class FileMockUtilities {
910

@@ -35,7 +36,7 @@ export abstract class FileMockUtilities {
3536
filesToMock: (keyof FileMockConstants)[] = [],
3637
contentOverrides: Partial<Record<keyof FileMockConstants, string | string[]>> = {}
3738
): Promise<void> {
38-
await FsUtilities.rm(mockConstants.PROJECT_DIR);
39+
await FsUtilities.rm(getPath(mockConstants.PROJECT_DIR));
3940
CPUtilities['cwd'] = mockConstants.PROJECT_DIR;
4041
await this.mockFolders(mockConstants);
4142
await this.mockFiles(filesToMock, contentOverrides, mockConstants);
@@ -52,7 +53,7 @@ export abstract class FileMockUtilities {
5253
GITHUB_WORKFLOW_DIR: mockConstants.GITHUB_WORKFLOW_DIR
5354
};
5455
for (const entry of Object.values(dirMockConstants)) {
55-
await FsUtilities.mkdir(entry, true, false);
56+
await FsUtilities.mkdir(getPath(entry), true, false);
5657
}
5758
}
5859

@@ -77,14 +78,14 @@ export abstract class FileMockUtilities {
7778
content: string | string[] | undefined
7879
): Promise<void> {
7980
if (hasContentOverride) {
80-
await FsUtilities.createFile(mockConstants[entry], content ?? '', true, false);
81+
await FsUtilities.createFile(getPath(mockConstants[entry]), content ?? '', true, false);
8182
return;
8283
}
8384
await this.mockMethodForFile[entry](mockConstants, entry);
8485
}
8586

8687
private static async createEmptyFile(mockConstants: MockConstants, entry: keyof MockConstants): Promise<void> {
87-
await FsUtilities.createFile(mockConstants[entry], '', true, false);
88+
await FsUtilities.createFile(getPath(mockConstants[entry]), '', true, false);
8889
}
8990

9091
private static async createAngularJson(mockConstants: MockConstants): Promise<void> {

src/angular/angular.utilities.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ANGULAR_APP_COMPONENT_FILE_NAME, ANGULAR_JSON_FILE_NAME, ANGULAR_ROUTES
1111
import { DefaultEnvKeys, EnvUtilities } from '../env';
1212
import { DeepPartial } from '../types';
1313
import { AddNavElementConfig } from './add-nav-element-config.model';
14-
import { getPath, mergeDeep, optionsToCliString } from '../utilities';
14+
import { getPath, mergeDeep, optionsToCliString, Path } from '../utilities';
1515
import { NavElementTypes } from './nav-element-types.enum';
1616
import { RobotsUtilities } from '../robots';
1717
import { WorkspaceProject, WorkspaceUtilities } from '../workspace';
@@ -132,7 +132,7 @@ export abstract class AngularUtilities {
132132
'}'
133133
]
134134
);
135-
const appComponentPath: string = getPath(root, 'src', 'app', ANGULAR_APP_COMPONENT_FILE_NAME);
135+
const appComponentPath: Path = getPath(root, 'src', 'app', ANGULAR_APP_COMPONENT_FILE_NAME);
136136
await TsUtilities.addImportStatements(
137137
appComponentPath,
138138
[{ defaultImport: false, element: 'LoggerService', path: './services/logger.service' }]
@@ -187,7 +187,7 @@ export abstract class AngularUtilities {
187187
false,
188188
getPath('.')
189189
);
190-
const authServicePath: string = getPath(projectRoot, 'src', 'app', 'services', 'auth.service.ts');
190+
const authServicePath: Path = getPath(projectRoot, 'src', 'app', 'services', 'auth.service.ts');
191191
await FsUtilities.createFile(authServicePath, authServiceContent);
192192
await this.addProvider(
193193
projectRoot,
@@ -205,7 +205,7 @@ export abstract class AngularUtilities {
205205
{ defaultImport: false, element: 'environment', path: '../environment/environment' }
206206
]
207207
);
208-
const appConfigPath: string = getPath(projectRoot, 'src', 'app', APP_CONFIG_FILE_NAME);
208+
const appConfigPath: Path = getPath(projectRoot, 'src', 'app', APP_CONFIG_FILE_NAME);
209209
await TsUtilities.addImportStatements(
210210
appConfigPath,
211211
[
@@ -249,9 +249,9 @@ export abstract class AngularUtilities {
249249
},
250250
domain
251251
);
252-
const pagesPath: string = getPath(projectRoot, 'src', 'app', 'pages');
253-
const loginPageTs: string = getPath(pagesPath, 'login', 'login.component.ts');
254-
const loginPageHtml: string = getPath(pagesPath, 'login', 'login.component.html');
252+
const pagesPath: Path = getPath(projectRoot, 'src', 'app', 'pages');
253+
const loginPageTs: Path = getPath(pagesPath, 'login', 'login.component.ts');
254+
const loginPageHtml: Path = getPath(pagesPath, 'login', 'login.component.html');
255255
await this.addComponentImports(
256256
loginPageTs,
257257
[{ defaultImport: false, element: 'NgxMatAuthLoginComponent', path: NpmPackage.NGX_MATERIAL_AUTH }]
@@ -284,9 +284,9 @@ export abstract class AngularUtilities {
284284
},
285285
domain
286286
);
287-
const requestResetPasswordPageTs: string = getPath(pagesPath, 'request-reset-password', 'request-reset-password.component.ts');
287+
const requestResetPasswordPageTs: Path = getPath(pagesPath, 'request-reset-password', 'request-reset-password.component.ts');
288288

289-
const requestResetPasswordPageHtml: string = getPath(pagesPath, 'request-reset-password', 'request-reset-password.component.html');
289+
const requestResetPasswordPageHtml: Path = getPath(pagesPath, 'request-reset-password', 'request-reset-password.component.html');
290290
await this.addComponentImports(
291291
requestResetPasswordPageTs,
292292
[{ defaultImport: false, element: 'NgxMatAuthRequestResetPasswordComponent', path: NpmPackage.NGX_MATERIAL_AUTH }]
@@ -317,9 +317,9 @@ export abstract class AngularUtilities {
317317
},
318318
domain
319319
);
320-
const confirmResetPasswordPageTs: string = getPath(pagesPath, 'confirm-reset-password', 'confirm-reset-password.component.ts');
320+
const confirmResetPasswordPageTs: Path = getPath(pagesPath, 'confirm-reset-password', 'confirm-reset-password.component.ts');
321321

322-
const confirmResetPasswordPageHtml: string = getPath(pagesPath, 'confirm-reset-password', 'confirm-reset-password.component.html');
322+
const confirmResetPasswordPageHtml: Path = getPath(pagesPath, 'confirm-reset-password', 'confirm-reset-password.component.html');
323323
await this.addComponentImports(
324324
confirmResetPasswordPageTs,
325325
[{ defaultImport: false, element: 'NgxMatAuthConfirmResetPasswordComponent', path: NpmPackage.NGX_MATERIAL_AUTH }]
@@ -358,8 +358,8 @@ export abstract class AngularUtilities {
358358
},
359359
domain
360360
);
361-
const adminsPageTs: string = getPath(pagesPath, 'admins', 'admins.component.ts');
362-
const adminsPageHtml: string = getPath(pagesPath, 'admins', 'admins.component.html');
361+
const adminsPageTs: Path = getPath(pagesPath, 'admins', 'admins.component.ts');
362+
const adminsPageHtml: Path = getPath(pagesPath, 'admins', 'admins.component.html');
363363
await FsUtilities.updateFile(
364364
adminsPageTs,
365365
adminsPageTsContent,
@@ -374,7 +374,7 @@ export abstract class AngularUtilities {
374374
],
375375
'replace'
376376
);
377-
const routesTs: string = getPath(projectRoot, 'src', 'app', ANGULAR_ROUTES_FILE_NAME);
377+
const routesTs: Path = getPath(projectRoot, 'src', 'app', ANGULAR_ROUTES_FILE_NAME);
378378
await TsUtilities.addImportStatements(
379379
routesTs,
380380
[
@@ -480,7 +480,7 @@ export abstract class AngularUtilities {
480480
provider: Provider | EnvironmentProviders | CustomTsValues,
481481
imports: TsImportDefinition[]
482482
): Promise<void> {
483-
const appConfigPath: string = getPath(root, 'src', 'app', APP_CONFIG_FILE_NAME);
483+
const appConfigPath: Path = getPath(root, 'src', 'app', APP_CONFIG_FILE_NAME);
484484

485485
const { result, contentString } = await TsUtilities.getArrayStartingWith(appConfigPath, 'providers: [');
486486

@@ -528,7 +528,7 @@ export abstract class AngularUtilities {
528528
await this.addNavElement(root, navElement);
529529
}
530530

531-
const sitemapPath: string = getPath(root, 'src', SITEMAP_FILE_NAME);
531+
const sitemapPath: Path = getPath(root, 'src', SITEMAP_FILE_NAME);
532532
const route: string | undefined = this.resolveInternalRoute(navElement);
533533
if (
534534
domain
@@ -566,7 +566,7 @@ export abstract class AngularUtilities {
566566
}
567567

568568
private static async addNavElement(projectPath: string, element: AddNavElementConfig): Promise<void> {
569-
const routesPath: string = getPath(projectPath, 'src', 'app', ANGULAR_ROUTES_FILE_NAME);
569+
const routesPath: Path = getPath(projectPath, 'src', 'app', ANGULAR_ROUTES_FILE_NAME);
570570

571571
const startIdentifier: ArrayStartIdentifier = this.getStartIdentifierForAddingNavElement(element);
572572
const { result, contentString } = await TsUtilities.getArrayStartingWith<typeof element.element>(routesPath, startIdentifier);
@@ -629,7 +629,7 @@ export abstract class AngularUtilities {
629629
'</urlset>'
630630
]);
631631

632-
const angularJsonPath: string = getPath(root, ANGULAR_JSON_FILE_NAME);
632+
const angularJsonPath: Path = getPath(root, ANGULAR_JSON_FILE_NAME);
633633
const currentAngularJson: AngularJson = await FsUtilities.parseFileAs(angularJsonPath);
634634
// eslint-disable-next-line stylistic/max-len
635635
const currentAssets: AngularJsonAssetPattern[] = currentAngularJson?.projects[projectName]?.architect?.['build'].options?.assets ?? [];
@@ -674,7 +674,7 @@ export abstract class AngularUtilities {
674674
],
675675
'append'
676676
);
677-
const appComponentTs: string = getPath(root, 'src', 'app', ANGULAR_APP_COMPONENT_FILE_NAME);
677+
const appComponentTs: Path = getPath(root, 'src', 'app', ANGULAR_APP_COMPONENT_FILE_NAME);
678678
await this.addComponentImports(
679679
appComponentTs,
680680
[
@@ -724,7 +724,7 @@ export abstract class AngularUtilities {
724724
}
725725
await FsUtilities.updateFile(appComponentTs, tsLines, 'replace');
726726

727-
const routesTs: string = getPath(root, 'src', 'app', ANGULAR_ROUTES_FILE_NAME);
727+
const routesTs: Path = getPath(root, 'src', 'app', ANGULAR_ROUTES_FILE_NAME);
728728
await FsUtilities.rename(
729729
getPath(root, 'src', 'app', 'app.routes.ts'),
730730
routesTs
@@ -825,7 +825,7 @@ export abstract class AngularUtilities {
825825
* @param path - The path of the ng-package.json.
826826
* @param data - The data to update with.
827827
*/
828-
static async updateNgPackageJson(path: string, data: Partial<NgPackageJson>): Promise<void> {
828+
static async updateNgPackageJson(path: Path, data: Partial<NgPackageJson>): Promise<void> {
829829
const oldData: NgPackageJson = await FsUtilities.parseFileAs(path);
830830
const updatedData: NgPackageJson = mergeDeep(oldData, data);
831831
await FsUtilities.updateFile(path, JsonUtilities.stringify(updatedData), 'replace', false);
@@ -836,13 +836,13 @@ export abstract class AngularUtilities {
836836
* @param path - The path of the angular.json.
837837
* @param data - The data to update with.
838838
*/
839-
static async updateAngularJson(path: string, data: DeepPartial<AngularJson>): Promise<void> {
839+
static async updateAngularJson(path: Path, data: DeepPartial<AngularJson>): Promise<void> {
840840
const oldData: AngularJson = await FsUtilities.parseFileAs(path);
841841
const newData: AngularJson = mergeDeep<AngularJson>(oldData, data);
842842
await FsUtilities.updateFile(path, JsonUtilities.stringify(newData), 'replace');
843843
}
844844

845-
private static async addComponentImports(componentPath: string, imports: TsImportDefinition[]): Promise<void> {
845+
private static async addComponentImports(componentPath: Path, imports: TsImportDefinition[]): Promise<void> {
846846
await TsUtilities.addImportStatements(componentPath, imports);
847847
let lines: string[] = await FsUtilities.readFileLines(componentPath);
848848
for (const imp of imports) {

0 commit comments

Comments
 (0)