Skip to content

Commit

Permalink
feat: add checks for url and logo
Browse files Browse the repository at this point in the history
  • Loading branch information
ilirbeqirii committed Jun 28, 2024
1 parent 866fa51 commit ceb227f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
24 changes: 15 additions & 9 deletions plugin/src/generators/create-community/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@ import { logger, readJson, Tree, updateJson } from '@nx/devkit';
import { CreateCommunityGeneratorSchema } from './schema';
import { exit } from 'node:process';
import { Community } from '../models/community';
import { isPublicAsset } from '../utils/isPublicAsset';

const COMMUNITIES_PATH = 'angular-hub/src/public/assets/data/community.json';

export async function createCommunityGenerator(
tree: Tree,
options: CreateCommunityGeneratorSchema,
) {
const { name, type } = options;

const packageJson = readJson(tree, 'package.json');
const angularCorePackage = packageJson['dependencies']['@angular/core'];

if (!angularCorePackage) {
logger.error(`[angular-hub] No @angular/core detected`);
return exit(1);
}
const { name, type, url, logo } = options;

if (!name) {
logger.error('[angular-hub] Name is missing');
Expand All @@ -29,6 +22,19 @@ export async function createCommunityGenerator(
return exit(1);
}

if (url && !isPublicAsset(url)) {
logger.error(
'[angular-hub] Url is not valid (should start with https or http). ',
);
return exit(1);
}

if (logo && !isPublicAsset(logo)) {
logger.info(
'[angular-hub] Make sure you upload the logo file at logos folder in the assets directory',
);
}

const existingCommunities: Community[] = readJson(tree, COMMUNITIES_PATH);

if (isCommunityExisting(existingCommunities, name)) {
Expand Down
8 changes: 0 additions & 8 deletions plugin/src/generators/create-event/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ export async function createEventGenerator(
tree: Tree,
options: CreateEventGeneratorSchema,
) {
const packageJson = readJson(tree, 'package.json');
const angularCorePackage = packageJson['dependencies']['@angular/core'];

if (!angularCorePackage) {
logger.error(`[angular-hub] No @angular/core detected`);
return exit(1);
}

if (!options.communityName) {
logger.error('[angular-hub] Community name is missing');
return exit(1);
Expand Down
22 changes: 14 additions & 8 deletions plugin/src/generators/create-podcast/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logger, readJson, Tree, updateJson } from '@nx/devkit';
import { CreatePodcastGeneratorSchema } from './schema';
import { exit } from 'node:process';
import { Podcast } from '../models/podcast';
import { isPublicAsset } from '../utils/isPublicAsset';

const PODCASTS_PATH = 'angular-hub/src/public/assets/data/podcast.json';

Expand All @@ -11,14 +12,6 @@ export async function createPodcastGenerator(
) {
const { name, logo, language, url } = options;

const packageJson = readJson(tree, 'package.json');
const angularCorePackage = packageJson['dependencies']['@angular/core'];

if (!angularCorePackage) {
logger.error(`[angular-hub] No @angular/core detected`);
return exit(1);
}

if (!name) {
logger.error('[angular-hub] Name is missing');
return exit(1);
Expand All @@ -39,6 +32,19 @@ export async function createPodcastGenerator(
return exit(1);
}

if (!isPublicAsset(url)) {
logger.error(
'[angular-hub] Url is not valid (should start with https or http). ',
);
return exit(1);
}

if (!isPublicAsset(logo)) {
logger.info(
'[angular-hub] Make sure you upload the logo file at logos folder in the assets directory',
);
}

const existingPodcasts: Podcast[] = readJson(tree, PODCASTS_PATH);

if (isPodcastExisting(existingPodcasts, name)) {
Expand Down
3 changes: 3 additions & 0 deletions plugin/src/generators/utils/isPublicAsset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isPublicAsset(assetLink: string): boolean {
return assetLink.startsWith('https://') || assetLink.startsWith('https://');
}

0 comments on commit ceb227f

Please sign in to comment.