Added support for v4

This commit is contained in:
Kasra Bigdeli 2020-08-09 07:54:27 -04:00
parent d2befaf8da
commit a4234efee3
3 changed files with 67 additions and 3 deletions

5
package-lock.json generated
View File

@ -411,6 +411,11 @@
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"yaml": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.0.tgz",
"integrity": "sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg=="
} }
} }
} }

View File

@ -22,6 +22,7 @@
"dependencies": { "dependencies": {
"fs-extra": "^9.0.1", "fs-extra": "^9.0.1",
"gh-pages": "^3.1.0", "gh-pages": "^3.1.0",
"prettier": "^2.0.5" "prettier": "^2.0.5",
"yaml": "^1.10.0"
} }
} }

View File

@ -1,5 +1,6 @@
/*jshint esversion: 6 */ /*jshint esversion: 6 */
const path = require('path'); const path = require('path');
const yaml = require('yaml');
const fs = require('fs-extra'); const fs = require('fs-extra');
const pathOfPublic = path.join(__dirname, '..', `public`); const pathOfPublic = path.join(__dirname, '..', `public`);
@ -8,6 +9,7 @@ const pathOfDist = path.join(__dirname, '..', `dist`);
// const pathOfDistV1 = path.join(pathOfDist, 'v1'); // const pathOfDistV1 = path.join(pathOfDist, 'v1');
const pathOfDistV2 = path.join(pathOfDist, 'v2'); const pathOfDistV2 = path.join(pathOfDist, 'v2');
const pathOfDistV3 = path.join(pathOfDist, 'v3'); const pathOfDistV3 = path.join(pathOfDist, 'v3');
const pathOfDistV4 = path.join(pathOfDist, 'v4');
const pathOfSourceDirectory = path.join(pathOfPublic, 'v2'); const pathOfSourceDirectory = path.join(pathOfPublic, 'v2');
const pathOfSourceDirectoryApps = path.join(pathOfSourceDirectory, 'apps'); const pathOfSourceDirectoryApps = path.join(pathOfSourceDirectory, 'apps');
@ -50,18 +52,73 @@ function createAppList(appsList, pathOfApps) {
}; };
} }
function convertV2toV4(v2String) {
const parsed = JSON.parse(v2String);
if (`${parsed.captainVersion}` !== '2') {
throw new Error('CaptainVersion must be 2 for this conversion');
}
function moveProperty(propertyName) {
parsed.caproverOneClickApp[propertyName] = parsed[propertyName];
parsed[propertyName] = undefined;
}
parsed.captainVersion = 4;
parsed.caproverOneClickApp = {};
parsed.services = parsed.dockerCompose.services;
parsed.dockerCompose = undefined;
moveProperty('variables');
moveProperty('instructions');
moveProperty('displayName');
moveProperty('description');
moveProperty('documentation');
Object.keys(parsed.services).forEach(serviceName => {
const service = parsed.services[serviceName];
if (service.containerHttpPort) {
service.caproverExtra = service.caproverExtra || {};
service.caproverExtra.containerHttpPort = service.containerHttpPort;
}
if (service.dockerfileLines) {
service.caproverExtra = service.caproverExtra || {};
service.caproverExtra.dockerfileLines = service.dockerfileLines;
}
if (service.notExposeAsWebApp) {
service.caproverExtra = service.caproverExtra || {};
service.caproverExtra.notExposeAsWebApp = service.notExposeAsWebApp;
}
service.containerHttpPort = undefined;
service.dockerfileLines = undefined;
service.notExposeAsWebApp = undefined;
});
return parsed;
}
function buildDist() { function buildDist() {
return fs.readdir(pathOfSourceDirectoryApps) return fs.readdir(pathOfSourceDirectoryApps)
.then(function (appsFileNames) { // [ app1.json app2.json .... ] .then(function (appsFileNames) { // [ app1.json app2.json .... ]
appsFileNames.forEach(appFileName => { appsFileNames.forEach(appFileName => {
fs.copySync(path.join(pathOfSourceDirectoryApps, appFileName), path.join(pathOfDistV2, `apps`, appFileName)); const pathOfAppFileInSource = path.join(pathOfSourceDirectoryApps, appFileName);
fs.copySync(path.join(pathOfSourceDirectoryApps, appFileName), path.join(pathOfDistV3, `apps`, appFileName.split('.')[0]));
//v2
fs.copySync(pathOfAppFileInSource, path.join(pathOfDistV2, `apps`, appFileName));
//v3
fs.copySync(pathOfAppFileInSource, path.join(pathOfDistV3, `apps`, appFileName.split('.')[0]));
//v4
const contentString = fs.readFileSync(pathOfAppFileInSource);
fs.outputJsonSync(path.join(pathOfDistV4, `apps`, appFileName.split('.')[0]), convertV2toV4(contentString));
}); });
fs.copySync(pathOfSourceDirectoryLogos, path.join(pathOfDistV2, `logos`)); fs.copySync(pathOfSourceDirectoryLogos, path.join(pathOfDistV2, `logos`));
fs.copySync(pathOfSourceDirectoryLogos, path.join(pathOfDistV3, `logos`)); fs.copySync(pathOfSourceDirectoryLogos, path.join(pathOfDistV3, `logos`));
fs.copySync(pathOfSourceDirectoryLogos, path.join(pathOfDistV4, `logos`));
const allAppsList = createAppList(appsFileNames, pathOfSourceDirectoryApps); const allAppsList = createAppList(appsFileNames, pathOfSourceDirectoryApps);
const v3List = { const v3List = {
@ -70,6 +127,7 @@ function buildDist() {
fs.outputJsonSync(path.join(pathOfDistV2, 'autoGeneratedList.json'), allAppsList); fs.outputJsonSync(path.join(pathOfDistV2, 'autoGeneratedList.json'), allAppsList);
fs.outputJsonSync(path.join(pathOfDistV2, 'list'), v3List); // TODO delete oneClickApps: fs.outputJsonSync(path.join(pathOfDistV2, 'list'), v3List); // TODO delete oneClickApps:
fs.outputJsonSync(path.join(pathOfDistV3, 'list'), v3List); fs.outputJsonSync(path.join(pathOfDistV3, 'list'), v3List);
fs.outputJsonSync(path.join(pathOfDistV4, 'list'), v3List);
}) })
.then(function () { .then(function () {
return fs.copySync(path.join(pathOfPublic, 'CNAME'), path.join(pathOfDist, 'CNAME')); return fs.copySync(path.join(pathOfPublic, 'CNAME'), path.join(pathOfDist, 'CNAME'));