From 1b0e3f48dc0e8228e94b04ad78b9043a1dfa1ab3 Mon Sep 17 00:00:00 2001 From: Vikram Chand Date: Tue, 19 Mar 2024 16:39:37 +0530 Subject: [PATCH] Updated: theme, taxonomy and user command --- src/commands/cms/t-make.ts | 149 +++++++++++++++++++++++++++++ src/commands/cms/t.ts | 100 ++++++++++++++++++++ src/commands/cms/taxonomies.ts | 167 +++++++++++++++++++++++++++++++++ src/commands/cms/users.ts | 144 ++++++++++++++++++++++++++++ 4 files changed, 560 insertions(+) create mode 100644 src/commands/cms/t-make.ts create mode 100644 src/commands/cms/t.ts create mode 100644 src/commands/cms/taxonomies.ts create mode 100644 src/commands/cms/users.ts diff --git a/src/commands/cms/t-make.ts b/src/commands/cms/t-make.ts new file mode 100644 index 0000000..5c25dbb --- /dev/null +++ b/src/commands/cms/t-make.ts @@ -0,0 +1,149 @@ +import {Args, Command, Flags} from '@oclif/core' +const Listr = require('listr'); + +import Generator from "../../libraries/Generator"; +import Helpers from "../../libraries/Helpers"; +import Functions from '../../libraries/Functions' + + +const chalk = require('chalk'); + + + +export default class CmsTMake extends Command { + questions: {[k: string]: any} = {}; + args: {[k: string]: any} = {}; + flags: {[k: string]: any} = {}; + inputs: {[k: string]: any} = {}; + + + static description = 'Generate for VaahCMS Theme'; + + + /* + *--------------------------------------------------- + * Command Flags/Options + *--------------------------------------------------- + */ + static flags = { + frontend: Flags.boolean({ + char: 'f', + default: true, + }), + backend: Flags.boolean({ + char: 'b', + default: false, + }), + help: Flags.help({char: 'h'}), + name: Flags.help({char: 'n'}), + }; + + + /* + *--------------------------------------------------- + * Command Arguments + *--------------------------------------------------- + */ + static args = { + type: Args.string({ + required: true, + options: [ + 'migration', + 'seed', + 'model', + 'controller', + 'view', + 'middleware', + 'observer', + 'trait', + 'test', + 'event', + 'listener', + 'mail', + 'notification', + ] + }), + theme: Args.string({ + required: true, + }), + name: Args.string({ + required: true, + }) + }; + + + /* + *--------------------------------------------------- + * Command Execution + *--------------------------------------------------- + */ + async run() { + + let functions = new Functions(); + let is_updates_available = await functions.isUpdatesAvailable(); + if(is_updates_available) + { + return true; + } + + const {args, flags} = await this.parse(CmsTMake); + + this.args = args; + this.flags = flags; + this.inputs['for'] = 'theme'; + + let helpers = new Helpers(this.args, this.flags, this.inputs); + + let params: any = helpers.getDerivedVariables(); + + + + for(let key in params) + { + this.inputs[key] = params[key]; + } + + for(let key in this.args) + { + this.inputs[key] = this.args[key]; + } + + for(let key in this.flags) + { + this.inputs[key] = this.flags[key]; + } + + let source = '/skeletons/vaahcms/theme-files/'; + + + let generator = new Generator(args, flags, this.inputs, source, this.inputs['target_dir']); + + + this.log(chalk.green('=======================================')); + this.log('Generating Files for Theme: '+chalk.green(this.args.theme)); + this.log(chalk.green('---------------------------------------')); + + + const tasks = new Listr([ + { + title: 'File Generated', + task: function () { + generator.file(); + } + } + ]); + + + + tasks.run().then((ctx: any) => { + this.log(chalk.green('=======================================')); + }).catch((err: any) => { + console.error(err); + }); + + + + } + + +} diff --git a/src/commands/cms/t.ts b/src/commands/cms/t.ts new file mode 100644 index 0000000..358df89 --- /dev/null +++ b/src/commands/cms/t.ts @@ -0,0 +1,100 @@ +import {Args, Command, Flags} from '@oclif/core' +const inquirer = require('inquirer') +const Listr = require('listr'); + +import Questions from "../../libraries/Questions"; +import Generator from "../../libraries/Generator"; +import Functions from '../../libraries/Functions' + + +const chalk = require('chalk'); + + +export default class CmsT extends Command { + + questions: {[k: string]: any} = {}; + inputs: {[k: string]: any} = {}; + + + static description = 'To generate theme for VaahCMS'; + + + /* + *--------------------------------------------------- + * Command Flags/Options + *--------------------------------------------------- + */ + static flags = { + help: Flags.help({char: 'h'}), + name: Flags.help({char: 'n'}), + force: Flags.boolean({char: 'f'}), + }; + + + /* + *--------------------------------------------------- + * Command Arguments + *--------------------------------------------------- + */ + static args = {}; + + + /* + *--------------------------------------------------- + * Command Execution + *--------------------------------------------------- + */ + + async run() { + + let functions = new Functions(); + let is_updates_available = await functions.isUpdatesAvailable(); + if(is_updates_available) + { + return true; + } + + const {args, flags} = await this.parse(CmsT); + + let questions = new Questions(); + + this.inputs = await inquirer.prompt(questions.getVaahCmsThemeQuestions()); + + this.inputs['webpack_port'] = functions.generateRandom(8000, 8999); + + this.inputs['namespace'] = 'VaahCms\\Themes\\'+this.inputs.theme_name; + this.inputs['service_provider_name'] = this.inputs.theme_name+'ServiceProvider.php'; + + this.inputs['year'] = (new Date()).getFullYear(); + + let source = '/skeletons/vaahcms/theme/'; + let target = "./VaahCms/Themes/"+this.inputs.theme_name; + + let generator = new Generator(args, flags, this.inputs, source, target); + + + this.log(chalk.green('=======================================')); + this.log('Generating Theme: '+chalk.green(this.inputs.theme_name)); + this.log(chalk.green('---------------------------------------')); + + + const tasks = new Listr([ + { + title: 'Files Generated', + task: function () { + generator.files(); + + } + } + ]); + + + tasks.run().then((ctx: any) => { + this.log(chalk.green('=======================================')); + }).catch((err: any) => { + console.error(err); + }); + + + } +} diff --git a/src/commands/cms/taxonomies.ts b/src/commands/cms/taxonomies.ts new file mode 100644 index 0000000..3909767 --- /dev/null +++ b/src/commands/cms/taxonomies.ts @@ -0,0 +1,167 @@ +import {Args, Command, Flags} from '@oclif/core' +import Questions from '../../libraries/Questions' +const inquirer = require('inquirer') +import Generator from '../../libraries/Generator' +import Helpers from '../../libraries/Helpers' +import Functions from '../../libraries/Functions' + +let fs = require('fs'); +let ora = require('ora'); +const execa = require('execa'); +const Listr = require('listr'); +var shell = require('shelljs'); +const { exec } = require('child_process'); +let fsSync = require('fs-sync'); +const fsPromises = fs.promises; + +const chalk = require('chalk'); + +export default class CmsCrud extends Command { + + args: {[k: string]: any} = {}; + flags: {[k: string]: any} = {}; + primary: {[k: string]: any} = {}; + inputs: {[k: string]: any} = {}; + primary_inputs: {[k: string]: any} = {}; + spinner: {[k: string]: any} = {}; + repo: string = 'https://github.com/webreinvent/vaahcms-ready'; + target_dir: string = './'; + source_dir: string = ''; + + static description = 'Vue 3: Generate Taxonomies CRUD operations for VaahCMS' + + /* + *--------------------------------------------------- + * Command Flags/Options + *--------------------------------------------------- + */ + static flags = { + help: Flags.boolean({ + description: 'Vue 3: Generate Taxonomies CRUD operations for VaahCMS', + default: false, + }), + }; + + /* + *--------------------------------------------------- + * Command Arguments + *--------------------------------------------------- + */ + static args = {}; + + /* + *--------------------------------------------------- + * Command Execution + *--------------------------------------------------- + */ + async run() { + + this.log(chalk.white.bgGreen.bold(" This command are only for Vue 3 module ")); + + let functions = new Functions(); + let is_updates_available = await functions.isUpdatesAvailable(); + if(is_updates_available) + { + return true; + } + + + const {args, flags} = await this.parse(CmsCrud) + + let questions = new Questions(); + + this.primary = await inquirer.prompt(questions.getVue3CrudQuestionsPrimary()); + + let get_primary_questions = questions.getTaxonomyQuestionsPrimary(this.primary.for); + + this.primary_inputs = await inquirer.prompt(get_primary_questions); + + let get_questions = questions.getTaxonomyQuestions(this.primary_inputs.generate_migration); + + this.inputs = await inquirer.prompt(get_questions); + + this.inputs = { + ...this.primary_inputs, + ...this.inputs + }; + + this.inputs.for = this.primary.for; + + let target = ""; + let source = '/skeletons/vaahcms/taxonomies/'; + this.inputs['namespace_controller'] = ''; + + this.inputs['namespace'] = 'VaahCms\\Modules\\'+this.inputs.folder_name; + target = "./VaahCms/Modules/"+this.inputs.folder_name; + + if(this.inputs.for == 'Custom Path') { + this.inputs['namespace_controller'] = this.inputs['namespace'] + '\\Http\\Controllers'; + target = this.inputs.path; + } + if(this.primary_inputs.generate_migration !== 'true') { + this.inputs['table_name'] = 'vh_taxonomies'; + this.inputs['second_table_name'] = 'vh_taxonomy_types'; + this.inputs['second_table_name_singular'] = 'vh_taxonomy_type'; + } + + + let generator = new Generator(args, flags, this.inputs, source, target); + + this.log(chalk.green('=======================================')); + this.log('Generating CRUD Files'); + this.log(chalk.green('---------------------------------------')); + + const tasks = new Listr([ + { + title: 'Files Generated for CRUD operations', + task: function () { + generator.generateCrudFiles(); + } + } + ]); + + let self = this; + + tasks.run().then((ctx: any) => { + self.successMessage(); + }).catch((err: any) => { + console.error(err); + }); + + } + + //--------------------------------------------------- + successMessage() + { + + let n = 1; + + this.log(chalk.white.bgGreen.bold(" Files Generated! ")); + this.log(chalk.green("==================================================================")); + this.log(chalk.green("Now, follow following steps:")); + + if(this.inputs['generate_migration'] === 'true') + { + this.log(n+++") Update the migration file with the table name and columns"); + this.log(n+++") Re-activate module to run migrations"); + } + + this.log(n+++") Run "+chalk.green("npm install --save @grapoza/vue-tree")+" command in "+this.inputs['namespace']+"\\Vue directory"); + this.log(n+++") Include the crud router file in the module's backend route file"); + this.log(n+++") Include the vue router file"); + + if(this.inputs.for == 'Module') + { + this.log(n+++") Add vue router link to you /Vue/Components/Aside.vue file"); + } + + + this.log(chalk.green("==================================================================")); + + } + + //--------------------------------------------------- + //--------------------------------------------------- + + +} diff --git a/src/commands/cms/users.ts b/src/commands/cms/users.ts new file mode 100644 index 0000000..75c8129 --- /dev/null +++ b/src/commands/cms/users.ts @@ -0,0 +1,144 @@ +import {Args, Command, Flags} from '@oclif/core' +import Questions from '../../libraries/Questions' +const inquirer = require('inquirer') +import Generator from '../../libraries/Generator' +import Helpers from '../../libraries/Helpers' +import Functions from '../../libraries/Functions' + +let fs = require('fs'); +let ora = require('ora'); +const execa = require('execa'); +const Listr = require('listr'); +var shell = require('shelljs'); +const { exec } = require('child_process'); +let fsSync = require('fs-sync'); +const fsPromises = fs.promises; + +const chalk = require('chalk'); + +export default class CmsCrud extends Command { + + args: {[k: string]: any} = {}; + flags: {[k: string]: any} = {}; + primary: {[k: string]: any} = {}; + inputs: {[k: string]: any} = {}; + spinner: {[k: string]: any} = {}; + repo: string = 'https://github.com/webreinvent/vaahcms-ready'; + target_dir: string = './'; + source_dir: string = ''; + + static description = 'Vue3: Generate User CRUD for VaahCMS' + + /* + *--------------------------------------------------- + * Command Flags/Options + *--------------------------------------------------- + */ + static flags = { + help: Flags.boolean({ + description: 'Vue3: Generate User CRUD for VaahCMS', + default: false, + }), + }; + + /* + *--------------------------------------------------- + * Command Arguments + *--------------------------------------------------- + */ + static args = {}; + + /* + *--------------------------------------------------- + * Command Execution + *--------------------------------------------------- + */ + async run() { + + this.log(chalk.white.bgGreen.bold(" This command are only for Vue 3 module ")); + + let functions = new Functions(); + let is_updates_available = await functions.isUpdatesAvailable(); + if(is_updates_available) + { + return true; + } + + + const {args, flags} = await this.parse(CmsCrud) + + let questions = new Questions(); + + this.primary = await inquirer.prompt(questions.getVue3CrudQuestionsPrimary()); + + let get_questions = questions.getUserQuestions(this.primary.for); + + this.inputs = await inquirer.prompt(get_questions); + + this.inputs.for = this.primary.for; + + let target = ""; + let source = '/skeletons/vaahcms/users/'; + this.inputs['namespace_controller'] = ''; + + this.inputs['namespace'] = 'VaahCms\\Modules\\'+this.inputs.folder_name; + target = "./VaahCms/Modules/"+this.inputs.folder_name; + + if(this.inputs.for == 'Custom Path') { + this.inputs['namespace_controller'] = this.inputs['namespace'] + '\\Http\\Controllers'; + target = this.inputs.path; + } + + let generator = new Generator(args, flags, this.inputs, source, target); + + this.log(chalk.green('=======================================')); + this.log('Vue 3: Generating User CRUD Files'); + this.log(chalk.green('---------------------------------------')); + + const tasks = new Listr([ + { + title: 'Files Generated for User CRUD operations', + task: function () { + generator.generateCrudFiles(); + } + } + ]); + + let self = this; + + tasks.run().then((ctx: any) => { + self.successMessage(); + }).catch((err: any) => { + console.error(err); + }); + + } + + //--------------------------------------------------- + successMessage() + { + + let n = 1; + + this.log(chalk.white.bgGreen.bold(" Files Generated! ")); + this.log(chalk.green("==================================================================")); + this.log(chalk.green("Now, follow following steps:")); + + this.log(n+++") Include the crud router file in the module's backend route file"); + this.log(n+++") Include the vue router file"); + + if(this.inputs.for == 'Module') + { + this.log(n+++") Add vue router link to you /Vue/Components/Aside.vue file"); + } + + + this.log(chalk.green("==================================================================")); + + } + + //--------------------------------------------------- + //--------------------------------------------------- + + +}