UNPKG

ryuu

Version:

Domo App Dev Studio CLI, The main tool used to create, edit, and publish app designs to Domo

85 lines 3.69 kB
"use strict"; /** * domo dev server */ Object.defineProperty(exports, "__esModule", { value: true }); exports.start = void 0; var path = require("path"); var _ = require("lodash"); var fs = require("fs-extra"); var bs = require('browser-sync').create(); var portfinder = require("portfinder"); portfinder.basePort = 3000; var session_1 = require("../util/session"); var appStructure = require("../util/appStructure"); var manifest_1 = require("../util/manifest"); var log_1 = require("../util/log"); var express = require("express"); var app = express(); var Proxy = require('@domoinc/ryuu-proxy').Proxy; var start = function (client, options) { return new Promise(function (resolve, reject) { portfinder.getPorts(2, {}, function (err, ports) { var assetsPort = ports[0]; var dataPort = ports[1]; var manifest = manifest_1.ManifestUtils.getManifest(options.manifest); // If we don't have an app proxyId, get a temporary one if (!manifest.proxyId) { client.createApp(manifest.id).then(function (app) { manifest.proxyId = app.instance.id; }); } var proxy = new Proxy({ manifest: manifest }, manifest.proxyId); app.get('/', function (req, res) { client.getDomoappsData(manifest).then(function (appData) { // sizes consistent with Domo Web var sizeMultiplier = { width: 235, height: 290, }; var width = sizeMultiplier.width * manifest.size.width - 10 + 'px'; var height = sizeMultiplier.height * manifest.size.height - 40 + 'px'; var userId = options.userId || appData.user.id; var customerId = appData.customer || 1; var url = "index.html?userId=".concat(userId, "&customer=").concat(customerId, "&locale=en-US&platform=desktop"); var hasThumbnail = appStructure.hasThumbnail(); var template = _.template(fs.readFileSync(path.resolve(__dirname + '/../server/domodev/index.html'), 'utf8')); var fullpage = manifest.fullpage; res.send(template({ manifest: manifest, width: width, height: height, url: url, hasThumbnail: hasThumbnail, fullpage: fullpage, })); }); }); app.use('/domodev', express.static(path.resolve(__dirname + '/../server/domodev'))); app.use(express.static('.')); app.use(proxy.express()); session_1.Session.check(client) .then(function () { var external = Boolean(options.external); app.listen(dataPort); bs.init({ proxy: 'localhost:' + dataPort, port: assetsPort, notify: false, ui: false, logLevel: 'info', logPrefix: 'Domo Dev', online: external, // TODO: add user's ignored files here too? files: ['**/*', '!node_modules/**/*'], }); bs.instance.logger.info('Instance: ' + client.getInstance()); }) .catch(function (e) { log_1.log.notAuthenticated; }); }); }); }; exports.start = start; //# sourceMappingURL=server.js.map