UNPKG

15.7 kBJavaScriptView Raw
1require("regenerator-runtime/runtime");
2(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
3/******/ // The module cache
4/******/ var installedModules = {};
5/******/
6/******/ // The require function
7/******/ function __webpack_require__(moduleId) {
8/******/
9/******/ // Check if module is in cache
10/******/ if(installedModules[moduleId])
11/******/ return installedModules[moduleId].exports;
12/******/
13/******/ // Create a new module (and put it into the cache)
14/******/ var module = installedModules[moduleId] = {
15/******/ i: moduleId,
16/******/ l: false,
17/******/ exports: {}
18/******/ };
19/******/
20/******/ // Execute the module function
21/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22/******/
23/******/ // Flag the module as loaded
24/******/ module.l = true;
25/******/
26/******/ // Return the exports of the module
27/******/ return module.exports;
28/******/ }
29/******/
30/******/
31/******/ // expose the modules object (__webpack_modules__)
32/******/ __webpack_require__.m = modules;
33/******/
34/******/ // expose the module cache
35/******/ __webpack_require__.c = installedModules;
36/******/
37/******/ // identity function for calling harmony imports with the correct context
38/******/ __webpack_require__.i = function(value) { return value; };
39/******/
40/******/ // define getter function for harmony exports
41/******/ __webpack_require__.d = function(exports, name, getter) {
42/******/ if(!__webpack_require__.o(exports, name)) {
43/******/ Object.defineProperty(exports, name, {
44/******/ configurable: false,
45/******/ enumerable: true,
46/******/ get: getter
47/******/ });
48/******/ }
49/******/ };
50/******/
51/******/ // getDefaultExport function for compatibility with non-harmony modules
52/******/ __webpack_require__.n = function(module) {
53/******/ var getter = module && module.__esModule ?
54/******/ function getDefault() { return module['default']; } :
55/******/ function getModuleExports() { return module; };
56/******/ __webpack_require__.d(getter, 'a', getter);
57/******/ return getter;
58/******/ };
59/******/
60/******/ // Object.prototype.hasOwnProperty.call
61/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
62/******/
63/******/ // __webpack_public_path__
64/******/ __webpack_require__.p = "";
65/******/
66/******/ // Load entry module and return exports
67/******/ return __webpack_require__(__webpack_require__.s = 14);
68/******/ })
69/************************************************************************/
70/******/ ([
71/* 0 */
72/***/ (function(module, exports) {
73
74module.exports = require("child_process");
75
76/***/ }),
77/* 1 */
78/***/ (function(module, exports) {
79
80module.exports = require("path");
81
82/***/ }),
83/* 2 */
84/***/ (function(module, exports) {
85
86module.exports = require("webpack");
87
88/***/ }),
89/* 3 */
90/***/ (function(module, exports, __webpack_require__) {
91
92const chalk = __webpack_require__(11),
93 webpack = __webpack_require__(2),
94 path = __webpack_require__(1),
95 ProgressBarPlugin = __webpack_require__(12),
96 externals = __webpack_require__(13);
97
98
99module.exports = function (options) {
100 if (typeof options.extensions === 'string') {
101 options.extensions = options.extensions.split(',');
102 }
103
104 const input = options.input,
105 output = options.output,
106 cwd = options.cwd,
107 sourceDir = path.parse(input).dir,
108 destDir = path.parse(output).dir,
109 modulesDir = path.join(cwd, 'node_modules');
110
111
112 return {
113 target: 'node',
114 externals: [externals({ modulesDir })],
115 devtool: 'source-map',
116 context: path.join(cwd, sourceDir),
117 entry: {
118 js: path.parse(input).base
119 },
120 output: {
121 path: path.join(cwd, destDir),
122 filename: path.parse(output).base,
123 libraryTarget: 'commonjs'
124 },
125 module: {
126 loaders: [{
127 test: /\.js$/,
128 exclude: /node_modules/,
129 loader: 'babel-loader',
130 query: {
131 cacheDirectory: !0,
132 presets: ['babel-preset-stage-2'],
133 plugins: ['transform-export-extensions', 'syntax-decorators', 'transform-decorators-legacy', 'transform-decorators', 'transform-es2015-object-super', 'transform-class-properties', 'transform-es2015-classes', 'minify-constant-folding', 'minify-dead-code-elimination', 'minify-infinity', 'minify-numeric-literals', 'minify-replace', 'transform-merge-sibling-variables', 'transform-minify-booleans', 'transform-regexp-constructors', 'transform-remove-undefined', 'transform-undefined-to-void'].map(p => `babel-plugin-${p}`)
134 }
135 }]
136 },
137 resolve: {
138 extensions: ['.js', '.json'],
139 modules: [path.join(cwd, sourceDir)]
140 },
141 plugins: [new ProgressBarPlugin({
142 clear: !1,
143 format: 'build [:bar] ' + chalk.green(':percent') + ' (:elapsed seconds)'
144 }),
145 //new webpack.NoErrorsPlugin(),
146 new webpack.LoaderOptionsPlugin({
147 minimize: !0,
148 debug: !0
149 }), new webpack.BannerPlugin({
150 banner: 'require("regenerator-runtime/runtime");',
151 raw: !0,
152 entryOnly: !1
153 })],
154 node: {
155 global: !1,
156 process: !1,
157 Buffer: !1,
158 crypto: !1,
159 module: !1,
160 clearImmediate: !1,
161 setImmediate: !1,
162 clearTimeout: !1,
163 setTimeout: !1,
164 os: !1,
165 _filename: !0,
166 __dirname: !0
167 }
168 };
169};
170
171/***/ }),
172/* 4 */
173/***/ (function(module, exports) {
174
175module.exports = require("@exoplay/exobot");
176
177/***/ }),
178/* 5 */
179/***/ (function(module, exports) {
180
181module.exports = require("change-case");
182
183/***/ }),
184/* 6 */
185/***/ (function(module, exports) {
186
187module.exports = require("fs-extra");
188
189/***/ }),
190/* 7 */
191/***/ (function(module, exports) {
192
193module.exports = require("generator-exobot");
194
195/***/ }),
196/* 8 */
197/***/ (function(module, exports) {
198
199module.exports = require("vm");
200
201/***/ }),
202/* 9 */
203/***/ (function(module, exports) {
204
205module.exports = require("yargs");
206
207/***/ }),
208/* 10 */
209/***/ (function(module, exports) {
210
211module.exports = require("yeoman-environment");
212
213/***/ }),
214/* 11 */
215/***/ (function(module, exports) {
216
217module.exports = require("chalk");
218
219/***/ }),
220/* 12 */
221/***/ (function(module, exports) {
222
223module.exports = require("progress-bar-webpack-plugin");
224
225/***/ }),
226/* 13 */
227/***/ (function(module, exports) {
228
229module.exports = require("webpack-node-externals");
230
231/***/ }),
232/* 14 */
233/***/ (function(module, __webpack_exports__, __webpack_require__) {
234
235"use strict";
236Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
237/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__exoplay_exobot__ = __webpack_require__(4);
238/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__exoplay_exobot___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__exoplay_exobot__);
239/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_change_case__ = __webpack_require__(5);
240/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_change_case___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_change_case__);
241/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_webpack__ = __webpack_require__(2);
242/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_webpack___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_webpack__);
243/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_path__ = __webpack_require__(1);
244/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_path___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_path__);
245/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_fs_extra__ = __webpack_require__(6);
246/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_fs_extra___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_4_fs_extra__);
247/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_vm__ = __webpack_require__(8);
248/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_vm___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_5_vm__);
249/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_yeoman_environment__ = __webpack_require__(10);
250/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_yeoman_environment___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_6_yeoman_environment__);
251/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7_child_process__ = __webpack_require__(0);
252/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7_child_process___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_7_child_process__);
253/* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__webpackConfig__ = __webpack_require__(3);
254/* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__webpackConfig___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_8__webpackConfig__);
255/* harmony import */ var __WEBPACK_IMPORTED_MODULE_9_generator_exobot__ = __webpack_require__(7);
256/* harmony import */ var __WEBPACK_IMPORTED_MODULE_9_generator_exobot___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_9_generator_exobot__);
257var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276const yeomanEnv = __WEBPACK_IMPORTED_MODULE_6_yeoman_environment___default.a.createEnv();
277yeomanEnv.register(require.resolve('generator-exobot/generators/app'), 'exobot:app');
278yeomanEnv.register(require.resolve('generator-exobot/generators/adapter'), 'exobot:adapter');
279yeomanEnv.register(require.resolve('generator-exobot/generators/plugin'), 'exobot:plugin');
280
281const defaultName = __WEBPACK_IMPORTED_MODULE_3_path___default.a.parse(process.cwd()).name + '.js',
282 exampleConfig = {
283 key: 'exobot-example',
284 plugins: {
285 shell: ['@exoplay/exobot', { import: 'adapters.Shell' }],
286 http: ['@exoplay/exobot', { import: 'adapters.HTTP' }],
287 uptime: ['@exoplay/exobot', { import: 'plugins.Uptime' }],
288 help: ['@exoplay/exobot', { import: 'plugins.Help' }],
289 greetings: ['@exoplay/exobot', { import: 'plugins.Greetings' }],
290 permissions: ['@exoplay/exobot', { import: 'plugins.Permissions' }],
291 config: ['@exoplay/exobot', { import: 'plugins.Config' }]
292 }
293},
294 inputOption = {
295 input: {
296 alias: 'i',
297 default: `./src/${defaultName}`
298 }
299},
300 outputOption = {
301 output: {
302 alias: 'o',
303 default: defaultName
304 }
305},
306 cwdOption = {
307 cwd: {
308 default: process.cwd()
309 }
310},
311 watchOption = {
312 watch: {
313 alias: 'w',
314 default: !1
315 }
316},
317 forceOption = {
318 force: {
319 alias: 'f',
320 default: !1
321 }
322},
323 argv = __webpack_require__(9).usage('exobot <command> [options]').command('build', 'Builds exobot', _extends({}, inputOption, outputOption, cwdOption, watchOption, forceOption)).command('watch', 'Builds exobot', _extends({}, inputOption, outputOption, cwdOption, forceOption, {
324 watch: _extends({}, watchOption.watch, {
325 default: !0
326 })
327})).command('run', 'Starts an exobot from config', _extends({}, inputOption, outputOption, cwdOption, watchOption, forceOption, {
328 start: {
329 default: !0
330 }
331})).command('example', 'Starts an exobot example', _extends({}, inputOption, outputOption, cwdOption, forceOption)).command('new <bot|plugin|adapter>', 'Bootstraps an exobot project', _extends({}, inputOption, cwdOption, outputOption, forceOption, {
332 name: {
333 default: 'exobot'
334 }
335})).demand(1).boolean('watch').boolean('start').alias('h', 'help').help('h').argv;
336
337function logResult(err, stats) {
338 if (err) {
339 return console.error(err);
340 }
341
342 const jsonStats = stats.toJson();
343
344 if (jsonStats.errors.length > 0) {
345 return console.error(jsonStats.errors);
346 }
347
348 if (jsonStats.warnings.length > 0) {
349 console.warn(jsonStats.warnings);
350 }
351
352 console.log(`Wrote to ${argv.o}`);
353}
354
355function build(args, callback) {
356 const webpackConfig = __WEBPACK_IMPORTED_MODULE_8__webpackConfig___default()(argv),
357 compiler = __WEBPACK_IMPORTED_MODULE_2_webpack___default()(webpackConfig);
358
359
360 if (argv.watch) {
361 compiler.watch({}, (err, stats) => {
362 logResult(err, stats);
363 if (callback) {
364 callback();
365 }
366 });
367 } else {
368 compiler.run((err, stats) => {
369 logResult(err, stats);
370
371 if (callback) {
372 callback();
373 } else {
374 process.exit();
375 }
376 });
377 }
378}
379
380function buildFromConfig(args, configFile, callback) {
381 eval('require')(configFile);
382
383 const packagePath = __WEBPACK_IMPORTED_MODULE_3_path___default.a.join(args.cwd, 'package.json');
384
385 if (__WEBPACK_IMPORTED_MODULE_4_fs_extra___default.a.existsSync(packagePath) && !argv.f) {
386 console.log('Using existing package.json.');
387 } else {
388 console.log('No package.json found; creating one.');
389
390 __WEBPACK_IMPORTED_MODULE_4_fs_extra___default.a.copySync('./package.json', packagePath);
391
392 const pluginsToInstall = (configFile.plugins || []).filter(p => typeof p === 'string');
393
394 __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_7_child_process__["execSync"])('npm install', ['--save', ...pluginsToInstall]);
395 }
396
397 const outputFile = __WEBPACK_IMPORTED_MODULE_3_path___default.a.join(argv.cwd, argv.output);
398
399 console.log('Generating exobot file...');
400
401 const botFileContents = [`require('babel-polyfill')`, `const config = require('${configFile}')`, `const { Exobot } = require('@exoplay/exobot');`, `const bot = new Exobot(config);`, `module.exports = bot;`].join('\n');
402
403 __WEBPACK_IMPORTED_MODULE_4_fs_extra___default.a.createFileSync(outputFile);
404 __WEBPACK_IMPORTED_MODULE_4_fs_extra___default.a.writeFileSync(outputFile, botFileContents);
405
406 if (callback) {
407 callback();
408 }
409}
410
411function createBot(cb = () => {}) {
412 const inputFile = __WEBPACK_IMPORTED_MODULE_3_path___default.a.join(argv.cwd, argv.input),
413 configFile = __WEBPACK_IMPORTED_MODULE_3_path___default.a.join(argv.cwd, 'exobot.config.js'),
414 outputFile = __WEBPACK_IMPORTED_MODULE_3_path___default.a.join(argv.cwd, argv.output);
415
416
417 let exobotPath = inputFile;
418 const exobotSourceExists = __WEBPACK_IMPORTED_MODULE_4_fs_extra___default.a.existsSync(inputFile);
419
420 if (!exobotSourceExists) {
421 if (__WEBPACK_IMPORTED_MODULE_4_fs_extra___default.a.existsSync(configFile)) {
422 exobotPath = configFile;
423 }
424 }
425
426 if (!exobotPath) {
427 throw new Error(`An exobot file was not found at ${inputFile} or ${configFile}.`);
428 }
429
430 buildFromConfig(argv, exobotPath, () => cb(outputFile));
431}
432
433function runExampleBot(args) {
434 const packagePath = __WEBPACK_IMPORTED_MODULE_3_path___default.a.join(args.cwd, 'package.json'),
435 pkg = require(packagePath),
436 botConfig = _extends({}, exampleConfig, {
437 plugins: _extends({}, exampleConfig.plugins, {
438 [__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1_change_case__["camel"])(pkg.name)]: [require(__WEBPACK_IMPORTED_MODULE_3_path___default.a.join(args.cwd, `./${pkg.main}`)), {}]
439 })
440 }),
441 exobot = new __WEBPACK_IMPORTED_MODULE_0__exoplay_exobot__["Exobot"](botConfig);
442
443 return exobot;
444}
445
446switch (argv._[0]) {
447 case 'build':
448 case 'watch':
449 build(argv);
450 break;
451
452 case 'run':
453 createBot(outputFile => __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_7_child_process__["fork"])(outputFile));
454 break;
455
456 case 'example':
457 // run yo generate bot
458 runExampleBot(argv);
459 break;
460
461 case 'new':
462 switch (argv.bot) {
463 case 'bot':
464 yeomanEnv.run('exobot:app');
465 break;
466 case 'adapter':
467 yeomanEnv.run('exobot:adapter');
468 break;
469 case 'plugin':
470 yeomanEnv.run('exobot:plugin');
471 break;
472 }
473 break;
474}
475
476/***/ })
477/******/ ])));
478//# sourceMappingURL=run.js.map
\No newline at end of file