From 157b99dbfa30bfd311e494792bfeb5c3b7af1bf1 Mon Sep 17 00:00:00 2001 From: Pradeep Date: Wed, 25 Nov 2020 03:29:35 +0530 Subject: [PATCH 1/3] Updated files --- README.md | 84 +++++++++++++++++++++++++++++++++++ lib/commands/cms/install.d.ts | 8 ++++ lib/commands/cms/install.js | 72 ++++++++++++++++++++++-------- 3 files changed, 145 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 5311e54..7b96420 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,10 @@ Security: * [Usage](#usage) * [Commands](#commands) +* [Vaah](#vaah) +* [Usage](#usage) +* [Commands](#commands) + # Usage ```sh-session @@ -192,6 +196,18 @@ $ npm install -g vaah $ vaah COMMAND running command... $ vaah (-v|--version|version) +vaah/1.0.2 win32-x64 node-v12.16.1 +$ vaah --help [COMMAND] +USAGE + $ vaah COMMAND +... +``` + +```sh-session +$ npm install -g vaah +$ vaah COMMAND +running command... +$ vaah (-v|--version|version) vaah/1.0.1 win32-x64 node-v12.16.1 $ vaah --help [COMMAND] USAGE @@ -232,6 +248,74 @@ OPTIONS --here If you want to VaahCMS in current director ``` +_See code: [src/commands/cms/install.ts](https://github.com/webreinvent/vaah/blob/v1.0.2/src/commands/cms/install.ts)_ + +## `vaah cms:m` + +``` +USAGE + $ vaah cms:m + +OPTIONS + -f, --force + -h, --help show CLI help + -n, --name show CLI help +``` + +_See code: [src/commands/cms/m.ts](https://github.com/webreinvent/vaah/blob/v1.0.2/src/commands/cms/m.ts)_ + +## `vaah hello [FILE]` + +``` +USAGE + $ vaah hello [FILE] + +OPTIONS + -f, --force + -h, --help show CLI help + -n, --name=name name to print + +EXAMPLE + $ vaah hello + hello world from ./src/hello.ts! +``` + +_See code: [src/commands/hello.ts](https://github.com/webreinvent/vaah/blob/v1.0.2/src/commands/hello.ts)_ + +## `vaah help [COMMAND]` + +``` +USAGE + $ vaah help [COMMAND] + +ARGUMENTS + COMMAND command to show help for + +OPTIONS + --all see all commands in CLI +``` + +_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.0/src/commands/help.ts)_ + +* [`vaah cms:install [PROJECT_NAME]`](#vaah-cmsinstall-project_name) +* [`vaah cms:m`](#vaah-cmsm) +* [`vaah hello [FILE]`](#vaah-hello-file) +* [`vaah help [COMMAND]`](#vaah-help-command) + +## `vaah cms:install [PROJECT_NAME]` + +``` +USAGE + $ vaah cms:install [PROJECT_NAME] + +ARGUMENTS + PROJECT_NAME [default: vaahcms] Enter the project folder name + +OPTIONS + -h, --help show CLI help + --here If you want to VaahCMS in current director +``` + _See code: [src/commands/cms/install.ts](https://github.com/webreinvent/vaah/blob/v1.0.1/src/commands/cms/install.ts)_ ## `vaah cms:m` diff --git a/lib/commands/cms/install.d.ts b/lib/commands/cms/install.d.ts index f323fca..5f9d91f 100644 --- a/lib/commands/cms/install.d.ts +++ b/lib/commands/cms/install.d.ts @@ -1,5 +1,11 @@ import { Command } from '@oclif/command'; export default class CmsInstall extends Command { + args: { + [k: string]: any; + }; + flags: { + [k: string]: any; + }; inputs: { [k: string]: any; }; @@ -21,5 +27,7 @@ export default class CmsInstall extends Command { run(): Promise; install(): Promise; spin(): Promise; + printName(): Promise; spinStop(): Promise; + spinStopWithError(): Promise; } diff --git a/lib/commands/cms/install.js b/lib/commands/cms/install.js index 75954e6..94569e7 100644 --- a/lib/commands/cms/install.js +++ b/lib/commands/cms/install.js @@ -7,18 +7,21 @@ 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'); const log = console.log; class CmsInstall extends command_1.Command { constructor() { super(...arguments); + this.args = {}; + this.flags = {}; this.inputs = {}; this.spinner = {}; this.repo = 'https://github.com/webreinvent/vaahcms-ready'; this.target_dir = './'; //----------------------------------- //----------------------------------- - //----------------------------------- } /* *--------------------------------------------------- @@ -27,18 +30,37 @@ class CmsInstall extends command_1.Command { */ async run() { const { args, flags } = this.parse(CmsInstall); + this.args = args; + this.flags = flags; + await this.printName(); + await this.spin(); if (!flags.here) { - this.target_dir = this.target_dir + args.project_name + "/"; + this.target_dir = this.target_dir + args.project_name; } - if (!fs.existsSync(this.target_dir)) { - fs.mkdirSync(this.target_dir); - } - await this.spin(); await this.install(); } //----------------------------------- + //----------------------------------- async install() { const tasks = new Listr([ + { + title: 'Creating Project Folder', + task: () => new Promise((resolve, reject) => { + { + let self = this; + if (this.args.project_name) { + fs.mkdir(self.target_dir, (error, result) => { + if (error != null) { + log(""); + log(chalk.red("- Project Folder Already Exists")); + return reject(error); + } + resolve(result); + }); + } + } + }) + }, { title: 'Downloading Repository', task: () => new Promise((resolve, reject) => { @@ -47,7 +69,7 @@ class CmsInstall extends command_1.Command { let options = [ 'clone', this.repo, - this.target_dir + './' ]; let git = execa('git', options); git.then(resolve) @@ -59,22 +81,26 @@ class CmsInstall extends command_1.Command { }) }, { - title: 'Installing Dependencies via Composer', + title: 'Installing Dependencies via Composer (Takes 5 - 6 minutes)', task: () => new Promise((resolve, reject) => { { + log(chalk.yellow("Be patient, this can take up to 5 - 6 minutes..")); shell.cd(this.target_dir); - fs.rmdirSync(this.target_dir + '.git/', { recursive: true }); + let project = '.git'; + fs.rmdirSync(project, { recursive: true }); let options = [ 'install', ]; - let composer = execa('composer', options, { - buffer: true, + let output_options = { + buffer: false, stderr: "inherit" - }); - composer.stdout.pipe(process.stdout); + }; + //let composer = execa('composer', options, output_options); + //composer.stdout.pipe(process.stdout); + let composer = execa('composer', options); composer.then(resolve) - .catch(() => { - reject(new Error('Failed')); + .catch((error) => { + return reject(error); }); return composer; } @@ -104,17 +130,17 @@ class CmsInstall extends command_1.Command { return command; } }) - }, + } ]); tasks.run().then(() => { this.spinStop(); }).catch((err) => { console.error(err); + this.spinStopWithError(); }); } //----------------------------------- //----------------------------------- - //----------------------------------- async spin() { this.spinner = ora(); this.spinner.start('Installing VaahCMS...'); @@ -135,20 +161,28 @@ class CmsInstall extends command_1.Command { }; } //----------------------------------- - async spinStop() { - this.spinner.succeed(); + async printName() { log(chalk.red(` /\\ /\\ __ _ __ _ | |__ / __\\ /\\/\\ / _\\ \\ \\ / // _\` | / _\` || '_ \\ / / / \\ \\ \\ \\ V /| (_| || (_| || | | |/ /___/ /\\/\\ \\_\\ \\ \\_/ \\__,_| \\__,_||_| |_|\\____/\\/ \\/\\__/ `)); + } + //----------------------------------- + async spinStop() { + this.spinner.succeed(); log(chalk.white.bgGreen.bold(" VaahCMS Installed! ")); log(chalk.green("==================================================================")); log("Run " + chalk.green("php artisan server") + " and visit following url to setup:"); log(chalk.green("http://127.0.0.1:8000/vaahcms/setup")); log(chalk.green("==================================================================")); } + //----------------------------------- + async spinStopWithError() { + this.spinner.succeed(); + log(chalk.white.bgRed.bold(" VaahCMS Installation Failed! ")); + } } exports.default = CmsInstall; CmsInstall.description = 'Install VaahCMS'; From 7646e674fbfe04af1b81edabd32636ba65a5432d Mon Sep 17 00:00:00 2001 From: Pradeep Date: Wed, 25 Nov 2020 14:08:26 +0530 Subject: [PATCH 2/3] Added: `vaah cms:t` command --- README.md | 18 +++- src/commands/cms/t.ts | 90 +++++++++++++++++++ src/libraries/Questions.ts | 65 ++++++++++++++ .../theme/Providers/ServiceProvider.php.ejs | 4 +- src/skeletons/vaahcms/theme/composer.json.ejs | 2 +- test/commands/cms/t.test.ts | 17 ++++ 6 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 src/commands/cms/t.ts create mode 100644 test/commands/cms/t.test.ts diff --git a/README.md b/README.md index 7b96420..e8a9712 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Please consider starring the project to show your :heart: and support. #### Completed :white_check_mark: VaahCMS Installer :white_check_mark: VaahCMS Module Generator +:white_check_mark: VaahCMS Themes #### Planned :black_square_button: Laravel Package Development @@ -18,8 +19,6 @@ Please consider starring the project to show your :heart: and support. :black_square_button: VaahCMS Modules Files (migration, model, view, controller, seed ) -:black_square_button: VaahCMS Themes - :black_square_button: VaahCMS Themes Files (migration, model, view, controller, seed ) :black_square_button: WordPress Theme @@ -231,6 +230,7 @@ USAGE * [`vaah cms:install [PROJECT_NAME]`](#vaah-cmsinstall-project_name) * [`vaah cms:m`](#vaah-cmsm) +* [`vaah cms:t [FILE]`](#vaah-cmst-file) * [`vaah hello [FILE]`](#vaah-hello-file) * [`vaah help [COMMAND]`](#vaah-help-command) @@ -264,6 +264,20 @@ OPTIONS _See code: [src/commands/cms/m.ts](https://github.com/webreinvent/vaah/blob/v1.0.2/src/commands/cms/m.ts)_ +## `vaah cms:t [FILE]` + +``` +USAGE + $ vaah cms:t [FILE] + +OPTIONS + -f, --force + -h, --help show CLI help + -n, --name=name name to print +``` + +_See code: [src/commands/cms/t.ts](https://github.com/webreinvent/vaah/blob/v1.0.2/src/commands/cms/t.ts)_ + ## `vaah hello [FILE]` ``` diff --git a/src/commands/cms/t.ts b/src/commands/cms/t.ts new file mode 100644 index 0000000..db99079 --- /dev/null +++ b/src/commands/cms/t.ts @@ -0,0 +1,90 @@ +import {Command, flags} from '@oclif/command' +import * as inquirer from 'inquirer'; +const Listr = require('listr'); + +import Questions from "../../libraries/Questions"; +import Generator from "../../libraries/Generator"; + + +const chalk = require('chalk'); +const log = console.log; + + +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() { + const {args, flags} = this.parse(CmsT); + + let questions = new Questions(); + + this.inputs = await inquirer.prompt(questions.getVaahCmsThemeQuestions()); + + this.inputs['namespace'] = 'VaahCms\\Themes\\'+this.inputs.theme_name; + this.inputs['service_provider_name'] = this.inputs.theme_name; + + 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); + + + log(chalk.green('=======================================')); + log('Generating Theme: '+chalk.green(this.inputs.theme_name)); + log(chalk.green('---------------------------------------')); + + + const tasks = new Listr([ + { + title: 'Files Generated', + task: function () { + generator.files(); + + } + } + ]); + + + tasks.run().then((ctx: any) => { + log(chalk.green('=======================================')); + }).catch((err: any) => { + console.error(err); + }); + + + } +} diff --git a/src/libraries/Questions.ts b/src/libraries/Questions.ts index d3ac1ee..99a76b1 100644 --- a/src/libraries/Questions.ts +++ b/src/libraries/Questions.ts @@ -78,6 +78,71 @@ export default class Generator { } //------------------------------------------------------- + getVaahCmsThemeQuestions() + { + + this.questions = [ + { + type : 'input', + name : 'theme_name', + default: 'VaahTheme', + message : 'Enter your theme name: ' + }, + { + type : 'input', + name : 'title', + default: 'Theme for VaahCMS', + message : 'Enter meaningful title for your theme: ' + }, + { + type : 'input', + name : 'description', + default: 'description', + message : 'Enter your theme description: ' + }, + { + type : 'input', + name : 'author_name', + default: 'vaah', + message : 'Enter Author name: ' + }, + { + type : 'input', + name : 'author_email', + default: 'support@vaah.dev', + message : 'Enter Author email: ' + }, + { + type : 'input', + name : 'author_website', + default: 'https://vaah.dev', + message : 'Enter author website: ' + }, + { + type : 'input', + name : 'download_link', + default: '', + message : 'Enter download url: ' + }, + { + type : 'input', + name : 'is_migratable', + default: 'true', + message : 'Do you want to run migration when activated (true/false): ' + }, + { + type : 'input', + name : 'has_sample_data', + default: 'false', + message : 'Will your theme contains sample data (true/false): ' + }, + + ]; + + return this.questions; + + } + //------------------------------------------------------- //------------------------------------------------------- //------------------------------------------------------- diff --git a/src/skeletons/vaahcms/theme/Providers/ServiceProvider.php.ejs b/src/skeletons/vaahcms/theme/Providers/ServiceProvider.php.ejs index e059b63..35e74fd 100644 --- a/src/skeletons/vaahcms/theme/Providers/ServiceProvider.php.ejs +++ b/src/skeletons/vaahcms/theme/Providers/ServiceProvider.php.ejs @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Factory; use <%= namespace %>\Providers\RouteServiceProvider; use <%= namespace %>\Providers\EventServiceProvider; -class <%= theme_name %>ServiceProvider extends ServiceProvider +class ServiceProvider extends ServiceProvider { /** * Indicates if loading of the provider is deferred. @@ -174,7 +174,7 @@ class <%= theme_name %>ServiceProvider extends ServiceProvider /** * Register an additional directory of factories. - * + * * @return void */ public function registerFactories() diff --git a/src/skeletons/vaahcms/theme/composer.json.ejs b/src/skeletons/vaahcms/theme/composer.json.ejs index deb5cbe..d03ef6e 100644 --- a/src/skeletons/vaahcms/theme/composer.json.ejs +++ b/src/skeletons/vaahcms/theme/composer.json.ejs @@ -1,5 +1,5 @@ { - "name": "<%= vendor_name_lower %>/<%= theme_name_lower %>", + "name": "vaahcms/<%= theme_name_lower %>", "description": "<%= description %>", "authors": [ { diff --git a/test/commands/cms/t.test.ts b/test/commands/cms/t.test.ts new file mode 100644 index 0000000..9a586b0 --- /dev/null +++ b/test/commands/cms/t.test.ts @@ -0,0 +1,17 @@ +import {expect, test} from '@oclif/test' + +describe('cms:t', () => { + test + .stdout() + .command(['cms:t']) + .it('runs hello', ctx => { + expect(ctx.stdout).to.contain('hello world') + }) + + test + .stdout() + .command(['cms:t', '--name', 'jeff']) + .it('runs hello --name jeff', ctx => { + expect(ctx.stdout).to.contain('hello jeff') + }) +}) From b443b5345aa48b884a520496722a2751d2a38573 Mon Sep 17 00:00:00 2001 From: Pradeep Date: Wed, 25 Nov 2020 14:09:24 +0530 Subject: [PATCH 3/3] Chnaged: version updated --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 12fab45..8e277b9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vaah", - "description": "CLi of VaahCMS", - "version": "1.0.2", + "description": "CLI of VaahCMS - VaahCLI", + "version": "1.0.3", "author": "Vaah", "bin": { "vaah": "./bin/run"