1 | "use strict";
|
2 | var path = require("path");
|
3 | var utils = require("./utils");
|
4 | var logger_1 = require("./logger");
|
5 | var PackageDef = (function () {
|
6 | function PackageDef(user, app, variant) {
|
7 | this.user = user;
|
8 | this.app = app;
|
9 | this.variant = variant;
|
10 | }
|
11 | return PackageDef;
|
12 | }());
|
13 | var Package = (function () {
|
14 | function Package(basePath) {
|
15 | this.pagkaceDefName = "cloudstitch.json";
|
16 | if (basePath) {
|
17 | this.packageRootPath = path.resolve(process.cwd(), basePath);
|
18 | var loadedJson = utils.loadJson(path.join(this.packageRootPath, this.pagkaceDefName));
|
19 | if (loadedJson) {
|
20 | this.packageDef = new PackageDef(loadedJson["user"], loadedJson["app"], loadedJson["variant"]);
|
21 | }
|
22 | }
|
23 | else {
|
24 | var fileDetails = utils.readFromParent(process.cwd(), this.pagkaceDefName);
|
25 | if (fileDetails.fileJson) {
|
26 | this.packageDef = new PackageDef(fileDetails.fileJson["user"], fileDetails.fileJson["app"], fileDetails.fileJson["variant"]);
|
27 | }
|
28 | this.packageRootPath = fileDetails.basePath;
|
29 | }
|
30 | logger_1.instance.info("Read package information from " + this.packageRootPath + ":" + JSON.stringify(this.packageDef));
|
31 | }
|
32 | Package.prototype.isInvalid = function () {
|
33 | var result = {}, invalid = false;
|
34 | if (!this.packageDef) {
|
35 | invalid = true;
|
36 | result.notFound = true;
|
37 | }
|
38 | else if (this.packageDef && (typeof this.packageDef.user !== "string"
|
39 | || typeof this.packageDef.user !== "string"
|
40 | || typeof this.packageDef.variant !== "string")) {
|
41 | invalid = true;
|
42 | result.packageMalformed = true;
|
43 | }
|
44 | logger_1.instance.info("Package detected as invalid(" + invalid + ") at path: " + this.packageRootPath);
|
45 | if (!invalid) {
|
46 | return invalid;
|
47 | }
|
48 | else {
|
49 | return result;
|
50 | }
|
51 | };
|
52 | Package.prototype.get = function (key) {
|
53 | return this.packageDef ? this.packageDef[key] : undefined;
|
54 | };
|
55 | return Package;
|
56 | }());
|
57 | exports.Package = Package;
|
58 | exports.instance = new Package();
|