@sasjs/cli 4.0.5 → 4.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/commands/build/build.d.ts +1 -1
- package/build/commands/build/build.js +9 -14
- package/build/commands/compile/compile.js +34 -31
- package/build/commands/compile/compileCommand.js +1 -1
- package/build/commands/compile/internal/compileTestFile.d.ts +1 -1
- package/build/commands/compile/internal/compileTestFile.js +4 -4
- package/build/commands/compile/internal/getAllFolders.d.ts +1 -1
- package/build/commands/compile/internal/loadDependencies.d.ts +1 -1
- package/build/commands/compile/internal/loadDependencies.js +1 -1
- package/build/commands/compile/spec/compile.spec.js +42 -0
- package/build/commands/docs/docsCommand.js +4 -9
- package/build/utils/config.js +19 -14
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ServerType, Target } from '@sasjs/utils';
|
|
2
2
|
export declare function build(target: Target): Promise<void>;
|
|
3
3
|
export declare function getWebServiceScriptInvocation(serverType: ServerType, isSASFile?: boolean, encoded?: boolean): string;
|
|
4
4
|
export declare function getBuildVars(target: Target): Promise<string>;
|
|
@@ -87,17 +87,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
87
87
|
};
|
|
88
88
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
89
89
|
exports.getBuildVars = exports.getWebServiceScriptInvocation = exports.build = void 0;
|
|
90
|
-
var path_1 = __importDefault(require("path"));
|
|
91
90
|
var utils_1 = require("@sasjs/utils");
|
|
92
91
|
var error_1 = require("@sasjs/utils/error");
|
|
93
|
-
var
|
|
92
|
+
var path_1 = __importDefault(require("path"));
|
|
93
|
+
var types_1 = require("@sasjs/utils/types");
|
|
94
|
+
var compressAndSave_1 = require("../../utils/compressAndSave");
|
|
94
95
|
var config_1 = require("../../utils/config");
|
|
96
|
+
var file_1 = require("../../utils/file");
|
|
95
97
|
var compile_1 = require("../compile/compile");
|
|
98
|
+
var loadDependencies_1 = require("../compile/internal/loadDependencies");
|
|
96
99
|
var config_2 = require("./internal/config");
|
|
97
100
|
var getLaunchPageCode_1 = require("./internal/getLaunchPageCode");
|
|
98
|
-
var types_1 = require("@sasjs/utils/types");
|
|
99
|
-
var compressAndSave_1 = require("../../utils/compressAndSave");
|
|
100
|
-
var loadDependencies_1 = require("../compile/internal/loadDependencies");
|
|
101
101
|
function build(target) {
|
|
102
102
|
return __awaiter(this, void 0, void 0, function () {
|
|
103
103
|
var _a;
|
|
@@ -515,15 +515,10 @@ function getBuildVars(target) {
|
|
|
515
515
|
return __awaiter(this, void 0, void 0, function () {
|
|
516
516
|
var targetBuildVars, configuration, commonBuildVars;
|
|
517
517
|
return __generator(this, function (_e) {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
case 1:
|
|
523
|
-
configuration = _e.sent();
|
|
524
|
-
commonBuildVars = (_d = (_c = configuration === null || configuration === void 0 ? void 0 : configuration.buildConfig) === null || _c === void 0 ? void 0 : _c.macroVars) !== null && _d !== void 0 ? _d : {};
|
|
525
|
-
return [2 /*return*/, convertVarsToSasFormat(__assign(__assign({}, commonBuildVars), targetBuildVars))];
|
|
526
|
-
}
|
|
518
|
+
targetBuildVars = (_b = (_a = target === null || target === void 0 ? void 0 : target.buildConfig) === null || _a === void 0 ? void 0 : _a.macroVars) !== null && _b !== void 0 ? _b : {};
|
|
519
|
+
configuration = process.sasjsConfig;
|
|
520
|
+
commonBuildVars = (_d = (_c = configuration === null || configuration === void 0 ? void 0 : configuration.buildConfig) === null || _c === void 0 ? void 0 : _c.macroVars) !== null && _d !== void 0 ? _d : {};
|
|
521
|
+
return [2 /*return*/, convertVarsToSasFormat(__assign(__assign({}, commonBuildVars), targetBuildVars))];
|
|
527
522
|
});
|
|
528
523
|
});
|
|
529
524
|
}
|
|
@@ -74,20 +74,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
74
74
|
};
|
|
75
75
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
76
|
exports.compileJobsServicesTests = exports.copyFilesToBuildFolder = exports.compile = void 0;
|
|
77
|
+
var utils_1 = require("@sasjs/utils");
|
|
78
|
+
var types_1 = require("@sasjs/utils/types");
|
|
79
|
+
var error_1 = require("@sasjs/utils/error");
|
|
77
80
|
var path_1 = __importDefault(require("path"));
|
|
78
81
|
var config_1 = require("../../utils/config");
|
|
79
|
-
var utils_1 = require("@sasjs/utils");
|
|
80
|
-
var web_1 = require("../web/web");
|
|
81
82
|
var file_1 = require("../../utils/file");
|
|
82
|
-
var
|
|
83
|
-
var checkCompileStatus_1 = require("./internal/checkCompileStatus");
|
|
83
|
+
var web_1 = require("../web/web");
|
|
84
84
|
var compileModule = __importStar(require("./compile"));
|
|
85
|
-
var
|
|
85
|
+
var checkCompileStatus_1 = require("./internal/checkCompileStatus");
|
|
86
86
|
var compileFile_1 = require("./internal/compileFile");
|
|
87
|
+
var getAllFolders_1 = require("./internal/getAllFolders");
|
|
87
88
|
var compileTestFile_1 = require("./internal/compileTestFile");
|
|
89
|
+
var copySyncFolder_1 = require("./internal/copySyncFolder");
|
|
88
90
|
var getDestinationPath_1 = require("./internal/getDestinationPath");
|
|
89
91
|
var loadDependencies_1 = require("./internal/loadDependencies");
|
|
90
|
-
var copySyncFolder_1 = require("./internal/copySyncFolder");
|
|
91
92
|
function compile(target, forceCompile) {
|
|
92
93
|
var _a, _b;
|
|
93
94
|
if (forceCompile === void 0) { forceCompile = false; }
|
|
@@ -173,7 +174,7 @@ exports.compile = compile;
|
|
|
173
174
|
function copyFilesToBuildFolder(target) {
|
|
174
175
|
var _a, _b;
|
|
175
176
|
return __awaiter(this, void 0, void 0, function () {
|
|
176
|
-
var buildDestinationFolder, serviceFolders, jobFolders,
|
|
177
|
+
var buildDestinationFolder, serviceFolders, jobFolders, error_2;
|
|
177
178
|
var _this = this;
|
|
178
179
|
return __generator(this, function (_c) {
|
|
179
180
|
switch (_c.label) {
|
|
@@ -228,9 +229,9 @@ function copyFilesToBuildFolder(target) {
|
|
|
228
229
|
_c.sent();
|
|
229
230
|
return [3 /*break*/, 8];
|
|
230
231
|
case 7:
|
|
231
|
-
|
|
232
|
+
error_2 = _c.sent();
|
|
232
233
|
(_b = process.logger) === null || _b === void 0 ? void 0 : _b.error("An error has occurred when copying files to ".concat(buildDestinationFolder, " ."));
|
|
233
|
-
throw
|
|
234
|
+
throw error_2;
|
|
234
235
|
case 8: return [2 /*return*/];
|
|
235
236
|
}
|
|
236
237
|
});
|
|
@@ -238,43 +239,46 @@ function copyFilesToBuildFolder(target) {
|
|
|
238
239
|
}
|
|
239
240
|
exports.copyFilesToBuildFolder = copyFilesToBuildFolder;
|
|
240
241
|
function compileJobsServicesTests(target, compileTree) {
|
|
241
|
-
var _a;
|
|
242
242
|
return __awaiter(this, void 0, void 0, function () {
|
|
243
|
-
var serviceFolders, jobFolders, macroFolders_1, programFolders_2, testSetUp, testTearDown,
|
|
243
|
+
var serviceFolders, jobFolders, macroFolders_1, programFolders_2, testSetUp, testTearDown, error_3;
|
|
244
244
|
var _this = this;
|
|
245
|
-
return __generator(this, function (
|
|
246
|
-
switch (
|
|
245
|
+
return __generator(this, function (_a) {
|
|
246
|
+
switch (_a.label) {
|
|
247
247
|
case 0:
|
|
248
|
-
|
|
248
|
+
_a.trys.push([0, 13, , 14]);
|
|
249
249
|
return [4 /*yield*/, (0, getAllFolders_1.getAllFolders)(target, getAllFolders_1.SasFileType.Service)];
|
|
250
250
|
case 1:
|
|
251
|
-
serviceFolders =
|
|
251
|
+
serviceFolders = _a.sent();
|
|
252
252
|
return [4 /*yield*/, (0, getAllFolders_1.getAllFolders)(target, getAllFolders_1.SasFileType.Job)];
|
|
253
253
|
case 2:
|
|
254
|
-
jobFolders =
|
|
254
|
+
jobFolders = _a.sent();
|
|
255
255
|
return [4 /*yield*/, (0, config_1.getMacroFolders)(target)];
|
|
256
256
|
case 3:
|
|
257
|
-
macroFolders_1 =
|
|
257
|
+
macroFolders_1 = _a.sent();
|
|
258
258
|
return [4 /*yield*/, (0, config_1.getProgramFolders)(target)];
|
|
259
259
|
case 4:
|
|
260
|
-
programFolders_2 =
|
|
260
|
+
programFolders_2 = _a.sent();
|
|
261
261
|
return [4 /*yield*/, (0, config_1.getTestSetUp)(target)];
|
|
262
262
|
case 5:
|
|
263
|
-
testSetUp =
|
|
263
|
+
testSetUp = _a.sent();
|
|
264
264
|
return [4 /*yield*/, (0, config_1.getTestTearDown)(target)];
|
|
265
265
|
case 6:
|
|
266
|
-
testTearDown =
|
|
266
|
+
testTearDown = _a.sent();
|
|
267
267
|
if (!testSetUp) return [3 /*break*/, 8];
|
|
268
|
-
return [4 /*yield*/, (0, compileTestFile_1.compileTestFile)(target, testSetUp, '', true, false, compileTree).catch(function (err) {
|
|
268
|
+
return [4 /*yield*/, (0, compileTestFile_1.compileTestFile)(target, testSetUp, '', true, false, compileTree).catch(function (err) {
|
|
269
|
+
throw (0, error_1.prefixMessage)(err, 'Test set up compilation has failed. ');
|
|
270
|
+
})];
|
|
269
271
|
case 7:
|
|
270
|
-
|
|
271
|
-
|
|
272
|
+
_a.sent();
|
|
273
|
+
_a.label = 8;
|
|
272
274
|
case 8:
|
|
273
275
|
if (!testTearDown) return [3 /*break*/, 10];
|
|
274
|
-
return [4 /*yield*/, (0, compileTestFile_1.compileTestFile)(target, testTearDown, '', true, false, compileTree).catch(function (err) {
|
|
276
|
+
return [4 /*yield*/, (0, compileTestFile_1.compileTestFile)(target, testTearDown, '', true, false, compileTree).catch(function (err) {
|
|
277
|
+
throw (0, error_1.prefixMessage)(err, 'Test tear down compilation has failed. ');
|
|
278
|
+
})];
|
|
275
279
|
case 9:
|
|
276
|
-
|
|
277
|
-
|
|
280
|
+
_a.sent();
|
|
281
|
+
_a.label = 10;
|
|
278
282
|
case 10: return [4 /*yield*/, (0, utils_1.asyncForEach)(serviceFolders, function (serviceFolder) { return __awaiter(_this, void 0, void 0, function () {
|
|
279
283
|
return __generator(this, function (_a) {
|
|
280
284
|
switch (_a.label) {
|
|
@@ -286,7 +290,7 @@ function compileJobsServicesTests(target, compileTree) {
|
|
|
286
290
|
});
|
|
287
291
|
}); })];
|
|
288
292
|
case 11:
|
|
289
|
-
|
|
293
|
+
_a.sent();
|
|
290
294
|
return [4 /*yield*/, (0, utils_1.asyncForEach)(jobFolders, function (jobFolder) { return __awaiter(_this, void 0, void 0, function () {
|
|
291
295
|
return __generator(this, function (_a) {
|
|
292
296
|
switch (_a.label) {
|
|
@@ -298,12 +302,11 @@ function compileJobsServicesTests(target, compileTree) {
|
|
|
298
302
|
});
|
|
299
303
|
}); })];
|
|
300
304
|
case 12:
|
|
301
|
-
|
|
305
|
+
_a.sent();
|
|
302
306
|
return [3 /*break*/, 14];
|
|
303
307
|
case 13:
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
throw error_2;
|
|
308
|
+
error_3 = _a.sent();
|
|
309
|
+
throw error_3;
|
|
307
310
|
case 14: return [2 /*return*/];
|
|
308
311
|
}
|
|
309
312
|
});
|
|
@@ -169,7 +169,7 @@ var CompileCommand = /** @class */ (function (_super) {
|
|
|
169
169
|
return command_1.ReturnCode.Success;
|
|
170
170
|
})
|
|
171
171
|
.catch(function (err) {
|
|
172
|
-
(0, utils_1.displayError)(err, 'An error has occurred
|
|
172
|
+
(0, utils_1.displayError)(err, 'An error has occurred during compilation.');
|
|
173
173
|
return command_1.ReturnCode.InternalError;
|
|
174
174
|
})];
|
|
175
175
|
case 2: return [2 /*return*/, _a.sent()];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { CompileTree, Configuration, Target } from '@sasjs/utils';
|
|
1
2
|
import { TestFlow } from '../../../types';
|
|
2
|
-
import { Target, Configuration, CompileTree } from '@sasjs/utils';
|
|
3
3
|
export declare function compileTestFile(target: Target, filePath: string, testVar: string | undefined, saveToRoot: boolean | undefined, removeOriginalFile: boolean | undefined, compileTree: CompileTree): Promise<void>;
|
|
4
4
|
export declare function copyTestMacroFiles(folderAbsolutePath: string): Promise<void>;
|
|
5
5
|
export declare const compileTestFlow: (target: Target, config?: Configuration) => Promise<TestFlow | undefined>;
|
|
@@ -65,13 +65,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
65
65
|
};
|
|
66
66
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
67
|
exports.compileTestFlow = exports.copyTestMacroFiles = exports.compileTestFile = void 0;
|
|
68
|
-
var types_1 = require("../../../types");
|
|
69
|
-
var path_1 = __importDefault(require("path"));
|
|
70
68
|
var utils_1 = require("@sasjs/utils");
|
|
71
|
-
var loadDependencies_1 = require("./loadDependencies");
|
|
72
|
-
var file_1 = require("../../../utils/file");
|
|
73
69
|
var chalk_1 = __importDefault(require("chalk"));
|
|
70
|
+
var path_1 = __importDefault(require("path"));
|
|
71
|
+
var types_1 = require("../../../types");
|
|
74
72
|
var config_1 = require("../../../utils/config");
|
|
73
|
+
var file_1 = require("../../../utils/file");
|
|
74
|
+
var loadDependencies_1 = require("./loadDependencies");
|
|
75
75
|
var getFileName = function (filePath) { return path_1.default.parse(filePath).base; };
|
|
76
76
|
function compileTestFile(target, filePath, testVar, saveToRoot, removeOriginalFile, compileTree) {
|
|
77
77
|
if (testVar === void 0) { testVar = ''; }
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CompileTree, SASJsFileType, Target } from '@sasjs/utils';
|
|
2
2
|
export declare function loadDependencies(target: Target, filePath: string, macroFolders: string[], programFolders: string[], type: SASJsFileType, compileTree: CompileTree): Promise<string>;
|
|
3
3
|
export declare const getCompileTree: (target: Target) => CompileTree;
|
|
@@ -41,8 +41,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.getCompileTree = exports.loadDependencies = void 0;
|
|
43
43
|
var utils_1 = require("@sasjs/utils");
|
|
44
|
-
var config_1 = require("../../../utils/config");
|
|
45
44
|
var path_1 = __importDefault(require("path"));
|
|
45
|
+
var config_1 = require("../../../utils/config");
|
|
46
46
|
function loadDependencies(target, filePath, macroFolders, programFolders, type, compileTree) {
|
|
47
47
|
var _a;
|
|
48
48
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -82,6 +82,8 @@ var compileSingleFile_1 = require("../compileSingleFile");
|
|
|
82
82
|
var compileFile = __importStar(require("../internal/compileFile"));
|
|
83
83
|
var utils_2 = require("../../../utils");
|
|
84
84
|
var compileCommand_1 = require("../compileCommand");
|
|
85
|
+
var error_1 = require("@sasjs/utils/error");
|
|
86
|
+
var compileTestFileModule = __importStar(require("../internal/compileTestFile"));
|
|
85
87
|
describe('sasjs compile', function () {
|
|
86
88
|
var sharedAppName;
|
|
87
89
|
var appName;
|
|
@@ -280,6 +282,46 @@ describe('sasjs compile', function () {
|
|
|
280
282
|
}
|
|
281
283
|
});
|
|
282
284
|
}); });
|
|
285
|
+
it('should fail to compile if testSetUp is present and test file compilation failed', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
286
|
+
var testSetUpFile, compileTestFileError, testTarget, expectedError;
|
|
287
|
+
return __generator(this, function (_a) {
|
|
288
|
+
switch (_a.label) {
|
|
289
|
+
case 0:
|
|
290
|
+
testSetUpFile = 'WRONG.sas';
|
|
291
|
+
compileTestFileError = "ENOENT: no such file or directory, open '".concat(testSetUpFile, "'");
|
|
292
|
+
testTarget = __assign({}, target);
|
|
293
|
+
testTarget.testConfig = { testSetUp: testSetUpFile };
|
|
294
|
+
jest
|
|
295
|
+
.spyOn(compileTestFileModule, 'compileTestFile')
|
|
296
|
+
.mockImplementation(function () { return Promise.reject(compileTestFileError); });
|
|
297
|
+
expectedError = (0, error_1.prefixMessage)(compileTestFileError, 'Test set up compilation has failed. ');
|
|
298
|
+
return [4 /*yield*/, expect(compileModule.compile(testTarget)).rejects.toEqual(expectedError)];
|
|
299
|
+
case 1:
|
|
300
|
+
_a.sent();
|
|
301
|
+
return [2 /*return*/];
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
}); });
|
|
305
|
+
it('should fail to compile if testTearDown is present and test file compilation failed', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
306
|
+
var testTearDownFile, compileTestFileError, testTarget, expectedError;
|
|
307
|
+
return __generator(this, function (_a) {
|
|
308
|
+
switch (_a.label) {
|
|
309
|
+
case 0:
|
|
310
|
+
testTearDownFile = 'WRONG.sas';
|
|
311
|
+
compileTestFileError = "ENOENT: no such file or directory, open '".concat(testTearDownFile, "'");
|
|
312
|
+
testTarget = __assign({}, target);
|
|
313
|
+
testTarget.testConfig = { testTearDown: testTearDownFile };
|
|
314
|
+
jest
|
|
315
|
+
.spyOn(compileTestFileModule, 'compileTestFile')
|
|
316
|
+
.mockImplementation(function () { return Promise.reject(compileTestFileError); });
|
|
317
|
+
expectedError = (0, error_1.prefixMessage)(compileTestFileError, 'Test tear down compilation has failed. ');
|
|
318
|
+
return [4 /*yield*/, expect(compileModule.compile(testTarget)).rejects.toEqual(expectedError)];
|
|
319
|
+
case 1:
|
|
320
|
+
_a.sent();
|
|
321
|
+
return [2 /*return*/];
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}); });
|
|
283
325
|
});
|
|
284
326
|
describe('sasjs compile single file', function () {
|
|
285
327
|
var appName;
|
|
@@ -55,7 +55,6 @@ exports.DocsCommand = void 0;
|
|
|
55
55
|
var __1 = require("..");
|
|
56
56
|
var command_1 = require("../../types/command");
|
|
57
57
|
var targetCommand_1 = require("../../types/command/targetCommand");
|
|
58
|
-
var utils_1 = require("../../utils");
|
|
59
58
|
var DocSubCommand;
|
|
60
59
|
(function (DocSubCommand) {
|
|
61
60
|
DocSubCommand["Init"] = "init";
|
|
@@ -137,9 +136,7 @@ var DocsCommand = /** @class */ (function (_super) {
|
|
|
137
136
|
case 0: return [4 /*yield*/, this.getTargetInfo()];
|
|
138
137
|
case 1:
|
|
139
138
|
target = (_a.sent()).target;
|
|
140
|
-
|
|
141
|
-
case 2:
|
|
142
|
-
config = _a.sent();
|
|
139
|
+
config = process.sasjsConfig;
|
|
143
140
|
return [4 /*yield*/, (0, __1.generateDocs)(target, config, this.parsed.outDirectory)
|
|
144
141
|
.then(function (res) {
|
|
145
142
|
var _a;
|
|
@@ -151,7 +148,7 @@ var DocsCommand = /** @class */ (function (_super) {
|
|
|
151
148
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error generating docs: ', err);
|
|
152
149
|
return command_1.ReturnCode.InternalError;
|
|
153
150
|
})];
|
|
154
|
-
case
|
|
151
|
+
case 2:
|
|
155
152
|
returnCode = _a.sent();
|
|
156
153
|
return [2 /*return*/, returnCode];
|
|
157
154
|
}
|
|
@@ -166,9 +163,7 @@ var DocsCommand = /** @class */ (function (_super) {
|
|
|
166
163
|
case 0: return [4 /*yield*/, this.getTargetInfo()];
|
|
167
164
|
case 1:
|
|
168
165
|
target = (_a.sent()).target;
|
|
169
|
-
|
|
170
|
-
case 2:
|
|
171
|
-
config = _a.sent();
|
|
166
|
+
config = process.sasjsConfig;
|
|
172
167
|
return [4 /*yield*/, (0, __1.generateDot)(target, config, this.parsed.outDirectory)
|
|
173
168
|
.then(function (res) {
|
|
174
169
|
var _a;
|
|
@@ -180,7 +175,7 @@ var DocsCommand = /** @class */ (function (_super) {
|
|
|
180
175
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error generating docs: ', err);
|
|
181
176
|
return command_1.ReturnCode.InternalError;
|
|
182
177
|
})];
|
|
183
|
-
case
|
|
178
|
+
case 2:
|
|
184
179
|
returnCode = _a.sent();
|
|
185
180
|
return [2 /*return*/, returnCode];
|
|
186
181
|
}
|
package/build/utils/config.js
CHANGED
|
@@ -879,26 +879,31 @@ function getAuthConfig(target) {
|
|
|
879
879
|
}
|
|
880
880
|
exports.getAuthConfig = getAuthConfig;
|
|
881
881
|
var saveTokens = function (targetName, client, secret, access_token, refresh_token) { return __awaiter(void 0, void 0, void 0, function () {
|
|
882
|
-
var
|
|
883
|
-
var _a, _b, _c
|
|
884
|
-
return __generator(this, function (
|
|
885
|
-
switch (
|
|
886
|
-
case 0: return [4 /*yield*/, getLocalConfig()
|
|
882
|
+
var isLocalTarget, envFileContent, envFilePath, globalConfig, target, targetJson;
|
|
883
|
+
var _a, _b, _c;
|
|
884
|
+
return __generator(this, function (_d) {
|
|
885
|
+
switch (_d.label) {
|
|
886
|
+
case 0: return [4 /*yield*/, getLocalConfig()
|
|
887
|
+
.then(function (localConfig) { var _a; return (_a = localConfig.targets) === null || _a === void 0 ? void 0 : _a.some(function (t) { return t.name === targetName; }); })
|
|
888
|
+
.catch(function () {
|
|
889
|
+
var _a;
|
|
890
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.info('Local sasjsconfig.json file could not be found! Now finding target in global .sasjsrc file');
|
|
891
|
+
return false;
|
|
892
|
+
})];
|
|
887
893
|
case 1:
|
|
888
|
-
|
|
889
|
-
isLocalTarget = (_a = localConfig.targets) === null || _a === void 0 ? void 0 : _a.some(function (t) { return t.name === targetName; });
|
|
894
|
+
isLocalTarget = _d.sent();
|
|
890
895
|
if (!isLocalTarget) return [3 /*break*/, 3];
|
|
891
896
|
envFileContent = "CLIENT=".concat(client, "\nSECRET=").concat(secret, "\nACCESS_TOKEN=").concat(access_token, "\nREFRESH_TOKEN=").concat(refresh_token, "\n");
|
|
892
897
|
envFilePath = path_1.default.join(process.projectDir, ".env.".concat(targetName));
|
|
893
898
|
return [4 /*yield*/, (0, utils_1.createFile)(envFilePath, envFileContent)];
|
|
894
899
|
case 2:
|
|
895
|
-
|
|
896
|
-
(
|
|
900
|
+
_d.sent();
|
|
901
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Environment file saved at ".concat(envFilePath));
|
|
897
902
|
return [3 /*break*/, 6];
|
|
898
903
|
case 3: return [4 /*yield*/, getGlobalRcFile()];
|
|
899
904
|
case 4:
|
|
900
|
-
globalConfig =
|
|
901
|
-
target = (
|
|
905
|
+
globalConfig = _d.sent();
|
|
906
|
+
target = (_b = globalConfig.targets) === null || _b === void 0 ? void 0 : _b.find(function (t) { return t.name === targetName; });
|
|
902
907
|
if (!target) {
|
|
903
908
|
throw new Error(ERROR_MESSAGE(targetName).NOT_FOUND_TARGET_NAME);
|
|
904
909
|
}
|
|
@@ -906,9 +911,9 @@ var saveTokens = function (targetName, client, secret, access_token, refresh_tok
|
|
|
906
911
|
targetJson.authConfig = { client: client, secret: secret, access_token: access_token, refresh_token: refresh_token };
|
|
907
912
|
return [4 /*yield*/, saveToGlobalConfig(new utils_1.Target(targetJson), globalConfig.defaultTarget === targetName)];
|
|
908
913
|
case 5:
|
|
909
|
-
|
|
910
|
-
(
|
|
911
|
-
|
|
914
|
+
_d.sent();
|
|
915
|
+
(_c = process.logger) === null || _c === void 0 ? void 0 : _c.success("Target saved to global .sasjsrc file at ~/.sasjsrc.");
|
|
916
|
+
_d.label = 6;
|
|
912
917
|
case 6: return [2 /*return*/];
|
|
913
918
|
}
|
|
914
919
|
});
|
package/package.json
CHANGED