UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

96 lines 3.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const pack_1 = require("./pack"); const cli_helper_1 = require("./cli-helper"); const cli_1 = require("./cli"); const request = require('request'); const FormData = require('form-data'); const fs = require('fs'); const uploadPackage = function (token) { pack_1.createZipArchive(process.cwd() + '/flagpole.zip', function (err, fileName) { if (err) { cli_1.Cli.log(''); cli_1.Cli.log('Error: ' + err); cli_1.Cli.log(''); cli_1.Cli.exit(1); } if (!fs.existsSync(fileName)) { cli_1.Cli.log(''); cli_1.Cli.log('Error generating package.'); cli_1.Cli.log(''); cli_1.Cli.exit(1); } let uri = cli_1.Cli.apiDomain + '/api/project/' + cli_1.Cli.config.project.id + '/package'; request.post({ url: uri, formData: { token: token, file: fs.createReadStream(fileName) } }, function (err, response, body) { if (err) { cli_1.Cli.log(''); cli_1.Cli.log('Error Deploying: ' + err); cli_1.Cli.log(''); cli_1.Cli.exit(1); } if (response.statusCode == 202) { cli_1.Cli.log(''); cli_1.Cli.log('Project ' + cli_1.Cli.config.project.name + ' was posted to your account on FlagpoleJS.com'); cli_1.Cli.log(''); cli_1.Cli.exit(0); } else { cli_1.Cli.log(''); cli_1.Cli.log('Error Uploading Deploy (' + response.statusCode + ')'); cli_1.Cli.log(body); cli_1.Cli.log(''); cli_1.Cli.exit(1); } }); }); }; function uploadProject(token) { if (!cli_1.Cli.config.project.hasId()) { request.post(cli_1.Cli.apiDomain + '/api/project', { body: JSON.stringify({ token: token, name: cli_1.Cli.config.project.name }), headers: { 'Content-Type': 'application/json' } }, function (err, response, body) { let json = JSON.parse(body); cli_1.Cli.config.project.id = json.data.id || ''; cli_1.Cli.config.save().then(function () { uploadPackage(token); }).catch(function (err) { cli_1.Cli.log(''); cli_1.Cli.log('Error uploading project: ' + err); cli_1.Cli.log(''); cli_1.Cli.exit(1); }); }); } else { uploadPackage(token); } } function deploy() { cli_1.Cli.hideBanner = true; cli_helper_1.printHeader(); cli_helper_1.printSubheader('Deploy Project to FlagpoleJS.com'); cli_1.Cli.getCredentials().then(function (credentials) { uploadProject(credentials.token); }).catch(function (err) { cli_1.Cli.log(''); cli_1.Cli.log(err + ' Must be logged in to deploy.'); cli_1.Cli.log('Use command: flagpole login'); cli_1.Cli.log('Create an account at: http://www.flagpolejs.com'); cli_1.Cli.log(''); cli_1.Cli.exit(0); }); } exports.deploy = deploy; //# sourceMappingURL=deploy.js.map