UNPKG

johnny-cli

Version:

CLI for Johnny Deps

91 lines (74 loc) 2.45 kB
// @flow import API from 'API'; import cardinal from 'cardinal'; import Dll from 'Dll'; import {cdnLinkPlugin, dllReferencePlugin} from 'templates'; import fetch from 'node-fetch'; import fs from 'fs'; import JohnnyFile from '../JohnnyFile'; import {getDllHostPackages, logError} from 'helpers'; import PluginsConfig from '../PluginsConfig'; import promptly from 'promptly'; import R from 'ramda'; import settings from 'settings'; require('babel-polyfill'); // WARN Add --path option export default async (name: ?string, cmd: ?{}) => { const packages = getDllHostPackages(); let johnnyFile, token, username = await promptly.prompt('Username: '); let // WARN Hide password input password = await promptly.prompt('Password: '); try { // Authorize to API token = await API({password: password, username: username}).requestToken().then(token => token); // Create johnny.json file with all config params johnnyFile = JohnnyFile().create({ name: name, // WARN fall back to default value if only no --path option passed path: settings.DEFAULT_DLL_PATH, token: token, user : username, }); } catch(error) { logError(error); return; } // Request API in ordeer to create dll on server side try { await API({token: token}).start({name, packages}); } catch(error) { logError(error); // Erase johnny.json if API request failed johnnyFile.remove(); return; } // WARN Apply https://github.com/winstonjs/winston // Build dll-bundle locally try { process.stdout.write('\n\x1b[1mCreating dll bundle...\x1b[0m'); await Dll({path: johnnyFile.get('path')}).create({packages: R.keys(packages)}); process.stdout.write('\x1b[1m\x1b[32mDone\x1b[0m\n'); } catch(error) { logError('\n\n' + error); return; } // Emit configuration options process.stdout.write('\n\x1b[1mPut this into .plugins array of webpack config and you ready to go.\n'); process.stdout.write('Please note that "manifest" and "bundleConfig" are paths relative to your webpack config file.\x1b[0m\n\n'); console.log( cardinal.highlight('// Johnny Deps plugins') + dllReferencePlugin() + cdnLinkPlugin() + cardinal.highlight('// End of Johnny Deps plugins\n') ); // WARN Auto locate webpack config and put correct paths process.stdout.write('\n\x1b[1mDon\'t forget to:\x1b[0m\n'); console.log(`* to replace paths * properly setup dev environment flag * change the dev sever params if needed.\n`); };