From e894ee6be4d868c970fb3f8746a2cb28d6635ada Mon Sep 17 00:00:00 2001 From: Masum ULU Date: Thu, 14 Sep 2023 14:42:27 +0300 Subject: [PATCH] Create change theme generator and options --- .../packages/generators/generators.json | 5 +++ .../generators/change-theme/generator.spec.ts | 20 ++++++++++ .../src/generators/change-theme/generator.ts | 22 +++++++++++ .../src/generators/change-theme/index.ts | 3 ++ .../src/generators/change-theme/schema.d.ts | 4 ++ .../src/generators/change-theme/schema.json | 37 +++++++++++++++++++ .../change-theme/theme-options.enum.ts | 8 ++++ npm/ng-packs/packages/generators/src/index.ts | 4 +- 8 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 npm/ng-packs/packages/generators/src/generators/change-theme/generator.spec.ts create mode 100644 npm/ng-packs/packages/generators/src/generators/change-theme/generator.ts create mode 100644 npm/ng-packs/packages/generators/src/generators/change-theme/index.ts create mode 100644 npm/ng-packs/packages/generators/src/generators/change-theme/schema.d.ts create mode 100644 npm/ng-packs/packages/generators/src/generators/change-theme/schema.json create mode 100644 npm/ng-packs/packages/generators/src/generators/change-theme/theme-options.enum.ts diff --git a/npm/ng-packs/packages/generators/generators.json b/npm/ng-packs/packages/generators/generators.json index 8910e6fdba..4f41032144 100644 --- a/npm/ng-packs/packages/generators/generators.json +++ b/npm/ng-packs/packages/generators/generators.json @@ -9,6 +9,11 @@ "factory": "./src/generators/update-version/generator", "schema": "./src/generators/update-version/schema.json", "description": "update-version generator" + }, + "change-theme": { + "factory": "./src/generators/change-theme/generator", + "schema": "./src/generators/change-theme/schema.json", + "description": "change-theme generator" } } } diff --git a/npm/ng-packs/packages/generators/src/generators/change-theme/generator.spec.ts b/npm/ng-packs/packages/generators/src/generators/change-theme/generator.spec.ts new file mode 100644 index 0000000000..940c5dbe3b --- /dev/null +++ b/npm/ng-packs/packages/generators/src/generators/change-theme/generator.spec.ts @@ -0,0 +1,20 @@ +import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; +import { Tree, readProjectConfiguration } from '@nx/devkit'; + +import { changeThemeGenerator } from './generator'; +import { ChangeThemeGeneratorSchema } from './schema'; + +describe('change-theme generator', () => { + let tree: Tree; + const options: ChangeThemeGeneratorSchema = { name: 'test' }; + + beforeEach(() => { + tree = createTreeWithEmptyWorkspace(); + }); + + it('should run successfully', async () => { + await changeThemeGenerator(tree, options); + const config = readProjectConfiguration(tree, 'test'); + expect(config).toBeDefined(); + }); +}); diff --git a/npm/ng-packs/packages/generators/src/generators/change-theme/generator.ts b/npm/ng-packs/packages/generators/src/generators/change-theme/generator.ts new file mode 100644 index 0000000000..14d2e8e68e --- /dev/null +++ b/npm/ng-packs/packages/generators/src/generators/change-theme/generator.ts @@ -0,0 +1,22 @@ +import { Tree } from '@nx/devkit'; +import { wrapAngularDevkitSchematic } from '@nx/devkit/ngcli-adapter'; +import { ChangeThemeGeneratorSchema } from './schema'; +import { ThemeOptionsEnum } from './theme-options.enum'; + +export async function changeThemeGenerator(host: Tree, schema: ChangeThemeGeneratorSchema) { + const runAngularLibrarySchematic = wrapAngularDevkitSchematic( + '@abp/ng.schematics', + 'change-theme', + ); + + await runAngularLibrarySchematic(host, { + ...schema, + }); + + return () => { + const destTheme = Object.values(ThemeOptionsEnum).find((t, i) => i + 1 === schema.name); + console.log(`✅️ theme changed to ${destTheme}`); + }; +} + +export default changeThemeGenerator; diff --git a/npm/ng-packs/packages/generators/src/generators/change-theme/index.ts b/npm/ng-packs/packages/generators/src/generators/change-theme/index.ts new file mode 100644 index 0000000000..05ffcdcc9b --- /dev/null +++ b/npm/ng-packs/packages/generators/src/generators/change-theme/index.ts @@ -0,0 +1,3 @@ +export * from './theme-options.enum'; +export * from './schema'; +export * from './generator'; diff --git a/npm/ng-packs/packages/generators/src/generators/change-theme/schema.d.ts b/npm/ng-packs/packages/generators/src/generators/change-theme/schema.d.ts new file mode 100644 index 0000000000..9ee931564e --- /dev/null +++ b/npm/ng-packs/packages/generators/src/generators/change-theme/schema.d.ts @@ -0,0 +1,4 @@ +export interface ChangeThemeGeneratorSchema { + name: number; + targetOption: string; +} diff --git a/npm/ng-packs/packages/generators/src/generators/change-theme/schema.json b/npm/ng-packs/packages/generators/src/generators/change-theme/schema.json new file mode 100644 index 0000000000..fe356e00ae --- /dev/null +++ b/npm/ng-packs/packages/generators/src/generators/change-theme/schema.json @@ -0,0 +1,37 @@ +{ + "$schema": "http://json-schema.org/schema", + "$id": "SchematicsABPThemeChanger", + "title": "ABP Theme Style Generator API Schema", + "type": "object", + "properties": { + "name": { + "description": "The name of theme will change.", + "type": "number", + "$default": { + "$source": "argv", + "index": 0 + }, + "enum": [1, 2, 3, 4], + "x-prompt": { + "message": "Which theme would you like to use?", + "type": "list", + "items": [ + { "value": 1, "label": "Basic" }, + { "value": 2, "label": "Lepton" }, + { "value": 3, "label": "LeptonXLite" }, + { "value": 4, "label": "LeptonX" } + ] + } + }, + "targetProject": { + "description": "The name of the project will change the style.The project type must be 'application'", + "type": "string", + "x-prompt": "Please enter the project name", + "$default": { + "$source": "argv", + "index": 1 + } + } + }, + "required": ["name", "targetProject"] +} diff --git a/npm/ng-packs/packages/generators/src/generators/change-theme/theme-options.enum.ts b/npm/ng-packs/packages/generators/src/generators/change-theme/theme-options.enum.ts new file mode 100644 index 0000000000..a64487ed8f --- /dev/null +++ b/npm/ng-packs/packages/generators/src/generators/change-theme/theme-options.enum.ts @@ -0,0 +1,8 @@ +// this enum create by https://raw.githubusercontent.com/abpframework/abp/rel-7.4/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Theme.cs + +export enum ThemeOptionsEnum { + Basic = 1, + Lepton = 2, + LeptonXLite = 3, + LeptonX = 4, +} diff --git a/npm/ng-packs/packages/generators/src/index.ts b/npm/ng-packs/packages/generators/src/index.ts index 9a6fb02c00..a2ce5894d3 100644 --- a/npm/ng-packs/packages/generators/src/index.ts +++ b/npm/ng-packs/packages/generators/src/index.ts @@ -1 +1,3 @@ -export * from './generators/generate-proxy' \ No newline at end of file +export * from './generators/change-theme'; +export * from './generators/generate-proxy'; +export * from './generators/update-version';