Skip to content

Commit

Permalink
fix(core): add root method to define project root
Browse files Browse the repository at this point in the history
  • Loading branch information
bahdcoder committed Dec 26, 2020
1 parent ed9553c commit 29d4893
Show file tree
Hide file tree
Showing 13 changed files with 1,200 additions and 1,194 deletions.
2 changes: 0 additions & 2 deletions examples/blog/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ const Comment = require('./resources/Comment')
const Reaction = require('./resources/Reaction')

module.exports = tensei()
// .dashboardPath('tensei')
.resources([Tag, Post, User, Comment, Editor, Reaction])
.clientUrl('https://google.com')
.serverUrl('http://localhost:5000')
// .defaultStorageDriver('local')
.graphQlQueries([])
.routes([
route('Get products')
Expand Down
1 change: 1 addition & 0 deletions packages/cms/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
.next
.env
mix-manifest.json
4 changes: 0 additions & 4 deletions packages/cms/mix-manifest.json

This file was deleted.

5 changes: 3 additions & 2 deletions packages/cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
],
"scripts": {
"prettier": "prettier --write './**/*.{js,json,ts,tsx,css}'",
"dev:css": "NODE_ENV=development yarn build:css",
"dev:css": "cross-env NODE_ENV=development yarn build:css",
"build:css": "tailwind build css/app.css -o css/app.min.css",
"dev": "yarn dev:css && webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js --watch",
"build": "NODE_ENV=production webpack --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
"build": "cross-env NODE_ENV=production webpack --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.12.1",
Expand All @@ -23,6 +23,7 @@
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-router-dom": "^5.1.6",
"cross-env": "^7.0.3",
"laravel-mix": "^5.0.9",
"laravel-mix-react-typescript-extension": "^1.0.3",
"react": "^16.14.0",
Expand Down
2,330 changes: 1,165 additions & 1,165 deletions packages/cms/public/app.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/common/typings/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ declare module '@tensei/common/config' {
events: {
[key: string]: EventContract<DataPayload>
}
root: string
emitter: Emittery
serverUrl: string
clientUrl: string
Expand Down
26 changes: 15 additions & 11 deletions packages/core/Tensei.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,25 @@ export class Tensei implements TenseiContract {
mailer: 'ethereal' as never
}

public ctx: Config
public ctx: Config = {} as any

public constructor() {
this.initCtx()
}

private initCtx() {
this.ctx = {
schemas: [],
routes: [],
events: {},
root: process.cwd(),
emitter: new Emittery(),
name: process.env.APP_NAME || 'Tensei',
graphQlQueries: [],
graphQlTypeDefs: [],
graphQlMiddleware: [],
rootBoot: () => {},
rootRegister: () => {},
viewsPath: Path.resolve(process.cwd(), 'emails'),
storage: new StorageManager(this.defaultStorageConfig),
storageConfig: this.defaultStorageConfig,
databaseClient: null,
Expand Down Expand Up @@ -130,7 +134,7 @@ export class Tensei implements TenseiContract {
}
} as any

this.ctx.mailer = mail(this.mailerConfig, this.ctx.logger)
this.ctx.mailer = mail(this.mailerConfig, this.ctx.logger, this.ctx.root)
}

public setConfigOnResourceFields() {
Expand All @@ -149,12 +153,6 @@ export class Tensei implements TenseiContract {
return this
}

public viewsPath(path: string) {
this.ctx.viewsPath = path

return this
}

public graphQlQueries(graphQlQueries: GraphQlQueryContract[]) {
this.ctx.graphQlQueries = [
...this.ctx.graphQlQueries,
Expand Down Expand Up @@ -372,7 +370,7 @@ export class Tensei implements TenseiContract {
}
}

this.ctx.mailer = mail(this.mailerConfig, this.ctx.logger)
this.ctx.mailer = mail(this.mailerConfig, this.ctx.logger, this.ctx.root)

this.ctx.mailer.extend(name, driver)
}
Expand Down Expand Up @@ -679,7 +677,13 @@ export class Tensei implements TenseiContract {
return this
}

private emit(name: string) {}
public root(root: string) {
this.ctx.root = root

this.initCtx()

return this
}
}

export const tensei = () => new Tensei()
Expand Down
4 changes: 2 additions & 2 deletions packages/core/typings/tensei.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ declare module '@tensei/core' {
events(events: EventContract<DataPayload>[]): this
serverUrl(url: string): this
clientUrl(url: string): this
viewsPath(path: string): this
root(path: string): this
resources(resources: ResourceContract[]): this
dashboards(dashboards: DashboardContract[]): this
plugins(plugins: PluginContract[]): this
Expand All @@ -48,7 +48,7 @@ declare module '@tensei/core' {
events(events: EventContract<DataPayload>[]): this
serverUrl(url: string): this
clientUrl(url: string): this
viewsPath(path: string): this
root(path: string): this
resources(resources: ResourceContract[]): this
dashboards(dashboards: DashboardContract[]): this
plugins(plugins: PluginContract[]): this
Expand Down
4 changes: 1 addition & 3 deletions packages/mail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
],
"typings": "./build/types/index.d.ts",
"scripts": {
"clean": "del build",
"dev": "tsc --watch",
"test": "node japaFile.js",
"build": "yarn clean && tsc",
"build": "tsc",
"format": "prettier --write ."
},
"keywords": [
Expand All @@ -30,7 +29,6 @@
"aws-sdk": "^2.799.0",
"commitizen": "^4.2.2",
"copyfiles": "^2.4.1",
"del-cli": "^3.0.1",
"japa": "^3.1.1",
"mrm": "^2.5.13",
"np": "^7.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/mail/src/MailManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class MailManager
*/
public view = {} as any

constructor(private config: MailConfig, public logger: Config['logger']) {
constructor(private config: MailConfig, public logger: Config['logger'], private mailsPath?: string) {
super({} as any)
this.BaseMailer.mail = this
this.setupViews()
Expand All @@ -118,7 +118,7 @@ export class MailManager
const supercharged = new Supercharged()

edge.mount(
Path.resolve(process.cwd(), 'emails')
this.mailsPath || Path.resolve(process.cwd(), 'mails')
)

edge.use(supercharged.wire, { recurring: !cacheViews })
Expand Down
2 changes: 1 addition & 1 deletion packages/mail/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import { MailManager } from './MailManager'
export { ses } from './plugins/Ses'
export { smtp } from './plugins/Smtp'

export const mail = (config: MailConfig, logger: Config['logger']) => new MailManager(config, logger)
export const mail = (config: MailConfig, logger: Config['logger'], mailsPath?: string) => new MailManager(config, logger, mailsPath)
2 changes: 1 addition & 1 deletion packages/mail/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"forceConsistentCasingInFileNames": false,
"types": ["@types/node"]
},
"exclude": ["build/"]
"exclude": ["build"]
}
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6195,6 +6195,13 @@ cross-env@^5.1.0:
dependencies:
cross-spawn "^6.0.5"

cross-env@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf"
integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==
dependencies:
cross-spawn "^7.0.1"

cross-fetch@3.0.5:
version "3.0.5"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.5.tgz#2739d2981892e7ab488a7ad03b92df2816e03f4c"
Expand All @@ -6209,7 +6216,7 @@ cross-fetch@3.0.6, cross-fetch@^3.0.6:
dependencies:
node-fetch "2.6.1"

cross-spawn@7.0.3, cross-spawn@^7.0.0, cross-spawn@^7.0.2:
cross-spawn@7.0.3, cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
Expand Down

0 comments on commit 29d4893

Please sign in to comment.