@sasjs/utils 2.48.1 → 2.49.0

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.
@@ -0,0 +1 @@
1
+ export declare const generateCompileProgram: (folderPath: string) => Promise<string>;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __values = (this && this.__values) || function(o) {
39
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
+ if (m) return m.call(o);
41
+ if (o && typeof o.length === "number") return {
42
+ next: function () {
43
+ if (o && i >= o.length) o = void 0;
44
+ return { value: o && o[i++], done: !o };
45
+ }
46
+ };
47
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.generateCompileProgram = void 0;
54
+ var path_1 = __importDefault(require("path"));
55
+ var file_1 = require("../file");
56
+ var helper_1 = require("./internal/helper");
57
+ var generateCompileProgram = function (folderPath) { return __awaiter(void 0, void 0, void 0, function () {
58
+ var compiledMacrosCode, initialProgramContent, folderCreationCode;
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0: return [4 /*yield*/, (0, helper_1.getCompiledMacrosCode)(['mf_mkdir.sas'])];
62
+ case 1:
63
+ compiledMacrosCode = _a.sent();
64
+ initialProgramContent = (0, helper_1.getInitialCode)();
65
+ return [4 /*yield*/, fileAndDirectoryCreationCode(folderPath)];
66
+ case 2:
67
+ folderCreationCode = _a.sent();
68
+ return [2 /*return*/, compiledMacrosCode + initialProgramContent + folderCreationCode];
69
+ }
70
+ });
71
+ }); };
72
+ exports.generateCompileProgram = generateCompileProgram;
73
+ var fileAndDirectoryCreationCode = function (resourcePath, pathRelativeTo, resultCode) {
74
+ if (pathRelativeTo === void 0) { pathRelativeTo = resourcePath; }
75
+ if (resultCode === void 0) { resultCode = ''; }
76
+ return __awaiter(void 0, void 0, void 0, function () {
77
+ var _a, files, files_1, files_1_1, file, e_1_1, subFolders, subFolders_1, subFolders_1_1, folder, folderPath, e_2_1;
78
+ var e_1, _b, e_2, _c;
79
+ return __generator(this, function (_d) {
80
+ switch (_d.label) {
81
+ case 0: return [4 /*yield*/, (0, file_1.isFolder)(resourcePath)];
82
+ case 1:
83
+ if (!!(_d.sent())) return [3 /*break*/, 3];
84
+ _a = resultCode;
85
+ return [4 /*yield*/, (0, helper_1.generateCodeForFileCreation)(resourcePath, pathRelativeTo)];
86
+ case 2:
87
+ resultCode = _a + _d.sent();
88
+ return [2 /*return*/, resultCode];
89
+ case 3: return [4 /*yield*/, (0, file_1.listFilesInFolder)(resourcePath)];
90
+ case 4:
91
+ files = _d.sent();
92
+ _d.label = 5;
93
+ case 5:
94
+ _d.trys.push([5, 10, 11, 12]);
95
+ files_1 = __values(files), files_1_1 = files_1.next();
96
+ _d.label = 6;
97
+ case 6:
98
+ if (!!files_1_1.done) return [3 /*break*/, 9];
99
+ file = files_1_1.value;
100
+ return [4 /*yield*/, fileAndDirectoryCreationCode(path_1.default.join(resourcePath, file), pathRelativeTo, resultCode)];
101
+ case 7:
102
+ resultCode = _d.sent();
103
+ _d.label = 8;
104
+ case 8:
105
+ files_1_1 = files_1.next();
106
+ return [3 /*break*/, 6];
107
+ case 9: return [3 /*break*/, 12];
108
+ case 10:
109
+ e_1_1 = _d.sent();
110
+ e_1 = { error: e_1_1 };
111
+ return [3 /*break*/, 12];
112
+ case 11:
113
+ try {
114
+ if (files_1_1 && !files_1_1.done && (_b = files_1.return)) _b.call(files_1);
115
+ }
116
+ finally { if (e_1) throw e_1.error; }
117
+ return [7 /*endfinally*/];
118
+ case 12: return [4 /*yield*/, (0, file_1.listSubFoldersInFolder)(resourcePath)];
119
+ case 13:
120
+ subFolders = _d.sent();
121
+ _d.label = 14;
122
+ case 14:
123
+ _d.trys.push([14, 19, 20, 21]);
124
+ subFolders_1 = __values(subFolders), subFolders_1_1 = subFolders_1.next();
125
+ _d.label = 15;
126
+ case 15:
127
+ if (!!subFolders_1_1.done) return [3 /*break*/, 18];
128
+ folder = subFolders_1_1.value;
129
+ folderPath = path_1.default.join(resourcePath, folder);
130
+ resultCode = "".concat(resultCode, "\n%mf_mkdir(&fsTarget").concat(folderPath.replace(pathRelativeTo, ''), ")\n");
131
+ return [4 /*yield*/, fileAndDirectoryCreationCode(folderPath, pathRelativeTo, resultCode)];
132
+ case 16:
133
+ resultCode = _d.sent();
134
+ _d.label = 17;
135
+ case 17:
136
+ subFolders_1_1 = subFolders_1.next();
137
+ return [3 /*break*/, 15];
138
+ case 18: return [3 /*break*/, 21];
139
+ case 19:
140
+ e_2_1 = _d.sent();
141
+ e_2 = { error: e_2_1 };
142
+ return [3 /*break*/, 21];
143
+ case 20:
144
+ try {
145
+ if (subFolders_1_1 && !subFolders_1_1.done && (_c = subFolders_1.return)) _c.call(subFolders_1);
146
+ }
147
+ finally { if (e_2) throw e_2.error; }
148
+ return [7 /*endfinally*/];
149
+ case 21: return [2 /*return*/, resultCode];
150
+ }
151
+ });
152
+ });
153
+ };
154
+ //# sourceMappingURL=generateCompileProgram.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateCompileProgram.js","sourceRoot":"","sources":["../../src/fs/generateCompileProgram.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAuB;AACvB,gCAA6E;AAC7E,4CAI0B;AAEnB,IAAM,sBAAsB,GAAG,UAAO,UAAkB;;;;oBAClC,qBAAM,IAAA,8BAAqB,EAAC,CAAC,cAAc,CAAC,CAAC,EAAA;;gBAAlE,kBAAkB,GAAG,SAA6C;gBAElE,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C7C,UAAU,EACV,cAAc,EACd,UAAU,CACX,EAAA;;oBAJD,UAAU,GAAG,SAIZ,CAAA;;;;;;;;;;;;;;;;yBAGH,sBAAO,UAAU,EAAA;;;;CAClB,CAAA"}
package/fs/hash.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { HashedFolder } from '../types';
2
+ /**
3
+ * Hashes each file in each directory, and then hashes the hashes to create a hash for each directory also.
4
+ *
5
+ * Whilst files are hashed in their entirety, the logic for creating a folder hash is as follows:
6
+ *
7
+ * Sort the files and subfolders by name (case sensitive, uppercase then lower)
8
+ * Take the first 100 hashes, concatenate and hash
9
+ * Concatenate this hash with another 100 hashes and hash again
10
+ * Continue until the end of the folder. This is the folder hash
11
+ * If a folder contains other folders, start from the bottom of the tree - the folder hashes cascade upwards so you know immediately if there is a change in a sub/sub directory
12
+ * If the folder has no content (empty) then it is ignored. No hash created.
13
+ *
14
+ * @param {string} folderPath - absolute folder path
15
+ */
16
+ export declare const getHash: (folderPath: string) => Promise<HashedFolder>;
17
+ /**
18
+ * It returns a hashed folder tree that contains the local directory resources that are not synced with remote
19
+ */
20
+ export declare function compareHashes(localHash: HashedFolder, remoteHashMap: {
21
+ [key: string]: string;
22
+ }): HashedFolder;
package/fs/hash.js ADDED
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __values = (this && this.__values) || function(o) {
39
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
+ if (m) return m.call(o);
41
+ if (o && typeof o.length === "number") return {
42
+ next: function () {
43
+ if (o && i >= o.length) o = void 0;
44
+ return { value: o && o[i++], done: !o };
45
+ }
46
+ };
47
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.compareHashes = exports.getHash = void 0;
54
+ var fs_extra_1 = __importDefault(require("fs-extra"));
55
+ var path_1 = __importDefault(require("path"));
56
+ var crypto_1 = require("crypto");
57
+ var file_1 = require("../file");
58
+ /**
59
+ * Hashes each file in each directory, and then hashes the hashes to create a hash for each directory also.
60
+ *
61
+ * Whilst files are hashed in their entirety, the logic for creating a folder hash is as follows:
62
+ *
63
+ * Sort the files and subfolders by name (case sensitive, uppercase then lower)
64
+ * Take the first 100 hashes, concatenate and hash
65
+ * Concatenate this hash with another 100 hashes and hash again
66
+ * Continue until the end of the folder. This is the folder hash
67
+ * If a folder contains other folders, start from the bottom of the tree - the folder hashes cascade upwards so you know immediately if there is a change in a sub/sub directory
68
+ * If the folder has no content (empty) then it is ignored. No hash created.
69
+ *
70
+ * @param {string} folderPath - absolute folder path
71
+ */
72
+ var getHash = function (folderPath) { return __awaiter(void 0, void 0, void 0, function () {
73
+ return __generator(this, function (_a) {
74
+ switch (_a.label) {
75
+ case 0: return [4 /*yield*/, hashFolder(folderPath)];
76
+ case 1: return [2 /*return*/, _a.sent()];
77
+ }
78
+ });
79
+ }); };
80
+ exports.getHash = getHash;
81
+ /**
82
+ * It returns a hashed folder tree that contains the local directory resources that are not synced with remote
83
+ */
84
+ function compareHashes(localHash, remoteHashMap) {
85
+ return hashDifference(localHash, remoteHashMap);
86
+ }
87
+ exports.compareHashes = compareHashes;
88
+ var hashDifference = function (localHash, remoteHashMap, hashedDiff) {
89
+ var e_1, _a;
90
+ if (hashedDiff === void 0) { hashedDiff = {
91
+ hash: localHash.hash,
92
+ absolutePath: localHash.absolutePath,
93
+ relativePath: localHash.relativePath,
94
+ isFile: false,
95
+ members: []
96
+ }; }
97
+ try {
98
+ for (var _b = __values(localHash.members), _c = _b.next(); !_c.done; _c = _b.next()) {
99
+ var member = _c.value;
100
+ if (remoteHashMap[member.relativePath] !== member.hash) {
101
+ if (member.isFile) {
102
+ hashedDiff.members.push(member);
103
+ }
104
+ else {
105
+ var diff = hashDifference(member, remoteHashMap, {
106
+ hash: member.hash,
107
+ absolutePath: member.absolutePath,
108
+ relativePath: member.relativePath,
109
+ isFile: false,
110
+ members: []
111
+ });
112
+ hashedDiff.members.push(diff);
113
+ }
114
+ }
115
+ }
116
+ }
117
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
118
+ finally {
119
+ try {
120
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
121
+ }
122
+ finally { if (e_1) throw e_1.error; }
123
+ }
124
+ return hashedDiff;
125
+ };
126
+ var hashFile = function (filePath) { return __awaiter(void 0, void 0, void 0, function () {
127
+ var fileContent, hash;
128
+ return __generator(this, function (_a) {
129
+ fileContent = fs_extra_1.default.readFileSync(filePath);
130
+ if (fileContent.length) {
131
+ hash = (0, crypto_1.createHash)('md5');
132
+ hash.update(fileContent);
133
+ return [2 /*return*/, hash.digest('hex').toUpperCase()];
134
+ }
135
+ return [2 /*return*/];
136
+ });
137
+ }); };
138
+ var hashFolder = function (folderPath, pathRelativeTo, hashedFolder) {
139
+ if (pathRelativeTo === void 0) { pathRelativeTo = folderPath; }
140
+ if (hashedFolder === void 0) { hashedFolder = {
141
+ hash: '',
142
+ absolutePath: folderPath,
143
+ relativePath: (0, file_1.getRelativePath)(pathRelativeTo, folderPath),
144
+ isFile: false,
145
+ members: []
146
+ }; }
147
+ return __awaiter(void 0, void 0, void 0, function () {
148
+ var filesAndFolders, concatenatedHash, chunkSize, i, resources, resources_1, resources_1_1, resource, resourcePath, hashedSubFolder, hash, e_2_1, hash;
149
+ var e_2, _a;
150
+ return __generator(this, function (_b) {
151
+ switch (_b.label) {
152
+ case 0: return [4 /*yield*/, (0, file_1.listFilesAndSubFoldersInFolder)(folderPath, false)];
153
+ case 1:
154
+ filesAndFolders = _b.sent();
155
+ filesAndFolders.sort();
156
+ concatenatedHash = '';
157
+ chunkSize = 100;
158
+ i = 0;
159
+ _b.label = 2;
160
+ case 2:
161
+ if (!(i < filesAndFolders.length)) return [3 /*break*/, 15];
162
+ resources = filesAndFolders.slice(i, i + chunkSize);
163
+ _b.label = 3;
164
+ case 3:
165
+ _b.trys.push([3, 11, 12, 13]);
166
+ resources_1 = (e_2 = void 0, __values(resources)), resources_1_1 = resources_1.next();
167
+ _b.label = 4;
168
+ case 4:
169
+ if (!!resources_1_1.done) return [3 /*break*/, 10];
170
+ resource = resources_1_1.value;
171
+ resourcePath = path_1.default.join(folderPath, resource);
172
+ return [4 /*yield*/, (0, file_1.isFolder)(resourcePath)];
173
+ case 5:
174
+ if (!_b.sent()) return [3 /*break*/, 7];
175
+ return [4 /*yield*/, hashFolder(resourcePath, pathRelativeTo)];
176
+ case 6:
177
+ hashedSubFolder = _b.sent();
178
+ hashedFolder.members.push(hashedSubFolder);
179
+ concatenatedHash += hashedSubFolder.hash;
180
+ return [3 /*break*/, 9];
181
+ case 7: return [4 /*yield*/, hashFile(resourcePath)];
182
+ case 8:
183
+ hash = _b.sent();
184
+ if (!hash)
185
+ return [3 /*break*/, 9];
186
+ hashedFolder.members.push({
187
+ hash: hash,
188
+ absolutePath: resourcePath,
189
+ relativePath: (0, file_1.getRelativePath)(pathRelativeTo, resourcePath),
190
+ isFile: true
191
+ });
192
+ concatenatedHash += hash;
193
+ _b.label = 9;
194
+ case 9:
195
+ resources_1_1 = resources_1.next();
196
+ return [3 /*break*/, 4];
197
+ case 10: return [3 /*break*/, 13];
198
+ case 11:
199
+ e_2_1 = _b.sent();
200
+ e_2 = { error: e_2_1 };
201
+ return [3 /*break*/, 13];
202
+ case 12:
203
+ try {
204
+ if (resources_1_1 && !resources_1_1.done && (_a = resources_1.return)) _a.call(resources_1);
205
+ }
206
+ finally { if (e_2) throw e_2.error; }
207
+ return [7 /*endfinally*/];
208
+ case 13:
209
+ if (concatenatedHash !== '') {
210
+ hash = (0, crypto_1.createHash)('md5');
211
+ hash.update(concatenatedHash);
212
+ concatenatedHash = hash.digest('hex').toUpperCase();
213
+ }
214
+ _b.label = 14;
215
+ case 14:
216
+ i += chunkSize;
217
+ return [3 /*break*/, 2];
218
+ case 15:
219
+ hashedFolder.hash = concatenatedHash;
220
+ return [2 /*return*/, hashedFolder];
221
+ }
222
+ });
223
+ });
224
+ };
225
+ //# sourceMappingURL=hash.js.map
package/fs/hash.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/fs/hash.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAyB;AACzB,8CAAuB;AACvB,iCAAmC;AAEnC,gCAIgB;AAChB;;;;;;;;;;;;;GAaG;AAEI,IAAM,OAAO,GAAG,UAAO,UAAkB;;;oBACvC,qBAAM,UAAU,CAAC,UAAU,CAAC,EAAA;oBAAnC,sBAAO,SAA4B,EAAA;;;KACpC,CAAA;AAFY,QAAA,OAAO,WAEnB;AAED;;GAEG;AACH,SAAgB,aAAa,CAC3B,SAAuB,EACvB,aAAwC;IAExC,OAAO,cAAc,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;AACjD,CAAC;AALD,sCAKC;AAED,IAAM,cAAc,GAAG,UACrB,SAAuB,EACvB,aAAwC,EACxC,UAMC;;IAND,2BAAA,EAAA;QACE,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,YAAY,EAAE,SAAS,CAAC,YAAY;QACpC,YAAY,EAAE,SAAS,CAAC,YAAY;QACpC,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,EAAE;KACZ;;QAED,KAAqB,IAAA,KAAA,SAAA,SAAS,CAAC,OAAO,CAAA,gBAAA,4BAAE;YAAnC,IAAM,MAAM,WAAA;YACf,IAAI,aAAa,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,MAAM,CAAC,IAAI,EAAE;gBACtD,IAAI,MAAM,CAAC,MAAM,EAAE;oBACjB,UAAU,CA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1D,YAAY,CAAC,IAAI,GAAG,gBAAgB,CAAA;oBAEpC,sBAAO,YAAY,EAAA;;;;CACpB,CAAA"}
package/fs/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { getHash, compareHashes } from './hash';
2
+ export { generateCompileProgram } from './generateCompileProgram';
3
+ export { generateProgramToGetRemoteHash, generateProgramToSyncHashDiff, findResourcesNotPresentLocally } from './sync';
package/fs/index.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findResourcesNotPresentLocally = exports.generateProgramToSyncHashDiff = exports.generateProgramToGetRemoteHash = exports.generateCompileProgram = exports.compareHashes = exports.getHash = void 0;
4
+ var hash_1 = require("./hash");
5
+ Object.defineProperty(exports, "getHash", { enumerable: true, get: function () { return hash_1.getHash; } });
6
+ Object.defineProperty(exports, "compareHashes", { enumerable: true, get: function () { return hash_1.compareHashes; } });
7
+ var generateCompileProgram_1 = require("./generateCompileProgram");
8
+ Object.defineProperty(exports, "generateCompileProgram", { enumerable: true, get: function () { return generateCompileProgram_1.generateCompileProgram; } });
9
+ var sync_1 = require("./sync");
10
+ Object.defineProperty(exports, "generateProgramToGetRemoteHash", { enumerable: true, get: function () { return sync_1.generateProgramToGetRemoteHash; } });
11
+ Object.defineProperty(exports, "generateProgramToSyncHashDiff", { enumerable: true, get: function () { return sync_1.generateProgramToSyncHashDiff; } });
12
+ Object.defineProperty(exports, "findResourcesNotPresentLocally", { enumerable: true, get: function () { return sync_1.findResourcesNotPresentLocally; } });
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fs/index.ts"],"names":[],"mappings":";;;AAAA,+BAA+C;AAAtC,+FAAA,OAAO,OAAA;AAAE,qGAAA,aAAa,OAAA;AAC/B,mEAAiE;AAAxD,gIAAA,sBAAsB,OAAA;AAC/B,+BAIe;AAHb,sHAAA,8BAA8B,OAAA;AAC9B,qHAAA,6BAA6B,OAAA;AAC7B,sHAAA,8BAA8B,OAAA"}
@@ -0,0 +1,4 @@
1
+ export declare const generateCodeForFileCreation: (filePath: string, pathRelativeTo: string) => Promise<string>;
2
+ export declare const chunkFileContent: (fileContent: string) => string;
3
+ export declare const getInitialCode: () => string;
4
+ export declare const getCompiledMacrosCode: (macros: string[]) => Promise<string>;
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __values = (this && this.__values) || function(o) {
39
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
+ if (m) return m.call(o);
41
+ if (o && typeof o.length === "number") return {
42
+ next: function () {
43
+ if (o && i >= o.length) o = void 0;
44
+ return { value: o && o[i++], done: !o };
45
+ }
46
+ };
47
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.getCompiledMacrosCode = exports.getInitialCode = exports.chunkFileContent = exports.generateCodeForFileCreation = void 0;
54
+ var path_1 = __importDefault(require("path"));
55
+ var getNodeModulePath_1 = require("../../utils/getNodeModulePath");
56
+ var chunk_1 = require("../../utils/chunk");
57
+ var file_1 = require("../../file");
58
+ var generateCodeForFileCreation = function (filePath, pathRelativeTo) { return __awaiter(void 0, void 0, void 0, function () {
59
+ var base64EncodedFileContent, chunkedFileContent;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0: return [4 /*yield*/, (0, file_1.base64EncodeFile)(filePath)];
63
+ case 1:
64
+ base64EncodedFileContent = _a.sent();
65
+ chunkedFileContent = (0, exports.chunkFileContent)(base64EncodedFileContent);
66
+ return [2 /*return*/, "\nfilename _in64 temp lrecl=99999999;\ndata _null_;\nfile _in64;\n".concat(chunkedFileContent, "\nrun;\n\nfilename _out64 \"&fsTarget").concat(filePath.replace(pathRelativeTo, ''), "\";\n\n/* convert from base64 */\ndata _null_;\nlength filein 8 fileout 8;\nfilein = fopen(\"_in64\",'I',4,'B');\nfileout = fopen(\"_out64\",'O',3,'B');\nchar= '20'x;\ndo while(fread(filein)=0);\n length raw $4 ;\n do i=1 to 4;\n rc=fget(filein,char,1);\n substr(raw,i,1)=char;\n end;\n rc = fput(fileout, input(raw,$base64X4.));\n rc =fwrite(fileout);\nend;\nrc = fclose(filein);\nrc = fclose(fileout);\nrun;\n\nfilename _in64 clear;\nfilename _out64 clear;\n")];
67
+ }
68
+ });
69
+ }); };
70
+ exports.generateCodeForFileCreation = generateCodeForFileCreation;
71
+ var chunkFileContent = function (fileContent) {
72
+ var chunkedLines = (0, chunk_1.chunk)(fileContent);
73
+ if (chunkedLines.length === 1) {
74
+ return " put '".concat(chunkedLines[0].split("'").join("''"), "';\n");
75
+ }
76
+ var combinedLines = '';
77
+ chunkedLines.forEach(function (chunkedLine, index) {
78
+ var text = " put '".concat(chunkedLine.split("'").join("''"), "'").concat(index !== chunkedLines.length - 1 ? '@;\n' : ';\n');
79
+ combinedLines += text;
80
+ });
81
+ return combinedLines;
82
+ };
83
+ exports.chunkFileContent = chunkFileContent;
84
+ var getInitialCode = function () { return "%global fsTarget;\n%let compiled_fsTarget=%sysfunc(pathname(work));\n%let fsTarget=%sysfunc(coalescec(&fsTarget,&compiled_fsTarget));\noptions nobomfile;\n\n%mf_mkdir(&fsTarget)\n"; };
85
+ exports.getInitialCode = getInitialCode;
86
+ var getCompiledMacrosCode = function (macros) { return __awaiter(void 0, void 0, void 0, function () {
87
+ var sasjsCorePath, compiledCode, macros_1, macros_1_1, macro, macroPath, macroContent, e_1_1;
88
+ var e_1, _a;
89
+ return __generator(this, function (_b) {
90
+ switch (_b.label) {
91
+ case 0: return [4 /*yield*/, (0, getNodeModulePath_1.getNodeModulePath)('@sasjs/core')];
92
+ case 1:
93
+ sasjsCorePath = _b.sent();
94
+ if (!sasjsCorePath)
95
+ throw new Error('@sasjs/core could not be found');
96
+ compiledCode = '';
97
+ _b.label = 2;
98
+ case 2:
99
+ _b.trys.push([2, 7, 8, 9]);
100
+ macros_1 = __values(macros), macros_1_1 = macros_1.next();
101
+ _b.label = 3;
102
+ case 3:
103
+ if (!!macros_1_1.done) return [3 /*break*/, 6];
104
+ macro = macros_1_1.value;
105
+ macroPath = path_1.default.join(sasjsCorePath, 'base', macro);
106
+ return [4 /*yield*/, (0, file_1.readFile)(macroPath)];
107
+ case 4:
108
+ macroContent = _b.sent();
109
+ compiledCode += macroContent + '\n';
110
+ _b.label = 5;
111
+ case 5:
112
+ macros_1_1 = macros_1.next();
113
+ return [3 /*break*/, 3];
114
+ case 6: return [3 /*break*/, 9];
115
+ case 7:
116
+ e_1_1 = _b.sent();
117
+ e_1 = { error: e_1_1 };
118
+ return [3 /*break*/, 9];
119
+ case 8:
120
+ try {
121
+ if (macros_1_1 && !macros_1_1.done && (_a = macros_1.return)) _a.call(macros_1);
122
+ }
123
+ finally { if (e_1) throw e_1.error; }
124
+ return [7 /*endfinally*/];
125
+ case 9: return [2 /*return*/, compiledCode];
126
+ }
127
+ });
128
+ }); };
129
+ exports.getCompiledMacrosCode = getCompiledMacrosCode;
130
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/fs/internal/helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAuB;AACvB,mEAAiE;AACjE,2CAAyC;AACzC,mCAAuD;AAEhD,IAAM,2BAA2B,GAAG,UACzC,QAAgB,EAChB,cAAsB;;;;oBAEW,qBAAM,IAAA,uBAAgB,EAAC,QAAQ,CAAC,EAAA;;gBAA3D,wBAAwB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AG,EAAE,CAAA;;;;gBAED,WAAA,SAAA,MAAM,CAAA;;;;gBAAf,KAAK;gBACR,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;gBACpC,qBAAM,IAAA,eAAQ,EAAC,SAAS,CAAC,EAAA;;gBAAxC,YAAY,GAAG,SAAyB;gBAE9C,YAAY,IAAI,YAAY,GAAG,IAAI,CAAA;;;;;;;;;;;;;;;;oBAGrC,sBAAO,YAAY,EAAA;;;KACpB,CAAA;AAdY,QAAA,qBAAqB,yBAcjC"}
package/fs/sync.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { HashedFolder } from '../types';
2
+ export declare const generateProgramToGetRemoteHash: (remotePath: string) => Promise<string>;
3
+ export declare const generateProgramToSyncHashDiff: (hashedFolder: HashedFolder, remotePath: string) => Promise<string>;
4
+ export declare const findResourcesNotPresentLocally: (localHash: HashedFolder, remoteHashMap: {
5
+ [key: string]: string;
6
+ }) => string[];
package/fs/sync.js ADDED
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __values = (this && this.__values) || function(o) {
39
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
+ if (m) return m.call(o);
41
+ if (o && typeof o.length === "number") return {
42
+ next: function () {
43
+ if (o && i >= o.length) o = void 0;
44
+ return { value: o && o[i++], done: !o };
45
+ }
46
+ };
47
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
+ };
49
+ var __read = (this && this.__read) || function (o, n) {
50
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
51
+ if (!m) return o;
52
+ var i = m.call(o), r, ar = [], e;
53
+ try {
54
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
+ }
56
+ catch (error) { e = { error: error }; }
57
+ finally {
58
+ try {
59
+ if (r && !r.done && (m = i["return"])) m.call(i);
60
+ }
61
+ finally { if (e) throw e.error; }
62
+ }
63
+ return ar;
64
+ };
65
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
66
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
67
+ if (ar || !(i in from)) {
68
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
69
+ ar[i] = from[i];
70
+ }
71
+ }
72
+ return to.concat(ar || Array.prototype.slice.call(from));
73
+ };
74
+ var __importDefault = (this && this.__importDefault) || function (mod) {
75
+ return (mod && mod.__esModule) ? mod : { "default": mod };
76
+ };
77
+ Object.defineProperty(exports, "__esModule", { value: true });
78
+ exports.findResourcesNotPresentLocally = exports.generateProgramToSyncHashDiff = exports.generateProgramToGetRemoteHash = void 0;
79
+ var path_1 = __importDefault(require("path"));
80
+ var helper_1 = require("./internal/helper");
81
+ var generateProgramToGetRemoteHash = function (remotePath) { return __awaiter(void 0, void 0, void 0, function () {
82
+ var compiledMacrosCode, codeForHashCreation, code;
83
+ return __generator(this, function (_a) {
84
+ switch (_a.label) {
85
+ case 0: return [4 /*yield*/, (0, helper_1.getCompiledMacrosCode)([
86
+ 'mp_hashdirectory.sas',
87
+ 'mp_jsonout.sas'
88
+ ])];
89
+ case 1:
90
+ compiledMacrosCode = _a.sent();
91
+ codeForHashCreation = getCodeForHashCreation();
92
+ code = compiledMacrosCode + codeForHashCreation;
93
+ return [2 /*return*/, setTargetAtStart(code, remotePath)];
94
+ }
95
+ });
96
+ }); };
97
+ exports.generateProgramToGetRemoteHash = generateProgramToGetRemoteHash;
98
+ var generateProgramToSyncHashDiff = function (hashedFolder, remotePath) { return __awaiter(void 0, void 0, void 0, function () {
99
+ var compiledMacrosCode, initialProgramContent, pathRelativeTo, folderCreationCode, codeForHashCreation, code;
100
+ return __generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0: return [4 /*yield*/, (0, helper_1.getCompiledMacrosCode)([
103
+ 'mp_hashdirectory.sas',
104
+ 'mp_jsonout.sas',
105
+ 'mf_mkdir.sas'
106
+ ])];
107
+ case 1:
108
+ compiledMacrosCode = _a.sent();
109
+ initialProgramContent = (0, helper_1.getInitialCode)();
110
+ pathRelativeTo = hashedFolder.absolutePath.endsWith(path_1.default.sep)
111
+ ? hashedFolder.absolutePath.slice(0, -1)
112
+ : hashedFolder.absolutePath;
113
+ return [4 /*yield*/, generateCodeForFolderCreation(hashedFolder, pathRelativeTo)];
114
+ case 2:
115
+ folderCreationCode = _a.sent();
116
+ codeForHashCreation = getCodeForHashCreation();
117
+ code = compiledMacrosCode +
118
+ initialProgramContent +
119
+ folderCreationCode +
120
+ codeForHashCreation;
121
+ return [2 /*return*/, setTargetAtStart(code, remotePath)];
122
+ }
123
+ });
124
+ }); };
125
+ exports.generateProgramToSyncHashDiff = generateProgramToSyncHashDiff;
126
+ var findResourcesNotPresentLocally = function (localHash, remoteHashMap) {
127
+ var localHashedArray = convertHashFolderTreeToArray(localHash);
128
+ var remoteHashedArray = Object.keys(remoteHashMap);
129
+ return remoteHashedArray.filter(function (item) { return !localHashedArray.includes(item); });
130
+ };
131
+ exports.findResourcesNotPresentLocally = findResourcesNotPresentLocally;
132
+ var generateCodeForFolderCreation = function (hashedFolder, pathRelativeTo, resultCode) {
133
+ if (resultCode === void 0) { resultCode = ''; }
134
+ return __awaiter(void 0, void 0, void 0, function () {
135
+ var _a, _b, member, _c, e_1_1;
136
+ var e_1, _d;
137
+ return __generator(this, function (_e) {
138
+ switch (_e.label) {
139
+ case 0:
140
+ _e.trys.push([0, 7, 8, 9]);
141
+ _a = __values(hashedFolder.members), _b = _a.next();
142
+ _e.label = 1;
143
+ case 1:
144
+ if (!!_b.done) return [3 /*break*/, 6];
145
+ member = _b.value;
146
+ if (!member.isFile) return [3 /*break*/, 3];
147
+ _c = resultCode;
148
+ return [4 /*yield*/, (0, helper_1.generateCodeForFileCreation)(member.absolutePath, pathRelativeTo)];
149
+ case 2:
150
+ resultCode = _c + _e.sent();
151
+ return [3 /*break*/, 5];
152
+ case 3:
153
+ resultCode += "%mf_mkdir(&fsTarget".concat(member.absolutePath.replace(pathRelativeTo, ''), ")\n");
154
+ return [4 /*yield*/, generateCodeForFolderCreation(member, pathRelativeTo, resultCode)];
155
+ case 4:
156
+ resultCode = _e.sent();
157
+ _e.label = 5;
158
+ case 5:
159
+ _b = _a.next();
160
+ return [3 /*break*/, 1];
161
+ case 6: return [3 /*break*/, 9];
162
+ case 7:
163
+ e_1_1 = _e.sent();
164
+ e_1 = { error: e_1_1 };
165
+ return [3 /*break*/, 9];
166
+ case 8:
167
+ try {
168
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
169
+ }
170
+ finally { if (e_1) throw e_1.error; }
171
+ return [7 /*endfinally*/];
172
+ case 9: return [2 /*return*/, resultCode];
173
+ }
174
+ });
175
+ });
176
+ };
177
+ var getCodeForHashCreation = function () {
178
+ return "/* Get Hashes */\n%mp_hashdirectory(&fsTarget,maxDepth=MAX,outds=work.hashes)\n\n/* Prepare Response JSON */\nfilename tmp temp;\n%mp_jsonout(OPEN,jref=tmp)\n%mp_jsonout(OBJ,hashes,fmt=N,jref=tmp)\n%mp_jsonout(CLOSE,jref=tmp)\n\n/* Print to Log */\ndata _null_;\n retain eof;\n infile tmp end=eof lrecl=10000;\n if _n_=1 then putlog '>>weboutBEGIN<<';\n input;\n putlog _infile_;\n if eof then putlog '>>weboutEND<<';\nrun;\n";
179
+ };
180
+ var setTargetAtStart = function (code, target) {
181
+ return "%let fsTarget=".concat(target, ";\n").concat(code);
182
+ };
183
+ /**
184
+ * convert hash folder tree to an array of relative paths,
185
+ * the returned array will be used to check the resources that are present on remote but not local
186
+ */
187
+ var convertHashFolderTreeToArray = function (hashedFolder, array) {
188
+ var e_2, _a;
189
+ if (array === void 0) { array = []; }
190
+ if (hashedFolder.isFile)
191
+ return __spreadArray(__spreadArray([], __read(array), false), [hashedFolder.relativePath], false);
192
+ try {
193
+ for (var _b = __values(hashedFolder.members), _c = _b.next(); !_c.done; _c = _b.next()) {
194
+ var member = _c.value;
195
+ array = convertHashFolderTreeToArray(member, array);
196
+ }
197
+ }
198
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
199
+ finally {
200
+ try {
201
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
202
+ }
203
+ finally { if (e_2) throw e_2.error; }
204
+ }
205
+ array.push(hashedFolder.relativePath);
206
+ return array;
207
+ };
208
+ //# sourceMappingURL=sync.js.map
package/fs/sync.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/fs/sync.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAuB;AACvB,4CAI0B;AAGnB,IAAM,8BAA8B,GAAG,UAAO,UAAkB;;;;oBAC1C,qBAAM,IAAA,8BAAqB,EAAC;oBACrD,sBAAsB;oBACtB,gBAAgB;iBACjB,CAAC,EAAA;;gBAHI,kBAAkB,GAAG,SAGzB;gBAEI,mBAAmB,GAAG,sBAAsB,EAAE,CAAA;gBAE9C,IAAI,GAAG,kBAAkB,GAAG,mBAAmB,CAAA;gBAErD,sBAAO,gBAAgB,CAAC,IAAI,EAAE,UAAU,CAAC,EAAA;;;KAC1C,CAAA;AAXY,QAAA,8BAA8B,kCAW1C;AAEM,IAAM,6BAA6B,GAAG,UAC3C,YAA0B,EAC1B,UAAkB;;;;oBAES,qBAAM,IAAA,8BAAqB,EAAC;oBACrD,sBAAsB;oBACtB,gBAAgB;oBAChB,cAAc;iBACf,CAAC,EAAA;;gBAJI,kBAAkB,GAAG,SAIzB;gBAEI,qBAAqB,GAAG,IAAA,uBAAc,GAAE,CAAA;gBAExC,cAAc,GAAG,YAAY,CAAC,YAAY,CAAC,QAAQ,CAAC,c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O,CAC7D,cAAc,EACd,EAAE,CACH,QAAK,CAAA;oBACO,qBAAM,6BAA6B,CAC9C,MAAsB,EACtB,cAAc,EACd,UAAU,CACX,EAAA;;oBAJD,UAAU,GAAG,SAIZ,CAAA;;;;;;;;;;;;;;;;wBAIL,sBAAO,UAAU,EAAA;;;;CAClB,CAAA;AAED,IAAM,sBAAsB,GAAG;IAC7B,OAAO,ibAkBR,CAAA;AACD,CAAC,CAAA;AAED,IAAM,gBAAgB,GAAG,UAAC,IAAY,EAAE,MAAc;IACpD,OAAO,wBAAiB,MAAM,gBAAM,IAAI,CAAE,CAAA;AAC5C,CAAC,CAAA;AAED;;;GAGG;AAEH,IAAM,4BAA4B,GAAG,UACnC,YAA0B,EAC1B,KAAoB;;IAApB,sBAAA,EAAA,UAAoB;IAEpB,IAAI,YAAY,CAAC,MAAM;QAAE,8CAAW,KAAK,YAAE,YAAY,CAAC,YAAY,UAAC;;QAErE,KAAqB,IAAA,KAAA,SAAA,YAAY,CAAC,OAAO,CAAA,gBAAA,4BAAE;YAAtC,IAAM,MAAM,WAAA;YACf,KAAK,GAAG,4BAA4B,CAAC,MAAsB,EAAE,KAAK,CAAC,CAAA;SACpE;;;;;;;;;IAED,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAA;IAErC,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
package/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from './time';
8
8
  export * from './types';
