1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const pack_1 = require("./pack");
|
4 | const cli_helper_1 = require("./cli-helper");
|
5 | const cli_1 = require("./cli");
|
6 | const request = require("request");
|
7 | const FormData = require("form-data");
|
8 | const fs = require("fs");
|
9 | const uploadPackage = function (token) {
|
10 | pack_1.createZipArchive(process.cwd() + "/flagpole.zip", function (err, fileName) {
|
11 | if (err) {
|
12 | cli_1.Cli.log("");
|
13 | cli_1.Cli.log("Error: " + err);
|
14 | cli_1.Cli.log("");
|
15 | cli_1.Cli.exit(1);
|
16 | }
|
17 | if (!fs.existsSync(fileName)) {
|
18 | cli_1.Cli.log("");
|
19 | cli_1.Cli.log("Error generating package.");
|
20 | cli_1.Cli.log("");
|
21 | cli_1.Cli.exit(1);
|
22 | }
|
23 | let uri = cli_1.Cli.apiDomain + "/api/project/" + cli_1.Cli.config.project.id + "/package";
|
24 | request.post({
|
25 | url: uri,
|
26 | formData: {
|
27 | token: token,
|
28 | file: fs.createReadStream(fileName)
|
29 | }
|
30 | }, function (err, response, body) {
|
31 | if (err) {
|
32 | cli_1.Cli.log("");
|
33 | cli_1.Cli.log("Error Deploying: " + err);
|
34 | cli_1.Cli.log("");
|
35 | cli_1.Cli.exit(1);
|
36 | }
|
37 | if (response.statusCode == 202) {
|
38 | cli_1.Cli.log("");
|
39 | cli_1.Cli.log("Project " +
|
40 | cli_1.Cli.config.project.name +
|
41 | " was posted to your account on FlagpoleJS.com");
|
42 | cli_1.Cli.log("");
|
43 | cli_1.Cli.exit(0);
|
44 | }
|
45 | else {
|
46 | cli_1.Cli.log("");
|
47 | cli_1.Cli.log("Error Uploading Deploy (" + response.statusCode + ")");
|
48 | cli_1.Cli.log(body);
|
49 | cli_1.Cli.log("");
|
50 | cli_1.Cli.exit(1);
|
51 | }
|
52 | });
|
53 | });
|
54 | };
|
55 | function uploadProject(token) {
|
56 | if (!cli_1.Cli.config.project.hasId) {
|
57 | request.post(cli_1.Cli.apiDomain + "/api/project", {
|
58 | body: JSON.stringify({
|
59 | token: token,
|
60 | name: cli_1.Cli.config.project.name
|
61 | }),
|
62 | headers: {
|
63 | "Content-Type": "application/json"
|
64 | }
|
65 | }, function (err, response, body) {
|
66 | let json = JSON.parse(body);
|
67 | cli_1.Cli.config.project.id = json.data.id || "";
|
68 | cli_1.Cli.config
|
69 | .save()
|
70 | .then(function () {
|
71 | uploadPackage(token);
|
72 | })
|
73 | .catch(function (err) {
|
74 | cli_1.Cli.log("");
|
75 | cli_1.Cli.log("Error uploading project: " + err);
|
76 | cli_1.Cli.log("");
|
77 | cli_1.Cli.exit(1);
|
78 | });
|
79 | });
|
80 | }
|
81 | else {
|
82 | uploadPackage(token);
|
83 | }
|
84 | }
|
85 | function deploy() {
|
86 | cli_1.Cli.hideBanner = true;
|
87 | cli_helper_1.printHeader();
|
88 | cli_helper_1.printSubheader("Deploy Project to FlagpoleJS.com");
|
89 | cli_1.Cli.getCredentials()
|
90 | .then(function (credentials) {
|
91 | uploadProject(credentials.token);
|
92 | })
|
93 | .catch(function (err) {
|
94 | cli_1.Cli.log("");
|
95 | cli_1.Cli.log(err + " Must be logged in to deploy.");
|
96 | cli_1.Cli.log("Use command: flagpole login");
|
97 | cli_1.Cli.log("Create an account at: http://www.flagpolejs.com");
|
98 | cli_1.Cli.log("");
|
99 | cli_1.Cli.exit(0);
|
100 | });
|
101 | }
|
102 | exports.deploy = deploy;
|
103 |
|
\ | No newline at end of file |