@sasjs/cli 3.8.8 → 3.10.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.
@@ -113,78 +113,66 @@ function build(target) {
113
113
  }
114
114
  exports.build = build;
115
115
  function createFinalSasFiles(target) {
116
- var _a;
116
+ var _a, _b, _c, _d, _e, _f, _g;
117
117
  return __awaiter(this, void 0, void 0, function () {
118
- var streamConfig;
119
- return __generator(this, function (_b) {
120
- switch (_b.label) {
118
+ var streamConfig, streamWeb, buildConfig, serverType, name, macroFolders, buildOutputFileName, buildDestinationFolder, finalSasFileContent, finalFilePath, finalFilePathJSON, buildInfo, buildInit, buildTerm, macroCorePath, dependencyFilePaths, dependenciesContent, _h, folderContent, folderContentJSON;
119
+ return __generator(this, function (_j) {
120
+ switch (_j.label) {
121
121
  case 0:
122
122
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info('Creating output SAS and JSON files.');
123
123
  return [4 /*yield*/, (0, config_1.getStreamConfig)(target)];
124
124
  case 1:
125
- streamConfig = _b.sent();
126
- return [4 /*yield*/, createFinalSasFile(target, streamConfig)];
127
- case 2:
128
- _b.sent();
129
- return [2 /*return*/];
130
- }
131
- });
132
- });
133
- }
134
- function createFinalSasFile(target, streamConfig) {
135
- var _a, _b, _c, _d, _e, _f;
136
- return __awaiter(this, void 0, void 0, function () {
137
- var streamWeb, buildConfig, serverType, name, macroFolders, buildOutputFileName, buildDestinationFolder, finalSasFileContent, finalFilePath, finalFilePathJSON, buildInfo, buildInit, buildTerm, macroCorePath, dependencyFilePaths, dependenciesContent, _g, folderContent, folderContentJSON;
138
- return __generator(this, function (_h) {
139
- switch (_h.label) {
140
- case 0:
141
- streamWeb = (_a = streamConfig.streamWeb) !== null && _a !== void 0 ? _a : false;
125
+ streamConfig = _j.sent();
126
+ streamWeb = (_b = streamConfig.streamWeb) !== null && _b !== void 0 ? _b : false;
142
127
  buildConfig = target.buildConfig, serverType = target.serverType, name = target.name;
143
128
  return [4 /*yield*/, (0, config_1.getMacroFolders)(target)];
144
- case 1:
145
- macroFolders = _h.sent();
146
- buildOutputFileName = (_b = buildConfig === null || buildConfig === void 0 ? void 0 : buildConfig.buildOutputFileName) !== null && _b !== void 0 ? _b : "".concat(name, ".sas");
129
+ case 2:
130
+ macroFolders = _j.sent();
131
+ buildOutputFileName = (_c = buildConfig === null || buildConfig === void 0 ? void 0 : buildConfig.buildOutputFileName) !== null && _c !== void 0 ? _c : "".concat(name, ".sas");
147
132
  buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
148
133
  finalSasFileContent = '';
149
134
  finalFilePath = path_1.default.join(buildDestinationFolder, buildOutputFileName);
150
135
  finalFilePathJSON = path_1.default.join(buildDestinationFolder, "".concat(name, ".json"));
151
136
  return [4 /*yield*/, getBuildInfo(target, streamWeb)];
152
- case 2:
153
- buildInfo = _h.sent();
137
+ case 3:
138
+ buildInfo = _j.sent();
154
139
  finalSasFileContent += "\n".concat(buildInfo);
155
140
  return [4 /*yield*/, (0, config_2.getBuildInit)(target)];
156
- case 3:
157
- buildInit = _h.sent();
158
- return [4 /*yield*/, (0, config_2.getBuildTerm)(target)];
159
141
  case 4:
160
- buildTerm = _h.sent();
142
+ buildInit = _j.sent();
143
+ return [4 /*yield*/, (0, config_2.getBuildTerm)(target)];
144
+ case 5:
145
+ buildTerm = _j.sent();
161
146
  macroCorePath = (0, config_1.getMacroCorePath)();
162
147
  return [4 /*yield*/, (0, utils_1.getDependencyPaths)("".concat(buildTerm, "\n").concat(buildInit), macroFolders, macroCorePath)];
163
- case 5:
164
- dependencyFilePaths = _h.sent();
165
- return [4 /*yield*/, getDependencies(dependencyFilePaths)];
166
148
  case 6:
167
- dependenciesContent = _h.sent();
149
+ dependencyFilePaths = _j.sent();
150
+ return [4 /*yield*/, getDependencies(dependencyFilePaths)];
151
+ case 7:
152
+ dependenciesContent = _j.sent();
168
153
  finalSasFileContent += "\n".concat(dependenciesContent, "\n\n").concat(buildInit, "\n");
169
154
  return [4 /*yield*/, getFolderContent(serverType)];
170
- case 7:
171
- _g = _h.sent(), folderContent = _g.folderContent, folderContentJSON = _g.folderContentJSON;
155
+ case 8:
156
+ _h = _j.sent(), folderContent = _h.folderContent, folderContentJSON = _h.folderContentJSON;
172
157
  finalSasFileContent += "\n".concat(folderContent);
173
158
  finalSasFileContent += "\n".concat(buildTerm);
174
159
  if (streamWeb) {
175
- finalSasFileContent += (0, getLaunchPageCode_1.getLaunchPageCode)(target.serverType, streamConfig.streamServiceName);
160
+ if (target.serverType === utils_1.ServerType.SasViya ||
161
+ target.serverType === utils_1.ServerType.Sas9) {
162
+ finalSasFileContent += (0, getLaunchPageCode_1.getLaunchPageCode)(target.serverType, streamConfig.streamServiceName);
163
+ }
176
164
  }
177
165
  finalSasFileContent = (0, utils_2.removeComments)(finalSasFileContent);
178
- (_c = process.logger) === null || _c === void 0 ? void 0 : _c.debug("Creating file ".concat(finalFilePath, " ."));
166
+ (_d = process.logger) === null || _d === void 0 ? void 0 : _d.debug("Creating file ".concat(finalFilePath, " ."));
179
167
  return [4 /*yield*/, (0, utils_1.createFile)(finalFilePath, finalSasFileContent)];
180
- case 8:
181
- _h.sent();
182
- (_d = process.logger) === null || _d === void 0 ? void 0 : _d.success("File ".concat(finalFilePath, " has been created."));
183
- (_e = process.logger) === null || _e === void 0 ? void 0 : _e.debug("Creating file ".concat(finalFilePathJSON, " ."));
184
- return [4 /*yield*/, (0, utils_1.createFile)(finalFilePathJSON, JSON.stringify(folderContentJSON, null, 1))];
185
168
  case 9:
186
- _h.sent();
187
- (_f = process.logger) === null || _f === void 0 ? void 0 : _f.success("File ".concat(finalFilePathJSON, " has been created."));
169
+ _j.sent();
170
+ (_e = process.logger) === null || _e === void 0 ? void 0 : _e.success("File ".concat(finalFilePath, " has been created."));
171
+ (_f = process.logger) === null || _f === void 0 ? void 0 : _f.debug("Creating file ".concat(finalFilePathJSON, " ."));
172
+ return [4 /*yield*/, (0, utils_1.createFile)(finalFilePathJSON, JSON.stringify(folderContentJSON, null, 1))];
173
+ case 10:
174
+ _j.sent();
175
+ (_g = process.logger) === null || _g === void 0 ? void 0 : _g.success("File ".concat(finalFilePathJSON, " has been created."));
188
176
  return [2 /*return*/];
189
177
  }
190
178
  });
@@ -1,4 +1,5 @@
1
+ import { CompileTree } from '@sasjs/utils';
1
2
  import { Target } from '@sasjs/utils/types';
2
3
  export declare function compile(target: Target, forceCompile?: boolean): Promise<void>;
3
4
  export declare function copyFilesToBuildFolder(target: Target): Promise<void>;
4
- export declare function compileJobsServicesTests(target: Target): Promise<void>;
5
+ export declare function compileJobsServicesTests(target: Target, compileTree: CompileTree): Promise<void>;
@@ -82,11 +82,12 @@ var compileServiceFile_1 = require("./internal/compileServiceFile");
82
82
  var compileJobFile_1 = require("./internal/compileJobFile");
83
83
  var compileTestFile_1 = require("./internal/compileTestFile");
84
84
  var getDestinationPath_1 = require("./internal/getDestinationPath");
85
+ var loadDependencies_1 = require("./internal/loadDependencies");
85
86
  function compile(target, forceCompile) {
86
87
  var _a, _b;
87
88
  if (forceCompile === void 0) { forceCompile = false; }
88
89
  return __awaiter(this, void 0, void 0, function () {
89
- var result, macroFolders, programFolders_1, buildMacroTestFolder_1, macroTestFiles;
90
+ var result, compileTree, macroFolders, programFolders_1, buildMacroTestFolder_1, macroTestFiles;
90
91
  var _this = this;
91
92
  return __generator(this, function (_c) {
92
93
  switch (_c.label) {
@@ -108,7 +109,8 @@ function compile(target, forceCompile) {
108
109
  })];
109
110
  case 2:
110
111
  _c.sent();
111
- return [4 /*yield*/, compileModule.compileJobsServicesTests(target)];
112
+ compileTree = (0, loadDependencies_1.getCompileTree)(target);
113
+ return [4 /*yield*/, compileModule.compileJobsServicesTests(target, compileTree)];
112
114
  case 3:
113
115
  _c.sent();
114
116
  return [4 /*yield*/, (0, config_1.getMacroFolders)(target)];
@@ -136,7 +138,7 @@ function compile(target, forceCompile) {
136
138
  macroTestFiles = _c.sent();
137
139
  return [4 /*yield*/, (0, utils_1.asyncForEach)(macroTestFiles, function (macroTestFile) { return __awaiter(_this, void 0, void 0, function () {
138
140
  return __generator(this, function (_a) {
139
- return [2 /*return*/, (0, compileServiceFile_1.compileServiceFile)(target, path_1.default.join(buildMacroTestFolder_1, macroTestFile), macroFolders, programFolders_1)];
141
+ return [2 /*return*/, (0, compileServiceFile_1.compileServiceFile)(target, path_1.default.join(buildMacroTestFolder_1, macroTestFile), macroFolders, programFolders_1, undefined, compileTree)];
140
142
  });
141
143
  }); })];
142
144
  case 10:
@@ -221,7 +223,7 @@ function copyFilesToBuildFolder(target) {
221
223
  });
222
224
  }
223
225
  exports.copyFilesToBuildFolder = copyFilesToBuildFolder;
224
- function compileJobsServicesTests(target) {
226
+ function compileJobsServicesTests(target, compileTree) {
225
227
  var _a;
226
228
  return __awaiter(this, void 0, void 0, function () {
227
229
  var serviceFolders, jobFolders, macroFolders_1, programFolders_2, testSetUp, testTearDown, error_2;
@@ -262,7 +264,7 @@ function compileJobsServicesTests(target) {
262
264
  case 10: return [4 /*yield*/, (0, utils_1.asyncForEach)(serviceFolders, function (serviceFolder) { return __awaiter(_this, void 0, void 0, function () {
263
265
  return __generator(this, function (_a) {
264
266
  switch (_a.label) {
265
- case 0: return [4 /*yield*/, compileServiceFolder(target, serviceFolder, macroFolders_1, programFolders_2)];
267
+ case 0: return [4 /*yield*/, compileServiceFolder(target, serviceFolder, macroFolders_1, programFolders_2, compileTree)];
266
268
  case 1:
267
269
  _a.sent();
268
270
  return [2 /*return*/];
@@ -274,7 +276,7 @@ function compileJobsServicesTests(target) {
274
276
  return [4 /*yield*/, (0, utils_1.asyncForEach)(jobFolders, function (jobFolder) { return __awaiter(_this, void 0, void 0, function () {
275
277
  return __generator(this, function (_a) {
276
278
  switch (_a.label) {
277
- case 0: return [4 /*yield*/, compileJobFolder(target, jobFolder, macroFolders_1, programFolders_2)];
279
+ case 0: return [4 /*yield*/, compileJobFolder(target, jobFolder, macroFolders_1, programFolders_2, compileTree)];
278
280
  case 1:
279
281
  _a.sent();
280
282
  return [2 /*return*/];
@@ -319,7 +321,7 @@ function recreateBuildFolder() {
319
321
  });
320
322
  });
321
323
  }
322
- var compileServiceFolder = function (target, serviceFolder, macroFolders, programFolders) { return __awaiter(void 0, void 0, void 0, function () {
324
+ var compileServiceFolder = function (target, serviceFolder, macroFolders, programFolders, compileTree) { return __awaiter(void 0, void 0, void 0, function () {
323
325
  var destinationPath, subFolders, filesNamesInPath;
324
326
  return __generator(this, function (_a) {
325
327
  switch (_a.label) {
@@ -342,7 +344,7 @@ var compileServiceFolder = function (target, serviceFolder, macroFolders, progra
342
344
  case 1:
343
345
  _a.sent();
344
346
  return [3 /*break*/, 4];
345
- case 2: return [4 /*yield*/, (0, compileServiceFile_1.compileServiceFile)(target, filePath, macroFolders, programFolders)];
347
+ case 2: return [4 /*yield*/, (0, compileServiceFile_1.compileServiceFile)(target, filePath, macroFolders, programFolders, undefined, compileTree)];
346
348
  case 3:
347
349
  _a.sent();
348
350
  _a.label = 4;
@@ -370,7 +372,7 @@ var compileServiceFolder = function (target, serviceFolder, macroFolders, progra
370
372
  case 1:
371
373
  _a.sent();
372
374
  return [3 /*break*/, 4];
373
- case 2: return [4 /*yield*/, (0, compileServiceFile_1.compileServiceFile)(target, filePath, macroFolders, programFolders)];
375
+ case 2: return [4 /*yield*/, (0, compileServiceFile_1.compileServiceFile)(target, filePath, macroFolders, programFolders, undefined, compileTree)];
374
376
  case 3:
375
377
  _a.sent();
376
378
  _a.label = 4;
@@ -386,11 +388,12 @@ var compileServiceFolder = function (target, serviceFolder, macroFolders, progra
386
388
  }); })];
387
389
  case 4:
388
390
  _a.sent();
391
+ compileTree.saveTree();
389
392
  return [2 /*return*/];
390
393
  }
391
394
  });
392
395
  }); };
393
- var compileJobFolder = function (target, jobFolder, macroFolders, programFolders) { return __awaiter(void 0, void 0, void 0, function () {
396
+ var compileJobFolder = function (target, jobFolder, macroFolders, programFolders, compileTree) { return __awaiter(void 0, void 0, void 0, function () {
394
397
  var destinationPath, subFolders, filesNamesInPath;
395
398
  return __generator(this, function (_a) {
396
399
  switch (_a.label) {
@@ -413,7 +416,7 @@ var compileJobFolder = function (target, jobFolder, macroFolders, programFolders
413
416
  case 1:
414
417
  _a.sent();
415
418
  return [3 /*break*/, 4];
416
- case 2: return [4 /*yield*/, (0, compileJobFile_1.compileJobFile)(target, filePath, macroFolders, programFolders)];
419
+ case 2: return [4 /*yield*/, (0, compileJobFile_1.compileJobFile)(target, filePath, macroFolders, programFolders, undefined, compileTree)];
417
420
  case 3:
418
421
  _a.sent();
419
422
  _a.label = 4;
@@ -441,7 +444,7 @@ var compileJobFolder = function (target, jobFolder, macroFolders, programFolders
441
444
  case 1:
442
445
  _a.sent();
443
446
  return [3 /*break*/, 4];
444
- case 2: return [4 /*yield*/, (0, compileJobFile_1.compileJobFile)(target, filePath, macroFolders, programFolders)];
447
+ case 2: return [4 /*yield*/, (0, compileJobFile_1.compileJobFile)(target, filePath, macroFolders, programFolders, undefined, compileTree)];
445
448
  case 3:
446
449
  _a.sent();
447
450
  _a.label = 4;
@@ -46,12 +46,13 @@ var utils_1 = require("@sasjs/utils");
46
46
  var compileServiceFile_1 = require("./internal/compileServiceFile");
47
47
  var compileJobFile_1 = require("./internal/compileJobFile");
48
48
  var identifySasFile_1 = require("./internal/identifySasFile");
49
+ var loadDependencies_1 = require("./internal/loadDependencies");
49
50
  function compileSingleFile(target, subCommand, source, output, insertProgramVar) {
50
51
  var _a;
51
52
  if (subCommand === void 0) { subCommand = 'identify'; }
52
53
  if (insertProgramVar === void 0) { insertProgramVar = false; }
53
54
  return __awaiter(this, void 0, void 0, function () {
54
- var subCommands, commandExample, sourcePath, outputPathParts, leafFolderName, parentOutputFolder, pathExists, sourceFileName, destinationPath, sourceFileNameWithoutExt, macroFolders, programFolders, psMaxOption, programVar, _b;
55
+ var subCommands, commandExample, sourcePath, outputPathParts, leafFolderName, parentOutputFolder, pathExists, sourceFileName, destinationPath, sourceFileNameWithoutExt, macroFolders, programFolders, psMaxOption, programVar, compileTree, _b;
55
56
  return __generator(this, function (_c) {
56
57
  switch (_c.label) {
57
58
  case 0:
@@ -111,17 +112,18 @@ function compileSingleFile(target, subCommand, source, output, insertProgramVar)
111
112
  programVar = insertProgramVar
112
113
  ? "%let _program=".concat(target.appLoc, "/").concat(subCommand, "s/").concat(leafFolderName, "/").concat(sourceFileNameWithoutExt, ";\n").concat(psMaxOption)
113
114
  : "".concat(psMaxOption);
115
+ compileTree = (0, loadDependencies_1.getCompileTree)(target);
114
116
  _b = subCommand;
115
117
  switch (_b) {
116
118
  case subCommands.service: return [3 /*break*/, 11];
117
119
  case subCommands.job: return [3 /*break*/, 13];
118
120
  }
119
121
  return [3 /*break*/, 15];
120
- case 11: return [4 /*yield*/, (0, compileServiceFile_1.compileServiceFile)(target, destinationPath, macroFolders, programFolders, programVar)];
122
+ case 11: return [4 /*yield*/, (0, compileServiceFile_1.compileServiceFile)(target, destinationPath, macroFolders, programFolders, programVar, compileTree)];
121
123
  case 12:
122
124
  _c.sent();
123
125
  return [3 /*break*/, 16];
124
- case 13: return [4 /*yield*/, (0, compileJobFile_1.compileJobFile)(target, destinationPath, macroFolders, programFolders, programVar)];
126
+ case 13: return [4 /*yield*/, (0, compileJobFile_1.compileJobFile)(target, destinationPath, macroFolders, programFolders, programVar, compileTree)];
125
127
  case 14:
126
128
  _c.sent();
127
129
  return [3 /*break*/, 16];
@@ -1,2 +1,3 @@
1
1
  import { Target } from '@sasjs/utils/types';
2
- export declare function compileJobFile(target: Target, filePath: string, macroFolders: string[], programFolders: string[], programVar?: string): Promise<void>;
2
+ import { CompileTree } from '@sasjs/utils';
3
+ export declare function compileJobFile(target: Target, filePath: string, macroFolders: string[], programFolders: string[], programVar: string | undefined, compileTree: CompileTree): Promise<void>;
@@ -39,13 +39,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.compileJobFile = void 0;
40
40
  var utils_1 = require("@sasjs/utils");
41
41
  var loadDependencies_1 = require("./loadDependencies");
42
- function compileJobFile(target, filePath, macroFolders, programFolders, programVar) {
42
+ function compileJobFile(target, filePath, macroFolders, programFolders, programVar, compileTree) {
43
43
  if (programVar === void 0) { programVar = ''; }
44
44
  return __awaiter(this, void 0, void 0, function () {
45
45
  var dependencies;
46
46
  return __generator(this, function (_a) {
47
47
  switch (_a.label) {
48
- case 0: return [4 /*yield*/, (0, loadDependencies_1.loadDependencies)(target, filePath, macroFolders, programFolders, (0, utils_1.isTestFile)(filePath) ? utils_1.SASJsFileType.test : utils_1.SASJsFileType.job)];
48
+ case 0: return [4 /*yield*/, (0, loadDependencies_1.loadDependencies)(target, filePath, macroFolders, programFolders, (0, utils_1.isTestFile)(filePath) ? utils_1.SASJsFileType.test : utils_1.SASJsFileType.job, compileTree)];
49
49
  case 1:
50
50
  dependencies = _a.sent();
51
51
  dependencies = "".concat(programVar ? programVar + '\n' : '').concat(dependencies);
@@ -1,3 +1,4 @@
1
+ import { CompileTree } from '@sasjs/utils';
1
2
  import { Target, ServerType } from '@sasjs/utils/types';
2
- export declare function compileServiceFile(target: Target, filePath: string, macroFolders: string[], programFolders: string[], programVar?: string): Promise<void>;
3
+ export declare function compileServiceFile(target: Target, filePath: string, macroFolders: string[], programFolders: string[], programVar: string | undefined, compileTree: CompileTree): Promise<void>;
3
4
  export declare function getPreCodeForServicePack(serverType: ServerType): Promise<string>;
@@ -43,13 +43,13 @@ var types_1 = require("@sasjs/utils/types");
43
43
  var error_1 = require("@sasjs/utils/error");
44
44
  var loadDependencies_1 = require("./loadDependencies");
45
45
  var getServerType_1 = require("./getServerType");
46
- function compileServiceFile(target, filePath, macroFolders, programFolders, programVar) {
46
+ function compileServiceFile(target, filePath, macroFolders, programFolders, programVar, compileTree) {
47
47
  if (programVar === void 0) { programVar = ''; }
48
48
  return __awaiter(this, void 0, void 0, function () {
49
49
  var dependencies, serverType, preCode;
50
50
  return __generator(this, function (_a) {
51
51
  switch (_a.label) {
52
- case 0: return [4 /*yield*/, (0, loadDependencies_1.loadDependencies)(target, filePath, macroFolders, programFolders, (0, utils_1.isTestFile)(filePath) ? types_1.SASJsFileType.test : types_1.SASJsFileType.service)];
52
+ case 0: return [4 /*yield*/, (0, loadDependencies_1.loadDependencies)(target, filePath, macroFolders, programFolders, (0, utils_1.isTestFile)(filePath) ? types_1.SASJsFileType.test : types_1.SASJsFileType.service, compileTree)];
53
53
  case 1:
54
54
  dependencies = _a.sent();
55
55
  return [4 /*yield*/, (0, getServerType_1.getServerType)(target)];
@@ -82,10 +82,11 @@ function compileTestFile(target, filePath, testVar, saveToRoot, removeOriginalFi
82
82
  if (saveToRoot === void 0) { saveToRoot = true; }
83
83
  if (removeOriginalFile === void 0) { removeOriginalFile = true; }
84
84
  return __awaiter(this, void 0, void 0, function () {
85
- var dependencies, _a, _b, preCode, destinationPath;
85
+ var compileTree, dependencies, _a, _b, preCode, destinationPath;
86
86
  return __generator(this, function (_c) {
87
87
  switch (_c.label) {
88
88
  case 0:
89
+ compileTree = (0, loadDependencies_1.getCompileTree)(target);
89
90
  _a = loadDependencies_1.loadDependencies;
90
91
  _b = [target,
91
92
  (0, utils_1.getAbsolutePath)(filePath, process.projectDir)];
@@ -93,7 +94,8 @@ function compileTestFile(target, filePath, testVar, saveToRoot, removeOriginalFi
93
94
  case 1:
94
95
  _b = _b.concat([_c.sent()]);
95
96
  return [4 /*yield*/, (0, config_1.getProgramFolders)(target)];
96
- case 2: return [4 /*yield*/, _a.apply(void 0, _b.concat([_c.sent(), utils_1.SASJsFileType.test]))];
97
+ case 2: return [4 /*yield*/, _a.apply(void 0, _b.concat([_c.sent(), utils_1.SASJsFileType.test,
98
+ compileTree]))];
97
99
  case 3:
98
100
  dependencies = _c.sent();
99
101
  return [4 /*yield*/, (0, compileServiceFile_1.getPreCodeForServicePack)(target.serverType)];
@@ -1,2 +1,3 @@
1
- import { Target, SASJsFileType } from '@sasjs/utils';
2
- export declare function loadDependencies(target: Target, filePath: string, macroFolders: string[], programFolders: string[], type: SASJsFileType): Promise<string>;
1
+ import { Target, SASJsFileType, CompileTree } from '@sasjs/utils';
2
+ export declare function loadDependencies(target: Target, filePath: string, macroFolders: string[], programFolders: string[], type: SASJsFileType, compileTree: CompileTree): Promise<string>;
3
+ export declare const getCompileTree: (target: Target) => CompileTree;
@@ -35,27 +35,43 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
38
41
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.loadDependencies = void 0;
42
+ exports.getCompileTree = exports.loadDependencies = void 0;
40
43
  var utils_1 = require("@sasjs/utils");
41
44
  var config_1 = require("../../../utils/config");
42
- function loadDependencies(target, filePath, macroFolders, programFolders, type) {
45
+ var path_1 = __importDefault(require("path"));
46
+ function loadDependencies(target, filePath, macroFolders, programFolders, type, compileTree) {
43
47
  var _a;
44
48
  return __awaiter(this, void 0, void 0, function () {
45
- var fileContent, configuration, _b, buildSourceFolder, macroCorePath, binaryFolders;
49
+ var fileContent, leaf, configuration, _b, buildSourceFolder, macroCorePath, binaryFolders;
46
50
  return __generator(this, function (_c) {
47
51
  switch (_c.label) {
48
52
  case 0:
49
53
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Loading dependencies for ".concat(filePath));
50
- return [4 /*yield*/, (0, utils_1.readFile)(filePath)];
51
- case 1:
52
- fileContent = _c.sent();
53
- return [4 /*yield*/, (0, config_1.getLocalOrGlobalConfig)()];
54
+ fileContent = '';
55
+ if (!(compileTree && Object.keys(compileTree).length)) return [3 /*break*/, 4];
56
+ leaf = compileTree.getLeaf(filePath);
57
+ if (!leaf) return [3 /*break*/, 1];
58
+ fileContent = leaf.content;
59
+ return [3 /*break*/, 3];
60
+ case 1: return [4 /*yield*/, (0, utils_1.readFile)(filePath)];
54
61
  case 2:
62
+ fileContent = _c.sent();
63
+ _c.label = 3;
64
+ case 3: return [3 /*break*/, 6];
65
+ case 4: return [4 /*yield*/, (0, utils_1.readFile)(filePath)];
66
+ case 5:
67
+ fileContent = _c.sent();
68
+ _c.label = 6;
69
+ case 6: return [4 /*yield*/, (0, config_1.getLocalOrGlobalConfig)()];
70
+ case 7:
55
71
  configuration = (_c.sent()).configuration;
56
72
  _b = process.sasjsConstants, buildSourceFolder = _b.buildSourceFolder, macroCorePath = _b.macroCorePath;
57
73
  return [4 /*yield*/, (0, config_1.getBinaryFolders)(target)];
58
- case 3:
74
+ case 8:
59
75
  binaryFolders = _c.sent();
60
76
  headerSyntaxNotices(fileContent);
61
77
  return [4 /*yield*/, (0, utils_1.loadDependenciesFile)({
@@ -68,9 +84,10 @@ function loadDependencies(target, filePath, macroFolders, programFolders, type)
68
84
  programFolders: programFolders,
69
85
  buildSourceFolder: buildSourceFolder,
70
86
  macroCorePath: macroCorePath,
71
- binaryFolders: binaryFolders
87
+ binaryFolders: binaryFolders,
88
+ compileTree: compileTree
72
89
  })];
73
- case 4: return [2 /*return*/, _c.sent()];
90
+ case 9: return [2 /*return*/, _c.sent()];
74
91
  }
75
92
  });
76
93
  });
@@ -78,21 +95,21 @@ function loadDependencies(target, filePath, macroFolders, programFolders, type)
78
95
  exports.loadDependencies = loadDependencies;
79
96
  var headerSyntaxNotices = function (fileContent) {
80
97
  var _a, _b, _c;
81
- if (fileContent.includes('<h4> Dependencies </h4>')) {
98
+ if (fileContent.includes(utils_1.DependencyHeader.DeprecatedMacro)) {
82
99
  var deprecationDate = new Date(2021, 10, 2);
83
100
  var today = new Date();
84
101
  if (today < deprecationDate) {
85
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.warn("Please use <h4> SAS Macros </h4> syntax to specify dependencies. Specifying dependencies with a <h4> Dependencies </h4> syntax will not be supported starting from November 1, 2021.");
102
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.warn("Please use ".concat(utils_1.DependencyHeader.Macro, " syntax to specify dependencies. Specifying dependencies with a ").concat(utils_1.DependencyHeader.DeprecatedMacro, " syntax will not be supported starting from November 1, 2021."));
86
103
  }
87
104
  else {
88
- throw new Error('Using <h4> Dependencies </h4> syntax is deprecated. Please use <h4> SAS Macros </h4> instead.');
105
+ throw new Error("Using ".concat(utils_1.DependencyHeader.DeprecatedMacro, " syntax is deprecated. Please use ").concat(utils_1.DependencyHeader.Macro, " instead."));
89
106
  }
90
107
  }
91
- if (fileContent.includes('<h4> SAS Programs </h4>')) {
108
+ if (fileContent.includes(utils_1.DependencyHeader.DeprecatedInclude)) {
92
109
  var deprecationDate = new Date(2022, 4, 2);
93
110
  var warningDate = new Date(2022, 10, 2);
94
111
  var today = new Date();
95
- var message = "Please use <h4> SAS Includes </h4> syntax to specify programs. Specifying programs with a <h4> SAS Programs </h4> syntax will not be supported starting from April 1, 2022.";
112
+ var message = "Please use ".concat(utils_1.DependencyHeader.Include, " syntax to specify programs. Specifying programs with a ").concat(utils_1.DependencyHeader.DeprecatedInclude, " syntax will not be supported starting from April 1, 2022.");
96
113
  if (today < warningDate) {
97
114
  (_b = process.logger) === null || _b === void 0 ? void 0 : _b.info(message);
98
115
  }
@@ -100,6 +117,10 @@ var headerSyntaxNotices = function (fileContent) {
100
117
  (_c = process.logger) === null || _c === void 0 ? void 0 : _c.warn(message);
101
118
  }
102
119
  else
103
- throw new Error('Using <h4> SAS Programs </h4> syntax is deprecated. Please use <h4> SAS Includes </h4> instead.');
120
+ throw new Error("Using ".concat(utils_1.DependencyHeader.DeprecatedInclude, " syntax is deprecated. Please use ").concat(utils_1.DependencyHeader.Include, " instead."));
104
121
  }
105
122
  };
123
+ var getCompileTree = function (target) {
124
+ return new utils_1.CompileTree(path_1.default.join(process.sasjsConstants.buildDestinationFolder, "".concat(target === null || target === void 0 ? void 0 : target.name, "_compileTree.json")));
125
+ };
126
+ exports.getCompileTree = getCompileTree;
@@ -129,8 +129,8 @@ describe('compileTestFile', function () {
129
129
  case 2:
130
130
  testFileContent = _a.apply(void 0, [_b.sent()]);
131
131
  testVar = replaceLineBreaks("* Test Variables start;\n\n%let ".concat(Object.keys(target.testConfig.macroVars)[0], "=").concat(Object.values(target.testConfig.macroVars)[0], ";\n\n* Test Variables end;"));
132
- testInit = replaceLineBreaks("* TestInit start;\n/**\n @file\n @brief setting up the test\n\n <h4> SAS Macros </h4>\n**/\n\n%put testing, init;\n* TestInit end;");
133
- testTerm = replaceLineBreaks("* TestTerm start;\n/**\n @file\n @brief ending the test\n\n <h4> SAS Macros </h4>\n**/\n\n%put testing, termed;\n* TestTerm end;");
132
+ testInit = replaceLineBreaks("* TestInit start;\n%put testing, init;\n* TestInit end;");
133
+ testTerm = replaceLineBreaks("* TestTerm start;\n%put testing, termed;\n* TestTerm end;");
134
134
  mvWebout = "%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y,missing=NULL<br> ,showmeta=NO<br>);";
135
135
  expect(testFileContent.indexOf(testVar)).toBeGreaterThan(-1);
136
136
  expect(testFileContent.indexOf(testInit)).toBeGreaterThan(-1);
@@ -65,8 +65,9 @@ var getInitTerm_1 = require("@sasjs/utils/sasjsCli/getInitTerm");
65
65
  var test_1 = require("../../../utils/test");
66
66
  var compileJobFile_1 = require("../internal/compileJobFile");
67
67
  var utils_2 = require("@sasjs/utils");
68
- var fakeJobInit = "/**\n @file\n @brief This code is inserted into the beginning of each Viya Job.\n @details Inserted during the `sasjs compile` step. Add any code here that\n should go at the beginning of every deployed job.\n\n The path to this file should be listed in the `jobInit` property of the\n sasjsconfig file.\n\n <h4> SAS Programs </h4>\n @li test.sas TEST\n\n <h4> SAS Macros </h4>\n @li examplemacro.sas\n\n**/\n\n%example(Job Init is executing!)\n\n%let mylib=WORK;";
69
- var fakeJobTerm = "/**\n @file serviceterm.sas\n @brief this file is called at the end of every service\n @details This file is included at the *end* of every service.\n\n <h4> SAS Macros </h4>\n @li mf_abort.sas\n @li mf_existds.sas\n\n**/\n\n%put service is finishing. Thanks, SASjs!;";
68
+ var loadDependencies_1 = require("../internal/loadDependencies");
69
+ var fakeJobInit = "/**\n @file\n @brief This code is inserted into the beginning of each Viya Job.\n @details Inserted during the `sasjs compile` step. Add any code here that\n should go at the beginning of every deployed job.\n\n The path to this file should be listed in the `jobInit` property of the\n sasjsconfig file.\n\n ".concat(utils_1.DependencyHeader.DeprecatedInclude, "\n @li test.sas TEST\n\n ").concat(utils_1.DependencyHeader.Macro, "\n @li examplemacro.sas\n\n**/\n\n%example(Job Init is executing!)\n\n%let mylib=WORK;");
70
+ var fakeJobTerm = "/**\n @file serviceterm.sas\n @brief this file is called at the end of every service\n @details This file is included at the *end* of every service.\n\n ".concat(utils_1.DependencyHeader.Macro, "\n @li mf_abort.sas\n @li mf_existds.sas\n\n**/\n\n%put service is finishing. Thanks, SASjs!;");
70
71
  var fakeProgramLines = [
71
72
  'filename TEST temp;',
72
73
  'data _null_;',
@@ -103,7 +104,7 @@ describe('compileJobFile', function () {
103
104
  });
104
105
  }); });
105
106
  test('it should compile and create file', function () { return __awaiter(void 0, void 0, void 0, function () {
106
- var filePath, buildPath, destinationPath, compiledContent, macrosToTest;
107
+ var filePath, buildPath, destinationPath, compileTree, compiledContent, macrosToTest;
107
108
  return __generator(this, function (_a) {
108
109
  switch (_a.label) {
109
110
  case 0:
@@ -111,13 +112,14 @@ describe('compileJobFile', function () {
111
112
  filePath = path_1.default.join(__dirname, './service.sas');
112
113
  buildPath = path_1.default.join(process.projectDir, 'sasjsbuild');
113
114
  destinationPath = path_1.default.join(buildPath, 'service.sas');
115
+ compileTree = (0, loadDependencies_1.getCompileTree)(target);
114
116
  return [4 /*yield*/, (0, utils_2.createFolder)(buildPath)];
115
117
  case 1:
116
118
  _a.sent();
117
119
  return [4 /*yield*/, (0, utils_2.copy)(filePath, destinationPath)];
118
120
  case 2:
119
121
  _a.sent();
120
- return [4 /*yield*/, expect((0, compileJobFile_1.compileJobFile)(target, destinationPath, [path_1.default.join(__dirname, './macros')], [path_1.default.join(__dirname, './'), path_1.default.join(__dirname, './services')])).toResolve()];
122
+ return [4 /*yield*/, expect((0, compileJobFile_1.compileJobFile)(target, destinationPath, [path_1.default.join(__dirname, './macros')], [path_1.default.join(__dirname, './'), path_1.default.join(__dirname, './services')], undefined, compileTree)).toResolve()];
121
123
  case 3:
122
124
  _a.sent();
123
125
  return [4 /*yield*/, expect((0, utils_2.fileExists)(destinationPath)).resolves.toEqual(true)];
@@ -65,8 +65,9 @@ var getInitTerm_1 = require("@sasjs/utils/sasjsCli/getInitTerm");
65
65
  var test_1 = require("../../../utils/test");
66
66
  var compileServiceFile_1 = require("../internal/compileServiceFile");
67
67
  var utils_2 = require("@sasjs/utils");
68
- var fakeJobInit = "/**\n @file\n @brief This code is inserted into the beginning of each Viya Job.\n @details Inserted during the `sasjs compile` step. Add any code here that\n should go at the beginning of every deployed job.\n\n The path to this file should be listed in the `jobInit` property of the\n sasjsconfig file.\n\n <h4> SAS Programs </h4>\n @li test.sas TEST\n\n <h4> SAS Macros </h4>\n @li examplemacro.sas\n\n**/\n\n%example(Job Init is executing!)\n\n%let mylib=WORK;";
69
- var fakeJobTerm = "/**\n @file serviceterm.sas\n @brief this file is called at the end of every service\n @details This file is included at the *end* of every service.\n\n <h4> SAS Macros </h4>\n @li mf_abort.sas\n @li mf_existds.sas\n\n**/\n\n%put service is finishing. Thanks, SASjs!;";
68
+ var loadDependencies_1 = require("../internal/loadDependencies");
69
+ var fakeJobInit = "/**\n @file\n @brief This code is inserted into the beginning of each Viya Job.\n @details Inserted during the `sasjs compile` step. Add any code here that\n should go at the beginning of every deployed job.\n\n The path to this file should be listed in the `jobInit` property of the\n sasjsconfig file.\n\n ".concat(utils_1.DependencyHeader.DeprecatedInclude, "\n @li test.sas TEST\n\n ").concat(utils_1.DependencyHeader.Macro, "\n @li examplemacro.sas\n\n**/\n\n%example(Job Init is executing!)\n\n%let mylib=WORK;");
70
+ var fakeJobTerm = "/**\n @file serviceterm.sas\n @brief this file is called at the end of every service\n @details This file is included at the *end* of every service.\n\n ".concat(utils_1.DependencyHeader.Macro, "\n @li mf_abort.sas\n @li mf_existds.sas\n\n**/\n\n%put service is finishing. Thanks, SASjs!;");
70
71
  var fakeProgramLines = [
71
72
  'filename TEST temp;',
72
73
  'data _null_;',
@@ -104,7 +105,7 @@ describe('compileServiceFile', function () {
104
105
  });
105
106
  }); });
106
107
  test('it should compile and create file', function () { return __awaiter(void 0, void 0, void 0, function () {
107
- var filePath, buildPath, destinationPath, compiledContent, macrosToTest;
108
+ var filePath, buildPath, destinationPath, compileTree, compiledContent, macrosToTest;
108
109
  return __generator(this, function (_a) {
109
110
  switch (_a.label) {
110
111
  case 0:
@@ -112,13 +113,14 @@ describe('compileServiceFile', function () {
112
113
  filePath = path_1.default.join(__dirname, './service.sas');
113
114
  buildPath = path_1.default.join(process.projectDir, 'sasjsbuild');
114
115
  destinationPath = path_1.default.join(buildPath, 'service.sas');
116
+ compileTree = (0, loadDependencies_1.getCompileTree)(target);
115
117
  return [4 /*yield*/, (0, utils_2.createFolder)(buildPath)];
116
118
  case 1:
117
119
  _a.sent();
118
120
  return [4 /*yield*/, (0, utils_2.copy)(filePath, destinationPath)];
119
121
  case 2:
120
122
  _a.sent();
121
- return [4 /*yield*/, expect((0, compileServiceFile_1.compileServiceFile)(target, destinationPath, [path_1.default.join(__dirname, './macros')], [path_1.default.join(__dirname, './'), path_1.default.join(__dirname, './services')])).toResolve()];
123
+ return [4 /*yield*/, expect((0, compileServiceFile_1.compileServiceFile)(target, destinationPath, [path_1.default.join(__dirname, './macros')], [path_1.default.join(__dirname, './'), path_1.default.join(__dirname, './services')], undefined, compileTree)).toResolve()];
122
124
  case 3:
123
125
  _a.sent();
124
126
  return [4 /*yield*/, expect((0, utils_2.fileExists)(destinationPath)).resolves.toEqual(true)];