@botonic/example-blank 0.25.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ /*
2
+ * This babel configuration is used along with Jest for execute tests,
3
+ * do not modify to avoid conflicts with webpack.config.js.
4
+ */
5
+
6
+ module.exports = {
7
+ presets: [
8
+ [
9
+ '@babel/preset-env',
10
+ {
11
+ targets: {
12
+ node: 'current',
13
+ },
14
+ },
15
+ ],
16
+ [
17
+ '@babel/react',
18
+ {
19
+ targets: {
20
+ node: 'current',
21
+ },
22
+ },
23
+ ],
24
+ ],
25
+ plugins: [
26
+ require('@babel/plugin-transform-modules-commonjs'),
27
+ require('@babel/plugin-transform-runtime'),
28
+ ],
29
+ }
package/jest.config.js ADDED
@@ -0,0 +1,18 @@
1
+ const path = require('path')
2
+
3
+ module.exports = {
4
+ rootDir: "tests",
5
+ transform: {
6
+ "^.+\\.jsx?$": [
7
+ "babel-jest",
8
+ { "configFile": path.resolve(__dirname, "babel.config.js") },
9
+ ],
10
+ },
11
+ transformIgnorePatterns: [
12
+ "/node_modules/(?!@botonic).+\\.(js|jsx|ts|tsx)$"
13
+ ],
14
+ moduleNameMapper: {
15
+ "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
16
+ "\\.(scss|css|less)$": "<rootDir>/__mocks__/styleMock.js"
17
+ }
18
+ }
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@botonic/example-blank",
3
+ "version": "0.25.0-alpha.0",
4
+ "scripts": {
5
+ "build": "webpack --env target=all --mode=production",
6
+ "start": "webpack-dev-server --env target=dev --mode=development",
7
+ "deploy": "botonic deploy -c build",
8
+ "test": "jest"
9
+ },
10
+ "dependencies": {
11
+ "@babel/runtime": "^7.23.9",
12
+ "@botonic/react": "0.25.0-alpha.6"
13
+ },
14
+ "devDependencies": {
15
+ "@botonic/dx": "0.25.0-alpha.7"
16
+ },
17
+ "engines": {
18
+ "node": ">=20.0.0"
19
+ }
20
+ }
File without changes
File without changes
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export const config = { defaultDelay: 0, defaultTyping: 0 }
File without changes
@@ -0,0 +1 @@
1
+ export const locales = {}
package/src/plugins.js ADDED
@@ -0,0 +1 @@
1
+ export const plugins = []
package/src/routes.js ADDED
@@ -0,0 +1 @@
1
+ export const routes = []
@@ -0,0 +1 @@
1
+ export const webchat = {}
@@ -0,0 +1 @@
1
+ export const webviews = []
@@ -0,0 +1 @@
1
+ module.exports = 'test-file-stub'
@@ -0,0 +1 @@
1
+ module.exports = {}
@@ -0,0 +1,20 @@
1
+ import {
2
+ BotonicInputTester,
3
+ BotonicOutputTester,
4
+ NodeApp,
5
+ } from '@botonic/react'
6
+
7
+ import { config } from '../src/'
8
+ import { locales } from '../src/locales'
9
+ import { plugins } from '../src/plugins'
10
+ import { routes } from '../src/routes'
11
+
12
+ const app = new NodeApp({ routes, locales, plugins, ...config })
13
+
14
+ const input = new BotonicInputTester(app)
15
+ const output = new BotonicOutputTester(app)
16
+
17
+ test('TEST: (404) NOT FOUND', async () => {
18
+ const response = await input.text('whatever')
19
+ expect(response).toBe(output.text("I don't understand you"))
20
+ })
@@ -0,0 +1,15 @@
1
+ import { DevApp } from '@botonic/react'
2
+
3
+ import { config } from '../src'
4
+ import { locales } from '../src/locales'
5
+ import { plugins } from '../src/plugins'
6
+ import { routes } from '../src/routes'
7
+ import { webchat } from '../src/webchat'
8
+
9
+ export const app = new DevApp({
10
+ routes,
11
+ locales,
12
+ plugins,
13
+ ...webchat,
14
+ ...config,
15
+ })
@@ -0,0 +1,8 @@
1
+ import { NodeApp } from '@botonic/react'
2
+
3
+ import { config } from '../src'
4
+ import { locales } from '../src/locales'
5
+ import { plugins } from '../src/plugins'
6
+ import { routes } from '../src/routes'
7
+
8
+ export const app = new NodeApp({ routes, locales, plugins, ...config })
@@ -0,0 +1,5 @@
1
+ import { WebchatApp } from '@botonic/react'
2
+
3
+ import { webchat } from '../src/webchat'
4
+
5
+ export const app = new WebchatApp(webchat)
@@ -0,0 +1,6 @@
1
+ import { WebviewApp } from '@botonic/react'
2
+
3
+ import { locales } from '../src/locales'
4
+ import { webviews } from '../src/webviews'
5
+
6
+ export const app = new WebviewApp({ webviews, locales })
@@ -0,0 +1,338 @@
1
+ const path = require('path')
2
+ const webpack = require('webpack')
3
+ const TerserPlugin = require('terser-webpack-plugin')
4
+ const HtmlWebpackPlugin = require('html-webpack-plugin')
5
+ const { CleanWebpackPlugin } = require('clean-webpack-plugin')
6
+ const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin')
7
+
8
+ const ROOT = path.resolve(__dirname, 'src')
9
+ const ASSETS_DIRNAME = 'assets'
10
+
11
+ const OUTPUT_PATH = path.resolve(__dirname, 'dist')
12
+ const WEBVIEWS_PATH = path.resolve(OUTPUT_PATH, 'webviews')
13
+
14
+ const BOTONIC_PATH = path.resolve(
15
+ __dirname,
16
+ 'node_modules',
17
+ '@botonic',
18
+ 'react'
19
+ )
20
+
21
+ const WEBPACK_MODE = {
22
+ DEVELOPMENT: 'development',
23
+ PRODUCTION: 'production',
24
+ }
25
+
26
+ const BOTONIC_TARGETS = {
27
+ ALL: 'all',
28
+ DEV: 'dev',
29
+ NODE: 'node',
30
+ WEBVIEWS: 'webviews',
31
+ WEBCHAT: 'webchat',
32
+ }
33
+
34
+ const WEBPACK_ENTRIES_DIRNAME = 'webpack-entries'
35
+ const WEBPACK_ENTRIES = {
36
+ DEV: 'dev-entry.js',
37
+ NODE: 'node-entry.js',
38
+ WEBCHAT: 'webchat-entry.js',
39
+ WEBVIEWS: 'webviews-entry.js',
40
+ }
41
+
42
+ const TEMPLATES = {
43
+ WEBCHAT: 'webchat.template.html',
44
+ WEBVIEWS: 'webview.template.html',
45
+ }
46
+
47
+ const UMD_LIBRARY_TARGET = 'umd'
48
+ const BOTONIC_LIBRARY_NAME = 'Botonic'
49
+ const WEBCHAT_FILENAME = 'webchat.botonic.js'
50
+
51
+ function sourceMap(mode) {
52
+ if (mode === WEBPACK_MODE.PRODUCTION) return 'hidden-source-map'
53
+ else if (mode === WEBPACK_MODE.DEVELOPMENT) return 'eval-cheap-source-map'
54
+ else
55
+ throw new Error(
56
+ 'Invalid mode argument (' + mode + '). See package.json scripts'
57
+ )
58
+ }
59
+
60
+ const optimizationConfig = {
61
+ minimize: true,
62
+ minimizer: [
63
+ new TerserPlugin({
64
+ parallel: true,
65
+ terserOptions: {
66
+ keep_fnames: true,
67
+ },
68
+ }),
69
+ ],
70
+ }
71
+
72
+ const resolveConfig = {
73
+ extensions: ['*', '.js', '.jsx', '.ts', '.tsx', '.mjs'],
74
+ alias: {
75
+ react: path.resolve(__dirname, 'node_modules', 'react'),
76
+ 'styled-components': path.resolve(
77
+ __dirname,
78
+ 'node_modules',
79
+ 'styled-components'
80
+ ),
81
+ },
82
+ fallback: {
83
+ util: require.resolve('util'),
84
+ },
85
+ }
86
+
87
+ const babelLoaderConfig = {
88
+ test: /\.(js|jsx|ts|tsx|mjs)$/,
89
+ exclude: /node_modules\/(?!@botonic)/,
90
+ use: {
91
+ loader: 'babel-loader',
92
+ options: {
93
+ sourceType: 'unambiguous',
94
+ cacheDirectory: true,
95
+ presets: [
96
+ '@babel/react',
97
+ [
98
+ '@babel/preset-env',
99
+ {
100
+ modules: false,
101
+ },
102
+ ],
103
+ ],
104
+ plugins: [
105
+ '@babel/plugin-transform-runtime',
106
+ ],
107
+ },
108
+ },
109
+ }
110
+
111
+ function fileLoaderConfig(outputPath) {
112
+ return {
113
+ test: /\.(jpe?g|png|gif|svg)$/i,
114
+ use: [
115
+ {
116
+ loader: 'file-loader',
117
+ options: {
118
+ outputPath: outputPath,
119
+ },
120
+ },
121
+ ],
122
+ }
123
+ }
124
+
125
+ const nullLoaderConfig = {
126
+ test: /\.(scss|css)$/,
127
+ use: 'null-loader',
128
+ }
129
+
130
+ const stylesLoaderConfig = {
131
+ test: /\.(scss|css)$/,
132
+ use: [
133
+ {
134
+ loader: 'style-loader',
135
+ options: {
136
+ insert: function (element) {
137
+ if (!window._botonicInsertStyles) window._botonicInsertStyles = []
138
+ window._botonicInsertStyles.push(element)
139
+ },
140
+ },
141
+ },
142
+ 'css-loader',
143
+ 'sass-loader',
144
+ ],
145
+ }
146
+
147
+ const imageminPlugin = new ImageMinimizerPlugin({
148
+ minimizer: {
149
+ implementation: ImageMinimizerPlugin.imageminMinify,
150
+ options: {
151
+ plugins: [
152
+ "imagemin-gifsicle",
153
+ "imagemin-jpegtran",
154
+ "imagemin-optipng",
155
+ "imagemin-svgo",
156
+ ],
157
+ },
158
+ },
159
+ })
160
+
161
+ function botonicDevConfig(mode) {
162
+ return {
163
+ mode: mode,
164
+ devtool: sourceMap(mode),
165
+ entry: path.resolve(WEBPACK_ENTRIES_DIRNAME, WEBPACK_ENTRIES.DEV),
166
+ target: 'web',
167
+ module: {
168
+ rules: [
169
+ babelLoaderConfig,
170
+ fileLoaderConfig(ASSETS_DIRNAME),
171
+ stylesLoaderConfig,
172
+ ],
173
+ },
174
+ output: {
175
+ filename: WEBCHAT_FILENAME,
176
+ library: BOTONIC_LIBRARY_NAME,
177
+ libraryTarget: UMD_LIBRARY_TARGET,
178
+ libraryExport: 'app',
179
+ path: OUTPUT_PATH,
180
+ },
181
+ resolve: resolveConfig,
182
+ devServer: {
183
+ static: [OUTPUT_PATH],
184
+ liveReload: true,
185
+ historyApiFallback: true,
186
+ hot: true,
187
+ },
188
+ plugins: [
189
+ new HtmlWebpackPlugin({
190
+ template: path.resolve(BOTONIC_PATH, 'src', TEMPLATES.WEBCHAT),
191
+ filename: 'index.html',
192
+ }),
193
+ new webpack.HotModuleReplacementPlugin(),
194
+ imageminPlugin,
195
+ new webpack.DefinePlugin({
196
+ IS_BROWSER: true,
197
+ IS_NODE: false,
198
+ HUBTYPE_API_URL: JSON.stringify(process.env.HUBTYPE_API_URL),
199
+ ...(mode === 'development'
200
+ ? { MODELS_BASE_URL: JSON.stringify('http://localhost:8080') }
201
+ : {}),
202
+ }),
203
+ new webpack.ProvidePlugin({
204
+ process: 'process/browser',
205
+ }),
206
+ ],
207
+ }
208
+ }
209
+
210
+ function botonicWebchatConfig(mode) {
211
+ return {
212
+ optimization: optimizationConfig,
213
+ mode: mode,
214
+ devtool: sourceMap(mode),
215
+ target: 'web',
216
+ entry: path.resolve(WEBPACK_ENTRIES_DIRNAME, WEBPACK_ENTRIES.WEBCHAT),
217
+ module: {
218
+ rules: [
219
+ babelLoaderConfig,
220
+ fileLoaderConfig(ASSETS_DIRNAME),
221
+ stylesLoaderConfig,
222
+ ],
223
+ },
224
+ output: {
225
+ filename: WEBCHAT_FILENAME,
226
+ library: BOTONIC_LIBRARY_NAME,
227
+ libraryTarget: UMD_LIBRARY_TARGET,
228
+ libraryExport: 'app',
229
+ path: OUTPUT_PATH,
230
+ },
231
+ resolve: resolveConfig,
232
+ plugins: [
233
+ new HtmlWebpackPlugin({
234
+ template: path.resolve(BOTONIC_PATH, 'src', TEMPLATES.WEBCHAT),
235
+ filename: 'index.html',
236
+ }),
237
+ imageminPlugin,
238
+ new webpack.DefinePlugin({
239
+ IS_BROWSER: true,
240
+ IS_NODE: false,
241
+ HUBTYPE_API_URL: JSON.stringify(process.env.HUBTYPE_API_URL),
242
+ WEBCHAT_PUSHER_KEY: JSON.stringify(process.env.WEBCHAT_PUSHER_KEY),
243
+ }),
244
+ ],
245
+ }
246
+ }
247
+
248
+ function botonicWebviewsConfig(mode) {
249
+ return {
250
+ optimization: optimizationConfig,
251
+ mode: mode,
252
+ devtool: sourceMap(mode),
253
+ target: 'web',
254
+ entry: path.resolve(WEBPACK_ENTRIES_DIRNAME, WEBPACK_ENTRIES.WEBVIEWS),
255
+ output: {
256
+ filename: 'webviews.js',
257
+ library: 'BotonicWebview',
258
+ libraryTarget: UMD_LIBRARY_TARGET,
259
+ libraryExport: 'app',
260
+ path: WEBVIEWS_PATH,
261
+ },
262
+ module: {
263
+ rules: [
264
+ babelLoaderConfig,
265
+ fileLoaderConfig(path.join('..', ASSETS_DIRNAME)),
266
+ stylesLoaderConfig,
267
+ ],
268
+ },
269
+ resolve: resolveConfig,
270
+ plugins: [
271
+ new HtmlWebpackPlugin({
272
+ template: path.resolve(BOTONIC_PATH, 'src', TEMPLATES.WEBVIEWS),
273
+ filename: 'index.html',
274
+ }),
275
+ imageminPlugin,
276
+ new webpack.DefinePlugin({
277
+ IS_BROWSER: true,
278
+ IS_NODE: false,
279
+ HUBTYPE_API_URL: JSON.stringify(process.env.HUBTYPE_API_URL),
280
+ }),
281
+ ],
282
+ }
283
+ }
284
+
285
+ function botonicNodeConfig(mode) {
286
+ return {
287
+ context: ROOT,
288
+ optimization: optimizationConfig,
289
+ mode: mode,
290
+ devtool: sourceMap(mode),
291
+ target: 'node',
292
+ entry: path.resolve(WEBPACK_ENTRIES_DIRNAME, WEBPACK_ENTRIES.NODE),
293
+ resolve: resolveConfig,
294
+ output: {
295
+ filename: 'bot.js',
296
+ library: 'bot',
297
+ libraryTarget: UMD_LIBRARY_TARGET,
298
+ libraryExport: 'app',
299
+ path: OUTPUT_PATH,
300
+ },
301
+ module: {
302
+ rules: [
303
+ babelLoaderConfig,
304
+ fileLoaderConfig(ASSETS_DIRNAME),
305
+ nullLoaderConfig,
306
+ ],
307
+ },
308
+ plugins: [
309
+ new CleanWebpackPlugin({ cleanOnceBeforeBuildPatterns: ['dist'] }),
310
+ imageminPlugin,
311
+ new webpack.DefinePlugin({
312
+ IS_BROWSER: false,
313
+ IS_NODE: true,
314
+ HUBTYPE_API_URL: JSON.stringify(process.env.HUBTYPE_API_URL),
315
+ }),
316
+ ],
317
+ }
318
+ }
319
+
320
+ module.exports = function (env, argv) {
321
+ if (env.target === BOTONIC_TARGETS.ALL) {
322
+ return [
323
+ botonicNodeConfig(argv.mode),
324
+ botonicWebviewsConfig(argv.mode),
325
+ botonicWebchatConfig(argv.mode),
326
+ ]
327
+ } else if (env.target === BOTONIC_TARGETS.DEV) {
328
+ return [botonicDevConfig(argv.mode)]
329
+ } else if (env.target === BOTONIC_TARGETS.NODE) {
330
+ return [botonicNodeConfig(argv.mode)]
331
+ } else if (env.target === BOTONIC_TARGETS.WEBVIEWS) {
332
+ return [botonicWebviewsConfig(argv.mode)]
333
+ } else if (env.target === BOTONIC_TARGETS.WEBCHAT) {
334
+ return [botonicWebchatConfig(argv.mode)]
335
+ } else {
336
+ return null
337
+ }
338
+ }