Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 add generators to create community/event/podcast #314

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"ignorePatterns": ["**/*"],
"plugins": ["@nx", "html"],
"overrides": [
{
"files": "*.json",
"parser": "jsonc-eslint-parser",
"rules": {}
},
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
Expand Down
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"recommendations": [
"nrwl.angular-console",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint"
"dbaeumer.vscode-eslint",
"firsttris.vscode-jest-runner"
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eslint.validate": ["json"]
}
5 changes: 5 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { getJestProjectsAsync } from '@nx/jest';

export default async () => ({
projects: await getJestProjectsAsync(),
});
3 changes: 3 additions & 0 deletions jest.preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const nxPreset = require('@nx/jest/preset').default;

module.exports = { ...nxPreset };
25 changes: 25 additions & 0 deletions libs/plugin/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["./package.json", "./generators.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/nx-plugin-checks": "error"
}
}
]
}
11 changes: 11 additions & 0 deletions libs/plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# plugin

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build plugin` to build the library.

## Running unit tests

Run `nx test plugin` to execute the unit tests via [Jest](https://jestjs.io).
19 changes: 19 additions & 0 deletions libs/plugin/generators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"generators": {
"create-community": {
"factory": "./src/generators/create-community/generator",
"schema": "./src/generators/create-community/schema.json",
"description": "Create a new community"
},
"create-podcast": {
"factory": "./src/generators/create-podcast/generator",
"schema": "./src/generators/create-podcast/schema.json",
"description": "Create a new podcast"
},
"create-event": {
"factory": "./src/generators/create-event/generator",
"schema": "./src/generators/create-event/schema.json",
"description": "Create a new event"
}
}
}
10 changes: 10 additions & 0 deletions libs/plugin/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
export default {
displayName: 'plugin',
preset: '../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../coverage/libs/plugin',
};
13 changes: 13 additions & 0 deletions libs/plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@angular-hub/plugin",
"version": "0.0.1",
"dependencies": {
"@nx/devkit": "19.3.1",
"tslib": "^2.3.0"
},
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"private": true,
"generators": "./generators.json"
}
51 changes: 51 additions & 0 deletions libs/plugin/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "plugin",
"$schema": "../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/plugin/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/plugin",
"main": "libs/plugin/src/index.ts",
"tsConfig": "libs/plugin/tsconfig.lib.json",
"assets": [
"libs/plugin/*.md",
{
"input": "./libs/plugin/src",
"glob": "**/!(*.ts)",
"output": "./src"
},
{
"input": "./libs/plugin/src",
"glob": "**/*.d.ts",
"output": "./src"
},
{
"input": "./libs/plugin",
"glob": "generators.json",
"output": "."
},
{
"input": "./libs/plugin",
"glob": "executors.json",
"output": "."
}
]
}
},
"lint": {
"executor": "@nx/eslint:lint"
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/plugin/jest.config.ts"
}
}
}
}
20 changes: 20 additions & 0 deletions libs/plugin/src/generators/create-community/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, readProjectConfiguration } from '@nx/devkit';

import { createCommunityGenerator } from './generator';
import { CreateCommunityGeneratorSchema } from './schema';

describe('create-community generator', () => {
let tree: Tree;
const options: CreateCommunityGeneratorSchema = { name: 'test' };

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});

it('should run successfully', async () => {
await createCommunityGenerator(tree, options);
const config = readProjectConfiguration(tree, 'test');
expect(config).toBeDefined();
});
});
72 changes: 72 additions & 0 deletions libs/plugin/src/generators/create-community/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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, url, logo } = options;

if (!name) {
logger.error('[angular-hub] Name is missing');
return exit(1);
}

if (!type) {
logger.error('[angular-hub] Type is missing');
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)) {
logger.error(`[angular-hub] ${name} Community already exists`);
return exit(1);
}

updateJson(tree, COMMUNITIES_PATH, (communities: Community[]) => {
communities.push({
name,
type,
url: options.url ?? '',
location: options.location ?? '',
logo: options.logo ?? '',
twitter: options.twitter ?? '',
linkedin: options.linkedin ?? '',
callForPapers: options.callForPapers ?? '',
events: [],
});

return communities;
});

logger.info(
`[angular-hub] Community is added successfully. You can manually update the data if needed afterwards`,
);
}

function isCommunityExisting(communities: Community[], name: string): boolean {
return communities
.map((community) => community.name.toLowerCase())
.includes(name.toLowerCase());
}

export default createCommunityGenerator;
10 changes: 10 additions & 0 deletions libs/plugin/src/generators/create-community/schema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface CreateCommunityGeneratorSchema {
name: string;
type: 'workshop' | 'conference' | 'meetup' | 'other';
location?: string;
url?: string;
logo?: string;
twitter?: string;
linkedin?: string;
callForPapers?: string;
}
75 changes: 75 additions & 0 deletions libs/plugin/src/generators/create-community/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"$schema": "https://json-schema.org/schema",
"$id": "CreateCommunity",
"title": "",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Provide the community name",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What is the name of community?"
},
"type": {
"type": "string",
"enum": ["workshop", "conference", "meetup", "other"],
"description": "Provide the community type:",
"x-prompt": {
"message": "What is the type of community?",
"type": "list",
"items": [
{
"value": "workshop",
"label": "Workshop"
},
{
"value": "conference",
"label": "Conference"
},
{
"value": "meetup",
"label": "Meetup"
},
{
"value": "other",
"label": "Other"
}
]
}
},
"location": {
"type": "string",
"description": "Provide the location where community takes place",
"x-prompt": "Provide the community location:"
},
"url": {
"type": "string",
"description": "Provide the site url",
"x-prompt": "Provide the site url:"
},
"logo": {
"type": "string",
"description": "Provide the brand logo",
"x-prompt": "Provide the brand logo url:"
},
"twitter": {
"type": "string",
"description": "Provide the twitter account link",
"x-prompt": "Provide the twitter profile:"
},
"linkedin": {
"type": "string",
"description": "Provide the linkedin account link",
"x-prompt": "Provide the linkedin profile:"
},
"callForPapers": {
"type": "string",
"description": "Provide the Call-For-Paper (CFP) form url",
"x-prompt": "Provide the CFP form url:"
}
},
"required": ["name", "type"]
}
20 changes: 20 additions & 0 deletions libs/plugin/src/generators/create-event/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, readProjectConfiguration } from '@nx/devkit';

import { createEventGenerator } from './generator';
import { CreateEventGeneratorSchema } from './schema';

describe('create-event generator', () => {
let tree: Tree;
const options: CreateEventGeneratorSchema = { name: 'test' };

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});

it('should run successfully', async () => {
await createEventGenerator(tree, options);
const config = readProjectConfiguration(tree, 'test');
expect(config).toBeDefined();
});
});
Loading
Loading