Skip to content

Commit

Permalink
feat(cli): add generate plugin command to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Frantz Kati committed Feb 1, 2021
1 parent 8930087 commit 2b3d00d
Show file tree
Hide file tree
Showing 49 changed files with 892 additions and 20,356 deletions.
7 changes: 7 additions & 0 deletions packages/cli/_templates/default/new/.gitignore.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
to: <%= h.changeCase.param(name) %>/.gitignore
---

build/
node_modules/
mix-manifest.json
7 changes: 7 additions & 0 deletions packages/cli/_templates/default/new/client/app.css.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
to: <%= h.changeCase.param(name) %>/client/app.css
---

@tailwind base;
@tailwind components;
@tailwind utilities;
26 changes: 26 additions & 0 deletions packages/cli/_templates/default/new/client/app.tsx.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
to: <%= h.changeCase.param(name) %>/client/app.tsx
---

import React from 'react'
import { Tensei, PageWrapper } from '@tensei/components'

declare var Tensei: Tensei

const <%= h.changeCase.pascal(name) %> = () => {
return (
<PageWrapper>
{`Hello <%= h.changeCase.param(name) %>`}
</PageWrapper>
)
}

Tensei.register(({ route }) => {
route({
path: '<%= h.changeCase.param(name) %>',
name: '<%= h.changeCase.pascal(name) %>',
icon: 'cog',
component: <%= h.changeCase.pascal(name) %>,
requiredPermissions: []
})
})
31 changes: 31 additions & 0 deletions packages/cli/_templates/default/new/package.json.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
to: <%= h.changeCase.param(name) %>/package.json
---

{
"name": "tensei-<%= h.changeCase.param(name) %>",
"version": "0.5.8",
"main": "./build/server/plugin.js",
"license": "MIT",
"types": "./build/server/plugin.d.ts",
"files": [
"build/"
],
"scripts": {
"prettier": "prettier --write './**/*.{js,json,ts,css}'",
"build:server": "tsc --p tsconfig.server.json",
"build:client": "cross-env NODE_ENV=production webpack --config=node_modules/laravel-mix/setup/webpack.config.js",
"dev:server": "tsc --watch --p tsconfig.server.json",
"dev:client": "webpack --config=node_modules/laravel-mix/setup/webpack.config.js --watch",
"test": "jest --verbose --runInBand --forceExit",
"build": "yarn build:server && yarn build:client"
},
"devDependencies": {
"@tensei/common": "^0.5.8",
"@tensei/components": "^0.5.8",
"laravel-mix": "^6.0.5",
"postcss": "^8.1",
"tailwindcss": "^2.0.2",
"typescript": "^4.1.3"
}
}
25 changes: 25 additions & 0 deletions packages/cli/_templates/default/new/server/plugin.ts.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
to: <%= h.changeCase.param(name) %>/server/plugin.ts
---

import Path from 'path'
import { plugin } from '@tensei/common'

class <%= h.changeCase.pascal(name) %> {
plugin() {
return plugin('<%= name %>').boot(({ script, style }) => {
script(
'<%= h.changeCase.param(name) %>.js',
Path.resolve(__dirname, '..', 'build/client/app.js')
)
style(
'<%= h.changeCase.param(name) %>.css',
Path.resolve(__dirname, '..', 'build/client/app.css')
)
})
}
}

const <%= h.changeCase.camel(name) %> = () => new <%= h.changeCase.pascal(name) %>()

export default <%= h.changeCase.camel(name) %>
44 changes: 44 additions & 0 deletions packages/cli/_templates/default/new/tailwind.config.js.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
to: <%= h.changeCase.param(name) %>/tailwind.config.js
---
const defaultTheme = require('tailwindcss/defaultTheme')

