Skip to content

Commit

Permalink
fix(cms): fix cms migration when running dev server
Browse files Browse the repository at this point in the history
Previously implemented the .migrate() method to the tensei instance. This was a move preparing us
for serverless. Right now it will be postponed until we have a stable release.
  • Loading branch information
bahdcoder committed Feb 1, 2021
1 parent f465a68 commit 2738c01
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 37 deletions.
1 change: 0 additions & 1 deletion examples/blog/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module.exports = tensei()
.root(__dirname)
.resources([Tag, Post, User, Comment, Editor, Reaction])
.clientUrl('https://google.com')
.serverUrl('http://localhost:5000')
.graphQlQueries([])
.routes([
route('Get products')
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/_templates/default/new/package.json.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ to: <%= h.changeCase.param(name) %>/package.json
"build": "yarn build:server && yarn build:client"
},
"devDependencies": {
"@tensei/common": "^0.5.8",
"@tensei/components": "^0.5.8",
"@tensei/common": "^0.5.10",
"@tensei/components": "^0.5.10",
"laravel-mix": "^6.0.5",
"postcss": "^8.1",
"tailwindcss": "^2.0.2",
Expand Down
5 changes: 2 additions & 3 deletions packages/cms/pages/Resource/Resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import {
Heading,
ResourceContract,
PaginatedData,
AbstractData
AbstractData,
DeleteModal
} from '@tensei/components'

import DeleteModal from '../../components/DeleteModal'

export interface ResourceProps {
detailId?: string
baseResource: ResourceContract
Expand Down
3 changes: 1 addition & 2 deletions packages/cms/pages/ResourceDetail/ResourceDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
useHistory,
Link
} from 'react-router-dom'
import { Heading, StackedList, Button, Pulse } from '@tensei/components'
import { Heading, StackedList, Button, Pulse, DeleteModal } from '@tensei/components'

import PageWrapper from '../../components/PageWrapper'
import DeleteModal from '../../components/DeleteModal'

export interface ResourceDetailProps {}

Expand Down
5 changes: 2 additions & 3 deletions packages/cms/pages/Settings/ManageUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import {
AbstractData,
Modal,
TextInput,
Checkbox
Checkbox,
DeleteModal
} from '@tensei/components'

import DeleteModal from '../../components/DeleteModal'

export interface ResourceProps {
onDelete?: () => void
onCreate?: () => void
Expand Down
10 changes: 4 additions & 6 deletions packages/cms/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,10 @@ class CmsPlugin {
this.sessionMikroOrmOptions
)

if (config.migrating) {
await setupCms(config, [
this.resources.role,
this.resources.permission
])
}
await setupCms(config, [
this.resources.role,
this.resources.permission
])

this.router.use(
ExpressSession({
Expand Down
9 changes: 8 additions & 1 deletion packages/cms/plugin/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,14 @@ export default (config: Config, cmsConfig: any) => {
)
}

await modelRepository.removeAndFlush(entity)
try {
await manager.removeAndFlush(entity)
} catch (e) {
console.log(e.name)

return response.formatter.badRequest(`Failed deleting ${modelName} with ID ${params.id}. ${e.name === 'ForeignKeyConstraintViolationException' ? 'Foreign key constraint violated.' : ''}`)
}


config.emitter.emit(`${singular}::deleted`, entity)

Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/Modal/DeleteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ const DeleteModal: React.FC<DeleteModalProps> = ({
onDelete()
}
})
.catch(() => {
.catch((error) => {
Tensei.error(
`An error occured deleting ${resource.name} with ID ${selected[0].id}.`
error?.response?.data?.error || `An error occured deleting ${resource.name} with ID ${selected[0].id}.`
)

setDeleting(false)
})
.finally(() => {
if (!leavesPage) {
Expand Down
4 changes: 1 addition & 3 deletions packages/core/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class Database {

this.orm = await MikroORM.init(this.getMikroORMOptions() as any)

if (this.config.migrating) {
await new Migrator(this.orm!, this.schemas).init()
}
await new Migrator(this.orm!, this.schemas).init()

return [this.orm!, this.schemas]
}
Expand Down
10 changes: 5 additions & 5 deletions packages/create-tensei-app/templates/default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"license": "MIT",
"dependencies": {
"@mikro-orm/sqlite": "^4.4.0",
"@tensei/auth": "^0.5.8",
"@tensei/cms": "^0.5.8",
"@tensei/core": "^0.5.8",
"@tensei/media": "^0.5.8",
"@tensei/graphql": "^0.5.8"
"@tensei/auth": "^0.5.10",
"@tensei/cms": "^0.5.10",
"@tensei/core": "^0.5.10",
"@tensei/media": "^0.5.10",
"@tensei/graphql": "^0.5.10"
},
"scripts": {
"dev": "nodemon src/index"
Expand Down
10 changes: 5 additions & 5 deletions packages/create-tensei-app/templates/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"license": "MIT",
"dependencies": {
"@mikro-orm/sqlite": "^4.4.0",
"@tensei/auth": "^0.5.8",
"@tensei/cms": "^0.5.8",
"@tensei/core": "^0.5.8",
"@tensei/media": "^0.5.8",
"@tensei/rest": "^0.5.8"
"@tensei/auth": "^0.5.10",
"@tensei/cms": "^0.5.10",
"@tensei/core": "^0.5.10",
"@tensei/media": "^0.5.10",
"@tensei/rest": "^0.5.10"
},
"scripts": {
"dev": "nodemon src/index"
Expand Down
4 changes: 2 additions & 2 deletions packages/mde/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"prettier": "prettier --write './**/*.{js,json,ts,tsx,css}'",
"dev:client": "cross-env NODE_ENV=development webpack --config=node_modules/laravel-mix/setup/webpack.config.js --watch",
"build:client": "cross-env NODE_ENV=production webpack --config=node_modules/laravel-mix/setup/webpack.config.js",
"build": "yarn build:server",
"build:server": "tsc",
"build": "yarn build:server && yarn build:client",
"build:server": "tsc --p tsconfig.server.json",
"dev:server": "tsc --watch"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/mde/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export class MdePlugin {

plugin() {
return plugin('Markdown Editor').register(({ script, style }) => {
style('mde.css', Path.resolve(__dirname, '..', 'public/app.css'))
script('mde.js', Path.resolve(__dirname, '..', 'public/app.js'))
style('mde.css', Path.resolve(__dirname, '..', 'build/client/app.css'))
script('mde.js', Path.resolve(__dirname, '..', 'build/client/app.js'))
})
}
}
Expand Down
15 changes: 15 additions & 0 deletions packages/mde/tsconfig.server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES2017",
"module": "commonjs",
"declaration": true,
"outDir": "./build/",
"strict": true,
"baseUrl": "./server",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"types": ["@types/jest"]
},
"exclude": ["__tests__", "build", "src/components"]
}
3 changes: 3 additions & 0 deletions packages/media/client/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
2 changes: 2 additions & 0 deletions packages/media/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class MediaLibrary {
return plugin('Media Library').register(
({
app,
style,
script,
currentCtx,
extendRoutes,
Expand All @@ -106,6 +107,7 @@ class MediaLibrary {
extendGraphQlTypeDefs,
extendGraphQlQueries
}) => {
style('media.css', Path.resolve(__dirname, 'public/app.css'))
script('media.js', Path.resolve(__dirname, 'public/app.js'))

if (!this.config.disk) {
Expand Down
41 changes: 41 additions & 0 deletions packages/media/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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'
}
}
}
}
1 change: 1 addition & 0 deletions packages/media/webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ mix.webpackConfig({
}
})
.js('./client/index.js', 'build/public/app.js')
.postCss('./client/app.css', 'build/public/app.css', [require('tailwindcss')])
.react()

0 comments on commit 2738c01

Please sign in to comment.