@things-factory/shell 6.2.84 → 7.0.0-alpha.1

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.
Files changed (77) hide show
  1. package/dist-server/graphql-local-client.d.ts +19 -0
  2. package/dist-server/graphql-local-client.js +14 -0
  3. package/dist-server/graphql-local-client.js.map +1 -1
  4. package/dist-server/initializers/database.d.ts +26 -0
  5. package/dist-server/initializers/database.js +26 -0
  6. package/dist-server/initializers/database.js.map +1 -1
  7. package/dist-server/pubsub-log-transport.d.ts +27 -0
  8. package/dist-server/pubsub-log-transport.js +15 -0
  9. package/dist-server/pubsub-log-transport.js.map +1 -1
  10. package/dist-server/pubsub.d.ts +9 -1
  11. package/dist-server/pubsub.js +14 -2
  12. package/dist-server/pubsub.js.map +1 -1
  13. package/dist-server/schema.d.ts +4 -0
  14. package/dist-server/schema.js +7 -3
  15. package/dist-server/schema.js.map +1 -1
  16. package/dist-server/service/subscription-data/data-resolver.js +6 -12
  17. package/dist-server/service/subscription-data/data-resolver.js.map +1 -1
  18. package/dist-server/tsconfig.tsbuildinfo +1 -1
  19. package/dist-server/typeorm/encrypt-transform.d.ts +5 -0
  20. package/dist-server/typeorm/encrypt-transform.js +25 -0
  21. package/dist-server/typeorm/encrypt-transform.js.map +1 -1
  22. package/dist-server/utils/condition-builder.d.ts +11 -0
  23. package/dist-server/utils/condition-builder.js +11 -0
  24. package/dist-server/utils/condition-builder.js.map +1 -1
  25. package/dist-server/utils/get-domain.d.ts +46 -0
  26. package/dist-server/utils/get-domain.js +70 -0
  27. package/dist-server/utils/get-domain.js.map +1 -1
  28. package/dist-server/utils/get-query-builder-from-list-params.d.ts +12 -2
  29. package/dist-server/utils/get-query-builder-from-list-params.js +24 -8
  30. package/dist-server/utils/get-query-builder-from-list-params.js.map +1 -1
  31. package/dist-server/utils/get-times-for-period.d.ts +14 -0
  32. package/dist-server/utils/get-times-for-period.js +14 -0
  33. package/dist-server/utils/get-times-for-period.js.map +1 -1
  34. package/dist-server/utils/list-param-adjuster.d.ts +9 -0
  35. package/dist-server/utils/list-param-adjuster.js +9 -0
  36. package/dist-server/utils/list-param-adjuster.js.map +1 -1
  37. package/dist-server/utils/list-params-converter.d.ts +6 -0
  38. package/dist-server/utils/list-params-converter.js +27 -0
  39. package/dist-server/utils/list-params-converter.js.map +1 -1
  40. package/dist-server/utils/list-query-builder.d.ts +10 -1
  41. package/dist-server/utils/list-query-builder.js +10 -1
  42. package/dist-server/utils/list-query-builder.js.map +1 -1
  43. package/dist-server/utils/publish-progress.d.ts +9 -0
  44. package/dist-server/utils/publish-progress.js +9 -0
  45. package/dist-server/utils/publish-progress.js.map +1 -1
  46. package/package.json +18 -18
  47. package/server/graphql-local-client.ts +20 -0
  48. package/server/initializers/database.ts +26 -0
  49. package/server/pubsub-log-transport.ts +29 -0
  50. package/server/pubsub.ts +17 -3
  51. package/server/schema.ts +9 -12
  52. package/server/service/subscription-data/data-resolver.ts +9 -18
  53. package/server/typeorm/encrypt-transform.ts +26 -0
  54. package/server/utils/condition-builder.ts +12 -8
  55. package/server/utils/get-domain.ts +70 -0
  56. package/server/utils/get-query-builder-from-list-params.ts +26 -16
  57. package/server/utils/get-times-for-period.ts +15 -4
  58. package/server/utils/list-param-adjuster.ts +9 -0
  59. package/server/utils/list-params-converter.ts +28 -4
  60. package/server/utils/list-query-builder.ts +13 -17
  61. package/server/utils/publish-progress.ts +9 -0
  62. package/dist-server/webpack/koa-webpack/client.d.ts +0 -1
  63. package/dist-server/webpack/koa-webpack/client.js +0 -24
  64. package/dist-server/webpack/koa-webpack/client.js.map +0 -1
  65. package/dist-server/webpack/koa-webpack/index.d.ts +0 -2
  66. package/dist-server/webpack/koa-webpack/index.js +0 -58
  67. package/dist-server/webpack/koa-webpack/index.js.map +0 -1
  68. package/dist-server/webpack/koa-webpack/middleware.d.ts +0 -0
  69. package/dist-server/webpack/koa-webpack/middleware.js +0 -42
  70. package/dist-server/webpack/koa-webpack/middleware.js.map +0 -1
  71. package/dist-server/webpack/koa-webpack/validate.d.ts +0 -1
  72. package/dist-server/webpack/koa-webpack/validate.js +0 -26
  73. package/dist-server/webpack/koa-webpack/validate.js.map +0 -1
  74. package/server/webpack/koa-webpack/client.ts +0 -26
  75. package/server/webpack/koa-webpack/index.ts +0 -71
  76. package/server/webpack/koa-webpack/middleware.ts +0 -47
  77. package/server/webpack/koa-webpack/validate.ts +0 -27
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /*
4
- Copyright © 2016 Andrew Powell
5
-
6
- This Source Code Form is subject to the terms of the Mozilla Public
7
- License, v. 2.0. If a copy of the MPL was not distributed with this
8
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
-
10
- The above copyright notice and this permission notice shall be
11
- included in all copies or substantial portions of this Source Code Form.
12
- */
13
- const { join } = require('path');
14
- const root = require('app-root-path');
15
- const chalk = require('chalk');
16
- const webpack = require('webpack');
17
- const webpackDevMiddleware = require('webpack-dev-middleware');
18
- const { getClient } = require('./client');
19
- const { getMiddleware } = require('./middleware');
20
- const { validate } = require('./validate');
21
- const defaults = { devMiddleware: {}, hotClient: {} };
22
- exports.default = async (opts) => {
23
- const valid = validate(opts);
24
- if (valid.error) {
25
- const { error } = console;
26
- error(chalk.red('⬢ koa-webpack:'), 'An option was passed to koa-webpack that is not valid');
27
- throw valid.error;
28
- }
29
- const options = Object.assign({}, defaults, opts);
30
- let { compiler, config } = options;
31
- if (!compiler) {
32
- if (!config) {
33
- // eslint-disable-next-line import/no-dynamic-require, global-require
34
- config = require(options.configPath || join(root.path, 'webpack.config.js'));
35
- }
36
- compiler = webpack(config);
37
- }
38
- if (!options.devMiddleware.publicPath) {
39
- const { publicPath } = compiler.options.output;
40
- if (!publicPath) {
41
- throw new Error("koa-webpack: publicPath must be set on `dev` options, or in a compiler's `output` configuration.");
42
- }
43
- options.devMiddleware.publicPath = publicPath;
44
- }
45
- const hotClient = await getClient(compiler, options);
46
- const devMiddleware = webpackDevMiddleware(compiler, options.devMiddleware);
47
- const middleware = getMiddleware(compiler, devMiddleware);
48
- const close = callback => {
49
- const next = hotClient ? () => hotClient.close(callback) : callback;
50
- devMiddleware.close(next);
51
- };
52
- return Object.assign(middleware, {
53
- hotClient,
54
- devMiddleware,
55
- close
56
- });
57
- };
58
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/webpack/koa-webpack/index.ts"],"names":[],"mappings":";;AAAA;;;;;;;;;EASE;AACF,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAEhC,MAAM,IAAI,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;AACrC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAClC,MAAM,oBAAoB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAA;AAE9D,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AACzC,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AACjD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;AAE1C,MAAM,QAAQ,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAA;AAErD,kBAAe,KAAK,EAAC,IAAI,EAAC,EAAE;IAC1B,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;IAE5B,IAAI,KAAK,CAAC,KAAK,EAAE;QACf,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;QACzB,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,uDAAuD,CAAC,CAAA;QAC3F,MAAM,KAAK,CAAC,KAAK,CAAA;KAClB;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;IAEjD,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAElC,IAAI,CAAC,QAAQ,EAAE;QACb,IAAI,CAAC,MAAM,EAAE;YACX,qEAAqE;YACrE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAA;SAC7E;QAED,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;KAC3B;IAED,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,EAAE;QACrC,MAAM,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAA;QAE9C,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,KAAK,CACb,kGAAkG,CACnG,CAAA;SACF;QAED,OAAO,CAAC,aAAa,CAAC,UAAU,GAAG,UAAU,CAAA;KAC9C;IAED,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACpD,MAAM,aAAa,GAAG,oBAAoB,CAAC,QAAQ,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;IAC3E,MAAM,UAAU,GAAG,aAAa,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAA;IACzD,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAE;QACvB,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;QACnE,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC,CAAA;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;QAC/B,SAAS;QACT,aAAa;QACb,KAAK;KACN,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["/*\n Copyright © 2016 Andrew Powell\n\n This Source Code Form is subject to the terms of the Mozilla Public\n License, v. 2.0. If a copy of the MPL was not distributed with this\n file, You can obtain one at http://mozilla.org/MPL/2.0/.\n\n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of this Source Code Form.\n*/\nconst { join } = require('path')\n\nconst root = require('app-root-path')\nconst chalk = require('chalk')\nconst webpack = require('webpack')\nconst webpackDevMiddleware = require('webpack-dev-middleware')\n\nconst { getClient } = require('./client')\nconst { getMiddleware } = require('./middleware')\nconst { validate } = require('./validate')\n\nconst defaults = { devMiddleware: {}, hotClient: {} }\n\nexport default async opts => {\n const valid = validate(opts)\n\n if (valid.error) {\n const { error } = console\n error(chalk.red('⬢ koa-webpack:'), 'An option was passed to koa-webpack that is not valid')\n throw valid.error\n }\n\n const options = Object.assign({}, defaults, opts)\n\n let { compiler, config } = options\n\n if (!compiler) {\n if (!config) {\n // eslint-disable-next-line import/no-dynamic-require, global-require\n config = require(options.configPath || join(root.path, 'webpack.config.js'))\n }\n\n compiler = webpack(config)\n }\n\n if (!options.devMiddleware.publicPath) {\n const { publicPath } = compiler.options.output\n\n if (!publicPath) {\n throw new Error(\n \"koa-webpack: publicPath must be set on `dev` options, or in a compiler's `output` configuration.\"\n )\n }\n\n options.devMiddleware.publicPath = publicPath\n }\n\n const hotClient = await getClient(compiler, options)\n const devMiddleware = webpackDevMiddleware(compiler, options.devMiddleware)\n const middleware = getMiddleware(compiler, devMiddleware)\n const close = callback => {\n const next = hotClient ? () => hotClient.close(callback) : callback\n devMiddleware.close(next)\n }\n\n return Object.assign(middleware, {\n hotClient,\n devMiddleware,\n close\n })\n}\n"]}
File without changes
@@ -1,42 +0,0 @@
1
- /*
2
- Copyright © 2016 Andrew Powell
3
-
4
- This Source Code Form is subject to the terms of the Mozilla Public
5
- License, v. 2.0. If a copy of the MPL was not distributed with this
6
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
-
8
- The above copyright notice and this permission notice shall be
9
- included in all copies or substantial portions of this Source Code Form.
10
- */
11
- module.exports = {
12
- getMiddleware(compiler, devMiddleware) {
13
- return (context, next) => {
14
- // wait for webpack-dev-middleware to signal that the build is ready
15
- const ready = new Promise((resolve, reject) => {
16
- for (const comp of [].concat(compiler.compilers || compiler)) {
17
- comp.hooks.failed.tap('KoaWebpack', error => {
18
- reject(error);
19
- });
20
- }
21
- devMiddleware.waitUntilValid(() => {
22
- resolve(true);
23
- });
24
- });
25
- // tell webpack-dev-middleware to handle the request
26
- const init = new Promise(resolve => {
27
- devMiddleware(context.req, {
28
- end: content => {
29
- // eslint-disable-next-line no-param-reassign
30
- context.body = content;
31
- resolve(null);
32
- },
33
- getHeader: context.get.bind(context),
34
- setHeader: context.set.bind(context),
35
- locals: context.state
36
- }, () => resolve(next()));
37
- });
38
- return Promise.all([ready, init]);
39
- };
40
- }
41
- };
42
- //# sourceMappingURL=middleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../server/webpack/koa-webpack/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AACF,MAAM,CAAC,OAAO,GAAG;IACf,aAAa,CAAC,QAAQ,EAAE,aAAa;QACnC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;YACvB,oEAAoE;YACpE,MAAM,KAAK,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC5C,KAAK,MAAM,IAAI,IAAI,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,EAAE;oBAC5D,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE;wBAC1C,MAAM,CAAC,KAAK,CAAC,CAAA;oBACf,CAAC,CAAC,CAAA;iBACH;gBAED,aAAa,CAAC,cAAc,CAAC,GAAG,EAAE;oBAChC,OAAO,CAAC,IAAI,CAAC,CAAA;gBACf,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;YACF,oDAAoD;YACpD,MAAM,IAAI,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;gBACjC,aAAa,CACX,OAAO,CAAC,GAAG,EACX;oBACE,GAAG,EAAE,OAAO,CAAC,EAAE;wBACb,6CAA6C;wBAC7C,OAAO,CAAC,IAAI,GAAG,OAAO,CAAA;wBACtB,OAAO,CAAC,IAAI,CAAC,CAAA;oBACf,CAAC;oBACD,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;oBACpC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;oBACpC,MAAM,EAAE,OAAO,CAAC,KAAK;iBACtB,EACD,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CACtB,CAAA;YACH,CAAC,CAAC,CAAA;YAEF,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;QACnC,CAAC,CAAA;IACH,CAAC;CACF,CAAA","sourcesContent":["/*\n Copyright © 2016 Andrew Powell\n\n This Source Code Form is subject to the terms of the Mozilla Public\n License, v. 2.0. If a copy of the MPL was not distributed with this\n file, You can obtain one at http://mozilla.org/MPL/2.0/.\n\n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of this Source Code Form.\n*/\nmodule.exports = {\n getMiddleware(compiler, devMiddleware) {\n return (context, next) => {\n // wait for webpack-dev-middleware to signal that the build is ready\n const ready = new Promise((resolve, reject) => {\n for (const comp of [].concat(compiler.compilers || compiler)) {\n comp.hooks.failed.tap('KoaWebpack', error => {\n reject(error)\n })\n }\n\n devMiddleware.waitUntilValid(() => {\n resolve(true)\n })\n })\n // tell webpack-dev-middleware to handle the request\n const init = new Promise(resolve => {\n devMiddleware(\n context.req,\n {\n end: content => {\n // eslint-disable-next-line no-param-reassign\n context.body = content\n resolve(null)\n },\n getHeader: context.get.bind(context),\n setHeader: context.set.bind(context),\n locals: context.state\n },\n () => resolve(next())\n )\n })\n\n return Promise.all([ready, init])\n }\n }\n}\n"]}
@@ -1 +0,0 @@
1
- declare const Joi: any;
@@ -1,26 +0,0 @@
1
- /*
2
- Copyright © 2016 Andrew Powell
3
-
4
- This Source Code Form is subject to the terms of the Mozilla Public
5
- License, v. 2.0. If a copy of the MPL was not distributed with this
6
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
-
8
- The above copyright notice and this permission notice shall be
9
- included in all copies or substantial portions of this Source Code Form.
10
- */
11
- const Joi = require('joi');
12
- module.exports = {
13
- validate(options) {
14
- const keys = {
15
- compiler: [Joi.object().allow(null)],
16
- config: [Joi.object().allow(null)],
17
- configPath: [Joi.string().allow(null)],
18
- devMiddleware: [Joi.object()],
19
- hotClient: [Joi.boolean(), Joi.object().allow(null)]
20
- };
21
- const schema = Joi.object().keys(keys);
22
- const results = schema.validate(options);
23
- return results;
24
- }
25
- };
26
- //# sourceMappingURL=validate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../server/webpack/koa-webpack/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AACF,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;AAE3B,MAAM,CAAC,OAAO,GAAG;IACf,QAAQ,CAAC,OAAO;QACd,MAAM,IAAI,GAAG;YACX,QAAQ,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACpC,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAClC,UAAU,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACtC,aAAa,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;YAC7B,SAAS,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SACrD,CAAC;QACF,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAEzC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAC","sourcesContent":["/*\n Copyright © 2016 Andrew Powell\n\n This Source Code Form is subject to the terms of the Mozilla Public\n License, v. 2.0. If a copy of the MPL was not distributed with this\n file, You can obtain one at http://mozilla.org/MPL/2.0/.\n\n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of this Source Code Form.\n*/\nconst Joi = require('joi');\n\nmodule.exports = {\n validate(options) {\n const keys = {\n compiler: [Joi.object().allow(null)],\n config: [Joi.object().allow(null)],\n configPath: [Joi.string().allow(null)],\n devMiddleware: [Joi.object()],\n hotClient: [Joi.boolean(), Joi.object().allow(null)]\n };\n const schema = Joi.object().keys(keys);\n const results = schema.validate(options);\n\n return results;\n }\n};\n"]}
@@ -1,26 +0,0 @@
1
- /*
2
- Copyright © 2016 Andrew Powell
3
-
4
- This Source Code Form is subject to the terms of the Mozilla Public
5
- License, v. 2.0. If a copy of the MPL was not distributed with this
6
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
-
8
- The above copyright notice and this permission notice shall be
9
- included in all copies or substantial portions of this Source Code Form.
10
- */
11
- const webpackHotClient = require('@hatiolab/webpack-hot-client')
12
-
13
- module.exports = {
14
- getClient(compiler, options) {
15
- if (!options.hotClient) {
16
- return Promise.resolve(null)
17
- }
18
-
19
- return new Promise(resolve => {
20
- const client = webpackHotClient(compiler, options.hotClient)
21
- const { server } = client
22
-
23
- server.on('listening', () => resolve(client))
24
- })
25
- }
26
- }
@@ -1,71 +0,0 @@
1
- /*
2
- Copyright © 2016 Andrew Powell
3
-
4
- This Source Code Form is subject to the terms of the Mozilla Public
5
- License, v. 2.0. If a copy of the MPL was not distributed with this
6
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
-
8
- The above copyright notice and this permission notice shall be
9
- included in all copies or substantial portions of this Source Code Form.
10
- */
11
- const { join } = require('path')
12
-
13
- const root = require('app-root-path')
14
- const chalk = require('chalk')
15
- const webpack = require('webpack')
16
- const webpackDevMiddleware = require('webpack-dev-middleware')
17
-
18
- const { getClient } = require('./client')
19
- const { getMiddleware } = require('./middleware')
20
- const { validate } = require('./validate')
21
-
22
- const defaults = { devMiddleware: {}, hotClient: {} }
23
-
24
- export default async opts => {
25
- const valid = validate(opts)
26
-
27
- if (valid.error) {
28
- const { error } = console
29
- error(chalk.red('⬢ koa-webpack:'), 'An option was passed to koa-webpack that is not valid')
30
- throw valid.error
31
- }
32
-
33
- const options = Object.assign({}, defaults, opts)
34
-
35
- let { compiler, config } = options
36
-
37
- if (!compiler) {
38
- if (!config) {
39
- // eslint-disable-next-line import/no-dynamic-require, global-require
40
- config = require(options.configPath || join(root.path, 'webpack.config.js'))
41
- }
42
-
43
- compiler = webpack(config)
44
- }
45
-
46
- if (!options.devMiddleware.publicPath) {
47
- const { publicPath } = compiler.options.output
48
-
49
- if (!publicPath) {
50
- throw new Error(
51
- "koa-webpack: publicPath must be set on `dev` options, or in a compiler's `output` configuration."
52
- )
53
- }
54
-
55
- options.devMiddleware.publicPath = publicPath
56
- }
57
-
58
- const hotClient = await getClient(compiler, options)
59
- const devMiddleware = webpackDevMiddleware(compiler, options.devMiddleware)
60
- const middleware = getMiddleware(compiler, devMiddleware)
61
- const close = callback => {
62
- const next = hotClient ? () => hotClient.close(callback) : callback
63
- devMiddleware.close(next)
64
- }
65
-
66
- return Object.assign(middleware, {
67
- hotClient,
68
- devMiddleware,
69
- close
70
- })
71
- }
@@ -1,47 +0,0 @@
1
- /*
2
- Copyright © 2016 Andrew Powell
3
-
4
- This Source Code Form is subject to the terms of the Mozilla Public
5
- License, v. 2.0. If a copy of the MPL was not distributed with this
6
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
-
8
- The above copyright notice and this permission notice shall be
9
- included in all copies or substantial portions of this Source Code Form.
10
- */
11
- module.exports = {
12
- getMiddleware(compiler, devMiddleware) {
13
- return (context, next) => {
14
- // wait for webpack-dev-middleware to signal that the build is ready
15
- const ready = new Promise((resolve, reject) => {
16
- for (const comp of [].concat(compiler.compilers || compiler)) {
17
- comp.hooks.failed.tap('KoaWebpack', error => {
18
- reject(error)
19
- })
20
- }
21
-
22
- devMiddleware.waitUntilValid(() => {
23
- resolve(true)
24
- })
25
- })
26
- // tell webpack-dev-middleware to handle the request
27
- const init = new Promise(resolve => {
28
- devMiddleware(
29
- context.req,
30
- {
31
- end: content => {
32
- // eslint-disable-next-line no-param-reassign
33
- context.body = content
34
- resolve(null)
35
- },
36
- getHeader: context.get.bind(context),
37
- setHeader: context.set.bind(context),
38
- locals: context.state
39
- },
40
- () => resolve(next())
41
- )
42
- })
43
-
44
- return Promise.all([ready, init])
45
- }
46
- }
47
- }
@@ -1,27 +0,0 @@
1
- /*
2
- Copyright © 2016 Andrew Powell
3
-
4
- This Source Code Form is subject to the terms of the Mozilla Public
5
- License, v. 2.0. If a copy of the MPL was not distributed with this
6
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
-
8
- The above copyright notice and this permission notice shall be
9
- included in all copies or substantial portions of this Source Code Form.
10
- */
11
- const Joi = require('joi');
12
-
13
- module.exports = {
14
- validate(options) {
15
- const keys = {
16
- compiler: [Joi.object().allow(null)],
17
- config: [Joi.object().allow(null)],
18
- configPath: [Joi.string().allow(null)],
19
- devMiddleware: [Joi.object()],
20
- hotClient: [Joi.boolean(), Joi.object().allow(null)]
21
- };
22
- const schema = Joi.object().keys(keys);
23
- const results = schema.validate(options);
24
-
25
- return results;
26
- }
27
- };