Skip to content

Commit

Permalink
Updated: crud command
Browse files Browse the repository at this point in the history
  • Loading branch information
we-vikram-wri231 committed Mar 19, 2024
1 parent a95942d commit 02ff061
Show file tree
Hide file tree
Showing 3 changed files with 469 additions and 1 deletion.
166 changes: 166 additions & 0 deletions src/commands/cms/crud.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import {Command, Flags} from '@oclif/core'
import Questions from '../../libraries/Questions'
const inquirer = require('inquirer')
import Generator from '../../libraries/Generator'
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 = 'Generate CRUD operations for VaahCMS'

/*
*---------------------------------------------------
* Command Flags/Options
*---------------------------------------------------
*/
static flags = {
help: Flags.boolean({
description: 'Generate CRUD operation for VaahCMS',
default: false,
}),
};

/*
*---------------------------------------------------
* 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(CmsCrud)

let questions = new Questions();

this.primary = await inquirer.prompt(questions.getCrudQuestionsPrimary());

let get_questions = questions.getCrudQuestions(this.primary.for);

this.inputs = await inquirer.prompt(get_questions);

this.inputs.for = this.primary.for;

let target = "";
let source = '\\skeletons\\vaahcms\\crud\\';
this.inputs['namespace_controller'] = '';

if(this.inputs.for == 'Module - Vue3 & PrimeVue')
{
source = '\\skeletons\\vaahcms\\crud-vue3\\';
this.inputs['namespace'] = 'VaahCms\\Modules\\'+this.inputs.folder_name;
target = "./VaahCms/Modules/"+this.inputs.folder_name;

} else if(this.inputs.for == 'Module - Vue2 & Buefy'){

source = '\\skeletons\\vaahcms\\crud\\';
this.inputs['namespace'] = 'VaahCms\\Modules\\'+this.inputs.folder_name;
target = "./VaahCms/Modules/"+this.inputs.folder_name;

} else if(this.inputs.for == 'Theme')
{
this.inputs['namespace'] = 'VaahCms\\Themes\\'+this.inputs.folder_name;
target = "./VaahCms/Themes/"+this.inputs.folder_name;
} else{
source = '\\skeletons\\vaahcms\\crud-vue3\\';
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('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()
{

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("0.1) Update the migration file with the table name and columns");
this.log("0.2) Re-activate module to run migrations");
}

this.log("2) Include the crud router file in the module's backend route file");
this.log("3) Include the vue router file");

if(this.inputs.for == 'Module - Vue2 & Buefy')
{
this.log("4) Include the vue store file");
this.log("5) Add vue router link to you menu");
}

if(this.inputs.for == 'Module - Vue3 & PrimeVue')
{
this.log("6) Add vue router link to you <module>/Vue/Components/Aside.vue file");
}


this.log(chalk.green("=================================================================="));

}

//---------------------------------------------------
//---------------------------------------------------


}
1 change: 0 additions & 1 deletion src/libraries/Functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const chalk = require('chalk');
var semver = require('semver');
const package_json = require("./../../package.json");


const log = console.log;

export default class Helpers {
Expand Down
Loading

0 comments on commit 02ff061

Please sign in to comment.