Skip to content

Commit

Permalink
refactor: moved automation to libs
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarco committed May 5, 2024
1 parent cdfcd82 commit 7f53872
Show file tree
Hide file tree
Showing 33 changed files with 119 additions and 302 deletions.
3 changes: 1 addition & 2 deletions .idea/nx-angular-config.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .source
Submodule .source deleted from 9b5c34
42 changes: 0 additions & 42 deletions automation/.eslintrc.base.json

This file was deleted.

35 changes: 0 additions & 35 deletions automation/.eslintrc.json

This file was deleted.

3 changes: 0 additions & 3 deletions automation/.prettierrc

This file was deleted.

11 changes: 0 additions & 11 deletions automation/jest.config.ts

This file was deleted.

3 changes: 0 additions & 3 deletions automation/jest.preset.js

This file was deleted.

Empty file removed automation/src/index.ts
Empty file.
35 changes: 0 additions & 35 deletions automation/tools/scripts/start-local-registry.ts

This file was deleted.

10 changes: 0 additions & 10 deletions automation/tools/scripts/stop-local-registry.ts

This file was deleted.

2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"npmClient": "pnpm",
"useNx": true,
"useWorkspaces": true,
"packages": ["apps/*", "libs/*", "packages/*", "enterprise/packages/*", "enterprise/packages/*/*", "providers/*","automation"],
"packages": ["apps/*", "libs/*", "packages/*", "enterprise/packages/*", "enterprise/packages/*/*", "providers/*"],
"command": {
"publish": {
"message": "chore(release): publish - ci skip"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions automation/package.json → libs/automation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"version": "0.24.1",
"license": "MIT",
"scripts": {
"generate:provider": "pnpm nx g automation:provider"
"generate:provider": "pnpm nx g automation:provider",
"fix:lint": "eslint src --ext .ts --fix"

},
"dependencies": {
"@nx/devkit": "^16.10.0",
"tslib": "^2.3.0"
"@nx/devkit": "^16.10.0"
},
"devDependencies": {
"@nx/js": "^16.10.0",
Expand Down
7 changes: 1 addition & 6 deletions automation/project.json → libs/automation/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"./src",
"{projectRoot}/package.json",
"./package.json",
"generators.json"
]
"lintFilePatterns": ["./src", "{projectRoot}/package.json", "./package.json", "generators.json"]
}
},
"test": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
import {
addProjectConfiguration,
formatFiles,
generateFiles,
Tree,
} from '@nx/devkit';
import { ProviderGeneratorSchema } from './schema';
import { addProjectConfiguration, formatFiles, generateFiles, Tree } from '@nx/devkit';
import { IProviderGeneratorSchema } from './schema';
import * as fs from 'node:fs';
import * as path from 'node:path';

const PROVIDERS_BASE_FOLDER = path.join(
'..',
'packages',
'providers',
'src',
'lib'
);
const PROVIDERS_BASE_FOLDER = path.join('..', '..', 'packages', 'providers', 'src', 'lib');

export async function providerGenerator(
tree: Tree,
options: ProviderGeneratorSchema
) {
export async function providerGenerator(tree: Tree, options: IProviderGeneratorSchema) {
options = enrichOptionsWithMultipleCases(options);
const providerNameInKebabCase = options.name;
const providerInnerFolder = path.join(
PROVIDERS_BASE_FOLDER,
providerNameInKebabCase
);
const providerInnerFolder = path.join(PROVIDERS_BASE_FOLDER, providerNameInKebabCase);
buildAndAddProjectConfiguration(tree, options, providerInnerFolder);
generateFilesBasedOnTemplate(tree, providerInnerFolder, options);
addExportToIndexTs(providerNameInKebabCase);
Expand All @@ -37,6 +20,7 @@ function repopulateFileWithNewLine(filePath, lines: string[]) {
fs.writeFile(filePath, lines.join('\n') + '\n', 'utf8', (err) => {
if (err) {
console.error('Error writing to file:', err);

return;
}
console.log('Line added successfully.');
Expand All @@ -47,6 +31,7 @@ function addLineToFile(filePath, lineToAdd) {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);

return;
}
const lines = data.split('\n');
Expand All @@ -67,7 +52,7 @@ function toPascalCase(kebabString) {
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join('');
}
function enrichOptionsWithMultipleCases(options: ProviderGeneratorSchema) {
function enrichOptionsWithMultipleCases(options: IProviderGeneratorSchema) {
return {
...options,
pascalType: toPascalCase(options.type),
Expand All @@ -76,11 +61,7 @@ function enrichOptionsWithMultipleCases(options: ProviderGeneratorSchema) {
};
}

function buildAndAddProjectConfiguration(
tree: Tree,
options: ProviderGeneratorSchema,
projectRoot: string
) {
function buildAndAddProjectConfiguration(tree: Tree, options: IProviderGeneratorSchema, projectRoot: string) {
addProjectConfiguration(tree, options.name, {
root: projectRoot,
projectType: 'library',
Expand All @@ -102,11 +83,7 @@ function removeDefaultProjectJsonFromTree(tree: Tree, projectRoot: string) {
tree.delete(projectRoot + '/project.json');
}

function generateFilesBasedOnTemplate(
tree: Tree,
projectRoot: string,
options: ProviderGeneratorSchema
) {
function generateFilesBasedOnTemplate(tree: Tree, projectRoot: string, options: IProviderGeneratorSchema) {
generateFiles(tree, path.join(__dirname, 'files'), projectRoot, options);
}
export default providerGenerator;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface ProviderGeneratorSchema {
export interface IProviderGeneratorSchema {
name: string;
type: string;
pascalType: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
"$source": "argv",
"index": 0
},
"enum": [
"EMAIL",
"SMS",
"PUSH",
"CHAT"
]
"enum": ["EMAIL", "SMS", "PUSH", "CHAT"]
}
},
"required": ["name"]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"commit": "cz",
"nx": "nx",
"lint-staged": "lint-staged",
"generate:provider": "cd automation && npm run generate:provider",
"generate:provider": "cd libs/automation && npm run generate:provider",
"lint": "nx run-many --target=lint --all",
"test": "cross-env CI=true lerna run test:watch --parallel",
"start:dev": "cross-env TZ=UTC lerna run start:dev --stream --parallel --concurrency=20 --scope=@novu/{api,worker,web,widget,ws,notification-center}",
Expand Down Expand Up @@ -149,7 +149,6 @@
"packages": [
"apps/*",
"libs/*",
"automation",
"packages/*",
"enterprise/packages/*",
"enterprise/packages/*/*",
Expand Down

0 comments on commit 7f53872

Please sign in to comment.