9
9
  export * from './utils';
10
10
  export * from './compileTree';
11
+ export * from './fs';
package/index.js CHANGED
@@ -20,4 +20,5 @@ __exportStar(require("./time"), exports);
20
20
  __exportStar(require("./types"), exports);
21
21
  __exportStar(require("./utils"), exports);
22
22
  __exportStar(require("./compileTree"), exports);
23
+ __exportStar(require("./fs"), exports);
23
24
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAsB;AACtB,yCAAsB;AACtB,8CAA2B;AAC3B,0CAAuB;AACvB,2CAAwB;AACxB,6CAA0B;AAC1B,yCAAsB;AACtB,0CAAuB;AACvB,0CAAuB;AACvB,gDAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAsB;AACtB,yCAAsB;AACtB,8CAA2B;AAC3B,0CAAuB;AACvB,2CAAwB;AACxB,6CAA0B;AAC1B,yCAAsB;AACtB,0CAAuB;AACvB,0CAAuB;AACvB,gDAA6B;AAC7B,uCAAoB"}
package/package.json CHANGED
@@ -11,12 +11,13 @@
11
11
  },
12
12
  "typings": "./index.d.ts",
13
13
  "scripts": {
14
- "preinstall": "node checkNodeVersion",
15
- "prebuild": "node checkNodeVersion",
14
+ "nodeVersionMessage": "echo \u001b[33m make sure you are running node lts version \u001b[0m",
15
+ "preinstall": "npm run nodeVersionMessage",
16
+ "prebuild": "npm run nodeVersionMessage",
16
17
  "build": "rimraf build && tsc",
17
18
  "prepublishOnly": "cp -r ./build/* . && rm -rf ./build && rm -rf ./src && rm jest.config.js && rm tsconfig.json",
18
19
  "postpublish": "git clean -fd",
19
- "package:lib": "npm run build && cp ./package.json ./checkNodeVersion.js build && cp README.md build && cd build && npm version \"5.0.0\" && npm pack",
20
+ "package:lib": "npm run build && cp ./package.json build && cp README.md build && cd build && npm version \"5.0.0\" && npm pack",
20
21
  "test": "jest --config=jest.config.js --coverage",
21
22
  "lint:fix": "npx prettier --write \"{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
22
23
  "lint": "npx prettier --check \"{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
@@ -33,7 +34,7 @@
33
34
  },
