drapcode-utility 1.9.1 → 1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export * from "./utils/uuid-generator";
14
14
  export * from "./utils/check-error";
15
15
  export * from "./utils/prepare-query";
16
16
  export * from "./utils/s3-util";
17
+ export * from "./utils/project-util";
17
18
  export * from "./encryption/index";
18
19
  export * from "./encryption/utility";
19
20
  export * from "./format-fields/index";
package/build/index.js CHANGED
@@ -30,6 +30,7 @@ __exportStar(require("./utils/uuid-generator"), exports);
30
30
  __exportStar(require("./utils/check-error"), exports);
31
31
  __exportStar(require("./utils/prepare-query"), exports);
32
32
  __exportStar(require("./utils/s3-util"), exports);
33
+ __exportStar(require("./utils/project-util"), exports);
33
34
  __exportStar(require("./encryption/index"), exports);
34
35
  __exportStar(require("./encryption/utility"), exports);
35
36
  __exportStar(require("./format-fields/index"), exports);
@@ -0,0 +1,4 @@
1
+ export declare const saveProjectToFile: (project: any) => void;
2
+ export declare const findProjectFromFile: (query: any) => any;
3
+ export declare const updateProjectInFile: () => void;
4
+ export declare const removeProjectFromFile: (project: any) => void;
@@ -0,0 +1,169 @@
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
+ exports.removeProjectFromFile = exports.updateProjectInFile = exports.findProjectFromFile = exports.saveProjectToFile = void 0;
7
+ var fs_1 = require("fs");
8
+ var path_1 = __importDefault(require("path"));
9
+ var filePath = process.env.BUILD_FOLDER;
10
+ var saveProjectToFile = function (project) {
11
+ if (!project) {
12
+ return;
13
+ }
14
+ console.log("Check path", filePath);
15
+ checkFolder(filePath);
16
+ var projectPath = path_1.default.join(filePath, "projects");
17
+ console.log("Check path", projectPath);
18
+ checkFolder(projectPath);
19
+ var uuid = project.uuid, seoName = project.seoName, apiDomainName = project.apiDomainName, domainName = project.domainName;
20
+ console.log("Create UUID JSON file");
21
+ createFile(path_1.default.join(projectPath, "".concat(uuid, ".json")), project);
22
+ console.log("Create SeoName JSON file");
23
+ createFile(path_1.default.join(projectPath, "".concat(seoName, ".json")), project);
24
+ if (apiDomainName) {
25
+ console.log("Create API Domain JSON file");
26
+ createFile(path_1.default.join(projectPath, "".concat(apiDomainName, ".json")), project);
27
+ }
28
+ if (domainName) {
29
+ console.log("Create Domain JSON file");
30
+ createFile(path_1.default.join(projectPath, "".concat(domainName, ".json")), project);
31
+ }
32
+ };
33
+ exports.saveProjectToFile = saveProjectToFile;
34
+ var findProjectFromFile = function (query) {
35
+ var _a, _b;
36
+ console.log("query :>> ", query);
37
+ var isMainExists = verifyProjectsFolder();
38
+ if (!isMainExists) {
39
+ return null;
40
+ }
41
+ var projectPath = path_1.default.join(filePath, "projects");
42
+ console.log("projectPath :>> ", projectPath);
43
+ var or = query.or, apiDomainName = query.apiDomainName, seoName = query.seoName, domainName = query.domainName;
44
+ if (apiDomainName) {
45
+ //If api domain exists then please check with this no need of or
46
+ console.log("Checking for Project API Domain");
47
+ var project = readFile(path_1.default.join(projectPath, "".concat(apiDomainName, ".json")));
48
+ return project;
49
+ }
50
+ if (seoName) {
51
+ //IF api seo name exists then not need to check or
52
+ console.log("Checking for Project SEO Name");
53
+ var project = readFile(path_1.default.join(projectPath, "".concat(seoName, ".json")));
54
+ return project;
55
+ }
56
+ if (domainName) {
57
+ //IF api seo name exists then not need to check or
58
+ console.log("Checking for Project SEO Name");
59
+ var project = readFile(path_1.default.join(projectPath, "".concat(domainName, ".json")));
60
+ return project;
61
+ }
62
+ if (!or || or.length === 0) {
63
+ return null;
64
+ }
65
+ var pSeoName = (_a = extractDomainSeo(or, "seoName")) === null || _a === void 0 ? void 0 : _a["seoName"];
66
+ var pDomainName = (_b = extractDomainSeo(or, "domainName")) === null || _b === void 0 ? void 0 : _b["domainName"];
67
+ // Now check with pSeoName and domainName
68
+ console.log("pSeoName :>> ", pSeoName);
69
+ console.log("domainName :>> ", domainName);
70
+ if (pSeoName) {
71
+ //IF api seo name exists then not need to check or
72
+ console.log("Checking for Project SEO Name");
73
+ var project = readFile(path_1.default.join(projectPath, "".concat(pSeoName, ".json")));
74
+ return project;
75
+ }
76
+ if (pDomainName) {
77
+ //IF api seo name exists then not need to check or
78
+ console.log("Checking for Project Domain Name");
79
+ var project = readFile(path_1.default.join(projectPath, "".concat(pDomainName, ".json")));
80
+ return project;
81
+ }
82
+ return null;
83
+ };
84
+ exports.findProjectFromFile = findProjectFromFile;
85
+ var updateProjectInFile = function () { };
86
+ exports.updateProjectInFile = updateProjectInFile;
87
+ var removeProjectFromFile = function (project) {
88
+ //Check if projects folder exists in filePath or not
89
+ //Remove
90
+ if (!project) {
91
+ console.log("I do not have project");
92
+ return;
93
+ }
94
+ var isMainExists = verifyProjectsFolder();
95
+ console.log("Project Folder failed", isMainExists);
96
+ if (!isMainExists) {
97
+ return;
98
+ }
99
+ var projectPath = "".concat(filePath, "projects");
100
+ console.log("Check path", projectPath);
101
+ var uuid = project.uuid, seoName = project.seoName, apiDomainName = project.apiDomainName, domainName = project.domainName;
102
+ console.log("Removing UUID JSON");
103
+ removeFile(path_1.default.join(projectPath, "".concat(uuid, ".json")));
104
+ console.log("Removing Seo Name JSON");
105
+ removeFile(path_1.default.join(projectPath, "".concat(seoName, ".json")));
106
+ if (apiDomainName) {
107
+ console.log("Removing API Domain JSON");
108
+ removeFile(path_1.default.join(projectPath, "".concat(apiDomainName, ".json")));
109
+ }
110
+ if (domainName) {
111
+ console.log("Removing Domain JSON");
112
+ removeFile(path_1.default.join(projectPath, "".concat(domainName, ".json")));
113
+ }
114
+ };
115
+ exports.removeProjectFromFile = removeProjectFromFile;
116
+ var checkFolder = function (path) {
117
+ if (!path) {
118
+ return;
119
+ }
120
+ if (!(0, fs_1.existsSync)(path)) {
121
+ try {
122
+ (0, fs_1.mkdirSync)(path);
123
+ }
124
+ catch (error) {
125
+ console.error(error);
126
+ }
127
+ }
128
+ };
129
+ var verifyProjectsFolder = function () {
130
+ var projectPath = path_1.default.join(filePath, "projects");
131
+ return (0, fs_1.existsSync)(filePath) && (0, fs_1.existsSync)(projectPath);
132
+ };
133
+ var createFile = function (filePath, content) {
134
+ try {
135
+ (0, fs_1.writeFileSync)(filePath, JSON.stringify(content));
136
+ }
137
+ catch (error) {
138
+ console.log("error :>> ", error);
139
+ }
140
+ };
141
+ var removeFile = function (filePath) {
142
+ console.log("removeFile filePath :>> ", filePath);
143
+ try {
144
+ (0, fs_1.existsSync)(filePath) && (0, fs_1.unlinkSync)(filePath);
145
+ }
146
+ catch (error) {
147
+ console.log("error :>> ", error);
148
+ }
149
+ };
150
+ var readFile = function (filePath) {
151
+ try {
152
+ console.log("readFile filePath :>> ", filePath);
153
+ if (!(0, fs_1.existsSync)(filePath)) {
154
+ return null;
155
+ }
156
+ var content = (0, fs_1.readFileSync)(filePath, "utf8");
157
+ if (!content)
158
+ return null;
159
+ console.log("*******************************");
160
+ return JSON.parse(content);
161
+ }
162
+ catch (error) {
163
+ console.log("error :>> ", error);
164
+ return null;
165
+ }
166
+ };
167
+ function extractDomainSeo(or, key) {
168
+ return or.find(function (obj) { return Object.keys(obj)[0] === key; });
169
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",