1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const Generator_1 = __importDefault(require("./Generator"));
|
7 | const generators_1 = __importDefault(require("./generators"));
|
8 | const PREFERRED_UBUNTU_VERSION = '18.04';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | function versionCompare(versionOne, versionTwo) {
|
16 | if (versionOne === versionTwo) {
|
17 | return 0;
|
18 | }
|
19 | let splitV1 = versionOne.split('.');
|
20 | let splitV2 = versionTwo.split('.');
|
21 | while (splitV1.length < splitV2.length) {
|
22 | splitV1.push('0');
|
23 | }
|
24 | while (splitV2.length < splitV1.length) {
|
25 | splitV2.push('0');
|
26 | }
|
27 | for (let i = 0; i < splitV1.length; i) {
|
28 | let component1 = parseInt(splitV1[i], 10);
|
29 | let component2 = parseInt(splitV2[i], 10);
|
30 | if (component1 < component2) {
|
31 | return -1;
|
32 | }
|
33 | else if (component1 > component2) {
|
34 | return 1;
|
35 | }
|
36 | }
|
37 | return 0;
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | class DockerGenerator extends Generator_1.default {
|
45 | constructor(urlFetcher, environ, folder) {
|
46 | super(urlFetcher, folder);
|
47 | this.environ = environ;
|
48 |
|
49 |
|
50 |
|
51 | this.generators = [];
|
52 | for (let pkg of this.environ.softwareRequirements) {
|
53 | for (let GeneratorClass of generators_1.default) {
|
54 |
|
55 | const generator = new GeneratorClass(urlFetcher, pkg, folder);
|
56 | if (generator.applies()) {
|
57 | this.generators.push(generator);
|
58 | break;
|
59 | }
|
60 | }
|
61 | }
|
62 | }
|
63 | |
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | collect(func) {
|
71 |
|
72 | return this.generators.map(func).reduce((memo, items) => (memo.concat(items)), []);
|
73 | }
|
74 | |
75 |
|
76 |
|
77 |
|
78 |
|
79 | join(func, sep = ' \\\n && ') {
|
80 |
|
81 | return this.generators.map(func).filter(cmd => cmd).join(sep);
|
82 | }
|
83 |
|
84 | applies() {
|
85 | return true;
|
86 | }
|
87 | baseVersion() {
|
88 | return [PREFERRED_UBUNTU_VERSION].concat(this.generators.filter(generator => generator.baseName() === this.baseName())
|
89 | .map(generator => generator.baseVersion()))
|
90 | .sort(versionCompare)[0];
|
91 | }
|
92 | envVars(sysVersion) {
|
93 | return this.collect((generator) => generator.envVars(sysVersion));
|
94 | }
|
95 | aptKeysCommand(sysVersion) {
|
96 | return this.join((generator) => generator.aptKeysCommand(sysVersion));
|
97 | }
|
98 | aptRepos(sysVersion) {
|
99 | return this.collect((generator) => generator.aptRepos(sysVersion));
|
100 | }
|
101 | aptPackages(sysVersion) {
|
102 |
|
103 | const pkgs = this.collect((generator) => generator.aptPackages(sysVersion)).sort();
|
104 | return Array.from(new Set(pkgs));
|
105 | }
|
106 | stencilaInstall(sysVersion) {
|
107 | return this.join((generator) => generator.stencilaInstall(sysVersion));
|
108 | }
|
109 | installFiles(sysVersion) {
|
110 | return this.collect((generator) => generator.installFiles(sysVersion));
|
111 | }
|
112 | installCommand(sysVersion) {
|
113 | return this.join((generator) => generator.installCommand(sysVersion));
|
114 | }
|
115 | projectFiles(sysVersion) {
|
116 | return this.collect((generator) => generator.projectFiles(sysVersion));
|
117 | }
|
118 | runCommand(sysVersion) {
|
119 | return this.join((generator) => generator.runCommand(sysVersion));
|
120 | }
|
121 | }
|
122 | exports.default = DockerGenerator;
|