Skip to content

Commit

Permalink
feat: Add template sub-list to all frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Oct 25, 2021
1 parent 328b020 commit d4d84d6
Show file tree
Hide file tree
Showing 72 changed files with 55 additions and 48 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ yo secjs Foo --path=./Bar

...

## License
---

MIT © [João Lenon](https://github.com/SecJS/Generator/blob/master/LICENSE)
Made with 🖤 by [jlenon7](https://github.com/jlenon7) :wave
47 changes: 27 additions & 20 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,52 @@ class SecGenerator extends Generator {
name: 'framework',
message: 'Select your framework:',
choices: [
{ name: 'Laravel', value: 'laravel' },
{ name: 'NestJS TypeORM', value: 'nestjsTypeOrm' },
{ name: 'NestJS Mongoose', value: 'nestjsMongoose' },
{ name: 'NestJS PrismaORM', value: 'nestjsPrismaOrm' },
{ name: 'NestJS', value: 'nestjs' },
{ name: 'ReactJS', value: 'reactjs' },
{ name: 'Laravel', value: 'laravel' },
],
},
{
when: answers => answers.framework === 'reactjs',
type: 'list',
name: 'reactjs',
message: 'Select your component type:',
name: 'template',
message: 'Select your template:',
choices: [
{ name: 'ReactJS Hook', value: 'reactjsHook' },
{ name: 'ReactJS Component', value: 'reactjsComponent' },
{ name: 'ReactJS ContextAPI', value: 'reactjsContext' },
{ name: 'ReactJS Material-UI', value: 'reactjsMui' },
{ name: 'ReactJS StyledComponents', value: 'reactjsStyled' },
{ name: 'ReactJS ContextAPI', value: 'reactjsContext' },
{ name: 'ReactJS Hook', value: 'reactjsHook' },
],
},
{
when: answers => answers.framework === 'nestjs',
type: 'list',
name: 'template',
message: 'Select your template:',
choices: [
{ name: 'NestJS TypeOrm', value: 'nestjsTypeOrm' },
{ name: 'NestJS Mongoose', value: 'nestjsMongoose' },
{ name: 'NestJS PrismaOrm', value: 'nestjsPrismaOrm' },
],
},
{
when: answers => answers.framework === 'laravel',
type: 'list',
name: 'template',
message: 'Select your template:',
choices: [{ name: 'Default', value: 'default' }],
},
])
}

frameworkChoice(framework) {
switch (framework) {
case 'reactjs':
return this.answers.reactjs
default:
return this.answers.framework
}
}

async writing() {
const framework = this.frameworkChoice(this.answers.framework)
const dir = path.join(__dirname, `templates/${framework}/`)
const template = `${this.answers.framework}/${this.answers.template}`
const dir = path.join(__dirname, `templates/${template}/`)

for await (const f of makeFileTemplate(dir, this.variables.name)) {
this.fs.copyTpl(
this.templatePath(`${framework}/${f.src}`),
this.templatePath(`${template}/${f.src}`),
this.destinationPath(`${this.variables.path}/${f.dist}`),
this.variables,
)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-secjs",
"version": "1.2.9",
"version": "1.3.0",
"description": "🧬 Generator for any NodeJS Project or Framework",
"main": "app/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions tests/laravel.spec.js → tests/laravel/default.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const assert = require('yeoman-assert')
describe('\n Laravel 😸', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../app'))
.run(path.join(__dirname, '../../app'))
.withOptions({ path: './Foo' })
.withArguments('Bar')
.withPrompts({ framework: 'laravel' })
.withPrompts({ framework: 'laravel', template: 'default' })
})

it('should create all files from resource Bar in folder Foo', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const assert = require('yeoman-assert')
describe('\n NestJS Mongoose 😸', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../app'))
.run(path.join(__dirname, '../../app'))
.withOptions({ path: './Foo' })
.withArguments('Bar')
.withPrompts({ framework: 'nestjsMongoose' })
.withPrompts({ framework: 'nestjs', template: 'nestjsMongoose' })
})

it('should create all files from resource Bar in folder Foo', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const assert = require('yeoman-assert')
describe('\n NestJS PrismaORM 😸', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../app'))
.run(path.join(__dirname, '../../app'))
.withOptions({ path: './Foo' })
.withArguments('Bar')
.withPrompts({ framework: 'nestjsPrismaOrm' })
.withPrompts({ framework: 'nestjs', template: 'nestjsPrismaOrm' })
})

it('should create all files from resource Bar in folder Foo', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const assert = require('yeoman-assert')
describe('\n NestJS TypeORM 😸', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../app'))
.run(path.join(__dirname, '../../app'))
.withOptions({ path: './Foo' })
.withArguments('Bar')
.withPrompts({ framework: 'nestjsTypeOrm' })
.withPrompts({ framework: 'nestjs', template: 'nestjsTypeOrm' })
})

it('should create all files from resource Bar in folder Foo', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const path = require('path')
const helpers = require('yeoman-test')
const assert = require('yeoman-assert')

describe('\n ReactJS 😸', () => {
describe('\n ReactJS Component ⚛️', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../app'))
.run(path.join(__dirname, '../../app'))
.withOptions({ path: './Foo' })
.withArguments('Bar')
.withPrompts({ framework: 'reactjsComponent' })
.withPrompts({ framework: 'reactjs', template: 'reactjsComponent' })
})

it('should create all files from resource Bar in folder Foo', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const path = require('path')
const helpers = require('yeoman-test')
const assert = require('yeoman-assert')

describe('\n ReactJS 😸', () => {
describe('\n ReactJS Context ⚛️', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../app'))
.run(path.join(__dirname, '../../app'))
.withOptions({ path: './Foo' })
.withArguments('Bar')
.withPrompts({ framework: 'reactjsContext' })
.withPrompts({ framework: 'reactjs', template: 'reactjsContext' })
})

it('should create all files from resource Bar in folder Foo', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const path = require('path')
const helpers = require('yeoman-test')
const assert = require('yeoman-assert')

describe('\n ReactJS 😸', () => {
describe('\n ReactJS Hook ⚛️', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../app'))
.run(path.join(__dirname, '../../app'))
.withOptions({ path: './Foo' })
.withArguments('Bar')
.withPrompts({ framework: 'reactjsHook' })
.withPrompts({ framework: 'reactjs', template: 'reactjsHook' })
})

it('should create all files from resource Bar in folder Foo', () => {
Expand Down
6 changes: 3 additions & 3 deletions tests/reactjsMui.spec.js → tests/reactjs/reactjsMui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const path = require('path')
const helpers = require('yeoman-test')
const assert = require('yeoman-assert')

describe('\n ReactJS 😸', () => {
describe('\n ReactJS Mui ⚛️', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../app'))
.run(path.join(__dirname, '../../app'))
.withOptions({ path: './Foo' })
.withArguments('Bar')
.withPrompts({ framework: 'reactjsMui' })
.withPrompts({ framework: 'reactjs', template: 'reactjsMui' })
})

it('should create all files from resource Bar in folder Foo', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const path = require('path')
const helpers = require('yeoman-test')
const assert = require('yeoman-assert')

describe('\n ReactJS 😸', () => {
describe('\n ReactJS Styled ⚛️', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../app'))
.run(path.join(__dirname, '../../app'))
.withOptions({ path: './Foo' })
.withArguments('Bar')
.withPrompts({ framework: 'reactjsStyled' })
.withPrompts({ framework: 'reactjs', template: 'reactjsStyled' })
})

it('should create all files from resource Bar in folder Foo', () => {
Expand Down

0 comments on commit d4d84d6

Please sign in to comment.