diff --git a/build/gulp.modules.js b/build/gulp.modules.js
index ba621c5e5d6..07f256583db 100644
--- a/build/gulp.modules.js
+++ b/build/gulp.modules.js
@@ -29,21 +29,6 @@ const readModuleConfig = modulePath => {
return JSON.parse(fs.readFileSync(packagePath))
}
-/**
- * Copies the [`botpress.d.ts`]{@see ../src/bp/sdk/botpress.d.ts} file to all the
- * modules individually.
- */
-const copySdkDefinitions = () => {
- let stream = gulp.src(['src/bp/sdk/botpress.d.ts', 'src/typings/global.d.ts'])
- const modules = getAllModulesRoot()
- for (let m of modules) {
- const src = _.get(readModuleConfig(m), 'botpress.src', 'src')
- const dest = path.join(m, src)
- stream = stream.pipe(gulp.dest(dest)).pipe(print())
- }
- return stream
-}
-
const getTargetOSConfig = () => {
if (process.argv.find(x => x.toLowerCase() === '--win32')) {
return 'win32'
@@ -142,12 +127,13 @@ const packageModules = () => {
return gulp.series(tasks)
}
-const build = () => {
- return gulp.series([buildModuleBuilder, copySdkDefinitions, buildModules()])
+// Temporarily cleaning the sdk, otherwise local copies will generate an error
+const cleanSdk = () => {
+ return gulp.src(['./modules/*/src/global.d.ts', './modules/*/src/botpress.d.ts'], { allowEmpty: true }).pipe(rimraf())
}
-const buildSdk = () => {
- return gulp.series([copySdkDefinitions])
+const build = () => {
+ return gulp.series([buildModuleBuilder, cleanSdk, buildModules()])
}
const cleanModuleAssets = () => {
@@ -190,7 +176,6 @@ const createAllModulesSymlink = () => {
module.exports = {
build,
- buildSdk,
buildModules,
packageModules,
buildModuleBuilder,
diff --git a/gulpfile.js b/gulpfile.js
index 8d625ad67f6..0a3f121fa54 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -40,7 +40,6 @@ gulp.task('build:ui', ui.build())
gulp.task('build:core', core.build())
gulp.task('build:shared', ui.buildShared())
gulp.task('build:modules', gulp.series([modules.build()]))
-gulp.task('build:sdk', gulp.series([modules.buildSdk()]))
gulp.task('start:guide', docs.startDevServer)
gulp.task('build:guide', docs.buildGuide())
diff --git a/modules/code-editor/build.extras.js b/modules/code-editor/build.extras.js
index 1f1dd06b69e..9068de5dc33 100644
--- a/modules/code-editor/build.extras.js
+++ b/modules/code-editor/build.extras.js
@@ -1,9 +1,15 @@
module.exports = {
copyFiles: [
'src/botpress.d.ts',
- 'src/typings/node.d.ts',
+ 'src/typings/node.d.txt',
'src/typings/es6include.txt',
'src/typings/bot.config.schema.json',
'src/typings/botpress.config.schema.json'
]
}
+
+const fs = require('fs')
+const path = require('path')
+
+fs.mkdirSync('dist')
+fs.copyFileSync(path.join(__dirname, '../../src/bp/sdk/botpress.d.ts'), path.join(__dirname, 'dist/botpress.d.js'))
diff --git a/modules/code-editor/src/backend/editor.ts b/modules/code-editor/src/backend/editor.ts
index 66447ea579e..4e34627b1cf 100644
--- a/modules/code-editor/src/backend/editor.ts
+++ b/modules/code-editor/src/backend/editor.ts
@@ -178,7 +178,7 @@ export default class Editor {
}
const sdkTyping = fs.readFileSync(path.join(__dirname, '/../botpress.d.js'), 'utf-8')
- const nodeTyping = fs.readFileSync(path.join(__dirname, `/../typings/node.d.js`), 'utf-8')
+ const nodeTyping = fs.readFileSync(path.join(__dirname, `/../typings/node.d.txt`), 'utf-8')
const ghost = this.bp.ghost.forRoot()
const botConfigSchema = await ghost.readFileAsString('/', 'bot.config.schema.json')
diff --git a/modules/code-editor/src/typings/node.d.ts b/modules/code-editor/src/typings/node.d.txt
similarity index 100%
rename from modules/code-editor/src/typings/node.d.ts
rename to modules/code-editor/src/typings/node.d.txt
diff --git a/modules/global.d.ts b/modules/global.d.ts
new file mode 100644
index 00000000000..bac66bfa333
--- /dev/null
+++ b/modules/global.d.ts
@@ -0,0 +1 @@
+/// #
diff --git a/modules/tsconfig.shared.json b/modules/tsconfig.shared.json
index a6ce1bdd1f7..749536286f1 100644
--- a/modules/tsconfig.shared.json
+++ b/modules/tsconfig.shared.json
@@ -12,11 +12,13 @@
"moduleResolution": "node",
"target": "es6",
"lib": ["es7"],
- "typeRoots": ["./node_modules/@types", "./node_modules", "./src/botpress.d.ts", "./src/typings"],
- "types": ["reflect-metadata", "jest", "bluebird-global", "node"],
+ "typeRoots": ["./node_modules/@types", "./node_modules", "./src/typings"],
+ "types": ["reflect-metadata", "jest", "bluebird-global"],
"paths": {
- "botpress/common/typings": ["../../out/bp/common/typings.d.ts"]
+ "botpress/common/typings": ["../../out/bp/common/typings.d.ts"],
+ "botpress/sdk": ["../../src/bp/sdk/botpress.d.ts"]
}
},
- "exclude": ["**/*.test.ts", "./src/views/**"]
+ "exclude": ["**/*.test.ts", "./src/views/**"],
+ "include": ["**/*.ts", "../../src/typings/global.d.ts"]
}
diff --git a/modules/tsconfig_view.shared.json b/modules/tsconfig_view.shared.json
index 6d1972c82f8..6f2c86614d1 100644
--- a/modules/tsconfig_view.shared.json
+++ b/modules/tsconfig_view.shared.json
@@ -15,7 +15,7 @@
"botpress/ui": ["../../../../src/bp/ui-studio/src/web/components/Shared/Interface/typings.d.ts"],
"botpress/utils": ["../../../../src/bp/ui-studio/src/web/components/Shared/Utils/typings.d.ts"],
"botpress/shared": ["../../../../src/bp/ui-shared/src/Interface/typings.d.ts"],
- "botpress/sdk": ["../botpress.d.ts"],
+ "botpress/sdk": ["../../../../src/bp/sdk/botpress.d.ts"],
"botpress/common/typings": ["../../../../out/bp/common/typings.d.ts"],
"@blueprintjs/core": ["../../../../src/bp/ui-studio/node_modules/@blueprintjs/core"],
"@blueprintjs/select": ["../../../../src/bp/ui-studio/node_modules/@blueprintjs/select"],
diff --git a/src/bp/core/routers/bots/index.ts b/src/bp/core/routers/bots/index.ts
index 0478ed23e2c..8b1a9dd4163 100644
--- a/src/bp/core/routers/bots/index.ts
+++ b/src/bp/core/routers/bots/index.ts
@@ -128,7 +128,7 @@ export class BotsRouter extends CustomRouter {
}
}
- getNewRouter(path: string, identity: string, options?: RouterOptions) {
+ getNewRouter(path: string, identity: string, options?: RouterOptions): Router {
const router = Router({ mergeParams: true })
if (_.get(options, 'checkAuthentication', true)) {
router.use(this.checkTokenHeader)
diff --git a/src/bp/sdk/botpress.d.ts b/src/bp/sdk/botpress.d.ts
index 759bebf3e4d..1121a7bb10d 100644
--- a/src/bp/sdk/botpress.d.ts
+++ b/src/bp/sdk/botpress.d.ts
@@ -6,6 +6,7 @@
*/
declare module 'botpress/sdk' {
import Knex from 'knex'
+ import { Router, Request, Response, NextFunction } from 'express'
export interface KnexExtension {
isLite: boolean
@@ -1313,7 +1314,7 @@ declare module 'botpress/sdk' {
* @param options - Additional options to apply to the router
* @param router - The router
*/
- export function createRouterForBot(routerName: string, options?: RouterOptions): any & RouterExtension
+ export function createRouterForBot(routerName: string, options?: RouterOptions): RouterExtension
/**
* This method is meant to unregister a router before unloading a module. It is meant to be used in a development environment.
@@ -1339,18 +1340,16 @@ declare module 'botpress/sdk' {
/**
* This Express middleware tries to decode the X-BP-ExternalAuth header and adds a credentials header in the request if it's valid.
*/
- export function extractExternalToken(req: any, res: any, next: any): Promise
+ export function extractExternalToken(req: Request, res: Response, next: NextFunction): Promise
export function needPermission(
operation: string,
resource: string
- ): (req: any, res: any, next: any) => Promise
+ ): (req: Request, res: Response, next: NextFunction) => Promise
export function hasPermission(req: any, operation: string, resource: string): Promise
- export interface RouterExtension {
- getPublicPath(): Promise
- }
+ export type RouterExtension = { getPublicPath(): Promise } & Router
}
/**