module.exports = {
purge: {
enabled: process.env.NODE_ENV === 'production',
content: ['./**/*.tsx']
},
theme: {
extend: {
fontFamily: {
sans: ['Nunito', ...defaultTheme.fontFamily.sans]
},
colors: {
'tensei-primary': '#2346F8',

'tensei-primary-200': '#D3D8FA',

'tensei-primary-lighter': '#3f70fa',

'tensei-primary-darker': '#243de1',
'tensei-secondary': '#33C5FF',
'tensei-darkest': '#21185A',

'tensei-gray-900': '#2C3E50',
'tensei-gray-800': '#61677C',
'tensei-gray-700': '#949BAF',
'tensei-gray-600': '#EEEFF1',
'tensei-gray-500': '#C3C8D2',
'tensei-gray-400': '#F0F1F4',
'tensei-gray-300': '#EAEBEF',
'tensei-gray-100': '#F7F9FA',

'tensei-warning': '#F0B103',
'tensei-success': '#00976E',
'tensei-success-lighter': '#00CA93',
'tensei-success-darker': '#006449',
'tensei-error': '#D41B44'
}
}
}
}
19 changes: 19 additions & 0 deletions packages/cli/_templates/default/new/tsconfig.json.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
to: <%= h.changeCase.param(name) %>/tsconfig.json
---
{
"compilerOptions": {
"jsx": "react",
"module": "commonjs",
"noImplicitAny": true,
"outDir": "./build/",
"preserveConstEnums": true,
"removeComments": true,
"sourceMap": true,
"target": "es5",
"baseUrl": "./client",
"esModuleInterop": true,
"declaration": false
},
"exclude": ["__tests__", "build", "server"]
}
18 changes: 18 additions & 0 deletions packages/cli/_templates/default/new/tsconfig.server.json.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
to: <%= h.changeCase.param(name) %>/tsconfig.server.json
---
{
"compilerOptions": {
"target": "ES2017",
"module": "commonjs",
"declaration": true,
"outDir": "./build/server",
"strict": true,
"baseUrl": "./server",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"types": ["@types/jest"]
},
"exclude": ["__tests__", "build", "client"]
}
13 changes: 13 additions & 0 deletions packages/cli/_templates/default/new/webpack.mix.js.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
to: <%= h.changeCase.param(name) %>/webpack.mix.js
---
const mix = require('laravel-mix')

mix.webpackConfig({
externals: {
react: 'window.React',
'@tensei/components': 'window.Tensei.lib'
}
})
.postCss('./client/app.css', 'build/client/app.css', [require('tailwindcss')])
.ts('./client/app.tsx', 'build/client/app.js')
5 changes: 5 additions & 0 deletions packages/cli/_templates/generator/help/index.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
message: |
hygen {bold generator new} --name [NAME] --action [ACTION]
hygen {bold generator with-prompt} --name [NAME] --action [ACTION]
---
18 changes: 18 additions & 0 deletions packages/cli/_templates/generator/new/hello.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t
---
---
to: app/hello.js
---
const hello = ```
Hello!
This is your first hygen template.

Learn what it can do here:

https://github.com/jondot/hygen
```

console.log(hello)


18 changes: 18 additions & 0 deletions packages/cli/_templates/generator/with-prompt/hello.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t
---
---
to: app/hello.js
---
const hello = ```
Hello!
This is your first prompt based hygen template.

Learn what it can do here:

https://github.com/jondot/hygen
```

console.log(hello)


14 changes: 14 additions & 0 deletions packages/cli/_templates/generator/with-prompt/prompt.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
to: _templates/<%= name %>/<%= action || 'new' %>/prompt.js
---

// see types of prompts:
// https://github.com/enquirer/enquirer/tree/master/examples
//
module.exports = [
{
type: 'input',
name: 'message',
message: "What's your message?"
}
]
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
},
"scripts": {
"prettier": "prettier --write './**/*.{js,json,ts,css}'",
"x-build": "tsc --p tsconfig.json",
"x-dev": "tsc --watch --p tsconfig.json",
"x-test": "jest --verbose --runInBand --forceExit"
"build": "tsc --p tsconfig.json",
"dev": "tsc --watch --p tsconfig.json"
},
"dependencies": {
"@types/change-case": "^2.3.1",
Expand All @@ -38,6 +37,7 @@
"edge.js": "^1.1.4",
"execa": "^5.0.0",
"fs-extra": "^9.1.0",
"hygen": "^6.0.4",
"kill-port": "^1.6.1",
"latest-version": "^5.1.0",
"listr": "^0.14.3",
Expand Down
Loading

0 comments on commit 2b3d00d

Please sign in to comment.