1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const cli_helper_1 = require("./cli-helper");
|
4 | const cli_1 = require("./cli");
|
5 | const fs = require("fs");
|
6 | const archiver = require("archiver");
|
7 | function createZipArchive(zipPath, callback) {
|
8 | let zipFile = fs.createWriteStream(zipPath);
|
9 | let archive = archiver("zip", {
|
10 | zlib: { level: 9 }
|
11 | });
|
12 | zipFile.on("close", function () {
|
13 | if (callback) {
|
14 | callback(null, zipPath);
|
15 | }
|
16 | else {
|
17 | cli_1.Cli.log("Flagpole Zip Archive created.");
|
18 | cli_1.Cli.list([
|
19 | "File Path: " + zipPath,
|
20 | "File Size: " + archive.pointer() + "bytes",
|
21 | "Contents: " + cli_1.Cli.configPath + " and " + cli_1.Cli.config.getTestsFolder()
|
22 | ]);
|
23 | cli_1.Cli.log("");
|
24 | cli_1.Cli.exit(0);
|
25 | }
|
26 | });
|
27 | archive.on("warning", function (err) {
|
28 | if (callback) {
|
29 | return callback(err);
|
30 | }
|
31 | if (err.code === "ENOENT") {
|
32 | }
|
33 | else {
|
34 | throw err;
|
35 | }
|
36 | });
|
37 | archive.on("error", function (err) {
|
38 | if (callback) {
|
39 | return callback(err);
|
40 | }
|
41 | throw err;
|
42 | });
|
43 | archive.pipe(zipFile);
|
44 | archive.append(fs.createReadStream(cli_1.Cli.configPath), {
|
45 | name: "flagpole.json"
|
46 | });
|
47 | archive.directory(cli_1.Cli.config.getTestsFolder(), cli_1.Cli.config.project.path);
|
48 | archive.finalize();
|
49 | }
|
50 | exports.createZipArchive = createZipArchive;
|
51 | function pack() {
|
52 | let testsFolder = cli_1.Cli.config.getTestsFolder();
|
53 | let configPath = cli_1.Cli.configPath;
|
54 | cli_1.Cli.hideBanner = true;
|
55 | cli_helper_1.printHeader();
|
56 | cli_helper_1.printSubheader("Pack Project to Zip Archive");
|
57 | if (!fs.existsSync(configPath)) {
|
58 | cli_1.Cli.log("Project config not found: " + configPath);
|
59 | cli_1.Cli.exit(1);
|
60 | }
|
61 | else if (!cli_1.Cli.config.isValid()) {
|
62 | cli_1.Cli.log("Project config is not valid: " + configPath);
|
63 | cli_1.Cli.exit(1);
|
64 | }
|
65 | else if (!fs.existsSync(testsFolder) ||
|
66 | !fs.lstatSync(testsFolder).isDirectory(testsFolder)) {
|
67 | cli_1.Cli.log("Tests folder does not exist: " + testsFolder);
|
68 | cli_1.Cli.exit(1);
|
69 | }
|
70 | else {
|
71 | createZipArchive(process.cwd() + "/flagpole.zip");
|
72 | }
|
73 | }
|
74 | exports.pack = pack;
|
75 |
|
\ | No newline at end of file |