34
35
  "homepage": "https://github.com/sasjs/utils#readme",
35
36
  "devDependencies": {
36
- "@sasjs/core": "3.10.0",
37
+ "@sasjs/core": "4.41.0",
37
38
  "@types/cli-table": "0.3.0",
38
39
  "@types/find": "0.2.1",
39
40
  "@types/jest": "27.4.0",
@@ -60,5 +61,5 @@
60
61
  "rimraf": "3.0.2",
61
62
  "valid-url": "1.0.9"
62
63
  },
63
- "version": "2.48.1"
64
+ "version": "2.49.0"
64
65
  }
@@ -0,0 +1,9 @@
1
+ export interface HashedFile {
2
+ hash: string;
3
+ absolutePath: string;
4
+ relativePath: string;
5
+ isFile: boolean;
6
+ }
7
+ export interface HashedFolder extends HashedFile {
8
+ members: (HashedFile | HashedFolder)[];
9
+ }
package/types/hash.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/types/hash.ts"],"names":[],"mappings":""}
package/types/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from './configuration';
3
3
  export * from './decodedToken';
4
4
  export * from './extraResponseAttributes';
5
5
  export * from './fileTree';
6
+ export * from './hash';
6
7
  export * from './httpsAgentOptions';
7
8
  export * from './macro';
