appcenter-cli
Version:
Command line tool for Visual Studio App Center
110 lines (109 loc) • 4.8 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppiumPreparer = void 0;
const path = require("path");
const pfs = require("../../../util/misc/promisfied-fs");
class AppiumPreparer {
constructor(artifactsDir, buildDir) {
if (!artifactsDir) {
throw new Error("Argument --artifacts-dir is required");
}
if (!buildDir) {
throw new Error("Argument --build-dir is required");
}
this.artifactsDir = artifactsDir;
this.buildDir = buildDir;
}
prepare() {
return __awaiter(this, void 0, void 0, function* () {
yield this.validateBuildDir();
yield pfs.cpDir(this.buildDir, this.artifactsDir);
const manifestPath = path.join(this.artifactsDir, "manifest.json");
const manifest = yield this.createAppiumManifest();
const manifestJson = JSON.stringify(manifest, null, 1);
yield pfs.writeFile(manifestPath, manifestJson);
return manifestPath;
});
}
validateBuildDir() {
return __awaiter(this, void 0, void 0, function* () {
yield this.validateBuildDirExists();
yield this.validatePomFile();
yield this.validateDependencyJarsDirectory();
yield this.validateTestClassesDirectory();
});
}
validateBuildDirExists() {
return __awaiter(this, void 0, void 0, function* () {
yield this.validatePathExists(this.buildDir, false, `Appium build directory "${this.buildDir}" doesn't exist`);
});
}
validatePomFile() {
return this.validatePathExists(path.join(this.buildDir, "pom.xml"), true, `Appium build directory "${this.buildDir}" must contain file "pom.xml"`);
}
validateDependencyJarsDirectory() {
return this.validatePathExists(path.join(this.buildDir, "dependency-jars"), false, `Appium build directory "${this.buildDir}" must contain directory "dependency-jars"`);
}
validateTestClassesDirectory() {
return __awaiter(this, void 0, void 0, function* () {
const testClassesDir = path.join(this.buildDir, "test-classes");
yield this.validatePathExists(path.join(this.buildDir, "test-classes"), false, `Appium build directory "${this.buildDir}" must contain directory "test-classes"`);
if (!(yield this.hasClassFile(testClassesDir))) {
throw new Error(`The "test-classes" directory inside Appium build directory "${this.buildDir}" must contain at least one "*.class" file`);
}
});
}
hasClassFile(rootPath) {
return __awaiter(this, void 0, void 0, function* () {
const entries = yield pfs.readdir(rootPath);
for (const entry of entries) {
const fullEntryPath = path.join(rootPath, entry);
const stats = yield pfs.stat(fullEntryPath);
if (stats.isFile() && entry.endsWith(".class")) {
return true;
}
if (stats.isDirectory() && this.hasClassFile(fullEntryPath)) {
return true;
}
}
return false;
});
}
validatePathExists(path, isFile, errorMessage) {
return __awaiter(this, void 0, void 0, function* () {
let stats = null;
try {
stats = yield pfs.stat(path);
}
catch (err) {
throw new Error(errorMessage);
}
if (isFile !== stats.isFile()) {
throw new Error(errorMessage);
}
});
}
createAppiumManifest() {
return __awaiter(this, void 0, void 0, function* () {
const result = {
schemaVersion: "1.0.0",
files: ["pom.xml", "dependency-jars", "test-classes"],
testFramework: {
name: "appium",
data: {},
},
};
return result;
});
}
}
exports.AppiumPreparer = AppiumPreparer;