react-cosmos 5.6.4
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.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/bin/cosmos-export.js +14 -0
- package/bin/cosmos-native.js +14 -0
- package/bin/cosmos.js +18 -0
- package/config.schema.json +186 -0
- package/dist/config/createCosmosConfig.d.ts +2 -0
- package/dist/config/createCosmosConfig.js +133 -0
- package/dist/config/detectCosmosConfig.d.ts +2 -0
- package/dist/config/detectCosmosConfig.js +57 -0
- package/dist/config/getCosmosConfigAtPath.d.ts +1 -0
- package/dist/config/getCosmosConfigAtPath.js +28 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.js +51 -0
- package/dist/config/resolve.d.ts +1 -0
- package/dist/config/resolve.js +20 -0
- package/dist/config/shared.d.ts +29 -0
- package/dist/config/shared.js +17 -0
- package/dist/dom/DomFixtureLoader.d.ts +8 -0
- package/dist/dom/DomFixtureLoader.js +38 -0
- package/dist/dom/ErrorCatch.d.ts +15 -0
- package/dist/dom/ErrorCatch.js +117 -0
- package/dist/dom/container.d.ts +1 -0
- package/dist/dom/container.js +32 -0
- package/dist/dom/globalErrorHandler.d.ts +1 -0
- package/dist/dom/globalErrorHandler.js +14 -0
- package/dist/dom/index.d.ts +13 -0
- package/dist/dom/index.js +47 -0
- package/dist/dom/renderMessage.d.ts +3 -0
- package/dist/dom/renderMessage.js +30 -0
- package/dist/dom/rendererConnect.d.ts +1 -0
- package/dist/dom/rendererConnect.js +18 -0
- package/dist/dom/rendererId.d.ts +1 -0
- package/dist/dom/rendererId.js +26 -0
- package/dist/dom/selectedFixtureId.d.ts +2 -0
- package/dist/dom/selectedFixtureId.js +41 -0
- package/dist/dom/shared.d.ts +1 -0
- package/dist/dom/shared.js +14 -0
- package/dist/fixture.d.ts +1 -0
- package/dist/fixture.js +31 -0
- package/dist/getFixtureUrls.d.ts +8 -0
- package/dist/getFixtureUrls.js +98 -0
- package/dist/getFixtures.d.ts +13 -0
- package/dist/getFixtures.js +90 -0
- package/dist/getFixtures2.d.ts +14 -0
- package/dist/getFixtures2.js +117 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +67 -0
- package/dist/native.d.ts +9 -0
- package/dist/native.js +69 -0
- package/dist/nativeServer.d.ts +1 -0
- package/dist/nativeServer.js +39 -0
- package/dist/plugins/httpProxy.d.ts +2 -0
- package/dist/plugins/httpProxy.js +31 -0
- package/dist/plugins/openFile.d.ts +2 -0
- package/dist/plugins/openFile.js +87 -0
- package/dist/plugins/userDepsFile.d.ts +2 -0
- package/dist/plugins/userDepsFile.js +164 -0
- package/dist/plugins/webpack/client/errorOverlay/index.d.ts +1 -0
- package/dist/plugins/webpack/client/errorOverlay/index.js +16 -0
- package/dist/plugins/webpack/client/errorOverlay/reactErrorOverlay.d.ts +2 -0
- package/dist/plugins/webpack/client/errorOverlay/reactErrorOverlay.js +63 -0
- package/dist/plugins/webpack/client/hmrErrorHandler.d.ts +1 -0
- package/dist/plugins/webpack/client/hmrErrorHandler.js +16 -0
- package/dist/plugins/webpack/client/index.d.ts +6 -0
- package/dist/plugins/webpack/client/index.js +43 -0
- package/dist/plugins/webpack/client/reactDevtoolsHook.d.ts +0 -0
- package/dist/plugins/webpack/client/reactDevtoolsHook.js +19 -0
- package/dist/plugins/webpack/client/userDeps.d.ts +5 -0
- package/dist/plugins/webpack/client/userDeps.js +15 -0
- package/dist/plugins/webpack/cosmosConfig/dom.d.ts +6 -0
- package/dist/plugins/webpack/cosmosConfig/dom.js +19 -0
- package/dist/plugins/webpack/cosmosConfig/webpack.d.ts +9 -0
- package/dist/plugins/webpack/cosmosConfig/webpack.js +88 -0
- package/dist/plugins/webpack/devServer.d.ts +2 -0
- package/dist/plugins/webpack/devServer.js +168 -0
- package/dist/plugins/webpack/export.d.ts +2 -0
- package/dist/plugins/webpack/export.js +135 -0
- package/dist/plugins/webpack/index.d.ts +2 -0
- package/dist/plugins/webpack/index.js +21 -0
- package/dist/plugins/webpack/shared.d.ts +2 -0
- package/dist/plugins/webpack/shared.js +22 -0
- package/dist/plugins/webpack/webpackConfig/default.d.ts +2 -0
- package/dist/plugins/webpack/webpackConfig/default.js +152 -0
- package/dist/plugins/webpack/webpackConfig/devServer.d.ts +3 -0
- package/dist/plugins/webpack/webpackConfig/devServer.js +144 -0
- package/dist/plugins/webpack/webpackConfig/export.d.ts +3 -0
- package/dist/plugins/webpack/webpackConfig/export.js +110 -0
- package/dist/plugins/webpack/webpackConfig/htmlPlugin.d.ts +16 -0
- package/dist/plugins/webpack/webpackConfig/htmlPlugin.js +80 -0
- package/dist/plugins/webpack/webpackConfig/index.d.ts +2 -0
- package/dist/plugins/webpack/webpackConfig/index.js +21 -0
- package/dist/plugins/webpack/webpackConfig/module.d.ts +3 -0
- package/dist/plugins/webpack/webpackConfig/module.js +18 -0
- package/dist/plugins/webpack/webpackConfig/shared.d.ts +11 -0
- package/dist/plugins/webpack/webpackConfig/shared.js +254 -0
- package/dist/plugins/webpack/webpackConfig/userDepsLoader.d.ts +1 -0
- package/dist/plugins/webpack/webpackConfig/userDepsLoader.js +36 -0
- package/dist/shared/cli.d.ts +5 -0
- package/dist/shared/cli.js +14 -0
- package/dist/shared/devServer/app.d.ts +5 -0
- package/dist/shared/devServer/app.js +51 -0
- package/dist/shared/devServer/httpServer.d.ts +11 -0
- package/dist/shared/devServer/httpServer.js +183 -0
- package/dist/shared/devServer/index.d.ts +18 -0
- package/dist/shared/devServer/index.js +209 -0
- package/dist/shared/devServer/messageHandler.d.ts +7 -0
- package/dist/shared/devServer/messageHandler.js +42 -0
- package/dist/shared/export.d.ts +6 -0
- package/dist/shared/export.js +137 -0
- package/dist/shared/fs.d.ts +4 -0
- package/dist/shared/fs.js +37 -0
- package/dist/shared/playgroundHtml.d.ts +6 -0
- package/dist/shared/playgroundHtml.js +116 -0
- package/dist/shared/pluginConfigs.d.ts +2 -0
- package/dist/shared/pluginConfigs.js +15 -0
- package/dist/shared/rendererConfig.d.ts +6 -0
- package/dist/shared/rendererConfig.js +5 -0
- package/dist/shared/shared.d.ts +6 -0
- package/dist/shared/shared.js +22 -0
- package/dist/shared/static/favicon.ico +0 -0
- package/dist/shared/static/index.html +19 -0
- package/dist/shared/static.d.ts +3 -0
- package/dist/shared/static.js +30 -0
- package/dist/shared/userDeps/findUserModulePaths.d.ts +11 -0
- package/dist/shared/userDeps/findUserModulePaths.js +45 -0
- package/dist/shared/userDeps/generateUserDepsModule.d.ts +9 -0
- package/dist/shared/userDeps/generateUserDepsModule.js +37 -0
- package/dist/shared/userDeps/getUserModules.d.ts +8 -0
- package/dist/shared/userDeps/getUserModules.js +45 -0
- package/dist/shared/userDeps/index.d.ts +4 -0
- package/dist/shared/userDeps/index.js +49 -0
- package/dist/shared/userDeps/shared.d.ts +6 -0
- package/dist/shared/userDeps/shared.js +32 -0
- package/dist/shared/userDeps/userDepsTemplate.d.ts +11 -0
- package/dist/shared/userDeps/userDepsTemplate.js +52 -0
- package/dist/webExport.d.ts +1 -0
- package/dist/webExport.js +37 -0
- package/dist/webServer.d.ts +1 -0
- package/dist/webServer.js +43 -0
- package/dom.d.ts +1 -0
- package/dom.js +2 -0
- package/fixture.d.ts +1 -0
- package/fixture.js +2 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/native.d.ts +1 -0
- package/native.js +2 -0
- package/package.json +42 -0
- package/yarn-error.log +13450 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createHttpServer = createHttpServer;
|
|
7
|
+
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
|
|
10
|
+
var _http = _interopRequireDefault(require("http"));
|
|
11
|
+
|
|
12
|
+
var _https = _interopRequireDefault(require("https"));
|
|
13
|
+
|
|
14
|
+
var _pem = _interopRequireDefault(require("pem"));
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
19
|
+
|
|
20
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
21
|
+
|
|
22
|
+
function createHttpServer(_x, _x2) {
|
|
23
|
+
return _createHttpServer.apply(this, arguments);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function _createHttpServer() {
|
|
27
|
+
_createHttpServer = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(cosmosConfig, requestListener) {
|
|
28
|
+
var port, hostname, httpsEnabled, server, start, _start, stop, _stop;
|
|
29
|
+
|
|
30
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
31
|
+
while (1) {
|
|
32
|
+
switch (_context3.prev = _context3.next) {
|
|
33
|
+
case 0:
|
|
34
|
+
_stop = function _stop3() {
|
|
35
|
+
_stop = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
36
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
37
|
+
while (1) {
|
|
38
|
+
switch (_context2.prev = _context2.next) {
|
|
39
|
+
case 0:
|
|
40
|
+
_context2.next = 2;
|
|
41
|
+
return new Promise(function (resolve) {
|
|
42
|
+
return server.close(resolve);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
case 2:
|
|
46
|
+
case "end":
|
|
47
|
+
return _context2.stop();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}, _callee2);
|
|
51
|
+
}));
|
|
52
|
+
return _stop.apply(this, arguments);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
stop = function _stop2() {
|
|
56
|
+
return _stop.apply(this, arguments);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
_start = function _start3() {
|
|
60
|
+
_start = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
61
|
+
var hostnameDisplay, protocol;
|
|
62
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
63
|
+
while (1) {
|
|
64
|
+
switch (_context.prev = _context.next) {
|
|
65
|
+
case 0:
|
|
66
|
+
_context.next = 2;
|
|
67
|
+
return new Promise(function (resolve) {
|
|
68
|
+
if (hostname === null) {
|
|
69
|
+
server.listen(port, resolve);
|
|
70
|
+
} else {
|
|
71
|
+
server.listen(port, hostname, resolve);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
case 2:
|
|
76
|
+
hostnameDisplay = hostname || 'localhost';
|
|
77
|
+
protocol = httpsEnabled ? 'https' : 'http';
|
|
78
|
+
console.log("[Cosmos] See you at ".concat(protocol, "://").concat(hostnameDisplay, ":").concat(port));
|
|
79
|
+
|
|
80
|
+
case 5:
|
|
81
|
+
case "end":
|
|
82
|
+
return _context.stop();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}, _callee);
|
|
86
|
+
}));
|
|
87
|
+
return _start.apply(this, arguments);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
start = function _start2() {
|
|
91
|
+
return _start.apply(this, arguments);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
port = cosmosConfig.port, hostname = cosmosConfig.hostname, httpsEnabled = cosmosConfig.https;
|
|
95
|
+
|
|
96
|
+
if (!httpsEnabled) {
|
|
97
|
+
_context3.next = 14;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
_context3.t1 = _https.default;
|
|
102
|
+
_context3.next = 9;
|
|
103
|
+
return getHttpsOpts(cosmosConfig);
|
|
104
|
+
|
|
105
|
+
case 9:
|
|
106
|
+
_context3.t2 = _context3.sent;
|
|
107
|
+
_context3.t3 = requestListener;
|
|
108
|
+
_context3.t0 = _context3.t1.createServer.call(_context3.t1, _context3.t2, _context3.t3);
|
|
109
|
+
_context3.next = 15;
|
|
110
|
+
break;
|
|
111
|
+
|
|
112
|
+
case 14:
|
|
113
|
+
_context3.t0 = _http.default.createServer(requestListener);
|
|
114
|
+
|
|
115
|
+
case 15:
|
|
116
|
+
server = _context3.t0;
|
|
117
|
+
return _context3.abrupt("return", {
|
|
118
|
+
server: server,
|
|
119
|
+
start: start,
|
|
120
|
+
stop: stop
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
case 17:
|
|
124
|
+
case "end":
|
|
125
|
+
return _context3.stop();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}, _callee3);
|
|
129
|
+
}));
|
|
130
|
+
return _createHttpServer.apply(this, arguments);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function getHttpsOpts(_x3) {
|
|
134
|
+
return _getHttpsOpts.apply(this, arguments);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function _getHttpsOpts() {
|
|
138
|
+
_getHttpsOpts = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(cosmosConfig) {
|
|
139
|
+
var httpsOptions;
|
|
140
|
+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
141
|
+
while (1) {
|
|
142
|
+
switch (_context4.prev = _context4.next) {
|
|
143
|
+
case 0:
|
|
144
|
+
httpsOptions = cosmosConfig.httpsOptions;
|
|
145
|
+
|
|
146
|
+
if (!httpsOptions) {
|
|
147
|
+
_context4.next = 3;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return _context4.abrupt("return", {
|
|
152
|
+
key: _fs.default.readFileSync(httpsOptions.keyPath, 'utf8'),
|
|
153
|
+
cert: _fs.default.readFileSync(httpsOptions.certPath, 'utf8')
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
case 3:
|
|
157
|
+
console.log('[Cosmos] Generating HTTPS certificate');
|
|
158
|
+
_context4.next = 6;
|
|
159
|
+
return new Promise(function (resolve, reject) {
|
|
160
|
+
_pem.default.createCertificate({
|
|
161
|
+
days: 1000,
|
|
162
|
+
selfSigned: true
|
|
163
|
+
}, function (err, keys) {
|
|
164
|
+
if (err) return reject(err);
|
|
165
|
+
return resolve({
|
|
166
|
+
key: keys.serviceKey,
|
|
167
|
+
cert: keys.certificate
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
case 6:
|
|
173
|
+
return _context4.abrupt("return", _context4.sent);
|
|
174
|
+
|
|
175
|
+
case 7:
|
|
176
|
+
case "end":
|
|
177
|
+
return _context4.stop();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}, _callee4);
|
|
181
|
+
}));
|
|
182
|
+
return _getHttpsOpts.apply(this, arguments);
|
|
183
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import http from 'http';
|
|
4
|
+
import { Message } from 'react-cosmos-shared2/util';
|
|
5
|
+
import { CosmosConfig } from '../../config';
|
|
6
|
+
import { PlatformType } from '../shared';
|
|
7
|
+
declare type PluginCleanupCallback = () => unknown;
|
|
8
|
+
declare type PluginReturn = void | null | PluginCleanupCallback;
|
|
9
|
+
export declare type DevServerPluginArgs = {
|
|
10
|
+
cosmosConfig: CosmosConfig;
|
|
11
|
+
platformType: PlatformType;
|
|
12
|
+
httpServer: http.Server;
|
|
13
|
+
expressApp: express.Express;
|
|
14
|
+
sendMessage(msg: Message): unknown;
|
|
15
|
+
};
|
|
16
|
+
export declare type DevServerPlugin = (args: DevServerPluginArgs) => PluginReturn | Promise<PluginReturn>;
|
|
17
|
+
export declare function startDevServer(platformType: PlatformType, plugins?: DevServerPlugin[]): Promise<() => Promise<void>>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.startDevServer = startDevServer;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _config = require("../../config");
|
|
11
|
+
|
|
12
|
+
var _pluginConfigs = require("../pluginConfigs");
|
|
13
|
+
|
|
14
|
+
var _static = require("../static");
|
|
15
|
+
|
|
16
|
+
var _app = require("./app");
|
|
17
|
+
|
|
18
|
+
var _httpServer = require("./httpServer");
|
|
19
|
+
|
|
20
|
+
var _messageHandler = require("./messageHandler");
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
25
|
+
|
|
26
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
27
|
+
|
|
28
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
29
|
+
|
|
30
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
31
|
+
|
|
32
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
33
|
+
|
|
34
|
+
function startDevServer(_x) {
|
|
35
|
+
return _startDevServer.apply(this, arguments);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function _startDevServer() {
|
|
39
|
+
_startDevServer = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(platformType) {
|
|
40
|
+
var plugins,
|
|
41
|
+
cosmosConfig,
|
|
42
|
+
pluginConfigs,
|
|
43
|
+
app,
|
|
44
|
+
pluginCleanupCallbacks,
|
|
45
|
+
httpServer,
|
|
46
|
+
msgHandler,
|
|
47
|
+
cleanUp,
|
|
48
|
+
_cleanUp,
|
|
49
|
+
_iterator,
|
|
50
|
+
_step,
|
|
51
|
+
plugin,
|
|
52
|
+
pluginReturn,
|
|
53
|
+
_args2 = arguments;
|
|
54
|
+
|
|
55
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
56
|
+
while (1) {
|
|
57
|
+
switch (_context2.prev = _context2.next) {
|
|
58
|
+
case 0:
|
|
59
|
+
_cleanUp = function _cleanUp3() {
|
|
60
|
+
_cleanUp = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
61
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
62
|
+
while (1) {
|
|
63
|
+
switch (_context.prev = _context.next) {
|
|
64
|
+
case 0:
|
|
65
|
+
_context.next = 2;
|
|
66
|
+
return Promise.all(pluginCleanupCallbacks.map(function (cleanup) {
|
|
67
|
+
return cleanup();
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
case 2:
|
|
71
|
+
_context.next = 4;
|
|
72
|
+
return httpServer.stop();
|
|
73
|
+
|
|
74
|
+
case 4:
|
|
75
|
+
msgHandler.cleanUp();
|
|
76
|
+
|
|
77
|
+
case 5:
|
|
78
|
+
case "end":
|
|
79
|
+
return _context.stop();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, _callee);
|
|
83
|
+
}));
|
|
84
|
+
return _cleanUp.apply(this, arguments);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
cleanUp = function _cleanUp2() {
|
|
88
|
+
return _cleanUp.apply(this, arguments);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
plugins = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : [];
|
|
92
|
+
cosmosConfig = (0, _config.detectCosmosConfig)();
|
|
93
|
+
logCosmosConfigInfo();
|
|
94
|
+
pluginConfigs = (0, _pluginConfigs.getPluginConfigs)(cosmosConfig);
|
|
95
|
+
logPluginInfo(pluginConfigs);
|
|
96
|
+
app = (0, _app.createApp)(platformType, cosmosConfig, pluginConfigs);
|
|
97
|
+
|
|
98
|
+
if (cosmosConfig.staticPath) {
|
|
99
|
+
(0, _static.serveStaticDir)(app, cosmosConfig.staticPath, cosmosConfig.publicUrl);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
pluginCleanupCallbacks = [];
|
|
103
|
+
_context2.next = 12;
|
|
104
|
+
return (0, _httpServer.createHttpServer)(cosmosConfig, app);
|
|
105
|
+
|
|
106
|
+
case 12:
|
|
107
|
+
httpServer = _context2.sent;
|
|
108
|
+
_context2.next = 15;
|
|
109
|
+
return httpServer.start();
|
|
110
|
+
|
|
111
|
+
case 15:
|
|
112
|
+
msgHandler = (0, _messageHandler.createMessageHandler)(httpServer.server);
|
|
113
|
+
_context2.prev = 16;
|
|
114
|
+
_iterator = _createForOfIteratorHelper(plugins);
|
|
115
|
+
_context2.prev = 18;
|
|
116
|
+
|
|
117
|
+
_iterator.s();
|
|
118
|
+
|
|
119
|
+
case 20:
|
|
120
|
+
if ((_step = _iterator.n()).done) {
|
|
121
|
+
_context2.next = 28;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
plugin = _step.value;
|
|
126
|
+
_context2.next = 24;
|
|
127
|
+
return plugin({
|
|
128
|
+
cosmosConfig: cosmosConfig,
|
|
129
|
+
platformType: platformType,
|
|
130
|
+
httpServer: httpServer.server,
|
|
131
|
+
expressApp: app,
|
|
132
|
+
sendMessage: msgHandler.sendMessage
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
case 24:
|
|
136
|
+
pluginReturn = _context2.sent;
|
|
137
|
+
|
|
138
|
+
if (typeof pluginReturn === 'function') {
|
|
139
|
+
pluginCleanupCallbacks.push(pluginReturn);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
case 26:
|
|
143
|
+
_context2.next = 20;
|
|
144
|
+
break;
|
|
145
|
+
|
|
146
|
+
case 28:
|
|
147
|
+
_context2.next = 33;
|
|
148
|
+
break;
|
|
149
|
+
|
|
150
|
+
case 30:
|
|
151
|
+
_context2.prev = 30;
|
|
152
|
+
_context2.t0 = _context2["catch"](18);
|
|
153
|
+
|
|
154
|
+
_iterator.e(_context2.t0);
|
|
155
|
+
|
|
156
|
+
case 33:
|
|
157
|
+
_context2.prev = 33;
|
|
158
|
+
|
|
159
|
+
_iterator.f();
|
|
160
|
+
|
|
161
|
+
return _context2.finish(33);
|
|
162
|
+
|
|
163
|
+
case 36:
|
|
164
|
+
_context2.next = 42;
|
|
165
|
+
break;
|
|
166
|
+
|
|
167
|
+
case 38:
|
|
168
|
+
_context2.prev = 38;
|
|
169
|
+
_context2.t1 = _context2["catch"](16);
|
|
170
|
+
cleanUp();
|
|
171
|
+
throw _context2.t1;
|
|
172
|
+
|
|
173
|
+
case 42:
|
|
174
|
+
return _context2.abrupt("return", cleanUp);
|
|
175
|
+
|
|
176
|
+
case 43:
|
|
177
|
+
case "end":
|
|
178
|
+
return _context2.stop();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}, _callee2, null, [[16, 38], [18, 30, 33, 36]]);
|
|
182
|
+
}));
|
|
183
|
+
return _startDevServer.apply(this, arguments);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function logCosmosConfigInfo() {
|
|
187
|
+
var cosmosConfigPath = (0, _config.detectCosmosConfigPath)();
|
|
188
|
+
|
|
189
|
+
if (!cosmosConfigPath) {
|
|
190
|
+
console.log("[Cosmos] Using default cosmos config");
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
var relConfigPath = _path.default.relative(process.cwd(), cosmosConfigPath);
|
|
195
|
+
|
|
196
|
+
console.log("[Cosmos] Using cosmos config found at ".concat(relConfigPath));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function logPluginInfo(pluginConfigs) {
|
|
200
|
+
var pluginCount = pluginConfigs.length;
|
|
201
|
+
|
|
202
|
+
if (pluginCount > 0) {
|
|
203
|
+
var pluginLabel = pluginCount === 1 ? 'plugin' : 'plugins';
|
|
204
|
+
var pluginNames = pluginConfigs.map(function (p) {
|
|
205
|
+
return p.name;
|
|
206
|
+
}).join(', ');
|
|
207
|
+
console.log("[Cosmos] Found ".concat(pluginCount, " ").concat(pluginLabel, ": ").concat(pluginNames));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createMessageHandler = createMessageHandler;
|
|
7
|
+
|
|
8
|
+
var _socket = _interopRequireDefault(require("socket.io"));
|
|
9
|
+
|
|
10
|
+
var _build = require("react-cosmos-shared2/build");
|
|
11
|
+
|
|
12
|
+
var _renderer = require("react-cosmos-shared2/renderer");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
function createMessageHandler(httpServer) {
|
|
17
|
+
var io = (0, _socket.default)(httpServer);
|
|
18
|
+
io.on('connection', function (socket) {
|
|
19
|
+
// Forward commands between connected clients. Parties involved can be the
|
|
20
|
+
// - The Cosmos UI, which acts as a remote control
|
|
21
|
+
// - The web iframe or the React Native component renderers
|
|
22
|
+
socket.on(_renderer.RENDERER_MESSAGE_EVENT_NAME, function (msg) {
|
|
23
|
+
socket.broadcast.emit(_renderer.RENDERER_MESSAGE_EVENT_NAME, msg);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function sendMessage(msg) {
|
|
28
|
+
io.emit(_build.SERVER_MESSAGE_EVENT_NAME, msg);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function cleanUp() {
|
|
32
|
+
var sockets = io.sockets.sockets;
|
|
33
|
+
Object.keys(sockets).forEach(function (id) {
|
|
34
|
+
sockets[id].disconnect(true);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
sendMessage: sendMessage,
|
|
40
|
+
cleanUp: cleanUp
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CosmosConfig } from '../config';
|
|
2
|
+
export declare type ExportPluginArgs = {
|
|
3
|
+
cosmosConfig: CosmosConfig;
|
|
4
|
+
};
|
|
5
|
+
export declare type ExportPlugin = (args: ExportPluginArgs) => unknown;
|
|
6
|
+
export declare function generateExport(plugins?: ExportPlugin[]): Promise<void>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateExport = generateExport;
|
|
7
|
+
|
|
8
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
|
+
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
|
|
12
|
+
var _config = require("../config");
|
|
13
|
+
|
|
14
|
+
var _playgroundHtml = require("./playgroundHtml");
|
|
15
|
+
|
|
16
|
+
var _pluginConfigs = require("./pluginConfigs");
|
|
17
|
+
|
|
18
|
+
var _shared = require("./shared");
|
|
19
|
+
|
|
20
|
+
var _static = require("./static");
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
25
|
+
|
|
26
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
27
|
+
|
|
28
|
+
function generateExport() {
|
|
29
|
+
return _generateExport.apply(this, arguments);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _generateExport() {
|
|
33
|
+
_generateExport = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
34
|
+
var plugins,
|
|
35
|
+
cosmosConfig,
|
|
36
|
+
exportPath,
|
|
37
|
+
_args = arguments;
|
|
38
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
39
|
+
while (1) {
|
|
40
|
+
switch (_context.prev = _context.next) {
|
|
41
|
+
case 0:
|
|
42
|
+
plugins = _args.length > 0 && _args[0] !== undefined ? _args[0] : [];
|
|
43
|
+
cosmosConfig = (0, _config.detectCosmosConfig)(); // Clear previous export (or other files at export path)
|
|
44
|
+
|
|
45
|
+
exportPath = cosmosConfig.exportPath;
|
|
46
|
+
|
|
47
|
+
_fsExtra.default.removeSync(exportPath); // Copy static assets first, so that the built index.html overrides the its
|
|
48
|
+
// template file (in case the static assets are served from the root path)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
copyStaticAssets(cosmosConfig);
|
|
52
|
+
_context.next = 7;
|
|
53
|
+
return Promise.all(plugins.map(function (plugin) {
|
|
54
|
+
return plugin({
|
|
55
|
+
cosmosConfig: cosmosConfig
|
|
56
|
+
});
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
case 7:
|
|
60
|
+
exportPlaygroundFiles(cosmosConfig);
|
|
61
|
+
console.log('[Cosmos] Export complete!');
|
|
62
|
+
console.log("Export path: ".concat(cosmosConfig.exportPath));
|
|
63
|
+
|
|
64
|
+
case 10:
|
|
65
|
+
case "end":
|
|
66
|
+
return _context.stop();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, _callee);
|
|
70
|
+
}));
|
|
71
|
+
return _generateExport.apply(this, arguments);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function copyStaticAssets(cosmosConfig) {
|
|
75
|
+
var staticPath = cosmosConfig.staticPath;
|
|
76
|
+
|
|
77
|
+
if (!staticPath) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var exportPath = cosmosConfig.exportPath;
|
|
82
|
+
|
|
83
|
+
if (exportPath.indexOf(staticPath) !== -1) {
|
|
84
|
+
console.warn("[Cosmos] Warning: Can't export static path because it contains the export path! (avoiding infinite loop)");
|
|
85
|
+
console.warn('Public path:', staticPath);
|
|
86
|
+
console.warn('Export path:', exportPath);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!_fsExtra.default.existsSync(staticPath)) {
|
|
91
|
+
console.log('[Cosmos] Warning: config.staticPath points to missing dir', staticPath);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
var publicUrl = cosmosConfig.publicUrl;
|
|
96
|
+
|
|
97
|
+
var exportStaticPath = _path.default.resolve(exportPath, (0, _shared.removeLeadingSlash)(publicUrl));
|
|
98
|
+
|
|
99
|
+
_fsExtra.default.copySync(staticPath, exportStaticPath);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function exportPlaygroundFiles(cosmosConfig) {
|
|
103
|
+
var exportPath = cosmosConfig.exportPath;
|
|
104
|
+
var pluginConfigs = (0, _pluginConfigs.getPluginConfigs)(cosmosConfig);
|
|
105
|
+
pluginConfigs.forEach(function (pluginConfig) {
|
|
106
|
+
return exportPlugin(cosmosConfig, pluginConfig);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
_fsExtra.default.copySync(require.resolve('react-cosmos-playground2/dist'), _path.default.resolve(exportPath, '_playground.js'));
|
|
110
|
+
|
|
111
|
+
_fsExtra.default.copySync((0, _static.getStaticPath)('favicon.ico'), _path.default.resolve(exportPath, '_cosmos.ico'));
|
|
112
|
+
|
|
113
|
+
var playgroundHtml = (0, _playgroundHtml.getExportPlaygroundHtml)(cosmosConfig, pluginConfigs);
|
|
114
|
+
|
|
115
|
+
_fsExtra.default.writeFileSync(_path.default.resolve(exportPath, 'index.html'), playgroundHtml);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function exportPlugin(cosmosConfig, pluginConfig) {
|
|
119
|
+
var rootDir = cosmosConfig.rootDir,
|
|
120
|
+
exportPath = cosmosConfig.exportPath;
|
|
121
|
+
|
|
122
|
+
var pluginExportDir = _path.default.resolve(exportPath, '_plugin'); // Copy plugin config
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
var relConfigPath = _path.default.join(pluginConfig.rootDir, 'cosmos.plugin.json');
|
|
126
|
+
|
|
127
|
+
var absConfigPath = _path.default.resolve(rootDir, relConfigPath);
|
|
128
|
+
|
|
129
|
+
_fsExtra.default.copySync(absConfigPath, _path.default.resolve(pluginExportDir, relConfigPath)); // Copy UI script
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
if (pluginConfig.ui) {
|
|
133
|
+
var absUiPath = _path.default.resolve(rootDir, pluginConfig.ui);
|
|
134
|
+
|
|
135
|
+
_fsExtra.default.copySync(absUiPath, _path.default.resolve(pluginExportDir, pluginConfig.ui));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.requireModule = requireModule;
|
|
7
|
+
exports.moduleExists = moduleExists;
|
|
8
|
+
exports.fileExists = fileExists;
|
|
9
|
+
exports.dirExists = dirExists;
|
|
10
|
+
|
|
11
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
|
|
15
|
+
// NOTE: This API has been extracted to be easily mocked inside tests
|
|
16
|
+
function requireModule(modulePath) {
|
|
17
|
+
// This purpose of this wrapper is merely to make it easy to mock user
|
|
18
|
+
// modules in tests
|
|
19
|
+
return require(modulePath);
|
|
20
|
+
} // Better than fs.exists because it works for module paths without an extension
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function moduleExists(modulePath) {
|
|
24
|
+
try {
|
|
25
|
+
return require.resolve(modulePath) && true;
|
|
26
|
+
} catch (err) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function fileExists(filePath) {
|
|
32
|
+
return _fs.default.existsSync(filePath) && _fs.default.lstatSync(filePath).isFile();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function dirExists(dirPath) {
|
|
36
|
+
return _fs.default.existsSync(dirPath) && _fs.default.lstatSync(dirPath).isDirectory();
|
|
37
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CosmosPluginConfig } from 'react-cosmos-plugin';
|
|
2
|
+
import { CosmosConfig } from '../config';
|
|
3
|
+
import { PlatformType } from './shared';
|
|
4
|
+
export declare const RENDERER_FILENAME = "_renderer.html";
|
|
5
|
+
export declare function getDevPlaygroundHtml(platformType: PlatformType, cosmosConfig: CosmosConfig, pluginConfigs: CosmosPluginConfig[]): string;
|
|
6
|
+
export declare function getExportPlaygroundHtml(cosmosConfig: CosmosConfig, pluginConfigs: CosmosPluginConfig[]): string;
|