8
9
  export * from './sasAuthResponse';
package/types/index.js CHANGED
@@ -15,6 +15,7 @@ __exportStar(require("./configuration"), exports);
15
15
  __exportStar(require("./decodedToken"), exports);
16
16
  __exportStar(require("./extraResponseAttributes"), exports);
17
17
  __exportStar(require("./fileTree"), exports);
18
+ __exportStar(require("./hash"), exports);
18
19
  __exportStar(require("./httpsAgentOptions"), exports);
19
20
  __exportStar(require("./macro"), exports);
20
21
  __exportStar(require("./sasAuthResponse"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwB;AACxB,kDAA+B;AAC/B,iDAA8B;AAC9B,4DAAyC;AACzC,6CAA0B;AAC1B,sDAAmC;AACnC,0CAAuB;AACvB,oDAAiC;AACjC,kDAA+B;AAC/B,gDAA6B;AAC7B,+CAA4B;AAC5B,gDAA6B;AAC7B,2CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwB;AACxB,kDAA+B;AAC/B,iDAA8B;AAC9B,4DAAyC;AACzC,6CAA0B;AAC1B,yCAAsB;AACtB,sDAAmC;AACnC,0CAAuB;AACvB,oDAAiC;AACjC,kDAA+B;AAC/B,gDAA6B;AAC7B,+CAA4B;AAC5B,gDAA6B;AAC7B,2CAAwB"}
@@ -0,0 +1,2 @@
1
+ export declare const getNodeModulePath: (module: string) => Promise<string>;
2
+ export declare const getGlobalNodeModulesPath: () => string;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.getGlobalNodeModulesPath = exports.getNodeModulePath = void 0;
43
+ var path_1 = __importDefault(require("path"));
44
+ var child_process_1 = require("child_process");
45
+ var file_1 = require("../file");
46
+ var getNodeModulePath = function (module) { return __awaiter(void 0, void 0, void 0, function () {
47
+ var projectPath, utilsDepsPath, utilsLocalPath, utilsGlobalPath;
48
+ return __generator(this, function (_a) {
49
+ switch (_a.label) {
50
+ case 0:
51
+ projectPath = path_1.default.join(process.cwd(), 'node_modules', module);
52
+ return [4 /*yield*/, (0, file_1.folderExists)(projectPath)];
53
+ case 1:
54
+ if (_a.sent())
55
+ return [2 /*return*/, projectPath
56
+ // Check if module is present in @sasjs/utils located in project's dependencies
57
+ ];
58
+ utilsDepsPath = path_1.default.join('@sasjs', 'utils', 'node_modules');
59
+ utilsLocalPath = path_1.default.join(process.cwd(), 'node_modules', utilsDepsPath, module);
60
+ return [4 /*yield*/, (0, file_1.folderExists)(utilsLocalPath)];
61
+ case 2:
62
+ if (_a.sent())
63
+ return [2 /*return*/, utilsLocalPath
64
+ // Check if module is present in global @sasjs/utils
65
+ ];
66
+ utilsGlobalPath = path_1.default.join((0, exports.getGlobalNodeModulesPath)(), utilsDepsPath, module);
67
+ return [4 /*yield*/, (0, file_1.folderExists)(utilsGlobalPath)];
68
+ case 3:
69
+ if (_a.sent())
70
+ return [2 /*return*/, utilsGlobalPath
71
+ // Return default value
72
+ ];
73
+ // Return default value
74
+ return [2 /*return*/, ''];
75
+ }
76
+ });
77
+ }); };
78
+ exports.getNodeModulePath = getNodeModulePath;
79
+ var getGlobalNodeModulesPath = function () {
80
+ return (0, child_process_1.execSync)("npm root -g").toString().replace(/\n/, '');
81
+ };
82
+ exports.getGlobalNodeModulesPath = getGlobalNodeModulesPath;
83
+ //# sourceMappingURL=getNodeModulePath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getNodeModulePath.js","sourceRoot":"","sources":["../../src/utils/getNodeModulePath.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAuB;AACvB,+CAAwC;AACxC,gCAAsC;AAE/B,IAAM,iBAAiB,GAAG,UAAO,MAAc;;;;;gBAE9C,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,MAAM,CAAC,CAAA;gBAEhE,qBAAM,IAAA,mBAAY,EAAC,WAAW,CAAC,EAAA;;gBAAnC,IAAI,SAA+B;oBAAE,sBAAO,WAAW;wBAEvD,+EAA+E;sBAFxB;gBAGjD,aAAa,GAAG,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,cAAc,CAAC,CAAA;gBAC5D,cAAc,GAAG,cAAI,CAAC,IAAI,CAC9B,OAAO,CAAC,GAAG,EAAE,EACb,cAAc,EACd,aAAa,EACb,MAAM,CACP,CAAA;gBAEG,qBAAM,IAAA,mBAAY,EAAC,cAAc,CAAC,EAAA;;gBAAtC,IAAI,SAAkC;oBAAE,sBAAO,cAAc;wBAE7D,oDAAoD;sBAFS;gBAGvD,eAAe,GAAG,cAAI,CAAC,IAAI,CAC/B,IAAA,gCAAwB,GAAE,EAC1B,aAAa,EACb,MAAM,CACP,CAAA;gBAEG,qBAAM,IAAA,mBAAY,EAAC,eAAe,CAAC,EAAA;;gBAAvC,IAAI,SAAmC;oBAAE,sBAAO,eAAe;wBAE/D,uBAAuB;sBAFwC;gBAE/D,uBAAuB;gBACvB,sBAAO,EAAE,EAAA;;;KACV,CAAA;AA5BY,QAAA,iBAAiB,qBA4B7B;AAEM,IAAM,wBAAwB,GAAG;IACtC,OAAA,IAAA,wBAAQ,EAAC,aAAa,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;AAApD,CAAoD,CAAA;AADzC,QAAA,wBAAwB,4BACiB"}
package/utils/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export { getExecutorPath } from './executor';
6
6
  export { bytesToSize } from './bytesToSize';
7
7
  export { diff } from './diff';
8
8
  export { chunk } from './chunk';
9
+ export { getNodeModulePath } from './getNodeModulePath';
package/utils/index.js CHANGED
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.chunk = exports.diff = exports.bytesToSize = exports.getExecutorPath = exports.decodeFromBase64 = exports.encodeToBase64 = exports.urlOrigin = exports.escapeWinSlashes = exports.isLinux = exports.isWindows = exports.uniqArray = exports.asyncForEach = exports.uuidv4 = void 0;
13
+ exports.getNodeModulePath = exports.chunk = exports.diff = exports.bytesToSize = exports.getExecutorPath = exports.decodeFromBase64 = exports.encodeToBase64 = exports.urlOrigin = exports.escapeWinSlashes = exports.isLinux = exports.isWindows = exports.uniqArray = exports.asyncForEach = exports.uuidv4 = void 0;
14
14
  var utils_1 = require("./utils");
15
15
  Object.defineProperty(exports, "uuidv4", { enumerable: true, get: function () { return utils_1.uuidv4; } });
16
16
  Object.defineProperty(exports, "asyncForEach", { enumerable: true, get: function () { return utils_1.asyncForEach; } });
@@ -32,4 +32,6 @@ var diff_1 = require("./diff");
32
32
  Object.defineProperty(exports, "diff", { enumerable: true, get: function () { return diff_1.diff; } });
33
33
  var chunk_1 = require("./chunk");
34
34
  Object.defineProperty(exports, "chunk", { enumerable: true, get: function () { return chunk_1.chunk; } });
35
+ var getNodeModulePath_1 = require("./getNodeModulePath");
36
+ Object.defineProperty(exports, "getNodeModulePath", { enumerable: true, get: function () { return getNodeModulePath_1.getNodeModulePath; } });
35
37
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iCAOgB;AANd,+FAAA,MAAM,OAAA;AACN,qGAAA,YAAY,OAAA;AACZ,kGAAA,SAAS,OAAA;AACT,kGAAA,SAAS,OAAA;AACT,gGAAA,OAAO,OAAA;AACP,yGAAA,gBAAgB,OAAA;AAElB,6CAA0B;AAE1B,6BAAiC;AAAxB,gGAAA,SAAS,OAAA;AAElB,mCAA2D;AAAlD,wGAAA,cAAc,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAEzC,uCAA4C;AAAnC,2GAAA,eAAe,OAAA;AAExB,6CAA2C;AAAlC,0GAAA,WAAW,OAAA;AACpB,+BAA6B;AAApB,4FAAA,IAAI,OAAA;AACb,iCAA+B;AAAtB,8FAAA,KAAK,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iCAOgB;AANd,+FAAA,MAAM,OAAA;AACN,qGAAA,YAAY,OAAA;AACZ,kGAAA,SAAS,OAAA;AACT,kGAAA,SAAS,OAAA;AACT,gGAAA,OAAO,OAAA;AACP,yGAAA,gBAAgB,OAAA;AAElB,6CAA0B;AAE1B,6BAAiC;AAAxB,gGAAA,SAAS,OAAA;AAElB,mCAA2D;AAAlD,wGAAA,cAAc,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAEzC,uCAA4C;AAAnC,2GAAA,eAAe,OAAA;AAExB,6CAA2C;AAAlC,0GAAA,WAAW,OAAA;AACpB,+BAA6B;AAApB,4FAAA,IAAI,OAAA;AACb,iCAA+B;AAAtB,8FAAA,KAAK,OAAA;AACd,yDAAuD;AAA9C,sHAAA,iBAAiB,OAAA"}